#oleksandr_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1369256754793287752
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi there!
what are you trying to do? you want to reuse the existing payment method saved on the customer?
Hi, yes I want to reuse existing payment method and avoid adding same PM to a customer on subsequent payments
can you share the request ID (req_xxx) where you created a new subscription? or the subscription ID (sub_xxx) itself?
Let me find it
Customer: cus_SGECjd6Dy1a5Q5
1st Sub Id: sub_1RLhkWCMkkLn6luHGaTIdzop
2nd Sub Id: sub_1RLiecCMkkLn6luHUlFNWNbr
got it. you could set this parameter when creating the second subscription: https://docs.stripe.com/api/subscriptions/create#create_subscription-default_payment_method
You mean "default_payment_method", right?
yes, that's exactly what I linked
Just double-checking ๐
Okay, will try to do that
Also, what are the base practice to reuse payment method from Appl/Google Pay? Is this flow correct:
- Check if customer payment method is equal to current PM
1.1 If yes --> create subscription with default_payment_method
1.2 If no --> create subscription with payment_settings.save_default_payment_method = 'on_subscription' and save this PM as a default one
I don't understand step 1. can you clarify what you mean by this?
There will be many subscription payments and as I understood every payment has new payment method id so in this situation I will need to reuse the first PM id for subsequent payments. In order to check is it first payment I am using default PM from customer object. If it is null then I will need to create new subscription with saving PM, if not then I must reuse it.
- By "customer payment method" I meant default PM that is attached to a customer object;
- By "current PM" I meant the payment method with comes on a current payment
There might be the case where users lost their card or whatever and try to pay with a new card from Apple Wallet. Should I then change default PM on every payment so that user will always have possibility to pay? In another words, in PM associated to Apple Wallet where doesn't matter what card user will use, Stripe will always define it automatically or PM is associated with a card from Apple Wallet?
Does this clarify something?
sure. but what did you meant earlier by "Check if customer payment method is equal to current PM"?
in general, if the customer already has a saved payment method, then you can directly create the subscription with default_payment_method, there's nothing to "check".
I meant that there will be many subscriptions payments. One of them will be at first time and one will be at second time. I will need to create subscription with argument default_payment_method only on the second purchases, right? Because at first time user does not have default payment method so I won't know which payment method I shoud put in a default_payment_method to reuse it so will need to check before creating every subscription does user has PM and maybe is it equal to the incoming payment, right or I am mistaking?
I'm sorry I'm confused.
when you want to create a subscription, check if the customer has a payment method saved:
- if not, then create the subscription, collect the payment method detail, and the subscription will be active. and every month the customer will be automatically charged.
- if yes, create the subscription with
default_payment_method. and every month the customer will be automatically charged.
Sorry for the confusion. Okay, I will try do that, thank you for guidance