質問編集履歴

1

data追記

2021/06/17 00:09

投稿

you88
you88

スコア147

test CHANGED
File without changes
test CHANGED
@@ -85,3 +85,201 @@
85
85
 
86
86
 
87
87
  このエラーの対処方法わかる方いるでしょうか?
88
+
89
+
90
+
91
+ dataの送り方は下記でviewからjsで送っています。
92
+
93
+
94
+
95
+ ```
96
+
97
+ <script>
98
+
99
+ var stripe = Stripe('pk_test_');
100
+
101
+ var csrf_token = document.querySelector('meta[name="csrf-token"]').content;
102
+
103
+ var createCheckoutSession = function(priceId,customerId,accountId) {
104
+
105
+ return fetch("/create-checkout-session", {
106
+
107
+ method: "POST",
108
+
109
+ headers: {
110
+
111
+ "Content-Type": "application/json",
112
+
113
+ 'X-CSRF-Token': csrf_token
114
+
115
+ },
116
+
117
+ body: JSON.stringify({
118
+
119
+ priceId: priceId,
120
+
121
+ customerId: customerId,
122
+
123
+ accountId: accountId,
124
+
125
+ })
126
+
127
+ }).then(function(result) {
128
+
129
+ return result.json();
130
+
131
+ });
132
+
133
+ };
134
+
135
+ document
136
+
137
+ .getElementById("checkout")
138
+
139
+ .addEventListener("click", function(evt) {
140
+
141
+ createCheckoutSession("<%= @plan.stripe_price_id %>","<%= current_user.stripe_customer_id %>","<%= @plan_user.stripe_account_id %>").then(function(data) {
142
+
143
+ stripe
144
+
145
+ .redirectToCheckout({
146
+
147
+ sessionId: data.id
148
+
149
+ })
150
+
151
+ .then(handleResult);
152
+
153
+ });
154
+
155
+ });
156
+
157
+ </script>
158
+
159
+
160
+
161
+ ```
162
+
163
+
164
+
165
+ dataは下記になります
166
+
167
+
168
+
169
+ ```
170
+
171
+ {
172
+
173
+ "id": "evt_",
174
+
175
+ "object": "event",
176
+
177
+ "api_version": "",
178
+
179
+ "created": ,
180
+
181
+ "data": {
182
+
183
+ "object": {
184
+
185
+ "id": "cs_test_",
186
+
187
+ "object": "checkout.session",
188
+
189
+ "allow_promotion_codes": null,
190
+
191
+ "amount_subtotal": 3000,
192
+
193
+ "amount_total": 3000,
194
+
195
+ "billing_address_collection": null,
196
+
197
+ "cancel_url": "",
198
+
199
+ "client_reference_id": null,
200
+
201
+ "currency": "usd",
202
+
203
+ "customer": "cus_",
204
+
205
+ "customer_details": {
206
+
207
+ "email": "",
208
+
209
+ "tax_exempt": "none",
210
+
211
+ "tax_ids": [
212
+
213
+ ]
214
+
215
+ },
216
+
217
+ "customer_email": null,
218
+
219
+ "livemode": false,
220
+
221
+ "locale": null,
222
+
223
+ "metadata": {
224
+
225
+ },
226
+
227
+ "mode": "payment",
228
+
229
+ "payment_intent": "pi_",
230
+
231
+ "payment_method_options": {
232
+
233
+ },
234
+
235
+ "payment_method_types": [
236
+
237
+ "card"
238
+
239
+ ],
240
+
241
+ "payment_status": "paid",
242
+
243
+ "setup_intent": null,
244
+
245
+ "shipping": null,
246
+
247
+ "shipping_address_collection": null,
248
+
249
+ "submit_type": null,
250
+
251
+ "subscription": null,
252
+
253
+ "success_url": "",
254
+
255
+ "total_details": {
256
+
257
+ "amount_discount": 0,
258
+
259
+ "amount_shipping": 0,
260
+
261
+ "amount_tax": 0
262
+
263
+ }
264
+
265
+ }
266
+
267
+ },
268
+
269
+ "livemode": false,
270
+
271
+ "pending_webhooks": 3,
272
+
273
+ "request": {
274
+
275
+ "id": null,
276
+
277
+ "idempotency_key": null
278
+
279
+ },
280
+
281
+ "type": "checkout.session.completed"
282
+
283
+ }
284
+
285
+ ```