View on GitHub

Amazon Pay SDK Samples

Amazon Pay Simple Checkout

Confirm

At this point we will make the Confirm API call to confirm the order reference and a subsequesnt Authorize and Capture API call.

This concludes the simple checkout example. Click here to start over.

If you have not registered for Amazon Pay click here.
To access our integration guides and all available SDKs click here.

Code

Here you can see how we made the Confirm, Authorize, and Capture calls. The API calls below will use the same client instantiated on the previous page.

You will need to parse the Authorize API response to obtain the Amazon Authorization Id. This id will be needed to make the Capture API call.
Click here to see the Python SDK.
Click here to see the Ruby SDK.
Click here to see the PHP SDK.

pretty_confirm = None
pretty_authorize = None

response = client.confirm_order_reference(
    amazon_order_reference_id= 'AMAZON_ORDER_REFERENCE_ID')

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

if response.success:
    response = client.authorize(
        amazon_order_reference_id= 'AMAZON_ORDER_REFERENCE_ID',
        authorization_reference_id=rand(),
        authorization_amount='175.00',
        transaction_timeout=0)
        
pretty_authorize = json.dumps(
    json.loads(
        response.to_json()),
    indent=4)
        
if response.success:
    response = client.capture(
        amazon_authorization_id='Parse the Authorize response for this id',
        capture_reference_id=rand(),
        capture_amount='175.00')

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

return render_template(
    'confirm.html', confirm=pretty_confirm, authorize=pretty_authorize, capture=pretty_capture)
namespace AmazonPay;

session_start();

// Create the parameters array
$requestParameters = array();

// Refer to GetDetails.php where the Amazon Order Reference ID was set
$requestParameters['amazon_order_reference_id'] = 'AMAZON_ORDER_REFERENCE_ID';

// Confirm the order by making the ConfirmOrderReference API call
$response = $client->confirmOrderReference($requestParameters);

$responsearray['confirm'] = json_decode($response->toJson());

// If the API call was a success make the Authorize API call
if($client->success)
{
    $requestParameters['authorization_amount'] = '175.00';
    $requestParameters['authorization_reference_id'] = 'Your Unique Reference Id';
    $requestParameters['seller_authorization_note'] = 'Authorizing payment';
    $requestParameters['transaction_timeout'] = 0;

    $response = $client->authorize($requestParameters);
    $responsearray['authorize'] = json_decode($response->toJson());
}

// If the Authorize API call was a success, make the Capture API call when you are ready to capture for the order (for example when the order has been dispatched)
if($client->success)
{
    $requestParameters['amazon_authorization_id'] = 'Parse the Authorize Response for this id';
    $requestParameters['capture_amount'] = '175.00';
    $requestParameters['currency_code'] = 'USD';
    $requestParameters['capture_reference_id'] = 'Your Unique Reference Id';

    $response = $client->capture($requestParameters);
    $responsearray['capture'] = json_decode($response->toJson());
}

// Echo the Json encoded array for the Ajax success
echo json_encode($responsearray);

amazon_order_reference_id = 'AMAZON_ORDER_REFERENCE_ID'

response = client.confirm_order_reference(
    amazon_order_reference_id)

respons_hash = Hash.from_xml(response.body)
return response_hash

authorization_reference_id = 'Your Unique Reference Id'
amount = '175.00'

if response.success
    response = client.authorize(
        amazon_order_reference_id,
        authorization_reference_id,
        amount,
        transaction_timeout: 0)
end

respons_hash = Hash.from_xml(response.body)
return response_hash

amazon_authorization_id = response.get_element('AuthorizeResponse/AuthorizeResult/AuthorizationDetails','AmazonAuthorizationId')
capture_reference_id = 'Your Unique Reference Id'
amount = '175.00'

if response.success
    response = client.capture(
        amazon_authorization_id,
        capture_reference_id,
        amount)
end

respons_hash = Hash.from_xml(response.body)
return response_hash

The Confirm API call does not return any special values. If it were unsuccessful you would see an error response.

{
    "ConfirmOrderReferenceResponse": {
        "ResponseMetadata": {
            "RequestId": "5f0ec610-a415-4299-8665-ec407e80bb83"
        }
    }
}

The Authorize API call will authorize the order reference id. You will then make a separate Capture API call to capture the funds.

{
  "AuthorizeResponse": {
    "xmlns": "http://mws.amazonservices.com/schema/OffAmazonPayments/2013-01-01",
    "AuthorizeResult": {
      "AuthorizationDetails": {
        "AuthorizationAmount": {
          "CurrencyCode": "USD",
          "Amount": "175.00"
        },
        "CapturedAmount": {
          "CurrencyCode": "USD",
          "Amount": "0"
        },
        "ExpirationTimestamp": "2015-07-17T17:40:24.238Z",
        "IdList": null,
        "AuthorizationStatus": {
          "LastUpdateTimestamp": "2015-06-17T17:40:24.238Z",
          "State": "Open"
        },
        "AuthorizationFee": {
          "CurrencyCode": "USD",
          "Amount": "0.00"
        },
        "CaptureNow": "false",
        "CreationTimestamp": "2015-06-17T17:40:24.238Z",
        "AmazonAuthorizationId": "S01-5425536-7210743-A035989",
        "AuthorizationReferenceId": "Your Unique Reference Id"
      }
    },
    "ResponseMetadata": {
      "RequestId": "67b52b42-27b9-4aed-ac8c-e07f129c8d6b"
    }
  }
}

The Capture API call will capture the funds for the given order reference id.

{
  "CaptureResponse": {
    "xmlns": "http://mws.amazonservices.com/schema/OffAmazonPayments/2013-01-01",
    "CaptureResult": {
      "CaptureDetails": {
        "CaptureReferenceId": "Your Unique Reference Id",
        "CaptureFee": {
          "CurrencyCode": "USD",
          "Amount": "0.00"
        },
        "AmazonCaptureId": "S01-5425536-7210743-C035989",
        "CreationTimestamp": "2015-06-17T17:44:00.234Z",
        "SoftDescriptor": "AMZ*Test",
        "IdList": null,
        "CaptureStatus": {
          "LastUpdateTimestamp": "2015-06-17T17:44:00.234Z",
          "State": "Completed"
        },
        "SellerCaptureNote": null,
        "RefundedAmount": {
          "CurrencyCode": "USD",
          "Amount": "0"
        },
        "CaptureAmount": {
          "CurrencyCode": "USD",
          "Amount": "175.00"
        }
      }
    },
    "ResponseMetadata": {
      "RequestId": "e1fb68c1-8144-4b5f-a435-ca74926cb4bd"
    }
  }
}