diff --git a/composer.json b/composer.json index e10b476..7aa2a46 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Model/GetOrderStatusExtended/PaymentAmountInfo.php b/src/Model/GetOrderStatusExtended/PaymentAmountInfo.php index deffb27..36734fb 100644 --- a/src/Model/GetOrderStatusExtended/PaymentAmountInfo.php +++ b/src/Model/GetOrderStatusExtended/PaymentAmountInfo.php @@ -31,7 +31,7 @@ class PaymentAmountInfo * @var string | null * @Serializer\Type("int") */ - private ?string $paymentState; + private null|string|int $paymentState; /** * @return int|null diff --git a/src/Util/ActionCodes.php b/src/Util/ActionCodes.php index 65c9f02..00d047f 100644 --- a/src/Util/ActionCodes.php +++ b/src/Util/ActionCodes.php @@ -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; } \ No newline at end of file diff --git a/tests/BTIPayClientTest.php b/tests/BTIPayClientTest.php deleted file mode 100644 index 8696d37..0000000 --- a/tests/BTIPayClientTest.php +++ /dev/null @@ -1,97 +0,0 @@ -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); - - $btClient = new BTIPayClient('test_iPay2_api', 'test_iPay2_api1', true); - - try { - $response = $btClient->register($order); - } catch (ValidationException $exception) { - print_r( - [ - 'property' => $exception->getProperty(), - 'value' => $exception->getValue(), - 'message' => $exception->getMessage(), - ] - ); - $this->fail(); - return; - } - - print_r($response); - - $this->assertEquals(ErrorCodes::SUCCESS, $response->getErrorCode()); - $this->assertNotEmpty($response->getFormUrl()); - } - - public function testGetOrderStatusExtendedSuccessful(){ - Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); - - $btClient = new BTIPayClient('test_iPay2_api', 'test_iPay2_api1', true); - - //Run the previous test and finish the payment, then copy the orderId here - $orderId = '5ba7984b-9ad0-4ec1-a3b0-5a516d207018'; - - try { - $response = $btClient->getOrderStatusExtendedByOrderId($orderId); - } catch (ValidationException $exception) { - print_r( - [ - 'property' => $exception->getProperty(), - 'value' => $exception->getValue(), - 'message' => $exception->getMessage(), - ] - ); - $this->fail(); - return; - } - - print_r($response->getErrorMessage()); - - $this->assertEquals(ErrorCodes::SUCCESS, $response->getErrorCode()); - $this->assertEquals(ActionCodes::ACTION_CODE_SUCCESS, $response->getActionCode()); - } - -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..fa3bf8d --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,6 @@ +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; + } +} \ No newline at end of file diff --git a/tests/src/BTIPayClientTest.php b/tests/src/BTIPayClientTest.php new file mode 100644 index 0000000..b0ba0da --- /dev/null +++ b/tests/src/BTIPayClientTest.php @@ -0,0 +1,75 @@ +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()); + } + +} diff --git a/tests/src/Model/OrderTest.php b/tests/src/Model/OrderTest.php new file mode 100644 index 0000000..3c623f7 --- /dev/null +++ b/tests/src/Model/OrderTest.php @@ -0,0 +1,54 @@ +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 + ); + } +}