-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_pay_method.pdt
271 lines (245 loc) · 10.9 KB
/
client_pay_method.pdt
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<div class="col-md-12">
<?php
echo $this->Html->ifSet($message);
$this->Form->create(null, ['class' => 'disable-on-submit']);
$this->Form->fieldHidden('pay_with', $this->Html->ifSet($vars->pay_with), ['id' => 'pay_with']);
$this->WidgetClient->clear();
$this->WidgetClient->create($this->_('ClientPay.method.boxtitle_method', true), ['id' => 'client_method'], $this->Html->ifSet($render_section, null));
$this->WidgetClient->startBody();
// Determine how many columns to draw
$column_widths = 12;
$columns = 3;
if (empty($payment_accounts) || count($payment_accounts) <= 1 || $this->Html->ifSet($require_passphrase)) {
$columns--;
}
if (empty($payment_types) || count($payment_types) <= 1) {
$columns--;
}
if (empty($nm_gateways)) {
$columns--;
}
$column_widths /= ($columns == 0 ? 1 : $columns);
// No payment options available
if ($columns == 0) {
?>
<div class="alert alert-info">
<?php $this->_('ClientPay.method.no_options');?>
</div>
<?php
}
// If the invoice has already been paid, remove all payment methods
if ($this->Html->ifSet($invoice_paid)) {
$payment_accounts = [];
$payment_types = [];
$nm_gateways = [];
$columns = 0;
}
// Set payment option container
if ($columns > 0) {
?>
<div class="row mb-2">
<?php
}
// Show column for payment accounts, if any
if (!empty($payment_accounts) && count($payment_accounts) > 1 && !$this->Html->ifSet($require_passphrase)) {
?>
<div class="col-md-<?php $this->Html->_($column_widths);?><?php echo $columns > 1 ? ' col-border' : '';?>">
<h4><?php $this->_('ClientPay.method.field_useaccount');?></h4>
<?php
$this->Form->fieldSelect('payment_account', $this->Html->ifSet($payment_accounts), $this->Html->ifSet($vars->payment_account), ['id' => 'account', 'class' => 'form-control form-control-sm']);
?>
</div>
<?php
}
// Show column for new payment types, if any
if (!empty($payment_types) && count($payment_types) > 1) {
?>
<div class="col-md-<?php $this->Html->_($column_widths);?><?php echo $columns > 2 ? ' col-border' : '';?>">
<h4><?php $this->_('ClientPay.method.field_newdetails');?></h4>
<?php
$this->Form->fieldSelect('payment_type', $this->Html->ifSet($payment_types), $this->Html->ifSet($vars->payment_type), ['id' => 'details', 'class' => 'form-control form-control-sm']);
?>
</div>
<?php
}
// Show column for non-merchant gateway payment options, if any
if (!empty($nm_gateways)) {
$options_heading = $this->_('ClientPay.method.heading_other_payment_options', true);
if ($columns == 1) {
$options_heading = $this->_('ClientPay.method.heading_payment_options', true);
}
?>
<div class="col-md-<?php $this->Html->_($column_widths);?>">
<h4><?php echo $this->Html->ifSet($options_heading);?></h4>
<?php
// Set non-merchant gateways
foreach ($this->Html->ifSet($nm_gateways, []) as $gateway) {
?>
<div class="radio">
<label>
<?php
$this->Form->fieldRadio('gateway', $this->Html->ifSet($gateway->id), ($this->Html->ifSet($vars->pay_with) == $this->Html->ifSet($gateway->id)), ['class' => 'gateway']);
$this->Html->_($gateway->name);
?>
</label>
</div>
<?php
}
?>
</div>
<?php
}
// Close payment option container
if ($columns > 0) {
?>
<div class="clearfix mb-2"></div>
</div>
<?php
}
?>
<div id="payment_details" style="display:none;">
<?php
echo $this->Html->ifSet($contact_info);
?>
<div id="payment_details_cc" style="display:none;">
<?php echo $this->Html->ifSet($cc_info);?>
</div>
<div id="payment_details_ach" style="display:none;">
<?php echo $this->Html->ifSet($ach_info);?>
</div>
</div>
<?php
// Allow credits to be selected
if ($this->Html->ifSet($credits['amount']) > 0 && !$this->Html->ifSet($invoice_paid)) {
?>
<div class="checkbox">
<label>
<?php
$this->Form->fieldCheckbox('apply_credit', 'true', $this->Html->ifSet($vars->apply_credit) == 'true', ['id' => 'apply_credit']);
$this->_('ClientPay.method.field_apply_credit', false, $this->CurrencyFormat->format($credits['amount'], $credits['currency']));
?>
</label>
</div>
<?php
}
?>
<hr />
<?php
if (!empty($invoice)) {
?>
<div class="mb-2">
<h4><?php $this->_('ClientPay.method.heading_invoice', false, $this->Html->_($invoice->id_code, true));?></h4>
<div class="table-responsive">
<table class="table table-curved table-striped">
<thead>
<tr>
<th><?php $this->_('ClientPay.method.invoice_description');?></th>
<th><?php $this->_('ClientPay.method.invoice_quantity');?></th>
<th><?php $this->_('ClientPay.method.invoice_amount');?></th>
</tr>
</thead>
<tbody>
<?php
$currency_options = [
'prefix' => false,
'suffix' => false,
'code' => false,
'with_separator' => false,
'html_code' => false,
'decimals' => $this->Html->ifSet($currency->precision)
];
foreach ($this->Html->ifSet($invoice->line_items, []) as $line) {
?>
<tr>
<td><?php $this->Html->_($line->description);?></td>
<td><?php echo $this->Html->safe($this->CurrencyFormat->truncateDecimal($this->Html->ifSet($line->qty), 0));?></td>
<td><?php echo $this->CurrencyFormat->format($this->Html->ifSet($line->amount), $this->Html->ifSet($currency->code), $currency_options);?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php
}
?>
<div class="float-right">
<div class="card bg-light d-block p-2 mb-2">
<?php $this->_('ClientPay.confirm.total');?>
<strong><?php echo $this->CurrencyFormat->format($this->Html->ifSet($total), $this->Html->ifSet($currency->code));?></strong>
</div>
</div>
<div class="clearfix"></div>
<button type="submit"<?php echo ($columns <= 0 ? 'style="display:none;"' : '');?> class="btn btn-light float-right" id="submit_payment">
<i class="fas fa-arrow-circle-right"></i>
<span class="confirm"><?php $this->_('ClientPay.method.field_submit');?></span>
<span class="credit_confirm" style="display:none;"><?php $this->_('ClientPay.method.field_credit_submit');?></span>
</button>
<?php
$this->WidgetClient->endBody();
$this->WidgetClient->end();
$this->Form->end();
?>
</div>
<script type="text/javascript">
$(document).ready(function() {
var payment_type = '<?php echo $this->Html->ifSet($vars->payment_type);?>';
if (payment_type == 'ach' || payment_type == 'cc') {
$("#payment_details").show();
$("#payment_details_" + payment_type).show();
}
$('#account, #details').on('change', function() {
$('#pay_with').val($(this).attr('id'));
$('.gateway').prop('checked', false);
if ($(this).attr('id') == 'details') {
if ($(this).val() == 'cc' || $(this).val() == 'ach') {
$('#payment_details').show();
togglePayDetails($(this).val());
$('html,body').animate({scrollTop: $('#payment_details').offset().top}, 'slow');
}
else
$('#payment_details').hide();
$('#account').val('');
}
else {
$('#payment_details, #payment_details_cc, #payment_details_ach').hide();
$('#details').val('');
}
});
$('.gateway').on('change', function() {
$('#pay_with').val($(this).val());
$('#payment_details, #payment_details_cc, #payment_details_ach').hide();
$('#account, #details').val('');
});
toggleCredit();
$('#apply_credit').change(function() {
toggleCredit();
});
});
function toggleCredit() {
if ($('#apply_credit').prop('checked')) {
$('span.credit_confirm').show();
$('#submit_payment').show();
$('span.confirm').hide();
}
else {
$('span.confirm').show();
$('span.credit_confirm').hide();
if (<?php echo $columns;?> <= 0) {
$('#submit_payment').hide();
}
}
}
function togglePayDetails(val) {
if (val == "cc") {
$("#payment_details_ach").hide();
$("#payment_details_cc").show();
}
else {
$("#payment_details_cc").hide();
$("#payment_details_ach").show();
}
}
</script>