Search code examples
phptestingamazon-pay

How to test declination of Amazon Payments authorization?


When authorizing an order on Amazon Payments, the authorization status may come back as Declined with InvalidPaymentMethod as the reason, if the customer has to login to Amazon Payments and change payment method.

How to force Amazon to reproduce this InvalidPaymentMethod case for testing?


Solution

  • Oh, RTM... I found the answer in the Integration Guide. When you make the Authorize call, you have to specify SellerAuthorizationNote:

    {"SandboxSimulation": {
         "State":"Declined",
         "ReasonCode":"InvalidPaymentMethod",
         "PaymentMethodUpdateTimeInMins":5}}
    

    Leaving question here for developers integrating this payment method.

    This is what the final method looks like:

    /**
     * @param string $orderReferenceId
     * @param string $authorizationReferenceId
     * @param float  $amount
     * @param string $currencyCode
     * @return \OffAmazonPaymentsService_Model_AuthorizeResponse
     */
    private function authorizeOrder($orderReferenceId, $authorizationReferenceId, $amount, $currencyCode)
    {
        return $this->getClient()->authorize([
            'SellerId'                 => $this->serviceCrendentials['merchantId'],
            'AmazonOrderReferenceId'   => $orderReferenceId,
            'AuthorizationReferenceId' => $authorizationReferenceId,
            'AuthorizationAmount'      => [
                'Amount'               => $amount,
                'CurrencyCode'         => $currencyCode
            ],
            // Delete it, it's just for sandbox testing
            'SellerAuthorizationNote'  => json_encode(['SandboxSimulation' => [
                'State'                         => 'Declined',
                'ReasonCode'                    => 'InvalidPaymentMethod',
                'PaymentMethodUpdateTimeInMins' => 5
            ]])
        ]);
    }