Skip to content

Commit 9b59f3a

Browse files
committed
Amazon Pay PHP SDK 3.6.0
1 parent 3b05458 commit 9b59f3a

File tree

7 files changed

+183
-6
lines changed

7 files changed

+183
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
composer.lock
3-
3+
amazon-pay.phar
4+
build

AmazonPay/Client.php

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class Client implements ClientInterface, LoggerAwareInterface
2525
{
26-
const SDK_VERSION = '3.5.0';
26+
const SDK_VERSION = '3.6.0';
2727
const MWS_VERSION = '2013-01-01';
2828
const MAX_ERROR_RETRY = 3;
2929

@@ -365,7 +365,7 @@ private function setParametersAndPost($parameters, $fieldMappings, $requestParam
365365
if (!is_bool($value)) {
366366
throw new \Exception($param . ' value ' . $value . ' is of type ' . gettype($value) . ' and should be a boolean value');
367367
}
368-
} elseif ($param === 'provider_credit_details' || $param === 'provider_credit_reversal_details' || $param === 'order_item_categories') {
368+
} elseif ($param === 'provider_credit_details' || $param === 'provider_credit_reversal_details' || $param === 'order_item_categories' || $param === 'notification_configuration_list') {
369369
if (!is_array($value)) {
370370
throw new \Exception($param . ' value ' . $value . ' is of type ' . gettype($value) . ' and should be an array value');
371371
}
@@ -382,6 +382,8 @@ private function setParametersAndPost($parameters, $fieldMappings, $requestParam
382382
$parameters = $this->setProviderCreditReversalDetails($parameters, $value);
383383
} elseif ($param === 'order_item_categories') {
384384
$parameters = $this->setOrderItemCategories($parameters, $value);
385+
} elseif ($param == 'notification_configuration_list') {
386+
$parameters = $this->setNotificationConfigurationList($parameters, $value);
385387
}
386388

387389
} else {
@@ -459,6 +461,32 @@ private function setOrderItemCategories($parameters, $categories)
459461
}
460462

461463

464+
/* setMerchantNotificationUrls - helper function used by SetMerchantNotificationConfiguration API to set
465+
* one or more Notification Configurations
466+
*/
467+
private function setNotificationConfigurationList($parameters, $configuration)
468+
{
469+
$configurationIndex = 0;
470+
if (!is_array($configuration)) {
471+
throw new \Exception('Notification Configuration List value ' . $configuration . ' is of type ' . gettype($configuration) . ' and should be an array value');
472+
}
473+
foreach ($configuration as $url => $events) {
474+
$configurationIndex = $configurationIndex + 1;
475+
$parameters['NotificationConfigurationList.NotificationConfiguration.' . $configurationIndex . '.NotificationUrl'] = $url;
476+
$eventIndex = 0;
477+
if (!is_array($events)) {
478+
throw new \Exception('Notification Configuration Events value ' . $events . ' is of type ' . gettype($events) . ' and should be an array value');
479+
}
480+
foreach ($events as $event) {
481+
$eventIndex = $eventIndex + 1;
482+
$parameters['NotificationConfigurationList.NotificationConfiguration.' . $configurationIndex . '.EventTypes.EventTypeList.' . $eventIndex] = $event;
483+
}
484+
}
485+
486+
return $parameters;
487+
}
488+
489+
462490
/* setProviderCreditDetails - sets the provider credit details sent via the Capture or Authorize API calls
463491
* @param provider_id - [String]
464492
* @param credit_amount - [String]
@@ -1336,6 +1364,50 @@ public function closeBillingAgreement($requestParameters = array())
13361364
}
13371365

13381366

1367+
/* GetMerchantNotificationConfiguration API Call - Returns details about the defined IPN endpoints
1368+
*
1369+
* @param requestParameters['merchant_id'] - [String]
1370+
* @optional requestParameters['mws_auth_token'] - [String]
1371+
*/
1372+
public function getMerchantNotificationConfiguration($requestParameters = array())
1373+
{
1374+
$parameters = array();
1375+
$parameters['Action'] = 'GetMerchantNotificationConfiguration';
1376+
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
1377+
1378+
$fieldMappings = array(
1379+
'merchant_id' => 'SellerId',
1380+
'mws_auth_token' => 'MWSAuthToken'
1381+
);
1382+
1383+
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
1384+
return ($responseObject);
1385+
}
1386+
1387+
1388+
/* SetMerchantNotificationConfiguration API Call - Set IPN endpoints
1389+
*
1390+
* @param requestParameters['merchant_id'] - [String]
1391+
* @param requestParameters['notification_configuration_list'] - [Array]
1392+
* @optional requestParameters['mws_auth_token'] - [String]
1393+
*/
1394+
public function setMerchantNotificationConfiguration($requestParameters = array())
1395+
{
1396+
$parameters = array();
1397+
$parameters['Action'] = 'SetMerchantNotificationConfiguration';
1398+
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
1399+
1400+
$fieldMappings = array(
1401+
'merchant_id' => 'SellerId',
1402+
'notification_configuration_list' => array(),
1403+
'mws_auth_token' => 'MWSAuthToken'
1404+
);
1405+
1406+
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
1407+
return ($responseObject);
1408+
}
1409+
1410+
13391411
/* charge convenience method
13401412
* Performs the API calls
13411413
* 1. SetOrderReferenceDetails / SetBillingAgreementDetails

AmazonPay/ClientInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ public function authorizeOnBillingAgreement($requestParameters = array());
391391
public function closeBillingAgreement($requestParameters = array());
392392

393393

394+
/* GetMerchantNotificationConfiguration API Call - Returns details about the defined IPN endpoints
395+
*
396+
* @param requestParameters['merchant_id'] - [String]
397+
* @optional requestParameters['mws_auth_token'] - [String]
398+
*/
399+
public function getMerchantNotificationConfiguration($requestParameters = array());
400+
401+
402+
/* SetMerchantNotificationConfiguration API Call - Set IPN endpoints
403+
*
404+
* @param requestParameters['merchant_id'] - [String]
405+
* @param requestParameters['notification_configuration_list'] - [Array]
406+
* @optional requestParameters['mws_auth_token'] - [String]
407+
*/
408+
public function setMerchantNotificationConfiguration($requestParameters = array());
409+
410+
394411
/* charge convenience method
395412
* Performs the API calls
396413
* 1. SetOrderReferenceDetails / SetBillingAgreementDetails

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
3.6.0 - November 2019
2+
- Add GetMerchantNotificationConfiguration API call
3+
- Add SetMerchantNotificationConfiguration API call
4+
15
3.5.0 - August 2019
26
- Added additional attributes (success_url, failure_url) to ConfirmBillingAgreement and (subscription_amount, currency_code) to SetBillingAgreement Details.. See Amazon Pay Strong Customer Authentication (SCA) Upgrade Integration Guide for more information.
37
- Synced missing changes in ClientInterface.php

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ See the [API Response](https://github.com/amzn/amazon-pay-sdk-php#api-response)
299299
### IPN Handling
300300

301301
1. To receive IPN's successfully you will need an valid SSL on your domain.
302-
2. You can set up your Notification endpoints in Seller Central by accessing the Integration Settings page in the Settings tab.
302+
2. You can set up your Notification endpoints by either (a) using the Seller Central Integration Settings page Settings tab, or (b) by using the SetMerchantNotificationConfiguration API call.
303303
3. IpnHandler.php class handles verification of the source and the data of the IPN
304304

305305
Add the below code into any file and set the URL to the file location in Merchant/Integrator URL by accessing Integration Settings page in the Settings tab.
@@ -320,6 +320,34 @@ $ipnHandler = new IpnHandler($headers, $body);
320320
```
321321
See the [IPN Response](https://github.com/amzn/amazon-pay-sdk-php#ipn-response) section for information on parsing the IPN response.
322322

323+
#### Setting notification endpoints using SetMerchantNotificationConfiguration API
324+
325+
```php
326+
$client = new AmazonPay\Client($config);
327+
328+
// possible array values: ALL, ORDER_REFERENCE, PAYMENT_AUTHORIZE, PAYMENT_CAPTURE, PAYMENT_REFUND, BILLING_AGREEMENT, CHARGEBACK_DETAILED
329+
$notificationConfiguration['https://dev.null/ipn/onetime'] = array('ORDER_REFERENCE', 'PAYMENT_AUTHORIZE', 'PAYMENT_CAPTURE');
330+
$notificationConfiguration['https://dev.null/ipn/recurring'] = array('BILLING_AGREEMENT');
331+
$notificationConfiguration['https://dev.null/ipn/refunds'] = array('PAYMENT_REFUND', 'CHARGEBACK_DETAILED');
332+
$requestParameters['notification_configuration_list'] = $notificationConfiguration;
333+
334+
// or, if you prefer all IPNs come to the same endpoint, do this one-liner instead:
335+
// $requestParameters['notification_configuration_list'] = array('https://dev.null/ipn' => array('ALL'));
336+
337+
// if you are calling on behalf of another merhcant using delegated access, be sure to set the merchant ID and auth token:
338+
// $requestParameters['merchant_id'] = 'A3URCZVLDMDI45';
339+
// $requestParameters['mws_auth_token'] = 'amzn.mws.d6ac8f2d-6a5f-b06a-bc12-1d0dbf4ca63d';
340+
341+
$response = $client->setMerchantNotificationConfiguration($requestParameters);
342+
if ($response->toArray()['ResponseStatus'] !== '200') {
343+
print "error occured calling API";
344+
}
345+
346+
// to troubleshoot, you can call GetMerchantNotificationConfiguration to view current IPN settings
347+
$response = $client->getMerchantNotificationConfiguration($requestParameters);
348+
print $response->toXml();
349+
```
350+
323351
### Convenience Methods
324352

325353
#### Charge Method

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "amzn/amazon-pay-sdk-php",
33
"type": "library",
44
"description": "Amazon Pay SDK (PHP)",
5-
"version": "3.5.0",
5+
"version": "3.6.0",
66
"keywords": [
77
"amazon",
88
"pay",

tst/unit/ClientTest.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,6 @@ public function testCloseBillingAgreement()
10151015

10161016
$action = 'CloseBillingAgreement';
10171017

1018-
10191018
$parameters = $this->setParametersAndPost($fieldMappings, $action);
10201019
$expectedParameters = $parameters['expectedParameters'];
10211020
$apiCallParams = $parameters['apiCallParams'];
@@ -1029,6 +1028,58 @@ public function testCloseBillingAgreement()
10291028
$this->assertEquals($apiParametersString, $expectedStringParams);
10301029
}
10311030

1031+
public function testGetMerchantNotificationConfiguration()
1032+
{
1033+
$client = new Client($this->configParams);
1034+
$fieldMappings = array(
1035+
'merchant_id' => 'SellerId',
1036+
'mws_auth_token' => 'MWSAuthToken'
1037+
);
1038+
1039+
$action = 'GetMerchantNotificationConfiguration';
1040+
1041+
$parameters = $this->setParametersAndPost($fieldMappings, $action);
1042+
$expectedParameters = $parameters['expectedParameters'];
1043+
$apiCallParams = $parameters['apiCallParams'];
1044+
1045+
$expectedStringParams = $this->callPrivateMethod($client, 'calculateSignatureAndParametersToString', $expectedParameters);
1046+
1047+
$response = $client->getMerchantNotificationConfiguration($apiCallParams);
1048+
1049+
$apiParametersString = $client->getParameters();
1050+
1051+
$this->assertEquals($apiParametersString, $expectedStringParams);
1052+
}
1053+
1054+
public function testSetMerchantNotificationConfiguration()
1055+
{
1056+
$client = new Client($this->configParams);
1057+
$fieldMappings = array(
1058+
'merchant_id' => 'SellerId',
1059+
'notification_configuration_list' => array(),
1060+
'mws_auth_token' => 'MWSAuthToken'
1061+
);
1062+
1063+
$action = 'SetMerchantNotificationConfiguration';
1064+
1065+
$parameters = $this->setParametersAndPost($fieldMappings, $action);
1066+
$expectedParameters = $parameters['expectedParameters'];
1067+
$expectedParameters['NotificationConfigurationList.NotificationConfiguration.1.NotificationUrl'] = 'https://dev.null/one';
1068+
$expectedParameters['NotificationConfigurationList.NotificationConfiguration.2.NotificationUrl'] = 'https://dev.null/two';
1069+
$expectedParameters['NotificationConfigurationList.NotificationConfiguration.1.EventTypes.EventTypeList.1'] = 'ORDER_REFERENCE';
1070+
$expectedParameters['NotificationConfigurationList.NotificationConfiguration.1.EventTypes.EventTypeList.2'] = 'PAYMENT_AUTHORIZE';
1071+
$expectedParameters['NotificationConfigurationList.NotificationConfiguration.2.EventTypes.EventTypeList.1'] = 'ALL';
1072+
$apiCallParams = $parameters['apiCallParams'];
1073+
1074+
$expectedStringParams = $this->callPrivateMethod($client, 'calculateSignatureAndParametersToString', $expectedParameters);
1075+
1076+
$response = $client->setMerchantNotificationConfiguration($apiCallParams);
1077+
1078+
$apiParametersString = $client->getParameters();
1079+
1080+
$this->assertEquals($apiParametersString, $expectedStringParams);
1081+
}
1082+
10321083
public function testCharge()
10331084
{
10341085
$client = new Client($this->configParams);
@@ -1183,6 +1234,10 @@ private function setParametersAndPost($fieldMappings, $action)
11831234
$apiCallParams[$parm] = array('Antiques', 'Electronics');
11841235
} elseif ($parm === 'order_status_list') {
11851236
$apiCallParams[$parm] = array('Open', 'Closed');
1237+
} elseif ($parm === 'notification_configuration_list') {
1238+
$notificationConfiguration['https://dev.null/one'] = array('ORDER_REFERENCE', 'PAYMENT_AUTHORIZE');
1239+
$notificationConfiguration['https://dev.null/two'] = array('ALL');
1240+
$apiCallParams[$parm] = $notificationConfiguration;
11861241
} elseif (!isset($expectedParameters[$value])) {
11871242
$unique_id = uniqid();
11881243
$expectedParameters[$value] = $unique_id;

0 commit comments

Comments
 (0)