|
3 | 3 |
|
4 | 4 |
|
5 | 5 | $(document).ready(function($) { |
| 6 | + var international_card = false; |
| 7 | + var amountField = $('#pf-amount'); |
| 8 | + var max = 10; |
| 9 | + amountField.keydown(function(e) { |
| 10 | + format_validate(max, e); |
| 11 | + }); |
| 12 | + |
| 13 | + function format_validate(max, e) { |
| 14 | + var value = amountField.text(); |
| 15 | + if (e.which != 8 && value.length > max) { |
| 16 | + e.preventDefault(); |
| 17 | + } |
| 18 | + // Allow: backspace, delete, tab, escape, enter and . |
| 19 | + if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || |
| 20 | + // Allow: Ctrl+A |
| 21 | + (e.keyCode == 65 && e.ctrlKey === true) || |
| 22 | + // Allow: Ctrl+C |
| 23 | + (e.keyCode == 67 && e.ctrlKey === true) || |
| 24 | + // Allow: Ctrl+X |
| 25 | + (e.keyCode == 88 && e.ctrlKey === true) || |
| 26 | + // Allow: home, end, left, right |
| 27 | + (e.keyCode >= 35 && e.keyCode <= 39)) { |
| 28 | + // let it happen, don't do anything |
| 29 | + calculateFees(); |
| 30 | + return; |
| 31 | + } |
| 32 | + // Ensure that it is a number and stop the keypress |
| 33 | + if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { |
| 34 | + e.preventDefault(); |
| 35 | + } else { |
| 36 | + calculateFees(); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + $.fn.digits = function(){ |
| 42 | + return this.each(function(){ |
| 43 | + $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); |
| 44 | + }) |
| 45 | + } |
| 46 | + function calculateFees() { |
| 47 | + setTimeout(function() { |
| 48 | + var transaction_amount = parseInt(amountField.val()); |
| 49 | + var multiplier = 0.0155; |
| 50 | + var fees = multiplier * transaction_amount; |
| 51 | + var extrafee = 0; |
| 52 | + if (fees > 2000) { |
| 53 | + var extrafee = 2000; |
| 54 | + }else{ |
| 55 | + if (transaction_amount > 2500) {extrafee = 100}; |
| 56 | + } |
| 57 | + var total = transaction_amount + fees + extrafee; |
| 58 | + if (transaction_amount == '' || transaction_amount == 0) { |
| 59 | + var total = 0; |
| 60 | + var fees = 0; |
| 61 | + } |
| 62 | + $(".pf-txncharge").hide().html("NGN"+fees.toFixed(2)).show().digits(); |
| 63 | + $(".pf-txntotal").hide().html("NGN"+total.toFixed(2)).show().digits(); |
| 64 | + }, 100); |
| 65 | + } |
| 66 | + |
| 67 | + calculateFees(); |
6 | 68 |
|
7 | 69 | $('.pf-number').keydown(function(event) { |
8 | 70 | if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 |
|
23 | 85 | $('.paystack-form').on('submit', function(e) { |
24 | 86 | var stop = false; |
25 | 87 | $(this).find("input,select, textarea").each(function() { |
26 | | - $(this).css({ "border-color":"#d1d1d1" }); |
| 88 | + $(this).removeClass('rerror');//.css({ "border-color":"#d1d1d1" }); |
27 | 89 | }); |
28 | 90 | var email = $(this).find("#pf-email").val(); |
29 | 91 | var amount = $(this).find("#pf-amount").val(); |
30 | 92 | if (Number(amount) > 0) { |
31 | 93 | }else{ |
32 | | - $(this).find("#pf-amount").css({ "border-color":"red" }); |
| 94 | + $(this).find("#pf-amount").addClass('rerror');// css({ "border-color":"red" }); |
33 | 95 | stop = true; |
34 | 96 | } |
35 | 97 | if (!validateEmail(email)) { |
36 | | - $(this).find("#pf-email").css({ "border-color":"red" }); |
| 98 | + $(this).find("#pf-email").addClass('rerror');//.css({ "border-color":"red" }); |
37 | 99 | stop = true; |
38 | 100 | } |
39 | 101 | $(this).find("input, select, textarea").filter("[required]").filter(function() { return this.value == ''; }).each(function() { |
40 | | - $(this).css({ "border-color":"red" }); |
| 102 | + $(this).addClass('rerror');///.css({ "border-color":"red" }); |
41 | 103 | stop = true; |
42 | 104 |
|
43 | 105 | }); |
44 | 106 | if (stop) { |
45 | | - $('html,body').animate({ scrollTop: $('.paystack-form').offset().top - 110 }, 500); |
| 107 | + $('html,body').animate({ scrollTop: $('.rerror').offset().top - 110 }, 500); |
46 | 108 | return false; |
47 | 109 |
|
48 | 110 | } |
|
92 | 154 | $(this).find("input, select, textarea").each(function() { |
93 | 155 | $(this).css({ "border-color":"#d1d1d1" }); |
94 | 156 | }); |
| 157 | + $(".pf-txncharge").hide().html("NGN0").show().digits(); |
| 158 | + $(".pf-txntotal").hide().html("NGN0").show().digits(); |
95 | 159 |
|
96 | 160 | $.unblockUI(); |
97 | 161 | }else{ |
|
126 | 190 | $(this).find("input, select, textarea").each(function() { |
127 | 191 | $(this).css({ "border-color":"#d1d1d1" }); |
128 | 192 | }); |
| 193 | + $(".pf-txncharge").hide().html("NGN0").show().digits(); |
| 194 | + $(".pf-txntotal").hide().html("NGN0").show().digits(); |
129 | 195 |
|
130 | 196 | $.unblockUI(); |
131 | 197 | }else{ |
|
140 | 206 | }); |
141 | 207 | } |
142 | 208 |
|
| 209 | + |
143 | 210 | handler.openIframe(); |
144 | 211 | }else{ |
145 | 212 | alert(data.message); |
|
0 commit comments