#oleksandr_api
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/1369340925217865820
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- oleksandr_best-practices, 4 hours ago, 20 messages
Hi, cannot reuse a customer payment method (PM) from Apple Pay for subsequent payments without avoiding creating a new payment method in a customer object. Can you help me with it and explain what is wrong?
What I did:
-
Initialize payment for subscription on a React Native using Apple Pay;
-
Create subscription with the following arguments (Node SDK) for stripe.subscriptions.create:
{ customer: subscriptionData.customerId, items: [{ price: newPrice.id }], payment_behavior: 'default_incomplete' as 'default_incomplete', collection_method: 'charge_automatically' as 'charge_automatically', expand: ['latest_invoice.payment_intent'], }
and return client secret to the FE -
Confirm Payment on FE using client secret
-
Make payment method from a first payment a default PM for a customer
-
Initialize second payment for second subscription on FE using Apple Pay
-
Create subscription but this time with
default_payment_methodargument where I pass PM from the first payment -
Do same further steps
Result: customer has 2 same payment methods (different PM id but cards are the same). Why on second payment PM is was not reused?
More details:
Customer cus_SGJxgZGV3IMass
First Subscription sub_1RLnJgCMkkLn6luHlrIha5FK
Payment method: pm_1RLnJlCMkkLn6luHNO7K1Ito
Second Subscription sub_1RLnLdCMkkLn6luHeaNBpjmS
Payment Method: pm_1RLnLkCMkkLn6luHePMkTIzJ
HI! Sorry for the delay. Looking into this now, but also helping some other folks.
Hi, no problem. I am not rushing 🙂
What's your code for step 3?
Give me 5 minutes please
Sorry for the delay. Actually, there is another person that wrote code for FE and can't connect with him. Is it possible to tell right now is everything done correctly on a backend and can another payment method be added to a customer because frontend confirm something wrong?
I don't entirely understand the question, but if you're instructing Stripe to save payment methods, it's not happening server-side.
Found FE code
const { error, paymentIntent } = await confirmPlatformPayPayment(clientSecret, {
applePay: {
cartItems: [
{
label: '',
amount: ``,
paymentType: "",
},
],
merchantCountryCode: 'some-country-code',
currencyCode: 'some-currency-code',
},
});
That 's one part of it, but wait one.
Sorry, didn't follow you. What else is needed?
Please wait for a moment, I'm looking for information. Sorry, I wasn't clear at all.
Got it. Let me know waht info I should provide to make it more clear
Ok, so at no point in do you (or your FE associate) seem to be requesting that Stripe save the payment method, which ... as one would expect, would result in not saving the payment method. 🙂
Can you provide the example of how to save payment method for future reuse e.g when user will buy next product I would like to reuse payment method from the first payment. As provided in my example, I expect to create subscription with default_payment_method param and do not trigger or cancel creating another payment method for a customer
I think you need to set this: https://docs.stripe.com/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
Should the flow look like this then?
- Create first subscription
- Store payment method in
customer.invoice_setting.default_payment_method - Create second subscription with
payment_setting.save_default_payment_method = "off"
Also, can Stripe automatically create and attach payment methods to a customer after every successful Apple Pay payment and are there ways to explicitly tell Stripe to do not do that?
Hold on.
1 and 2 are correct. 3 is not, and how to handle 3 depends on when & how your customer selects whether they want to reuse an existing payment method, or a different one.
Ohh, yeah
If customer wants to use new payment method (so customer choses in Apple Pay another card), what I need to do then? As far as I know, every apple payment has unique payment method so it it impossible to tell which card customer chooses
I think you and your front-end person need to get together and get a good understanding of how Subscriptions work and decide what needs to be handled where, as there are some options.
I've written it few times but still didn't get why second payment method is created despite I explicitly tell Stripe to use customer default payment method in subscription create API. Can you tell what needs to be done generally if let's say I want to reuse payment method for subsequent subscription payments and do not create a new PM for a customer?
You don't do that.
Can you show me a Request ID that shows you telling Stripe to use the Customer default payment method?
Sure, 1 sec
Here is req_jwzBOV1wzrOZHE
Here you can see how I reproduced the error from the begining to the end
Customer cus_SGJxgZGV3IMass
First Subscription sub_1RLnJgCMkkLn6luHlrIha5FK (req_ovLowtW0wx5xww)
Payment method: pm_1RLnJlCMkkLn6luHNO7K1Ito
Second Subscription sub_1RLnLdCMkkLn6luHeaNBpjmS (req_jwzBOV1wzrOZHE)
Payment Method: pm_1RLnLkCMkkLn6luHePMkTIzJ
You are setting the Subscription's default payment method, not the Customer's default payment method for Invoices. You need to update the Customer object with the Payment Method once you get it.
Actually I did it after the first payment. When subscription was created I sent client secret to FE, FE confirmed the payment and then sent to the backend payment method where PM was stored in a customer.invoice_settings.default_payment_method by using stripe SDK
Can you share that request, and then a request after that where you try to create a Subscription and use the Customer's default, and it fails?
Sure, let me share all request that I did
- Created customer -- req_gvLT3yJe4Q7UuS
- Prepared price for subscription (here I already have a stripe product) -- req_x0ZhOnsMB1VEhK
- Created first subscription -- req_ovLowtW0wx5xww)
- Not sure waht it is. Guess request for detokenising apple pay card -- req_I5kMtAsB3i46C7
- Payment methods -- req_eA3F3pQmJYfFup
- Created payment intent -- req_ETiO19W2wvoLDF
- Updated customer default payment method -- req_EjuFAMkILDI30A
Second payment
- Created seconds subscription req_jwzBOV1wzrOZHE
- Detokenizing -- req_AUiszl2d3sYu5H
- POST Payment methods -- req_XE3KH9NIBCpPaq
11.Creating payment intent -- req_YByfYJDjXOyL5R
I noticed that there are 2 POST payment methods requests. Why they are triggered?
In 8 you don't need to set the Subscription's default payment method unless it's different than the Customer's s invoice default payment method. You also don't want payment_behavior set to "default_incomplete", you want it set to "allow_incomplete". https://docs.stripe.com/api/subscriptions/create#create_subscription-payment_behavior
- and 10. should not happen; the front end code is doing that because somehow you're sending the user there with an 'incomplete' subscription - as you do with new ones - except your front-end doesn't know it's not the same thing as usual, so it gets a new payment method.
Thank you very much for the help. Will try to fix that. Wish you a good rest of you day
You're very welcome - have a great day! 🙂