From 05b2817457bec30e83a4fed6737a54f9c3a0205a Mon Sep 17 00:00:00 2001 From: mustapayev Date: Sat, 12 Oct 2024 14:48:50 +0200 Subject: [PATCH 1/3] vakifkatilim - improve order_status response mapping --- .../KuveytPosResponseDataMapper.php | 2 +- .../VakifKatilimPosResponseDataMapper.php | 26 ++++++++++++------- .../VakifKatilimPosResponseDataMapperTest.php | 10 +++---- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php index ef4c5723..7090184b 100644 --- a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php @@ -25,7 +25,7 @@ class KuveytPosResponseDataMapper extends AbstractResponseDataMapper /** * Order Status Codes * - * @var array + * @var array */ protected array $orderStatusMappings = [ 1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, diff --git a/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php index 3eedcea9..cd114625 100644 --- a/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php @@ -21,6 +21,18 @@ class VakifKatilimPosResponseDataMapper extends AbstractResponseDataMapper '51' => 'reject', ]; + /** + * Order Status Codes + * + * @var array + */ + protected array $orderStatusMappings = [ + 1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 4 => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, + 5 => PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED, + 6 => PosInterface::PAYMENT_STATUS_CANCELED, + ]; + /** * {@inheritDoc} */ @@ -491,20 +503,16 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array $defaultResponse['installment_count'] = $this->mapInstallment($rawTx['InstallmentCount']); $defaultResponse['masked_number'] = $rawTx['CardNumber']; $defaultResponse['first_amount'] = (float) $rawTx['FirstAmount']; - $defaultResponse['order_status'] = $rawTx['LastOrderStatusDescription']; - - /** - * OrderStatus - * 1 => Satis - * 6 => Iptal - */ - if ('1' === $rawTx['OrderStatus']) { + $defaultResponse['order_status'] = $this->orderStatusMappings[$rawTx['LastOrderStatus']] ?? $rawTx['LastOrderStatusDescription']; + $initialOrderStatus = $this->orderStatusMappings[$rawTx['OrderStatus']] ?? null; + + if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $initialOrderStatus) { $defaultResponse['capture_amount'] = isset($rawTx['TranAmount']) ? (float) $rawTx['TranAmount'] : 0; $defaultResponse['capture'] = $defaultResponse['first_amount'] === $defaultResponse['capture_amount']; if ($defaultResponse['capture']) { $defaultResponse['capture_time'] = $defaultResponse['transaction_time']; } - } elseif ('6' === $rawTx['OrderStatus']) { + } elseif (PosInterface::PAYMENT_STATUS_CANCELED === $initialOrderStatus) { $defaultResponse['cancel_time'] = $defaultResponse['transaction_time']; } } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php index 7b8f7e7e..2b3c15b0 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php @@ -722,7 +722,7 @@ public static function statusTestDataProvider(): iterable 'installment_count' => 0, 'masked_number' => '5353********7017', 'order_id' => '1995434716', - 'order_status' => null, + 'order_status' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, 'payment_model' => null, 'proc_return_code' => '00', 'ref_ret_num' => '035909014127', @@ -797,7 +797,7 @@ public static function statusTestDataProvider(): iterable 'installment_count' => 0, 'masked_number' => '5188********2666', 'order_id' => '20240701CF44', - 'order_status' => 'Iptal', + 'order_status' => PosInterface::PAYMENT_STATUS_CANCELED, 'payment_model' => '3d', 'proc_return_code' => '00', 'ref_ret_num' => '418315149569', @@ -1283,7 +1283,7 @@ public static function historyTestDataProvider(): array 'capture_time' => null, 'error_message' => null, 'ref_ret_num' => '036008014143', - 'order_status' => 'Satis', + 'order_status' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, 'transaction_type' => null, 'first_amount' => 2.7, 'capture_amount' => 0, @@ -1494,7 +1494,7 @@ public static function orderHistoryTestDataProvider(): array 'first_amount' => 10.01, 'installment_count' => 2, 'masked_number' => '5351********9885', - 'order_status' => 'Iptal', + 'order_status' => PosInterface::PAYMENT_STATUS_CANCELED, 'payment_model' => '3d', 'proc_return_code' => '00', 'ref_ret_num' => '418315158962', @@ -1515,7 +1515,7 @@ public static function orderHistoryTestDataProvider(): array 'first_amount' => 10.01, 'installment_count' => 2, 'masked_number' => '5351********9885', - 'order_status' => 'Iptal', + 'order_status' => PosInterface::PAYMENT_STATUS_CANCELED, 'payment_model' => '3d', 'proc_return_code' => '00', 'ref_ret_num' => '418315158962', From 16f032d3c8ef8bd93b1a52c13d4e9171ce6d244a Mon Sep 17 00:00:00 2001 From: mustapayev Date: Sat, 12 Oct 2024 14:55:34 +0200 Subject: [PATCH 2/3] interpos - added a comment --- .../ResponseDataMapper/InterPosResponseDataMapper.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php index a90d942a..0f4d0282 100644 --- a/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php @@ -360,6 +360,14 @@ private function map3DCommonResponseData(array $raw3DAuthResponseData, ?array $r 'currency' => $this->mapCurrency($raw3DAuthResponseData['Currency']), 'transaction_time' => isset($raw3DAuthResponseData['TRXDATE']) ? new \DateTimeImmutable($raw3DAuthResponseData['TRXDATE']) : null, 'eci' => $raw3DAuthResponseData['Eci'], + /** + * TxnStat 3D doğrulama sonucunu belirtir : + * Y : Başarılı + * N : Başarısız + * A : Half Secure) + * U : Teknik Hata + * E : Hata + */ 'tx_status' => $raw3DAuthResponseData['TxnStat'], 'cavv' => null, 'md_error_message' => $raw3DAuthResponseData['ErrorMessage'], From 1055b66f3209724e529fde7f81b9fd6a38eb3381 Mon Sep 17 00:00:00 2001 From: mustapayev Date: Sat, 12 Oct 2024 16:19:37 +0200 Subject: [PATCH 3/3] tests - test coverage for factory classes --- src/Factory/CryptFactory.php | 8 +- src/Factory/RequestDataMapperFactory.php | 10 +- src/Factory/ResponseDataMapperFactory.php | 12 +- src/Factory/SerializerFactory.php | 6 +- tests/Unit/Factory/AccountFactoryTest.php | 2 +- tests/Unit/Factory/CryptFactoryTest.php | 47 +++++ tests/Unit/Factory/PosFactoryTest.php | 198 ++++++++++++++++++ .../Factory/RequestDataMapperFactoryTest.php | 65 ++++++ .../Factory/ResponseDataMapperFactoryTest.php | 64 ++++++ tests/Unit/Factory/SerializerFactoryTest.php | 50 +++++ 10 files changed, 443 insertions(+), 19 deletions(-) create mode 100644 tests/Unit/Factory/CryptFactoryTest.php create mode 100644 tests/Unit/Factory/PosFactoryTest.php create mode 100644 tests/Unit/Factory/RequestDataMapperFactoryTest.php create mode 100644 tests/Unit/Factory/ResponseDataMapperFactoryTest.php create mode 100644 tests/Unit/Factory/SerializerFactoryTest.php diff --git a/src/Factory/CryptFactory.php b/src/Factory/CryptFactory.php index 13d056e1..952e9b51 100644 --- a/src/Factory/CryptFactory.php +++ b/src/Factory/CryptFactory.php @@ -46,18 +46,18 @@ class CryptFactory public static function createGatewayCrypt(string $gatewayClass, LoggerInterface $logger): CryptInterface { $classMappings = [ - ToslaPos::class => ToslaPosCrypt::class, AkbankPos::class => AkbankPosCrypt::class, - EstV3Pos::class => EstV3PosCrypt::class, EstPos::class => EstPosCrypt::class, + EstV3Pos::class => EstV3PosCrypt::class, GarantiPos::class => GarantiPosCrypt::class, InterPos::class => InterPosCrypt::class, KuveytPos::class => KuveytPosCrypt::class, - VakifKatilimPos::class => KuveytPosCrypt::class, + PayFlexCPV4Pos::class => PayFlexCPV4Crypt::class, PayForPos::class => PayForPosCrypt::class, PosNet::class => PosNetCrypt::class, PosNetV1Pos::class => PosNetV1PosCrypt::class, - PayFlexCPV4Pos::class => PayFlexCPV4Crypt::class, + ToslaPos::class => ToslaPosCrypt::class, + VakifKatilimPos::class => KuveytPosCrypt::class, ]; if (isset($classMappings[$gatewayClass])) { diff --git a/src/Factory/RequestDataMapperFactory.php b/src/Factory/RequestDataMapperFactory.php index 72e81a54..9dd1ec31 100644 --- a/src/Factory/RequestDataMapperFactory.php +++ b/src/Factory/RequestDataMapperFactory.php @@ -53,24 +53,24 @@ class RequestDataMapperFactory public static function createGatewayRequestMapper(string $gatewayClass, EventDispatcherInterface $eventDispatcher, CryptInterface $crypt, array $currencies = []): RequestDataMapperInterface { $classMappings = [ - ToslaPos::class => ToslaPosRequestDataMapper::class, AkbankPos::class => AkbankPosRequestDataMapper::class, EstPos::class => EstPosRequestDataMapper::class, EstV3Pos::class => EstV3PosRequestDataMapper::class, GarantiPos::class => GarantiPosRequestDataMapper::class, InterPos::class => InterPosRequestDataMapper::class, KuveytPos::class => KuveytPosRequestDataMapper::class, - VakifKatilimPos::class => VakifKatilimPosRequestDataMapper::class, + PayFlexCPV4Pos::class => PayFlexCPV4PosRequestDataMapper::class, + PayFlexV4Pos::class => PayFlexV4PosRequestDataMapper::class, PayForPos::class => PayForPosRequestDataMapper::class, PosNet::class => PosNetRequestDataMapper::class, PosNetV1Pos::class => PosNetV1PosRequestDataMapper::class, - PayFlexCPV4Pos::class => PayFlexCPV4PosRequestDataMapper::class, - PayFlexV4Pos::class => PayFlexV4PosRequestDataMapper::class, + ToslaPos::class => ToslaPosRequestDataMapper::class, + VakifKatilimPos::class => VakifKatilimPosRequestDataMapper::class, ]; if (isset($classMappings[$gatewayClass])) { return new $classMappings[$gatewayClass]($eventDispatcher, $crypt, $currencies); } - throw new DomainException('unsupported gateway'); + throw new DomainException(\sprintf('Request data mapper not found for the gateway %s', $gatewayClass)); } } diff --git a/src/Factory/ResponseDataMapperFactory.php b/src/Factory/ResponseDataMapperFactory.php index 8a7f45da..141d6db9 100644 --- a/src/Factory/ResponseDataMapperFactory.php +++ b/src/Factory/ResponseDataMapperFactory.php @@ -50,19 +50,19 @@ class ResponseDataMapperFactory public static function createGatewayResponseMapper(string $gatewayClass, RequestDataMapperInterface $requestDataMapper, LoggerInterface $logger): ResponseDataMapperInterface { $classMappings = [ - ToslaPos::class => ToslaPosResponseDataMapper::class, AkbankPos::class => AkbankPosResponseDataMapper::class, - EstV3Pos::class => EstPosResponseDataMapper::class, EstPos::class => EstPosResponseDataMapper::class, + EstV3Pos::class => EstPosResponseDataMapper::class, GarantiPos::class => GarantiPosResponseDataMapper::class, InterPos::class => InterPosResponseDataMapper::class, KuveytPos::class => KuveytPosResponseDataMapper::class, - VakifKatilimPos::class => VakifKatilimPosResponseDataMapper::class, + PayFlexCPV4Pos::class => PayFlexCPV4PosResponseDataMapper::class, + PayFlexV4Pos::class => PayFlexV4PosResponseDataMapper::class, PayForPos::class => PayForPosResponseDataMapper::class, PosNet::class => PosNetResponseDataMapper::class, PosNetV1Pos::class => PosNetV1PosResponseDataMapper::class, - PayFlexV4Pos::class => PayFlexV4PosResponseDataMapper::class, - PayFlexCPV4Pos::class => PayFlexCPV4PosResponseDataMapper::class, + ToslaPos::class => ToslaPosResponseDataMapper::class, + VakifKatilimPos::class => VakifKatilimPosResponseDataMapper::class, ]; if (isset($classMappings[$gatewayClass])) { @@ -74,6 +74,6 @@ public static function createGatewayResponseMapper(string $gatewayClass, Request ); } - throw new DomainException('unsupported gateway'); + throw new DomainException(\sprintf('Response data mapper not found for the gateway %s', $gatewayClass)); } } diff --git a/src/Factory/SerializerFactory.php b/src/Factory/SerializerFactory.php index fb4d1d20..008ed86d 100644 --- a/src/Factory/SerializerFactory.php +++ b/src/Factory/SerializerFactory.php @@ -34,18 +34,18 @@ public static function createGatewaySerializer(string $gatewayClass): Serializer { /** @var SerializerInterface[] $serializers */ $serializers = [ - ToslaPosSerializer::class, AkbankPosSerializer::class, EstPosSerializer::class, GarantiPosSerializer::class, InterPosSerializer::class, KuveytPosSerializer::class, - VakifKatilimPosSerializer::class, - PayFlexV4PosSerializer::class, PayFlexCPV4PosSerializer::class, + PayFlexV4PosSerializer::class, PayForPosSerializer::class, PosNetSerializer::class, PosNetV1PosSerializer::class, + ToslaPosSerializer::class, + VakifKatilimPosSerializer::class, ]; foreach ($serializers as $serializer) { diff --git a/tests/Unit/Factory/AccountFactoryTest.php b/tests/Unit/Factory/AccountFactoryTest.php index c6172b2f..b6a46593 100644 --- a/tests/Unit/Factory/AccountFactoryTest.php +++ b/tests/Unit/Factory/AccountFactoryTest.php @@ -3,7 +3,7 @@ * @license MIT */ -namespace Factory; +namespace Mews\Pos\Tests\Unit\Factory; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\PosInterface; diff --git a/tests/Unit/Factory/CryptFactoryTest.php b/tests/Unit/Factory/CryptFactoryTest.php new file mode 100644 index 00000000..02ad7ffa --- /dev/null +++ b/tests/Unit/Factory/CryptFactoryTest.php @@ -0,0 +1,47 @@ +createMock(LoggerInterface::class); + $crypt = CryptFactory::createGatewayCrypt($gatewayClass, $logger); + $this->assertInstanceOf($serializerClass, $crypt); + } + + public static function createGatewayCryptDataProvider(): array + { + return [ + [\Mews\Pos\Gateways\AkbankPos::class, \Mews\Pos\Crypt\AkbankPosCrypt::class], + [\Mews\Pos\Gateways\EstPos::class, \Mews\Pos\Crypt\EstPosCrypt::class], + [\Mews\Pos\Gateways\EstV3Pos::class, \Mews\Pos\Crypt\EstV3PosCrypt::class], + [\Mews\Pos\Gateways\GarantiPos::class, \Mews\Pos\Crypt\GarantiPosCrypt::class], + [\Mews\Pos\Gateways\InterPos::class, \Mews\Pos\Crypt\InterPosCrypt::class], + [\Mews\Pos\Gateways\KuveytPos::class, \Mews\Pos\Crypt\KuveytPosCrypt::class], + [\Mews\Pos\Gateways\PayFlexV4Pos::class, \Mews\Pos\Crypt\NullCrypt::class], + [\Mews\Pos\Gateways\PayFlexCPV4Pos::class, \Mews\Pos\Crypt\PayFlexCPV4Crypt::class], + [\Mews\Pos\Gateways\PayForPos::class, \Mews\Pos\Crypt\PayForPosCrypt::class], + [\Mews\Pos\Gateways\PosNet::class, \Mews\Pos\Crypt\PosNetCrypt::class], + [\Mews\Pos\Gateways\PosNetV1Pos::class, \Mews\Pos\Crypt\PosNetV1PosCrypt::class], + [\Mews\Pos\Gateways\ToslaPos::class, \Mews\Pos\Crypt\ToslaPosCrypt::class], + [\Mews\Pos\Gateways\VakifKatilimPos::class, \Mews\Pos\Crypt\KuveytPosCrypt::class], + [\stdClass::class, \Mews\Pos\Crypt\NullCrypt::class], + ]; + } +} diff --git a/tests/Unit/Factory/PosFactoryTest.php b/tests/Unit/Factory/PosFactoryTest.php new file mode 100644 index 00000000..ede92a87 --- /dev/null +++ b/tests/Unit/Factory/PosFactoryTest.php @@ -0,0 +1,198 @@ +createMock(AbstractPosAccount::class); + $account->expects(self::atLeastOnce()) + ->method('getBank') + ->willReturn($configKey); + + $eventDispatcher = $this->createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); + $httpClient = $this->createMock(\Mews\Pos\Client\HttpClient::class); + $logger = $this->createMock(\Psr\Log\LoggerInterface::class); + + $gateway = PosFactory::createPosGateway( + $account, + $config, + $eventDispatcher, + $httpClient, + $logger + ); + $this->assertInstanceOf($expectedGatewayClass, $gateway); + + $this->assertSame($account, $gateway->getAccount()); + $this->assertNotEmpty($gateway->getCurrencies()); + if ($cardTypeMapping) { + $this->assertNotEmpty($gateway->getCardTypeMapping()); + } else { + $this->assertEmpty($gateway->getCardTypeMapping()); + } + } + + + public function testCreatePosGatewayWithOnlyRequiredParameters(): void + { + $gatewayClass = \Mews\Pos\Gateways\AkbankPos::class; + $config = [ + 'banks' => [ + 'akbank' => [ + 'name' => 'Akbank', + 'class' => $gatewayClass, + 'gateway_endpoints' => [ + 'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', + 'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', + 'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', + ], + ], + ], + ]; + $account = $this->createMock(AbstractPosAccount::class); + $account->expects(self::atLeastOnce()) + ->method('getBank') + ->willReturn('akbank'); + + $eventDispatcher = $this->createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); + + $gateway = PosFactory::createPosGateway( + $account, + $config, + $eventDispatcher, + ); + $this->assertInstanceOf($gatewayClass, $gateway); + } + + /** + * @dataProvider createPosGatewayDataExceptionProvider + */ + public function testCreatePosGatewayFail(array $config, string $configKey, string $expectedExceptionClass): void + { + $account = $this->createMock(AbstractPosAccount::class); + $account->expects(self::atLeastOnce()) + ->method('getBank') + ->willReturn($configKey); + + $eventDispatcher = $this->createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); + + $this->expectException($expectedExceptionClass); + PosFactory::createPosGateway( + $account, + $config, + $eventDispatcher, + ); + } + + public static function createPosGatewayDataExceptionProvider(): \Generator + { + yield 'missing_gateway_class_in_config' => [ + 'config' => [ + 'banks' => [ + 'akbank' => [ + 'name' => 'Akbank', + 'gateway_endpoints' => [ + 'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', + 'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', + 'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', + ], + ], + ], + ], + 'config_key' => 'akbank', + 'expected_exception_class' => BankClassNullException::class, + ]; + + yield 'invalid_gateway_class' => [ + 'config' => [ + 'banks' => [ + 'akbank' => [ + 'name' => 'Akbank', + 'class' => \stdClass::class, + 'gateway_endpoints' => [ + 'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', + 'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', + 'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', + ], + ], + ], + ], + 'config_key' => 'akbank', + 'expected_exception_class' => \InvalidArgumentException::class, + ]; + + yield 'non_existing_config_key' => [ + 'config' => [ + 'banks' => [ + 'estpos' => [ + 'name' => 'Akbank', + 'class' => \stdClass::class, + 'gateway_endpoints' => [ + 'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', + 'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', + 'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', + ], + ], + ], + ], + 'config_key' => 'akbank', + 'expected_exception_class' => BankNotFoundException::class, + ]; + } + + public static function createPosGatewayDataProvider(): \Generator + { + $gatewayClasses = [ + \Mews\Pos\Gateways\AkbankPos::class => false, + \Mews\Pos\Gateways\EstPos::class => false, + \Mews\Pos\Gateways\EstV3Pos::class => false, + \Mews\Pos\Gateways\GarantiPos::class => false, + \Mews\Pos\Gateways\InterPos::class => true, + \Mews\Pos\Gateways\KuveytPos::class => true, + \Mews\Pos\Gateways\PayFlexCPV4Pos::class => true, + \Mews\Pos\Gateways\PayFlexV4Pos::class => true, + \Mews\Pos\Gateways\PayForPos::class => false, + \Mews\Pos\Gateways\PosNet::class => false, + \Mews\Pos\Gateways\PosNetV1Pos::class => false, + \Mews\Pos\Gateways\ToslaPos::class => false, + \Mews\Pos\Gateways\VakifKatilimPos::class => false, + ]; + + foreach ($gatewayClasses as $gatewayClass => $cardTypeMapping) { + $configKey = 'abcdse'; + $config = [ + 'banks' => [ + $configKey => [ + 'name' => 'Akbank', + 'class' => $gatewayClass, + 'gateway_endpoints' => [ + 'payment_api' => 'https://apipre.akbank.com/api/v1/payment/virtualpos', + 'gateway_3d' => 'https://virtualpospaymentgatewaypre.akbank.com/securepay', + 'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', + ], + ], + ], + ]; + yield [ + $config, + $configKey, + $cardTypeMapping, + $gatewayClass, + ]; + } + } +} diff --git a/tests/Unit/Factory/RequestDataMapperFactoryTest.php b/tests/Unit/Factory/RequestDataMapperFactoryTest.php new file mode 100644 index 00000000..00219bf0 --- /dev/null +++ b/tests/Unit/Factory/RequestDataMapperFactoryTest.php @@ -0,0 +1,65 @@ +createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); + $crypt = $this->createMock(\Mews\Pos\Crypt\CryptInterface::class); + $currencies = []; + $mapper = RequestDataMapperFactory::createGatewayRequestMapper( + $gatewayClass, + $eventDispatcher, + $crypt, + $currencies + ); + $this->assertInstanceOf($mapperClass, $mapper); + } + + public function testCreateGatewayRequestMapperUnsupported(): void + { + $eventDispatcher = $this->createMock(\Psr\EventDispatcher\EventDispatcherInterface::class); + $crypt = $this->createMock(\Mews\Pos\Crypt\CryptInterface::class); + $currencies = []; + $this->expectException(\DomainException::class); + RequestDataMapperFactory::createGatewayRequestMapper( + \stdClass::class, + $eventDispatcher, + $crypt, + $currencies + ); + } + + public static function createGatewayRequestMapperDataProvider(): array + { + return [ + [\Mews\Pos\Gateways\AkbankPos::class, \Mews\Pos\DataMapper\RequestDataMapper\AkbankPosRequestDataMapper::class], + [\Mews\Pos\Gateways\EstPos::class, \Mews\Pos\DataMapper\RequestDataMapper\EstPosRequestDataMapper::class], + [\Mews\Pos\Gateways\EstV3Pos::class, \Mews\Pos\DataMapper\RequestDataMapper\EstV3PosRequestDataMapper::class], + [\Mews\Pos\Gateways\GarantiPos::class, \Mews\Pos\DataMapper\RequestDataMapper\GarantiPosRequestDataMapper::class], + [\Mews\Pos\Gateways\InterPos::class, \Mews\Pos\DataMapper\RequestDataMapper\InterPosRequestDataMapper::class], + [\Mews\Pos\Gateways\KuveytPos::class, \Mews\Pos\DataMapper\RequestDataMapper\KuveytPosRequestDataMapper::class], + [\Mews\Pos\Gateways\PayFlexCPV4Pos::class, \Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper::class], + [\Mews\Pos\Gateways\PayForPos::class, \Mews\Pos\DataMapper\RequestDataMapper\PayForPosRequestDataMapper::class], + [\Mews\Pos\Gateways\PosNet::class, \Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper::class], + [\Mews\Pos\Gateways\PosNetV1Pos::class, \Mews\Pos\DataMapper\RequestDataMapper\PosNetV1PosRequestDataMapper::class], + [\Mews\Pos\Gateways\ToslaPos::class, \Mews\Pos\DataMapper\RequestDataMapper\ToslaPosRequestDataMapper::class], + [\Mews\Pos\Gateways\VakifKatilimPos::class, \Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper::class], + ]; + } +} diff --git a/tests/Unit/Factory/ResponseDataMapperFactoryTest.php b/tests/Unit/Factory/ResponseDataMapperFactoryTest.php new file mode 100644 index 00000000..2294ac0c --- /dev/null +++ b/tests/Unit/Factory/ResponseDataMapperFactoryTest.php @@ -0,0 +1,64 @@ +createMock(RequestDataMapperInterface::class); + $logger = $this->createMock(LoggerInterface::class); + $mapper = ResponseDataMapperFactory::createGatewayResponseMapper( + $gatewayClass, + $requestDataMapper, + $logger + ); + $this->assertInstanceOf($mapperClass, $mapper); + } + + public function testCreateGatewayResponseMapperUnsupported(): void + { + $requestDataMapper = $this->createMock(RequestDataMapperInterface::class); + $logger = $this->createMock(LoggerInterface::class); + $this->expectException(\DomainException::class); + ResponseDataMapperFactory::createGatewayResponseMapper( + \stdClass::class, + $requestDataMapper, + $logger + ); + } + + public static function createGatewayResponseMapperDataProvider(): array + { + return [ + [\Mews\Pos\Gateways\AkbankPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\AkbankPosResponseDataMapper::class], + [\Mews\Pos\Gateways\EstPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper::class], + [\Mews\Pos\Gateways\EstV3Pos::class, \Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper::class], + [\Mews\Pos\Gateways\GarantiPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper::class], + [\Mews\Pos\Gateways\InterPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\InterPosResponseDataMapper::class], + [\Mews\Pos\Gateways\KuveytPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\KuveytPosResponseDataMapper::class], + [\Mews\Pos\Gateways\PayFlexCPV4Pos::class, \Mews\Pos\DataMapper\ResponseDataMapper\PayFlexCPV4PosResponseDataMapper::class], + [\Mews\Pos\Gateways\PayFlexV4Pos::class, \Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper::class], + [\Mews\Pos\Gateways\PayForPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\PayForPosResponseDataMapper::class], + [\Mews\Pos\Gateways\PosNet::class, \Mews\Pos\DataMapper\ResponseDataMapper\PosNetResponseDataMapper::class], + [\Mews\Pos\Gateways\PosNetV1Pos::class, \Mews\Pos\DataMapper\ResponseDataMapper\PosNetV1PosResponseDataMapper::class], + [\Mews\Pos\Gateways\ToslaPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\ToslaPosResponseDataMapper::class], + [\Mews\Pos\Gateways\VakifKatilimPos::class, \Mews\Pos\DataMapper\ResponseDataMapper\VakifKatilimPosResponseDataMapper::class], + ]; + } +} diff --git a/tests/Unit/Factory/SerializerFactoryTest.php b/tests/Unit/Factory/SerializerFactoryTest.php new file mode 100644 index 00000000..ba8a3897 --- /dev/null +++ b/tests/Unit/Factory/SerializerFactoryTest.php @@ -0,0 +1,50 @@ +assertInstanceOf($serializerClass, $serializer); + } + + public function testCreateGatewaySerializerUnsupported(): void + { + $this->expectException(\DomainException::class); + SerializerFactory::createGatewaySerializer(\stdClass::class); + } + + public function createGatewaySerializerDataProvider(): array + { + return [ + [\Mews\Pos\Gateways\AkbankPos::class, \Mews\Pos\Serializer\AkbankPosSerializer::class], + [\Mews\Pos\Gateways\EstPos::class, \Mews\Pos\Serializer\EstPosSerializer::class], + [\Mews\Pos\Gateways\EstV3Pos::class, \Mews\Pos\Serializer\EstPosSerializer::class], + [\Mews\Pos\Gateways\GarantiPos::class, \Mews\Pos\Serializer\GarantiPosSerializer::class], + [\Mews\Pos\Gateways\InterPos::class, \Mews\Pos\Serializer\InterPosSerializer::class], + [\Mews\Pos\Gateways\KuveytPos::class, \Mews\Pos\Serializer\KuveytPosSerializer::class], + [\Mews\Pos\Gateways\PayFlexCPV4Pos::class, \Mews\Pos\Serializer\PayFlexCPV4PosSerializer::class], + [\Mews\Pos\Gateways\PayFlexV4Pos::class, \Mews\Pos\Serializer\PayFlexV4PosSerializer::class], + [\Mews\Pos\Gateways\PayForPos::class, \Mews\Pos\Serializer\PayForPosSerializer::class], + [\Mews\Pos\Gateways\PosNet::class, \Mews\Pos\Serializer\PosNetSerializer::class], + [\Mews\Pos\Gateways\PosNetV1Pos::class, \Mews\Pos\Serializer\PosNetV1PosSerializer::class], + [\Mews\Pos\Gateways\ToslaPos::class, \Mews\Pos\Serializer\ToslaPosSerializer::class], + [\Mews\Pos\Gateways\VakifKatilimPos::class, \Mews\Pos\Serializer\VakifKatilimPosSerializer::class], + ]; + } +}