Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECP-9639] Refactor API clients, validator and handlers #2910

Draft
wants to merge 44 commits into
base: develop-10
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
752f83b
[ECP-9593] Implement an abstract handler for order status history
Mar 5, 2025
e505f01
[ECP-9593] Revert changes related to CAPTURE response handler
Mar 10, 2025
7b8d213
[ECP-9593] Implement comment builder for webhooks
Mar 10, 2025
848d53e
[ECP-9593] Refactor the renamed method
Mar 10, 2025
37dcfde
[ECP-9593] Improve order cancellation message and add optional reason
Mar 10, 2025
a078565
[ECP-9593] Add comment builder for webhooks
Mar 10, 2025
04d8501
[ECP-9593] Improve object handling on capture webhook handling proces…
Mar 10, 2025
e58a17c
[ECP-9593] Remove CheckoutPaymentCommentHistoryHandler class
Mar 10, 2025
b6543fb
[ECP-9639] Refactor CheckoutResponseValidator
Mar 11, 2025
93b252a
[ECP-9639] Add argument type declaration
Mar 11, 2025
c19260a
[ECP-9639] Use SubjectReader for response collection
Mar 11, 2025
13a9b32
[ECP-9639] Implement abstract response validator for modification req…
Mar 11, 2025
c793c2b
[ECP-9639] Move abstract class parameters to di.xml
Mar 11, 2025
3946811
[ECP-9639] Refactor Pay by Link request validator
Mar 11, 2025
26e32f9
[ECP-9639] Refactor InstallmentValidator class
Mar 11, 2025
0e36438
[ECP-9639] Remove hasOnlyGiftCards temporary handler
Mar 11, 2025
f681b9c
[ECP-9639] Refactor CheckoutPaymentsDetailsHandler
Mar 11, 2025
6128eb6
Merge remote-tracking branch 'origin/develop-10' into ECP-9593
Mar 11, 2025
7c9da9a
Merge remote-tracking branch 'origin/ECP-9593' into ECP-9639
Mar 11, 2025
e76ea26
[ECP-9639] Refactor PaymentLinks handlers and validators
Mar 11, 2025
ab390a2
[ECP-9639] Refactor DonateResponseValidator
Mar 11, 2025
93ffab8
[ECP-9639] Update payment method vaults response handler and remove r…
Mar 11, 2025
987c4f5
[ECP-9639] Remove redundant response handler
Mar 11, 2025
3c216a2
[ECP-9639] Rename the class only used by capture command pool
Mar 11, 2025
bd4f6a3
[ECP-9639] Move argument validator to the constructor
Mar 11, 2025
801a9cb
[ECP-9639] Refactor refunds response handler
Mar 11, 2025
e4e0f2f
[ECP-9639] Refactor cancels response handler
Mar 11, 2025
ae6762b
[ECP-9639] Rename the class
Mar 11, 2025
d48ab29
[ECP-9639] Refactor captures response handler
Mar 11, 2025
cc1dd9a
[ECP-9639] Update lastTransId logic
Mar 11, 2025
d464908
[ECP-9639] Add required field validator to modifications response val…
Mar 11, 2025
f797659
[ECP-9639] Formatting
Mar 11, 2025
ae34409
[ECP-9639] Merge VaultDetailsHandler into CheckoutPaymentsResponseHan…
Mar 11, 2025
2112a35
[ECP-9639] Refactor state data handler
Mar 11, 2025
08b6188
[ECP-9639] Use abstract order status history handler for captures
Mar 11, 2025
2dfae66
[ECP-9639] Update valid status constants
Mar 11, 2025
abe09cb
[ECP-9639] Remove hasOnlyGiftCards flag on payments chain
Mar 11, 2025
c4e1a55
[ECP-9639] Remove abstract keyword from the classes to use DI
Mar 11, 2025
61cf61a
[ECP-9639] Remove the comment
Mar 11, 2025
aa67447
[ECP-9639] Fix the class name
Mar 11, 2025
9e03866
[ECP-9639] Fix the response type
Mar 11, 2025
7e72072
[ECP-9639] Refactor Cancel command chain
Mar 12, 2025
f81059b
[ECP-9639] Introduce a constant for the string
Mar 12, 2025
97edd2a
[ECP-9639] Refactor capture command chain
Mar 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[ECP-9593] Implement an abstract handler for order status history
Can Demiralp committed Mar 5, 2025
commit 752f83b842b985d7d371ecf7565a7665fd99a40b
55 changes: 55 additions & 0 deletions Gateway/Response/AbstractOrderStatusHistoryHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Gateway\Response;

