#OBietnua - ios sdk

1 messages · Page 1 of 1 (latest)

tacit dew
#

Hello. orakaro is out right now

#

I can assist

plush valve
#

Thanks

tacit dew
#

Can you explain more what you are trying to do? With as many details as possible

plush valve
#

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

#

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

tacit dew
#

Are you using the card element or mobile payment element?

plush valve
#

I am on mobile side

#

How can I know which one I am using

tacit dew
#

yeah I understand

#

What guide are you following?

plush valve
#

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

tacit dew
#

Ok checking with a colleague

plush valve
#

Thanks

hollow plinth
#

what component are you actually using?The screenshot is the STPPaymentOptionsViewController but are you using it directly or with the STPPaymentContext?

plush valve
#

Yes

hollow plinth
#

yes you're using it in the STPPaymentContext?

plush valve
#

Yes

#

I use it to get the callback

hollow plinth
#

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.

plush valve
#

What is your suggestion?

#

We wanna have that feature from mobile app

hollow plinth
#

that component is just for adding/selecting cards and you get the selected payment method in the didSelect delegate function

plush valve
#

And I will present it manually right?

#

Don’t open it from the context

hollow plinth
#

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.

plush valve
#

How about the callback? Still using old function right?

hollow plinth
#

what do you mean by 'callback'?

plush valve
#

I mean get selected payment method

plush valve
#

Oh cool

#

I got it

#

Let me try

#

I can see did select

hollow plinth
plush valve
#

I still can get payment method id in did select function

#

It returned SPTPaymentOption

hollow plinth
#

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).

plush valve
#

Oh I can get it

#

It’s seem a solution right?

hollow plinth
#

can you expand on the question?

plush valve
#

I mean that is a solution

#

Because you suggested using paymentsheet

hollow plinth
#

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.

plush valve
#

Hi, the didselect function return immediately

#

But I wanna get payment method after user select only

hollow plinth
#

did you read the documentation for the function, which I linked above?

#

This will be triggered after the view controller loads with the user’s current selection (if they have one) and then subsequently when they change their choice.