simple_paypal_field-8.x-1.1/js/paypal.js

js/paypal.js
(function (jQuery, settings) {
  Drupal.behaviors.paypal_smart_buttons = {
    attach: function (context) {
      jQuery('.paypal-button', context).each(function (key, element) {
        paypal.Buttons({
          style: JSON.parse(element.getAttribute('data-settings')),
          createOrder: function (data, actions) {
            return actions.order.create({
              purchase_units: [{
                amount: {
                  value: element.getAttribute('data-value'),
                }
              }]
            });
          },
          onApprove: function (data, actions) {
            actions.order.capture().then(function (details) {
              fetch('/simple_paypal_field/approve', {
                method: 'post',
                headers: new Headers({
                  'Content-type': 'application/json'
                }),
                body: JSON.stringify({
                  details: details,
                  element: element.getAttribute('id'),
                })
              }).then(function() {
                window.location.reload();
              })
            });

          },
        }).render(element);
      })
    }
  }
})(jQuery, drupalSettings);

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc