Open atomos1 opened 3 years ago
upps, you're right, my bad 😅
Are you up to send a pull request to revise that? If not, i'll take a look a bit later!
Thanks!
Hi Bruno, I'm really newbie and learning right now about git and laravel.
If you tell me where to look to to this I will for sure help you. (also other examples have the same problem).
Bye the way just an help from you... is this flow correct?
public function checkout(){
$customer = Stripe::customers()->create([
'email' => 'john@doe.com',
'name' => 'John Doe',
]);
$payIntent = Stripe::paymentIntents()->create([
'amount' => 2000,
'currency' => 'eur',
'customer' => $customer['id'],
]);
return view('checkout', compact('payIntent','customer'));
}
With this form
<form action="{{ route('pay') }}" method="POST" id="payment-form">
...
With this js
$('#payment-button').on('click', function() {
$('#payment-button').attr('disabled', true);
stripe
.confirmCardPayment('{{$payIntent['client_secret']}}', {
payment_method: {
card: cardElement,
},
})
.then(function(result) {
if (result.error) {
$('#card-error').text(result.error.message).removeClass('d-none');
$('#payment-button').attr('disabled', false);
} else {
$('#payment-method').val(result.paymentIntent.payment_method);
$('#payment-form').submit();
}
});
})
In Stripe when the user visit /checkout
page a payment intent is created on status requires_payment_method
"status": "succeeded"
Is this correct? Can be done in a better way?
I thought the intent should be confirmed after pay click with something like this...
public function pay(Request $request){
$paymentMethodID = $request->input('payment_method');
$payment_intentID = $request->input('payment_intent');
$paymentIntent = Stripe::paymentIntents()->find($payment_intentID);
Stripe::paymentIntents()->update($paymentIntent['id'], [
'payment_method' => $paymentMethodID,
]);
Stripe::paymentIntents()->confirm($paymentIntent['id']);
// return thank you page
}
But i can see that this is enough, why I don't have to confirm in the controller?
public function pay(Request $request){
// return thank you page
}
Routes
Route::get('/checkout', 'PaymentController@checkout')->name('checkout');
Route::post('/pay', 'PaymentController@pay')->name('pay');
In this part of the doc "Create a setup intent"
the provided example code I think is wrong and refer to payment methods.