diff --git a/docs/THREED-PAYMENT-EXAMPLE.md b/docs/THREED-PAYMENT-EXAMPLE.md index a4fdfb98..2403f61e 100644 --- a/docs/THREED-PAYMENT-EXAMPLE.md +++ b/docs/THREED-PAYMENT-EXAMPLE.md @@ -221,6 +221,12 @@ try { $transactionType, $card ); +} catch (\InvalidArgumentException $e) { + // örneğin kart bilgisi sağlanmadığında bu exception'i alırsınız. + var_dump($e); +} catch (\LogicException $e) { + // ödeme modeli veya işlem tipi desteklenmiyorsa bu exception'i alırsınız. + var_dump($e); } catch (\Exception|\Error $e) { var_dump($e); exit; diff --git a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md index c6132bbb..794ef57f 100644 --- a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md +++ b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md @@ -143,6 +143,12 @@ try { $transactionType, $card ); +} catch (\InvalidArgumentException $e) { + // örneğin kart bilgisi sağlanmadığında bu exception'i alırsınız. + var_dump($e); +} catch (\LogicException $e) { + // ödeme modeli veya işlem tipi desteklenmiyorsa bu exception'i alırsınız. + var_dump($e); } catch (\Throwable $e) { var_dump($e); exit; diff --git a/examples/_common-codes/3d-host/index.php b/examples/_common-codes/3d-host/index.php index e288e639..6e25bfdb 100644 --- a/examples/_common-codes/3d-host/index.php +++ b/examples/_common-codes/3d-host/index.php @@ -67,6 +67,9 @@ try { $formData = $pos->get3DFormData($order, PosInterface::MODEL_3D_HOST, $transaction); +} catch (\LogicException $e) { + // ödeme modeli veya işlem tipi desteklenmiyorsa bu exception'i alırsınız. + dd($e); } catch (\Exception $e) { dd($e); } diff --git a/examples/_common-codes/3d/form.php b/examples/_common-codes/3d/form.php index fecadd2b..ebe5b7b3 100644 --- a/examples/_common-codes/3d/form.php +++ b/examples/_common-codes/3d/form.php @@ -165,6 +165,12 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void { try { $formData = $pos->get3DFormData($order, $paymentModel, $transaction, $card); //dd($formData); +} catch (\InvalidArgumentException $e) { + // örneğin kart bilgisi sağlanmadığında bu exception'i alırsınız. + dd($e); +} catch (\LogicException $e) { + // ödeme modeli veya işlem tipi desteklenmiyorsa bu exception'i alırsınız. + dd($e); } catch (\Throwable $e) { dd($e); } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ccd9bdfb..d64abbe3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -165,6 +165,11 @@ parameters: count: 1 path: src/Gateways/PayFlexCPV4Pos.php + - + message: "#^Parameter \\#2 \\$creditCard of method Mews\\\\Pos\\\\Gateways\\\\PayFlexV4Pos\\:\\:sendEnrollmentRequest\\(\\) expects Mews\\\\Pos\\\\Entity\\\\Card\\\\CreditCardInterface, Mews\\\\Pos\\\\Entity\\\\Card\\\\CreditCardInterface\\|null given\\.$#" + count: 1 + path: src/Gateways/PayFlexV4Pos.php + - message: "#^Method Mews\\\\Pos\\\\Gateways\\\\PosNet\\:\\:getOosTransactionData\\(\\) should return array\\{approved\\: string, respCode\\: string, respText\\: string, oosRequestDataResponse\\?\\: array\\{data1\\: string, data2\\: string, sign\\: string\\}\\} but returns array\\\\.$#" count: 1 @@ -174,3 +179,8 @@ parameters: message: "#^Offset 'oosRequestDataRespo…' does not exist on array\\{approved\\: string, respCode\\: string, respText\\: string, oosRequestDataResponse\\?\\: array\\{data1\\: string, data2\\: string, sign\\: string\\}\\}\\.$#" count: 1 path: src/Gateways/PosNet.php + + - + message: "#^Parameter \\#4 \\$creditCard of method Mews\\\\Pos\\\\Gateways\\\\PosNet\\:\\:getOosTransactionData\\(\\) expects Mews\\\\Pos\\\\Entity\\\\Card\\\\CreditCardInterface, Mews\\\\Pos\\\\Entity\\\\Card\\\\CreditCardInterface\\|null given\\.$#" + count: 1 + path: src/Gateways/PosNet.php diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index c5427ed7..1d09dad3 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -642,4 +642,22 @@ protected function is3DAuthSuccess(array $responseData): bool return false; } + + /** + * @param PosInterface::MODEL_3D_* $paymentModel + * @param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType + * @param CreditCardInterface|null $card + * + * @throws \InvalidArgumentException when inputs are not valid + */ + protected function check3DFormInputs(string $paymentModel, string $txType, CreditCardInterface $card = null): void + { + if (!self::isSupportedTransaction($txType, $paymentModel)) { + throw new \LogicException('Bu banka altyapısı sağlanan ödeme modelini ya da işlem tipini desteklenmiyor.'); + } + + if ((PosInterface::MODEL_3D_SECURE === $paymentModel || PosInterface::MODEL_3D_PAY === $paymentModel) && null === $card) { + throw new \InvalidArgumentException('Bu ödeme modeli için kart bilgileri zorunlu!'); + } + } } diff --git a/src/Gateways/AkbankPos.php b/src/Gateways/AkbankPos.php index 26c783b3..c7d230a0 100644 --- a/src/Gateways/AkbankPos.php +++ b/src/Gateways/AkbankPos.php @@ -160,6 +160,8 @@ public function make3DHostPayment(Request $request, array $order, string $txType */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + $this->logger->debug('preparing 3D form data'); $gatewayUrl = PosInterface::MODEL_3D_HOST === $paymentModel ? $this->get3DHostGatewayURL() : $this->get3DGatewayURL(); diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index d61cb387..2289d7bf 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -157,6 +157,8 @@ public function make3DHostPayment(Request $request, array $order, string $txType */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + $this->logger->debug('preparing 3D form data'); return $this->requestDataMapper->create3DFormData($this->account, $order, $paymentModel, $txType, $this->get3DGatewayURL(), $creditCard); diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 2d1766d6..16edfd69 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -127,6 +127,8 @@ public function make3DPayPayment(Request $request, array $order, string $txType) */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + $this->logger->debug('preparing 3D form data'); return $this->requestDataMapper->create3DFormData($this->account, $order, $paymentModel, $txType, $this->get3DGatewayURL(), $creditCard); diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index 625d86e7..2fc7895b 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -161,14 +161,12 @@ public function orderHistory(array $order): PosInterface */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { - $gatewayUrl = $this->get3DHostGatewayURL(); - - if (PosInterface::MODEL_3D_SECURE === $paymentModel || PosInterface::MODEL_3D_PAY === $paymentModel) { - $gatewayUrl = $this->get3DGatewayURL(); - } + $this->check3DFormInputs($paymentModel, $txType, $creditCard); $this->logger->debug('preparing 3D form data'); + $gatewayUrl = PosInterface::MODEL_3D_HOST === $paymentModel ? $this->get3DHostGatewayURL() : $this->get3DGatewayURL(); + return $this->requestDataMapper->create3DFormData($this->account, $order, $paymentModel, $txType, $gatewayUrl, $creditCard); } diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index df5ea019..bb94fd72 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -134,7 +134,10 @@ public function orderHistory(array $order): PosInterface */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + $gatewayUrl = $this->get3DGatewayURL(); + $this->logger->debug('preparing 3D form data'); return $this->getCommon3DFormData($this->account, $order, $paymentModel, $txType, $gatewayUrl, $creditCard); diff --git a/src/Gateways/PayFlexCPV4Pos.php b/src/Gateways/PayFlexCPV4Pos.php index 0d1e896d..c8f08dd0 100644 --- a/src/Gateways/PayFlexCPV4Pos.php +++ b/src/Gateways/PayFlexCPV4Pos.php @@ -176,6 +176,8 @@ public function orderHistory(array $order): PosInterface */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + /** @var array{CommonPaymentUrl: string|null, PaymentToken: string|null, ErrorCode: string|null, ResponseMessage: string|null} $data */ $data = $this->registerPayment($order, $txType, $paymentModel, $creditCard); diff --git a/src/Gateways/PayFlexV4Pos.php b/src/Gateways/PayFlexV4Pos.php index 1b0ec579..d9c9b9d6 100644 --- a/src/Gateways/PayFlexV4Pos.php +++ b/src/Gateways/PayFlexV4Pos.php @@ -5,7 +5,6 @@ namespace Mews\Pos\Gateways; use Exception; -use LogicException; use Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper; use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface; use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper; @@ -159,9 +158,7 @@ public function orderHistory(array $order): PosInterface */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { - if (!$creditCard instanceof CreditCardInterface) { - throw new LogicException('Kredi kartı bilgileri eksik!'); - } + $this->check3DFormInputs($paymentModel, $txType, $creditCard); $data = $this->sendEnrollmentRequest($order, $creditCard, $txType, $paymentModel); diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index aebf2d6b..205d2abb 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -168,12 +168,11 @@ public function orderHistory(array $order): PosInterface */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + $this->logger->debug('preparing 3D form data'); - $gatewayURL = $this->get3DGatewayURL(); - if (PosInterface::MODEL_3D_HOST === $paymentModel) { - $gatewayURL = $this->get3DHostGatewayURL(); - } + $gatewayURL = PosInterface::MODEL_3D_HOST === $paymentModel ? $this->get3DHostGatewayURL() : $this->get3DGatewayURL(); return $this->requestDataMapper->create3DFormData($this->account, $order, $paymentModel, $txType, $gatewayURL, $creditCard); } diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index ac0c8954..290b1ef9 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -6,7 +6,6 @@ namespace Mews\Pos\Gateways; use InvalidArgumentException; -use LogicException; use Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper; use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface; use Mews\Pos\DataMapper\ResponseDataMapper\PosNetResponseDataMapper; @@ -167,9 +166,7 @@ public function make3DHostPayment(Request $request, array $order, string $txType */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { - if (!$creditCard instanceof CreditCardInterface) { - throw new LogicException('Kredi kartı veya sipariş bilgileri eksik!'); - } + $this->check3DFormInputs($paymentModel, $txType, $creditCard); $data = $this->getOosTransactionData($order, $txType, $paymentModel, $creditCard); @@ -180,7 +177,15 @@ public function get3DFormData(array $order, string $paymentModel, string $txType $this->logger->debug('preparing 3D form data'); - return $this->requestDataMapper->create3DFormData($this->account, $order, $paymentModel, $txType, $this->get3DGatewayURL(), null, $data['oosRequestDataResponse']); + return $this->requestDataMapper->create3DFormData( + $this->account, + $order, + $paymentModel, + $txType, + $this->get3DGatewayURL(), + null, + $data['oosRequestDataResponse'] + ); } /** @return PosNetAccount */ diff --git a/src/Gateways/PosNetV1Pos.php b/src/Gateways/PosNetV1Pos.php index ea61a498..32517453 100644 --- a/src/Gateways/PosNetV1Pos.php +++ b/src/Gateways/PosNetV1Pos.php @@ -148,6 +148,8 @@ public function make3DHostPayment(Request $request, array $order, string $txType */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + $this->logger->debug('preparing 3D form data'); return $this->requestDataMapper->create3DFormData($this->account, $order, $paymentModel, $txType, $this->get3DGatewayURL(), $creditCard); diff --git a/src/Gateways/ToslaPos.php b/src/Gateways/ToslaPos.php index a480bb0a..eacc6822 100644 --- a/src/Gateways/ToslaPos.php +++ b/src/Gateways/ToslaPos.php @@ -139,9 +139,7 @@ public function make3DHostPayment(Request $request, array $order, string $txType */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { - if (PosInterface::MODEL_3D_HOST !== $paymentModel && !$creditCard instanceof CreditCardInterface) { - throw new \LogicException('Kredi kart bilgileri eksik!'); - } + $this->check3DFormInputs($paymentModel, $txType, $creditCard); $data = $this->registerPayment($order, $paymentModel, $txType); diff --git a/src/Gateways/VakifKatilimPos.php b/src/Gateways/VakifKatilimPos.php index 483b1621..f4e7a789 100644 --- a/src/Gateways/VakifKatilimPos.php +++ b/src/Gateways/VakifKatilimPos.php @@ -101,6 +101,8 @@ public function make3DHostPayment(Request $request, array $order, string $txType */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { + $this->check3DFormInputs($paymentModel, $txType, $creditCard); + $this->logger->debug('preparing 3D form data'); if (PosInterface::MODEL_3D_HOST === $paymentModel) { diff --git a/src/PosInterface.php b/src/PosInterface.php index 9ee6a2e2..11a67797 100644 --- a/src/PosInterface.php +++ b/src/PosInterface.php @@ -111,7 +111,7 @@ interface PosInterface /** * returns form data, key values, necessary for 3D payment * - * @phpstan-param PosInterface::MODEL_3D_* $paymentModel + * @phpstan-param PosInterface::MODEL_3D_* $paymentModel * @phpstan-param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType * * @param array $order @@ -122,7 +122,9 @@ interface PosInterface * @return array{gateway: string, method: 'POST'|'GET', inputs: array} * * @throws \RuntimeException when request to the bank to get 3D form data failed - * @throws \LogicException when card data is not provided when it is required for the given payment model + * @throws ClientExceptionInterface when request to the bank to get 3D form data failed + * @throws \InvalidArgumentException when card data is not provided when it is required for the given payment model + * @throws \LogicException when given payment model or transaction type is not supported * @throws UnsupportedTransactionTypeException * @throws ClientExceptionInterface */ diff --git a/tests/Unit/Gateways/AkbankPosTest.php b/tests/Unit/Gateways/AkbankPosTest.php index dd73cafe..c7ec7853 100644 --- a/tests/Unit/Gateways/AkbankPosTest.php +++ b/tests/Unit/Gateways/AkbankPosTest.php @@ -396,6 +396,24 @@ public function testGet3DFormData( $this->assertSame($actual, $formData); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @dataProvider historyRequestDataProvider */ @@ -849,6 +867,33 @@ public static function orderHistoryDataProvider(): iterable ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + '3d_pay_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY_HOSTING, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + public static function threeDFormDataProvider(): iterable { yield '3d_host' => [ diff --git a/tests/Unit/Gateways/EstPosTest.php b/tests/Unit/Gateways/EstPosTest.php index 68f373f5..e98c119a 100644 --- a/tests/Unit/Gateways/EstPosTest.php +++ b/tests/Unit/Gateways/EstPosTest.php @@ -178,6 +178,24 @@ public function testGet3DFormData( $this->assertSame(['formData'], $actual); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @return void */ @@ -805,6 +823,26 @@ public static function cancelRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + '3d_pay_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/GarantiPosTest.php b/tests/Unit/Gateways/GarantiPosTest.php index f35d6998..8e926071 100644 --- a/tests/Unit/Gateways/GarantiPosTest.php +++ b/tests/Unit/Gateways/GarantiPosTest.php @@ -167,6 +167,24 @@ public function testGet3DFormData( $this->assertSame(['formData'], $actual); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @dataProvider make3DPaymentDataProvider */ @@ -720,6 +738,33 @@ public static function orderHistoryRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + '3d_pay_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_HOST, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/InterPosTest.php b/tests/Unit/Gateways/InterPosTest.php index faf79179..022ac664 100644 --- a/tests/Unit/Gateways/InterPosTest.php +++ b/tests/Unit/Gateways/InterPosTest.php @@ -176,6 +176,24 @@ public function testGet3DFormData( $this->assertSame(['formData'], $actual); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @dataProvider make3DPaymentDataProvider */ @@ -661,6 +679,33 @@ public static function refundRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + '3d_pay_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY_HOSTING, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/KuveytPosTest.php b/tests/Unit/Gateways/KuveytPosTest.php index 7e1eeaa9..4f44dd84 100644 --- a/tests/Unit/Gateways/KuveytPosTest.php +++ b/tests/Unit/Gateways/KuveytPosTest.php @@ -235,6 +235,24 @@ public function testGetCommon3DFormDataSuccessResponse(): void $this->assertSame(['3d-form-data'], $result); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @dataProvider make3DPaymentDataProvider */ @@ -578,6 +596,33 @@ public static function getApiUrlExceptionDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_HOST, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + 'unsupported_tx' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/PayFlexCPV4PosTest.php b/tests/Unit/Gateways/PayFlexCPV4PosTest.php index d8b1a489..06d17d19 100644 --- a/tests/Unit/Gateways/PayFlexCPV4PosTest.php +++ b/tests/Unit/Gateways/PayFlexCPV4PosTest.php @@ -248,6 +248,24 @@ public function testGet3DFormDataEnrollmentFail(): void $this->pos->get3DFormData($order, $paymentModel, $txType, $card); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + public function testMake3DPayment(): void { $request = Request::create('', 'POST'); @@ -621,6 +639,26 @@ public static function refundRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_pay_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/PayFlexV4PosTest.php b/tests/Unit/Gateways/PayFlexV4PosTest.php index 0550a64e..31c0a01c 100644 --- a/tests/Unit/Gateways/PayFlexV4PosTest.php +++ b/tests/Unit/Gateways/PayFlexV4PosTest.php @@ -184,19 +184,22 @@ public function testGet3DFormDataEnrollmentFail(array $response): void $this->pos->get3DFormData($order, PosInterface::MODEL_3D_SECURE, $txType, $this->card); } - public function testGet3DFormDataWithoutCard(): void + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void { - $this->requestMapperMock->expects(self::never()) - ->method('create3DEnrollmentCheckRequestData'); + $card = $isWithCard ? $this->card : null; - $this->httpClientMock->expects(self::never()) - ->method('post'); - - $this->requestMapperMock->expects(self::never()) - ->method('create3DFormData'); + $this->expectException($expectedExceptionClass); - $this->expectException(\LogicException::class); - $this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH); + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); } /** @@ -697,6 +700,26 @@ public static function make3DPaymentDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/PayForTest.php b/tests/Unit/Gateways/PayForTest.php index 31999ba3..5c76a49e 100644 --- a/tests/Unit/Gateways/PayForTest.php +++ b/tests/Unit/Gateways/PayForTest.php @@ -180,6 +180,24 @@ public function testGet3DFormData( $this->assertSame(['formData'], $actual); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @dataProvider make3DPaymentDataProvider */ @@ -766,6 +784,33 @@ public static function orderHistoryRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + '3d_pay_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY_HOSTING, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/PosNetTest.php b/tests/Unit/Gateways/PosNetTest.php index 377f2577..5e6592de 100644 --- a/tests/Unit/Gateways/PosNetTest.php +++ b/tests/Unit/Gateways/PosNetTest.php @@ -183,19 +183,22 @@ public function testGet3DFormDataOosTransactionFail(): void $this->pos->get3DFormData($order, PosInterface::MODEL_3D_SECURE, $txType, $this->card); } - public function testGet3DFormDataWithoutCard(): void + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void { - $this->requestMapperMock->expects(self::never()) - ->method('create3DEnrollmentCheckRequestData'); + $card = $isWithCard ? $this->card : null; - $this->httpClientMock->expects(self::never()) - ->method('post'); - - $this->requestMapperMock->expects(self::never()) - ->method('create3DFormData'); + $this->expectException($expectedExceptionClass); - $this->expectException(\LogicException::class); - $this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH); + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); } /** @@ -810,6 +813,26 @@ public static function refundRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_HOST, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/PosNetV1PosTest.php b/tests/Unit/Gateways/PosNetV1PosTest.php index 14941f59..82d21d44 100644 --- a/tests/Unit/Gateways/PosNetV1PosTest.php +++ b/tests/Unit/Gateways/PosNetV1PosTest.php @@ -180,6 +180,24 @@ public function testGet3DFormData( $this->assertSame(['formData'], $actual); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @dataProvider make3DPaymentDataProvider */ @@ -693,6 +711,26 @@ public static function refundRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_HOST, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/ToslaPosTest.php b/tests/Unit/Gateways/ToslaPosTest.php index 72b2c4c5..e1da675a 100644 --- a/tests/Unit/Gateways/ToslaPosTest.php +++ b/tests/Unit/Gateways/ToslaPosTest.php @@ -344,19 +344,22 @@ public function testGet3DFormData( $this->assertSame($actual, $formData); } - public function testGet3DFormDataWithoutCard(): void + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void { - $this->requestMapperMock->expects(self::never()) - ->method('create3DEnrollmentCheckRequestData'); + $card = $isWithCard ? $this->card : null; - $this->httpClientMock->expects(self::never()) - ->method('post'); + $this->expectException($expectedExceptionClass); - $this->requestMapperMock->expects(self::never()) - ->method('create3DFormData'); - - $this->expectException(\LogicException::class); - $this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH); + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); } /** @@ -1073,6 +1076,26 @@ public static function registerFailResponseDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_pay_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl, diff --git a/tests/Unit/Gateways/VakifKatilimTest.php b/tests/Unit/Gateways/VakifKatilimTest.php index 85127897..2d3c8812 100644 --- a/tests/Unit/Gateways/VakifKatilimTest.php +++ b/tests/Unit/Gateways/VakifKatilimTest.php @@ -246,6 +246,24 @@ public function testGet3DHostFormData(): void $this->assertSame(['formData'], $actual); } + /** + * @dataProvider threeDFormDataBadInputsProvider + */ + public function testGet3DFormDataWithBadInputs( + array $order, + string $paymentModel, + string $txType, + bool $isWithCard, + string $expectedExceptionClass + ): void + { + $card = $isWithCard ? $this->card : null; + + $this->expectException($expectedExceptionClass); + + $this->pos->get3DFormData($order, $paymentModel, $txType, $card); + } + /** * @dataProvider make3DPaymentDataProvider */ @@ -887,6 +905,40 @@ public static function orderHistoryRequestDataProvider(): array ]; } + public static function threeDFormDataBadInputsProvider(): array + { + return [ + '3d_secure_without_card' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \InvalidArgumentException::class, + ], + 'unsupported_payment_model' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_PAY, + 'txType' => PosInterface::TX_TYPE_PAY_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + 'unsupported_3d_secure_tx' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_SECURE, + 'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + 'unsupported_3d_host_tx' => [ + 'order' => ['id' => '2020110828BC'], + 'paymentModel' => PosInterface::MODEL_3D_HOST, + 'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, + 'isWithCard' => false, + 'expectedExceptionClass' => \LogicException::class, + ], + ]; + } + private function configureClientResponse( string $txType, string $apiUrl,