質問編集履歴
4
javascriptタグを追加しました
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
3
初心者マークをつけ忘れていたため、つけました
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,6 +40,8 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
+
|
44
|
+
|
43
45
|
```
|
44
46
|
|
45
47
|
エラーメッセージ:ありません
|
2
jsファイルを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,6 +110,132 @@
|
|
110
110
|
|
111
111
|
```
|
112
112
|
|
113
|
+
|
114
|
+
|
115
|
+
```js
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
var stripe = Stripe('pk_test_XXXXXX');
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
var elements = stripe.elements();
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
var style = {
|
128
|
+
|
129
|
+
base: {
|
130
|
+
|
131
|
+
color: '#000',
|
132
|
+
|
133
|
+
fontSize: '12px'
|
134
|
+
|
135
|
+
},
|
136
|
+
|
137
|
+
invalid: {
|
138
|
+
|
139
|
+
color: '#000',
|
140
|
+
|
141
|
+
iconColor: '#000'
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
};
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
const cardNumber = elements.create('cardNumber', {style: style,placeholder: 'カード番号 1111 1111 1111 1111'});
|
150
|
+
|
151
|
+
cardNumber.mount('#card-number');
|
152
|
+
|
153
|
+
const cardExpiry = elements.create('cardExpiry',{style: style,placeholder: '有効期限 MM/YY'});
|
154
|
+
|
155
|
+
cardExpiry.mount('#card-expiry');
|
156
|
+
|
157
|
+
const cardCvc = elements.create('cardCvc', {style: style,placeholder: 'セキュリティ番号'});
|
158
|
+
|
159
|
+
cardCvc.mount('#card-cvc');
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
cardNumber.addEventListener('change', function(event) {
|
164
|
+
|
165
|
+
var displayError = document.getElementById('stripe_err');
|
166
|
+
|
167
|
+
if (event.error) {
|
168
|
+
|
169
|
+
displayError.textContent = event.error.message;
|
170
|
+
|
171
|
+
} else {
|
172
|
+
|
173
|
+
displayError.textContent = '';
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
});
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
var form = document.getElementById('payment-form');
|
182
|
+
|
183
|
+
form.addEventListener('submit', function(event) {
|
184
|
+
|
185
|
+
event.preventDefault();
|
186
|
+
|
187
|
+
stripe.createToken(cardNumber).then(function(result) {
|
188
|
+
|
189
|
+
if (result.error) {
|
190
|
+
|
191
|
+
var errorElement = document.getElementById('stripe_err');
|
192
|
+
|
193
|
+
errorElement.textContent = result.error.message;
|
194
|
+
|
195
|
+
} else {
|
196
|
+
|
197
|
+
// Send the token to your server.
|
198
|
+
|
199
|
+
stripeTokenHandler(result.token);
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
});
|
204
|
+
|
205
|
+
});
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
function stripeTokenHandler(token) {
|
210
|
+
|
211
|
+
// Insert the token ID into the form so it gets submitted to the server
|
212
|
+
|
213
|
+
var form = document.getElementById('payment-form');
|
214
|
+
|
215
|
+
var hiddenInput = document.createElement('input');
|
216
|
+
|
217
|
+
hiddenInput.setAttribute('type', 'hidden');
|
218
|
+
|
219
|
+
hiddenInput.setAttribute('name', 'stripeToken');
|
220
|
+
|
221
|
+
hiddenInput.setAttribute('value', token.id);
|
222
|
+
|
223
|
+
form.appendChild(hiddenInput);
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
// Submit the form
|
228
|
+
|
229
|
+
form.submit();
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
|
238
|
+
|
113
239
|
```php
|
114
240
|
|
115
241
|
<?php
|
1
タイトルを具体的にしました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Stripe
|
1
|
+
【Stripe】複数のプランの中から一つを選択できるフォームを作りたい
|
test
CHANGED
File without changes
|