File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,8 @@ private function getNotificationDataToSign($params)
66
66
$ originalReference = (!empty ($ params ['originalReference ' ])) ? $ params ['originalReference ' ] : "" ;
67
67
$ merchantAccountCode = (!empty ($ params ['merchantAccountCode ' ])) ? $ params ['merchantAccountCode ' ] : "" ;
68
68
$ merchantReference = (!empty ($ params ['merchantReference ' ])) ? $ params ['merchantReference ' ] : "" ;
69
- $ value = (!empty ($ params ['amount ' ]['value ' ])) ? $ params ['amount ' ]['value ' ] : "" ;
69
+ // `empty` treats too many value types as empty. `isset` should prevent some of these cases.
70
+ $ value = (isset ($ params ['amount ' ]['value ' ])) ? $ params ['amount ' ]['value ' ] : "" ;
70
71
$ currency = (!empty ($ params ['amount ' ]['currency ' ])) ? $ params ['amount ' ]['currency ' ] : "" ;
71
72
$ eventCode = (!empty ($ params ['eventCode ' ])) ? $ params ['eventCode ' ] : "" ;
72
73
$ success = (!empty ($ params ['success ' ])) ? $ params ['success ' ] : "" ;
Original file line number Diff line number Diff line change @@ -56,4 +56,32 @@ public function testNotificationRequestItemHmac()
56
56
$ this ->fail ('Unexpected exception ' );
57
57
}
58
58
}
59
+ public function testHmacSignatureForRefundWithZeroValue ()
60
+ {
61
+ $ params = json_decode ('{
62
+ "pspReference": "7914073381342284",
63
+ "merchantAccountCode": "TestMerchant",
64
+ "merchantReference": "TestPayment-1407325143704",
65
+ "amount": {
66
+ "value": 0,
67
+ "currency": "EUR"
68
+ },
69
+ "eventCode": "REFUND",
70
+ "success": "true"
71
+ } ' , true );
72
+ $ key = "44782DEF547AAA06C910C43932B1EB0C71FC68D9D0C057550C48EC2ACF6BA056 " ;
73
+ $ hmac = new HmacSignature ();
74
+ try {
75
+ $ hmacCalculation = $ hmac ->calculateNotificationHMAC ($ key , $ params );
76
+ $ this ->assertNotEmpty ($ hmacCalculation );
77
+ $ this ->assertEquals ("J7HhsgZo5KwqdB7LFZJV6rfQgp+RqC2kuYyw/3x3w+8= " , $ hmacCalculation );
78
+ $ params ['additionalData ' ] = array (
79
+ 'hmacSignature ' => $ hmacCalculation
80
+ );
81
+ $ hmacValidate = $ hmac ->isValidNotificationHMAC ($ key , $ params );
82
+ $ this ->assertTrue ($ hmacValidate );
83
+ } catch (AdyenException $ e ) {
84
+ $ this ->fail ('Unexpected exception ' );
85
+ }
86
+ }
59
87
}
You can’t perform that action at this time.
0 commit comments