first commit
This commit is contained in:
77
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/NotificationTest.php
vendored
Normal file
77
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/NotificationTest.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Paynow\Tests;
|
||||
|
||||
use Paynow\Exception\SignatureVerificationException;
|
||||
use Paynow\Notification;
|
||||
|
||||
class NotificationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider requestsToTest
|
||||
*/
|
||||
public function testVerifyPayloadSuccessfully($payload, $headers)
|
||||
{
|
||||
// given
|
||||
|
||||
// when
|
||||
new Notification('s3ecret-k3y', $payload, $headers);
|
||||
|
||||
// then
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function requestsToTest()
|
||||
{
|
||||
$payload = $this->loadData('notification.json', true);
|
||||
return [
|
||||
[
|
||||
$payload,
|
||||
['Signature' => 'UZgTT6iSv174R/OyQ2DWRCE9UCmvdXDS8rbQQcjk+AA=']
|
||||
],
|
||||
[
|
||||
$payload,
|
||||
['signature' => 'UZgTT6iSv174R/OyQ2DWRCE9UCmvdXDS8rbQQcjk+AA=']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function testShouldThrowExceptionOnIncorrectSignature()
|
||||
{
|
||||
// given
|
||||
$this->expectException(SignatureVerificationException::class);
|
||||
$payload = $this->loadData('notification.json', true);
|
||||
$headers = ['Signature' => 'Aq/VmN15rtjVbuy9F7Yw+Ym76H+VZjVSuHGpg4dwitY='];
|
||||
|
||||
// when
|
||||
new Notification('s3ecret-k3y', $payload, $headers);
|
||||
|
||||
// then
|
||||
}
|
||||
|
||||
public function testShouldThrowExceptionOnMissingPayload()
|
||||
{
|
||||
// given
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$payload = null;
|
||||
$headers = [];
|
||||
|
||||
// when
|
||||
new Notification('s3ecret-k3y', null, null);
|
||||
|
||||
// then
|
||||
}
|
||||
|
||||
public function testShouldThrowExceptionOnMissingPayloadHeaders()
|
||||
{
|
||||
// given
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$payload = $this->loadData('notification.json', true);
|
||||
$headers = null;
|
||||
|
||||
// when
|
||||
new Notification('s3ecret-k3y', $payload, null);
|
||||
|
||||
// then
|
||||
}
|
||||
}
|
||||
88
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/Service/PaymentTest.php
vendored
Normal file
88
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/Service/PaymentTest.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Paynow\Tests\Service;
|
||||
|
||||
use Paynow\Exception\PaynowException;
|
||||
use Paynow\Service\Payment;
|
||||
use Paynow\Tests\TestCase;
|
||||
|
||||
class PaymentTest extends TestCase
|
||||
{
|
||||
public function testShouldAuthorizePaymentSuccessfully()
|
||||
{
|
||||
// given
|
||||
$this->testHttpClient->mockResponse('payment_success.json', 200);
|
||||
$this->client->setHttpClient($this->testHttpClient);
|
||||
$paymentService = new Payment($this->client);
|
||||
$paymentData = $this->loadData('payment_request.json');
|
||||
|
||||
// when
|
||||
$response = $paymentService->authorize($paymentData, 'idempotencyKey123');
|
||||
|
||||
// then
|
||||
$this->assertNotEmpty($response->redirectUrl);
|
||||
$this->assertNotEmpty($response->paymentId);
|
||||
$this->assertNotEmpty($response->status);
|
||||
}
|
||||
|
||||
public function testShouldNotAuthorizePaymentSuccessfully()
|
||||
{
|
||||
// given
|
||||
$this->testHttpClient->mockResponse('payment_failed.json', 400);
|
||||
$this->client->setHttpClient($this->testHttpClient);
|
||||
|
||||
$paymentData = $this->loadData('payment_request.json');
|
||||
$paymentService = new Payment($this->client);
|
||||
|
||||
// when
|
||||
try {
|
||||
$response = $paymentService->authorize($paymentData, 'idempotencyKey123');
|
||||
} catch (PaynowException $exception) {
|
||||
// then
|
||||
$this->assertEquals(400, $exception->getCode());
|
||||
$this->assertEquals('VALIDATION_ERROR', $exception->getErrors()[0]->errorType);
|
||||
$this->assertEquals(
|
||||
'currency: invalid field value (EUR)',
|
||||
$exception->getErrors()[0]->message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testShouldRetrievePaymentStatusSuccessfully()
|
||||
{
|
||||
// given
|
||||
$this->testHttpClient->mockResponse('payment_status.json', 200);
|
||||
$this->client->setHttpClient($this->testHttpClient);
|
||||
$paymentService = new Payment($this->client);
|
||||
$paymentId = 'PBYV-3AZ-UPW-DPC';
|
||||
|
||||
// when
|
||||
$response = $paymentService->status($paymentId);
|
||||
|
||||
// then
|
||||
$this->assertEquals($response->paymentId, $paymentId);
|
||||
$this->assertEquals($response->status, 'NEW');
|
||||
}
|
||||
|
||||
public function testShouldNotRetrievePaymentStatusSuccesfully()
|
||||
{
|
||||
// given
|
||||
$this->testHttpClient->mockResponse('payment_status_not_found.json', 404);
|
||||
$this->client->setHttpClient($this->testHttpClient);
|
||||
$paymentService = new Payment($this->client);
|
||||
$paymentId = 'PBYV-3AZ-UPW-DPC';
|
||||
|
||||
// when
|
||||
try {
|
||||
$response = $paymentService->status($paymentId);
|
||||
} catch (PaynowException $exception) {
|
||||
// then
|
||||
$this->assertEquals(404, $exception->getCode());
|
||||
$this->assertEquals('NOT_FOUND', $exception->getErrors()[0]->errorType);
|
||||
$this->assertEquals(
|
||||
'Could not find status for payment {paymentId=PBYV-3AZ-UPW-DPCf}',
|
||||
$exception->getErrors()[0]->message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/Service/ShopConfigurationTest.php
vendored
Normal file
47
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/Service/ShopConfigurationTest.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Paynow\Tests\Service;
|
||||
|
||||
use Paynow\Exception\PaynowException;
|
||||
use Paynow\Service\ShopConfiguration;
|
||||
use Paynow\Tests\TestCase;
|
||||
|
||||
class ShopConfigurationTest extends TestCase
|
||||
{
|
||||
private $continueUrl = 'http://shopdomain.com/return';
|
||||
private $notificationUrl = 'http://shopdomain.com/notifications';
|
||||
|
||||
public function testShouldUpdateShopConfigurationSuccessfully()
|
||||
{
|
||||
// given
|
||||
$this->testHttpClient->mockResponse(null, 204);
|
||||
$this->client->setHttpClient($this->testHttpClient);
|
||||
$shopConfigurationService = new ShopConfiguration($this->client);
|
||||
|
||||
// when
|
||||
$response = $shopConfigurationService->changeUrls($this->continueUrl, $this->notificationUrl);
|
||||
|
||||
// then
|
||||
$this->assertEquals(204, $response->status);
|
||||
}
|
||||
|
||||
public function testShouldNotUpdateShopConfigurationSuccessfully()
|
||||
{
|
||||
// given
|
||||
$this->testHttpClient->mockResponse('shop_configuration_urls_failed.json', 400);
|
||||
$this->client->setHttpClient($this->testHttpClient);
|
||||
$shopConfigurationService = new ShopConfiguration($this->client);
|
||||
// when
|
||||
try {
|
||||
$response = $shopConfigurationService->changeUrls($this->continueUrl, $this->notificationUrl);
|
||||
} catch (PaynowException $exception) {
|
||||
// then
|
||||
$this->assertEquals(400, $exception->getCode());
|
||||
$this->assertEquals('VALIDATION_ERROR', $exception->getErrors()[0]->errorType);
|
||||
$this->assertEquals(
|
||||
'continue_url: invalid field value',
|
||||
$exception->getErrors()[0]->message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/TestCase.php
vendored
Normal file
36
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/TestCase.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Paynow\Tests;
|
||||
|
||||
use Paynow\Client;
|
||||
use Paynow\Environment;
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
|
||||
class TestCase extends BaseTestCase
|
||||
{
|
||||
protected $testHttpClient;
|
||||
|
||||
protected $client;
|
||||
|
||||
public function __construct($name = null, array $data = [], $dataName = '')
|
||||
{
|
||||
$this->client = new Client(
|
||||
'TestApiKey',
|
||||
'TestSignatureKey',
|
||||
Environment::SANDBOX,
|
||||
'PHPUnitTests'
|
||||
);
|
||||
$this->testHttpClient = new TestHttpClient($this->client->getConfiguration());
|
||||
parent::__construct($name, $data, $dataName);
|
||||
}
|
||||
|
||||
public function loadData($fileName, $asString = false)
|
||||
{
|
||||
$filePath = dirname(__FILE__).'/resources/'.$fileName;
|
||||
if (! $asString) {
|
||||
return json_decode(file_get_contents($filePath), true);
|
||||
} else {
|
||||
return file_get_contents($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/TestHttpClient.php
vendored
Normal file
22
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/TestHttpClient.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Paynow\Tests;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Http\Mock\Client;
|
||||
use Paynow\HttpClient\HttpClient;
|
||||
|
||||
class TestHttpClient extends HttpClient
|
||||
{
|
||||
public function mockResponse($responseFile, $httpStatus)
|
||||
{
|
||||
$this->client = new Client();
|
||||
$content = null;
|
||||
if (null != $responseFile) {
|
||||
$filePath = dirname(__FILE__).'/resources/'.$responseFile;
|
||||
$content = file_get_contents($filePath, true);
|
||||
}
|
||||
$response = new Response($httpStatus, ['Content-Type' => 'application/json'], $content);
|
||||
$this->client->addResponse($response);
|
||||
}
|
||||
}
|
||||
44
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/Util/SignatureCalculatorTest.php
vendored
Normal file
44
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/Util/SignatureCalculatorTest.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Paynow\Tests\Util;
|
||||
|
||||
use Paynow\Tests\TestCase;
|
||||
use Paynow\Util\SignatureCalculator;
|
||||
|
||||
class SignatureCalculatorTest extends TestCase
|
||||
{
|
||||
public function testNotValidSuccessfully()
|
||||
{
|
||||
// given + when
|
||||
$signatureCalculator = new SignatureCalculator('InvalidSecretKey', ['key' => 'value']);
|
||||
|
||||
// then
|
||||
$this->assertNotEquals('hash', $signatureCalculator->getHash());
|
||||
}
|
||||
|
||||
public function testShouldValidSuccessfully()
|
||||
{
|
||||
// given + when
|
||||
$signatureCalculator = new SignatureCalculator(
|
||||
'a621a1fb-b4d8-48ba-a6a3-2a28ed61f605',
|
||||
[
|
||||
'key1' => 'value1',
|
||||
'key2' => 'val/ue2',
|
||||
]
|
||||
);
|
||||
|
||||
// then
|
||||
$this->assertEquals('bqD6spGJwPABe58i+mbqsYoF/JLUDR58yqxRqrb0AR0=', $signatureCalculator->getHash());
|
||||
}
|
||||
|
||||
public function testExceptionForEmptyData()
|
||||
{
|
||||
// given
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
// when
|
||||
$signatureCalculator = new SignatureCalculator('a621a1fb-b4d8-48ba-a6a3-2a28ed61f605', []);
|
||||
|
||||
// then
|
||||
}
|
||||
}
|
||||
5
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/bootstrap.php
vendored
Normal file
5
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
require_once __DIR__.'/TestCase.php';
|
||||
require_once __DIR__.'/TestHttpClient.php';
|
||||
5
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/notification.json
vendored
Normal file
5
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/notification.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"paymentId": "NOLV-8F9-08K-WGD",
|
||||
"status": "CONFIRMED",
|
||||
"modifiedAt": "2018-12-12T13:24:52"
|
||||
}
|
||||
9
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_failed.json
vendored
Normal file
9
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_failed.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"statusCode": 400,
|
||||
"errors": [
|
||||
{
|
||||
"errorType": "VALIDATION_ERROR",
|
||||
"message": "currency: invalid field value (EUR)"
|
||||
}
|
||||
]
|
||||
}
|
||||
9
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_request.json
vendored
Normal file
9
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_request.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"amount": 100,
|
||||
"currency": "PLN",
|
||||
"externalId": "success_1234567",
|
||||
"description": "Test payment",
|
||||
"buyer": {
|
||||
"email": "customer@domain.com"
|
||||
}
|
||||
}
|
||||
4
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_status.json
vendored
Normal file
4
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_status.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"paymentId": "PBYV-3AZ-UPW-DPC",
|
||||
"status": "NEW"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"statusCode": 404,
|
||||
"errors": [
|
||||
{
|
||||
"errorType": "NOT_FOUND",
|
||||
"message": "Could not find status for payment {paymentId=PBYV-3AZ-UPW-DPCf}"
|
||||
}
|
||||
]
|
||||
}
|
||||
5
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_success.json
vendored
Normal file
5
plugins/stPayNowPlugin/vendor/pay-now/paynow-php-sdk/tests/resources/payment_success.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"redirectUrl": "https://paywall.sandbox.paynow.pl/NO0U-5G2-XC1-ESX?token=eyJraWQiOiJhMDAyNjJjYS02NTU3LTRjOTktOGU0NC1kMTFlMTAxYjhhNTIiLCJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJOTzBVLTVHMi1YQzEtRVNYIiwiYXVkIjoicGF5d2FsbC5zYW5kYm94LnBheW5vdy5wbCIsImlzcyI6InNhbmRib3gucGF5bm93LnBsIiwiZXhwIjoxNTY2ODk5MTYwLCJpYXQiOjE1NjY4MTI3NjB9.25TM-BXTDJV3NLEufgYVNZ7W_0JmJjS2Qu-0-d1HIQM",
|
||||
"paymentId": "NO0U-5G2-XC1-ESX",
|
||||
"status": "NEW"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"statusCode": 400,
|
||||
"errors": [
|
||||
{
|
||||
"errorType": "VALIDATION_ERROR",
|
||||
"message": "continue_url: invalid field value"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user