#csolis - Installments

1 messages · Page 1 of 1 (latest)

deft spear
willow panther
#

OK

#

have a problem with payment to months without interest in Mexico, could you help me?

#

plans installments

deft spear
#

Maybe! What's your question?

willow panther
#

I have the payment options of one payment, 3,6,9 and 12 months.

but when I select a single payment it sends me an error in the json and destroys the whole development.

deft spear
#

What's the error?

willow panther
#

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

#

Later

deft spear
#

Right, but what's the actual error that was sent instead of the JSON you expected?

willow panther
#

const response = await fetch('assets/js/confirm_payment.php', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
payment_intent_id: intentId,
selected_plan: selectedPlan,
}),
});

deft spear
#

It sounds like you're trying to fetch a specific Payment Intent from the API but the ID you're passing in is blank.

#

In your server-side code do you have code that's trying to get a Payment Intent by it's ID?

#

Yeah, so this code:

$intent = \Stripe\PaymentIntent::retrieve(
    $json_obj['payment_intent_id']
);```The problem is that `$json_obj['payment_intent_id']` is actually blank.
#

You should add validation code to make sure it's not blank before calling the Stripe code, and you should wrap the Stripe code in a try...catch block and return a JSON error if something goes wrong there.

#

And then handle the JSON error on your frontend.

#

Also, you shared your secret test key above, so you'll probably want to roll that to make sure no one else can do anything to your test data.

#

Does that help?

willow panther
#

your documentation is wrong

#

It is the 100% implementation of the documentation

deft spear
#

Which documentation?

willow panther
deft spear
#

That's sample code designed to get you started. It should work fine, but there's a lot of validation and error handling code you would need to add before going to production.

#

In your client side code do you have exactly this code: fetch('/collect_details', {?

willow panther
#

If I leave fetch('/collect_details' it is destroyed.

#

I changed it to fetch('assets/js/confirm_payment.php', { only this way it works

deft spear
#

Do you have your server configured to map the /collect_details URI to the PHP code running on your server?

#

Okay, that should work if that's where you put the code.

#

So does this help you fix the issue? Are you unblocked?

deft spear
#

csolis - Installments