Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents decimal conversion issues with certain locales #89

Merged
merged 3 commits into from
Jan 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions pay_ios/ios/Classes/PaymentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(string: (item["amount"] as! String), locale:["NSLocaleDecimalSeparator": "."]),
type: (PKPaymentSummaryItemType.fromString(item["status"] as? String ?? "final_price"))
)
}

// Configure the payment.
Expand Down Expand Up @@ -309,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
}
}
}
Expand Down