#sarvesh3742_api
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/1306221742011715634
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Sure, what specifically can I help with?
We have list of invoices and user will select all or few of them and click on Pay button, I need to show a summary of all selected invoices and want to pay bulk invoices with Pay by Card and Pay by Bank options. How to do tihs?
There's no native API to bulk pay invoices I'm afraid. Most basic way assuming you have payment method details for each would be to call the /pay endpoint for each
we want to create payment_intent object and handle payment with API calls
Well assuming each invoice is finalized there will be a Payment Intent automatically generated for each, on the payment_intent field: https://docs.stripe.com/api/invoices/object#invoice_object-payment_intent
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
But you can't confirm multiple intents in bulk, you'd need to do them one by one
so do we need do with loops internally and send single, single request with card / bank details filled by user?
Yes
or any other way or API we can use for this bulk payment?
I just told you
But like I said that assuming there's a invoice_settings[default_payment_method] set on the Customer that we'd attempt to charge
for single invoice payment we are creating the object like below
$payment_intent = PaymentIntent::create([
'amount' => $stripe_amount,
'currency' => CONFIG['stripe']['currencyText'],
'receipt_email' => $agency->email,
'payment_method_types' => ['card', 'us_bank_account'],
'metadata' => [
'invoice_id' => $invoice_id,
'agency_id' => $agency->id,
'company_id' => $agency->sc_id,
'amount' => $total_amount,
'customer_name' => $agency->name,
'customer_ip' => $_SERVER['REMOTE_ADDR'],
'user_id' => $user_id,
],
]);
So can we do this in Loop for bulk inovices for payment? is it possible?
Why are you creating a Payment Intent if you have a Stripe Invoice?
Are you using Stripe Invoices? https://docs.stripe.com/api/invoices
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
No, we are internally creating invoices and payments will be done by user through Stripe and we are processing it at our end and updateing from webhook events
OK, then you should be more explicit about that earlier on
Do you have payment method details for this customer before they click 'pay'? Or do you need to also collect them?
Yes, we have a form with payment methods to select and input it
OK, then my recommendation would be that you collect payment details during the initial payment for one of those invoices and save the details during payment (this guide: https://docs.stripe.com/payments/save-during-payment?platform=web&ui=elements)
Once that initial payment succeeds, you can then create and confirm the other invoice payments using the existing payment details you just saved. See: https://docs.stripe.com/payments/existing-customers?platform=web&ui=direct-api
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
ok, so from 1st link, we need to add 7th point - Charge the saved payment method later and create another payment intenents dynamically to pay for remaining invoices?
this saved payment method will be used only for active session or for next months payment also?
are you creating a subscription?
if you've saved the PM to be used for off_session payments then it should be ok, you just need to pass off_session: true
'setup_future_usage' => 'off_session' are you talking about this?
this is in the first PI you create to save the PM for future usage
for subsequent payments you need to use off_session: true since the customer isn't on session
and this is what we call an MIT: merchant initiated transaction
i see, ok so for first invoice, we need to create Stripe PI object with 'setup_future_usage': 'off_session' and then Stripe will save the payment method on Stripe side and we need to retrive that and create another invoice PI obects in loop with
off_session: true
is this correct or I missed anything?
that seems correct
ok, So on stripe side each invoice PI will get created separately and we will receive webhook events for each invoice separately right? SO we can validate each invoice id and update them to our database
yes that's correct
good, thanks, I will check this approach in details and try to impleement it