1var TBPagePayment = function (options) { 2 this.settings = $.extend({ 3 formSelector: '#payment-form', 4 tiktokPixelId: '' 5 }, options); 6 this.form = $(this.settings.formSelector); 7 this._inited = false; 8 this._xenditError = false; 9 this.tiktokPixelId = ''; 10 11 this.updateOptions = (options) => { 12 this.settings = $.extend(this.settings, options); 13 }; 14 15 this.getPaymentType = () => { 16 return $(this.form).find('.nav-link.active').attr('payment-type'); 17 }; 18 this.defaultDisplayError = (err) => { 19 TBPage.unblockElement(this.form); 20 $('#three-ds-container').hide(); 21 $('.overlay').hide(); 22 if (typeof err == 'string') { 23 if (err != '') { 24 if (err != 'AUTHENTICATION_FAILED') { 25 TBPage.showError(err); 26 } 27 } 28 } else { 29 TBPage.showError(err.message); 30 } 31 }; 32 this.onError = (err) => { 33 if (typeof this.settings.onError == 'function') { 34 this.settings.onError(err); 35 } else { 36 this.defaultDisplayError(err); 37 } 38 }; 39 this.block = () => { 40 return TBPage.blockElement(this.form); 41 }; 42 this.unblock = () => { 43 return TBPage.unblockElement(this.form); 44 }; 45 this.ajaxSubmit = async () => { 46 this._xenditError = false; 47 var postData = await this.getPostData(); 48 var submitUrl = this.settings.submitUrl; 49 if (this._xenditError !== false) { 50 return; 51 } 52 this.block(); 53 54 // var skipPayment = false; 55 // if (parseInt(postData.amount) > 0) { 56 // skipPayment = true; 57 // } 58 (function (tbPayment) { 59 $.ajax({ 60 url: submitUrl, 61 method: 'post', 62 dataType: 'json', 63 data: postData, 64 success: function (response) { 65 TBPage.handleResponse(response, function (data) { 66 if (typeof tbPayment.settings.onSuccess == 'function') { 67 tbPayment.settings.onSuccess(tbPayment, data); 68 } 69 }, tbPayment.onError); 70 }, 71 error: function (jqXHR, exception) { 72 var msg = ''; 73 if (jqXHR.status === 0) { 74 msg = 'Not connect.\n Verify Network.'; 75 } else if (jqXHR.status == 404) { 76 msg = 'Requested page not found. [404]'; 77 } else if (jqXHR.status == 500) { 78 msg = 'Internal Server Error [500].'; 79 } else if (exception === 'parsererror') { 80 msg = 'Requested JSON parse failed.'; 81 } else if (exception === 'timeout') { 82 msg = 'Time out error.'; 83 } else if (exception === 'abort') { 84 msg = 'Ajax request aborted.'; 85 } else { 86 msg = 'Uncaught Error.\n' + jqXHR.responseText; 87 } 88 tbPayment.onError(msg); 89 }, 90 complete: function () { 91 tbPayment.unblock(); 92 } 93 94 }); 95 }(this)); 96 }; 97 98 this.validate = () => { 99 let errCode = 0; 100 let errMessage = ''; 101 let paymentType = this.getPaymentType(); 102 103 let needSkipPayment = false; 104 let amount = parseFloat(this.getAmount()); 105 if (this.settings.allowFree == true) { 106 if (amount <= 0) { 107 needSkipPayment = true; 108 } 109 } 110 111 if (!needSkipPayment) { 112 if (errCode == 0) { 113 if (typeof paymentType != 'string' || paymentType == '') { 114 errCode++; 115 errMessage = 'Please select payment type'; 116 } 117 } 118 if (errCode == 0) { 119 if (paymentType == 'va') { 120 let bank = this.getBank(); 121 if (typeof bank != 'string' || bank == '') { 122 errCode++; 123 errMessage = 'Please select bank'; 124 } 125 } 126 } 127 if(errCode==0) { 128 if(paymentType=='eWallet') { 129 let eWalletSelected = this.getEwallet(); 130 if (eWalletSelected == undefined) { 131 errCode++; 132 errMessage = 'Please select eWallet type'; 133 } 134 135 if (errCode == 0 && eWalletSelected.toLowerCase() === 'ovo') { 136 let ovoPhone = this.getOvoPhone(); 137 if (typeof ovoPhone != 'string' || ovoPhone == '') { 138 errCode++; 139 errMessage = 'Please input phone number'; 140 } 141 } 142 } 143 } 144 if(errCode==0) { 145 if(paymentType=='e-money') {
146 let emoneyType = this.getEmoneyType(); 147 if(typeof emoneyType != 'string' || emoneyType=='') { 148 errCode++; 149 errMessage='Please choose qris'; 150 } 151 } 152 } 153 if(errCode==0) { 154 if(paymentType=='cc') { 155 let creditCardNumber = this.getCreditCardNumber(); 156 let creditCardMonthExpired = this.getCreditCardMonthExpired(); 157 let creditCardYearExpired = this.getCreditCardYearExpired(); 158 let creditCardCVV = this.getCreditCardCVV(); 159 if (typeof creditCardNumber != 'string' || creditCardNumber == '') { 160 errCode++; 161 errMessage = 'Please input credit card number'; 162 } 163 if (typeof creditCardMonthExpired != 'string' || creditCardMonthExpired == '') { 164 errCode++; 165 errMessage = 'Please input credit card expired month'; 166 } 167 if (typeof creditCardYearExpired != 'string' || creditCardYearExpired == '') { 168 errCode++; 169 errMessage = 'Please input credit card expired year'; 170 } 171 if (typeof creditCardCVV != 'string' || creditCardCVV == '') { 172 errCode++; 173 errMessage = 'Please input credit card cvv'; 174 } 175 } 176 } 177 } 178 179 if (errCode > 0) { 180 this.onError(errMessage); 181 return false; 182 } 183 return true; 184 }; 185 186 this.getAmount = () => { 187 var amountSelector = this.settings.amountSelector ? this.settings.amountSelector : '#amount'; 188 return this.form.find(amountSelector).val(); 189 }; 190 this.getFee = () => { 191 var feeSelector = this.settings.feeSelector ? this.settings.feeSelector : '#fee'; 192 return this.form.find(feeSelector).val(); 193 }; 194 this.isFeeChief = () => { 195 var feeChief = this.settings.isFeeChief ? this.settings.isFeeChief : '0'; 196 return feeChief == '1'; 197 }; 198 199 this.getCreditCardNumber = () => { 200 return this.form.find('#cardNumber').val(); 201 }; 202 this.getCreditCardMonthExpired = () => { 203 return this.form.find('#monthExpired').val(); 204 }; 205 this.getCreditCardYearExpired = () => { 206 let yearExpired = this.form.find('#yearExpired').val(); 207 if (yearExpired.length == 2) { 208 yearExpired = '20' + yearExpired; 209 } 210 return yearExpired; 211 }; 212 this.getCreditCardCVV = () => { 213 return this.form.find('#cvn').val(); 214 }; 215 216 this.getTokenData = () => { 217 return { 218 amount: this.getAmount(), 219 card_number: this.getCreditCardNumber(), 220 card_exp_month: this.getCreditCardMonthExpired(), 221 card_exp_year: this.getCreditCardYearExpired(), 222 card_cvn: this.getCreditCardCVV(), 223 is_multiple_use: true, 224 should_authenticate: true 225 }; 226 }; 227 this.getCreditCardData = async () => { 228 var promise = new Promise((resolve, reject) => { 229 var tokenData = this.getTokenData(); 230 let creditCardData = {}; 231 Xendit.card.createToken(tokenData, (err, xenditToken) => { 232 if (err) { 233 console.log('error on response handler'); 234 this.onError(err); 235 this._xenditError = err; 236 resolve(null); 237 } else if (xenditToken.status === 'APPROVED' || xenditToken.status === 'VERIFIED') { 238 if (typeof this.settings.tiktokPixelId != 'undefined' && this.settings.tiktokPixelId.length > 0) { 239 ttq.track('InitiateCheckout'); 240 } 241 var authenticationData = {}; 242 authenticationData.token_id = xenditToken.id; 243 authenticationData.amount = parseInt(this.getAmount()) + parseInt(this.getFee()); 244 if (this.isFeeChief()) { 245 authenticationData.amount = parseInt(this.getAmount()); 246 } 247 authenticationData.card_cvn = this.form.find('#card-cvn').val();
248 creditCardData.tokenId = xenditToken.id; 249 creditCardData.maskedCardNumber = xenditToken.masked_card_number; 250 creditCardData.tokenData = xenditToken; 251 Xendit.card.createAuthentication(authenticationData, (err, creditCardCharge) => { 252 if (err) { 253 console.log('error on auth handler'); 254 this._xenditError = err; 255 this.onError(err); 256 resolve(null); 257 } else { 258 creditCardData.chargeData = creditCardCharge; 259 if (creditCardCharge.status === 'APPROVED' || creditCardCharge.status === 'VERIFIED') { 260 resolve(creditCardData); 261 } else if (creditCardCharge.status === 'IN_REVIEW') { 262 window.open(creditCardCharge.payer_authentication_url, 'sample-inline-frame'); 263 $('.overlay').show(); 264 $('#three-ds-container').show(); 265 } else if (creditCardCharge.status === 'FRAUD') { 266 this.onError(creditCardCharge.failure_reason); 267 this._xenditError = creditCardCharge.failure_reason; 268 resolve(null); 269 } else if (creditCardCharge.status === 'FAILED') { 270 this.onError(creditCardCharge.failure_reason); 271 this._xenditError = creditCardCharge.failure_reason; 272 resolve(null); 273 } else { 274 this.onError('Unknown Error tbPayment'); 275 this._xenditError = 'Unknown Error tbPayment'; 276 resolve(null); 277 } 278 } 279 }); 280 } else if (xenditToken.status === 'IN_REVIEW') { 281 window.open(xenditToken.payer_authentication_url, 'sample-inline-frame'); 282 $('.overlay').show(); 283 $('#three-ds-container').show(); 284 //resolve(null); 285 } else if (xenditToken.status === 'FRAUD') { 286 this.onError(xenditToken.failure_reason); 287 this._xenditError = xenditToken.failure_reason; 288 resolve(null); 289 } else if (xenditToken.status === 'FAILED') { 290 this.onError(xenditToken.failure_reason); 291 this._xenditError = xenditToken.failure_reason; 292 resolve(null); 293 } else { 294 this.onError('Unknown Error tbPayment'); 295 this._xenditError = 'Unknown Error tbPayment'; 296 resolve(null); 297 } 298 }); 299 }); 300 301 302 var creditCardData = await promise; 303 304 $('#three-ds-container').hide(); 305 $('.overlay').hide(); 306 return creditCardData; 307 }; 308 309 this.getBank = () => { 310 return $('input[name="va_bank"]:checked').val(); 311 }; 312 313 this.getEwallet = () => { 314 return $('input[name="eWallet"]:checked').val(); 315 }; 316 317 this.getEmoneyType = () => { 318 return $('input[name="e-money"]:checked').val(); 319 }; 320 321 this.getOvoPhone = () => { 322 return $('#ovo-phone').val(); 323 }; 324 this.getPaymentData = async () => { 325 var paymentData = {}; 326 var paymentType = this.getPaymentType(); 327 328 var amount = this.getAmount(); 329 330 if (parseInt(amount) === 0 && this.settings.allowNullPaymentType == true) { 331 paymentType = null; 332 } 333 334 if (paymentType == 'va') { 335 paymentData.bank = this.getBank(); 336 } 337 if (paymentType == 'e-money') { 338 paymentData.emoneyType = this.getEmoneyType(); 339 } 340 if (paymentType == 'eWallet') { 341 paymentData.ewalletType = this.getEwallet(); 342 paymentData.ovoPhone = this.getOvoPhone(); 343 } 344 if (paymentType == 'cc') {
345 var creditCardData = await this.getCreditCardData(); 346 347 if (creditCardData) { 348 paymentData.tokenId = creditCardData.tokenId; 349 paymentData.maskedCardNumber = creditCardData.maskedCardNumber; 350 paymentData.authenticationId = creditCardData.chargeData.id; 351 } 352 } 353 354 paymentData.paymentType = paymentType; 355 return paymentData; 356 }; 357 this.getPostData = async () => { 358 var request = {}; 359 if (this.settings.additionalData) { 360 let data = this.settings.additionalData; 361 if (typeof data == 'function') { 362 data = data(); 363 } 364 365 for (var key in data) { 366 if (data.hasOwnProperty(key)) { 367 let dataVal = data[key]; 368 if (typeof dataVal == 'function') { 369 request[key] = dataVal(); 370 } else { 371 request[key] = dataVal; 372 } 373 } 374 } 375 } 376 377 378 let needSkipPayment = false; 379 let amount = parseFloat(this.getAmount()); 380 if (this.settings.allowFree == true) { 381 if (amount <= 0) { 382 needSkipPayment = true; 383 } 384 } 385 let paymentData = {}; 386 if (!needSkipPayment) { 387 paymentData = await this.getPaymentData(); 388 } 389 390 request = $.extend(request, paymentData); 391 request.amount = amount; 392 request.fee = this.getFee(); 393 return request; 394 }; 395 396 this.loadXenditJs = () => { 397 return new Promise((resolve, reject) => { 398 cresenity.loadJs('https://js.xendit.co/v1/xendit.min.js', () => { 399 Xendit.setPublishableKey(this.settings.xenditPublicApiKey); 400 resolve(Xendit); 401 }); 402 }); 403 }; 404 this.submitXendit = () => { 405 if (this.validate()) { 406 this.ajaxSubmit(); 407 } 408 }; 409 this.init = async () => { 410 if (!this._inited) { 411 await this.loadXenditJs(); 412 413 (function (tbPayment) { 414 tbPayment.form.submit(function (event) { 415 event.preventDefault(); 416 417 tbPayment.submitXendit(); 418 }); 419 }(this)); 420 421 $('.option-payment-radio').click(function () { 422 var dataOption = $(this).attr('data-option'); 423 $('.option-payment-detail').addClass('d-none'); 424 if (dataOption) { 425 $('.option-payment-detail-' + dataOption).removeClass('d-none'); 426 } 427 }); 428 429 if (typeof this.settings.onInit == 'function') { 430 this.settings.onInit(this); 431 } 432 this._inited = true; 433 } 434 }; 435};
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.