-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
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.