use Adyen\AdyenException;
use Adyen\Payment\Helper\OrderStatusHistory;
use Magento\Payment\Gateway\Helper\SubjectReader;
use Magento\Payment\Gateway\Response\HandlerInterface;

class AbstractOrderStatusHistoryHandler implements HandlerInterface
{
/**
* @param string $eventType Indicates the API call event type (authorization, capture etc.)
* @param OrderStatusHistory $orderStatusHistoryHelper
*/
public function __construct(
protected readonly string $eventType,
protected readonly OrderStatusHistory $orderStatusHistoryHelper
) { }

/**
* @throws AdyenException
*/
public function handle(array $handlingSubject, array $responseCollection): void
{
if (empty($this->eventType)) {
throw new AdyenException(
__('Order status history can not be handled due to missing event type!')
);
}

$readPayment = SubjectReader::readPayment($handlingSubject);
$payment = $readPayment->getPayment();
$order = $payment->getOrder();

// Temporary workaround to clean-up `hasOnlyGiftCards` key. It needs to be handled separately.
if (isset($responseCollection['hasOnlyGiftCards'])) {
unset($responseCollection['hasOnlyGiftCards']);
}

foreach ($responseCollection as $response) {
$comment = $this->orderStatusHistoryHelper->buildComment($response, $this->eventType);
$order->addCommentToStatusHistory($comment, $order->getStatus());
}
}
}
37 changes: 37 additions & 0 deletions Helper/OrderStatusHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/

namespace Adyen\Payment\Helper;

class OrderStatusHistory
{
public function buildComment(array $response, string $actionName): String
{
$comment = __("Adyen %1 API response:", $actionName) . '<br />';

if (isset($response['resultCode'])) {
$comment .= __("Result Code: %1", $response['resultCode']) . '<br />';
}

// Modification responses contain `status` but not `resultCode`.
if (isset($response['status'])) {
$comment .= __("Status: %1", $response['status']) . '<br />';
}

if (isset($response['pspReference'])) {
$comment .= __("PSP reference: %1", $response['pspReference']);
}

$comment .= '<br />';

return $comment;
}
}
28 changes: 24 additions & 4 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -1334,11 +1334,31 @@
<argument name="handlers" xsi:type="array">
<item name="payment_details" xsi:type="string">Adyen\Payment\Gateway\Response\CheckoutPaymentsDetailsHandler</item>
<item name="vault_details" xsi:type="string">Adyen\Payment\Gateway\Response\VaultDetailsHandler</item>
<item name="payment_comments" xsi:type="string">Adyen\Payment\Gateway\Response\CheckoutPaymentCommentHistoryHandler</item>
<item name="order_status_history" xsi:type="string">AdyenPaymentAuthorisationOrderStatusHistoryHandler</item>
<item name="state_data" xsi:type="string">Adyen\Payment\Gateway\Response\StateDataHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentAuthorisationOrderStatusHistoryHandler" type="Adyen\Payment\Gateway\Response\AbstractOrderStatusHistoryHandler">
<arguments>
<argument name="eventType" xsi:type="string">authorisation</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentCaptureOrderStatusHistoryHandler" type="Adyen\Payment\Gateway\Response\AbstractOrderStatusHistoryHandler">
<arguments>
<argument name="eventType" xsi:type="string">capture</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentRefundOrderStatusHistoryHandler" type="Adyen\Payment\Gateway\Response\AbstractOrderStatusHistoryHandler">
<arguments>
<argument name="eventType" xsi:type="string">refund</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentCancellationOrderStatusHistoryHandler" type="Adyen\Payment\Gateway\Response\AbstractOrderStatusHistoryHandler">
<arguments>
<argument name="eventType" xsi:type="string">cancellation</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentBoletoResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
@@ -1359,23 +1379,23 @@
<arguments>
<argument name="handlers" xsi:type="array">
<item name="capture" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentCaptureDetailsHandler</item>
<item name="payment_comments" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentCommentHistoryHandler</item>
<item name="order_comment_history" xsi:type="string">AdyenPaymentCaptureOrderStatusHistoryHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentRefundResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="capture" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentRefundDetailsHandler</item>
<item name="payment_comments" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentCommentHistoryRefundHandler</item>
<item name="order_comment_history" xsi:type="string">AdyenPaymentRefundOrderStatusHistoryHandler</item>
</argument>
</arguments>
</virtualType>
<virtualType name="AdyenPaymentCancelResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="cancel" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentCancelDetailsHandler</item>
<item name="payment_comments" xsi:type="string">Adyen\Payment\Gateway\Response\PaymentCommentHistoryHandler</item>
<item name="order_comment_history" xsi:type="string">AdyenPaymentCancellationOrderStatusHistoryHandler</item>
</argument>
</arguments>
</virtualType>