Skip to content

Commit

Permalink
Amazon Pay API SDK PHP 2.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhirajnow committed Jun 29, 2023
1 parent 19186c9 commit 4583b73
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
18 changes: 17 additions & 1 deletion Amazon/Pay/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

class Client implements ClientInterface, ReportingClientInterface
{
const SDK_VERSION = '2.6.1';
const SDK_VERSION = '2.6.2';
const SDK_LANGUAGE = 'PHP';
const HASH_ALGORITHM = 'sha256';
const API_VERSION = 'v2';

Expand Down Expand Up @@ -357,10 +358,25 @@ public function getPostSignedHeaders($http_request_method, $request_uri, $reques
'x-amz-pay-host' => $this->getHost($request_uri),
'x-amz-pay-date' => $timeStamp,
'x-amz-pay-region' => $this->config['region'],
'x-amz-pay-sdk-type' => self::SDK_LANGUAGE,
'x-amz-pay-sdk-version' => self::SDK_VERSION,
'x-amz-pay-language-version' => PHP_VERSION,
'authorization' => $this->getAlgorithm() . " PublicKeyId=" . $public_key_id . ", " . $signedHeaders,
'user-agent' => $this->constructUserAgentHeader()
);

if(isset($this->config['integrator_id'])){
$headerArray['x-amz-pay-integrator-id'] = $this->config['integrator_id'];
}

if(isset($this->config['integrator_version'])){
$headerArray['x-amz-pay-integrator-version'] = $this->config['integrator_version'];
}

if(isset($this->config['platform_version'])){
$headerArray['x-amz-pay-platform-version'] = $this->config['platform_version'];
}

ksort($headerArray);
foreach ($headerArray as $key => $value) {
$queryParameters[] = $key . ':' . $value;
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Version 2.6.2 - June 2023
* Added optional headers to APIs. These are intended to be used by solution providers to send their platform/plugin id’s and versions.
* Corrected README.md file related to Reporting APIs.

### Version 2.6.1 - March 2023
* Corrected some minor changes in Reporting APIs
* Note: Please use 2.6.1 if you are implementing Reporting APIs and avoid 2.6.0
Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Namespace for this package is Amazon\Pay\API so that there are no conflicts with
'sandbox' => true, // true (Sandbox) or false (Production) boolean
'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
'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format
'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format
'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format
);
```
If you have created environment specific keys (i.e Public Key Starts with LIVE or SANDBOX) in Seller Central, then use those PublicKeyId & PrivateKey. In this case, there is no need to pass the Sandbox parameter to the ApiConfiguration.
Expand All @@ -87,6 +90,9 @@ If you have want to enable proxy support, you can set it in the $amazonpay_confi
'sandbox' => true, // true (Sandbox) or false (Production) boolean
'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
'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format
'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format
'platform_version' => '0.0.4', // (optional) Solution Provider Platform Version in Semantic Versioning Format
'proxy' => [
'host' => 'proxy_host',
'port' => 'proxy_port',
Expand Down Expand Up @@ -286,6 +292,9 @@ An alternate way to do Step 2 would be to use PHP arrays and programmatically ge
'region' => 'US',
'sandbox' => true,
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2',
'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format
'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format
'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format
);
$payload = array(
'webCheckoutDetails' => array(
Expand Down Expand Up @@ -326,6 +335,9 @@ An alternate way to do Step 2 would be to use PHP arrays and programmatically ge
'region' => 'US',
'sandbox' => true,
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2',
'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format
'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format
'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format
);
$payload = array(
'webCheckoutDetails' => array(
Expand Down Expand Up @@ -366,6 +378,9 @@ An alternate way to do Step 2 would be to use PHP arrays and programmatically ge
'region' => 'US',
'sandbox' => true,
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2',
'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format
'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format
'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format
);

try {
Expand Down Expand Up @@ -417,6 +432,9 @@ An alternate way to do Step 2 would be to use PHP arrays and programmatically ge
'region' => 'US',
'sandbox' => true,
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2',
'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format
'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format
'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format
);

$payload = array(
Expand Down Expand Up @@ -466,6 +484,9 @@ An alternate way to do Step 2 would be to use PHP arrays and programmatically ge
'region' => 'US',
'sandbox' => true,
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2',
'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format
'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format
'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format
);

$payload = array(
Expand Down Expand Up @@ -649,8 +670,8 @@ Example call to createSignature function with values:
);

$requestPayload = array(
'reportType' => '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_',
'processingStatus' => 'COMPLETED',
'reportTypes' => '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_',
'processingStatuses' => 'COMPLETED',
'pageSize' => '10'
);

Expand Down Expand Up @@ -722,7 +743,7 @@ Example call to createSignature function with values:
);

try {
$reportDocumentId = "1234567890";
$reportDocumentId = "amzn1.tortuga.0.000000000-0000-0000-0000-000000000000.00000000000000";
$client = new Amazon\Pay\API\Client($amazonpay_config);
$result = $client->getReportDocument($reportDocumentId);

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amzn/amazon-pay-api-sdk-php",
"type": "library",
"description": "Amazon Pay API SDK (PHP)",
"version": "2.6.1",
"version": "2.6.2",
"keywords": [
"amazon",
"pay",
Expand Down
27 changes: 25 additions & 2 deletions tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,42 @@

class ClientTest extends TestCase
{
const INTEGRATOR_ID = 'AXXXXXXXXXXXXX';
const INTEGRATOR_VERSION = '5.4.3';
const PLATFORM_VERSION = '2.0.7';

private $configArray = array(
//config
array(
'public_key_id' => 'ABC123DEF456XYZ789IJK000',
'private_key' => 'tests/unit/unit_test_key_private.txt',
'sandbox' => true,
'region' => 'na'
'region' => 'na',
'integrator_id' => self::INTEGRATOR_ID,
'integrator_version' => self::INTEGRATOR_VERSION,
'platform_version' => self::PLATFORM_VERSION
),
//config with algorithm as a parameter
array(
'public_key_id' => 'ABC123DEF456XYZ789IJK000',
'private_key' => 'tests/unit/unit_test_key_private.txt',
'sandbox' => true,
'region' => 'na',
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2'
'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2',
'integrator_id' => self::INTEGRATOR_ID,
'integrator_version' => self::INTEGRATOR_VERSION,
'platform_version' => self::PLATFORM_VERSION

),
//config with proxy parameters
array(
'public_key_id' => 'ABC123DEF456XYZ789IJK000',
'private_key' => 'tests/unit/unit_test_key_private.txt',
'sandbox' => true,
'region' => 'na',
'integrator_id' => self::INTEGRATOR_ID,
'integrator_version' => self::INTEGRATOR_VERSION,
'platform_version' => self::PLATFORM_VERSION,
'proxy' => [
'host' => 'proxy_host',
'port' => 'proxy_port',
Expand Down Expand Up @@ -75,6 +89,9 @@ public function testConfigArray()
$this->assertEquals($this->configArray[0]['private_key'], $client->__get('private_key'));
$this->assertEquals($this->configArray[0]['sandbox'], $client->__get('sandbox'));
$this->assertEquals($this->configArray[0]['region'], $client->__get('region'));
$this->assertEquals($this->configArray[0]['integrator_id'], $client->__get('integrator_id'));
$this->assertEquals($this->configArray[0]['integrator_version'], $client->__get('integrator_version'));
$this->assertEquals($this->configArray[0]['platform_version'], $client->__get('platform_version'));
}

public function testConfigArrayWithAlgorithm()
Expand All @@ -86,6 +103,9 @@ public function testConfigArrayWithAlgorithm()
$this->assertEquals($this->configArray[1]['sandbox'], $client->__get('sandbox'));
$this->assertEquals($this->configArray[1]['region'], $client->__get('region'));
$this->assertEquals($this->configArray[1]['algorithm'], $client->__get('algorithm'));
$this->assertEquals($this->configArray[1]['integrator_id'], $client->__get('integrator_id'));
$this->assertEquals($this->configArray[1]['integrator_version'], $client->__get('integrator_version'));
$this->assertEquals($this->configArray[1]['platform_version'], $client->__get('platform_version'));
}

public function testConfigArrayWithProxy() {
Expand All @@ -99,6 +119,9 @@ public function testConfigArrayWithProxy() {
$this->assertEquals($this->configArray[2]['proxy']['port'], $client->__get('proxy')['port']);
$this->assertEquals($this->configArray[2]['proxy']['username'], $client->__get('proxy')['username']);
$this->assertEquals($this->configArray[2]['proxy']['password'], $client->__get('proxy')['password']);
$this->assertEquals($this->configArray[2]['integrator_id'], $client->__get('integrator_id'));
$this->assertEquals($this->configArray[2]['integrator_version'], $client->__get('integrator_version'));
$this->assertEquals($this->configArray[2]['platform_version'], $client->__get('platform_version'));
}

public function testGetCanonicalURI()
Expand Down

0 comments on commit 4583b73

Please sign in to comment.