-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_sepa.php
206 lines (170 loc) · 6.87 KB
/
form_sepa.php
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Submit Payment</title>
<script src="https://js.stripe.com/v3/"></script>
</head>
<body>
<form action="/form" method="post" id="setup-form">
<div class="form-row inline">
<div class="col">
<label for="accountholder-name">
Name
</label>
<input
id="accountholder-name"
name="accountholder-name"
placeholder="Jenny Rosen"
required
/>
</div>
<div class="col">
<label for="email">
Email Address
</label>
<input
id="email"
name="email"
type="email"
placeholder="[email protected]"
required
/>
</div>
</div>
<div class="form-row">
<!--
Using a label with a for attribute that matches the ID of the
Element container enables the Element to automatically gain focus
when the customer clicks on the label.
-->
<label for="iban-element">
IBAN
</label>
<div id="iban-element">
<!-- A Stripe Element will be inserted here. -->
</div>
</div>
<!-- Add the client_secret from the SetupIntent as a data attribute -->
<button id="submit-button" data-secret="<?= $setup->client_secret ;?>">
Set up SEPA Direct Debit
</button>
<!-- Used to display form errors. -->
<div id="error-message" role="alert"></div>
<!-- Display mandate acceptance text. -->
<div id="mandate-acceptance">
By providing your IBAN, you are authorizing *Rocketship Inc* and Stripe,
our payment service provider, to send instructions to your bank to debit
your account in accordance with those instructions. Subsequent payments are
entitled to a refund from your bank under the terms and conditions of your
agreement with your bank. A refund must be claimed within eight weeks
starting from the date on which your account was debited.
</div>
</form>
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<script>
var stripe = Stripe('pk_test_8I8CLoJqelcPAjz60yP76o69003QmHvBTI');
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
var style = {
base: {
color: '#32325d',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
},
':-webkit-autofill': {
color: '#32325d',
},
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a',
':-webkit-autofill': {
color: '#fa755a',
},
},
};
var options = {
style: style,
supportedCountries: ['SEPA'],
// Elements can use a placeholder as an example IBAN that reflects
// the IBAN format of your customer's country. If you know your
// customer's country, we recommend that you pass it to the Element as the
// placeholderCountry.
placeholderCountry: 'FR',
};
// Create an instance of the IBAN Element
var iban = elements.create('iban', options);
// Add an instance of the IBAN Element into the `iban-element` <div>
iban.mount('#iban-element');
iban.on('change', function(event) {
var displayError = document.getElementById('error-message');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
var form = document.getElementById('setup-form');
var accountholderName = document.getElementById('accountholder-name');
var email = document.getElementById('email');
var submitButton = document.getElementById('submit-button');
var clientSecret = submitButton.dataset.secret;
form.addEventListener('submit', function(event) {
event.preventDefault();
stripe.confirmSepaDebitPayment(
clientSecret,
{
payment_method: {
sepa_debit: iban,
billing_details: {
name: accountholderName.value,
email: email.value,
},
},
}
) .then(function(result) {
// Handle result.error or result.setupIntent
console.log(result);
$.ajax({
url: "ajaxStripe.php",
type: "post",
data: {
setup_id: result.paymentIntent.id,
setup_pm: result.paymentIntent.payment_method,
customer: '<?= $customer->id; ?>',
// intent_id: result.paymentIntent.id,
// intent_pm: result.paiementIntent.payment_method
} ,
success: function (response) {
// You will get response from your PHP page (what you echo or print)
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
});
/*
stripe
.confirmSepaDebitSetup('', {
payment_method: {
sepa_debit: iban,
billing_details: {
name: accountholderName.value,
email: email.value,
},
},
})
.then(function(result1) {
// Handle result.error or result.setupIntent
console.log(result1.setupIntent);
/
});*/
});
</script>
</body>
</html>