diff --git a/Amazon/Pay/API/Client.php b/Amazon/Pay/API/Client.php index fd4fef5..d449435 100644 --- a/Amazon/Pay/API/Client.php +++ b/Amazon/Pay/API/Client.php @@ -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'; @@ -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; diff --git a/CHANGES.md b/CHANGES.md index c2f2944..3288761 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/README.md b/README.md index ed8509a..131804b 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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', @@ -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( @@ -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( @@ -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 { @@ -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( @@ -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( @@ -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' ); @@ -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); diff --git a/composer.json b/composer.json index 4ca7f45..d319225 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/tests/unit/ClientTest.php b/tests/unit/ClientTest.php index 6674422..19f3a67 100644 --- a/tests/unit/ClientTest.php +++ b/tests/unit/ClientTest.php @@ -9,13 +9,20 @@ 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( @@ -23,7 +30,11 @@ class ClientTest extends TestCase '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( @@ -31,6 +42,9 @@ class ClientTest extends TestCase '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', @@ -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() @@ -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() { @@ -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()