-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECP-9482] Refactor Header Data Builder For Transaction Clients (#2819)
* [ECP-9482-1] Added HeaderDataBuilderInterface, moved header builder to separate directory, updated constants in the observers, updated frontend type values to `luma`, added HeaderDataBuilder in the authorization flow for cancel, capture, refund, donate, payByLink, and pos transaction clients in di.xml * [ECP-9482-1] Removed HeaderDataBuilder from pos transaction client, updated the headers in all transaction clients * [ECP-9482-1] Updated Tests * [ECP-9482-1] Updated constants in data helper * [ECP-9482-1] Updated header in refund request options * [ECP-9482-1] Updated header in capture request options, revert donation header updates * [ECP-9482-1] Updated format * [ECP-9482-1] Remove capture test update * [ECP-9482-1] Update DataTest for new frontend type constant * [ECP-9482-1] Update Constants use in Data, remove unused constant for `headless` from HeaderDataBuilderInterface * [ECP-9482-1] Set frontendType in JS renderers to be `default` * [ECP-9482-1] Set placeorder method * [ECP-9482-1] Remove unused variable * [ECP-9482-1] fix formatting issue * [ECP-9482-1] reverse the frontend type change for giftcard * [ECP-9482-1] Added unit test for TransactionPaymentLinks * [ECP-9482-1] Added unit test for initializePaymentLinksApi in DataTest * [ECP-9482-1] Optimized TrasactionPaymentLinks test * [ECP-9482-1] Remove unused classes --------- Co-authored-by: sushmita <sushmita.thakur@adyen.com>
- Loading branch information
1 parent
6316bb3
commit 3ab803c
Showing
17 changed files
with
207 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Adyen\Payment\Gateway\Request\Header; | ||
|
||
interface HeaderDataBuilderInterface | ||
{ | ||
const EXTERNAL_PLATFORM_NAME = 'external-platform-name'; | ||
const EXTERNAL_PLATFORM_VERSION = 'external-platform-version'; | ||
const EXTERNAL_PLATFORM_EDITION = 'external-platform-edition'; | ||
const EXTERNAL_PLATFORM_FRONTEND_TYPE = 'external-platform-frontendtype'; | ||
const MERCHANT_APPLICATION_NAME = 'merchant-application-name'; | ||
const MERCHANT_APPLICATION_VERSION = 'merchant-application-version'; | ||
|
||
const ADDITIONAL_DATA_FRONTEND_TYPE_KEY = 'frontendType'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
Test/Unit/Gateway/Http/Client/TransactionPaymentLinksTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace Adyen\Payment\Test\Unit\Gateway\Http\Client; | ||
|
||
use Adyen\AdyenException; | ||
use Adyen\Model\Checkout\ApplicationInfo; | ||
use Adyen\Model\Checkout\PaymentLinkRequest; | ||
use Adyen\Model\Checkout\PaymentLinkResponse; | ||
use Adyen\Payment\Gateway\Http\Client\TransactionPaymentLinks; | ||
use Adyen\Payment\Helper\Data; | ||
use Adyen\Payment\Helper\Idempotency; | ||
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; | ||
use Adyen\Client; | ||
use Adyen\Service\Checkout\PaymentLinksApi; | ||
use Magento\Payment\Gateway\Http\TransferInterface; | ||
|
||
class TransactionPaymentLinksTest extends AbstractAdyenTestCase | ||
{ | ||
private $clientMock; | ||
private $adyenHelperMock; | ||
private $idempotencyHelperMock; | ||
private $transferObjectMock; | ||
private $transactionPaymentLinks; | ||
private $paymentLinksApiMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->adyenHelperMock = $this->createMock(Data::class); | ||
$this->idempotencyHelperMock = $this->createMock(Idempotency::class); | ||
$this->transferObjectMock = $this->createMock(TransferInterface::class); | ||
$this->applicationInfoMock = $this->createMock(ApplicationInfo::class); | ||
$this->adyenHelperMock->method('buildApplicationInfo')->willReturn($this->applicationInfoMock); | ||
$this->transferObjectMock->method('getClientConfig')->willReturn([]); | ||
$this->clientMock = $this->createMock(Client::class); | ||
$this->adyenHelperMock->method('initializeAdyenClientWithClientConfig')->willReturn($this->clientMock); | ||
$this->paymentLinksApiMock = $this->createMock(PaymentLinksApi::class); | ||
$this->adyenHelperMock | ||
->method('initializePaymentLinksApi') | ||
->with($this->clientMock) | ||
->willReturn($this->paymentLinksApiMock); | ||
|
||
$this->transactionPaymentLinks = new TransactionPaymentLinks( | ||
$this->adyenHelperMock, | ||
$this->idempotencyHelperMock | ||
); | ||
} | ||
|
||
public function testSuccessfulPlaceRequest() | ||
{ | ||
$requestBody = [ | ||
'allowedPaymentMethods' => ['ideal','giropay'], | ||
'amount' => ['value' => 1000, 'currency' => 'EUR'], | ||
'applicationInfo' => $this->applicationInfoMock | ||
]; | ||
|
||
$headers = [ 'idempotencyExtraData' => [], 'header' => 'some-data']; | ||
$idempotencyKey = 'generated_idempotency_key'; | ||
|
||
$this->transferObjectMock->method('getBody')->willReturn($requestBody); | ||
$this->transferObjectMock->method('getHeaders')->willReturn($headers); | ||
|
||
$this->idempotencyHelperMock->expects($this->once()) | ||
->method('generateIdempotencyKey') | ||
->with($requestBody, $headers['idempotencyExtraData']) | ||
->willReturn('generated_idempotency_key'); | ||
|
||
$this->paymentLinksApiMock->expects($this->once()) | ||
->method('paymentLinks') | ||
->with( | ||
$this->callback(function (PaymentLinkRequest $paymentLinkRequest) use ($requestBody) { | ||
$amount = $paymentLinkRequest->getAmount(); | ||
$this->assertEquals($amount, ['value' => 1000, 'currency' => 'EUR']); | ||
$allowedPaymentMethods = $paymentLinkRequest->getAllowedPaymentMethods(); | ||
$this->assertEquals($allowedPaymentMethods, ['ideal', 'giropay']); | ||
return true; | ||
}), | ||
$this->callback(function ($requestOptions) use ($idempotencyKey, $headers) { | ||
$this->assertArrayHasKey('idempotencyKey', $requestOptions); | ||
$this->assertArrayHasKey('headers', $requestOptions); | ||
$this->assertEquals($idempotencyKey, $requestOptions['idempotencyKey']); | ||
$this->assertEquals(['header' => 'some-data'], $requestOptions['headers']); | ||
return true; | ||
}) | ||
)->willReturn(new PaymentLinkResponse(['url' => 'https://paymentlink.com'])); | ||
|
||
$response = $this->transactionPaymentLinks->placeRequest($this->transferObjectMock); | ||
$this->assertIsArray($response); | ||
$this->assertArrayHasKey('url', $response); | ||
} | ||
|
||
public function testRequestWithAdyenException() | ||
{ | ||
$requestBody = [ | ||
'amount' => ['currency' => 'EUR', 'value' => 1000], | ||
'merchantAccount' => 'TestMerchant', | ||
'reference' => 'TestReference', | ||
]; | ||
$this->transferObjectMock->method('getBody')->willReturn($requestBody); | ||
$this->transferObjectMock->method('getHeaders')->willReturn([]); | ||
$this->transferObjectMock->method('getClientConfig')->willReturn([]); | ||
|
||
$this->paymentLinksApiMock | ||
->method('paymentLinks') | ||
->willThrowException(new AdyenException()); | ||
|
||
$response = $this->transactionPaymentLinks->placeRequest($this->transferObjectMock); | ||
|
||
$this->assertArrayHasKey('error', $response); | ||
} | ||
|
||
public function testRequestWithResultCodePresent() | ||
{ | ||
$requestBody = ['resultCode' => 'Authorised']; | ||
$this->transferObjectMock->method('getBody')->willReturn($requestBody); | ||
|
||
$response = $this->transactionPaymentLinks->placeRequest($this->transferObjectMock); | ||
$this->assertEquals($requestBody, $response); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.