Skip to content

Commit

Permalink
Amazon Pay PHP SDK 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Shangamesh T committed Aug 26, 2022
1 parent 7037a9b commit 6c579f0
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Amazon/Pay/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Client implements ClientInterface
{
const SDK_VERSION = '2.3.2';
const SDK_VERSION = '2.4.0';
const HASH_ALGORITHM = 'sha256';
const AMAZON_SIGNATURE_ALGORITHM = 'AMZN-PAY-RSASSA-PSS';
const API_VERSION = 'v2';
Expand Down Expand Up @@ -479,7 +479,7 @@ public function apiCall($method, $urlFragment, $payload, $headers = null, $query
}
}

$httpCurlRequest = new HttpCurl();
$httpCurlRequest = new HttpCurl(isset($this->config['proxy']) ? $this->config['proxy'] : []);
$response = $httpCurlRequest->invokeCurl($method, $url, $payload, $postSignedHeaders);
return $response;
}
Expand Down
17 changes: 17 additions & 0 deletions Amazon/Pay/API/HttpCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class HttpCurl

private $curlResponseInfo = null;
private $requestId = null;
private $proxyConfig;

/**
* @param array $proxyConfig
*/
public function __construct ($proxyConfig = []) {
$this->proxyConfig = $proxyConfig;
}

private function header_callback($ch, $header_line)
{
Expand Down Expand Up @@ -40,6 +48,11 @@ private function commonCurlParams($url)
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'header_callback'));

if ($this->useProxy()) {
curl_setopt($ch, CURLOPT_PROXY, $this->proxyConfig['host'] . ':' . $this->proxyConfig['port']);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxyConfig['username'] . ':' . $this->proxyConfig['password']);
}

return $ch;
}

Expand Down Expand Up @@ -153,6 +166,10 @@ private function pauseOnRetry($retries, $response)
}
}

private function useProxy() {
return !empty($this->proxyConfig['username']) && !empty($this->proxyConfig['password']) && !empty($this->proxyConfig['host']) && !empty($this->proxyConfig['port']);
}

}

?>
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### Version 2.4.0 - August 2022
* Enabled Proxy Support for HttpCurl

#### Version 2.3.2 - February 2022
* Fixed Deprecation error for PHP version 8 - Passing null to parameter ($data) of type string is deprecate

Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ If you have created environment specific keys (i.e Public Key Starts with LIVE o
'region' => 'us' // Must be one of: 'us', 'eu', 'jp'
);
```

If you have want to enable proxy support, you can set it in the $amazonpay_config in the following way:
```php
$amazonpay_config = array(
'public_key_id' => 'ABC123DEF456XYZ', // RSA Public Key ID (this is not the Merchant or Seller ID)
'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation)
'sandbox' => true, // true (Sandbox) or false (Production) boolean
'region' => 'us', // Must be one of: 'us', 'eu', 'jp'
'proxy' => [
'host' => 'proxy_host',
'port' => 'proxy_port',
'username' => 'proxy_username',
'password' => 'proxy_password',
]
);
```
# Versioning

The pay-api.amazon.com|eu|jp endpoint uses versioning to allow future updates. The major version of this SDK will stay aligned with the API version of the endpoint.
Expand Down
4 changes: 2 additions & 2 deletions 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.3.2",
"version": "2.4.0",
"keywords": [
"amazon",
"pay",
Expand Down Expand Up @@ -33,4 +33,4 @@
"require-dev": {
"phpunit/phpunit": "^4"
}
}
}
28 changes: 27 additions & 1 deletion tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ class ClientTest extends TestCase
'public_key_id' => 'ABC123DEF456XYZ789IJK000',
'private_key' => 'tests/unit/unit_test_key_private.txt',
'sandbox' => true,
'region' => 'us'
'region' => 'us',
);

private $configParamsWithProxy = array(
'public_key_id' => 'ABC123DEF456XYZ789IJK000',
'private_key' => 'tests/unit/unit_test_key_private.txt',
'sandbox' => true,
'region' => 'us',
'proxy' => [
'host' => 'proxy_host',
'port' => 'proxy_port',
'username' => 'proxy_username',
'password' => 'proxy_password',
]
);

private $requestParameters = array(
Expand Down Expand Up @@ -53,6 +66,19 @@ public function testConfigArray()
$this->assertEquals($this->configParams['region'], $client->__get('region'));
}

public function testConfigArrayWithProxy() {
$client = new Client($this->configParamsWithProxy);

$this->assertEquals($this->configParamsWithProxy['public_key_id'], $client->__get('public_key_id'));
$this->assertEquals($this->configParamsWithProxy['private_key'], $client->__get('private_key'));
$this->assertEquals($this->configParamsWithProxy['sandbox'], $client->__get('sandbox'));
$this->assertEquals($this->configParamsWithProxy['region'], $client->__get('region'));
$this->assertEquals($this->configParamsWithProxy['proxy']['host'], $client->__get('proxy')['host']);
$this->assertEquals($this->configParamsWithProxy['proxy']['port'], $client->__get('proxy')['port']);
$this->assertEquals($this->configParamsWithProxy['proxy']['username'], $client->__get('proxy')['username']);
$this->assertEquals($this->configParamsWithProxy['proxy']['password'], $client->__get('proxy')['password']);
}

public function testGetCanonicalURI()
{
$client = new Client($this->configParams);
Expand Down

0 comments on commit 6c579f0

Please sign in to comment.