Skip to content

Commit

Permalink
Amazon Pay API SDK (Node.js) 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
akshitaWaldia committed Mar 16, 2023
1 parent 5f05285 commit 87cf11a
Show file tree
Hide file tree
Showing 11 changed files with 1,895 additions and 74 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Version 2.3.0 - March 2023
* Introducing new v2 Reporting APIs. Reports allow you to retieve consolidated data about Amazon Pay transactions and settlements. In addition to managing and downloading reports using Seller Central, Amazon Pay offers APIs to manage and retrieve your reports.
* Introducing new signature generation algorithm AMZN-PAY-RSASSA-PSS-V2 and increasing salt length from 20 to 32.
* Added support for handling new parameter 'shippingAddressList' in Checkout Session response. Change is fully backwards compatible.
* Added Error code 408 to API retry logic
* Note : To use new algorithm AMZN-PAY-RSASSA-PSS-V2, "algorithm" needs to be provided as an additional field in "config" and also while rendering Amazon Pay button in "createCheckoutSessionConfig". The changes are backwards-compatible, SDK will use AMZN-PAY-RSASSA-PSS by default.

#### Version 2.2.2 - June 2022
* Fixed security vulnerabilities in dependencies.

Expand Down
229 changes: 221 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ To associate the key with your account, follow the instructions here to
'publicKeyId': 'ABC123DEF456XYZ', // RSA Public Key ID (this is not the Merchant or Seller ID)
'privateKey': fs.readFileSync('tst/private.pem'), // Path to RSA Private Key (or a string representation)
'region': 'us', // Must be one of: 'us', 'eu', 'jp'
'sandbox': true // true (Sandbox) or false (Production) boolean
'sandbox': true, // true (Sandbox) or false (Production) boolean
'algorithm': 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};
```

Expand All @@ -61,6 +62,7 @@ If you have created environment specific keys (i.e Public Key Starts with LIVE o
'publicKeyId': 'PUBLIC_KEY_ID', // LIVE-XXXXX or SANDBOX-XXXXX
'privateKey': fs.readFileSync('tst/private.pem'), // Path to RSA Private Key (or a string representation)
'region': 'us', // Must be one of: 'us', 'eu', 'jp'
'algorithm': 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};
```

Expand Down Expand Up @@ -196,7 +198,8 @@ If you are a Solution Provider and need to make an API call on behalf of a diffe
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};

const payload = {
Expand Down Expand Up @@ -224,7 +227,8 @@ If you are a Solution Provider and need to make an API call on behalf of a diffe
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};

const payload = {
Expand Down Expand Up @@ -255,7 +259,8 @@ If you are a Solution Provider and need to make an API call on behalf of a diffe
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};

const headers = {
Expand All @@ -280,7 +285,8 @@ If you are a Solution Provider and need to make an API call on behalf of a diffe
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};

const payload = {
Expand Down Expand Up @@ -321,7 +327,8 @@ If you are a Solution Provider and need to make an API call on behalf of a diffe
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};

const payload = {
Expand Down Expand Up @@ -371,7 +378,8 @@ Example call to generateButtonSignature function:
publicKeyId: 'ABC123DEF456XYZ',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: true
sandbox: true,
algorithm: 'AMZN-PAY-RSASSA-PSS-V2' // Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified
};

const testPayClient = new Client.AmazonPayClient(config);
Expand Down Expand Up @@ -453,7 +461,7 @@ Example request method:
const options = {
method: 'POST',
urlFragment: '${version}/in-store/merchantScan',
payload = {
payload: {
scanData: 'UKhrmatMeKdlfY6b',
scanReferenceId: '0b8fb271-2ae2-49a5-b35d4',
merchantCOE: 'US',
Expand Down Expand Up @@ -484,3 +492,208 @@ Example request method:
const client = new Client.AmazonPayClient(config);
const signedHeaders = client.getSignedHeaders(options);
```

# Reporting APIs code samples

## Amazon Checkout v2 Reporting APIs - GetReport API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const testPayClient = new Client.WebStoreClient(config);
const requestPayload = {
reportTypes: "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_SETTLEMENT_DATA_",
};
const response = testPayClient.getReports(requestPayload);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```

## Amazon Checkout v2 Reporting APIs - GetReportById API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const reportId = '1234567890';
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.getReportById(reportId);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```

## Amazon Checkout v2 Reporting APIs - GetReportDocument API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const reportDocumentId = '1234567890';
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.getReportDocument(reportDocumentId);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```

## Amazon Checkout v2 Reporting APIs - GetReportSchedules API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const reportTypes = '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_,_GET_FLAT_FILE_OFFAMAZONPAYMENTS_BILLING_AGREEMENT_DATA_';
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.getReportSchedules(reportTypes);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```

## Amazon Checkout v2 Reporting APIs - GetReportScheduleById API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const reportScheduleId = '1234567890';
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.getReportScheduleById(reportScheduleId);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```

## Amazon Checkout v2 Reporting APIs - CreateReport API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const requestPayload = {
reportType: '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_AUTHORIZATION_DATA_',
startTime: '20221114T074550Z',
endTime: '20221114T074550Z'
}
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.createReport(requestPayload);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```

## Amazon Checkout v2 Reporting APIs - CreateReportSchedule API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const requestPayload = {
reportType: "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_",
scheduleFrequency: "P1D",
nextReportCreationTime: "20230317T074550Z",
deleteExistingSchedule: false
}
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.createReportSchedule(requestPayload);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```

## Amazon Checkout v2 Reporting APIs - CancelReportSchedule API
```js
const fs = require('fs');
const uuidv4 = require('uuid/v4');
const Client = require('@amazonpay/amazon-pay-api-sdk-nodejs');

const config = {
publicKeyId: 'YOUR_PUBLIC_KEY_ID',
privateKey: fs.readFileSync('tst/private.pem'),
region: 'us',
sandbox: false,
};

const reportScheduleId = "1234567890";
const testPayClient = new Client.WebStoreClient(config);
const response = testPayClient.cancelReportSchedule(reportScheduleId);

response.then(function (result) {
console.log(result.data);
}).catch(err => {
console.log(err);
});
```
Loading

0 comments on commit 87cf11a

Please sign in to comment.