#tarunmv30
1 messages · Page 1 of 1 (latest)
You would need to use 1 Customer Id and not keep creating new
When the PaymentSheet has the Customer Id, it will display previously saved PaymentMethod list
let me try hold on
so im now able to create the customer object in my stripe dashboard when a user makes an account
let jsonData = try? JSONEncoder().encode(cart)
var request = URLRequest(url: backendCheckoutUrl)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = jsonData
let task = URLSession.shared.dataTask(
with: request,
completionHandler: { (data, _, _) in
guard let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: [])
as? [String: Any],
let customerId = json["customer"] as? String,
let customerEphemeralKeySecret = json["ephemeralKey"] as? String,
let paymentIntentClientSecret = json["paymentIntent"] as? String,
let publishableKey = json["publishableKey"] as? String
else {
print("There was an error with the data")
return
}
STPAPIClient.shared.publishableKey = publishableKey
var configuration = PaymentSheet.Configuration()
configuration.merchantDisplayName = "Neils Urban Oven"
configuration.customer = .init(
id: customerId,
ephemeralKeySecret: customerEphemeralKeySecret
)
configuration.returnURL = "your-app-url://stripe-redirect"
configuration.allowsDelayedPaymentMethods = true
```
self.paymentSheet = PaymentSheet(
paymentIntentClientSecret: paymentIntentClientSecret,
configuration: configuration
)
self.paymentSheet?.onResult { result in
self.paymentResult = result
}
if let paymentMethod = self.paymentResult?.paymentMethod {
self.savePaymentMethod(paymentMethod: paymentMethod)
}
}
}
)
task.resume()
}````
im just confused on how I would retrieve the customer id from the stripe object and somehow use that to save the payment details
Your code makes sense! But I don't really follow your last question. Next time opening the PaymentSheet, you should receive the Customer ID from your backend and the PaymentSheet will automatically recognize if that Customer has a saved PaymentMethod last time
Thank you! Im getting these errors tho any idea what may be causing this chatgpt wasnt able to help me