Forum
Getting values back from perch_shop_checkout
I am integrating Perch shop with another app for posting classified adverts. Members can pay to upgrade their ads.
On successful payment I redirect the user to a page which triggers a database change (to upgrade the advert) and then they end up at the ‘success’ page with the review of their purchase.
It works but currently I’m using perch_shop_order_successful in the model as the green light for updating the database so technically anyone could pay for one ad, then if they guessed the redirect url they could keep visiting it for any advert on the site and upgrade it without paying again (as perch_shop_order_successful is session based).
I think what I need to do in the model is check that the advert ID number is equal to a value I pass to perch_shop_checkout on the cart page and only approve the database update if that is true. However I’m not sure if it’s possible to get back any of those values from perch_shop_checkout?
I can use ‘metadata’ to pass values to Stripe but don’t know if I can get those value and use them on my site after payment is complete?
If not, is there another way to achieve my goal?
Many thanks.
Hello Stephen,
Are you recording the successful order ID in your app?
While
perch_shop_order_successful()
returnstrue
in the same session, you can check which order it is referencing withperch_shop_successful_order_id()
:So you can probably perform a number of checks with Perch Shop functions and within your app (perhaps based on order ID).
Hi Hussein,
I'm not really sure how I can get that to work. Here is the logic I currently have which updates the db and upgrades an ad:
So that function runs from the return_url on perch_shop_checkout. Using perch_shop_successful_order_id() the only thing I can think of would be running a check on all the db's upgraded_order_id entries to ensure the number is unique? There's probably a simpler way I'm not seeing!
That would be the correct way to do it. Make sure you only ratify each order once.
Thanks both, I have it working now :)