#sarvesh3742_api

1 messages ยท Page 1 of 1 (latest)

chrome spadeBOT
#

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

gusty jacinth
#

Sure, what specifically can I help with?

magic sinew
#

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?

gusty jacinth
#

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

magic sinew
#

we want to create payment_intent object and handle payment with API calls

gusty jacinth
#

But you can't confirm multiple intents in bulk, you'd need to do them one by one

magic sinew
#

so do we need do with loops internally and send single, single request with card / bank details filled by user?

gusty jacinth
#

Yes

magic sinew
#

or any other way or API we can use for this bulk payment?

gusty jacinth
#

But like I said that assuming there's a invoice_settings[default_payment_method] set on the Customer that we'd attempt to charge

magic sinew
#

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?

gusty jacinth
#

Why are you creating a Payment Intent if you have a Stripe Invoice?

magic sinew
#

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

gusty jacinth
#

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?

magic sinew
#

Yes, we have a form with payment methods to select and input it

gusty jacinth
#

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

Learn how to save payment details during a payment.

Learn how to charge an existing payment method while a customer is on-session.

chrome spadeBOT
river harbor
#

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

magic sinew
#

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?

river harbor
magic sinew
#

no

#

but montly invoices based on software use

river harbor
#

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

magic sinew
#

'setup_future_usage' => 'off_session' are you talking about this?

river harbor
#

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

magic sinew
#

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?

river harbor
#

that seems correct

magic sinew
#

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

river harbor
#

yes that's correct

magic sinew
#

good, thanks, I will check this approach in details and try to impleement it