Exploring the integration of Amazon pay as a payment option for customers on my website has led me to encounter some challenges with understanding the request headers required for calling the Amazon Pay API.
Attempting a request to 'https://pay-api.amazon.com/v2/checkoutSessions/checkoutSessionId' is resulting in a CORS policy error.
The access to fetch at 'https://pay-api.amazon.com/v2/checkoutSessions/d9b4418d-0c6f-4085-8c37-08bef6da6807' from origin 'http://localhost:3000' has been blocked due to CORS policy restrictions. The absence of an 'Access-Control-Allow-Origin' header on the requested resource is causing this issue. Consider setting the request's mode to 'no-cors', if appropriate, to bypass this restriction and fetch the resource.
Below is the fetch request code snippet that I am using to make the API call:
fetch(`https://pay-api.amazon.com/v2/checkoutSessions/${this.$route.query.amazonCheckoutSessionId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'authorization': 'Px2e5oHhQZ88vVhc0DO%2FsShHj8MDDg%3DEXAMPLESIGNATURE',
'x-amz-pay-date': `${new Date()}`
}
})
this.$route.query.amazonCheckoutSessionId refers to the unique url extension generated after a user initiates a checkout session through the Amazon Pay button.
The documentation specifies a structured format for making requests as demonstrated by this curl example:
curl "https://pay-api.amazon.com/:version/checkoutSessions/:checkoutSessionId"
-X GET
-H "authorization: Px2e5oHhQZ88vVhc0DO%2FsShHj8MDDg%3DEXAMPLESIGNATURE"
-H "x-amz-pay-date: 20201012T235046Z"
I'm seeking guidance on obtaining the authorization string and its specific format requirements. Additionally, I would like to know if there is a straightforward way to convert and format a date string into the specified format mentioned in the documentation or if the date string format is not critical.
Despite extensive research on Stack Overflow threads related to Amazon Pay (which are limited) and exploring other Amazon and AWS resources, I have been unable to find clear instructions on formatting the auth string. I did attempt passing my button signature as the authorization string but saw no improvement.
Your assistance in this matter would be greatly appreciated. Thank you.