#milad-rahimi_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1261048010612408472
๐ Have more to share? Add 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.
- milad-rahimi_best-practices, 5 hours ago, 6 messages
- milad-rahimi_api, 1 day ago, 11 messages
Hi there ๐ a Checkout Session running in setup mode does sound like what you're after, but you don't use the payment_intent_data hash you referenced, as a setup mode Checkout Session doesn't generate a Payment Intent.
Our guide for creating and surfacing a Checkout Session that sets up a payment method for future usage can be found here:
https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=stripe-hosted
Then this guide walks through how to create an Invoice using our API:
https://docs.stripe.com/invoicing/integration
If you want that Invoie to automatically process a payment, instead of sending the Invoice to the customer to be paid, then there are couple changes you'll need to make.
In step 5 when you're creating the Invoice, you'll want to change the collection_method to charge_automatically. To facilitate that you, you'll also need to set a default payment method on the Customer, so we know what payment method to charge.
To do that, you make a request to update the Customer object, and pass the desired Payment Method ID to invoice_settings.default_payment_method
https://docs.stripe.com/api/customers/update#update_customer-invoice_settings-default_payment_method
Hi, I read that doc but I have some questions, can I make sure checkout session stores a payment method with direct debit? and can I use that multiple times? How can I make user update the their payment method if last invoice/charge failed?
can I make sure checkout session stores a payment method with direct debit?
Can you elaborate on this part. Is "direct debit" referring to a particular Payment Method type here?
and can I use that multiple times?
Yes
How can I make user update the their payment method if last invoice/charge failed?
There are several options here. You can use another Checkout Session insetupmode to collect new Payment Method details from your customer, and update their default Payment Method setting.
You could also give them access to the Customer Portal for maintaining that.
No I just make sure I can charge user, of course I know it's impossible to make sure 100%, but at least make sure user entered a card or other method which is chargable in future
Regarding to invoices I change collection_method to charge_automatically. but In test mode it didn't charge the customer card (successful fake card) and pay the invoice autoamtically as expected
It keeps invoice open until I pay it manually with invoice link
Can you share the ID of an Invoice from your testing where you saw that behavior?
That ID should have an in_ prefix.
Taking a look (I'm juggling multiple threads simultaneously)
one useful point is that I didn't specified payment method explicitly, as it documented that if not provided it use default payment method and it's what i want too.
Ah, you're manually finalizing the Invoices, in that case you also have to manually trigger the payment for the Invoice. Or you can wait for about an hour to pass for the payment to happen automatically since auto_advance is on.
what's best practice, shouldn't I finalize invoice, if i just create it and add items would it be paid?
i want to generate invoices monthly for user based on their usage, so each invoice will only have one item
Immediately finalizing the Invoice is fine, but if you do that the automatic payment still doesn't happen until about an hour after the Invoice was first created. You'll have to manually trigger the payment if you want it to happen sooner than that.
which api should i use to trigger payment? that actually would be great to understand immediately if it's successful or not
This one here:
https://docs.stripe.com/api/invoices/pay
You can also explicitly specify the payment method you want to use via the payment_method parameter, if you don't want to use the customer's default.
great thank you
Any time!