#johann-muller_invoice
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/1252543590572490833
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
Hi, let me help you with this.
When the client des have a "saved payment method" and they buy only a one-time product (so no subscription) this works perfect as well - i.e. invoiceItems->create followed by invoices->create. But there is cases where the client want's to use a different credit card for one time purchases and they don't want to save the card.
Could you please share the error Request ID req_xxx? https://support.stripe.com/questions/finding-the-id-for-an-api-request
How do we do this without an attached payment method - so one time card use please?
Hmm. I'm not sure if you can. You could try and retrieve the generatedpayment_intentfrom your invoice creation and then useconfirmCardPaymentand then you can pass thepm_xxxID
Thanks ynnoj - so current the only front-end work is getting the pm_xxxx - after that 100% of the work is on the backend PHP. What you're saying is I have to do the current backend work, retrieve the payment_intent then pass that back to the frontend and facilitate the confirmCardPayment on the frontend?
To be honest, I'm not sure that'll work. Out of interest, why are you creating the PM this way? https://dashboard.stripe.com/test/logs/req_VbGfPDqUrLgd9i
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
100% of the transactions we will do are from registered clients that have memberships and they typically save their card of iban detail. So the process right now is the add items to the cart and during checkout they can select the "saved payment" method we retrieve when they started the checkout. So once they click "pay" we send the cart items and payment_method ID to the backend and do create subscription schedule and any one of items is added to invoice items before we finalise the subscription schedule. We then listen to webhooks and process their items based on the response. So this works perfect and the only interaction on the frontend is to let them now the transaction was successful or failed.
So the flow for the "saved card" or new card but with the agreement to use in future is :
- get the client from stripe
- if saved card the retrieve payment_method, else if new card then attach payment_method to client
- process one-time items via create invoice items
- check if there is a subscription and if so create the schedule (subscriptions have multi phases for us) - this invoices everything perfect
- if no subscription then fire a create invoice - works perfect because we have an attached payment method
issues is sometimes the client will buy a one off item (so they do not need to save the payment method) and we were thinking the same process would work ๐
So would it be possible to have this flow:
- create all the invoice items,
- then create the invoice but without a payment method
- get the payment_intent from the invoice and send that back to the frontend
- do confirm card payment
Hmm, I'm not 100% sure as the intent will still be tied to cus_xxx and therefore the pm_xxx needs to be associated to them. Try it though
Thanks - let me give it a bash ๐
The crucial difference between those two invoice payments is the on one that succeeded the pm_xxx was attached to the customer (here: https://dashboard.stripe.com/test/logs/req_h4LhFTV7gC7UAL)
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
You didn't do that for the other
So add invoice items followed by create invoice including pending invoice items but without default payment method creates the invoice but it doesn't contain a payment_intent? Guess I need to work 2 totally different flow based on if the client want's to use a saved method vs not
If you're using invoices then the default_payment_method set needs to be saved/set on the customer. How you do that is up to you
Ok - still trying to wrap my head around this....
Hey, taking over here. Let me know if there's any follow-up Qs I can answer!
customer adds 2 products and both one-time purchase. The next step they can select the payment method
So they could select the saved card then we follow the create invoice items and create invoice flow that could also manage subscriptions.
If they select "use new card" I can generate a payment_intent on the backend, and use that on the client side to confirmCardPayment but then the client won't get an invoice from stripe with the 2 lines items?
Yes they won't, you should create an Invoice using Stripe API
and then confirm the invoice's payment_intent using Stripe Element and confirmPayment of Stripe JS
where do I get the "invoice's payment_intent" - that's the big question now ๐
After you create the invoice, you can make a fetch API call and get it from the invoice object:
https://docs.stripe.com/api/invoices/object#invoice_object-payment_intent
johann-muller_invoice
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
Perfect - let me try again - used the shell to test create an invoice and then retrieved it but it had no pi... think my options were wrong - trying again ๐
duh, I'm really stupid - didn't call the invoices-pay after creating it - now got the pi ๐
having some issues
when I try it via the shell it works... here's the successful request req_MXsvKdAc9r06i2
when I try via the api it throws an error saying it needs a payment method request: req_aev3athwwEV4rx
and error with api create invoice req_jV6qpnIijKbWPH
nope had to add 'payment_settings' => ['payment_method_types' => ['card', 'ideal']], to the create invoice
otherwise you need to finalize in the backend and pass it to your frontend to collect the payment method details
No this is getting me - if I do this via the dashboard - works and my invoice has a payment_intent. If I do it via the API 1) create invoice items, create invoice, invoice->pay then payment_intent=null??
created via API req_EYvWQ6CAEONZgX
When I create the invoice and select "send_invoice" as per the popup text "Either charge_automatically, or send_invoice. When charging automatically, Stripe will attempt to pay this invoice using the default source attached to the customer. When sending an invoice, Stripe will email this invoice to the customer with payment instructions. Defaults to charge_automatically." So if you select "send_invoice" it means DO NOT look at the default source but rather "send the invoice" with instructions on how to pay it
hi! I'm taking over this thread.
๐
the request you just shared is successful. what exactly is the issue with it?
I think there has been a few different request so depending which one you looking at ?
I checked the latest one you shared: req_EYvWQ6CAEONZgX
The issue is not the API - I think it's the process more that anything else.
We have a process for subscriptions and one-off purchases that works perfect. It processes all the cart items using a very well structured PHP class that maps through all the items in a cart and either does a add_invoice_item or creates a subscription schedule depending on the type of item. Once all cart items are done the invoice is ready and does a auto-collect from the client's saved payment method. This is a 95% case scenario
The the 5% case scenario is the same customer places a one-time purchase item in their cart and selects a new card to pay with (CardElement) and check NO DON'T SAVE for future use. We call the same backend PHP but this now cannot work because we are not using the clients save payment method and cannot "attach" this card they are using for this payment. The challenge is that we need to provide a detailed stripe invoice so just creating a payment_intent without creating the invoices won't work so we're trying to figure out how to basically do the following:
- Create invoice items
- Create invoice including all outstanding (non subscription) invoice items
- Collect payment using a NEW card the client entered on the client side and validated with CardElement
This is the question ๐
thanks for sharing the context! however I don't see any questions, so what's the issue exactly?
I have a meeting now - will get back to this. Seems we going in a circle ๐
Sorry for the short interruption - meeting done. So I guess we have most of it worked out so the final question is:
Create invoice items, create invoice and then and remember we don't have a SAVED PAYMENT method for this client. So how do we get tht invoice we just created with
$stripe->invoices->create(
[
'customer' => 'cus_QJdvqW9wDZqdBA',
'days_until_due' => 0,
'collection_method' => 'send_invoice',
'pending_invoice_items_behavior' => 'include',
'currency' => 'EUR',
'application_fee_amount' => 25,
],
['stripe_account' => 'xxxxxxxxxxxxxxxxxx']
);
to have the property payment_intent !== null??
hey there, stepping in for my teammate here and have read the background chat above
If we can get the payment_intent for the invoice and pass that back to the client side we can then do the confirmXXXX method from the client side
Thanks ๐
Yes, that sounds like the right approach given your described situation
You'll need to finalize the invoice to get the payment intent created, then you can get it either via expansion or retrieval after that
expand[]=payment_intent on the finalize request should get you the full object
Let me check it out - wow tried lots of stuff apart from this one ๐
Draft invoices don't have a payment intent yet, so you'd never be able to get that
so flow:
- create invoice items
- create invoice (send_invoice, pending include etc)
- invoice retrieve expand
or is there something else between 2 and 3
trying in shell now
2.5: finalize invoice
ok - good point
step 1 - req_qlejSnhoGyQaMB
and step 2 req_qlejSnhoGyQaMB
WOW - magic - works req_5xxuwDvpbedf5u
So now I can retrieve the payment intent object and pass that back to the client for confirm action via stripe-js ๐
I see the client_secret is also in the response from the invoice->finalise - so can skip the retrieve - even better!
Thanks for all the help and as always we would be STUCK if it wasn't for the great help and knowledge!!
Great! glad we were able to help ๐