samedi 30 novembre 2019

Laravel Cashier 10 - Stripe payment element empty

I am trying to show a Stripe payment element, but it's not showing.

Using dd() statements, I can tell that the user PaymentMethods is empty (as expected for a new user) and the Intent is not null.

show() method in PlanController.php:

    public function show(Plan $plan, Request $request)
    {
        $user = $request->user();
        $user->createOrGetStripeCustomer();
        $paymentMethods = $user->paymentMethods();
        $intent = $user->createSetupIntent();
        return view('plans.show', compact('plan', 'intent'));
    }

Javascript, truncated because SO won't let me post it all:

<script src="https://js.stripe.com/v3/"></script>
    ...
    // Submit the form with the token ID.
    function stripeTokenHandler(paymentMethod) {
        // Insert the token ID into the form so it gets submitted to the server
        var form = document.getElementById('payment-form');
        var hiddenInput = document.createElement('input');
        hiddenInput.setAttribute('type', 'hidden');
        hiddenInput.setAttribute('name', 'paymentMethod');
        hiddenInput.setAttribute('value', paymentMethod);
        form.appendChild(hiddenInput);

        // Submit the form
        form.submit();
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire