1

I'm struggling to complete a Amazon Pay transaction in PHP.

First of all I followed this guide https://developer.amazon.com/de/docs/amazon-pay-checkout/get-set-up-for-integration.html and implemented version 2 of Amazon Pay. For implementation I used the following PHP Amazon Pay SDK: https://github.com/amzn/amazon-pay-api-sdk-php

Up to point 4 (Set payment info) I got everything working. But here I am stuck. 4.2 says that the response contains an amazonPayRedirectUrl to which the user has to be redirected.

My problem is the following: I am working with a kind of legacy software where there are a lot of forms in an online shop. When these forms are submitted they are always posting to the same url and depending on the payload data different views are loaded to proceed in the checkout process. When I am now redirecting the user via the generated amazonPayRedirectUrl (using header function of PHP) the user is redirected to the shops landing page (due to htaccess config) instead of the page/view which should logically follow in the checkout process because the redirect does not include the payload data of the submit form.

I already tried to save the needed checkout session id (which is appened as a query parameter to the amazonPayRedirectUrl) into the session to complete the transaction without redirecting the user but this does not work. When calling $client->completeCheckoutSession I get an error message in the response: InvalidCheckoutSessionStatus You tried to call an operation on a Checkout Session that is in a state where that operation is not allowed. The status of the checkout session in the response is "open" instead of "completed". I assume this error occurs because I did not redirect the user (not sure though).

What would be the best way to redirect the user to the correct logically following view/page in the checkout process? Do I somehow have to gather the submit data and do an ajax call including this payload data while calling the amazonPayRedirectUrl or how do I prevent being redirected to the shops landing page respectivly load the correct following view/form?

Thanks in advance!

omegon
  • 23
  • 2
  • Thanks for the detailed description of the issue It can be hard to deal with the requirements of a legacy system, but I am sure there is a trick. However, the redirect action is always mandatory - there is no way to omit that part. If you can share more details, feel free to contact me directly. One quick solution could be: Save the original POST data before redirecting; set a custom page for the return URL; on landing there restore the POST data either directly or by rendering a hidden form with that data and submitting it. – marcus.kreusch Jan 12 '22 at 22:27
  • BTW: Good to see, that you have been able to move forward with that integration since our last contact ;-) – marcus.kreusch Jan 12 '22 at 22:28
  • 1
    Thank you for helping me again. I am currently working on a solution based on your suggestion and will give feedback as soon as I solved the problem! – omegon Jan 26 '22 at 16:28
  • Great! Let me know, if you need any help! – marcus.kreusch Jan 27 '22 at 18:36

0 Answers0