Repository navigation
Expand file tree
/
Copy pathform.phtml
More file actions
193 lines (168 loc) · 8.3 KB
/
Copy pathform.phtml
File metadata and controls
193 lines (168 loc) · 8.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<input type="hidden" id="paystack_transaction_id" name="paystack_plugincustomfields[paystack_transaction_id]" value="">
<input type="hidden" id="paystack_skip_captcha" name="paystack_plugincustomfields[paystack_skip_captcha]" value="0">
<script src="https://js.paystack.co/v2/inline.js"></script>
<?php if ($this->from == 'signup') { ?>
<a style="margin-left:0px;cursor:pointer;" class="center-on-mobile app-btns primary customButton paystackButton" id="customButton"></a>
<?php } elseif ($this->from == 'invoice') { ?>
<button class="app-btns primary customButton paystackButton"><?php echo $this->user->lang('Pay Invoice'); ?></button>
<?php } ?>
<script>
function paystackOpenHandler() {
<?php if ($this->from == 'signup') { ?>
let email = '';
<?php if (!$this->loggedIn) { ?>
const CT_4 = document.getElementById('CT_4');
if (CT_4 !== null) {
email = CT_4.value;
}
<?php } else { ?>
email = '<?php echo $this->user->getEmail(); ?>';
<?php } ?>
const amount = Math.round(
parseFloat(document.getElementById('totalPay_raw').value) * 100
);
const currency = '<?php echo $this->Currency; ?>';
<?php } else { ?>
const email = '<?php echo $this->user->getEmail(); ?>';
const amount = <?php echo (int) $this->amount; ?>;
const currency = '<?php echo $this->currency; ?>';
<?php } ?>
const paystack = new PaystackPop();
paystack.newTransaction({
key: '<?php echo $this->publicKey; ?>',
email: email,
amount: amount,
currency: currency,
onSuccess: function(transaction) {
document.getElementById('paystack_transaction_id').value = transaction.reference;
document.getElementById('paystack_skip_captcha').value = "1";
$('#submitButton').click();
},
onCancel: function() {
// User closed the Paystack popup
}
});
}
$('.paystackButton').on('click', function(e) {
e.preventDefault();
<?php if ($this->from == 'signup') { ?>
if ($('.paystackButton').hasClass('disabled')) {
return;
}
var password_validated = true;
<?php if (!$this->loggedIn) { ?>
$('.password-strength-error').remove();
$('#password').parent().removeClass('has-error');
//let's validate remote data
if ($('#password').length > 0) {
$.ajax({
type: "POST",
data: {"password": $('#password').val()},
url: 'index.php?controller=signup&fuse=admin&action=testpasswordstrength',
async: false,
success : function(response) {
const json = clientexec.parseResponse(response);
if (!json.valid) {
password_validated = false;
$('#password').parent().addClass('has-error');
$('#password').after('<span class="help-block password-strength-error">'+json.errorMessage+'</span>');
$('#password').get(0).scrollIntoView();
}
}
});
}
<?php } ?>
var parsleyForm = $('#submitForm').parsley({
excluded: 'input[type=button], input[type=submit], input[type=reset], :hidden'
});
var form_validated = parsleyForm.validate();
if (password_validated && form_validated) {
<?php } ?>
<?php if ($this->from == 'invoice') { ?>
$.ajax({
type: 'POST',
url: 'index.php?fuse=billing&action=fraudcheck',
dataType: 'json',
data: {
params: {
actionType: 'singlepayment',
plugin: 'paystack',
invoiceId: '<?php echo (int)$this->invoiceId; ?>'
}
},
success: function(response) {
if (response.fraudCheckPassed) {
// Open Handler
paystackOpenHandler();
} else {
window.location.href = '<?php echo CE_Lib::getSoftwareURL() . "/index.php?fuse=billing&cancel=1&controller=invoice&view=invoice&id=" . $this->invoiceId; ?>'
}
},
error: function() {
alert('<?php echo $this->user->lang("There was an error validating the payment."); ?>');
}
});
<?php } elseif ($this->from == 'signup') { ?>
paystack_ccNumber = document.getElementById(`paystack_ccNumber`);
const myElements = {};
myElements[`totalPay_raw`] = Math.round(
parseFloat(document.getElementById('totalPay_raw').value) * 100
);
<?php if (!$this->loggedIn) { ?>
const fieldIds = [
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeEMAIL); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeFIRSTNAME); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeLASTNAME); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeADDRESS); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeCITY); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeSTATE); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeCOUNTRY); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeZIPCODE); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typePHONENUMBER); ?>',
'<?php echo $this->user->getCustomFieldsObj()->_getCustomFieldIdByType(typeORGANIZATION); ?>'
];
fieldIds.forEach(id => {
const element = document.getElementById(`CT_${id}`);
// If the element exists, get its value; otherwise, default to an empty string
myElements[`CT_${id}`] = element?.value ?? '';
});
myElements[`paymentMethod`] = 'paystack';
myElements[`paystack_ccNumber`] = paystack_ccNumber?.value ?? '';
myElements[`selectedcurrency`] = '<?php echo $this->Currency; ?>';
myElements[`currency`] = '<?php echo $this->Currency; ?>';
<?php } else { ?>
myElements[`actionType`] = 'singlepayment';
myElements[`plugin`] = 'paystack';
myElements[`cc_num`] = paystack_ccNumber?.value ?? '';
myElements[`clientId`] = '<?php echo $this->user->getId(); ?>';
<?php } ?>
$.ajax({
type: 'POST',
url: 'index.php?fuse=billing&action=fraudcheck',
dataType: 'json',
data: {
params: myElements
},
success: function(response) {
if (response.fraudCheckPassed) {
// Open Handler
paystackOpenHandler();
} else {
//Complete the order but avoid charging
document.getElementById('paystack_skip_captcha').value = "0";
$('#submitButton').click();
}
},
error: function() {
alert('<?php echo $this->user->lang("There was an error validating the payment."); ?>');
}
});
<?php } else { ?>
// Open Handler
paystackOpenHandler();
<?php } ?>
<?php if ($this->from == 'signup') { ?>
}
<?php } ?>
});
</script>