Skip to content

Commit

Permalink
Merge pull request #4 from paytic/master
Browse files Browse the repository at this point in the history
refactor: tests to separate folder with fixtures
  • Loading branch information
stevro authored Apr 17, 2024
2 parents 6072516 + e34571a commit 9e9c4f7
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 98 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"Stev\\BTIPay\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Stev\\BTIPay\\Tests\\Fixtures\\": "tests/fixtures",
"Stev\\BTIPay\\Tests\\": "tests/src"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
Expand Down
2 changes: 1 addition & 1 deletion src/Model/GetOrderStatusExtended/PaymentAmountInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PaymentAmountInfo
* @var string | null
* @Serializer\Type("int")
*/
private ?string $paymentState;
private null|string|int $paymentState;

/**
* @return int|null
Expand Down
52 changes: 52 additions & 0 deletions src/Util/ActionCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,74 @@ class ActionCodes
{

public const ACTION_CODE_SUCCESS = 0;

// = Card restricționat (blocat temporar sau permanent din cauza lipsei plății sau a morții titularului de card).
public const ACTION_CODE_CARD_RESTRICTED = 104;

// Tranzacția nu poate fi autorizată din cauza acordului guvernului, băncii
//centrale sau instituției financiare, legi sau reglementări
public const ACTION_CODE_CARD_REGULATION_ERROR = 124;

// Card inactiv. Vă rugăm activați cardul.
public const ACTION_CODE_INACTIVE = 320;

// Emitent indisponibil.
public const ACTION_CODE_ISSUER_UNAVAILABLE = 801;

// Card blocat. Contactați banca emitentă sau reîncercați tranzacția cu alt card.
public const ACTION_CODE_BLOCKED_CARD = 803;

// Tranzacția nu este permisă. Contactați banca emitentă sau reîncercați tranzacția cu alt card.
public const ACTION_CODE_TRANSACTION_NOT_ALLOWED = 804;

// Tranzacție respinsă.
public const ACTION_CODE_TRANSACTION_REJECTED = 805;

// Dată expirare card greșită.
public const ACTION_CODE_INVALID_CARD_EXPIRY_DATE = 861;

// CVV gresit.
public const ACTION_CODE_INVALID_CARD_CVV = 871;

// Card invalid. Acesta nu există în baza de date.
public const ACTION_CODE_INVALID_CARD = 905;

// Card expirat.
public const ACTION_CODE_EXPIRED_CARD = 906;

// Tranzacție invalidă. Contactați banca emitentă sau reîncercați tranzacția cu alt card.
public const ACTION_CODE_INVALID_TRANSACTION = 913;

// Cont invalid. Vă rugăm contactați banca emitentă.
public const ACTION_CODE_INVALID_ACCOUNT = 914;

// Fonduri insuficiente.
public const ACTION_CODE_INSUFFICIENT_FUNDS = 915;

// Limită tranzacționare depășită.
public const ACTION_CODE_TRANSACTION_LIMIT_EXCEDED = 917;

// Suspect de fraudă.
public const ACTION_CODE_FRAUD_SUSPICION = 952;

// Tranzacția în rate nu este permisă cu acest card. Te rugăm să folosești un card de credit emise de Banca Transilvania.
public const ACTION_CODE_INSTALLMENTS_NOT_ALLOWED = 998;

// 3DS2 authentication is declined by Authentication Response (ARes) – issuer
public const ACTION_CODE_3DS_AUTH_DECLINED = 341016;

// 3DS2 authentication status in ARes is unknown - issuer
public const ACTION_CODE_3DS_AUTH_STATUS_UNKNOWN = 341017;

// 3DS2 CReq cancelled - client
public const ACTION_CODE_3DS_CREQ_CANCELLED = 341018;

// 3DS2 CReq failed - client/issuer
public const ACTION_CODE_3DS_CREQ_FAILED = 341019;

// 3DS2 unknown status in RReq - issuer
public const ACTION_CODE_3DS_RREQ_UNKNOWN_STATUS = 341020;

// No payment attempts yet
public const ACTION_CODE_NO_PAYMENT_ATTEMPTS = -100;
}
97 changes: 0 additions & 97 deletions tests/BTIPayClientTest.php

This file was deleted.

6 changes: 6 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

require dirname(__DIR__, 1) . '/vendor/autoload.php';

define('BTIPAY_USERNAME', 'test_iPay4_api');
define('BTIPAY_PASSWORD', 'test_iPay4_ap!r5t');
42 changes: 42 additions & 0 deletions tests/fixtures/Factories/OrderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Stev\BTIPay\Tests\Fixtures\Factories;

use DateTime;
use Stev\BTIPay\Model\BillingInfo;
use Stev\BTIPay\Model\CustomerDetails;
use Stev\BTIPay\Model\Order;
use Stev\BTIPay\Model\OrderBundle;

class OrderFactory
{
public static function basicOrder(): Order
{
$currentDate = new DateTime();
$order = new Order();
$order->setOrderNumber(uniqid('F', false) . '/' . $currentDate->format('d-m-Y'))
->setDescription('Plata Fact F')
->setEmail('contact.webservice@gmail.com')
->setAmount(1000)
->setCurrencyAlpha3('RON')
->setReturnUrl("https://ecclients.btrl.ro:5443/payment/merchants/Test_BT/finish.html");

$order->force3DSecure(true);

$customerDetails = new CustomerDetails();
$customerDetails->setEmail('contact.webservice@gmail.com')
->setPhone(40743333333)
->setContact('Stefan');

$billingInfo = new BillingInfo();
$billingInfo->setCountryAlpha2('RO')
->setCity('Iasi')
->setPostAddress('Elena Doamna 20-22');
$customerDetails->setBillingInfo($billingInfo);

$orderBundle = new OrderBundle($currentDate, $customerDetails);

$order->setOrderBundle($orderBundle);
return $order;
}
}
75 changes: 75 additions & 0 deletions tests/src/BTIPayClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Stev\BTIPay\Tests;

use PHPUnit\Framework\TestCase;
use Stev\BTIPay\BTIPayClient;
use Stev\BTIPay\Exceptions\ValidationException;
use Stev\BTIPay\Tests\Fixtures\Factories\OrderFactory;
use Stev\BTIPay\Util\ActionCodes;
use Stev\BTIPay\Util\ErrorCodes;

final class BTIPayClientTest extends TestCase
{
protected static $orderIdCreated = null;

public function testRegisterSuccessful()
{
$order = OrderFactory::basicOrder();

$btClient = new BTIPayClient(BTIPAY_USERNAME, BTIPAY_PASSWORD, true);

try {
$response = $btClient->register($order);
} catch (ValidationException $exception) {
$this->fail(
print_r(
[
'property' => $exception->getProperty(),
'value' => $exception->getValue(),
'message' => $exception->getMessage(),
],
true
)
);
}

// print_r($response);

$this->assertEquals(ErrorCodes::SUCCESS, $response->getErrorCode());
$this->assertNotEmpty($response->getFormUrl());

self::$orderIdCreated = $response->getOrderId();
}

public function testGetOrderStatusExtendedSuccessful()
{
$btClient = new BTIPayClient(BTIPAY_USERNAME, BTIPAY_PASSWORD, true);

if (self::$orderIdCreated === null) {
//Run the previous test and finish the payment, then copy the orderId here
$this->fail('You need to run the previous test first');
}

try {
$response = $btClient->getOrderStatusExtendedByOrderId(self::$orderIdCreated);
} catch (ValidationException $exception) {
$this->fail(
print_r(
[
'property' => $exception->getProperty(),
'value' => $exception->getValue(),
'message' => $exception->getMessage(),
],
true
)
);
}

// print_r($response);

$this->assertEquals(ErrorCodes::SUCCESS, $response->getErrorCode());
$this->assertEquals(ActionCodes::ACTION_CODE_NO_PAYMENT_ATTEMPTS, $response->getActionCode());
}

}
54 changes: 54 additions & 0 deletions tests/src/Model/OrderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Stev\BTIPay\Tests\Model;

use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerBuilder;
use PHPUnit\Framework\TestCase;
use Stev\BTIPay\Tests\Fixtures\Factories\OrderFactory;

use function PHPUnit\Framework\assertSame;

class OrderTest extends TestCase
{
public function testSerialize()
{
$order = OrderFactory::basicOrder();
$order->setOrderNumber('F661eaee8bf2a7/16-04-2024');
$order->setUsername(BTIPAY_USERNAME);
$order->setPassword(BTIPAY_PASSWORD);

$serializer = SerializerBuilder::create()
->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new IdenticalPropertyNamingStrategy()))
->setSerializationContextFactory(
function () {
return SerializationContext::create()
->setSerializeNull(false);
}
)
->build();

$orderJson = $serializer->serialize($order, 'json');
assertSame(
'{"userName":"test_iPay4_api","password":"test_iPay4_ap!r5t","orderNumber":"F661eaee8bf2a7\/16-04-2024","amount":1000,"currency":"946","returnUrl":"https:\/\/ecclients.btrl.ro:5443\/payment\/merchants\/Test_BT\/finish.html","description":"Plata Fact F","pageView":"DESKTOP","email":"contact.webservice@gmail.com"}',
$orderJson
);
$requestData = $serializer->deserialize($orderJson, 'array', 'json');
assertSame(
[
'userName' => 'test_iPay4_api',
'password' => 'test_iPay4_ap!r5t',
'orderNumber' => 'F661eaee8bf2a7/16-04-2024',
'amount' => 1000,
'currency' => '946',
'returnUrl' => 'https://ecclients.btrl.ro:5443/payment/merchants/Test_BT/finish.html',
'description' => 'Plata Fact F',
'pageView' => 'DESKTOP',
'email' => 'contact.webservice@gmail.com',
],
$requestData
);
}
}

0 comments on commit 9e9c4f7

Please sign in to comment.