[ECP-9950] Fix CHARGEBACK webhooks failing to create credit memo#3304
Conversation
There was a problem hiding this comment.
Code Review
This pull request expands the getByRefundWebhook method in AdyenCreditmemoRepository to support chargeback-related event codes and adds corresponding unit tests. Feedback includes moving the allowed event codes to a class constant for better maintainability, updating the exception message to reflect the newly supported event types, and adding positive test cases to verify successful credit memo retrieval for chargeback events.
| public function getByRefundWebhook(NotificationInterface $notification): ?CreditmemoInterface | ||
| { | ||
| if (!in_array($notification->getEventCode(), [EventCodes::REFUND, EventCodes::CANCEL_OR_REFUND])) { | ||
| $allowedEventCodes = [ |
| EventCodes::CHARGEBACK_REVERSED | ||
| ]; | ||
|
|
||
| if (!in_array($notification->getEventCode(), $allowedEventCodes)) { |
There was a problem hiding this comment.
| [ | ||
| 'eventCode' => 'CHARGEBACK', | ||
| 'isExpectedType' => true, | ||
| 'creditmemoId' => "", | ||
| 'isResultValid' => false | ||
| ], |
There was a problem hiding this comment.
The new test cases only verify the scenario where no credit memo is found (returning null). It is recommended to add at least one positive test case for a chargeback event code to ensure that the repository correctly returns the CreditmemoInterface when a matching record exists in the database.
[
'eventCode' => 'CHARGEBACK',
'isExpectedType' => true,
'creditmemoId' => "",
'isResultValid' => false
],
[
'eventCode' => 'CHARGEBACK',
'isExpectedType' => true,
'creditmemoId' => "1",
'isResultValid' => true
],
|



Description
This PR updates the AdyenCreditmemoRepository to support chargeback-related webhook event codes, ensuring credit memos are successfully created for chargebacks.
Fixes #3296