99require_once 'HttpCurl.php ' ;
1010require_once 'IpnHandlerInterface.php ' ;
1111if (!interface_exists ('\Psr\Log\LoggerAwareInterface ' )) {
12- require_once (__DIR__ . '/../Psr/Log/LoggerAwareInterface.php ' );
12+ require_once (__DIR__ . '/../Psr/Log/LoggerAwareInterface.php ' );
1313}
1414if (!interface_exists ('\Psr\Log\LoggerInterface ' )) {
15- require_once (__DIR__ . '/../Psr/Log/LoggerInterface.php ' );
15+ require_once (__DIR__ . '/../Psr/Log/LoggerInterface.php ' );
1616}
17+
1718use Psr \Log \LoggerAwareInterface ;
1819use 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 }
0 commit comments