PageSourceSearch

https://priborelektro.ru/js/addons/paypal/in_context_checkout.js?ver=1790257262

js priborelektro.ru collected 2026-09-25 05:04:32 UTC 4,543 bytes, 126 lines download raw bytes

1(function (_, $) {
2  var is_paypal_script_loaded;
3  var methods = {
4    set_submit_button_id: function set_submit_button_id(button_id) {
5      var button_id_new = button_id + '_' + Date.now();
6      var button = $('#' + button_id);
7      button.attr('id', button_id_new);
8      return button_id_new;
9    },
10    get_token_request: function get_token_request(payment_form) {
11      var form_data = {
12        in_context_order: 1
13      };
14      var fields = payment_form.serializeArray();
15
16      for (var i in fields) {
17        form_data[fields[i].name] = fields[i].value;
18      }
19
20      form_data.result_ids = null;
21      return form_data;
22    },
23    set_window_close_error_handler: function set_window_close_error_handler() {
24      window.onerror = function (e) {
25        $.redirect(_.current_url);
26      };
27    },
28    setup_payment_form: function setup_payment_form(params) {
29      params = params || {};
30      params.merchat_id = params.merchat_id || '';
31      params.environment = params.environment || 'sandbox';
32      params.payment_form = params.payment_form || null;
33      params.submit_button_id = params.submit_button_id || '';
34      paypal.checkout.setup(params.merchat_id, {
35        environment: params.environment,
36        buttons: [{
37          button: params.submit_button_id,
38          condition: function condition() {
39            return $.ceLiteCheckout('check', function (result) {
40              return result;
41            });
42          },
43          click: function click(e) {
44            $.ceEvent('on', 'ce.formpost_' + params.payment_form.prop('name'), function () {
45              return false;
46            });
47            e.preventDefault(); // window has to be inited in 'click' handler to prevent browser pop-up blocking
48
49            paypal.checkout.initXO();
50            $.ceLiteCheckout('updateCustomerInfo', function () {
51              var form_data = methods.get_token_request($("form[name=\"".concat(params.payment_form.prop('name'), "\"]")));
52              $.ceAjax('request', fn_url('checkout.place_order'), {
53                method: 'post',
54                caching: false,
55                hidden: true,
56                data: form_data,
57                callback: function callback(response) {
58                  try {
59                    if (response.token) {
60                      var url = paypal.checkout.urlPrefix + response.token + '&useraction=commit';
61                      paypal.checkout.startFlow(url);
62                    }
63
64                    if (response.error) {
65                      paypal.checkout.closeFlow();
66                    }
67                  } catch (ex) {
68                    paypal.checkout.initXO();
69                  }
70                }
71              });
72            }, false);
73          }
74        }]
75      });
76    },
77    init: function init(jelm) {
78      var payment_form = jelm.closest('form'); // submit button id must be altered to prevent 'button_already_has_paypal_click_listener' warning
79
80      var submit_button_id = methods.set_submit_button_id(jelm.data('caPaypalButton')); // workaround for https://github.com/paypal/paypal-checkout/issues/469
81
82      methods.set_window_close_error_handler();
83
84      var paypal_script_load_callback = function paypal_script_load_callback() {
85        is_paypal_script_loaded = true;
86        var paypal_presence_checker = setInterval(function () {
87          if (typeof paypal !== 'undefined') {
88            clearInterval(paypal_presence_checker);
89            methods.setup_payment_form({
90              merchant_id: jelm.data('caPaypalMerchantId'),
91              environment: jelm.data('caPaypalEnvironment'),
92              payment_form: payment_form,
93              submit_button_id: submit_button_id
94            });
95          }
96        }, 300);
97      };
98
99      if (is_paypal_script_loaded) {
100        paypal_script_load_callback();
101      } else {
102        $.getScript('https://www.paypalobjects.com/api/checkout.min.js', paypal_script_load_callback);
103      }
104    }
105  };
106  $.extend({
107    cePaypalInContextCheckout: function cePaypalInContextCheckout(method) {
108      if (methods[method]) {
109        return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
110      } else {
111        $.error('ty.paypalInContextCheckout: method ' + method + ' does not exist');
112      }
113    }
114  });
115  $.ceEvent('on', 'ce.commoninit', function () {
116    if (_.embedded) {
117      return;
118    }
119
120    var jelm = $('[data-ca-paypal-in-context-checkout]');
121
122    if (jelm.length) {
123      $.cePaypalInContextCheckout('init', jelm);
124    }
125  });
126})(Tygh, Tygh.$);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.