pythonpayment-gatewayamazon-payamazonsellercentral

Amazon Pay - how to get authorization decline codes


Working through integration guide step 7 found here which states the codes will be found in the response when an authorization is declined

enter image description here

So I'm just printing out the response to the console but all see is an Amazon payment response object? I request an authorization in step 6 of the integration guide like so

response = client.authorize(
        amazon_order_reference_id=session['order_reference_id'],
        authorization_reference_id=rand(),
        authorization_amount=totalamount,
        transaction_timeout=0,
        capture_now=True)
print('authorize response ',response)

What I get in the console is authorize response <amazon_pay.payment_response.PaymentResponse object at 0x7f7f9494b8d0>

How do I get the actual decline codes (invalid payment, transaction timeout, etc..) from the response object? I'm simulating transaction timeout with one of the preconfigured cards in the sandbox...


Solution

  • The print function is printing the object it self because there's no string definition for it.

    As per Amazon SDK example for python, to get what response is, try this:

    pretty_authorize = json.dumps(json.loads(response.to_json()), indent = 4 )
    
    print(pretty_authorize)
    

    This will print the entire object in a pretty json format, this will help you debug properly.

    There are more options like to_dict and stuff, you can look at Amazon Pay's payment_response.py to know about other options.