#MatiasGz
1 messages ยท Page 1 of 1 (latest)
Hi ๐
You're talking about this code, right?
form.addEventListener('submit', async (ev) => {
ev.preventDefault();
const {paymentMethod, error} = await stripe.createPaymentMethod(
'card',
cardElement,
{billing_details: {name: cardholderName.value}},
);
if (error) {
// Show error in payment form
} else {
// Send paymentMethod.id to your server (see Step 2)
const response = await fetch('/collect_details', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({payment_method_id: paymentMethod.id}),
});
const json = await response.json();
// Handle server response (see Step 3)
handleInstallmentPlans(json);
}
});
yes
Okay and the error you are seeing is on ev.preventDefault()? Do you have an example of this I could see (like a test site that is publicly accessible)?
is not publicly accessible, but I will tell you how I have declared the code:
form.addEventListener('submit', async (ev) => {
console.log(ev.preventDefault(),'PreventDefault');
ev.preventDefault();
const {paymentMethod, error} = await stripe.createPaymentMethod(
'card',
cardElement,
{billing_details: {name: cardholderName.value}},
);
if (error) {
console.log(error);
} else {
// Send paymentMethod.id to your server (see Step 2)
const response = await fetch('/collect_details', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({payment_method_id: paymentMethod.id}),
});
console.log('response', response);
console.log('response apply json function', response.json());
const json = await response.json();
console.log(json, 'success');
// Handle server response (see Step 3)
handleInstallmentPlans(json);
}
});
and now I send you what I receive in the browser console
(now thinking about it, I think that the error is at the moment of using the json() function)
ok!
This sounds like https://github.com/whatwg/fetch/issues/196
You can only read a JSON body once
Are you handling that multiple times somewhere?
it is important to clarify that I am entering all this functionality in a php file, there are no problems?
Or should I separate by html and javascript separately?
the problem of calling more than once the json function, is because I wanted to print the function, that was removed, it was inside a console.log
yes!