Skip to content

[ECP-9950] Fix CHARGEBACK webhooks failing to create credit memo#3304

Merged
shubhamk67 merged 1 commit into
mainfrom
ECP-9950
May 12, 2026
Merged

[ECP-9950] Fix CHARGEBACK webhooks failing to create credit memo#3304
shubhamk67 merged 1 commit into
mainfrom
ECP-9950

Conversation

@shubhamk67
Copy link
Copy Markdown
Contributor

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

Fixes #3296

@shubhamk67 shubhamk67 requested a review from a team as a code owner May 8, 2026 16:13
@shubhamk67 shubhamk67 added the Fix Indicates a bug fix label May 8, 2026
@shubhamk67 shubhamk67 changed the title Fix CHARGEBACK webhooks failing to create credit memo [ECP-9950] Fix CHARGEBACK webhooks failing to create credit memo May 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider defining the allowed event codes as a class constant instead of a local variable within the method. This improves maintainability and makes the list of supported events more explicit and potentially reusable.

EventCodes::CHARGEBACK_REVERSED
];

if (!in_array($notification->getEventCode(), $allowedEventCodes)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The associated error message (currently on lines 117-118) should be updated to reflect that chargeback-related event codes are now also supported. It currently explicitly mentions only REFUND or CANCEL_OR_REFUND, which is misleading for the newly added event types.

Comment on lines +207 to +212
[
'eventCode' => 'CHARGEBACK',
'isExpectedType' => true,
'creditmemoId' => "",
'isResultValid' => false
],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
            ],

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

@shubhamk67 shubhamk67 merged commit f232304 into main May 12, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Indicates a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Adyen Chargeback fails to create creditmemo

3 participants