PageSourceSearch

https://febestore.pl/modules/przelewy24/views/js/p24_inside.js

js febestore.pl collected 2026-10-09 02:49:02 UTC 15,768 bytes, 523 lines download raw bytes

1/*
2* @author Przelewy24
3* @copyright Przelewy24
4* @license https://www.gnu.org/licenses/lgpl-3.0.en.html
5*/
6
7var p24GetRawAdditionalFormsContainer = function () {
8    var idVar = 'p24-additional-forms';
9    var rawContainer = document.getElementById(idVar);
10    if (!rawContainer) {
11        rawContainer = document.createElement('div');
12        rawContainer.id = idVar;
13        document.body.appendChild(rawContainer);
14    }
15
16    return rawContainer;
17};
18
19function redirectAfterCardPayment(url)
20{
21    setTimeout(function() {
22        window.location.href = $('#p24-card-config-element').data(url);
23    }, 500);
24}
25
26function payInShopSuccess() {
27    redirectAfterCardPayment('successUrl');
28}
29
30function payInShopFailure() {
31    redirectAfterCardPayment('failureUrl');
32}
33
34/* BLIK */
35$(function(){
36    var $configElement;
37    var armed = false;
38
39    var commonError = function(selector) {
40        var $section = $('#p24-blik-section');
41        var $error = $section.find(selector);
42        $error.show();
43        $error.addClass('animate');
44        setTimeout(function () {
45            $error.removeClass('animate');
46        }, 2000);
47    };
48
49    var blikError = function() {
50        commonError('.error-code');
51    };
52
53    var regulationError = function() {
54        commonError('.error-regulation');
55    };
56
57    var regulationNoError = function() {
58        var $section = $('#p24-blik-section');
59        var $error = $section.find('.error-regulation');
60        $error.hide();
61    };
62
63    var prRegulationError = function() {
64        commonError('.error-pr-regulation');
65    };
66
67    var prRegulationNoError = function() {
68        var $section = $('#p24-blik-section');
69        var $error = $section.find('.error-pr-regulation');
70        $error.hide();
71    };
72
73    var executePaymentByBlikCode = function($form, cartId, blikCode) {
74        $form.find('button').prop('disabled', true);
75        var request = {
76            'action': 'executeBlik',
77            'cartId': cartId,
78            'blikCode': blikCode
79        };
80        $.ajax($configElement.data('ajaxurl'), {
81            method: 'POST', type: 'POST',
82            data: request,
83        }).success(function (response) {
84            var response = JSON.parse(response);
85            if (response.success || response.reload) {
86                var returnUrl = response.returnUrl;
87                /* We are giving few seconds for user to accept transaction. */
88                setTimeout(function() {window.location = returnUrl;}, 3000);
89            } else {
90                blikError();
91                $form.find('button').prop('disabled', false);
92            }
93        }).error(function () {
94            blikError();
95            $form.find('button').prop('disabled', false);
96        });
97    };
98
99    var checkRegulations = function ()
100    {
101        var $regulation;
102        $regulation = $('#p24_regulation_accept');
103        if (!$regulation.length) {
104            $regulation = $('#p24-blik-regulation-accept');
105        }
106        if (!$regulation.length) {
107            /* Not possible on valid site. */
108            return false;
109        }
110        if ($regulation.prop('checked')) {
111            regulationNoError();
112            return true;
113        } else {
114            regulationError();
115            return false;
116        }
117    };
118
119    var checkPrRegulations = function ()
120    {
121        var $regulation;
122        $regulation = $('#conditions_to_approve\\[terms-and-conditions\\]');
123        if (!$regulation.length) {
124            /* Accepted or not needed. */
125            return true;
126        }
127        if ($regulation.prop('checked')) {
128            prRegulationNoError();
129            return true;
130        } else {
131            prRegulationError();
132            return false;
133        }
134    };
135
136    var showBlikSection  = function() {
137        var $section = $('#p24-blik-section');
138        var $pad = $('#p24-additional-forms');
139        $section.appendTo($pad);
140        $section.show();
141        var cartId = $configElement.data('cartid');
142        var $form = $section.find('form');
143        $form.on('submit', function (e) {
144            e.preventDefault();
145            var regulations = checkRegulations();
146            var prRegulations = checkPrRegulations();
147            if (regulations && prRegulations) {
148                var blikCode = $section.find('input[name=blik]').val();
149                executePaymentByBlikCode($form, cartId, blikCode);
150            }
151        });
152    };
153
154    var hideBlikSection = function () {
155        var $section = $('#p24-blik-section');
156        $section.hide();
157    }
158
159    var tryArmBlikBoxPayment = function() {
160        var $masterMethodId = $('#master-active-payment-method');
161        $masterMethodId.on('change', function () {
162            var val = parseInt($masterMethodId.val());
163            if (181 === val) {
164                showBlikSection();
165            } else {
166                hideBlikSection();
167            }
168        });
169        armed = true;
170    };
171
172    var tryArmBlikBoxConfirmation = function() {
173        /* The id is too random to use. */
174        var $input = $('input[data-module-name=przelewy24-method-181]');
175        if ($input.length) {
176            var rawFormContainer = p24GetRawAdditionalFormsContainer();
177            $input.on('change', function (e) {
178                if (!$input.prop('checked')) {
179                    /* Nothing to do. */
180                    return;
181                }
182
183                var randomId = $input.attr('id');
184                var $container = $('#' + randomId + '-container');
185                var $formContainer = $(rawFormContainer);
186                $container.append($formContainer);
187                $formContainer.trigger('hide-old');
188                var hideOldEvent = new Event('hide-old');
189                rawFormContainer.dispatchEvent(hideOldEvent);
190                showBlikSection();
191            });
192            rawFormContainer.addEventListener('hide-old', function() {
193                hideBlikSection();
194            });
195
196            armed = true;
197        }
198    };
199
200    var tryArmBlikBox = function(retries) {
201        if (armed || retries <= 0) {
202            return;
203        }
204
205        $configElement = $('#p24-blik-config-element');
206        if ($configElement.length) {
207            var pageType = $configElement.data('pagetype');
208            switch (pageType) {
209                case 'payment':
210                    tryArmBlikBoxPayment();
211                    break;
212                case 'confirmation':
213                    tryArmBlikBoxConfirmation();
214                    break;
215            }
216        }
217
218        if (!armed) {
219            setTimeout(tryArmBlikBox, 1000, retries - 1);
220        }
221    };
222
223    tryArmBlikBox(10);
224});
225
226/* Card */
227$(function(){
228    var $configElement;
229    var armed = false;
230
231    var commonError = function(selector) {
232        var $section = $('#p24-card-section');
233        var $error = $section.find(selector);
234        $error.show();
235        $error.addClass('animate');
236        setTimeout(function () {
237            $error.removeClass('animate');
238        }, 2000);
239    };
240
241    var otherError = function () {
242        commonError('error-other');
243    }
244
245    var regulationError = function() {
246        commonError('.error-regulation');
247    };
248
249    var regulationNoError = function() {
250        var $section = $('#p24-card-section');
251        var $error = $section.find('.error-regulation');
252        $error.hide();
253    };
254
255    var prRegulationError = function() {
256        commonError('.error-pr-regulation');
257    };
258
259    var prRegulationNoError = function() {
260        var $section = $('#p24-card-section');
261        var $error = $section.find('.error-pr-regulation');
262        $error.hide();
263    };
264
265    var showCardLoader = function () {
266        $('.p24-card-loader').fadeIn(400);
267    }
268
269    function hideCardLoader() {
270        $('.p24-card-loader').fadeOut(300);
271    }
272
273    var register = function (cartId, method) {
274        if ('object' === typeof P24_Transaction) {
275            return;
276        }
277        var $formContainer = $('#P24FormContainer');
278        var termsAcceptRequired = $configElement.data('termsConfirmRequired');
279        if (termsAcceptRequired && !$('#p24-card-regulation-accept').is(':checked')) {
280            return;
281        }
282        showCardLoader();
283        $.ajax($configElement.data('ajaxurl'), {
284            method: 'POST',
285            type: 'POST',
286            data: {
287                action: 'register',
288                cartId: cartId,
289                method: method,
290            },
291        }).success(function (response) {
292            var response = JSON.parse(response);
293            if (response.script && response.signature) {
294                $formContainer.attr('data-sign', response.signature);
295                $.getScript(response.script, function () {
296                    P24_Transaction.init();
297                    hideCardLoader();
298                });
299            } else {
300                hideCardLoader();
301                commonError();
302            }
303        }).error(function () {
304            hideCardLoader();
305            payInShopFailure();
306        });
307    };
308
309    var checkRegulations = function ()
310    {
311        var $regulation;
312        $regulation = $('#p24_regulation_accept');
313        if (!$regulation.length) {
314            $regulation = $('#p24-card-regulation-accept');
315        }
316        if (!$regulation.length) {
317            /* Not possible on valid site. */
318            return false;
319        }
320        if ($regulation.prop('checked')) {
321            regulationNoError();
322            return true;
323        } else {
324            regulationError();
325            return false;
326        }
327    };
328
329    var checkPrRegulations = function ()
330    {
331        var $regulation;
332        $regulation = $('#conditions_to_approve\\[terms-and-conditions\\]');
333        if (!$regulation.length) {
334            /* Accepted or not needed. */
335            return true;
336        }
337        if ($regulation.prop('checked')) {
338            prRegulationNoError();
339            return true;
340        } else {
341            prRegulationError();
342            return false;
343        }
344    };
345
346    var getMethodId = function() {
347        var $masterMethodId = $('#master-active-payment-method');
348        var $primaryMethod = $('[data-module-name^="przelewy24-method-"]:checked');
349        if ($masterMethodId.length === 0 && $primaryMethod.length > 0) {
350            return parseInt($primaryMethod.data('moduleName').replace('przelewy24-method-', ''));
351        }
352
353        return parseInt($masterMethodId.val());
354    }
355
356    var showCardSection  = function() {
357        var $section = $('#p24-card-section');
358        var $pad = $('#p24-additional-forms');
359        $section.appendTo($pad);
360        $section.show();
361        register($configElement.data('cartid'), getMethodId());
362    };
363
364    var hideCardSection = function () {
365        var $section = $('#p24-card-section');
366        $section.hide();
367    }
368
369    var tryArmCardBoxPayment = function($configElement) {
370        var ids = $configElement.data('ids').split(',');
371
372        var $masterMethodId = $('#master-active-payment-method');
373        $masterMethodId.on('change', function () {
374            var val = parseInt($masterMethodId.val());
375            var notSelected = ids.every(function (id) {
376                id = parseInt(id);
377                return id !== val;
378            });
379            if (notSelected) {
380                hideCardSection();
381            } else {
382                showCardSection();
383            }
384        });
385
386        armed = true;
387    }
388
389    var tryArmCardBoxConfirmationOne = function(id) {
390        /* It could be armed for different card id. */
391        if (armed) {
392            return;
393        }
394
395        /* The id is too random to use. */
396        var $input = $('input[data-module-name=przelewy24-method-' + id + ']');
397        if ($input.length) {
398            var rawFormContainer = p24GetRawAdditionalFormsContainer();
399            $input.on('change', function (e) {
400                if (!$input.prop('checked')) {
401                    /* Nothing to do. */
402                    return;
403                }
404
405                var randomId = $input.attr('id');
406                var $container = $('#' + randomId + '-container');
407                var $formContainer = $(rawFormContainer);
408                $container.append($formContainer);
409                $formContainer.trigger('hide-old');
410                var hideOldEvent = new Event('hide-old');
411                rawFormContainer.dispatchEvent(hideOldEvent);
412                showCardSection();
413            });
414            rawFormContainer.addEventListener('hide-old', function() {
415                hideCardSection();
416            });
417
418            armed = true;
419        }
420    };
421
422    var tryArmCardBoxConfirmation = function() {
423        var ids = $configElement.data('ids').split(',');
424        ids.forEach(function (id) {
425            tryArmCardBoxConfirmationOne(id);
426        });
427    };
428
429    var tryArmCardBox = function(retries) {
430        if (armed || retries <= 0) {
431            return;
432        }
433
434        $configElement = $('#p24-card-config-element');
435        $(document).on('change', '#p24-card-regulation-accept', function() {
436            if ($(this).is(':checked')) {
437                $('#P24FormContainer').show();
438                register($configElement.data('cartid'), getMethodId());
439            } else {
440                $('#P24FormContainer').hide();
441            }
442        });
443        if ($configElement.length) {
444            var pageType = $configElement.data('pagetype');
445            switch (pageType) {
446                case 'payment':
447                    tryArmCardBoxPayment($configElement);
448                    break;
449                case 'confirmation':
450                    tryArmCardBoxConfirmation();
451                    break;
452            }
453        }
454
455        if (!armed) {
456            setTimeout(tryArmCardBox, 1000, retries - 1);
457        }
458    };
459
460    tryArmCardBox(10);
461});
462
463/* Other methods: from Przelewy24 and other vendors */
464$(function(){
465    var armed = false;
466
467    var checkForBlikOrCard = function ($configElement, number) {
468        /* This list is not empty. */
469        var ids = $configElement.data('cardIds').split(',');
470        ids.push('181'); /* Blik */
471        number = number.toString();
472
473        return ids.indexOf(number) >= 0;
474    };
475
476    var tryArmOtherConfirmation = function ($configElement) {
477        var rawFormContainer = p24GetRawAdditionalFormsContainer();
478        var paymentOptions = document.querySelectorAll('input[name=payment-option]');
479        paymentOptions.forEach(function (elm) {
480            var needArming;
481            var result = /^przelewy24-method-(\d+)$/.exec(elm.dataset.moduleName);
482            if (result) {
483                needArming = !checkForBlikOrCard($configElement, parseInt(result[1]));
484            } else {
485                /* Different module. */
486                needArming = true;
487            }
488
489            console.log(elm.dataset.moduleName, needArming)
490
491            if (needArming) {
492                elm.addEventListener('change', function (e) {
493                    var hideOldEvent = new Event('hide-old');
494                    rawFormContainer.dispatchEvent(hideOldEvent);
495                });
496            }
497        });
498
499        armed = true;
500    };
501
502    var tryArmOther = function(retries) {
503        if (armed || retries <= 0) {
504            return;
505        }
506
507        $configElement = $('#p24-other-config-element');
508        if ($configElement.length) {
509            var pageType = $configElement.data('pagetype');
510            switch (pageType) {
511                case 'confirmation':
512                    tryArmOtherConfirmation($configElement);
513                    break;
514            }
515        }
516
517        if (!armed) {
518            setTimeout(tryArmOther, 1000, retries - 1);
519        }
520    };
521
522    tryArmOther(10);
523});

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.