1/* 2* @author Przelewy24 3* @copyright Przelewy24 4* @license https://www.gnu.org/licenses/lgpl-3.0.en.html 5*/ 6 7$(function(){ 8 var $paymentBox; 9 var $configElement; 10 var armed = false; 11 12 var blikError = function() { 13 var $modal = $('#p24-blik-modal'); 14 $modal.removeClass('loading'); 15 $modal.find('.error').show(); 16 }; 17 18 var executePaymentByBlikCode = function(currencySuffix, token, blikCode) { 19 var request = { 20 'action': 'executePaymentByBlikCode', 21 'currencySuffix': currencySuffix, 22 'token': token, 23 'blikCode': blikCode 24 }; 25 $.ajax($configElement.data('ajaxurl'), { 26 method: 'POST', type: 'POST', 27 data: request, 28 }).success(function (response) { 29 var response = JSON.parse(response); 30 31 if (response.success) { 32 var returnUrl = $configElement.data('returnurl'); 33 /* We are giving few seconds for user to accept transaction. */ 34 setTimeout(function() {window.location = returnUrl;}, 3000); 35 } else { 36 blikError(); 37 } 38 }).error(blikError); 39 }; 40 41 var trnRegister = function(cartId) { 42 var request = { 43 'action': 'trnRegister', 44 'cartId': cartId 45 }; 46 /* The xhr from jQuery do not have responseURL. */ 47 var redirectHackXhr = new XMLHttpRequest(); 48 $.ajax($configElement.data('ajaxurl'), { 49 method: 'POST', type: 'POST', 50 data: request, 51 xhr: function() {return redirectHackXhr;} 52 }).success(function (response) { 53 try { 54 response = JSON.parse(response); 55 } catch (e) { 56 /* Assume 302 or something like that. */ 57 location = redirectHackXhr.responseURL; 58 return; 59 } 60 if (response.success) { 61 var $modal = $('#p24-blik-modal'); 62 $modal.removeClass('loading'); 63 var $button = $modal.find('button'); 64 $button.on('click', function (e) { 65 e.preventDefault(); 66 var $input = $modal.find('input'); 67 var code = $input.val(); 68 if (/^\d{6}$/.test(code)) { 69 $modal.addClass('loading'); 70 executePaymentByBlikCode(response.currencySuffix, response.token, code); 71 } else { 72 $modal.find('.error').show(); 73 } 74 }); 75 } 76 }); 77 }; 78 79 var tryArmBlikBoxPaymentGraphical = function($configElement) { 80 var $paymentBox = $('a.bank-box[data-id=181]'); 81 if ($paymentBox.length) { 82 var clickFunction = function (e) { 83 if (!$paymentBox.hasClass('selected')) { 84 /* Nothing to do. */ 85 return; 86 } 87 var $regulation = $('#p24_regulation_accept'); 88 if ($regulation.length) { 89 var regulationAccepted = $regulation.prop('checked'); 90 if (!regulationAccepted) { 91 /* Nothing to do. */ 92 return; 93 } 94 } 95 e.preventDefault(); 96 var $modal = $('#p24-blik-modal'); 97 $modal.addClass('loading'); 98 $('#p24-blik-modal-background').show(); 99 var cartId = $configElement.data('cartid'); 100 trnRegister(cartId); 101 } 102 $paymentBox.on('click', function (e) { 103 /* There may be an event we want to execute first. */ 104 setTimeout(clickFunction, 100, e); 105 }); 106 107 armed = true; 108 } 109 } 110 111 var tryArmBlikBoxPaymentTextual = function($configElement) { 112 var $paymentInput = $('input#paymethod-bank-id-181'); 113 if ($paymentInput.length) { 114 $paymentInput.on('change', function (e) { 115 var $regulation = $('#p24_regulation_accept'); 116 if ($regulation.length) { 117 var regulationAccepted = $regulation.prop('checked'); 118 if (!regulationAccepted) { 119 /* Nothing to do. */ 120 return; 121 } 122 } 123 if ($paymentInput.prop('checked')) { 124 var $modal = $('#p24-blik-modal'); 125 $modal.addClass('loading'); 126 $('#p24-blik-modal-background').show(); 127 var cartId = $configElement.data('cartid'); 128 trnRegister(cartId); 129 } 130 }); 131 132 armed = true; 133 } 134 }; 135 136 var tryArmBlikBoxConfirmation = function($configElement) { 137 /* The id is too random to use. */ 138 var $input = $('input[data-module-name=przelewy24-method-181]'); 139 if ($input.length) { 140 var $regulation = $('#conditions_to_approve\\[terms-and-conditions\\]'); 141 $input.on('change', function (e) { 142 if (!$input.prop('checked')) { 143 /* Nothing to do. */ 144 return; 145 } 146 if ($regulation.length) { 147 var regulationAccepted = $regulation.prop('checked'); 148 if (!regulationAccepted) { 149 /* Nothing to do. */ 150 return; 151 } 152 } 153 var $modal = $('#p24-blik-modal'); 154 $modal.addClass('loading'); 155 $('#p24-blik-modal-background').show(); 156 var cartId = $configElement.data('cartid'); 157 trnRegister(cartId); 158 }); 159 if ($regulation.length) { 160 $regulation.on('change', function (e) { 161 $input.trigger('change'); 162 }); 163 } 164 165 armed = true; 166 } 167 }; 168 169 var tryArmBlikBox = function(retries) { 170 if (armed || retries <= 0) { 171 return; 172 } 173 174 $configElement = $('#p24-blik-config-element'); 175 if ($configElement.length) { 176 var pageType = $configElement.data('pagetype'); 177 switch (pageType) { 178 case 'payment': 179 /* We have to check both methods. */ 180 tryArmBlikBoxPaymentGraphical($configElement); 181 tryArmBlikBoxPaymentTextual($configElement); 182 break; 183 case 'confirmation': 184 tryArmBlikBoxConfirmation($configElement); 185 break; 186 } 187 } 188 189 if (!armed) { 190 setTimeout(tryArmBlikBox, 1000, retries - 1); 191 } 192 }; 193 194 tryArmBlikBox(10); 195});
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.