diff --git a/Example/Standard Integration/CheckoutViewController.swift b/Example/Standard Integration/CheckoutViewController.swift index 5ab1627ec2b..a238f930d2b 100644 --- a/Example/Standard Integration/CheckoutViewController.swift +++ b/Example/Standard Integration/CheckoutViewController.swift @@ -264,7 +264,7 @@ extension CheckoutViewController: STPPaymentContextDelegate { func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPPaymentStatusBlock) { // Create the PaymentIntent on the backend // A real app should do this at the beginning of the checkout flow, instead of re-creating a PaymentIntent for every payment attempt. - MyAPIClient.sharedClient.createPaymentIntent() { result in + MyAPIClient.sharedClient.createPaymentIntent(products: self.products, shippingMethod: paymentContext.selectedShippingMethod) { result in switch result { case .success(let clientSecret): // Confirm the PaymentIntent @@ -381,6 +381,7 @@ extension CheckoutViewController: STPPaymentContextDelegate { } else { fedEx.amount = 20.99 + fedEx.identifier = "fedex_world" completion(.valid, nil, [upsWorldwide, fedEx], fedEx) } } diff --git a/Example/Standard Integration/MyAPIClient.swift b/Example/Standard Integration/MyAPIClient.swift index 77266e2639d..5f835642e44 100644 --- a/Example/Standard Integration/MyAPIClient.swift +++ b/Example/Standard Integration/MyAPIClient.swift @@ -31,15 +31,20 @@ class MyAPIClient: NSObject, STPCustomerEphemeralKeyProvider { } } - func createPaymentIntent(completion: @escaping ((Result) -> Void)) { + func createPaymentIntent(products: [Product], shippingMethod: PKShippingMethod?, completion: @escaping ((Result) -> Void)) { let url = self.baseURL.appendingPathComponent("create_payment_intent") - let params: [String: Any] = [ + var params: [String: Any] = [ "metadata": [ // example-ios-backend allows passing metadata through to Stripe "payment_request_id": "B3E611D1-5FA1-4410-9CEC-00958A5126CB", ], ] - + params["products"] = products.map({ (p) -> String in + return p.emoji + }) + if let shippingMethod = shippingMethod { + params["shipping"] = shippingMethod.identifier + } let jsonData = try? JSONSerialization.data(withJSONObject: params) var request = URLRequest(url: url) request.httpMethod = "POST"