Redirecting to Stripe

Im not sure if someone can assist here. I am following a basic example at

I have created the HTML and added the code as below including the Javascript as required

<!DOCTYPE html>
<script src="https://js.stripe.com/v3/"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <button onclick="checkout()">Check Out</button>
    </form>
</body>
</html>

<script type="text/javascript">
    function checkout() {
        var stripe = Stripe('pk_test_KEY');
        stripe.redirectToCheckout({
            // Make the id field from the Checkout Session creation API response
            // available to this file, so you can provide it as parameter here
            // instead of the {{CHECKOUT_SESSION_ID}} placeholder.
            sessionId: '123456789'
        }).then(function (result) {
            // If `redirectToCheckout` fails due to a browser or network
            // error, display the localized error message to your customer
            // using `result.error.message`.
        });
    }
</script>

When i click the button it doesnt redirect to the payment gateway page. What am i missing?

Your JS should be placed before the closing </body> tag. That might help.

I tried but it didnt make a difference

So… okay…when you did Step 1 in that page you linked, did it actually spit back ‘123456789’? Cause… i’m guessing it didnt. Or are you obfuscating that from us here?

And also the pk_test_KEY… you’re replacing that with pk_test_whateveryouusedinstep1 , right?

Yes - but it seems our IT were blocking some scripts from executing on the browser. So its now sorted. Thanks for your help guys.

1 Like