#asommer12 - Connect
1 messages ยท Page 1 of 1 (latest)
Hey Rubeus
I'll give you some context and then ask you two specific questions
I build billing software. On an arbitrary cadence, my company determines how much our customers ought to charge their customers. We generate invoice printouts, and then my customers manually create invoices on Stripe to charge their customers. Make sense?
My customers have asked me to automate the final part, so that I can charge their customers directly when that all happens
Stripe Connect seems like the right way to do this
So
- I'm looking at the Invoicing with Connect docs (https://stripe.com/docs/invoicing/connect#direct). In the dashboard, I am able to manually create one-off invoices. But I don't see anywhere in the documentation about how to create a one-off invoice programmatically. I'd need to define the
line_itemsandamounts. Is there a way to do that?
That's the most important question, but I'll start typing out my follow-up too
To create an Invoice with the API you first create Invoice Items associated with the Customer to represent what you want to charge the Customer for: https://stripe.com/docs/api/invoiceitems/create
Next you create an Invoice, which will sweep up the pending Invoice Items on the Customer: https://stripe.com/docs/api/invoices/create
For Connect, with those Invoices living on the connected Standard accounts, you would make the API calls with the Stripe-Account header as documented here: https://stripe.com/docs/connect/authentication
Okay amazing. So if I have 4 line_items, I'd need to make 5 consecutive calls to Stripe -- 1 to create each line item, and then 1 to sweep them all up into an invoice? Is that the idea?
Yep!
Okay cool
Are you working for the next 45+ minutes?
I might hold off on my second question for a moment (which was a fallback plan) and try this first
Can I ping back here in 15-20 with follow ups please?
Yep, I'll be here for a while longer.
great, brb
thank you
okay beautiful
that worked
two follow-ups to that
- I see in my Stripe Dashboard that an invoice was created, but I don't see the pending invoice on the customer's account. Is that because it takes an hour for the Invoice to show up there? It will show up soon?
Yeah, new Invoices start in draft status. I recommend you read through this, which covers the Invoice lifecycle: https://stripe.com/docs/invoicing/overview
You may also be interested in finalizing the Invoice manually via the API: https://stripe.com/docs/api/invoices/finalize
- I see that there are options for "automatically process invoice with payment on-file" versus "send invoice to customer." If the customer has a payment method on-file, great, then the invoice will process automatically. If the customer does not have a payment method on file, will the invoice FAIL? Or fall back to sending the customer an email?
I believe the Invoice will fail, but you should test it to make sure you understand exactly what will happen.
and then finally
- If I do not finalize the Invoice manually (if I let Stripe run its normal course), will the invoice eventually be sent to the customer? Or is "send invoice" something I need to manually trigger too?
If the Invoice is set to send_invoice Stripe will send it for you when the time comes, you don't need to explicitly trigger it (although you can using the API if you want).
Also note that Stripe does not send emails in test mode.
Happy to help!
Okay, one more alternate flavor of questions
Let's say I wanted to use Charges instead of Invoices
I would use a PaymentIntent
I built that out, and I was running a few tests, and I'm seeing some strange behavior perhaps you can help me with:
I created a PaymentIntent on a ConnectedAccount's Customer. The API succeeded, and I see it in the Dashboard
But I also see "Incomplete, The customer has not entered their payment method."
However, the Customer DOES have a Payment Method on file
Could you perhaps help me understand what might be going on here?
Can you give me the Payment Intent ID so I can take a look?
pi_3KWUMwRStBrARgKU0BrJRez1
You'll see several attempts there. I created a few which failed, then I added a Payment Method manually, and then I tried again (the most recent). But It doesn't seem to be finding the Visa ending in 1111
(a Test card)
Looking...
no rush, thank you
In this request you only created the Payment Intent, but you didn't specify a Payment Method, nor did you confirm the Payment Intent: https://dashboard.stripe.com/test/logs/req_ahSBIdXWQJ9uxm
Okay
Payment Intents require you to specify a specific Payment Method, there's no such thing as a default Payment Method on a Customer for a Payment Intent.
so the payment method I'd like to default to payment-on-file -- is that not the default behavior?
Ohhhhhhhh
Okay that's good to know
You can specify one associated with the Customer, but you still have to specify it.
I see
And with Invoices that's not the case, correct? With invoices, if I set charge_automatically then it will use a default payment method on file, right?
For confirmation, that should ideally happen client-side while the Customer is on-session so they can handle any async steps, like 3D Secure or an async payment flow for non-card payments.
Right, there is no client-side interaction for my use-case
This is recurring billing that happens offline
Ah, okay, then you need to specify both off_session: true and confirm: true when making the API call.
Okay and if I do that, I **also ** still need to provide the payment_method ID right?
No problem!
This is super helpful
Let's leave this channel open for a few mins longer if you don't mind
Are these payments US and/or Canada only?
Not necessarily
Okay, so in order to minimize the chances authentication will be required for these off-session payments you need to make sure you're setting up the Payment Methods for future use. Are you doing that with a Setup Intent or anything like that now? Basically I'm asking how you're creating the Payment Methods in the first place?
Great question
I am not handling that part as the Platform
I am expecting my Connected Account to set that up
Is that abnormal?
No, that's not abnormal.
Just watch out for connected accounts not doing that properly and be prepared to answer their questions about higher-than-expected declines. ๐
And in that case, I would need to instruct my ConnectedAccount that they need to set up cards with off-session
right
Sounds like Invoicing might be cleaner for this use-case, right?
If you're using existing Payment Methods this applies to both Payment Intents and Invoices.
Invoices generate Payment Intents under the hood.
Payment Intents are a lower-level object in Stripe that allow you to charge a specific amount. Invoices are an abstraction built on top of Payment Intents to add functionality like line items and whatnot.
Right
So whichever route I choose, I will need to instruct my ConnectedAccounts to ensure that the PaymentMethods they collect are setup for off-session use
Yep. The guide for doing this without taking a payment is here: https://stripe.com/docs/payments/save-and-reuse
OR, I need to specify send_invoice on the invoice to avoid this risk
The guide for doing it while taking a payment is here: https://stripe.com/docs/payments/save-during-payment
Yeah, sending the Invoice to the Customer will result in them being on-session when they pay and, thus, present to handle authentication or async flows.
If you do the off-session payments you'll need to watch out for declines due to authentication being required and in those cases bring the Customer online to try again while on-session.
My future optimizations would include using charge_automatically but only after I can ensure that my ConnectedAccounts set up their payment methods properly with off-session
Thanks so much @buoyant fiber
Wait, one more question haha
This one is probably more simple
I have an invoice with 3 line items
I make 4 calls to Stripe:
- create item
- create item
- create item
- create Invoice
let's say the second call fails
When I try to re-create the invoice, how do I ensure that there aren't duplicates of the first line item in the resulting invoice?
Is there a good method for idempotency on the line items?
(Looking at docs as I type)
My recommendation would be to structure your code such that any failed call is retried until it succeeds. You can also specify an existing draft Invoice when creating a line item if you want to add one to an existing draft Invoice: https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-invoice
You may be interested in the automatic network retries functionality built-in to our client libraries: https://stripe.com/docs/error-handling#network-errors
You can enable that, then perform a check after the Invoice is created to confirm everything looks good, then add missing items as needed to cover all your bases.
stripe.setMaxNetworkRetries(2);
This applies only for GET requests or POST too?
It applies to all requests.
@river prism Hello! I'm about to end my shift and was wondering if you had any remaining questions?