Stripe Checkout Только для клиента интеграция с Django - PullRequest
0 голосов
/ 28 марта 2020

Моя цель - интегрировать интеграцию только с Stripe Checkout Client с приложением Django, используя эти инструкции . Я скопировал код, предоставленный stripe, в шаблон html.

Когда я запускаю шаблон, появляется кнопка извлечения, но при нажатии кнопки не выполняется скрипт полосы (без ошибок). Я ожидал, что меня перенаправят на страницу оформления заказа.

Я пытался переместить javascript в отдельные файлы в папке stati c с тем же результатом.

Проблема, связывающая нажатие кнопки с javascript?

Вот шаблон html с вставленным кодом полосы:

{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
 <head>
  <title></title>

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

 </head>
 <body>

  <!-- 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-sku_GyczP1qEmsj6eZ"
    role="link"
  >
    Checkout
  </button>

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

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

    var checkoutButton = document.getElementById('checkout-button-sku_GyczP1qEmsj6eZ');
    checkoutButton.addEventListener('click', function () {
      // When the customer clicks on the button, redirect
      // them to Checkout.
      stripe.redirectToCheckout({
        items: [{sku: 'sku_GyczP1qEmsj6eZ', quantity: 1}],

        // 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/fulfillment
        successUrl: 'http://127.0.0.1:8000/home',
        cancelUrl: 'http://127.0.0.1:8000/',
      })
      .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>

 </body>
</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...