Skip to content

Commit

Permalink
tests - cover get3DFormData
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Sep 7, 2024
1 parent 0f51ef3 commit 926eb7e
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,83 @@ public static function threeDPaymentDataProvider(): array
'transaction_time' => null,
],
],
'3d_auth_fail_1' => [
'order' => [],
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'threeDResponseData' => [
'apiversion' => '512',
'authcode' => '',
'cavv' => '',
'cavvalgorithm' => '',
'clientid' => '30691298',
'customeripaddress' => '192.168.0.1',
'eci' => '',
'errmsg' => '',
'errorurl' => 'http://localhost:807/garanti/3d/response.php',
'garanticardind' => '',
'hash' => 'FD9BF014BFBC3D977B123AE84247CE3F639913644429304C4EE108C0F40212853628CAECAADB798EE73D467F50C3B5D90FE0F3B921EDAA94B6E2EA888F9FE9B7',
'hashparams' => 'clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:',
'hashparamsval' => '30691298202409078CF30aW5kZXg6MDIYjoYTHmZE91tOHZxS3PEkMcb8vBvm21xQz107TS6WKHVjLlrZP9AMx7KFu8jZRZA3WtZxMUuaUynWLxQGsVrw1vTKIofUQ0dw2P/jVVvPMX/RxI7Bpjvo/pZp3Nmbj2wd1W146UhNNmge7eA+hdrNSHuPp7PmjAihyZEPujAi3Q==6ga2Y3buKZ3ZcJSC7uE6',
'hostmsg' => '',
'hostrefnum' => '',
'ireqcode' => '',
'ireqdetail' => '',
'MaskedPan' => '42822090****8012',
'md' => 'aW5kZXg6MDIYjoYTHmZE91tOHZxS3PEkMcb8vBvm21xQz107TS6WKHVjLlrZP9AMx7KFu8jZRZA3WtZxMUuaUynWLxQGsVrw1vTKIofUQ0dw2P/jVVvPMX/RxI7Bpjvo/pZp3Nmbj2wd1W146UhNNmge7eA+hdrNSHuPp7PmjAihyZEPujAi3Q==',
'mderrormessage' => '',
'mdstatus' => '0',
'mode' => 'TEST',
'oid' => '202409078CF3',
'orderid' => '202409078CF3',
'paressyntaxok' => '',
'paresverified' => '',
'procreturncode' => '',
'response' => '',
'rnd' => '6ga2Y3buKZ3ZcJSC7uE6',
'secure3dhash' => '9F3027C22FB3485484144993E5EE0B0B99FB30A7CF76EBF885F0F01BC0898FB54C3892F02FAB1BF8C16B0F8C868A6C6F7689381D0DBC882ABA786EA764B13DCA',
'secure3dsecuritylevel' => '3D',
'successurl' => 'http://localhost:807/garanti/3d/response.php',
'terminalid' => '30691298',
'terminalmerchantid' => '7000679',
'terminalprovuserid' => 'PROVAUT',
'terminaluserid' => 'PROVAUT',
'transid' => '202409078CF3',
'txnamount' => '1001',
'txncurrencycode' => '949',
'txninstallmentcount' => '',
'txnstatus' => '',
'txntype' => 'sales',
'vendorcode' => '',
'version' => '',
'xid' => '9df81889-86f6-42bf-9129-8189d30e6fef',
],
'paymentData' => [],
'expectedData' => [
'order_id' => '202409078CF3',
'transaction_id' => null,
'auth_code' => null,
'ref_ret_num' => null,
'transaction_security' => 'MPI fallback',
'proc_return_code' => null,
'md_status' => '0',
'status' => 'declined',
'status_detail' => null,
'masked_number' => null,
'amount' => 10.01,
'currency' => 'TRY',
'tx_status' => null,
'eci' => null,
'cavv' => null,
'error_code' => null,
'error_message' => null,
'md_error_message' => null,
'batch_num' => null,
'transaction_type' => 'pay',
'payment_model' => '3d',
'installment_count' => 0,
'transaction_time' => null,
],
],
'success1' => [
'order' => [],
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Gateways/GarantiPosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,19 @@ public function testOrderHistoryRequest(array $order, string $apiUrl): void
public static function make3DPaymentDataProvider(): array
{
return [
'3d_auth_fail_1' => [
'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['order'],
'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['txType'],
'request' => Request::create(
'',
'POST',
GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['threeDResponseData']
),
'paymentResponse' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['paymentData'],
'expected' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_fail_1']['expectedData'],
'is3DSuccess' => false,
'isSuccess' => false,
],
'3d_auth_success_payment_fail' => [
'order' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['order'],
'txType' => GarantiPosResponseDataMapperTest::threeDPaymentDataProvider()['paymentFail1']['txType'],
Expand Down
94 changes: 60 additions & 34 deletions tests/Unit/Gateways/PayFlexV4PosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ protected function setUp(): void
parent::setUp();

$this->config = [
'name' => 'VakifBank-VPOS',
'class' => PayFlexV4Pos::class,
'gateway_endpoints' => [
'payment_api' => 'https://onlineodemetest.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx',
'gateway_3d' => 'https://3dsecuretest.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspxs',
'query_api' => 'https://sanalpos.vakifbank.com.tr/v4/UIWebService/Search.aspx',
'name' => 'VakifBank-VPOS',
'class' => PayFlexV4Pos::class,
'gateway_endpoints' => [
'payment_api' => 'https://onlineodemetest.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx',
'gateway_3d' => 'https://3dsecuretest.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspxs',
'query_api' => 'https://sanalpos.vakifbank.com.tr/v4/UIWebService/Search.aspx',
],
];

Expand Down Expand Up @@ -128,7 +128,14 @@ protected function setUp(): void

$this->pos->setTestMode(true);

$this->card = CreditCardFactory::createForGateway($this->pos, '5555444433332222', '2021', '12', '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA);
$this->card = CreditCardFactory::create(
'5555444433332222',
'2021',
'12',
'122',
'ahmet',
CreditCardInterface::CARD_TYPE_VISA
);
}

/**
Expand All @@ -147,11 +154,10 @@ public function testInit(): void
/**
* @return void
*
* @throws Exception
* @dataProvider enrollmentFailResponseDataProvider
*/
public function testGet3DFormDataEnrollmentFail(): void
public function testGet3DFormDataEnrollmentFail(array $response): void
{
$this->expectException(Exception::class);
$txType = PosInterface::TX_TYPE_PAY_AUTH;
$requestData = ['request-data'];
$order = $this->order;
Expand All @@ -162,21 +168,37 @@ public function testGet3DFormDataEnrollmentFail(): void

$this->configureClientResponse(
$txType,
$this->config['gateway_endpoints']['gateway_3d'],
'https://3dsecuretest.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspxs',
$requestData,
$requestData,
'response-body',
self::getSampleEnrollmentFailResponseDataProvider(),
$response,
$order,
PosInterface::MODEL_3D_SECURE
);

$this->requestMapperMock->expects(self::never())
->method('create3DFormData');

$this->expectException(\RuntimeException::class);
$this->pos->get3DFormData($order, PosInterface::MODEL_3D_SECURE, $txType, $this->card);
}

public function testGet3DFormDataWithoutCard(): void
{
$this->requestMapperMock->expects(self::never())
->method('create3DEnrollmentCheckRequestData');

$this->httpClientMock->expects(self::never())
->method('post');

$this->requestMapperMock->expects(self::never())
->method('create3DFormData');

$this->expectException(\LogicException::class);
$this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH);
}

/**
* @return void
*
Expand Down Expand Up @@ -496,17 +518,21 @@ public function testOrderHistoryRequest(): void
$this->pos->orderHistory([]);
}

public static function getSampleEnrollmentFailResponseDataProvider(): array
public static function enrollmentFailResponseDataProvider(): array
{
return [
'Message' => [
'VERes' => [
'Status' => 'E',
'merchant_not_found' => [
'response' => [
'Message' => [
'VERes' => [
'Status' => 'E',
],
],
'VerifyEnrollmentRequestId' => '0aebb0757acccae6fba75b2e4d78cecf',
'MessageErrorCode' => '2005',
'ErrorMessage' => 'Merchant cannot be found for this bank',
],
],
'VerifyEnrollmentRequestId' => '0aebb0757acccae6fba75b2e4d78cecf',
'MessageErrorCode' => '2005',
'ErrorMessage' => 'Merchant cannot be found for this bank',
];
}

Expand Down Expand Up @@ -595,28 +621,28 @@ public static function make3DPaymentDataProvider(): array
'isSuccess' => false,
],
'3d_auth_success_payment_fail' => [
'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['order'],
'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['txType'],
'request' => Request::create(
'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['order'],
'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['txType'],
'request' => Request::create(
'',
'POST',
PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['threeDResponseData']
), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['paymentData'],
'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['expectedData'],
'is3DSuccess' => true,
'isSuccess' => false,
), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['paymentData'],
'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['expectedData'],
'is3DSuccess' => true,
'isSuccess' => false,
],
'success' => [
'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'],
'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'],
'request' => Request::create(
'order' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['order'],
'txType' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['txType'],
'request' => Request::create(
'',
'POST',
PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['3d_auth_success_payment_fail']['threeDResponseData']
), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'],
'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'],
'is3DSuccess' => true,
'isSuccess' => true,
), 'paymentResponse' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['paymentData'],
'expected' => PayFlexV4PosResponseDataMapperTest::threeDPaymentDataProvider()['success1']['expectedData'],
'is3DSuccess' => true,
'isSuccess' => true,
],
];
}
Expand All @@ -625,7 +651,7 @@ private function configureClientResponse(
string $txType,
string $apiUrl,
array $requestData,
$encodedRequestData,
$encodedRequestData,
string $responseContent,
array $decodedResponse,
array $order,
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Gateways/PosNetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ public function testGet3DFormDataOosTransactionFail(): void
$this->pos->get3DFormData($order, PosInterface::MODEL_3D_SECURE, $txType, $this->card);
}

public function testGet3DFormDataWithoutCard(): void
{
$this->requestMapperMock->expects(self::never())
->method('create3DEnrollmentCheckRequestData');

$this->httpClientMock->expects(self::never())
->method('post');

$this->requestMapperMock->expects(self::never())
->method('create3DFormData');

$this->expectException(\LogicException::class);
$this->pos->get3DFormData([], PosInterface::MODEL_3D_SECURE, PosInterface::TX_TYPE_PAY_AUTH);
}

/**
* @dataProvider make3DPaymentDataProvider
*/
Expand Down
Loading

0 comments on commit 926eb7e

Please sign in to comment.