#MatiasGz

1 messages ยท Page 1 of 1 (latest)

cloud shuttleBOT
swift coyote
#

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);
  }
});
shut kraken
#

yes

swift coyote
#

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)?

shut kraken
#

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)

olive raptor
#

๐Ÿ‘‹

#

Stepping in as Snufkin needs to step away

shut kraken
#

ok!

olive raptor
#

You can only read a JSON body once

#

Are you handling that multiple times somewhere?

shut kraken
#

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

olive raptor
#

Ah okay

#

So the only error is the Unexpected token

shut kraken
#

yes!

olive raptor
#

Sorry for the delay!

#

Server is quite busy

#

So yeah I don't think the issue here is the preventDefault at all

#

It seems that your browser doesn't like the way your PHP is rendering your HTML