node.jsamazon-pay

Amazon Pay: Complete Checkout Session is successful but not confirming transaction


For my Amazon Pay integration with the NodeJs SDK, everything seems to be working great until I get to completeCheckoutSession. When I call completeCheckoutSession, the call is successful and appears to work, but I never receive a confirmation email stating the order has been processed and taking a look in seller central "Payment Status" is still marked as "Open". Moreover, I receive an email 24 hours later noting that the order was canceled.

Here is my code calling completeCheckoutSession with the NodeJs SDK:

const testPayClient = new Client.WebStoreClient(config)
const checkoutSessionId = requestBody.checkoutSessionId
const purchasePrice = requestBody.productInfo.price

const payload = {
    chargeAmount: {
        amount: `${purchasePrice}`,
        currencyCode: 'USD'
    }
}
    
let apiResponse = await testPayClient.completeCheckoutSession(checkoutSessionId, payload)

The price and checkoutSessionId are both coming from the front-end, and I have verified that the checkoutSessionId is the same as that being passed to getCheckoutSession and updateCheckoutSession.

Here is the data object that is returned if I console log apiResponse.data. I've removed null values for the sake of brevity. Additionally, the status code I receive is 200 if I were to log the entire "apiResponse" object.

{
    checkoutSessionId: "not sure I should expose this, but it's here.",
    statusDetails: {
        state: 'Completed',
        lastUpdatedTimestamp: '20211124T141939Z'
    },
    chargePermissionId: 'S01-9642704-9639513',
    creationTimestamp: '20211124T141931Z',
}

Regarding that "state: 'Completed'", the docs note the following:

The Checkout Session moves to the Completed state after you call Complete Checkout Session if transaction processing was successful.

Is there something that I am missing about this call or doing incorrectly that my implementation is not moving the PaymentStatus from "Open" to something along the lines of "Succeeded"? I'd also like to point out that I am doing this all in Sandbox mode.

Thank you in advance for any guidance you can provide.


Solution

  • This issue is about the paymentIntent of the checkout session. According to the docs it has to be set to one of these values:

    Confirm: Create a Charge Permission to authorize and capture funds at a later time

    Authorize: Authorize funds immediately and capture at a later time

    AuthorizeWithCapture: Authorize and capture funds immediately

    When set to Confirm, you have to manually create a Charge to prevent the expiry, which you currently encounter. There are only very few use cases for using Confirm. In fact I have not seen any in real life until now.

    Authorize is suitable, if you would like to have maximum control over the point of time to capture the amount. It also allows for an asynchronous flow, which increases the chances for a successful authorization by giving Amazon Pay up to 24h to decide.

    AuthorizeWithCapture is the easiest and safest. It takes care of everything including the capture. If the checkout session is completed successfully, you will always have a complete payment.