#OBietnua - ios sdk
1 messages · Page 1 of 1 (latest)
Thanks
Can you explain more what you are trying to do? With as many details as possible
So right now we wanna update default payment method from mobile app
We will call API to set it as default payment for subscription
But in sdk I can’t get payment method id
What I can get only last 4 Digits and image
https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#default-payment-method
Create and manage subscriptions to accept recurring payments.
Our backend guy already created an API to set default payment method b
But he need payment method id
Right now I am unable to get it
Are you using the card element or mobile payment element?
yeah I understand
Are you using this guide? https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet
What guide are you following?
I’m using card element only
I mean this screen
So I wanna have payment method id to call api update default payment method on platform
Ok checking with a colleague
Thanks
what component are you actually using?The screenshot is the STPPaymentOptionsViewController but are you using it directly or with the STPPaymentContext?
Yes
yes you're using it in the STPPaymentContext?
makes sense
but yeah, the component won't work here, since it's optimised for taking payments, it doesn't just give you a PaymentMethod ID that you can send to your backend.
you should use the STPPaymentOptionsViewController directly instead (https://stripe.dev/stripe-ios/docs/Classes/STPPaymentOptionsViewController.html)
that component is just for adding/selecting cards and you get the selected payment method in the didSelect delegate function
yes, you would present it directly
// Setup payment Options view controller
let paymentOptionsViewController = STPPaymentOptionsViewController(configuration: STPPaymentConfiguration.shared, theme: STPTheme.defaultTheme, customerContext: self.customerContext!, delegate: self)
// Present payment Options view controller
let navigationController = UINavigationController(rootViewController: paymentOptionsViewController)
present(navigationController, animated: true)
e.g.
How about the callback? Still using old function right?
what do you mean by 'callback'?
I mean get selected payment method
for what it's worth though I wouldn't build it this way, these components are older. You should be using the PaymentSheet mentioned above, with a SetupIntent. (https://stripe.com/docs/payments/save-and-reuse?platform=ios&ui=payment-sheet)
I still can get payment method id in did select function
It returned SPTPaymentOption
yep it does return that
you can cast it to an STPPaymentMethod but you need to check the type
for example
selectedPaymentOption = paymentOption
print(paymentOption)
if let card = paymentOption as? STPPaymentMethod {
let cardId = card.stripeId // "pm_xxx"
print(cardId)
}
(using as? in Swift to try to cast if possible).
can you expand on the question?
not sure what "that" is, but yes, there are multiple ways to approach this.
The recommended one would be the PaymentSheet integration with SetupIntents since it handles 3D Secure to authenticate the card when it saved, and also lets you use a few different payment methods, but the STPPaymentOptionsViewController can be a simpler option.