Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 2a9fe1b

Browse files
committed
Make whitespace consistent
To make future diffs cleaner. Also inserts explicit braces around oneline if statements and fixes a couple of elseifs.
1 parent 0b96d1e commit 2a9fe1b

11 files changed

Lines changed: 592 additions & 550 deletions

AmazonPay/Client.php

Lines changed: 232 additions & 210 deletions
Large diffs are not rendered by default.

AmazonPay/HttpCurl.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class HttpCurl implements HttpCurlInterface
1313
private $header = false;
1414
private $accessToken = null;
1515
private $curlResponseInfo = null;
16-
private $headerArray = array();
16+
private $headerArray = [];
1717

1818
/* Takes user configuration array as input
1919
* Takes configuration for API call or IPN config
@@ -47,7 +47,7 @@ public function setAccessToken($accesstoken)
4747
* config['proxy_password']
4848
*/
4949

50-
protected function commonCurlParams($url,$userAgent)
50+
protected function commonCurlParams($url, $userAgent)
5151
{
5252
$ch = curl_init();
5353
curl_setopt($ch, CURLOPT_URL, $url);
@@ -60,8 +60,9 @@ protected function commonCurlParams($url,$userAgent)
6060
curl_setopt($ch, CURLOPT_CAINFO, $this->config['cabundle_file']);
6161
}
6262

63-
if (!empty($userAgent))
63+
if (!empty($userAgent)) {
6464
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
65+
}
6566

