PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
payplug / resources / js / frontend / helper / wc-payplug-requests.js

wc-payplug-requests.js in PayPlug for WooCommerce (Official) 3.1.0, at resources/js/frontend/helper/wc-payplug-requests.js

55 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getSetting } from '@woocommerce/settings';
2 import $ from 'jquery';
3 const settings = getSetting('payplug_data', {});
4
5 // jQuery's .fail() callback receives a jqXHR object, not an Error - normalize it so
6 // callers doing `catch (error) { error.message }` get a usable string instead of undefined.
7 function toRequestError(jqXHR, textStatus, errorThrown) {
8 const data = jqXHR?.responseJSON?.data;
9 const message = (typeof data === 'string' && data) || data?.message || errorThrown || textStatus || 'Request failed';
10 return new Error(message);
11 }
12
13 export const getPayment = (props, _settings, order_id) => {
14 const data = getPaymentData(props);
15 return new Promise((resolve, reject) => {
16 return $.ajax({
17 type: 'POST',
18 data: data,
19 url: settings.payplug_create_intent_payment,
20
21 }).done(function (response) {
22 resolve(response);
23
24 }).fail(function (jqXHR, textStatus, errorThrown) {
25 reject(toRequestError(jqXHR, textStatus, errorThrown));
26
27 });
28 });
29
30 function getPaymentData(props) {
31 return {
32 "order_id": order_id,
33 "woocommerce-process-checkout-nonce": settings.wp_nonce,
34 "gateway": _settings?.payment_method,
35 "order_pay_key": _settings?.order_pay_key || ''
36 }
37 }
38 };
39
40 export const check_payment = (data) => {
41 return new Promise((resolve, reject) => {
42 $.ajax({
43 type: 'POST',
44 data: data,
45 url: settings.payplug_integrated_payment_check_payment_url
46 }).done(function (response) {
47 resolve(response);
48
49 }).fail(function (jqXHR, textStatus, errorThrown) {
50 reject(toRequestError(jqXHR, textStatus, errorThrown));
51
52 });
53 });
54 };
55