#Gesundheit-card-setup
1 messages · Page 1 of 1 (latest)
Hello again
Was about to say the same thing!
Glad that you joined me again, then I wouldn't have to repeat the question again haha
Basically we're following the steps as presented here to allow customers to purchase a subscription:
https://stripe.com/docs/billing/subscriptions/elements#collect-payment
Note that this only applies to invoices/subscriptions, not one-time payment intents
you need to always provide an explicit payment method for one time payments
by this do you mean we would always have to collect the card every time for one-time payments?
You can use it for both, just collecting it once
One moment let me look through that doc again
Thanks! Yeah. I'm not sure if the method described in the doc saves the payment method to the subscription or to the user.
If you would allow me, let me describe the use case we're trying to achieve here
It does not, you can modify the webhook the doc has for invoice.payment_succeeded to accomplish that though
Yes please, that will be very helpful
Cool! So basically when a new customer without a card on file decides to purchase something (whether it's recurring (i.e. subscription) or not)
- The user provides their card
- We save their card
- We use that card to pay for their purchase
Later on, when the customer wants to purchase something else, we use the card-on-file to make that purchase.
When the billing period of a subscription renews, we automatically use that card to pay as well.
The user should always have one and only one card on file. They should be able to modify / delete their card as well.
Hopefully that's specific enough lol
So yeah, judging by the use case, I would imagine that I have to set and use customer.invoice_settings.default_payment_method every time
Correct, so for that flow you can do the same steps as in that tutorial up until step 8 https://stripe.com/docs/billing/subscriptions/elements#default-payment-method
Which I am sure you knew just typing it out
So in the invoice.payment_succeeded event, instead of modifying the subscription, you will want to attach the PaymentMethod to the customer https://stripe.com/docs/api/payment_methods/attach
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And then set it as their invoice_settings.default_payment_method https://stripe.com/docs/api/customers/update
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
We don't have a built in way to limit them to one PaymentMethod so you will likely want to do your own logic to list their PaymentMethods and delete an attached one if it exists https://stripe.com/docs/api/payment_methods/list
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
// Set the default payment method
var options = new SubscriptionUpdateOptions <--- new CustomerUpdateOptions() instead?
{
DefaultPaymentMethod = paymentIntent.PaymentMethodId, <--- something something default payment method update instead
};
var subscriptionService = new SubscriptionService();
subscriptionService.Update(invoice.SubscriptionId, options);
something along the lines as above perhaps?
can't i just access and modify invoice_settings.default_payment_method every time instead of going through the whole list?
That's thinking like an engineer! Yeah that would make sense to just check if the default payment method has been set, let me look at modifying that object though
And yes that code would work, just keep in mind calling the Attach method first, you need to attach a PaymentMethod to be able to set it as the default
On second thought I feel like you're absolutely right on that one. I imagine that attaching a payment method just adds a payment method to the list, query-able through the List Payment Methods API.
Of course, it's not going to cause a lot of problems since I will only be accessing the default_payment_method property anyway; but as time goes on a customer may have changed a dozen of different cards and that will leave the list growing without notice.
Just speculation haha, dunno if i'm right
I guess for the sake of housekeeping it's better to keep that list limited to one?
If that is the behavior that you want then yes. You could make either work to keep the customer having only one card
For example checking if the default is null or not, if it is not detach the card, then attach and default the new one
And just to make sure we are on the page with some terminology, when you say "access and modify invoice_settings.default_payment_method", that is something you can do on that field on the customer but the actual PaymentMethod object it refers to would need to be detached to remove it. It can't be modified to refer to a new card as far as I am aware
Of course, and you know where to go with any questions!
thanks!