> Important: This SDK has been deprecated. Amazon Pay will continue to support this version but it will not be updated with new features. New integrations should use Amazon Pay API SDK (.NET) & refer this documentation for more details.
Amazon Pay API Integration
Instantiating the client: Client takes in parameters in the following format
Install-Package AmazonPay
Folder PATH listing
+---lib
| Common.Logging.dll
| config.json
| Json.txt
| Newtonsoft.Json.dll
| nunit.framework.dll
| AmazonPay.dll
| TestResult.xml
| UnitTests.dll
|
+---AmazonPay
| | AccountStatus.cs
| | Client.cs
| | Constants.cs
| | HttpImpl.cs
| | IpnHandler.cs
| | NestedJsonToDictionary.cs
| | AmazonPay.csproj
| | region.Designer.cs
| | Regions.cs
| | ResponseParser.cs
| | packages.config
| | Signature.cs
| | SanitizeData.cs
| +---ProviderCreditRequests
| | GetProviderCreditDetailsRequest.cs
| | GetProviderCreditReversalDetailsRequest.cs
| | ReverseProviderCreditRequest.cs
| |
| +---RecurringPaymentRequests
| | AuthorizeOnBillingAgreementRequest.cs
| | CloseBillingAgreementRequest.cs
| | ConfirmBillingAgreementRequest.cs
| | CreateOrderReferenceForIdRequest.cs
| | GetBillingAgreementDetailsRequest.cs
| | SetBillingAgreementDetailsRequest.cs
| | ValidateBillingAgreementRequest.cs
| |
| +---Responses
| | AuthorizeResponse.cs
| | BillingAddressDetails.cs
| | BillingAgreementDetailsResponse.cs
| | CancelOrderReferenceResponse.cs
| | CaptureResponse.cs
| | CloseAuthorizationResponse.cs
| | CloseBillingAgreementResponse.cs
| | CloseOrderReferenceResponse.cs
| | ConfirmBillingAgreementResponse.cs
| | ConfirmOrderReferenceResponse.cs
| | ErrorResponse.cs
| | GetMerchantAccountStatus.cs
| | GetProviderCreditDetailsResponse.cs
| | GetProviderCreditReversalDetailsResponse.cs
| | GetServiceStatusResponse.cs
| | OrderReferenceDetailsResponse.cs
| | PaymentDetailsResponse.cs
| | RefundResponse.cs
| | ValidateBillingAgreementResponse.cs
| |
| \---StandardPaymentRequests
| AuthorizeRequest.cs
| CancelOrderReferenceRequest.cs
| CaptureRequest.cs
| ChargeRequest.cs
| CloseAuthorizationRequest.cs
| CloseOrderReferenceRequest.cs
| ConfirmOrderReferenceRequest.cs
| GetAuthorizationDetailsRequest.cs
| GetCaptureDetailsRequest.cs
| GetMerchantAccountStatusRequest.cs
| GetOrderReferenceDetailsRequest.cs
| GetRefundDetailsRequest.cs
| RefundRequest.cs
| SetOrderAttributesRequest.cs
| SetOrderReferenceDetailsRequest.cs
|
|
\---UnitTests
| App.config
| AuthorizeNotification.json
| config.json
| Json.txt
| packages.config
| AmazonPayUnitTests.cs
| UnitTests.csproj
Parameter | Json file Key name | Values |
---|---|---|
Merchant Id | merchant_id |
Default : null |
Access Key | access_key |
Default : null |
Secret Key | secret_key |
Default : null |
Region | region |
Default : null Other: us ,de ,uk ,jp |
Parameter | Json file Key name | Values |
---|---|---|
Currency Code | currency_code |
Default : null Other: USD ,EUR ,GBP ,JPY |
Environment | sandbox |
Default : false Other: true |
Platform ID | platform_id |
Default : null |
CA Bundle File | cabundle_file |
Default : null |
Application Name | application_name |
Default : null |
Application Version | application_version |
Default : null |
Proxy Host | proxy_host |
Default : null |
Proxy Port | proxy_port |
Default : -1 |
Proxy Username | proxy_username |
Default : null |
Proxy Password | proxy_password |
Default : null |
LWA Client ID | client_id |
Default : null |
Auto Retry On Throttle | auto_retry_on_throttle |
Default : true Other: false |
Setting configuration while instantiating the Client object
using AmazonPay;
using AmazonPay.CommonRequests;
using AmazonPay.StandardPaymentRequests;
using AmazonPay.Responses;
// Your Amazon Pay keys are available in your Seller Central account
// Configuration class object
Configuration config = new Configuration();
config.WithAccessKey("YOUR_ACCESS_KEY")
.WithMerchantId("YOUR_MERCHANT_ID")
.WithSecretKey("YOUR_SECRET_KEY")
/* Supported regions are mentioned in the Regions class and accessed by the enum supportedRegions.
* Example for 'us' is shown below
*/
.WithRegion(Regions.supportedRegions.us);
// Or you can also provide a JSON file path which has the above configuration information in JSON format
string config = "PATH_TO_JSON_FILE\filename.fileextension";
// Instantiate the client class with the config type
Client client = new Client(config);
Setting configuration while instantiating the Client object with Json file
merchant_id
can also be named as Merchant_ID
// Your AmazonPay keys are available in your Seller Central account
// Sample Json file input
{
// Required parameters
"merchant_id": "YOUR_MERCHANT_ID",
"access_key": "YOUR_ACCESS_KEY",
"secret_key": "YOUR_SECRET_KEY",
"region": "REGION",
"sandbox": true,
// Optional parameters
"currency_code": "CURRENCY_CODE",
"client_id": "amzn.oa2.client.xxx",
"application_name": "sdk testing",
"application_version": "1.0",
"proxy_host": null,
"proxy_port": -1,
"proxy_username": null,
"proxy_password": null
"auto_retry_on_throttle": true
}
using AmazonPay;
using AmazonPay.CommonRequests;
using AmazonPay.StandardPaymentRequests;
using AmazonPay.Responses;
string config = "PATH_TO_JSON_FILE\filename.FileExtension";
// Instantiate the client class with the Json file path
Client client = new Client(config);
The sandbox parameter defaults to false if not specified
using AmazonPay;
using AmazonPay.CommonRequests;
using AmazonPay.Responses;
Configuration config = new Configuration();
config.WithAccessKey("YOUR_ACCESS_KEY")
.WithMerchantId("YOUR_MERCHANT_ID")
.WithSecretKey("YOUR_SECRET_KEY")
.WithRegion(Regions.supportedRegions.us)
.WithSandbox(true);
Client client = new Client(config);
Below is an example on how to make the GetOrderReferenceDetails API call
using AmazonPay;
using AmazonPay.CommonRequests;
using Newtonsoft.json;
using AmazonPay.StandardPaymentRequests;
using AmazonPay.Responses;
// STEP 1 : Create the object of the GetOrderReferenceDetailsRequest class to add the parameters for the API call
GetOrderReferenceDetailsRequest requestParameters = new GetOrderReferenceDetailsRequest();
// AMAZON_ORDER_REFERENCE_ID is obtained from the Amazon Pay Address/Wallet widgets
// ACCESS_TOKEN is obtained from the GET parameter from the URL.
// Required Parameter
requestParameters.WithAmazonOrderReferenceId("AMAZON_ORDER_REFERENCE_ID");
// Optional Parameters
requestParameters.WithAccessToken("ACCESS_TOKEN");
requestParameters.WithMWSAuthToken("MWS_AUTH_TOKEN");
/* STEP 2 : Making the API call by passing in the GetOrderReferenceDetailsRequest object i.e requestParameters from step 1.
* response here is the object of the GetOrderReferenceDetailsResponse class
*/
OrderReferenceDetailsResponse getOrderReferenceDetailsResponse = client.GetOrderReferenceDetails(requestParameters);
// Getting response variables
// Variable values can be obtained directly from the OrderReferenceDetailsResponse object received from making the API call in step 2
// Check if the API call was successful
bool isGetOrderReferenceDetailsSuccess = getOrderReferenceDetailsResponse.GetSuccess();
if(isGetOrderReferenceDetailsSuccess)
{
// Getting the XML Response
string xml = getOrderReferenceDetailsResponse.GetXml();
// Json Response
string json = getOrderReferenceDetailsResponse.GetJson();
// Dictionary
Dictionary<string, object> dictionary = getOrderReferenceDetailsResponse.GetDictionary();
// Getting individual variable values that is parsed in the Response class
string amazonOrderReferenceId = getOrderReferenceDetailsResponse.GetAmazonOrderReferenceId();
// Checking if any constraints on the Amazon OrderReference ID exist in the response for which an action should be taken.
if(getOrderReferenceDetailsResponse.GetHasConstraint())
{
List<string> constraintIdList = getOrderReferenceDetailsResponse.GetConstraintIdList();
List<string> constraintDescriptionList = getOrderReferenceDetailsResponse.GetDescriptionList();
}
}
else
{
string errorCode = getOrderReferenceDetailsResponse.GetErrorCode();
string ErrorMessage = getOrderReferenceDetailsResponse.GetErrorMessage();
}
See the OrderReferenceDetailsResponse section for all the parameters returned.
For API calls that need the Amount parameter, the type of the amount parameter is decimal
using AmazonPay;
using AmazonPay.CommonRequests;
using Newtonsoft.json;
using AmazonPay.StandardPaymentRequests;
using AmazonPay.Responses;
Configuration config = new Configuration();
config.WithAccessKey("YOUR_ACCESS_KEY")
.WithMerchantId("YOUR_MERCHANT_ID")
.WithSecretKey("YOUR_SECRET_KEY")
.WithRegion(Regions.supportedRegions.us)
.WithSandbox(true);
Client client = new Client(config);
// Example SetOrderReferenceDetails API call
// Creating the SetOrderReferenceDetailsRequest object
SetOrderReferenceDetailsRequest requestParameters = new SetOrderReferenceDetailsRequest();
// If the amount type was a string or a non decimal value type,
// convert it into decimal type.
requestParameters.WithAmount(decimal.Parse("amount"));
// Also in general decimal values can be directly passed by
requestParameters.WithAmount(19.95m);
// Making the SetOrderReferenceDetails API call
OrderReferenceDetailsResponse setOrderReferenceDetailsResponse = client.SetOrderReferenceDetails(requestParameters);
For API calls that need the currency code parameter, there are two ways to set it
Setting it in the configuration class object globally
using AmazonPay;
using AmazonPay.CommonRequests;
using Newtonsoft.json;
using AmazonPay.StandardPaymentRequests;
using AmazonPay.Responses;
Configuration config = new Configuration();
config.WithAccessKey("YOUR_ACCESS_KEY")
.WithMerchantId("YOUR_MERCHANT_ID")
.WithSecretKey("YOUR_SECRET_KEY")
.WithRegion(Regions.supportedRegions.us)
.WithSandbox(true)
.WithCurrencyCode(Regions.currencyCode.USD);
Client client = new Client(config);
Setting it while making the API call
This takes priority over setting it globally. If this is not set via the following way the global value is taken.
using AmazonPay;
using AmazonPay.CommonRequests;
using Newtonsoft.json;
using AmazonPay.StandardPaymentRequests;
using AmazonPay.Responses;
Configuration config = new Configuration();
config.WithAccessKey("YOUR_ACCESS_KEY")
.WithMerchantId("YOUR_MERCHANT_ID")
.WithSecretKey("YOUR_SECRET_KEY")
.WithRegion(Regions.supportedRegions.us)
.WithSandbox(true);
Client client = new Client(config);
// Creating the SetOrderReferenceDetailsRequest object
SetOrderReferenceDetailsRequest requestParameters = new SetOrderReferenceDetailsRequest();
requestParameters.WithCurrencyCode(Regions.currencyCode.USD);
// Making the SetOrderReferenceDetails API call
OrderReferenceDetailsResponse setOrderReferenceDetailsResponse = client.SetOrderReferenceDetails(requestParameters);
In your web project you can create a file (for example ipn.aspx with a CodeBehind file ipn.aspx.cs). Add the below code into that file and set the URL to the file (ipn.aspx) location in Merchant/Integrator URL by accessing Integration Settings page in the Settings tab.
See IPN Documentation for all the information on IPN and types.
using AmazonPay;
using AmazonPay.Responses;
// Get the IPN headers and Message body
Stream s = Request.InputStream;
StreamReader sr = new StreamReader(s);
string ipnMessage = sr.ReadToEnd();
NameValueCollection headers = Request.Headers;
// Create an object of the IpnHandler class
IpnHandler ipnObject = new IpnHandler(headers, ipnMessage);
// Response types
string xml = ipnObject.ToXml();
string json = ipnObject.ToJson();
Dictionary<string,object> dictionary = ipnObject.ToDict();
// Getting IPN common elements
string notificationType = ipnObject.GetNotificationType();
string merchantId = ipnObject.GetSellerId();
string notificationReferenceId = ipnObject.GetNotificationReferenceId();
string releaseEnvironment = ipnObject.GetReleaseEnvironment();
IPN's contain the XML response for the selective API calls made
Notification types returned
using AmazonPay;
using AmazonPay.Responses;
// Getting response objects.
string notificationType = ipnObject.GetNotificationType();
AuthorizeResponse authResponse = null;
// Example - In this case the Authorize notification was returned
if (notificationType.Equals(NotificationType.PaymentAuthorize.ToString()))
{
authResponse = ipnObject.GetAuthorizeResponse();
}
// With the authResponse object you can get the required variable values
// Example - see AuthorizeResponse class for all variables and their Getter functions.
string amazonAuthorizationId = authResponse.GetAmazonAuthorizationId();
Dictionary<string, List<URLEventTypes>> urlCollection = new Dictionary<string, List<URLEventTypes>>();
urlCollection.Add("https://www.abc.com", new List<URLEventTypes>() { URLEventTypes.ORDER_REFERENCE, URLEventTypes.PAYMENT_AUTHORIZE });
urlCollection.Add("https://www.xyz.com", new List<URLEventTypes>() { URLEventTypes.PAYMENT_CAPTURE });
SetMerchantNotificationConfigurationRequest setRequest = new SetMerchantNotificationConfigurationRequest();
setRequest.WithMerchantNotificationUrls(urlCollection);
SetMerchantNotificationConfigurationResponse setResponse = client.SetMerchantNotificationConfiguration(setRequest);
// to troubleshoot, you can call GetMerchantNotificationConfiguration to view current IPN settings
GetMerchantNotificationConfigurationRequest getRequest = new GetMerchantNotificationConfigurationRequest();
GetMerchantNotificationConfigurationResponse getResponse = client.GetMerchantNotificationConfiguration(getRequest);
ListOrderReferenceRequest listRequest = new ListOrderReferenceRequest();
//REQUIRED PARAMETERS
listRequest.WithQueryId("YOUR_CUSTOM_ORDER_REFERENCE_ID");
listRequest.WithQueryIdType("SellerOrderId");
//OPTIONAL PARAMETERS
listRequest.WithPageSize(1);
listRequest.WithCreatedStartTime(new DateTime(2020, 1, 1, 1, 1, 1));
listRequest.WithCreatedEndTime(new DateTime(2020, 1, 15, 23, 59, 59));
ListOrderReferenceResponse listResponse = client.ListOrderReference(listRequest);
string NextPageToken = listResponse.GetNextPageToken();
ListOrderReferenceByNextTokenRequest listByTokenRequest = new ListOrderReferenceByNextTokenRequest();
listByTokenRequest.WithNextPageToken(NextPageToken);
ListOrderReferenceResponse listByTokenResponse = client.ListOrderReferenceByNextToken(listByTokenRequest);
The charge method combines the following API calls:
Standard Payments / Recurring Payments
For Standard payments the first charge
call will make the SetOrderReferenceDetails, ConfirmOrderReference, Authorize API calls.
Subsequent call to charge
method for the same Order Reference ID will make the call only to Authorize.
For Recurring payments the first charge
call will make the SetBillingAgreementDetails, ConfirmBillingAgreement, AuthorizeOnBillingAgreement API calls.
Subsequent call to charge
method for the same Billing Agreement ID will make the call only to AuthorizeOnBillingAgreement.
Capture Now can be set to
true
for digital goods . For Physical goods it's highly recommended to set the Capture Now tofalse
and the amount captured by making thecapture
API call after the shipment is complete.
Parameter | Mandatory | Values |
---|---|---|
Amazon Reference ID | yes | OrderReference ID (starts with P01 or S01 ) or Billing Agreement ID ( starts with B01 or C01 ) |
Merchant ID | no | Value taken from configuration in the Client class. |
Charge Amount | yes | Amount that needs to be captured |
Currency code | no | If no value is provided, value is taken from the configuration of the Client class |
Authorization Reference ID | yes | Unique string to be passed |
Transaction Timeout | no | Timeout for Authorization - Defaults to 1440 minutes |
Capture Now | no | Will capture the payment automatically when set to true . Defaults to false |
Charge Note | no | Note that is sent to the buyer. Maps to API call variables seller_note , SellerAuthorizationNote |
Charge Order ID | no | Custom order ID provided Maps to API call variables SellerOrderId , SellerBillingAgreementId |
Store Name | no | Name of the store |
Platform ID | no | Merchant ID of the Solution Provider |
Custom Information | no | Any custom string |
Inherit Shipping Address | no | Specifies whether to inherit the shipping address details, Default: true |
Soft Descriptor | no | The description to be shown on the buyer's payment instrument statement, Default: AMZ* |
Provider Credit Details | no | Marketplace information |
MWS Auth Token | no | MWS Auth Token required if API call is made on behalf of the seller |
using AmazonPay;
using AmazonPay.CommonRequests;
using Newtonsoft.json;
using AmazonPay.StandardPaymentRequests;
using AmazonPay.RecurringPaymentRequests;
using AmazonPay.Responses;
try
{
// ChargeRequest class object
ChargeRequest requestParameters = new ChargeRequest();
// Adding the parameters values to the ChargeRequest class
requestParameters.WithAmazonReferenceId("AMAZON_REFERENCE_ID")
.WithChargeReferenceId("AUTHORIZATION_REFERENCE_ID")
.WithAmount("100.50")
.WithMerchantId("MERCHANT_ID")
.WithCurrencyCode(Regions.currencyCode.USD)
.WithPlatformId("SOLUTION_PROVIDER_MERCHANT_ID")
.WithSoftDescriptor("AMZ*")
.WithStoreName("cool stuff store")
.WithMWSAuthToken("MWS_AUTH_TOKEN")
.WithChargeNote("sample note")
.WithChargeOrderId("1234-1234")
.WithCaptureNow(false)
.WithProviderCreditDetails("PROVIDER_MERCHANT_ID", "10", Regions.currencyCode.USD)
.WithInheritShippingAddress(true)
.WithTransactionTimeout(5)
.WithCustomInformation("custom information");
// Get the Authorization response from the charge method
AuthorizeResponse response = client.Charge(requestParameters);
}
catch (InvalidDataException ex)
{
string errorMessage = ex.Data["errorMessage"];
string errorCode = ex.Data["errorCode"];
string exceptionMessage = ex.Message;
}
Parameter | Variable Name | Mandatory | Values |
---|---|---|---|
Access Token | access_token |
yes | Retrieved as GET parameter from the URL |
Region | region |
yes | Default :null Other: us ,de ,uk ,jp Value is set in Client class Configuration |
LWA Client ID | client_id |
yes | Default: null Value should be set in the Client class Configuration |
using AmazonPay;
using AmazonPay.CommonRequests;
using AmazonPay.Responses;
// Your AmazonPay keys are available in your Seller Central account
// Configuration class object
Configuration config = new Configuration();
config.WithAccessToken("ACCESS_TOKEN")
.WithClientId("YOUR_LWA_CLIENT_ID");
Client client = new Client(config);
// Get the Access Token from the URL
string access_token = "ACCESS_TOKEN";
// Calling the function getUserInfo with the access token parameter returns object
string jsonResponse = client.GetUserInfo(access_token);
//using Newtonsoft library
Jobject jsonObject = JObject.Parse(jsonResponse);
// Buyer name
string buyerName = jsonObject.GetValue("name").ToString();
// Buyer Email
string email = jsonObject.GetValue("email").ToString();
// Buyer User Id
string userId = jsonObject.GetValue("user_id").ToString();
<add key="sanitizeList" value="RequestID;Error;SellerId;SignatureMethod;CaptureNow"/>
// Setting Simple Logger Adapter
Common.Logging.LogManager.Adapter = new Common.Logging.Simple.TraceLoggerFactoryAdapter();
// Create logger of type "Client"
Common.Logging.ILog logger = Common.Logging.LogManager.GetLogger<Client>();
Client client = new Client(config);
// Set Logger for Client
client.Logger = logger;
//GetPaymentDetails takes two parameters - AmazonOrderReferenID(required) and MWSAuthToken(optional)
PaymentDetailsResponse payDetailsResponse = client.GetPaymentDetails("S01-9111020-6707923", null);
System.Diagnostics.Debug.WriteLine(payDetailsResponse.GetOrderReferenceDetails().GetXml());
foreach (var group in payDetailsResponse.GetAuthorizationDetails())
{
System.Diagnostics.Debug.WriteLine("Key: {0} Value: {1}", group.Key, group.Value.GetXml());
}
foreach (var group in payDetailsResponse.GetCaptureDetails())
{
System.Diagnostics.Debug.WriteLine("Key: {0} Value: {1}", group.Key, group.Value.GetXml());
}
foreach (var group in payDetailsResponse.GetRefundDetails())
{
System.Diagnostics.Debug.WriteLine("Key: {0} Value: {1}", group.Key, group.Value.GetXml());
}
GetOrderReferenceDetailsRequest getOrderReferenceDetailsRequest = new GetOrderReferenceDetailsRequest();
getOrderReferenceDetailsRequest.WithAmazonOrderReferenceId("AMAZON_ORDER_REFERENCE_ID");
getOrderReferenceDetailsRequest.WithaccessToken(ACCESS_TOKEN);
OrderReferenceDetailsResponse getOrderReferenceDetailsResponse = client.GetOrderReferenceDetails(getOrderReferenceDetailsRequest);
System.Diagnostics.Debug.WriteLine(getOrderReferenceDetailsResponse.GetFullDescriptor());
System.Diagnostics.Debug.WriteLine(getOrderReferenceDetailsResponse.GetAmazonBalanceFirst());
System.Diagnostics.Debug.WriteLine(getOrderReferenceDetailsResponse.GetXml());
// To check the status of your merchant account
GetMerchantAccountStatusRequest request = new GetMerchantAccountStatusRequest();
request.WithMerchantId("YOUR_MERCHANT_ID");
GetMerchantAccountStatusResponse response = client.GetMerchantAccountStatus(request);
System.Diagnostics.Debug.WriteLine("Merchant account status is:" + " " + response.GetAccountStatus());
// Or using MWS delegation to check on the status of another merchant account
GetMerchantAccountStatusRequest request = new GetMerchantAccountStatusRequest();
request.WithMerchantId("YOUR_MERCHANT_ID")
.WithMWSAuthToken("YOUR_MWS_AUTH_TOKEN");
GetMerchantAccountStatusResponse response = client.GetMerchantAccountStatus(request);
System.Diagnostics.Debug.WriteLine("Child account status is:" + " " + response.GetAccountStatus());