Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func submitApplePayTransaction(controller: UIViewController, call: FlutterMethodCall, result: FlutterResult) {
- let dictPayment : Dictionary<String,String> = call.arguments as? Dictionary<String,String> ?? [:]
- var checkOutID = dictPayment[PaymentConfig.checkoutIdArgument] ?? ""
- applePayCheckOutID = checkOutID
- var merchantId = dictPayment[PaymentConfig.merchantIDArgument] ?? ""
- var amount = dictPayment[PaymentConfig.amountArgument] ?? "00.00"
- do {
- let request = OPPPaymentProvider.paymentRequest(withMerchantIdentifier: merchantId, countryCode: "SA")
- amount = amount.replacingOccurrences(of: ".", with: "")
- var convertedAmount: UInt64 = UInt64(amount)!
- // Set currency.
- request.currencyCode = "SAR"
- request.merchantCapabilities = PKMerchantCapability.threeDSecure
- // Create total item. Label should represent your company.
- // It will be prepended with the word "Pay" (i.e. "Pay Sportswear $100.00")
- let amount = NSDecimalNumber(mantissa: convertedAmount, exponent: -2, isNegative: false)
- request.paymentSummaryItems = [PKPaymentSummaryItem(label: "banzeeny", amount: amount)]
- if OPPPaymentProvider.canSubmitPaymentRequest(request) {
- if let vc = PKPaymentAuthorizationViewController(paymentRequest: request) as? PKPaymentAuthorizationViewController {
- vc.delegate = self
- if let navVc = controller.navigationController {
- navVc.present(vc, animated: true, completion: nil)
- } else {
- print("Controller not found")
- }
- } else {
- self.paymentStatusChannel?.invokeMethod(PaymentManager.shared.failedMethod, arguments: [
- PaymentConfig.typeArgument: PaymentConfig.applePayTransactionType,
- PaymentConfig.checkoutIdArgument: checkOutID ,
- PaymentConfig.errorMessageArgument: "Apple Pay not supported.",
- PaymentConfig.errorCodeArgument: ""
- ])
- }
- }
- result(true)
- } catch let err {
- self.paymentStatusChannel?.invokeMethod(PaymentManager.shared.failedMethod, arguments: [
- PaymentConfig.typeArgument: PaymentConfig.applePayTransactionType,
- PaymentConfig.checkoutIdArgument: checkOutID ?? "",
- PaymentConfig.errorMessageArgument: err.localizedDescription,
- PaymentConfig.errorCodeArgument: ""
- ])
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement