Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong documentation for "Create a setup intent" #71

Open
atomos1 opened this issue Apr 28, 2021 · 2 comments
Open

Wrong documentation for "Create a setup intent" #71

atomos1 opened this issue Apr 28, 2021 · 2 comments

Comments

@atomos1
Copy link

atomos1 commented Apr 28, 2021

In this part of the doc "Create a setup intent"

the provided example code I think is wrong and refer to payment methods.

@brunogaspar
Copy link
Member

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!

@atomos1
Copy link
Author

atomos1 commented Apr 28, 2021

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?

  1. When user go to checkout page I create a paymentIntent
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

  1. When the user click on PAY (and if needed provide SCA auth) the charge is immediately taken and the payment got to "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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants