diff --git a/packages/mad_pay/CHANGELOG.md b/packages/mad_pay/CHANGELOG.md index 41b9dbc..9acf17d 100644 --- a/packages/mad_pay/CHANGELOG.md +++ b/packages/mad_pay/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.3 + +* [iOS] Fix nil arguments + ## 2.2.1-2.2.2 * [Android] Fix release build diff --git a/packages/mad_pay/pubspec.yaml b/packages/mad_pay/pubspec.yaml index 0ac8346..f4ff054 100644 --- a/packages/mad_pay/pubspec.yaml +++ b/packages/mad_pay/pubspec.yaml @@ -1,6 +1,6 @@ name: mad_pay description: Mad Pay will help you make payments through Apple Pay and Google Pay -version: 2.2.2 +version: 2.2.3 repository: https://github.com/MadBrains/Mad-Pay-Flutter issue_tracker: https://github.com/MadBrains/Mad-Pay-Flutter/issues homepage: https://madbrains.ru/ @@ -14,7 +14,7 @@ dependencies: sdk: flutter mad_pay_platform_interface: ^2.2.0 mad_pay_android: ^2.2.2 - mad_pay_ios: ^2.2.0 + mad_pay_ios: ^2.2.1 # For development. Remove/comment before publishing to pub. # dependency_overrides: diff --git a/packages/mad_pay_ios/CHANGELOG.md b/packages/mad_pay_ios/CHANGELOG.md index 272f183..fe195d1 100644 --- a/packages/mad_pay_ios/CHANGELOG.md +++ b/packages/mad_pay_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.2.1 + +* Fix nil arguments + ## 2.2.0 * Initial `mad_pay_ios` module. \ No newline at end of file diff --git a/packages/mad_pay_ios/ios/Classes/SwiftMadPayIosPlugin.swift b/packages/mad_pay_ios/ios/Classes/SwiftMadPayIosPlugin.swift index 47d6f67..d8eb4a8 100644 --- a/packages/mad_pay_ios/ios/Classes/SwiftMadPayIosPlugin.swift +++ b/packages/mad_pay_ios/ios/Classes/SwiftMadPayIosPlugin.swift @@ -5,17 +5,17 @@ import PassKit @available(iOS 10.0, *) public class SwiftMadPayIosPlugin: NSObject, FlutterPlugin { private var activeResult: FlutterResult? - + public static func register(with registrar: FlutterPluginRegistrar) { let messenger = registrar.messenger() - + let channel = FlutterMethodChannel(name: Constants.channel, binaryMessenger: messenger) registrar.addMethodCallDelegate(SwiftMadPayIosPlugin(), channel: channel) - + let buttonFactory = ApplePayButtonViewFactory(messenger: messenger) registrar.register(buttonFactory, withId: Constants.buttonChannel) } - + func invokeSuccessResult(success: Bool = true, data: Data? = nil) { guard (try? activeResult?(Response.with({ (res) in res.success = success @@ -26,7 +26,7 @@ public class SwiftMadPayIosPlugin: NSObject, FlutterPlugin { return } } - + func invokeErrorResult(success: Bool = false, errorCode: String? = nil, message: String? = nil) { guard (try? activeResult?(Response.with({ (res) in res.success = success @@ -40,42 +40,44 @@ public class SwiftMadPayIosPlugin: NSObject, FlutterPlugin { return } } - + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { activeResult = result - - guard let arguments = (call.arguments as? Flutter.FlutterStandardTypedData?)??.data else { + + let arguments = (call.arguments as? Flutter.FlutterStandardTypedData?)??.data + + if arguments == nil && (call.method == Constants.checkActiveCard || call.method == Constants.payment) { invokeErrorResult(errorCode: Constants.invalidParametersCode, message: "Invalid parameters. \"Arguments\" is null") return } - + switch call.method { case Constants.checkPayments: checkPayments() - case Constants.checkActiveCard: try? checkActiveCard(arguments: CheckActiveCardRequest(serializedData: arguments)) - case Constants.payment: try? payment(arguments: PaymentRequest(serializedData: arguments)) + case Constants.checkActiveCard: try? checkActiveCard(arguments: CheckActiveCardRequest(serializedData: arguments!)) + case Constants.payment: try? payment(arguments: PaymentRequest(serializedData: arguments!)) default: invokeErrorResult(errorCode: Constants.notImplementedCode, message: "Method \(call.method) not implemented") } } - + func checkPayments() { let canMakePayment = PKPaymentAuthorizationController.canMakePayments() invokeSuccessResult(success: canMakePayment) } - + func checkActiveCard(arguments: CheckActiveCardRequest) { let canMakePayments = PKPaymentAuthorizationController.canMakePayments( - usingNetworks: PaymentNetworkHelper.getPaymentNetworks(arguments.allowedPaymentNetworks)) - + usingNetworks: PaymentNetworkHelper.getPaymentNetworks(arguments.allowedPaymentNetworks)) + invokeSuccessResult(success: canMakePayments) } - + func payment(arguments: PaymentRequest) { if (arguments.parameters == nil) { invokeErrorResult(errorCode: Constants.invalidParametersCode, message: "Invalid Payment parameters. \"Apple\" parameter required") return } - + if (arguments.apple.merchantIdentifier.isEmpty || arguments.currencyCode.isEmpty || arguments.countryCode.isEmpty) { invokeErrorResult(errorCode: Constants.invalidParametersCode, message: """ Invalid Payment parameters. @@ -85,10 +87,10 @@ public class SwiftMadPayIosPlugin: NSObject, FlutterPlugin { """) return } - + var paymentNetworks = PaymentNetworkHelper.getPaymentNetworks(arguments.allowedPaymentNetworks) paymentNetworks = paymentNetworks.isEmpty ? PKPaymentRequest.availableNetworks() : paymentNetworks - + let paymentRequest = PKPaymentRequest() paymentRequest.paymentSummaryItems = PaymentNetworkHelper.getPaymentSummaryItem(arguments.paymentItems) paymentRequest.supportedNetworks = paymentNetworks @@ -100,11 +102,11 @@ public class SwiftMadPayIosPlugin: NSObject, FlutterPlugin { paymentRequest.shippingContact = PaymentNetworkHelper.getContact(arguments.apple.shippingContact) paymentRequest.shippingMethods = PaymentNetworkHelper.getShippingMethods(arguments.apple.shippingMethods) paymentRequest.shippingType = PaymentNetworkHelper.getShippingType(arguments.apple.shippingType) - + if !arguments.apple.applicationData.isEmpty { paymentRequest.applicationData = arguments.apple.applicationData } - + if #available(iOS 11.0, *) { if !arguments.apple.requiredBillingContactFields.isEmpty { paymentRequest.requiredBillingContactFields = PaymentNetworkHelper.getContactFields(arguments.apple.requiredBillingContactFields) @@ -113,12 +115,12 @@ public class SwiftMadPayIosPlugin: NSObject, FlutterPlugin { paymentRequest.requiredShippingContactFields = PaymentNetworkHelper.getContactFields(arguments.apple.requiredShippingContactFields) } } - + let paymentController = PKPaymentAuthorizationController(paymentRequest: paymentRequest) paymentController.delegate = self paymentController.present(completion: nil) } - + private func paymentResult(pkPayment: PKPayment?) { if let payment = pkPayment { let jsonEncoder = JSONEncoder() @@ -140,7 +142,7 @@ extension SwiftMadPayIosPlugin: PKPaymentAuthorizationControllerDelegate { paymentResult(pkPayment: nil) controller.dismiss(completion: nil) } - + @available(iOS 11.0, *) public func paymentAuthorizationController(_ controller: PKPaymentAuthorizationController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) { paymentResult(pkPayment: payment) diff --git a/packages/mad_pay_ios/pubspec.yaml b/packages/mad_pay_ios/pubspec.yaml index c41afd2..cda8cc5 100644 --- a/packages/mad_pay_ios/pubspec.yaml +++ b/packages/mad_pay_ios/pubspec.yaml @@ -1,6 +1,6 @@ name: mad_pay_ios description: A plug-in to add support for payments on the iOS side of Mad Pay -version: 2.2.0 +version: 2.2.1 repository: https://github.com/MadBrains/Mad-Pay-Flutter issue_tracker: https://github.com/MadBrains/Mad-Pay-Flutter/issues homepage: https://madbrains.ru/