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 :)