1function PffPaystackFee() 2{ 3 4 this.DEFAULT_PERCENTAGE = 0.015; 5 this.DEFAULT_ADDITIONAL_CHARGE = 10000; 6 this.DEFAULT_THRESHOLD = 250000; 7 this.DEFAULT_CAP = 200000; 8 9 this.__initialize = function () { 10 11 this.percentage = this.DEFAULT_PERCENTAGE; 12 this.additional_charge = this.DEFAULT_ADDITIONAL_CHARGE; 13 this.threshold = this.DEFAULT_THRESHOLD; 14 this.cap = this.DEFAULT_CAP; 15 16 if (window && window.KKD_PAYSTACK_CHARGE_SETTINGS) { 17 this.percentage = window.KKD_PAYSTACK_CHARGE_SETTINGS.percentage; 18 this.additional_charge = window.KKD_PAYSTACK_CHARGE_SETTINGS.additional_charge; 19 this.threshold = window.KKD_PAYSTACK_CHARGE_SETTINGS.threshold; 20 this.cap = window.KKD_PAYSTACK_CHARGE_SETTINGS.cap; 21 } 22 23 } 24 25 this.chargeDivider = 0; 26 this.crossover = 0; 27 this.flatlinePlusCharge = 0; 28 this.flatline = 0; 29 30 this.withPercentage = function (percentage) { 31 this.percentage = percentage; 32 this.__setup(); 33 }; 34 35 this.withAdditionalCharge = function (additional_charge) { 36 this.additional_charge = additional_charge; 37 this.__setup(); 38 }; 39 40 this.withThreshold = function (threshold) { 41 this.threshold = threshold; 42 this.__setup(); 43 }; 44 45 this.withCap = function (cap) { 46 this.cap = cap; 47 this.__setup(); 48 }; 49 50 this.__setup = function () { 51 this.__initialize(); 52 this.chargeDivider = this.__chargeDivider(); 53 this.crossover = this.__crossover(); 54 this.flatlinePlusCharge = this.__flatlinePlusCharge(); 55 this.flatline = this.__flatline(); 56 }; 57 58 this.__chargeDivider = function () { 59 return 1 - this.percentage; 60 }; 61 62 this.__crossover = function () { 63 return this.threshold * this.chargeDivider - this.additional_charge; 64 }; 65 66 this.__flatlinePlusCharge = function () { 67 return (this.cap - this.additional_charge) / this.percentage; 68 }; 69 70 this.__flatline = function () { 71 return this.flatlinePlusCharge - this.cap; 72 }; 73 74 this.addFor = function (amountinkobo) { 75 if (amountinkobo > this.flatline) { 76 return parseInt(Math.round(amountinkobo + this.cap)); 77 } else if (amountinkobo > this.crossover) { 78 return parseInt( 79 Math.round((amountinkobo + this.additional_charge) / this.chargeDivider) 80 ); 81 } else { 82 return parseInt(Math.round(amountinkobo / this.chargeDivider)); 83 } 84 }; 85 86 this.__setup = function () { 87 this.chargeDivider = this.__chargeDivider(); 88 this.crossover = this.__crossover(); 89 this.flatlinePlusCharge = this.__flatlinePlusCharge(); 90 this.flatline = this.__flatline(); 91 }; 92 93 this.__setup(); 94} 95 96(function ($) { 97 "use strict"; 98 $(document).ready( 99 function ($) { 100 101 /*if ( 0 < $(".date-picker").length ) { 102 $(".date-picker").each( function() { 103 $(".date-picker").datepicker( 104 { 105 dateFormat: "mm/dd/yy", 106 prevText: '<i class="fa fa-caret-left"></i>', 107 nextText: '<i class="fa fa-caret-right"></i>' 108 } 109 ); 110 } ); 111 }*/ 112 113 if ( $("#pf-vamount").length ) { 114 var amountField = $("#pf-vamount"); 115 calculateTotal(); 116 } else { 117 var amountField = $("#pf-amount"); 118 } 119 var max = 10; 120 amountField.keydown( 121 function (e) { 122 format_validate(max, e); 123 } 124 ); 125 126 amountField.keyup( 127 function (e) { 128 checkMinimumVal(); 129 } 130 ); 131 132 $.fn.digits = function () { 133 return this.each( 134 function () { 135 $(this).text( 136 $(this) 137 .text() 138 .replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") 139 ); 140 } 141 ); 142 }; 143 144 calculateFees(); 145 146 $(".pf-number").keydown( 147 function (event) { 148 if (event.keyCode == 46 149 || event.keyCode == 8 150 || event.keyCode == 9 151 || event.keyCode == 27 152 || event.keyCode == 13 153 || (event.keyCode == 65 && event.ctrlKey === true) 154 || (event.keyCode >= 35 && event.keyCode <= 39) 155 ) { 156 return; 157 } else { 158 if (event.shiftKey 159 || ((event.keyCode < 48 || event.keyCode > 57) 160 && (event.keyCode < 96 || event.keyCode > 105)) 161 ) { 162 event.preventDefault(); 163 } 164 } 165 } 166 ); 167 168 if ($("#pf-quantity").length) { 169 $( "#pf-quantity" ).on( 'change', function(event){ 170 checkMinimumVal(); 171 } ); 172 calculateTotal(); 173 }; 174 175 $("#pf-quantity, #pf-vamount, #pf-amount").on( 176 "change", function () { 177 calculateTotal(); 178 calculateFees(); 179 } 180 ); 181 182 $(".paystack-form").on( 183 "submit", function (e) { 184 var requiredFieldIsInvalid = false;
185 e.preventDefault(); 186 187 $("#pf-agreementicon").removeClass("rerror"); 188 189 $(this) 190 .find("input, select, textarea") 191 .each( 192 function () { 193 $(this).removeClass("rerror"); //.css({ "border-color":"#d1d1d1" }); 194 } 195 ); 196 var email = $(this) 197 .find("#pf-email") 198 .val(); 199 200 var amount; 201 if ($("#pf-vamount").length) { 202 amount = $("#pf-vamount").val(); 203 calculateTotal(); 204 } else { 205 amount = $(this) 206 .find("#pf-amount") 207 .val(); 208 } 209 210 if (Number(amount) > 0) { 211 } else { 212 $(this) 213 .find("#pf-amount,#pf-vamount") 214 .addClass("rerror"); // css({ "border-color":"red" }); 215 $("html,body").animate( 216 { scrollTop: $(".rerror").offset().top - 110 }, 217 500 218 ); 219 return false; 220 } 221 if (!validateEmail(email)) { 222 $(this) 223 .find("#pf-email") 224 .addClass("rerror"); //.css({ "border-color":"red" }); 225 $("html,body").animate( 226 { scrollTop: $(".rerror").offset().top - 110 }, 227 500 228 ); 229 return false; 230 } 231 232 if (checkMinimumVal() == false) { 233 $(this) 234 .find("#pf-amount") 235 .addClass("rerror"); //.css({ "border-color":"red" }); 236 $("html,body").animate( 237 { scrollTop: $(".rerror").offset().top - 110 }, 238 500 239 ); 240 return false; 241 } 242 243 $(this) 244 .find("input, select, text, textarea") 245 .filter("[required]") 246 .filter( 247 function () { 248 return this.value === ""; 249 } 250 ) 251 .each( 252 function () { 253 $(this).addClass("rerror"); 254 requiredFieldIsInvalid = true; 255 } 256 ); 257 258 if ($("#pf-agreement").length && !$("#pf-agreement").is(":checked")) { 259 $("#pf-agreementicon").addClass("rerror"); 260 requiredFieldIsInvalid = true; 261 } 262 263 if (requiredFieldIsInvalid) { 264 $("html,body").animate( 265 { scrollTop: $(".rerror").offset().top - 110 }, 266 500 267 ); 268 return false; 269 } 270 271 var self = $(this); 272 var $form = $(this); 273 274 $.blockUI({ message: "Please wait..." }); 275 276 var formdata = new FormData(this); 277 278 $.ajax( 279 { 280 url: $form.attr("action"), 281 type: "POST", 282 data: formdata, 283 mimeTypes: "multipart/form-data", 284 contentType: false, 285 cache: false, 286 processData: false, 287 dataType: "JSON", 288 success: function (data) { 289 $.unblockUI(); 290 291 data.custom_fields.push( 292 { 293 "display_name": "Plugin", 294 "variable_name": "plugin", 295 "value": "pff-paystack" 296 } 297 ) 298 if ( data.result == "success" ) { 299 var names = data.name.split(" "); 300 var firstName = names[0] || ""; 301 var lastName = names[1] || ""; 302 var quantity = data.quantity; 303 304 $("#pf-nonce").val(data.invoiceNonce); 305 306 if (data.plan == "none" || data.plan == "" || data.plan == "no") { 307 var handler = PaystackPop.setup( 308 { 309 key: pffSettings.key, 310 email: data.email, 311 amount: data.total, 312 firstname: firstName, 313 lastname: lastName, 314 currency: data.currency, 315 subaccount: data.subaccount, 316 bearer: data.txnbearer, 317 transaction_charge: data.transaction_charge, 318 ref: data.code, 319 metadata: { custom_fields: data.custom_fields }, 320 callback: function (response) { 321 $.blockUI({ message: "Please wait..." }); 322 $.post( 323 $form.attr("action"), 324 { 325 action: "pff_paystack_confirm_payment", 326 code: response.trxref, 327 quantity: quantity, 328 nonce: data.confirmNonce 329 }, 330 function (newdata) { 331 data = JSON.parse(newdata); 332 if (data.result == "success2") { 333 window.location.href = data.link; 334 } 335 if (data.result == "success") { 336 $(".paystack-form")[0].reset(); 337 $("html,body").animate( 338 { scrollTop: $(".paystack-form").offset().top - 110 }, 339 500 340 ); 341 342 self.before('<div class="alert-success">' + data.message + '</div>'); 343 $(this) 344 .find("input, select, textarea") 345 .each( 346 function () { 347 $(this).css( 348 { 349 "border-color": "#d1d1d1", 350 "background-color": "#fff" 351 } 352 ); 353 } 354 ); 355 calculateFees(); 356 357 $.unblockUI(); 358 } else { 359 self.before('<div class="alert-danger">' + data.message + '</div>'); 360 $.unblockUI(); 361 } 362 } 363 ); 364 }, 365 onClose: function () { } 366 } 367 ); 368 } else { 369 var handler = PaystackPop.setup( 370 { 371 key: pffSettings.key, 372 email: data.email, 373 plan: data.plan, 374 firstname: firstName, 375 lastname: lastName, 376 ref: data.code, 377 currency: data.currency, 378 subaccount: data.subaccount, 379 bearer: data.txnbearer, 380 transaction_charge: data.transaction_charge, 381 metadata: { custom_fields: data.custom_fields }, 382 callback: function (response) { 383 $.blockUI({ message: "Please wait..." }); 384 $.post( 385 $form.attr("action"), 386 { 387 action: "pff_paystack_confirm_payment", 388 code: response.trxref, 389 nonce: data.confirmNonce 390 }, 391 function (newdata) { 392 data = JSON.parse(newdata); 393 if (data.result == "success2") { 394 window.location.href = data.link; 395 } 396 if (data.result == "success") { 397 $(".paystack-form")[0].reset(); 398 $("html,body").animate( 399 { scrollTop: $(".paystack-form").offset().top - 110 }, 400 500 401 ); 402 403 self.before('<div class="alert-success">' + data.message + '</div>'); 404 $(this) 405 .find("input, select, textarea") 406 .each( 407 function () { 408 $(this).css( 409 { 410 "border-color": "#d1d1d1", 411 "background-color": "#fff" 412 } 413 ); 414 } 415 ); 416 calculateFees(); 417 418 $.unblockUI(); 419 } else { 420 self.before('<div class="alert-danger">' + data.message + '</div>'); 421 $.unblockUI(); 422 } 423 } 424 ); 425 }, 426 onClose: function () { } 427 } 428 ); 429 } 430 431 handler.openIframe(); 432 } else { 433 alert(data.error_message); 434 } 435 436 }, 437 error: function (xhr, status, error) { 438 console.log("An error occurred"); 439 console.log("XHR: ", xhr); 440 console.log("Status: ", status); 441 console.log("Error: ", error); 442 } 443 } 444 ); 445 } 446 ); 447 448 $(".retry-form").on( 449 "submit", function (e) { 450 var self = $(this); 451 var $form = $(this); 452 e.preventDefault(); 453 454 $.blockUI({ message: "Please wait..." }); 455 456 var formdata = new FormData(this); 457 458 $.ajax( 459 { 460 url: $form.attr("action"), 461 type: "POST", 462 data: formdata, 463 mimeTypes: "multipart/form-data", 464 contentType: false, 465 cache: false, 466 processData: false, 467 dataType: "JSON", 468 success: function (data) { 469 data.custom_fields.push( 470 { 471 "display_name": "Plugin", 472 "variable_name": "plugin", 473 "value": "pff-paystack" 474 } 475 ) 476 $.unblockUI(); 477 if (data.result == "success") { 478 var names = data.name.split(" "); 479 var firstName = names[0] || ""; 480 var lastName = names[1] || ""; 481 var quantity = data.quantity; 482 483 $("#pf-nonce").val(data.retryNonce); 484 485 if (data.plan == "none" || data.plan == "" || data.plan == "no") { 486 var handler = PaystackPop.setup( 487 { 488 key: pffSettings.key, 489 email: data.email, 490 amount: data.total, 491 firstname: firstName, 492 lastname: lastName, 493 ref: data.code, 494 currency: data.currency, 495 subaccount: data.subaccount, 496 bearer: data.txnbearer, 497 transaction_charge: data.transaction_charge, 498 metadata: { custom_fields: data.custom_fields }, 499 callback: function (response) { 500 $.blockUI({ message: "Please wait..." }); 501 $.post( 502 $form.attr("action"), 503 { 504 action: "pff_paystack_confirm_payment", 505 code: response.trxref, 506 quantity: quantity, 507 retry:
507true, 508 nonce: data.confirmNonce 509 }, 510 function (newdata) { 511 data = JSON.parse(newdata); 512 if (data.result == "success2") { 513 window.location.href = data.link; 514 } 515 if (data.result == "success") { 516 // Get the current URL 517 const currentUrl = window.location.href; 518 519 // Use URL object to parse the current URL 520 const url = new URL( currentUrl ); 521 522 // Redirect to the same URL without query parameters 523 window.location.href = url.origin + url.pathname; 524 } else { 525 self.before('<div class="alert-success">' + data.message + '</div>'); 526 $.unblockUI(); 527 } 528 } 529 ); 530 }, 531 onClose: function () { } 532 } 533 ); 534 } else { 535 var handler = PaystackPop.setup( 536 { 537 key: pffSettings.key, 538 email: data.email, 539 plan: data.plan, 540 firstname: firstName, 541 lastname: lastName, 542 ref: data.code, 543 currency: data.currency, 544 subaccount: data.subaccount, 545 bearer: data.txnbearer, 546 transaction_charge: data.transaction_charge, 547 metadata: { custom_fields: data.custom_fields }, 548 callback: function (response) { 549 $.blockUI({ message: "Please wait..." }); 550 $.post( 551 $form.attr("action"), 552 { 553 action: "pff_paystack_confirm_payment", 554 code: response.trxref, 555 retry: true, 556 nonce: data.confirmNonce 557 }, 558 function (newdata) { 559 data = JSON.parse(newdata); 560 if (data.result == "success2") { 561 window.location.href = data.link; 562 } 563 if (data.result == "success") { 564 // Get the current URL 565 const currentUrl = window.location.href; 566 567 // Use URL object to parse the current URL 568 const url = new URL(currentUrl); 569 570 // Redirect to the same URL without query parameters 571 window.location.href = url.origin + url.pathname; 572 } else { 573 self.before('<div class="alert-danger">' + data.message + '</div>'); 574 $.unblockUI(); 575 } 576 } 577 ); 578 }, 579 onClose: function () { } 580 } 581 ); 582 } 583 584 handler.openIframe(); 585 } else { 586 alert(data.message); 587 } 588 }, 589 error: function (xhr, status, error) { 590 console.log("An error occurred"); 591 console.log("XHR: ", xhr); 592 console.log("Status: ", status); 593 console.log("Error: ", error); 594 } 595 } 596 ); 597 } 598 ); 599 600 function checkMinimumVal() { 601 if ( $("#pf-amount").length ) { 602 var min_amount = Number($("#pf-amount").attr('min')); 603 var amt = Number($("#pf-amount").val()); 604 var quantity = 1; 605 606 if ( $("#pf-quantity").length ) { 607 quantity = $("#pf-quantity").val(); 608 } 609 610 amt = amt * quantity; 611 612 if (min_amount > 0 && amt < min_amount) { 613 $("#pf-min-val-warn").text( "Amount cannot be less than the minimum amount"); 614 return false;
615 } else { 616 $("#pf-min-val-warn").text(""); 617 $("#pf-amount").removeClass("rerror"); 618 } 619 } 620 } 621 622 function format_validate(max, e) { 623 var value = amountField.text(); 624 if (e.which != 8 && value.length > max) { 625 e.preventDefault(); 626 } 627 // Allow: backspace, delete, tab, escape, enter and . 628 if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 629 // Allow: Ctrl+A 630 || (e.keyCode == 65 && e.ctrlKey === true) 631 // Allow: Ctrl+C 632 || (e.keyCode == 67 && e.ctrlKey === true) 633 // Allow: Ctrl+X 634 || (e.keyCode == 88 && e.ctrlKey === true) 635 // Allow: home, end, left, right 636 || (e.keyCode >= 35 && e.keyCode <= 39) 637 ) { 638 // let it happen, don't do anything 639 calculateFees(); 640 return; 641 } 642 // Ensure that it is a number and stop the keypress 643 if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) 644 && (e.keyCode < 96 || e.keyCode > 105) 645 ) { 646 e.preventDefault(); 647 } else { 648 calculateFees(); 649 } 650 } 651 652 function calculateTotal() { 653 var unit; 654 655 if ($("#pf-vamount").length) { 656 unit = $("#pf-vamount").val(); 657 } else { 658 unit = $("#pf-amount").val(); 659 } 660 var quant = $("#pf-quantity").val(); 661 662 var newvalue = unit * quant; 663 664 if (quant == "" || quant == null) { 665 quant = 1; 666 } else { 667 $("#pf-total").val(newvalue); 668 } 669 670 } 671 function calculateFees(transaction_amount) { 672 setTimeout( 673 function () { 674 transaction_amount = transaction_amount || parseInt(amountField.val()); 675 var currency = $("#pf-currency").val(); 676 var quant = $("#pf-quantity").val(); 677 if ($("#pf-vamount").length) { 678 var name = $("#pf-vamount option:selected").attr("data-name"); 679 $("#pf-vname").val(name); 680 } 681 if (transaction_amount == "" 682 || transaction_amount == 0 683 || transaction_amount.length == 0 684 || transaction_amount == null 685 || isNaN(transaction_amount) 686 ) { 687 var total = 0; 688 var fees = 0; 689 } else { 690 var obj = new PffPaystackFee(); 691 692 obj.withAdditionalCharge(pffSettings.fee.adc); 693 obj.withThreshold(pffSettings.fee.ths); 694 obj.withCap(pffSettings.fee.cap); 695 obj.withPercentage(pffSettings.fee.prc); 696 if (quant) { 697 transaction_amount = transaction_amount * quant; 698 } 699 var total = obj.addFor(transaction_amount * 100) / 100; 700 var fees = total - transaction_amount; 701 } 702 $(".pf-txncharge") 703 .hide() 704 .html(currency + " " + fees.toFixed(2)) 705 .show() 706 .digits(); 707 $(".pf-txntotal") 708 .hide() 709 .html(currency + " " + total.toFixed(2)) 710 .show() 711 .digits(); 712 }, 100 713 ); 714 } 715 716 function validateEmail(email) { 717 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 718 return re.test(email); 719 } 720 721 } 722 ); 723})(jQuery);
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.