From a918558e4cc7c917b67dbcef1a16cd9036b37bc5 Mon Sep 17 00:00:00 2001 From: Jose Ugia Date: Fri, 10 Sep 2021 14:45:51 +0200 Subject: [PATCH 1/3] Use Double to convert from string to number, to ensure consistency using the decimal character (.) regardless of the local configuration of each device --- pay_ios/ios/Classes/PaymentHandler.swift | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pay_ios/ios/Classes/PaymentHandler.swift b/pay_ios/ios/Classes/PaymentHandler.swift index 35de7c12..249557a5 100644 --- a/pay_ios/ios/Classes/PaymentHandler.swift +++ b/pay_ios/ios/Classes/PaymentHandler.swift @@ -119,16 +119,11 @@ class PaymentHandler: NSObject { // Create payment request and include summary items let paymentRequest = PKPaymentRequest() paymentRequest.paymentSummaryItems = paymentItems.map { item in - if let statusString = item["status"] { - return PKPaymentSummaryItem( - label: item["label"] as! String , - amount: NSDecimalNumber(string: (item["amount"] as! String)), - type: PKPaymentSummaryItemType.fromString(statusString as! String)) - } - return PKPaymentSummaryItem( label: item["label"] as! String, - amount: NSDecimalNumber(string: (item["amount"] as! String))) + amount: NSDecimalNumber(value: Double(item["amount"] as! String)!), + type: (PKPaymentSummaryItemType.fromString(item["status"] as? String ?? "final_price")) + ) } // Configure the payment. From cdc30165ea7e059b39c43f7a1c10ff78fdd5e699 Mon Sep 17 00:00:00 2001 From: Jose Ugia Date: Fri, 10 Sep 2021 14:46:31 +0200 Subject: [PATCH 2/3] Apple Pay defaults to final when the price type is not set --- pay_ios/ios/Classes/PaymentHandler.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pay_ios/ios/Classes/PaymentHandler.swift b/pay_ios/ios/Classes/PaymentHandler.swift index 249557a5..b3aa5fca 100644 --- a/pay_ios/ios/Classes/PaymentHandler.swift +++ b/pay_ios/ios/Classes/PaymentHandler.swift @@ -304,10 +304,10 @@ extension PKPaymentSummaryItemType { /// Creates a `PKPaymentSummaryItemType` object from an item type in string format. public static func fromString(_ summaryItemType: String) -> PKPaymentSummaryItemType { switch summaryItemType { - case "final_price": - return .final - default: + case "pending": return .pending + default: + return .final // final_price } } } From 4ef1b8aff1caa591cf80f77f3d158265a5e42cde Mon Sep 17 00:00:00 2001 From: Jose Ugia Date: Sun, 16 Jan 2022 13:55:20 +0100 Subject: [PATCH 3/3] Use the decimal separator instead of Double to make the parsing more explicit --- pay_ios/ios/Classes/PaymentHandler.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pay_ios/ios/Classes/PaymentHandler.swift b/pay_ios/ios/Classes/PaymentHandler.swift index b3aa5fca..042aa3b5 100644 --- a/pay_ios/ios/Classes/PaymentHandler.swift +++ b/pay_ios/ios/Classes/PaymentHandler.swift @@ -121,7 +121,7 @@ class PaymentHandler: NSObject { paymentRequest.paymentSummaryItems = paymentItems.map { item in return PKPaymentSummaryItem( label: item["label"] as! String, - amount: NSDecimalNumber(value: Double(item["amount"] as! String)!), + amount: NSDecimalNumber(string: (item["amount"] as! String), locale:["NSLocaleDecimalSeparator": "."]), type: (PKPaymentSummaryItemType.fromString(item["status"] as? String ?? "final_price")) ) }