0

I'm trying to integrate a payment system on my Laravel 6 project.

But I Have no idea how to retrieve the ClientSecret from my serverside

I have this in my CheckOutController

    public function charge(Request $request)
{
    Stripe::setApiKey('sk_test_GEQCwhRyT9PcK1vju3YcsIEN00gXSsjo1P');

    $intent = PaymentIntent::create([
        'amount' => round(Cart::total()),
        'currency' => 'eur',
    ]);

    echo json_encode($intent);
}

And I should retrieve information and work with this (from Stripe documentation)

submitButton.addEventListener('click', function(ev) {
  stripe.confirmCardPayment(clientSecret, {
    payment_method: {
      card: card,
      billing_details: {
       name: 'Jenny Rosen'
      }
    }
  }).then(function(result) {
   if (result.error) {
     // Show error to your customer (e.g., insufficient funds)
      console.log(result.error.message);
    } else {
      // The payment has been processed!
      if (result.paymentIntent.status === 'succeeded') {
        // Show a success message to your customer
        // There's a risk of the customer closing the window before callback
        // execution. Set up a webhook or plugin to listen for the
        // payment_intent.succeeded event that handles any business critical
        // post-payment actions.
      }
   }
  });
});

Thank you for reading me :)

Amit Kumar PRO
  • 1,222
  • 2
  • 15
  • 27
  • ClientSecret is a property on $intent, which is returned from Stripe when you call create payment intent. That is what you need to pass when you call confirmCardPayment. – allan Jan 20 '20 at 23:26

1 Answers1

0

The client secret that you are looking for is returned by Stripe as client_secret.

So you can get that value with:

Arr::get($intent, 'client_secret');

You can have a look at the example response from the docs here: https://stripe.com/docs/api/payment_intents/create

Chin Leung
  • 14,621
  • 3
  • 34
  • 58
  • Hello ! Thank you very much for your response, however I know how to get the client_secret but I don't know the way I'd use to inject it in my JS script :) – Ludovic Guénet Jan 21 '20 at 06:13
  • @LudovicGuénet Aren't you sending a json response of your intent somewhere? You have to decide that json in your JS. – Chin Leung Jan 23 '20 at 12:58