Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 4 additions & 8 deletions Helper/Webhook/AuthorisationWebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use Adyen\Payment\Helper\AdyenOrderPayment;
use Adyen\Payment\Helper\CaseManagement;
use Adyen\Payment\Helper\ChargedCurrency;
use Adyen\Payment\Helper\Config;
use Adyen\Payment\Helper\Invoice;
use Adyen\Payment\Helper\Order as OrderHelper;
Expand All @@ -36,7 +35,6 @@ class AuthorisationWebhookHandler implements WebhookHandlerInterface
* @param CaseManagement $caseManagementHelper
* @param SerializerInterface $serializer
* @param AdyenLogger $adyenLogger
* @param ChargedCurrency $chargedCurrency
* @param Config $configHelper
* @param Invoice $invoiceHelper
* @param PaymentMethods $paymentMethodsHelper
Expand All @@ -48,7 +46,6 @@ public function __construct(
private readonly CaseManagement $caseManagementHelper,
private readonly SerializerInterface $serializer,
private readonly AdyenLogger $adyenLogger,
private readonly ChargedCurrency $chargedCurrency,
private readonly Config $configHelper,
private readonly Invoice $invoiceHelper,
private readonly PaymentMethods $paymentMethodsHelper,
Expand Down Expand Up @@ -109,15 +106,14 @@ private function handleSuccessfulAuthorisation(Order $order, Notification $notif
if ($notification->getPaymentMethod() != "adyen_boleto" && !$order->getEmailSent()) {
$this->orderHelper->sendOrderMail($order);
}

// Set authorized amount in sales_order_payment
$order->getPayment()->setAmountAuthorized($order->getGrandTotal());
$order->getPayment()->setBaseAmountAuthorized($order->getBaseGrandTotal());
} else {
$this->orderHelper->addWebhookStatusHistoryComment($order, $notification);
}

// Set authorized amount in sales_order_payment
$orderAmountCurrency = $this->chargedCurrency->getOrderAmountCurrency($order, false);
$orderAmount = $orderAmountCurrency->getAmount();
$order->getPayment()->setAmountAuthorized($orderAmount);

if ($notification->getPaymentMethod() == "c_cash" &&
$this->configHelper->getConfigData('create_shipment', 'adyen_cash', $order->getStoreId())
) {
Expand Down
26 changes: 2 additions & 24 deletions Test/Unit/Helper/Webhook/AuthorisationWebhookHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class AuthorisationWebhookHandlerTest extends AbstractAdyenTestCase
protected function setUp(): void
{
parent::setUp();

$this->orderMock = $this->createOrder();
$this->adyenOrderPaymentMock = $this->createMock(AdyenOrderPayment::class);
$this->orderAmountCurrency = $this->createMock(AdyenAmountCurrency::class);
$this->chargedCurrencyMock = $this->createMock(ChargedCurrency::class);
$this->notificationMock = $this->createMock(Notification::class);
$this->orderMock = $this->createMock(Order::class);
$this->orderHelperMock = $this->createMock(OrderHelper::class);
Expand Down Expand Up @@ -66,13 +66,6 @@ protected function setUp(): void
public function testHandleWebhook(): void
{
// Set up expectations for mock objects
$orderAmountCurrency = new AdyenAmountCurrency(
10.33,
'EUR',
null,
null,
10.33
);
$storeId = 1;
$paymentMock = $this->createConfiguredMock(Order\Payment::class, [
'getMethod' => 'adyen_cc'
Expand All @@ -87,9 +80,7 @@ public function testHandleWebhook(): void
$paymentMethodsHelperMock = $this->createConfiguredMock(PaymentMethods::class, [
'isAutoCapture' => true
]);
$mockChargedCurrency = $this->createConfiguredMock(ChargedCurrency::class, [
'getOrderAmountCurrency' => $orderAmountCurrency
]);


$transitionState = PaymentStates::STATE_PAID;

Expand All @@ -102,7 +93,6 @@ public function testHandleWebhook(): void
null,
null,
null,
$mockChargedCurrency,
null,
null,
$paymentMethodsHelperMock,
Expand Down Expand Up @@ -142,10 +132,6 @@ public function testHandleSuccessfulAuthorisation($isAutoCapture): void
$orderAmount
);

$mockChargedCurrency = $this->createConfiguredMock(ChargedCurrency::class, [
'getOrderAmountCurrency' => $this->orderAmountCurrency
]);

// Create mock instances for Order and Notification
$paymentMock = $this->createMock(Order::class);
$storeId = 1;
Expand Down Expand Up @@ -177,7 +163,6 @@ public function testHandleSuccessfulAuthorisation($isAutoCapture): void
null,
null,
null,
$mockChargedCurrency,
null,
null,
$paymentMethodsMock,
Expand Down Expand Up @@ -291,7 +276,6 @@ public function testDisableQuote()
null,
null,
null,
null,
$cartRepositoryMock
);

Expand Down Expand Up @@ -397,7 +381,6 @@ protected function createAuthorisationWebhookHandler(
$mockCaseManagementHelper = null,
$mockSerializer = null,
$mockAdyenLogger = null,
$mockChargedCurrency = null,
$mockConfigHelper = null,
$mockInvoiceHelper = null,
$mockPaymentMethodsHelper = null,
Expand All @@ -423,10 +406,6 @@ protected function createAuthorisationWebhookHandler(
$mockAdyenLogger = $this->createMock(AdyenLogger::class);
}

if (is_null($mockChargedCurrency)) {
$mockChargedCurrency = $this->createMock(ChargedCurrency::class);
}

if (is_null($mockConfigHelper)) {
$mockConfigHelper = $this->createMock(Config::class);
}
Expand All @@ -449,7 +428,6 @@ protected function createAuthorisationWebhookHandler(
$mockCaseManagementHelper,
$mockSerializer,
$mockAdyenLogger,
$mockChargedCurrency,
$mockConfigHelper,
$mockInvoiceHelper,
$mockPaymentMethodsHelper,
Expand Down
Loading