#b33fb0n3_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/1318972011372085308
๐ 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.
- b33fb0n3_api, 3 hours ago, 8 messages
Hello
What Stripe APIs are you using to create invoices and collect payment from the customers?
The payment method needs to set up for future use before you can charge them for other charges.
I am using the customers api, the invoices api and the invoice items api
My code looks like this: https://paste.gg/p/B33fb0n3/2babbc9a24b34a09b930250c0811b46f
Ah so you're using Invoices API directly. Hmm.. I don't think there's a way to set up the payment method from customer in the flow you currently have.
One option is to alter your flow and switch to an integration that utilizes PaymentElement - https://docs.stripe.com/invoicing/integration?method=elements#accept-invoice-payment
Here you can update setup_future_usage parameter after invoice has been finalized and collect customer's payment method details - which will set up the payment method for future use.
hmm I don't want the users to pay directly thought the website. I don't want to handle any kind of payment integration. I would like to leverage the hosted site from stripe
Gotcha. Let me test something quickly..
Okay so I found a workaround that might work with little bit of tweaking.
In your current flow, after you finalize the invoice - the invoice would generate a PaymentIntent. Once the PaymentIntent gets generated, you can update the Intent and specify which payment method types you want to set up for future use by utilizing following param - https://docs.stripe.com/api/payment_intents/update#update_payment_intent-payment_method_options
the request options would look something like
payment_method_options: {
card: {
setup_future_usage: 'off_session'
}
},
Once you update the PaymentIntent, the hosted invoice page should save and attach the card customer pays with.
You can list the attached payment method using this API - https://docs.stripe.com/api/payment_methods/customer_list
And pass the payment method ID to the next invoice you create using default_payment_method param - https://docs.stripe.com/api/invoices/create#create_invoice-default_payment_method
oh that's smart. I will integrate that directly. Can this thread stay open for about 10 - 15 minutes?
Sure
It looks like it's working! Just to get this right the collection method must also be changed, right?
It should work with either collection methods
I just tried it with both:
charge_automatically: in_1QXQU0GdgFrJRsM6fQqa6z0n
send_invoice: in_1QXQR1GdgFrJRsM6SkcZrq9T
For this customer: cus_RQGk29IZ4ZElAT
However, even if the payment method is attached (and made as default), it won't be fulfilled.
Hello! I'm taking over and catching up...
sure ๐
This is what I done: #1318972011372085308 message
And you can see inside the provided ids, that everything works fine except the automatic collection of the invoice
Can you clarify what you mean by "won't be fulfilled"?
The invoice won't be paid automatically even if there is a default payment method attached to the customer
It should be with charge_automatically as long as you don't turn off auto advance.
So you only finalized Invoice in_1QXQU0GdgFrJRsM6fQqa6z0n and auto advance is disabled on it. Have you tried finalizing it and setting auto_advance to true? https://docs.stripe.com/api/invoices/finalize#finalize_invoice-auto_advance
Or you can explicitly call /pay on it: https://docs.stripe.com/api/invoices/pay
I thought so too, however it still won't be automatically collected. This is the id to the screenshot: in_1QXQU0GdgFrJRsM6fQqa6z0n
Right, but have you tried either of the things I mentioned above?
yes, right now I finalize it:
const finalInvoice = await stripe.invoices.finalizeInvoice(invoice.id);
When auto_advance is by default true, then yes, I am doing this
Inside the docs it's not clear what's the default value
when I am using the pay endpoint, will I directly receive the result if it's was successful or not?
It depends on the payment method. I recommend you try setting auto_advance to true when you finalize and then see what happens first. Then, after that, try /pay and see how that works.
What's the default value of auto_advance?
There is no default, it depends on the state of the underlying Invoice.
ah ok. I just added the pay endpoint call and it worked ๐
Thanks!