JSFiddle - React, Tailwind, and code Playground

by Michelle Bu

HTML

<!-- Load Stripe.js on your website. -->
<script src="https://js.stripe.com/v3"></script>

<!-- Create a button that your customers click to complete their purchase. -->
<button id="checkout-button">Pay</button>
<div id="error-message"></div>

<script>
  var stripe = Stripe('pk_test_pn9edQ1LOK6zMJnLd9zYzqb2', {
    betas: ['checkout_beta_3']
  });

  var checkoutButton = document.getElementById('checkout-button');
  checkoutButton.addEventListener('click', function () {
    // When the customer clicks on the button, redirect
    // them to Checkout.
    stripe.redirectToCheckout({
      items: [{plan: 'test', quantity: 1}],
      successUrl: 'https://shirt.codes/success',
      cancelUrl: 'https://shirt.codes/canceled',
    })
    .then(function (result) {
      if (result.error) {
        // If `redirectToCheckout` fails due to a browser or network
        // error, display the localized error message to your customer.
        var displayError = document.getElementById('error-message');
        displayError.textContent = error.message;
      }
    });
  });
</script>