Forum
Pay and Stripe
Hi Drew,
Can I use the perch_shop_checkout('stripe')
etc to take an Pay payment via this method, https://stripe.com/docs/apple-pay/web?
I have tried the example code, and the post to the cart with the token seems to result in the website hanging (guessing infinite loop!)?
Any help, super appreciated as always.
You've not really given anyone anything to go on there. Where would we start?
Okay, so in
stripe_payment_form.html
, as per the guide, I've added the following:This works, Pay shows and the Stripe side processes. However, the POST to
/basket
which works for a standard Stripe payment with the stripeToken, doesn't work for the post request, and just seems to hang, almost like there's too many redirects.You should be able to recreate in Safari, using the script above! Any questions, or if you need anymore, please let me know.
What have you done so far to debug it?
I’ve tried changing the post request to firstly just a blank page, which worked okay obviously. Then added just the stripe checkout via ‘perch_shop_checkout’, which immiedialy recreates my issue. The post request never actually completes which makes me think it’s some sort of redirect issue, but wasn’t really sure how’s best to debug further! As I say, standard stripe checkout seems to work fine!
What happens when you go directly to
/basket
? Do you get redirected to/basket/
?No, just get served the cart as usual, no redirects or anything happening there. All I have at the top of that page is:
```<?php if (!perch_member_logged_in()) { PerchUtil::redirect("/account/login?r=/basket"); } else { // your 'success' and 'failure' URLs $return_url = '/payment'; $cancel_url = '/';
if (perch_post('stripeToken')) { perch_shop_checkout('stripe', [ 'return_url' => $return_url, 'cancel_url' => $cancel_url, 'token' => perch_post('stripeToken') ]); }
}```
The JavaScript will be posted with your cookies, so if you're logged in, that request should be logged in.
I'd suggest inspecting
$_POST
at that point to see if what you're getting is what you're expecting.The request doesn't seem to complete, so I can't analyse POST, that's what I can't workout. Doesn't appear in the console, only other requests the site has made, so strange!
So post to a completely different page until you see what you're getting.
Yep, stripeToken is in the POST, anything else I need to be looking for?
If
stripeToken
is there, you should be able to callperch_shop_checkout()
``if (perch_member_logged_in()) { // your 'success' and 'failure' URLs $return_url = '/payment'; $cancel_url = '/';
if (perch_post('stripeToken')) { perch_shop_checkout('stripe', [ 'return_url' => $return_url, 'cancel_url' => $cancel_url, 'token' => perch_post('stripeToken') ]); }
}```
That's in my basket, but as soon as that's called, it doesn't post and the site hangs!
Just as before, break it down and isolate where it's going wrong.
It's in the
perch_shop_checkout
, the minute I remove that, no hangBut the input is the same?
Both post with the stripeToken as far as I’m aware!
That's curious then. The same input should have the same result. Does your failure URL point somewhere intelligent?
Failure goes to
/
, homepage. No redirects or other stuff happening there. I just can't figure out how to easily debug it, because the post doesn't give me a response...Any clues if you hold redirects?
Before anything that causes a redirect, add:
and obviously turn on debug.