PageSourceSearch

https://www.charleskeith.co.uk/on/demandware.static/Sites-ck-gb-Si…/custom/js/cybersource-custom.js

js charleskeith.co.uk collected 2026-09-29 00:17:41 UTC 15,198 bytes, 351 lines download raw bytes

1/* eslint-disable */
2
3var init = {
4    initConfig: function () {
5        var requestId; var billingAgreementFlag; // A Flag to show whether user has opted for Billing Agreement or not
6        var billingAgreementButton; // The Billing Agreement Checkbox
7        var billingAgreementID; // Billing Agreement ID
8        var isPayPalCredit = false; var
9            endPoint = $('#paypal_endpoint').length > 0 ? document.getElementById('paypal_endpoint').value : 'sandbox';
10        var config = {
11            env: endPoint,
12            commit: true,
13
14            validate: function (actions) {
15                if ($('.paypal-address').length > 0) {
16                    paypalvalidator.toggleForm(actions);
17                    paypalvalidator.onChangeForm(function () {
18                        paypalvalidator.toggleForm(actions);
19                    });
20                }
21            },
22            payment: function () {
23                var CREATE_URL = document.getElementById('paypal_express').value;
24                if (config.paymentOption.credit) {
25                    isPayPalCredit = true;
26                } else {
27                    isPayPalCredit = false;
28                }
29                billingAgreementButton = document.getElementById('billingAgreementCheckbox');
30                // billingAgreementFlag - This variable is used to indicate if billing agreement creation is requested or not
31                billingAgreementFlag = (billingAgreementButton == null) ? false : billingAgreementButton.checked;
32                // Append a parameter to URL when Billing Agreement is checked
33                if (billingAgreementFlag) {
34                    CREATE_URL += '?billingAgreement=true';
35                } else if (isPayPalCredit) {
36                // Append a parameter to URL when PayPal Credit is used
37                    CREATE_URL += '?isPayPalCredit=true';
38                }
39                return paypal.request.post(CREATE_URL)
40                    .then(function (res) {
41                        requestId = res.requestID;
42                        return res.processorTransactionID;
43                    });
44            },
45            onAuthorize: function (data, actions) {
46                var data = {
47                    requestId: requestId,
48                    billingAgreementFlag: billingAgreementFlag,
49                    paymentID: data.paymentID,
50                    payerID: data.payerID,
51                    isPayPalCredit: isPayPalCredit
52                };
53
54                var paypalcallback = document.getElementById('paypal_callback').value;
55                var form = $('<form action="' + paypalcallback + '" method="post">'
56                + '<input type="hidden" name="requestId" value="' + requestId + '" />'
57                + '<input type="hidden" name="billingAgreementFlag" value="' + billingAgreementFlag + '" />'
58                + '<input type="hidden" name="paymentID" value="' + data.paymentID + '" />'
59                + '<input type="hidden" name="payerID" value="' + data.payerID + '" />'
60                + '<input type="hidden" name="isPayPalCredit" value="' + isPayPalCredit + '" />'
61                + '</form>');
62                $('body').append(form);
63                form.submit();
64            }
65        };
66        return config;
67    },
68
69    initPayPalButtons: function () {
70        var isPaypalEnabled;
71        isPaypalEnabled = !!($('#paypal_enabled').length > 0 && document.getElementById('paypal_enabled').value == 'true');
72        var locale = $('#currentLocale').length > 0 ? document.getElementById('currentLocale').value : '';
73        var config = init.initConfig();
74        config.paymentOption = {
75            express: true,
76            credit: false
77        };
78        config.locale = locale;
79        if (isPaypalEnabled && $('.paypal-button-container-cart1').length > 0) {
80            paypal.Button.render(config, '.paypal-button-container-cart1');
81        }
82        if (isPaypalEnabled && $('.paypal-button-container-cart2').length > 0) {
83            paypal.Button.render(config, '.paypal-button-container-cart2');
84        }
85        if (isPaypalEnabled && $('#paypal-button-container').length > 0) {
86            paypal.Button.render(config, '#paypal-button-container');
87        }
88        // Settings for PayPal Credit Card Button
89        if (isPaypalEnabled && $('#paypal-credit-container').length > 0) {
90            var creditConfig = init.initConfig();
91            creditConfig.style = {
92                label: 'credit',
93                size: 'small', // small | medium
94                shape: 'rect' // pill | rect
95            };
96            creditConfig.paymentOption = {
97                express: false,
98                credit: true
99            };
100            creditConfig.locale = locale;
101            paypal.Button.render(creditConfig, '#paypal-credit-container');
102        }
103    },
104
105    initFunctions: function () {
106        $(document).on('click', '.credit_card, .sa_flex', function (e) {
107            e.stopImmediatePropagation();
108            var payerAuth = $(this).data('payerauth');
109            window.location.href = payerAuth;
110        });
111
112        $(document).on('click', '.dw_google_pay, .paypal, .paypal_credit, .wechat', function (e) {
113            e.stopImmediatePropagation();
114            var formaction = $(this).attr('data-action');
115            setTimeout(function () {
116                window.location.href = formaction;
117            }, 500);
118        });
119
120        // for Alipay Intermediate
121        if ($('body').hasClass('cyb_alipayintermediate')) {
122            var loaded = false;
123            setTimeout(function () {
124                document.RedirectForm.submit();
125                loaded = true;
126            }, 1000);
127        }
128        // For FingerPrint Unit testing
129        if ($('body').hasClass('cyb_testfingerprintRedirect')) {
130            var url_loc = document.getElementById('URl_redirect').value;
131            setTimeout(function () { location.href = url_loc; }, 1000);
132        }
133        // For Payerauth during checkout
134        if ($('div').hasClass('payerauth')) {
135            document.PAInfoForm.submit();
136        }
137        // For payerauth during  Credit card
138        if ($('body').hasClass('cyb_payerauthenticationredirect')) {
139            document.RedirectForm.submit();
140        }
141        // For payerauth during  Unit testing
142        if ($('body').hasClass('cyb_unitTest_payerauth')) {
143            document.RedirectForm.submit();
144        }
145        // For payer auth during  Unit testing
146        if ($('div').hasClass('cyb_unitTest_payerauthsubmit')) {
147            document.PAInfoForm.submit();
148        }
149        // For Secure Acceptance Redirect
150        if ($('body').hasClass('cyb_sa_redirect')) {
151            var url_loc = document.getElementById('redirect_url_sa').value;
152            window.top.location.replace(url_loc);
153        }
154        // For Secure Acceptance Iframe
155        if ($('div').hasClass('SecureAcceptance_IFRAME')) {
156            var url_loc = document.getElementById('sa_iframeURL').value;
157            $('.SecureAcceptance_IFRAME').append('<iframe src=' + url_loc + '  name="hss_iframe"  width="85%" height="730px" scrolling="no" />');
158        }
159        // For Secure Acceptance Iframe
160        if ($('body').hasClass('sa_iframe_request_form')) {
161            document.form_iframe.submit();
162        }
163        // For Secure Acceptance
164        if ($('body').hasClass('cyb_sa_request_form')) {
165            $('#loading').css('display', 'block');
166            document.ePayment.submit();
167        }
168
169        // FOR POS
170        $('#entry-mode-pos_unittest select.input-select').change(function () {
171            if (this.value == 'swiped') {
172                $('#card-section, #sample-card-section').css('display', 'none');
173            } else if (this.value == 'keyed') {
174                $('#card-section, #sample-card-section').css('display', 'block');
175            }
176        });
177
178        /*
179        * If billing agreement ID already exists in the user profile then a different button
180        * is displayed on the the page. This function handles the action of that button.
181        * This functions directly calls checkstatusservice
182    */
183        $(document).on('click', '.billingAgreementExpressCheckout', function (e) {
184            e.preventDefault();
185            var paypalcallback = document.getElementById('paypal_callback').value;
186            var form = $('<form action="' + paypalcallback + '" method="post">'
187                    + '</form>');
188            $('body').append(form);
189            form.submit();
190        });
191
192        $(document).on('click', '.sa_silentpost, .sa_redirect, .alipay, .gpy, .eps, .sof, .mch, .idl , .klarna, .wechat', function (e) {
193            e.stopImmediatePropagation();
194            var CsSaType = $('div[data-payment-method-id="CREDIT_CARD"]').attr('data-sa-type');
195            var paymentMethodID = $('input[name=dwfrm_billing_paymentMethod]').val();
196            var paymentMethodIds = ['KLARNA', 'ALIPAY', 'GPY', 'EPS', 'SOF', 'IDL', 'MCH', 'WECHAT'];
197            var paymentMethod = $.inArray(paymentMethodID, paymentMethodIds) > -1;
198            if ((CsSaType != 'CREDIT_CARD' && paymentMethodID == 'CREDIT_CARD') || paymentMethod) {
199                var formaction = $(this).attr('data-action');
200                setTimeout(function () {
201                    window.location.href = formaction;
202                }, 500);
203            }
204        });
205
206        /**
207 * @function
208 * @description function to Open the secure acceptance page inside Iframe if secure acceptance Iframe is selected
209 */
210        $(document).on('click', '.sa_iframe', function (e) {
211            e.stopImmediatePropagation();
212            var creditCardItem = $('div[data-payment-method-id="CREDIT_CARD"]');
213            var CsSaType = $(creditCardItem).attr('data-sa-type');
214            if (CsSaType == 'SA_IFRAME') {
215                var formaction = $(this).attr('data-action');
216                $.ajax({
217                    url: formaction,
218                    type: 'POST',
219                    success: function (xhr, data) {
220                        if (xhr) {
221                            if (xhr.error == true) {
222                                $('#saspCardError').html(xhr.errorMsg);
223                                $('#saspCardError').addClass('error');
224                            } else {
225                                $('#secureAcceptanceIframe').html(xhr);
226                                document.getElementById('submit-order').classList.add('d-none');
227                            }
228                        } else {
229                            $('#saspCardError').html(xhr.errorMsg);
230                            $('#saspCardError').addClass('error');
231                        }
232                        return true;
233                    },
234                    error: function () {
235                        $('#saspCardError').html(xhr.errorMsg).addClass('error');
236                    }
237                });
238            } else {
239                return true;
240            }
241        });
242
243        $('#capturepaymenttype, #authreversalpaymenttype').change(function () {
244            if ($(this).val() == 'visacheckout') {
245                $('#orderRequestID').attr('required', 'required');
246                $('.orderRequestID').removeClass('hidden').addClass('show');
247            } else {
248                $('#orderRequestID').removeAttr('required');
249                $('.orderRequestID').removeClass('show').addClass('hidden');
250            }
251        });
252
253        if ($('#checkout-main').attr('data-checkout-stage') === 'placeOrder') {
254            var placeOrderBtn = $('#checkout-main').find('#submit-order');
255            $(placeOrderBtn).closest('.row').find('.next-step-button').removeClass('next-step-button');
256        }
257    }
258};
259
260var paypalhelper = {
261    paypalMini: function () {
262        var config = init.initConfig();
263        var locale = $('#currentLocale').length > 0 ? document.getElementById('currentLocale').value : '';
264        config.paymentOption = {
265            express: true,
266            credit: false
267        };
268        config.locale = locale;
269        var isPaypalEnabled = false;
270        if (document.getElementById('paypal_enabled') != null) {
271            isPaypalEnabled = document.getElementById('paypal_enabled').value;
272        }
273        if (isPaypalEnabled && $('.paypal-button-container-mini').length > 0) {
274            paypal.Button.render(config, '.paypal-button-container-mini');
275        }
276    },
277    validateForms: function () {
278        var currentForm = $('data-checkout-stage').attr('data-checkout-stage');
279        if (currentForm == 'payment') {
280            false;
281        } return true;
282    }
283};
284
285var paypalvalidator = {
286    toggleForm: function (actions) {
287        if (this.isValid()) { return actions.enable(); }
288        return actions.disable();
289    },
290    isValid: function () {
291        var paymentForm = $('#dwfrm_billing').serialize();
292        var isValidForm = false;
293
294        $('body').trigger('checkout:serializeBilling', {
295            form: $('#dwfrm_billing'),
296            data: paymentForm,
297            callback: function (data) { paymentForm = data; }
298        });
299        paypalvalidator.validateAddress(function (data) {
300            isValidForm = !data.error;
301            if (data.fieldErrors.length) {
302                data.fieldErrors.forEach(function (error) {
303                    if (Object.keys(error).length) {
304                        paypalvalidator.loadFormErrors('.payment-form', error);
305                    }
306                });
307            }
308        });
309        return isValidForm;
310    },
311
312    loadFormErrors: function (parentSelector, fieldErrors) {
313        $.each(fieldErrors, function (attr) {
314            $('*[name=' + attr + ']', parentSelector).addClass('is-invalid').siblings('.invalid-feedback').html(fieldErrors[attr]);
315        });
316    },
317
318    paypalMini: function () {
319        var config = init.initConfig();
320        var isPaypalEnabled = document.getElementById('paypal_enabled').value;
321        if (isPaypalEnabled && $('.paypal-button-container-mini').length > 0) {
322            paypal.Button.render(config, '.paypal-button-container-mini');
323        }
324    },
325    validateAddress: function (callback) {
326        var paymentForm = $('#dwfrm_billing').serialize();
327        $.ajax({
328            method: 'POST',
329            async: false,
330            data: paymentForm,
331            url: $('.paypal-address').attr('action'),
332            success: function (data) {
333                callback(data);
334            },
335            error: function (err) {
336            }
337        });
338    },
339    onChangeForm: function (handler) {
340        $('.billing-information').on('change', handler);
341    }
342};
343
344$(document).ready(function () {
345    init.initConfig();
346    init.initPayPalButtons();
347    init.initFunctions();
348    if ($('#isGooglePayEnabled').val() == 'true') {
349        onGooglePayLoaded();
350    }
351});

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.