PluginProbe
HyperPay Payments / trunk
HyperPay Payments vtrunk
6.6.0 trunk 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.5 4.0.0 4.0.2 All 34 releases
hyperpay-gateways / src / assets / js / script.js

script.js in HyperPay Payments trunk, at src/assets/js/script.js

159 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 *
3 * to check if current browser support ApplePay
4 * @param {boolean}
5 * if @returns {false} attach error message Your Device Dose Not Support ApplePay
6 */
7 if (!window.ApplePaySession && dataObj.payment_brands.includes('APPLEPAY')) {
8 jQuery('.woocommerce-notices-wrapper')
9 .append(`<ul class="woocommerce-error" role="alert"><li> ${dataObj.is_arabic ? 'جهازك او �
10 تصفحك لا يدع�
11 الدفع عن طريق ابل' : 'Your Device Or Browser Dose Not Support ApplePay'} </li></ul>`)
12 }
13
14 /**
15 * initiate wpwlOptions
16 */
17
18
19 function updateHyperpayCheckout(extraData) {
20 shouldProceed = false;
21 jQuery.ajax({
22 url: '/?wc-ajax=recurring_update_checkout',
23 type: "POST",
24 dataType: "json",
25 async: false,
26 data: {
27 selectedCard: jQuery('input[name="registrationId"]:checked').val(),
28 checkoutId: dataObj.checkoutId,
29 orderId: dataObj.orderId,
30 ...extraData,
31 _wpnonce: dataObj.hyperpay_update_nonce,
32
33 },
34 success: function (response) {
35 if (response && response.success) {
36 shouldProceed = true;
37 } else {
38 alert("Something went wrong, please try again.");
39 shouldProceed = false;
40 }
41 },
42 error: function (xhr, status, error) {
43 alert("Server error. Please try again later.");
44 shouldProceed = false;
45 }
46 });
47 return shouldProceed;
48 }
49
50 var wpwlOptions = {
51
52 registrations: {requireCvv: true},
53 onReady: function () {
54
55
56 jQuery('.wpwl-form-virtualAccount-STC_PAY .wpwl-wrapper-radio-qrcode').hide();
57 jQuery('.wpwl-form-virtualAccount-STC_PAY .wpwl-wrapper-radio-mobile').hide();
58 jQuery('.wpwl-form-virtualAccount-STC_PAY .wpwl-group-paymentMode').hide();
59 jQuery('.wpwl-form-virtualAccount-STC_PAY .wpwl-group-mobilePhone').show();
60 jQuery('.wpwl-form-virtualAccount-STC_PAY .wpwl-wrapper-radio-mobile .wpwl-control-radio-mobile').attr('checked', true);
61 jQuery('.wpwl-form-virtualAccount-STC_PAY .wpwl-wrapper-radio-mobile .wpwl-control-radio-mobile').trigger('click');
62 jQuery(".wpwl-form.wpwl-form-registrations.wpwl-clearfix").last().find(".wpwl-button.wpwl-button-pay").remove();
63 jQuery(".wpwl-form.wpwl-form-registrations.wpwl-clearfix").last().remove();
64 jQuery('.wpwl-group.wpwl-group-brand').hide() ;
65
66 let element = jQuery("" +
67 "<div class=\"wpwl-group wpwl-group-registration show_new_card_form_div wpwl-clearfix \"> " +
68 "<label class=\"wpwl-registration\"> " +
69 "<div class=\"\"> " +
70 "<input value='' type=\"radio\" name=\"registrationId\" id='show_new_card_form' > <div class='add_new_card_brand'>+ Add New Card </div></div>" +
71 " </div> </div> </label> </div>");
72
73 // Find the last element of the target group
74 let target = jQuery(".wpwl-group.wpwl-group-registration.wpwl-has-cvv.wpwl-clearfix").last();
75
76
77 // Move the element after the target
78
79 if (element.length && target.length) {
80 element.insertAfter(target);
81 }
82
83 var createRegistrationHtml = `
84 <div class="customLabel">
85 <input
86 type="checkbox"
87 aria-required="true"
88 id="hyperpay_save_card"
89 value="true"
90 ${dataObj.is_subscription == 'yes' ? 'checked disabled' : ''}
91 />
92 <label for="hyperpay_save_card">
93 ${dataObj.is_subscription == 'yes' ?
94 dataObj.is_arabic ? 'حفظ بيانات بطاقتي للدفع في ال�
95 ستقبل (�
96 طلوب للاشتراكات)' : 'Save my card details for future payments (required for subscriptions)'
97 :
98 dataObj.is_arabic ? 'حفظ بيانات بطاقتي للدفع في ال�
99 ستقبل ' : 'Save my card details for future payments'
100 }
101 </label>
102 </div>
103 <div class="customInput"></div>`;
104 jQuery('input[name="registrationId"]').on("change", function () {
105 if (jQuery("#show_new_card_form").is(':checked')) {
106 jQuery(".wpwl-wrapper-registration-cvv iframe").css("visibility", "hidden").css("height", "0");
107 jQuery(".wpwl-group-registration").removeClass("wpwl-selected");
108 jQuery(this).closest(".wpwl-group-registration").addClass("wpwl-selected");
109 jQuery(".wpwl-container.wpwl-container-card.wpwl-clearfix").show();
110 jQuery(".wpwl-form.wpwl-form-registrations.wpwl-clearfix").find(".wpwl-button.wpwl-button-pay").last().hide();
111 } else {
112 jQuery(".wpwl-container.wpwl-container-card.wpwl-clearfix").hide();
113 jQuery(this).closest(".wpwl-group-registration").removeClass("wpwl-selected");
114 jQuery(".wpwl-form.wpwl-form-registrations.wpwl-clearfix").find(".wpwl-button.wpwl-button-pay").last().show();
115 }
116 })
117 jQuery('form.wpwl-form-card').find('.wpwl-button').before(createRegistrationHtml);
118
119 },
120 onBeforeSubmitOneClickCard: function (e) {
121 return updateHyperpayCheckout({createRegistration: "false"});
122 },
123 onBlurCardNumber: function (isValid) {
124 let paymentBrand = this.$form.find('.wpwl-control-brand').val();
125 if (dataObj.id != 'hyperpay_mada' && paymentBrand == "MADA") {
126 setTimeout(function () {
127 jQuery('.wpwl-hint-cardNumberError').remove();
128 jQuery('.wpwl-control-cardNumber').removeClass('wpwl-has-error');
129 jQuery('.wpwl-control-cardNumber').addClass('wpwl-has-error').after('<div class="wpwl-hint wpwl-hint-cardNumberError">mada card is not allowed, please choose mada debit card from the payment options</div>');
130 jQuery('.wpwl-button-pay').prop('disabled', true);
131 }, 5);
132 }
133 },
134
135 onBeforeSubmitCard: function (e) {
136 let createRegistration = jQuery("#hyperpay_save_card").is(":checked")
137 return updateHyperpayCheckout({createRegistration})
138 },
139 style: dataObj.style, // <== this style comes from settings page of gateways
140 paymentTarget: "_top",
141 locale: dataObj.is_arabic ? 'ar' : 'en',
142 registrations: {
143 hideInitialPaymentForms: true,
144 requireCvv: "true"
145 },
146 browser: {
147 threeDChallengeWindow: 5
148 }
149
150
151 }
152
153 if (dataObj.supported_network) {
154 wpwlOptions.applePay = {
155 supportedNetworks: dataObj.supported_network
156 }
157 }
158
159