条纹结帐按钮不起作用-Wordpress

时间:2020-10-17 12:11:58

标签: javascript wordpress stripe-payments

我一直在尝试将条纹签出与我正在工作的网站集成。我已经按照文档操作并从仪表板生成了代码,但是当我将其粘贴到我的网站时,单击该按钮实际上并没有执行任何操作?

代码如下:

<!-- 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. Customize the styling to suit your branding. -->
<button
  style="background-color:#6772E5;color:#FFF;padding:8px 12px;border:0;border-radius:4px;font-size:1em"
  id="checkout-button-price_1HVKZsEesDKuM7IwbBRQvR3S"
  role="link"
  type="button"
>
  Checkout
</button>

<div id="error-message"></div>

<script>
(function() {
  var stripe = Stripe('pk_live_51HVKWSEesDKuM7IwSuFMChZpiMpOeVCHA5YbDnJS7FEPZfTVeXA4UPHVLdXoFfRNU6tIKWhtkiCAUHLYujIcBOF800qa6tu6lx');

  var checkoutButton = document.getElementById('checkout-button-price_1HVKZsEesDKuM7IwbBRQvR3S');
  checkoutButton.addEventListener('click', function () {
    // When the customer clicks on the button, redirect
    // them to Checkout.
    stripe.redirectToCheckout({
      lineItems: [{price: 'price_1HVKZsEesDKuM7IwbBRQvR3S', quantity: 1}],
      mode: 'subscription',
      // Do not rely on the redirect to the successUrl for fulfilling
      // purchases, customers may not always reach the success_url after
      // a successful payment.
      // Instead use one of the strategies described in
      // https://stripe.com/docs/payments/checkout/fulfill-orders
      successUrl: window.location.protocol + '//www.melting-moments.co.uk/success',
      cancelUrl: window.location.protocol + '//www.melting-moments.co.uk/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 = result.error.message;
      }
    });
  });
})();
</script>

谢谢你们。

0 个答案:

没有答案