Skip to content

Commit

Permalink
feat: get3DFormData support for form data generation without card.
Browse files Browse the repository at this point in the history
default value of $createWithoutCard is set to true for backward compatibility. In the next major version it will be false.
These changes are fix to backward compatibility break on commit ec4e461
  • Loading branch information
mustapayev committed Dec 24, 2024
1 parent 4eca22c commit 1f460d3
Show file tree
Hide file tree
Showing 29 changed files with 94 additions and 48 deletions.
3 changes: 2 additions & 1 deletion docs/PRE-AUTH-POST-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ try {
$order,
$paymentModel,
$transactionType,
$card
$card,
false
);
} catch (\Exception|\Error $e) {
var_dump($e);
Expand Down
3 changes: 2 additions & 1 deletion docs/THREED-PAYMENT-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ try {
$order,
$paymentModel,
$transactionType,
$card
$card,
false
);
} catch (\InvalidArgumentException $e) {
// örneğin kart bilgisi sağlanmadığında bu exception'i alırsınız.
Expand Down
3 changes: 2 additions & 1 deletion docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ try {
$order,
$paymentModel,
$transactionType,
$card
$card,
false
);
} catch (\InvalidArgumentException $e) {
// örneğin kart bilgisi sağlanmadığında bu exception'i alırsınız.
Expand Down
2 changes: 1 addition & 1 deletion examples/_common-codes/3d/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
// ============================================================================================

try {
$formData = $pos->get3DFormData($order, $paymentModel, $transaction, $card);
$formData = $pos->get3DFormData($order, $paymentModel, $transaction, $card, false);
//dd($formData);
} catch (\InvalidArgumentException $e) {
// örneğin kart bilgisi sağlanmadığında bu exception'i alırsınız.
Expand Down
7 changes: 6 additions & 1 deletion src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,15 +655,20 @@ protected function is3DAuthSuccess(array $responseData): bool
* @param PosInterface::MODEL_3D_* $paymentModel
* @param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType
* @param CreditCardInterface|null $card
* @param bool $createWithoutCard
*
* @throws \InvalidArgumentException when inputs are not valid
*/
protected function check3DFormInputs(string $paymentModel, string $txType, CreditCardInterface $card = null): void
protected function check3DFormInputs(string $paymentModel, string $txType, CreditCardInterface $card = null, bool $createWithoutCard = false): void
{
if (!self::isSupportedTransaction($txType, $paymentModel)) {
throw new \LogicException('Bu banka altyapısı sağlanan ödeme modelini ya da işlem tipini desteklenmiyor.');
}

if ($createWithoutCard) {
return;
}

if ((PosInterface::MODEL_3D_SECURE === $paymentModel || PosInterface::MODEL_3D_PAY === $paymentModel)
&& !$card instanceof \Mews\Pos\Entity\Card\CreditCardInterface) {
throw new \InvalidArgumentException('Bu ödeme modeli için kart bilgileri zorunlu!');
Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/AkbankPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ public function make3DHostPayment(Request $request, array $order, string $txType
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/EstPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ public function make3DHostPayment(Request $request, array $order, string $txType
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/GarantiPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ public function make3DPayPayment(Request $request, array $order, string $txType)
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/InterPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ public function orderHistory(array $order): PosInterface
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/KuveytPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public function orderHistory(array $order): PosInterface
*
* @throws SoapFault
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/PayFlexCPV4Pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ public function orderHistory(array $order): PosInterface
/**
* {@inheritDoc}
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

/** @var array{CommonPaymentUrl: string|null, PaymentToken: string|null, ErrorCode: string|null, ResponseMessage: string|null} $data */
$data = $this->registerPayment($order, $txType, $paymentModel, $creditCard);
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/PayFlexV4Pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function orderHistory(array $order): PosInterface
/**
* {@inheritDoc}
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/PayForPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public function orderHistory(array $order): PosInterface
/**
* {@inheritDoc}
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/PosNet.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function make3DHostPayment(Request $request, array $order, string $txType
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/PosNetV1Pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public function make3DHostPayment(Request $request, array $order, string $txType
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/ToslaPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public function make3DHostPayment(Request $request, array $order, string $txType
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$data = $this->registerPayment($order, $paymentModel, $txType);

Expand Down
4 changes: 2 additions & 2 deletions src/Gateways/VakifKatilimPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public function make3DHostPayment(Request $request, array $order, string $txType
/**
* @inheritDoc
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array
public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array
{
$this->check3DFormInputs($paymentModel, $txType, $creditCard);
$this->check3DFormInputs($paymentModel, $txType, $creditCard, $createWithoutCard);

$this->logger->debug('preparing 3D form data');

Expand Down
3 changes: 2 additions & 1 deletion src/PosInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ interface PosInterface
* @param string $paymentModel
* @param string $txType
* @param CreditCardInterface|null $creditCard
* @param bool $createWithoutCard 3D ve 3D_PAY ödemelerde kart bilgisi olmadan 3D formu oluşturulmasına izin verir.
*
* @return array{gateway: string, method: 'POST'|'GET', inputs: array<string, string>}
*
Expand All @@ -128,7 +129,7 @@ interface PosInterface
* @throws UnsupportedTransactionTypeException
* @throws ClientExceptionInterface
*/
public function get3DFormData(array $order, string $paymentModel, string $txType, ?CreditCardInterface $creditCard = null): array;
public function get3DFormData(array $order, string $paymentModel, string $txType, ?CreditCardInterface $creditCard = null, bool $createWithoutCard = true): array;

/**
* Regular Payment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class AkbankPosRequestDataMapperTest extends TestCase

private array $order;

/** @var MockObject|EventDispatcherInterface */
private EventDispatcherInterface $dispatcher;

protected function setUp(): void
Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/Gateways/AkbankPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,15 @@ public function testGet3DFormDataWithBadInputs(
string $paymentModel,
string $txType,
bool $isWithCard,
bool $createWithoutCard,
string $expectedExceptionClass
): void
{
$card = $isWithCard ? $this->card : null;

$this->expectException($expectedExceptionClass);

$this->pos->get3DFormData($order, $paymentModel, $txType, $card);
$this->pos->get3DFormData($order, $paymentModel, $txType, $card, $createWithoutCard);
}

/**
Expand Down Expand Up @@ -875,20 +876,23 @@ public static function threeDFormDataBadInputsProvider(): array
'paymentModel' => PosInterface::MODEL_3D_SECURE,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => false,
'expectedExceptionClass' => \InvalidArgumentException::class,
],
'3d_pay_without_card' => [
'order' => ['id' => '2020110828BC'],
'paymentModel' => PosInterface::MODEL_3D_PAY,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => false,
'expectedExceptionClass' => \InvalidArgumentException::class,
],
'unsupported_payment_model' => [
'order' => ['id' => '2020110828BC'],
'paymentModel' => PosInterface::MODEL_3D_PAY_HOSTING,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => true,
'expectedExceptionClass' => \LogicException::class,
],
];
Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/Gateways/EstPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ public function testGet3DFormDataWithBadInputs(
string $paymentModel,
string $txType,
bool $isWithCard,
bool $createWithoutCard,
string $expectedExceptionClass
): void
{
$card = $isWithCard ? $this->card : null;

$this->expectException($expectedExceptionClass);

$this->pos->get3DFormData($order, $paymentModel, $txType, $card);
$this->pos->get3DFormData($order, $paymentModel, $txType, $card, $createWithoutCard);
}

/**
Expand Down Expand Up @@ -831,13 +832,15 @@ public static function threeDFormDataBadInputsProvider(): array
'paymentModel' => PosInterface::MODEL_3D_SECURE,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => false,
'expectedExceptionClass' => \InvalidArgumentException::class,
],
'3d_pay_without_card' => [
'order' => ['id' => '2020110828BC'],
'paymentModel' => PosInterface::MODEL_3D_PAY,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => false,
'expectedExceptionClass' => \InvalidArgumentException::class,
],
];
Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Gateways/GarantiPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,15 @@ public function testGet3DFormDataWithBadInputs(
string $paymentModel,
string $txType,
bool $isWithCard,
bool $createWithoutCard,
string $expectedExceptionClass
): void
{
$card = $isWithCard ? $this->card : null;

$this->expectException($expectedExceptionClass);

$this->pos->get3DFormData($order, $paymentModel, $txType, $card);
$this->pos->get3DFormData($order, $paymentModel, $txType, $card, $createWithoutCard);
}

/**
Expand Down Expand Up @@ -741,25 +742,28 @@ public static function orderHistoryRequestDataProvider(): array
public static function threeDFormDataBadInputsProvider(): array
{
return [
'3d_secure_without_card' => [
'3d_secure_without_card' => [
'order' => ['id' => '2020110828BC'],
'paymentModel' => PosInterface::MODEL_3D_SECURE,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => false,
'expectedExceptionClass' => \InvalidArgumentException::class,
],
'3d_pay_without_card' => [
'3d_pay_without_card' => [
'order' => ['id' => '2020110828BC'],
'paymentModel' => PosInterface::MODEL_3D_PAY,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => false,
'expectedExceptionClass' => \InvalidArgumentException::class,
],
'unsupported_payment_model' => [
'order' => ['id' => '2020110828BC'],
'paymentModel' => PosInterface::MODEL_3D_HOST,
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'isWithCard' => false,
'create_with_card' => true,
'expectedExceptionClass' => \LogicException::class,
],
];
Expand Down
Loading

0 comments on commit 1f460d3

Please sign in to comment.