Skip to content

Commit

Permalink
Merge pull request #47 from nuryagdym/master
Browse files Browse the repository at this point in the history
Fix Vakifbank empty installment issue
  • Loading branch information
nuryagdym authored Dec 4, 2021
2 parents 2b39121 + 084f3a5 commit 42a1491
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/Gateways/VakifBankPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ public function create3DEnrollmentCheckData()
'Currency' => $this->order->currency,
'SuccessUrl' => $this->order->success_url,
'FailureUrl' => $this->order->fail_url,
'InstallmentCount' => $this->order->installment,
'Pan' => $this->card->getNumber(),
'ExpiryDate' => $this->card->getExpirationDate(),
'BrandName' => $this->card->getCardCode(),
Expand Down Expand Up @@ -368,7 +367,6 @@ public function create3DPaymentXML($responseData)
'TerminalNo' => $this->account->getTerminalId(),
'TransactionType' => $this->type,
'TransactionId' => $this->order->rand,
'NumberOfInstallments' => $this->order->installment,
'CardHoldersName' => $this->card->getHolderName(),
'Cvv' => $this->card->getCvv(),
'ECI' => $responseData['Eci'],
Expand Down
51 changes: 51 additions & 0 deletions tests/Gateways/EstPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Mews\Pos\Gateways\AbstractGateway;
use Mews\Pos\Gateways\EstPos;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
use Symfony\Component\Serializer\Encoder\XmlEncoder;

class EstPostTest extends TestCase
Expand Down Expand Up @@ -377,6 +380,37 @@ public function testCreateRefundXML()
//$this->assertEquals([], $actualData);
}

public function testMapCancelResponse()
{
$gatewayResponse = [
'OrderId' => rand(),
'GroupId' => rand(1, 100),
'Response' => rand(1, 100),
'AuthCode' => rand(1, 100),
'HostRefNum' => rand(1, 100),
'ProcReturnCode' => rand(1, 100),
'TransId' => rand(1, 100),
'Extra' => null,
'ErrMsg' => null,
];
$mapCancelResponseFunc = $this->getProtectedMethod('mapCancelResponse');
$pos = PosFactory::createPosGateway($this->account);

$canceledResult = $mapCancelResponseFunc->invokeArgs($pos, [json_decode(json_encode($gatewayResponse))]);
$this->assertNotEmpty($canceledResult);

$this->assertSame($gatewayResponse['OrderId'], $canceledResult->order_id);
$this->assertSame($gatewayResponse['GroupId'], $canceledResult->group_id);
$this->assertSame($gatewayResponse['Response'], $canceledResult->response);
$this->assertSame($gatewayResponse['AuthCode'], $canceledResult->auth_code);
$this->assertSame($gatewayResponse['HostRefNum'], $canceledResult->host_ref_num);
$this->assertSame($gatewayResponse['ProcReturnCode'], $canceledResult->proc_return_code);
$this->assertSame($gatewayResponse['TransId'], $canceledResult->trans_id);
$this->assertSame(null, $canceledResult->error_code);
$this->assertSame(null, $canceledResult->error_message);
$this->assertSame('declined', $canceledResult->status);
}

/**
* @param $order
* @param CreditCardEstPos $card
Expand Down Expand Up @@ -536,4 +570,21 @@ private function getSampleRefundXMLData($order, $account)

return $data;
}


/**
* @param string $name
*
* @return ReflectionMethod
*
* @throws ReflectionException
*/
private static function getProtectedMethod(string $name)
{
$class = new ReflectionClass(EstPos::class);
$method = $class->getMethod($name);
$method->setAccessible(true);

return $method;
}
}
80 changes: 69 additions & 11 deletions tests/Gateways/VakifBankPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ public function testCreate3DEnrollmentCheckData()
'Currency' => $order->currency,
'SuccessUrl' => $order->success_url,
'FailureUrl' => $order->fail_url,
'InstallmentCount' => $order->installment,
'Pan' => $this->card->getNumber(),
'ExpiryDate' => $this->card->getExpirationDate(),
'BrandName' => $this->card->getCardCode(),
'IsRecurring' => 'false',
];

$this->assertEquals($expectedValue, $this->pos->create3DEnrollmentCheckData());


