@@ -73,6 +73,16 @@ private function hasEventWithAnyKey(array $eventWrappers, array $keys): bool
7373 return false ;
7474 }
7575
76+ private function constructWebhookEvent (array $ payload , string $ secret = 'whsec_test_secret ' ): \Stripe \Event
77+ {
78+ $ payloadJson = json_encode ($ payload );
79+ $ timestamp = time ();
80+ $ signedPayload = $ timestamp . '. ' . $ payloadJson ;
81+ $ signature = hash_hmac ('sha256 ' , $ signedPayload , $ secret );
82+ $ sigHeader = "t= {$ timestamp },v1= {$ signature }" ;
83+ return \Stripe \Webhook::constructEvent ($ payloadJson , $ sigHeader , $ secret );
84+ }
85+
7686 protected function ddTearDown ()
7787 {
7888 parent ::ddTearDown ();
@@ -97,7 +107,7 @@ public function testPaymentSuccessWebhook()
97107 ]
98108 ];
99109
100- \ Stripe \Event:: constructFrom ($ payload );
110+ $ this -> constructWebhookEvent ($ payload );
101111
102112 $ allEvents = AppsecStatus::getInstance ()->getEvents (['push_addresses ' ], []);
103113
@@ -143,7 +153,7 @@ public function testPaymentFailureWebhook()
143153 ]
144154 ];
145155
146- \ Stripe \Event:: constructFrom ($ payload );
156+ $ this -> constructWebhookEvent ($ payload );
147157
148158 $ allEvents = AppsecStatus::getInstance ()->getEvents (['push_addresses ' ], []);
149159
@@ -186,7 +196,7 @@ public function testPaymentCancellationWebhook()
186196 ]
187197 ];
188198
189- \ Stripe \Event:: constructFrom ($ payload );
199+ $ this -> constructWebhookEvent ($ payload );
190200
191201 $ allEvents = AppsecStatus::getInstance ()->getEvents (['push_addresses ' ], []);
192202
@@ -222,7 +232,7 @@ public function testWebhookInvalidOrUnsupportedEvents()
222232 ]
223233 ];
224234
225- \ Stripe \Event:: constructFrom ($ payload );
235+ $ this -> constructWebhookEvent ($ payload );
226236
227237 $ allEvents = AppsecStatus::getInstance ()->getEvents (['push_addresses ' ], []);
228238
@@ -257,14 +267,7 @@ public function testPaymentSuccessWebhookViaConstructEvent()
257267 ]
258268 ]
259269 ];
260- $ payloadJson = json_encode ($ payload );
261- $ secret = 'whsec_test_secret ' ;
262- $ timestamp = time ();
263- $ signedPayload = $ timestamp . '. ' . $ payloadJson ;
264- $ signature = hash_hmac ('sha256 ' , $ signedPayload , $ secret );
265- $ sigHeader = "t= {$ timestamp },v1= {$ signature }" ;
266-
267- $ event = \Stripe \Webhook::constructEvent ($ payloadJson , $ sigHeader , $ secret );
270+ $ event = $ this ->constructWebhookEvent ($ payload );
268271
269272 $ this ->assertSame ('payment_intent.succeeded ' , $ event ->type );
270273
@@ -583,7 +586,7 @@ public function __construct(string $responseBody, int $responseCode = 200)
583586 $ this ->responseCode = $ responseCode ;
584587 }
585588
586- public function request ($ method , $ absUrl , $ headers , $ params , $ hasFile )
589+ public function request ($ method , $ absUrl , $ headers , $ params , $ hasFile, $ apiMode = null , $ maxNetworkRetries = null )
587590 {
588591 return [$ this ->responseBody , $ this ->responseCode , []];
589592 }
0 commit comments