#Mr Stinky Pants
1 messages · Page 1 of 1 (latest)
Hi there
There are a couple ways to do this
But I would recommend using a SetupIntent to ensure the card is set up and attached to the Customer
well ill tell you what ive done so far
customer = customerResult.Data[0];
subscription = customer.Subscriptions.First();
InvoiceService invoiceService = new InvoiceService();
invoice = invoiceService.Get(subscription.LatestInvoiceId);
PaymentIntentService paymentIntentService = new PaymentIntentService();
paymentIntent = paymentIntentService.Get(invoice.PaymentIntentId);
Then you can update the Sub's or Customer's default with that Card
well this is if the card has failed
so i assume there will always be a payment to take anyway?
Oh okay if the card fails then yes you want to grab the latest_invoice.payment_intent.client_secret and pass that to your frontend, and then confirm the PaymentIntent using the new card details.
but thinking about it you might be right
because a customer might want to update card with no due invoice
You can use expansion so you only need one API call here to retrieve the Sub: https://stripe.com/docs/api/expanding_objects
Yeah you likely want a different flow for updating a card outside the billing cycle
well i did try to extend it actual but it said it wasnt valid
customerSearchOptions.AddExpand("data.subscriptions.data.paymentIntent");
whats up with that
oh because there latest invoice
yes i also tried this but that doesnt work
InvoiceGetOptions invoiceGetOptions = new InvoiceGetOptions();
invoiceGetOptions.AddExpand("paymentIntent");
InvoiceService invoiceService = new InvoiceService();
invoice = invoiceService.Get(subscription.LatestInvoiceId, invoiceGetOptions);
Let's back up a second.
What are you using to determine a failed payment?
Are you using Webhooks?
Is this only for Sub-creation?
no i havent done that bit so far
Or are you focused on handling renewals as well?
this is when card fails on the old global payments
to move to stripe
oh sorry i did that bit
this is just assuming i get an email from stripe a payment fails?
i would send a user to this page
i would link it with a webhook later
so what will it make with setup intent
a new payment method?
Yes, but you don't really want to use a SetupIntent if you are going to charge that PaymentMethod immediately.
For the above, you look like you are attempting to list Invoices for a Sub.
no ill do what you say for now
I wouldn't go that route
If you have the Sub ID already then you can just retrieve the Sub: https://stripe.com/docs/api/subscriptions/retrieve?lang=dotnet
And then you can expand using subscription.LatestInvoiceId
ill just update the card and ill manually apply that in the dashboard for a start?
then i can take payment for any due invoices
in the dashboard
i can automate that later
or i guess i can apply the payment method to the sub in webhook
I would not recommend using the Dashboard to update cards. This brings you into a higher PCI scope because you will have to handle card details.
Would really recommend just putting a full integration together here, or using the Customer Portal instead for this customer management
yes i dont mean update the card
i mean using elements
so is setup intent making a new payment method?
Gotcha, then yeah. You create a SetupIntent on your Server, pass the client-secret to frontend, render Payment Element, and use confirmSetup()
That will create a new PaymentMethod and attach it to the Customer (assuming you passed a Customer ID when creating the SetupIntent)
yes so then ill have 2 payment methods?
Yep
i guess ill have to remove any others first?
Up to you whether to remove or not. But you mostly want to just update the Customer's invoice_settings.default_payment_method with the new PaymentMethod
So that it is used for all of their Subs going forward
so what event would i listen for?
In terms of...?
i guess i need a webhook to know when the setupintent is done
Gotcha, yeah a Webhook is the safest here. You can also just use the callback from confirmSetup but it is always possible that the customer navigates away before that callback completes so we do recommend Webhooks. You would use setup_intent.succeeded in this case.
That will fire anytime you confirm a SetupIntent successfully
its saying No such payment_intent: 'seti_1M46GsJKY8YXH2zhPjg0lv69'
What is?
Are you using confirmSetup()?
And that isn't a client-secret, that is a SetupIntent ID.