| 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 |
|
| 65 |
let element = jQuery("" + |
| 66 |
"<div class=\"wpwl-group wpwl-group-registration show_new_card_form_div wpwl-clearfix \"> " + |
| 67 |
"<label class=\"wpwl-registration\"> " + |
| 68 |
"<div class=\"\"> " + |
| 69 |
"<input value='' type=\"radio\" name=\"registrationId\" id='show_new_card_form' > <div class='add_new_card_brand'>+ Add New Card </div></div>" + |
| 70 |
" </div> </div> </label> </div>"); |
| 71 |
|
| 72 |
// Find the last element of the target group |
| 73 |
let target = jQuery(".wpwl-group.wpwl-group-registration.wpwl-has-cvv.wpwl-clearfix").last(); |
| 74 |
|
| 75 |
|
| 76 |
// Move the element after the target |
| 77 |
|
| 78 |
if (element.length && target.length) { |
| 79 |
element.insertAfter(target); |
| 80 |
} |
| 81 |
|
| 82 |
var createRegistrationHtml = ` |
| 83 |
<div class="customLabel"> |
| 84 |
<input |
| 85 |
type="checkbox" |
| 86 |
aria-required="true" |
| 87 |
id="hyperpay_save_card" |
| 88 |
value="true" |
| 89 |
${dataObj.is_subscription == 'yes' ? 'checked disabled' : ''} |
| 90 |
/> |
| 91 |
<label for="hyperpay_save_card"> |
| 92 |
${dataObj.is_subscription == 'yes' ? |
| 93 |
dataObj.is_arabic ? 'حفظ بيانات بطاقتي للدفع في ال� |
| 94 |
ستقبل (� |
| 95 |
طلوب للاشتراكات)' : 'Save my card details for future payments (required for subscriptions)' |
| 96 |
: |
| 97 |
dataObj.is_arabic ? 'حفظ بيانات بطاقتي للدفع في ال� |
| 98 |
ستقبل ' : 'Save my card details for future payments' |
| 99 |
} |
| 100 |
</label> |
| 101 |
</div> |
| 102 |
<div class="customInput"></div>`; |
| 103 |
jQuery('input[name="registrationId"]').on("change", function () { |
| 104 |
if (jQuery("#show_new_card_form").is(':checked')) { |
| 105 |
jQuery(".wpwl-wrapper-registration-cvv iframe").css("visibility", "hidden").css("height", "0"); |
| 106 |
jQuery(".wpwl-group-registration").removeClass("wpwl-selected"); |
| 107 |
jQuery(this).closest(".wpwl-group-registration").addClass("wpwl-selected"); |
| 108 |
jQuery(".wpwl-container.wpwl-container-card.wpwl-clearfix").show(); |
| 109 |
jQuery(".wpwl-form.wpwl-form-registrations.wpwl-clearfix").find(".wpwl-button.wpwl-button-pay").last().hide(); |
| 110 |
} else { |
| 111 |
jQuery(".wpwl-container.wpwl-container-card.wpwl-clearfix").hide(); |
| 112 |
jQuery(this).closest(".wpwl-group-registration").removeClass("wpwl-selected"); |
| 113 |
jQuery(".wpwl-form.wpwl-form-registrations.wpwl-clearfix").find(".wpwl-button.wpwl-button-pay").last().show(); |
| 114 |
} |
| 115 |
}) |
| 116 |
jQuery('form.wpwl-form-card').find('.wpwl-button').before(createRegistrationHtml); |
| 117 |
|
| 118 |
}, |
| 119 |
onBeforeSubmitOneClickCard: function (e) { |
| 120 |
return updateHyperpayCheckout({createRegistration: "false"}); |
| 121 |
}, |
| 122 |
onBlurCardNumber: function (isValid) { |
| 123 |
let paymentBrand = this.$form.find('.wpwl-control-brand').val(); |
| 124 |
if (dataObj.id != 'hyperpay_mada' && paymentBrand == "MADA") { |
| 125 |
setTimeout(function () { |
| 126 |
jQuery('.wpwl-hint-cardNumberError').remove(); |
| 127 |
jQuery('.wpwl-control-cardNumber').removeClass('wpwl-has-error'); |
| 128 |
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>'); |
| 129 |
jQuery('.wpwl-button-pay').prop('disabled', true); |
| 130 |
}, 5); |
| 131 |
} |
| 132 |
}, |
| 133 |
|
| 134 |
onBeforeSubmitCard: function (e) { |
| 135 |
let createRegistration = jQuery("#hyperpay_save_card").is(":checked") |
| 136 |
return updateHyperpayCheckout({createRegistration}) |
| 137 |
}, |
| 138 |
style: dataObj.style, // <== this style comes from settings page of gateways |
| 139 |
paymentTarget: "_top", |
| 140 |
locale: dataObj.is_arabic ? 'ar' : 'en', |
| 141 |
registrations: { |
| 142 |
hideInitialPaymentForms: true, |
| 143 |
requireCvv: "true" |
| 144 |
}, |
| 145 |
browser: { |
| 146 |
threeDChallengeWindow: 5 |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
if (dataObj.supported_network) { |
| 153 |
wpwlOptions.applePay = { |
| 154 |
supportedNetworks: dataObj.supported_network |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|