Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

asad98iftikhar's avatar

POST https://api.stripe.com/v1/tokens 402

This is mine PlanBlade.php

    Stripe.setPublishableKey("{{ config('services.stripe.key') }}");

    $(function() {
        var $form = $('#payment-form');
        $form.submit(function(event) {
            // Disable the submit button to prevent repeated clicks:
            $form.find('.submit').prop('disabled', true);

            // Request a token from Stripe:
            Stripe.card.createToken($form, stripeResponseHandler);

            // Prevent the form from being submitted:
            return false;
        });
    });

    function stripeResponseHandler(status, response) {
        // Grab the form:
        var $form = $('#payment-form');

        if (response.error) { // Problem!

            // Show the errors on the form:
            $form.find('.payment-errors').text(response.error.message);
            $form.find('.submit').prop('disabled', false); // Re-enable submission

        } else { // Token was created!

            // Get the token ID:
            var token = response.id;

            // Insert the token ID into the form so it gets submitted to the server:
            $form.append($('<input type="hidden" name="stripeToken">').val(token));

            // Submit the form:
            $form.get(0).submit();
        }
    };
</script>

@endsection

0 likes
11 replies
Cronix's avatar

Please Help me with this i will really appreciate it I am trying to solve it for past 5 days

Solve what? You didn't ask a question or state what's not working.

arthvrian's avatar
Level 2

according to the docs https://stripe.com/docs/api/errors

402 - Request Failed The parameters were valid but the request failed.

can you post all the response?

Solve what? You didn't ask a question or state what's not working.

@Cronix, you must figure it out :P

Cronix's avatar

Which token? CSRF? Do you have a callback setup in stripe? What is the url of the callback? Is that url excluded from the csrf_token?

arthvrian's avatar

@asad98iftikhar that is the response?

docs examples says must be like:

{
  error: {
    type: "card_error", // Type of error
    code: "invalid_expiry_year", // Optional identifier of specific error
    message: "Your card's expiration year is invalid.", // Description of the error
    param: "exp_year" // Optional identifier of the offending parameter
  }
}

also, as I can see ** Stripe.card.createToken($form, stripeResponseHandler);** is deprecated too https://stripe.com/docs/stripe-js/v2

Cronix's avatar

@arthvrian According to the title of the post, it looks like he's actually using v1 of Stripe (don't know why they'd use such an old version).

Please or to participate in this conversation.