Place a hold on the credit card and charge using Stripe paymentIntent

1.7k Views Asked by At

I want to build the process below

  1. When a client presses the Book button, we need to place a hold on the credit card for the amount of the transaction

I think the hold does not charge the card, ie the money does not leave the card The hold just checks that the money is available and reserves it for a few days

  1. Within these 7 days, I call another API to complete the charge, to cancel the hold, or just let the hold expire.

  2. If a client books an appointment, the money goes on hold and then, after a day or so, he cancels, the hold should be released I checked the Stripe API doc, but I am not sure how to do this process. I think it must to using the paymentIntent API. Please explain to me what process I must do.

             $stripe = new \Stripe\StripeClient(env('STRIPE_SECRET_KEY'));
    
             $getPaymentMethod = $stripe->paymentMethods->all([
                 'customer' => $request->customerId,
                 'type' => 'card',
             ]);
             $createIntent = $stripe->paymentIntents->create([
                 'amount' => $request->price * 100,
                 'currency' => 'usd',
                 'payment_method' => $getPaymentMethod->data[0]->id,
                 'payment_method_types' => [$request->paymentType],
                 'customer' => $request->customerId,
                 'capture_method' => 'manual',
                 'description' => 'The payment of the appointment',
             ]);
    
             $confirmPaymentIntent = $stripe->paymentIntents->confirm(
                 $createIntent->id,
                 ['payment_method' => $getPaymentMethod->data[0]->id]
             );
    
             $captureIntent = $stripe->paymentIntents->retrieve($confirmPaymentIntent->id);
    
             $results = $captureIntent->capture($confirmPaymentIntent->id);
    
             return $results;
    

I tried this code so it is working and the payment capture. But it didn't charge the money on the stripe and the balance is $0.00. I am not sure it is correct and how to do next step for complete. Please help me. what should I?

screenshot

screenshot1

0

There are 0 best solutions below