diff --git a/Test/Unit/Gateway/Http/Client/TransactionPaymentTest.php b/Test/Unit/Gateway/Http/Client/TransactionPaymentTest.php index 2e5ff6526..c61cd35c2 100644 --- a/Test/Unit/Gateway/Http/Client/TransactionPaymentTest.php +++ b/Test/Unit/Gateway/Http/Client/TransactionPaymentTest.php @@ -6,7 +6,6 @@ use Adyen\Payment\Model\PaymentResponse; use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; use Adyen\Service\Checkout; -use PHPUnit\Framework\TestCase; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Adyen\Payment\Helper\Data; use Adyen\Payment\Model\PaymentResponseFactory; diff --git a/Test/Unit/Helper/PaymentDetailsTest.php b/Test/Unit/Helper/PaymentDetailsTest.php new file mode 100644 index 000000000..303c37874 --- /dev/null +++ b/Test/Unit/Helper/PaymentDetailsTest.php @@ -0,0 +1,99 @@ + + */ + +use Adyen\Payment\Helper\PaymentsDetails; +use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; +use Magento\Sales\Api\Data\OrderInterface; +use Magento\Sales\Model\Order\Payment; +use Adyen\Payment\Helper\Data; +use Adyen\Payment\Logger\AdyenLogger; +use Adyen\Payment\Helper\PaymentResponseHandler; +use Adyen\Payment\Helper\Idempotency; +use Adyen\AdyenException; +use Magento\Checkout\Model\Session; +use Magento\Framework\Exception\ValidatorException; +use Adyen\Service\Checkout; +use Adyen\Client; + +class PaymentDetailsTest extends AbstractAdyenTestCase +{ + private $checkoutSessionMock; + private $adyenHelperMock; + private $adyenLoggerMock; + private $paymentResponseHandlerMock; + private $idempotencyHelperMock; + private $paymentDetails; + + protected function setUp(): void + { + $this->checkoutSessionMock = $this->createMock(Session::class); + $this->adyenHelperMock = $this->createMock(Data::class); + $this->adyenLoggerMock = $this->createMock(AdyenLogger::class); + $this->paymentResponseHandlerMock = $this->createMock(PaymentResponseHandler::class); + $this->idempotencyHelperMock = $this->createMock(Idempotency::class); + + $this->paymentDetails = new PaymentsDetails( + $this->checkoutSessionMock, + $this->adyenHelperMock, + $this->adyenLoggerMock, + $this->paymentResponseHandlerMock, + $this->idempotencyHelperMock + ); + } + + public function testRequestHeadersAreAddedToRequest() + { + $orderMock = $this->createMock(OrderInterface::class); + $paymentMock = $this->createMock(Payment::class); + $checkoutServiceMock = $this->createMock(Checkout::class); + $adyenClientMock = $this->createMock(Client::class); + $storeId = 1; + $payload = json_encode([ + 'details' => 'some_details', + 'paymentData' => 'some_payment_data', + 'threeDSAuthenticationOnly' => true + ]); + $requestOptions = [ + 'idempotencyKey' => 'some_idempotency_key', + 'headers' => ['headerKey' => 'headerValue'] + ]; + $paymentDetailsResult = ['resultCode' => 'Authorised', 'action' => null, 'additionalData' => null]; + + $orderMock->method('getPayment')->willReturn($paymentMock); + $orderMock->method('getStoreId')->willReturn($storeId); + $paymentMock->method('getOrder')->willReturn($orderMock); + + $this->adyenHelperMock->method('initializeAdyenClient')->willReturn($adyenClientMock); + $this->adyenHelperMock->method('createAdyenCheckoutService')->willReturn($checkoutServiceMock); + $this->adyenHelperMock->method('buildRequestHeaders')->willReturn($requestOptions['headers']); + $this->idempotencyHelperMock->method('generateIdempotencyKey')->willReturn($requestOptions['idempotencyKey']); + + $checkoutServiceMock->expects($this->once()) + ->method('paymentsDetails') + ->with( + $this->equalTo([ + 'details' => 'some_details', + 'paymentData' => 'some_payment_data', + 'threeDSAuthenticationOnly' => true + ]), + $this->equalTo($requestOptions) + ) + ->willReturn($paymentDetailsResult); + + $this->paymentResponseHandlerMock->method('handlePaymentResponse')->willReturn(true); + $this->paymentResponseHandlerMock->method('formatPaymentResponse')->willReturn($paymentDetailsResult); + + $result = $this->paymentDetails->initiatePaymentDetails($orderMock, $payload); + + $this->assertJson($result); + $this->assertEquals(json_encode($paymentDetailsResult), $result); + } +}