6667
if ($this->config['proxy_host'] != null && $this->config['proxy_port'] != -1) {
6768
curl_setopt($ch, CURLOPT_PROXY, $this->config['proxy_host'] . ':' . $this->config['proxy_port']);
@@ -82,12 +83,12 @@ protected function commonCurlParams($url,$userAgent)
8283

8384
public function httpPost($url, $userAgent = null, $parameters = null)
8485
{
85-
$ch = $this->commonCurlParams($url,$userAgent);
86-
86+
$ch = $this->commonCurlParams($url, $userAgent);
87+
8788
curl_setopt($ch, CURLOPT_POST, true);
8889
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
8990
curl_setopt($ch, CURLOPT_HEADER, false);
90-
91+
9192
$response = $this->execute($ch);
9293
return $response;
9394
}
@@ -99,7 +100,7 @@ public function httpPost($url, $userAgent = null, $parameters = null)
99100

100101
public function httpGet($url, $userAgent = null)
101102
{
102-
$ch = $this->commonCurlParams($url,$userAgent);
103+
$ch = $this->commonCurlParams($url, $userAgent);
103104

104105
// Setting the HTTP header with the Access Token only for Getting user info
105106
if ($this->header) {

AmazonPay/HttpCurlInterface.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
/* Interface for HttpCurl.php */
55

66
interface HttpCurlInterface
7-
{
7+
{
88
/* Set Http header for Access token for the GetUserInfo call */
9-
9+
1010
public function setHttpHeader();
11-
11+
1212
/* Setter for Access token to get the user info */
13-
13+
1414
public function setAccessToken($accesstoken);
15-
15+
1616
/* POST using curl for the following situations
1717
* 1. API calls
1818
* 2. IPN certificate retrieval
1919
* 3. Get User Info
2020
*/
21-
21+
2222
public function httpPost($url, $userAgent = null, $parameters = null);
23-
23+
2424
/* GET using curl for the following situations
2525
* 1. IPN certificate retrieval
2626
* 3. Get User Info
2727
*/
28-
28+
2929
public function httpGet($url, $userAgent = null);
3030
}

AmazonPay/IpnHandler.php

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
require_once 'HttpCurl.php';
1010
require_once 'IpnHandlerInterface.php';
1111
if (!interface_exists('\Psr\Log\LoggerAwareInterface')) {
12-
require_once(__DIR__.'/../Psr/Log/LoggerAwareInterface.php');
12+
require_once(__DIR__ . '/../Psr/Log/LoggerAwareInterface.php');
1313
}
1414
if (!interface_exists('\Psr\Log\LoggerInterface')) {
15-
require_once(__DIR__.'/../Psr/Log/LoggerInterface.php');
15+
require_once(__DIR__ . '/../Psr/Log/LoggerInterface.php');
1616
}
17+
1718
use Psr\Log\LoggerAwareInterface;
1819
use Psr\Log\LoggerInterface;
1920

@@ -32,11 +33,13 @@ class IpnHandler implements IpnHandlerInterface, LoggerAwareInterface
3233
// Implement a logging library that utilizes the PSR 3 logger interface
3334
private $logger = null;
3435

35-
private $ipnConfig = array('cabundle_file' => null,
36-
'proxy_host' => null,
37-
'proxy_port' => -1,
38-
'proxy_username' => null,
39-
'proxy_password' => null);
36+
private $ipnConfig = array(
37+
'cabundle_file' => null,
38+
'proxy_host' => null,
39+
'proxy_port' => -1,
40+
'proxy_username' => null,
41+
'proxy_password' => null
42+
);
4043

4144

4245
public function __construct($headers, $body, $ipnConfig = null)
@@ -51,11 +54,11 @@ public function __construct($headers, $body, $ipnConfig = null)
5154
// Get the list of fields that we are interested in
5255
$this->fields = array(
5356
"Timestamp" => true,
54-
"Message" => true,
57+
"Message" => true,
5558
"MessageId" => true,
56-
"Subject" => false,
57-
"TopicArn" => true,
58-
"Type" => true
59+
"Subject" => false,
60+
"TopicArn" => true,
61+
"Type" => true
5962
);
6063

6164
// Validate the IPN message header [x-amz-sns-message-type]
@@ -74,7 +77,7 @@ public function __construct($headers, $body, $ipnConfig = null)
7477
private function checkConfigKeys($ipnConfig)
7578
{
7679
$ipnConfig = array_change_key_case($ipnConfig, CASE_LOWER);
77-
$ipnConfig = $this->trimArray($ipnConfig);
80+
$ipnConfig = $this->trimArray($ipnConfig);
7881

7982
foreach ($ipnConfig as $key => $value) {
8083
if (array_key_exists($key, $this->ipnConfig)) {
@@ -86,13 +89,15 @@ private function checkConfigKeys($ipnConfig)
8689
}
8790
}
8891

89-
public function setLogger(LoggerInterface $logger = null) {
92+
public function setLogger(LoggerInterface $logger = null)
93+
{
9094
$this->logger = $logger;
9195
}
92-
96+
9397
/* Helper function to log data within the Client */
9498

95-
private function logMessage($message) {
99+
private function logMessage($message)
100+
{
96101
if ($this->logger) {
97102
$this->logger->debug($message);
98103
}
@@ -101,7 +106,7 @@ private function logMessage($message) {
101106
/* Setter function
102107
* Sets the value for the key if the key exists in ipnConfig
103108
*/
104-
109+
105110
public function __set($name, $value)
106111
{
107112
if (array_key_exists(strtolower($name), $this->ipnConfig)) {
@@ -114,7 +119,7 @@ public function __set($name, $value)
114119
/* Getter function
115120
* Returns the value for the key if the key exists in ipnConfig
116121
*/
117-
122+
118123
public function __get($name)
119124
{
120125
if (array_key_exists(strtolower($name), $this->ipnConfig)) {
@@ -125,16 +130,15 @@ public function __get($name)
125130
}
126131

127132
/* Trim the input Array key values */
128-
133+
129134
private function trimArray($array)
130135
{
131-
foreach ($array as $key => $value)
132-
{
133-
$array[$key] = trim($value);
134-
}
135-
return $array;
136+
foreach ($array as $key => $value) {
137+
$array[$key] = trim($value);
138+
}
139+
return $array;
136140
}
137-
141+
138142
private function validateHeaders()
139143
{
140144
// Quickly check that this is a sns message
@@ -165,7 +169,7 @@ private function getMessage()
165169
*
166170
* @return string error message
167171
*/
168-
172+
169173
private function getErrorMessageForJsonError($json_error)
170174
{
171175
switch ($json_error) {
@@ -263,10 +267,10 @@ private function validateUrl($url)
263267
*
264268
* @return bool true if valid
265269
*/
266-
270+
267271
private function constructAndVerifySignature()
268272
{
269-
$signature = base64_decode($this->getMandatoryField("Signature"));
273+
$signature = base64_decode($this->getMandatoryField("Signature"));
270274
$certificatePath = $this->getMandatoryField("SigningCertURL");
271275
$this->validateUrl($certificatePath);
272276
$this->certificate = $this->getCertificate($certificatePath);
@@ -281,12 +285,12 @@ private function constructAndVerifySignature()
281285
*
282286
* gets the certificate from the $certificatePath using Curl
283287
*/
284-
288+
285289
private function getCertificate($certificatePath)
286290
{
287-
$httpCurlRequest = new HttpCurl($this->ipnConfig);
291+
$httpCurlRequest = new HttpCurl($this->ipnConfig);
288292

289-
$response = $httpCurlRequest->httpGet($certificatePath);
293+
$response = $httpCurlRequest->httpGet($certificatePath);
290294

291295
return $response;
292296
}
@@ -302,12 +306,12 @@ public function verifySignatureIsCorrectFromCertificate($signature)
302306
{
303307
$certKey = openssl_get_publickey($this->certificate);
304308

305-
if ($certKey === False) {
309+
if ($certKey === false) {
306310
throw new \Exception("Unable to extract public key from cert");
307311
}
308312

309313
try {
310-
$certInfo = openssl_x509_parse($this->certificate, true);
314+
$certInfo = openssl_x509_parse($this->certificate, true);
311315
$certSubject = $certInfo["subject"];
312316

313317
if (is_null($certSubject)) {
@@ -340,7 +344,7 @@ public function verifySignatureIsCorrectFromCertificate($signature)
340344
*
341345
* @return string field contents if found
342346
*/
343-
347+
344348
private function getMandatoryField($fieldName)
345349
{
346350
$value = $this->getField($fieldName);
@@ -356,7 +360,7 @@ private function getMandatoryField($fieldName)
356360
*
357361
* @return string field contents if found, null otherwise
358362
*/
359-
363+
360364
private function getField($fieldName)
361365
{
362366
if (array_key_exists($fieldName, $this->snsMessage)) {
@@ -367,7 +371,7 @@ private function getField($fieldName)
367371
}
368372

369373
/* returnMessage() - JSON decode the raw [Message] portion of the IPN */
370-
374+
371375
public function returnMessage()
372376
{
373377
return json_decode($this->snsMessage['Message'], true);
@@ -383,14 +387,14 @@ public function returnMessage()
383387
* Topic ARN - Topic of the IPN
384388
* @return response in JSON format
385389
*/
386-
390+
387391
public function toJson()
388392
{
389393
$response = $this->simpleXmlObject();
390394

391395
// Merging the remaining fields with the response
392396
$remainingFields = $this->getRemainingIpnFields();
393-
$responseArray = array_merge($remainingFields,(array)$response);
397+
$responseArray = array_merge($remainingFields, (array)$response);
394398

395399
// Converting to JSON format
396400
$response = json_encode($responseArray);
@@ -401,7 +405,7 @@ public function toJson()
401405
/* toArray() - Converts IPN [Message] field to associative array
402406
* @return response in array format
403407
*/
404-
408+
405409
public function toArray()
406410
{
407411
$response = $this->simpleXmlObject();
@@ -412,7 +416,7 @@ public function toArray()
412416

413417
// Merging the remaining fields with the response array
414418
$remainingFields = $this->getRemainingIpnFields();
415-
$response = array_merge($remainingFields,$response);
419+
$response = array_merge($remainingFields, $response);
416420

417421
return $response;
418422
}
@@ -436,7 +440,7 @@ private function simpleXmlObject()
436440
$this->logMessage($this->sanitizeResponseData($ipnMessage['NotificationData']));
437441

438442
// Getting the Simple XML element object of the IPN XML Response Body
439-
$response = simplexml_load_string((string) $ipnMessage['NotificationData']);
443+
$response = simplexml_load_string((string)$ipnMessage['NotificationData']);
440444

441445
// Adding the Type, MessageId, TopicArn details of the IPN to the Simple XML element Object
442446
$response->addChild('Type', $this->snsMessage['Type']);
@@ -449,16 +453,17 @@ private function simpleXmlObject()
449453
/* getRemainingIpnFields()
450454
* Gets the remaining fields of the IPN to be later appended to the return message
451455
*/
452-
456+
453457
private function getRemainingIpnFields()
454458
{
455459
$ipnMessage = $this->returnMessage();
456460

457461
$remainingFields = array(
458-
'NotificationReferenceId' =>$ipnMessage['NotificationReferenceId'],
459-
'NotificationType' =>$ipnMessage['NotificationType'],
460-
'SellerId' =>$ipnMessage['SellerId'],
461-
'ReleaseEnvironment' =>$ipnMessage['ReleaseEnvironment'] );
462+
'NotificationReferenceId' => $ipnMessage['NotificationReferenceId'],
463+
'NotificationType' => $ipnMessage['NotificationType'],
464+
'SellerId' => $ipnMessage['SellerId'],
465+
'ReleaseEnvironment' => $ipnMessage['ReleaseEnvironment']
466+
);
462467

463468
return $remainingFields;
464469
}

AmazonPay/IpnHandlerInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
/* Interface for IpnHandler.php */
55

66
interface IpnHandlerInterface
7-
{
7+
{
88
/* returnMessage() - JSON decode the raw [Message] portion of the IPN */
9-
9+
1010
public function returnMessage();
1111

1212
/* toJson() - Converts IPN [Message] field to JSON
@@ -19,12 +19,12 @@ public function returnMessage();
1919
* Topic ARN - Topic of the IPN
2020
* @return response in JSON format
2121
*/
22-
22+
2323
public function toJson();
2424

2525
/* toArray() - Converts IPN [Message] field to associative array
2626
* @return response in array format
2727
*/
28-
28+
2929
public function toArray();
3030
}

0 commit comments

Comments
 (0)