Skip to content

Commit

Permalink
PAYOSWXP-105: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Feb 5, 2024
1 parent 0a003c5 commit daea519
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 30 deletions.
13 changes: 7 additions & 6 deletions src/PaymentHandler/AbstractAsynchronousPayonePaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ public function pay(
$salesChannelContext
);

$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
$response,
$salesChannelContext->getContext()
);

if ($this->deviceFingerprintService instanceof AbstractDeviceFingerprintService) {
$this->deviceFingerprintService->deleteDeviceIdentToken();
}
Expand Down Expand Up @@ -147,12 +154,6 @@ protected function handleResponse(
);

$this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data);
$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
$response,
$salesChannelContext->getContext()
);
}

protected function getRedirectResponse(array $request, array $response): RedirectResponse
Expand Down
13 changes: 7 additions & 6 deletions src/PaymentHandler/AbstractSynchronousPayonePaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public function pay(
$salesChannelContext
);

$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
$response,
$salesChannelContext->getContext()
);

if ($this->deviceFingerprintService instanceof AbstractDeviceFingerprintService) {
$this->deviceFingerprintService->deleteDeviceIdentToken();
}
Expand Down Expand Up @@ -133,11 +140,5 @@ protected function handleResponse(
);

$this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data);
$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
$response,
$salesChannelContext->getContext()
);
}
}
1 change: 1 addition & 0 deletions src/PaymentHandler/PayoneApplePayPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function pay(

$data = $this->preparePayoneOrderTransactionData($request, $response);
$this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data);
// special case: the request has been already processed before the payment handler has been executed. Now we will log the previous request/response
$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
Expand Down
6 changes: 0 additions & 6 deletions src/PaymentHandler/PayoneCreditCardPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ protected function handleResponse(
],
]);
$this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data);
$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
$response,
$salesChannelContext->getContext()
);

if ($paymentTransaction->getOrder()->getLineItems() !== null) {
$this->setLineItemCustomFields($paymentTransaction->getOrder()->getLineItems(), $salesChannelContext->getContext());
Expand Down
6 changes: 0 additions & 6 deletions src/PaymentHandler/PayonePaypalExpressPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ protected function handleResponse(
]);

$this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data);
$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
$response,
$salesChannelContext->getContext()
);
}

protected function getRedirectResponse(array $request, array $response): RedirectResponse
Expand Down
6 changes: 0 additions & 6 deletions src/PaymentHandler/PayonePaypalPaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ protected function handleResponse(

$data = $this->preparePayoneOrderTransactionData($request, $response);
$this->transactionDataHandler->saveTransactionData($paymentTransaction, $salesChannelContext->getContext(), $data);
$this->orderActionLogDataHandler->createOrderActionLog(
$transaction->getOrder(),
$request,
$response,
$salesChannelContext->getContext()
);
}

protected function getRedirectResponse(array $request, array $response): RedirectResponse
Expand Down
76 changes: 76 additions & 0 deletions tests/PaymentHandler/PayoneApplePayPaymentHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace PayonePayment\PaymentHandler;

use PayonePayment\Components\Currency\CurrencyPrecision;
use PayonePayment\Components\DataHandler\OrderActionLog\OrderActionLogDataHandlerInterface;
use PayonePayment\Components\DataHandler\Transaction\TransactionDataHandler;
use PayonePayment\Payone\Client\PayoneClient;
use PayonePayment\Payone\RequestParameter\RequestParameterFactory;
use PayonePayment\TestCaseBase\Mock\ConfigReaderMock;
use PayonePayment\TestCaseBase\PayoneTestBehavior;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Checkout\Payment\Cart\SyncPaymentTransactionStruct;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;

/**
* @covers \PayonePayment\PaymentHandler\PayoneApplePayPaymentHandler
*/
class PayoneApplePayPaymentHandlerTest extends TestCase
{
use PayoneTestBehavior;

public function testIfCreateOrderActionLogGotCalled(): void
{
$salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

$requestDataBag = new RequestDataBag(['response' => json_encode([
'status' => 'APPROVED',
'txid' => '123456789',
'userid' => '987654321',
])]);

/** @var PayoneApplePayPaymentHandler $paymentHandler */
$paymentHandler = $this->getPaymentHandler($requestDataBag);

$paymentTransaction = $this->getPaymentTransaction(
$this->getRandomOrder($salesChannelContext),
PayoneApplePayPaymentHandler::class
);

$paymentHandler->pay(
new SyncPaymentTransactionStruct(
$paymentTransaction->getOrderTransaction(),
$paymentTransaction->getOrder()
),
$requestDataBag,
$salesChannelContext
);

// info: assertion if the `createOrderActionLog` is called, is in the `getPaymentHandler`.
}

private function getPaymentHandler(RequestDataBag $dataBag): PayoneApplePayPaymentHandler
{
$configReader = new ConfigReaderMock([
'applePayAuthorizationMethod' => 'authorization',
]);

$orderActionLogDataHandler = $this->createMock(OrderActionLogDataHandlerInterface::class);
$orderActionLogDataHandler->expects(static::once())->method('createOrderActionLog');

return new PayoneApplePayPaymentHandler(
$configReader,
$this->createMock(EntityRepository::class),
$this->getRequestStack($dataBag),
$this->createMock(PayoneClient::class),
$this->getContainer()->get('translator'),
new TransactionDataHandler($this->createMock(EntityRepository::class), new CurrencyPrecision()),
$orderActionLogDataHandler,
$this->createMock(RequestParameterFactory::class)
);
}
}

0 comments on commit daea519

Please sign in to comment.