#johann-muller_invoice

1 messages ยท Page 1 of 1 (latest)

toxic impBOT
#

๐Ÿ‘‹ 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.

hazy tartan
#

Hi, let me help you with this.

analog iris
#

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.

hazy tartan
analog iris
#

req_omYkUbZEiObpam

#

req_oxMsRunYWf56No

toxic impBOT
white cedar
#

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 generated payment_intent from your invoice creation and then use confirmCardPayment and then you can pass the pm_xxx ID

analog iris
#

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?

white cedar
analog iris
#

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 :

  1. get the client from stripe
  2. if saved card the retrieve payment_method, else if new card then attach payment_method to client
  3. process one-time items via create invoice items
  4. check if there is a subscription and if so create the schedule (subscriptions have multi phases for us) - this invoices everything perfect
  5. 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:

  1. create all the invoice items,
  2. then create the invoice but without a payment method
  3. get the payment_intent from the invoice and send that back to the frontend
  4. do confirm card payment
white cedar
#

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

analog iris
#

Thanks - let me give it a bash ๐Ÿ™‚

white cedar
#

You didn't do that for the other

analog iris
#

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

white cedar
#

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

toxic impBOT
analog iris
#

Ok - still trying to wrap my head around this....

livid epoch
#

Hey, taking over here. Let me know if there's any follow-up Qs I can answer!

analog iris
#

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?

livid epoch
#

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

analog iris
#

where do I get the "invoice's payment_intent" - that's the big question now ๐Ÿ™‚

toxic impBOT
livid epoch
toxic impBOT
#

johann-muller_invoice

sturdy echo
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

toxic impBOT
analog iris
#

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 ๐Ÿ™‚

sturdy echo
#

did you finalize it?

#

you can see the PaymentIntent once you finalize the invoice

analog iris
#

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

sturdy echo
#

taking a look

#

you need to pass a payment method when using /pay

analog iris
#

nope had to add 'payment_settings' => ['payment_method_types' => ['card', 'ideal']], to the create invoice

sturdy echo
#

otherwise you need to finalize in the backend and pass it to your frontend to collect the payment method details

analog iris
#

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

prisma lion
#

hi! I'm taking over this thread.

analog iris
#

๐Ÿ™

prisma lion
#

the request you just shared is successful. what exactly is the issue with it?

toxic impBOT
analog iris
#

I think there has been a few different request so depending which one you looking at ?

prisma lion
#

I checked the latest one you shared: req_EYvWQ6CAEONZgX

analog iris
#

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:

  1. Create invoice items
  2. Create invoice including all outstanding (non subscription) invoice items
  3. Collect payment using a NEW card the client entered on the client side and validated with CardElement

This is the question ๐Ÿ™‚

prisma lion
#

thanks for sharing the context! however I don't see any questions, so what's the issue exactly?

analog iris
#

I have a meeting now - will get back to this. Seems we going in a circle ๐Ÿ™‚

toxic impBOT
analog iris
#

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??

plucky bough
#

hey there, stepping in for my teammate here and have read the background chat above

analog iris
#

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 ๐Ÿ™‚

plucky bough
#

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

analog iris
#

Let me check it out - wow tried lots of stuff apart from this one ๐Ÿ™‚

plucky bough
#

Draft invoices don't have a payment intent yet, so you'd never be able to get that

analog iris
#

so flow:

  1. create invoice items
  2. create invoice (send_invoice, pending include etc)
  3. invoice retrieve expand
#

or is there something else between 2 and 3

#

trying in shell now

plucky bough
#

2.5: finalize invoice

analog iris
#

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!!

plucky bough
#

Great! glad we were able to help ๐ŸŽ‰