2424class Notification {
2525
2626 /**
27- * @var Order ID
27+ * @var string Order ID
2828 */
2929 public $ id ;
3030 /**
31- * @var Order Status
31+ * @var string Status of Order
3232 */
3333 public $ status ;
34+ /**
35+ * @var string Description of Decision
36+ */
37+ public $ description ;
3438
3539 protected $ signature ;
3640 protected $ headers ;
@@ -41,7 +45,7 @@ class Notification {
4145 * Inits and validates the request.
4246 * @param $signature Signature An instance of a Signature class that handles authentication
4347 * @param $headers array A list of HTTP Headers as strings
44- * @param $body string The body of the Request
48+ * @param $body string The raw body of the Request
4549 * @throws NotificationException on issues with the request
4650 */
4751 public function __construct ($ signature , $ headers , $ body ) {
@@ -50,7 +54,7 @@ public function __construct($signature, $headers, $body) {
5054 $ this ->body = $ body ;
5155
5256 $ this ->parse_headers ();
53- $ this ->parse_body ($ body );
57+ $ this ->parse_body ();
5458 $ this ->test_authorization ();
5559 }
5660
@@ -64,7 +68,8 @@ protected function parse_headers() {
6468 list ($ key , $ value ) = explode (': ' , $ header );
6569 if (!$ key || !$ value )
6670 throw new Exception \BadHeaderException ($ this ->headers , $ this ->body , $ header );
67- $ this ->headers_map [trim ($ key )] = trim ($ value );
71+ $ header = str_replace ('- ' , '_ ' , strtoupper (trim ($ key )));
72+ $ this ->headers_map [$ header ] = trim ($ value );
6873 }
6974 }
7075
@@ -75,7 +80,7 @@ protected function parse_headers() {
7580 protected function test_authorization () {
7681 $ signature = $ this ->signature ;
7782 $ remote_hmac = $ this ->headers_map [$ signature ::HMAC_HEADER_NAME ];
78- $ local_hmac = $ signature ->calc_hmac ($ this ->data_string () );
83+ $ local_hmac = $ signature ->calc_hmac ($ this ->body );
7984 if ($ remote_hmac != $ local_hmac )
8085 throw new Exception \AuthorizationException ($ this ->headers , $ this ->body , $ local_hmac , $ remote_hmac );
8186 }
@@ -90,14 +95,7 @@ protected function parse_body() {
9095 if (!$ vars ['id ' ] || !$ vars ['status ' ])
9196 throw new Exception \BadPostParametersException ($ this ->headers , $ this ->body );
9297
93- $ this ->id = $ vars ['id ' ];
94- $ this ->status = $ vars ['status ' ];
95- }
96-
97- /**
98- * @return string sorted param string for hashing
99- */
100- protected function data_string () {
101- return "id= $ this ->id &status= $ this ->status " ;
98+ foreach ($ vars as $ key => $ value )
99+ $ this ->$ key = $ value ;
102100 }
103101}
0 commit comments