-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.phtml
More file actions
95 lines (85 loc) · 3.45 KB
/
form.phtml
File metadata and controls
95 lines (85 loc) · 3.45 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
<input type="hidden" id="stripeTokenId" name="stripe_plugincustomfields[stripeTokenId]" value="">
<input type="hidden" id="stripe_currency" value="<?php echo $this->currency; ?>"/>
<div id="card-element"></div>
<div id="card-errors" role="alert"></div>
<script data-cfasync="false" src="https://js.stripe.com/v3/"></script>
<script data-cfasync="false" type="text/javascript">
var stripe = Stripe('<?php echo $this->publishableKey; ?>');
var elements = '';
function submitPayment() {
valid = $('#submitForm').parsley({
excluded: 'input[type=button], input[type=submit], input[type=reset], :hidden'
});
valid.validate();
if (valid.isValid()) {
clientexec.mask();
elements.submit();
var totalPay = $('#totalPay_raw').val();
$.get('plugins/gateways/stripe/callback.php?initStripe=1&totalPay=' + totalPay + '¤cy=' + $('#stripe_currency').val() + '¶ms=' + $('#submitForm').serialize(), function( data ) {
}).done(function(data) {
$('#stripeTokenId').val(data.id);
paymentIntentSecret = data.secret;
stripe.confirmPayment({
elements,
clientSecret: paymentIntentSecret,
redirect: "if_required",
confirmParams: {
return_url: '<?php echo $this->returnUrl; ?>',
payment_method_data: {
billing_details: {
address: {
country: data.country,
postal_code: data.postal_code
}
}
}
}
}).then(function(result) {
if (result.error) {
clientexec.unMask();
clientexec.error(result.error.message);
} else {
if (result.paymentIntent.status === 'requires_capture') {
cart.submit_form(0);
}
}
});
});
}
}
function initStripe()
{
var totalPay = $('#totalPay_raw').val();
var paymentIntentSecret = '';
elements = stripe.elements({
mode: 'payment',
currency: $('#stripe_currency').val().toLowerCase(),
amount: Math.round(totalPay*100),
setupFutureUsage: 'off_session',
captureMethod: 'manual'
});
var card = elements.create("payment",
{
fields: {
billingDetails: {
address: {
country: 'never',
postalCode: 'never'
}
}
}
});
card.mount("#card-element");
card.on('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
}
</script>
<a style="margin-left:0px;cursor:pointer;" class="app-btns primary customButton center-on-mobile mt-3 stripeButton <?php if (@$this->termsConditions) {
?>disabled<?php
} ?>" onclick="submitPayment();" id="submitButton"></a>