first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace Paynow\Tests\Service;
use Paynow\Service\DataProcessing;
use Paynow\Tests\TestCase;
class DataProcessingTest extends TestCase
{
public function testShouldRetrieveAllNoticeListSuccessfully()
{
// given
$this->testHttpClient->mockResponse('data_processing_notices_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$dataProcessing = new DataProcessing($this->client);
// when
$notices = $dataProcessing->getNotices('pl-PL')->getAll();
// then
$this->assertNotEmpty($notices);
}
}

View File

@@ -0,0 +1,128 @@
<?php
namespace Paynow\Tests\Service;
use Paynow\Model\PaymentMethods\AuthorizationType;
use Paynow\Model\PaymentMethods\Status;
use Paynow\Model\PaymentMethods\Type;
use Paynow\Service\Payment;
use Paynow\Tests\TestCase;
class PaymentMethodsTest extends TestCase
{
public function testShouldRetrieveAllPaymentMethodsListSuccessfully()
{
// given
$this->testHttpClient->mockResponse('payment_methods_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$paymentService = new Payment($this->client);
// when
$paymentMethods = $paymentService->getPaymentMethods('PLN', 1000)->getAll();
// then
$this->assertNotEmpty($paymentMethods);
$this->assertEquals('2007', $paymentMethods[0]->getId());
$this->assertEquals('BLIK', $paymentMethods[0]->getName());
$this->assertEquals('https://static.sandbox.paynow.pl/payment-method-icons/2007.png', $paymentMethods[0]->getImage());
$this->assertEquals('Płacę z Blikiem', $paymentMethods[0]->getDescription());
$this->assertEquals(Type::BLIK, $paymentMethods[0]->getType());
$this->assertEquals(Status::ENABLED, $paymentMethods[0]->getStatus());
$this->assertTrue($paymentMethods[0]->isEnabled());
}
public function testShouldRetrieveAllPaymentMethodsListSuccessfullyForWhiteLabel()
{
// given
$this->testHttpClient->mockResponse('payment_methods_white_label_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$paymentService = new Payment($this->client);
// when
$paymentMethods = $paymentService->getPaymentMethods('PLN', 1000, true)->getAll();
// then
$this->assertNotEmpty($paymentMethods);
$this->assertEquals('2007', $paymentMethods[0]->getId());
$this->assertEquals('BLIK', $paymentMethods[0]->getName());
$this->assertEquals('https://static.sandbox.paynow.pl/payment-method-icons/2007.png', $paymentMethods[0]->getImage());
$this->assertEquals(Status::ENABLED, $paymentMethods[0]->getStatus());
$this->assertEquals('Płacę z Blikiem', $paymentMethods[0]->getDescription());
$this->assertEquals(Type::BLIK, $paymentMethods[0]->getType());
$this->assertEquals(Status::ENABLED, $paymentMethods[0]->getStatus());
$this->assertEquals(AuthorizationType::CODE, $paymentMethods[0]->getAuthorizationType());
$this->assertTrue($paymentMethods[0]->isEnabled());
}
public function testShouldRetrieveOnlyBlikPaymentMethodsListSuccessfully()
{
// given
$this->testHttpClient->mockResponse('payment_methods_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$paymentService = new Payment($this->client);
// when
$blikPaymentMethods = $paymentService->getPaymentMethods("PLN")->getOnlyBlik();
// then
$this->assertNotEmpty($blikPaymentMethods);
$this->assertEquals(1, sizeof($blikPaymentMethods));
$this->assertEquals('BLIK', $blikPaymentMethods[0]->getName());
$this->assertEquals(Type::BLIK, $blikPaymentMethods[0]->getType());
$this->assertTrue($blikPaymentMethods[0]->isEnabled());
}
public function testShouldRetrieveOnlyCardPaymentMethodsListSuccessfully()
{
// given
$this->testHttpClient->mockResponse('payment_methods_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$paymentService = new Payment($this->client);
// when
$cardPaymentMethods = $paymentService->getPaymentMethods()->getOnlyCards();
// then
$this->assertNotEmpty($cardPaymentMethods);
$this->assertEquals(1, sizeof($cardPaymentMethods));
$this->assertEquals('Karta płatnicza', $cardPaymentMethods[0]->getName());
$this->assertEquals(Type::CARD, $cardPaymentMethods[0]->getType());
$this->assertTrue($cardPaymentMethods[0]->isEnabled());
}
public function testShouldRetrieveOnlyGooglePayPaymentMethodsListSuccessfully()
{
// given
$this->testHttpClient->mockResponse('payment_methods_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$paymentService = new Payment($this->client);
// when
$cardPaymentMethods = $paymentService->getPaymentMethods()->getOnlyGooglePay();
// then
$this->assertNotEmpty($cardPaymentMethods);
$this->assertEquals(1, sizeof($cardPaymentMethods));
$this->assertEquals('Google Pay', $cardPaymentMethods[0]->getName());
$this->assertEquals(Type::GOOGLE_PAY, $cardPaymentMethods[0]->getType());
$this->assertTrue($cardPaymentMethods[0]->isEnabled());
}
public function testShouldRetrieveOnlyPblPaymentMethodsListSuccessfully()
{
// given
$this->testHttpClient->mockResponse('payment_methods_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$paymentService = new Payment($this->client);
// when
$pblPaymentMethods = $paymentService->getPaymentMethods()->getOnlyPbls();
// then
$this->assertNotEmpty($pblPaymentMethods);
$this->assertEquals(3, sizeof($pblPaymentMethods));
$this->assertEquals('mTransfer', $pblPaymentMethods[0]->getName());
$this->assertEquals(Type::PBL, $pblPaymentMethods[0]->getType());
$this->assertTrue($pblPaymentMethods[0]->isEnabled());
}
}

View 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->getRedirectUrl());
$this->assertNotEmpty($response->getPaymentId());
$this->assertNotEmpty($response->getStatus());
}
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]->getType());
$this->assertEquals(
'currency: invalid field value (EUR)',
$exception->getErrors()[0]->getMessage()
);
}
}
public function testShouldRetrievePaymentStatusSuccessfully()
{
// given
$this->testHttpClient->mockResponse('payment_status_success.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($paymentId, $response->getPaymentId());
$this->assertEquals('NEW', $response->getStatus());
}
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]->getType());
$this->assertEquals(
'Could not find status for payment {paymentId=PBYV-3AZ-UPW-DPC}',
$exception->getErrors()[0]->getMessage()
);
}
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Paynow\Tests\Service;
use Paynow\Exception\PaynowException;
use Paynow\Service\Refund;
use Paynow\Tests\TestCase;
class RefundTest extends TestCase
{
public function testShouldRefundPaymentSuccessfully()
{
// given
$this->testHttpClient->mockResponse('refund_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$refundService = new Refund($this->client);
// when
$response = $refundService->create('NOR3-FUN-D4U-LOL', 'idempotencyKey123', 100, null);
// then
$this->assertNotEmpty($response->getRefundId());
$this->assertNotEmpty($response->getStatus());
}
public function testShouldNotAuthorizePaymentSuccessfully()
{
// given
$this->testHttpClient->mockResponse('refund_failed.json', 400);
$this->client->setHttpClient($this->testHttpClient);
$refundService = new Refund($this->client);
// when
try {
$response = $refundService->create('NOR3-FUN-D4U-LOL', 'idempotencyKey123', 100, null);
} catch (PaynowException $exception) {
// then
$this->assertEquals(400, $exception->getCode());
$this->assertEquals('INSUFFICIENT_BALANCE_FUNDS', $exception->getErrors()[0]->getType());
$this->assertEquals(
'Insufficient funds on balance',
$exception->getErrors()[0]->getMessage()
);
}
}
public function testShouldRetrieveRefundStatusSuccessfully()
{
// given
$this->testHttpClient->mockResponse('refund_status_success.json', 200);
$this->client->setHttpClient($this->testHttpClient);
$refundService = new Refund($this->client);
$refundId = 'R3FU-UND-D8K-WZD';
// when
$response = $refundService->status($refundId);
// then
$this->assertEquals($refundId, $response->getRefundId());
$this->assertEquals('NEW', $response->getStatus());
}
public function testShouldNotRetrievePaymentStatusSuccesfully()
{
// given
$this->testHttpClient->mockResponse('refund_status_not_found.json', 404);
$this->client->setHttpClient($this->testHttpClient);
$refundService = new Refund($this->client);
$refundId = 'R3FU-UND-D8K-WZD';
// when
try {
$response = $refundService->status($refundId);
} catch (PaynowException $exception) {
// then
$this->assertEquals(404, $exception->getCode());
$this->assertEquals('NOT_FOUND', $exception->getErrors()[0]->getType());
$this->assertEquals(
'Could not find status for refund {refundId=R3FU-UND-D8K-WZD}',
$exception->getErrors()[0]->getMessage()
);
}
}
}

View 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]->getType());
$this->assertEquals(
'continue_url: invalid field value',
$exception->getErrors()[0]->getMessage()
);
}
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;