 
 /// Extension that implements the completion methods in the delegate to respond to user selection.
 extension PaymentHandler: PKPaymentAuthorizationControllerDelegate {
+
+  func paymentAuthorizationControllerWillAuthorizePayment(_ controller: PKPaymentAuthorizationController) {
+      paymentHandlerStatus = .authorizationStarted
+  }
+    
   func paymentAuthorizationController(_: PKPaymentAuthorizationController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
     
     // Collect payment result or error and return if no payment was selected

class PaymentHandler: NSObject {
  
  /// Holds the current status of the payment process.
  var paymentStatus = PKPaymentAuthorizationStatus.failure
  
  /// Stores a reference to the Flutter result while the operation completes.
  var paymentResult: FlutterResult!

    // Return the result back to the channel
    self.paymentResult(String(decoding: paymentResultData, as: UTF8.self))
    
    paymentHandlerStatus = .authorized

    completion(PKPaymentAuthorizationResult(status: PKPaymentAuthorizationStatus.success, errors: nil))
  }
  
  func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
    controller.dismiss {
      DispatchQueue.main.async {
        // There was no attempt to authorize.
        if self.paymentHandlerStatus == .presented {
          self.paymentResult(FlutterError(code: "paymentCanceled", message: "User canceled payment authorization", details: nil))
        }
        // Authorization started, but it did not succeed
        if self.paymentHandlerStatus == .authorizationStarted {
          self.paymentResult(FlutterError(code: "paymentFailed", message: "Failed to complete the payment", details: nil))
        }
      }
