Advertisement
harsh-brainvire

ApplePay Code

Oct 11th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.77 KB | None | 0 0
  1. func submitApplePayTransaction(controller: UIViewController, call: FlutterMethodCall, result: FlutterResult) {
  2.        
  3.         let dictPayment : Dictionary<String,String> =  call.arguments as? Dictionary<String,String> ?? [:]
  4.        
  5.         var checkOutID = dictPayment[PaymentConfig.checkoutIdArgument] ?? ""
  6.         applePayCheckOutID = checkOutID
  7.         var merchantId = dictPayment[PaymentConfig.merchantIDArgument] ?? ""
  8.         var amount = dictPayment[PaymentConfig.amountArgument] ?? "00.00"
  9.        
  10.        
  11.         do {
  12.             let request = OPPPaymentProvider.paymentRequest(withMerchantIdentifier: merchantId, countryCode: "SA")
  13.             amount = amount.replacingOccurrences(of: ".", with: "")
  14.             var convertedAmount: UInt64 = UInt64(amount)!
  15.             // Set currency.
  16.             request.currencyCode = "SAR"
  17.             request.merchantCapabilities = PKMerchantCapability.threeDSecure
  18.            
  19.             // Create total item. Label should represent your company.
  20.             // It will be prepended with the word "Pay" (i.e. "Pay Sportswear $100.00")
  21.             let amount = NSDecimalNumber(mantissa: convertedAmount, exponent: -2, isNegative: false)
  22.            
  23.             request.paymentSummaryItems = [PKPaymentSummaryItem(label: "banzeeny", amount: amount)]
  24.             if OPPPaymentProvider.canSubmitPaymentRequest(request) {
  25.                 if let vc = PKPaymentAuthorizationViewController(paymentRequest: request) as? PKPaymentAuthorizationViewController {
  26.                     vc.delegate = self
  27.                    
  28.                     if let navVc = controller.navigationController {
  29.                         navVc.present(vc, animated: true, completion: nil)
  30.                     } else {
  31.                         print("Controller not found")
  32.                     }
  33.                 } else {
  34.                     self.paymentStatusChannel?.invokeMethod(PaymentManager.shared.failedMethod, arguments: [
  35.                         PaymentConfig.typeArgument: PaymentConfig.applePayTransactionType,
  36.                         PaymentConfig.checkoutIdArgument: checkOutID ,
  37.                         PaymentConfig.errorMessageArgument: "Apple Pay not supported.",
  38.                         PaymentConfig.errorCodeArgument: ""
  39.                     ])
  40.                 }
  41.             }
  42.             result(true)
  43.         } catch let err {
  44.             self.paymentStatusChannel?.invokeMethod(PaymentManager.shared.failedMethod, arguments: [
  45.                 PaymentConfig.typeArgument: PaymentConfig.applePayTransactionType,
  46.                 PaymentConfig.checkoutIdArgument: checkOutID ?? "",
  47.                 PaymentConfig.errorMessageArgument: err.localizedDescription,
  48.                 PaymentConfig.errorCodeArgument: ""
  49.             ])
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement