#sarvesh3742_api

1 messages · Page 1 of 1 (latest)

hearty pikeBOT
#

👋 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/1306577940385107969

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

misty dagger
#

hi there!

calm jay
#

Hi

misty dagger
calm jay
#

$first_payment_intent = PaymentIntent::create([
'amount' => $stripe_amount,
'currency' => CONFIG['stripe']['currencyText'],
'receipt_email' => $agency_email,
'setup_future_usage' => 'off_session',
'payment_method_types' => ['card', 'us_bank_account'],
//'return_url' => $returnUrl,
//'confirm' => true,
'metadata' => [
'invoice_id' => $invoice_id,
'agency_id' => $agency_id,
'company_id' => $company_id,
'amount' => $total_amount,
'customer_name' => $agency_name,
'customer_ip' => $_SERVER['REMOTE_ADDR'],
'user_id' => $user_id,
],
//'return_url' => $returnUrl
]);

#

$saved_payment_method_id = $first_payment_intent->payment_method;
$payment_intents[] = $first_payment_intent->id;

#

// Subsequent PaymentIntents - reusing the saved Payment Method ID
for ($i = 1; $i < count($selected_invoices); $i++) {
$invoice = $selected_invoices[$i];
$invoice_id = $invoice['id'] ?? 0;
$agency_id = $invoice['sa_id'] ?? 0;
$company_id = $invoice['sc_id'] ?? 0;
$agency_email = isset($invoice['agency']->email) ? $invoice['agency']->email : '';
$agency_name = isset($invoice['agency']->name) ? $invoice['agency']->name : '';
$invoice_amount = $invoice['amount'] ?? 0;
$misc_amount = $invoice['misc_amount'] ?? 0;
$total_amount = $invoice_amount + $misc_amount;
$stripe_amount = (int)number_format($total_amount * 100, 2, ',', '');
$payment_intent = PaymentIntent::create([
'amount' => $stripe_amount,
'currency' => CONFIG['stripe']['currencyText'],
'receipt_email' => $agency_email,
'payment_method' => $saved_payment_method_id, // Use the saved Payment Method
'confirm' => true, // Automatically confirm since Payment Method is saved
'metadata' => [
'invoice_id' => $invoice_id,
'agency_id' => $agency_id,
'company_id' => $company_id,
'amount' => $total_amount,
'customer_name' => $agency_name,
'customer_ip' => $_SERVER['REMOTE_ADDR'],
'user_id' => $user_id,
],
]);
// Store each PaymentIntent ID
$payment_intents[] = $payment_intent->id;
}

misty dagger
calm jay
#

what needs to change in this to make it working

misty dagger
#

well, do you get an error when you run that code? can you share it here?

calm jay
#

Fatal error: Uncaught (Status 400) (Request req_4G13RRkfMvDfMD) You cannot confirm this PaymentIntent because it's missing a payment method. You can either update the PaymentIntent with a payment method and then confirm it again, or confirm it again directly with a payment method or ConfirmationToken. thrown in /var/www/gatewaytitleloop/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38

misty dagger
#

I'm confused by your code. are you trying to create two PaymentIntent in a row? one to save the card, and one to reuse the card?

#

when does the user enter their payment information?

calm jay
#

yes, right, with 1st payment intenent I want to capture Card/Bank details and want to use it for other selected invoices at same time using saved payment method

#

there will be multiple invoice payments user will select once and click on Pay Now which you create seperate transaction for each invoice payment but he can enter payment card/bank details only onces to proceed for all selected invoice payments

#

this is a use case

misty dagger
#

so you completely need to change your code:

  1. Create a PaymentIntent with setup_future_usage
  2. Then use the Payment Element to let the user enter their payment information
  3. Then confirm the ¨PaymentIntent
  4. At this point the PaymentIntent has a Payment Method that you can reuse
calm jay
#

ok, let me check it

#

So as per your above steps,

  1. Create a PaymentIntent with setup_future_usage
  2. The I need to load the UI/View page to enter the Card/Bank details to user in UI interface and he will click on Submit
  3. After that payment method will get saved in Stripe and user will redirect to Payment Complete page
  4. On that payment complete page - I need to fetch the saved payment method
    $saved_payment_method_id = $first_payment_intent->payment_method;
    $payment_intents[] = $first_payment_intent->id;
  5. And the create another payment Intent obeject for remaining invoices to pay/charge automatically from saved payment method?