$this->order['installment'] = 2;
$this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card);
$order = $this->pos->getOrder();

$expectedValue['InstallmentCount'] = $order->installment;
$this->assertEquals($expectedValue, $this->pos->create3DEnrollmentCheckData());
}

public function testRecurringCreate3DEnrollmentCheckData()
Expand All @@ -120,28 +127,79 @@ public function testRecurringCreate3DEnrollmentCheckData()
$order['recurringInstallmentCount'] = 2;

$this->pos->prepare($order, AbstractGateway::TX_PAY, $this->card);
$order = $this->pos->getOrder();
$posOrder = $this->pos->getOrder();

$expectedValue = [
'MerchantId' => $this->account->getClientId(),
'MerchantPassword' => $this->account->getPassword(),
'MerchantType' => $this->account->getMerchantType(),
'PurchaseAmount' => $order->amount,
'VerifyEnrollmentRequestId' => $order->rand,
'Currency' => $order->currency,
'SuccessUrl' => $order->success_url,
'FailureUrl' => $order->fail_url,
'InstallmentCount' => $order->installment,
'PurchaseAmount' => $posOrder->amount,
'VerifyEnrollmentRequestId' => $posOrder->rand,
'Currency' => $posOrder->currency,
'SuccessUrl' => $posOrder->success_url,
'FailureUrl' => $posOrder->fail_url,
'Pan' => $this->card->getNumber(),
'ExpiryDate' => $this->card->getExpirationDate(),
'BrandName' => $this->card->getCardCode(),
'IsRecurring' => 'true',
'RecurringFrequency' => $order->recurringFrequency,
'RecurringFrequencyType' => $order->recurringFrequencyType,
'RecurringInstallmentCount' => $order->recurringInstallmentCount,
'RecurringFrequency' => $posOrder->recurringFrequency,
'RecurringFrequencyType' => $posOrder->recurringFrequencyType,
'RecurringInstallmentCount' => $posOrder->recurringInstallmentCount,
];

$this->assertEquals($expectedValue, $this->pos->create3DEnrollmentCheckData());


$order['installment'] = 2;
$this->pos->prepare($order, AbstractGateway::TX_PAY, $this->card);
$posOrder = $this->pos->getOrder();

$expectedValue['InstallmentCount'] = $posOrder->installment;
$this->assertEquals($expectedValue, $this->pos->create3DEnrollmentCheckData());
}

public function testCreate3DPaymentXML()
{
$order = $this->order;
$order['amount'] = 1000;
$this->pos->prepare($order, AbstractGateway::TX_PAY, $this->card);

$gatewayResponse = [
'Eci' => rand(1, 100),
'Cavv' => rand(1, 100),
'VerifyEnrollmentRequestId' => rand(1, 100),
];
$expectedValue = [
'MerchantId' => $this->account->getClientId(),
'Password' => $this->account->getPassword(),
'TerminalNo' => $this->account->getTerminalId(),
'TransactionType' => 'Sale',
'OrderId' => $order['id'],
'ClientIp' => $order['ip'],
'OrderDescription' => '',
'TransactionId' => $order['rand'],
'Cvv' => $this->card->getCvv(),
'CardHoldersName' => $this->card->getHolderName(),
'ECI' => $gatewayResponse['Eci'],
'CAVV' => $gatewayResponse['Cavv'],
'MpiTransactionId' => $gatewayResponse['VerifyEnrollmentRequestId'],
'TransactionDeviceSource' => 0,
];

$actualXML = $this->pos->create3DPaymentXML($gatewayResponse);
$actualData = $this->xmlDecoder->decode($actualXML, 'xml');

$this->assertEquals($expectedValue, $actualData);


$order['installment'] = 2;
$expectedValue['NumberOfInstallments'] = $order['installment'];
$this->pos->prepare($order, AbstractGateway::TX_PAY, $this->card);

$actualXML = $this->pos->create3DPaymentXML($gatewayResponse);
$actualData = $this->xmlDecoder->decode($actualXML, 'xml');

$this->assertEquals($expectedValue, $actualData);
}

public function testCreateRegularPaymentXML()
Expand Down

0 comments on commit 42a1491

Please sign in to comment.