Skip to content

Commit

Permalink
ran rector
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Jan 21, 2024
1 parent 7867a36 commit 09248b6
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ public function mapStatusResponse(array $rawResponseData): array
if (isset($extra['RECURRINGID'])) {
return $this->mapRecurringStatusResponse($rawResponseData);
}

$defaultResponse = $this->getDefaultStatusResponse($rawResponseData);

$defaultResponse['order_id'] = $rawResponseData['OrderId'];
Expand Down Expand Up @@ -405,10 +406,10 @@ public function mapHistoryResponse(array $rawResponseData): array

$transactions = [];
$i = 1;
while (isset($rawResponseData['Extra']["TRX$i"])) {
$rawTx = \explode("\t", $rawResponseData['Extra']["TRX$i"]);
while (isset($rawResponseData['Extra']['TRX'.$i])) {
$rawTx = \explode("\t", $rawResponseData['Extra']['TRX'.$i]);
$transactions[] = $this->mapSingleHistoryTransaction($rawTx);
$i++;
++$i;
}

return [
Expand Down Expand Up @@ -493,6 +494,7 @@ private function mapSingleHistoryTransaction(array $rawTx): array
if (self::PROCEDURE_SUCCESS_CODE === $transaction['proc_return_code']) {
$transaction['status'] = self::TX_APPROVED;
}

$transaction['status_detail'] = $this->getStatusDetail($transaction['proc_return_code']);
$transaction['trans_id'] = $rawTx[10];
/**
Expand Down Expand Up @@ -525,6 +527,7 @@ private function mapSingleRecurringOrderStatus(array $extra, int $i): array
} elseif (null === $procReturnCode) {
$status = null;
}

$recurringOrder = [
'order_id' => $extra[\sprintf('ORD_ID_%d', $i)],
'masked_number' => $extra[\sprintf('PAN_%d', $i)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public function mapStatusResponse(array $rawResponseData): array
if ('WAITINGPOSTAUTH' === $orderInqResult['Status']) {
$orderStatus = PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED;
}

$result = [
'order_id' => $rawResponseData['Order']['OrderID'] ?? null,
'auth_code' => $orderInqResult['AuthCode'] ?? null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function mapStatusResponse(array $rawResponseData): array
if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) {
$status = self::TX_APPROVED;
}

$defaultResponse['status'] = $status;
$defaultResponse['proc_return_code'] = $procReturnCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public function mapStatusResponse(array $rawResponseData): array
if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) {
$status = self::TX_APPROVED;
}

$defaultResponse['status'] = $status;
$defaultResponse['status_detail'] = $this->getStatusDetail($procReturnCode);
if (self::TX_DECLINED === $status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ public function mapStatusResponse(array $rawResponseData): array
if ('true' === $rawResponseData['IsVoided']) {
$orderStatus = PosInterface::PAYMENT_STATUS_CANCELED;
}

if ('true' === $rawResponseData['IsRefunded']) {
$orderStatus = PosInterface::PAYMENT_STATUS_FULLY_REFUNDED;
}

$defaultResponse['order_status'] = $orderStatus;
} else {
$defaultResponse['error_message'] = $rawResponseData['ErrMsg'];
Expand Down Expand Up @@ -289,6 +291,7 @@ public function mapHistoryResponse(array $rawResponseData): array
$status = self::TX_APPROVED;
$mappedTransactions[] = $this->mapSingleHistoryTransaction($paymentRequest);
}

$orderId = $paymentRequest['OrderId'];
} else {
foreach ($rawResponseData['PaymentRequestExtended'] as $tx) {
Expand Down Expand Up @@ -481,6 +484,7 @@ private function mapSingleHistoryTransaction(array $rawTx): array
$defaultResponse['capture'] = false;
$orderStatus = PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED;
}

$defaultResponse['order_status'] = $orderStatus;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen
if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode && $this->getStatusDetail($procReturnCode) === self::TX_APPROVED) {
$status = self::TX_APPROVED;
}

$defaultResponse = $this->getDefaultPaymentResponse($txType, PosInterface::MODEL_3D_SECURE);

if (!isset($raw3DAuthResponseData['oosResolveMerchantDataResponse'])) {
Expand Down Expand Up @@ -231,6 +232,7 @@ public function mapStatusResponse(array $rawResponseData): array
if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode && isset($rawResponseData['transactions']) && !$errorCode) {
$status = self::TX_APPROVED;
}

$txResults = [];

$defaultResponse = $this->getDefaultStatusResponse($rawResponseData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public function mapStatusResponse(array $rawResponseData): array
break;
}
}

if (null === $rawTx) {
return $defaultResponse;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/PaymentTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private function createHistoryOrder(string $gatewayClass, array $lastResponse, a
'pageSize' => 10, // optional, default: 10
];
}

if (PayForPos::class === $gatewayClass) {
if (isset($extraData['reqDate'])) {
$order = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ public function testMapHistoryResponse(array $responseData, array $expectedData)
$actualData['transactions'][1]['trans_time'],
);
}

foreach ($responseData['Transactions'] as $key => $tx) {
if (isset($tx['CreateDate'])) {
$this->assertSame($actualData['transactions'][$key]['trans_time']->format('YmdHis'), $tx['CreateDate']);
$this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time']);
unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']);
unset($actualData['transactions'][$key]['capture_time'], $expectedData['transactions'][$key]['capture_time']);
}

\ksort($actualData['transactions'][$key]);
\ksort($expectedData['transactions'][$key]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ public function testMapHistoryResponse(array $responseData, array $expectedData)
$actualData['transactions'][1]['trans_time'],
);
}
foreach ($actualData['transactions'] as $key => $tx) {

foreach (array_keys($actualData['transactions']) as $key) {
$this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time']);
$this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time']);
unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']);
\ksort($actualData['transactions'][$key]);
\ksort($expectedData['transactions'][$key]);
}

$this->assertCount($actualData['trans_count'], $actualData['transactions']);
}

unset($actualData['all']);
\ksort($expectedData);
\ksort($actualData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ public function testMapHistoryResponse(array $responseData, array $expectedData)
$actualData['transactions'][1]['trans_time'],
);
}
foreach ($actualData['transactions'] as $key => $tx) {

foreach (array_keys($actualData['transactions']) as $key) {
$this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time']);
$this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time']);
unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']);
unset($actualData['transactions'][$key]['capture_time'], $expectedData['transactions'][$key]['capture_time']);
\ksort($actualData['transactions'][$key]);
\ksort($expectedData['transactions'][$key]);
}

$this->assertCount($actualData['trans_count'], $actualData['transactions']);

unset($actualData['all']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public function testMapHistoryResponse(array $responseData, array $expectedData)

$this->assertCount($actualData['trans_count'], $actualData['transactions']);

foreach ($actualData['transactions'] as $key => $tx) {
$this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time'], "tx: $key");
$this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time'], "tx: $key");
foreach (array_keys($actualData['transactions']) as $key) {
$this->assertEquals($expectedData['transactions'][$key]['trans_time'], $actualData['transactions'][$key]['trans_time'], 'tx: '.$key);
$this->assertEquals($expectedData['transactions'][$key]['capture_time'], $actualData['transactions'][$key]['capture_time'], 'tx: '.$key);
unset($actualData['transactions'][$key]['trans_time'], $expectedData['transactions'][$key]['trans_time']);
unset($actualData['transactions'][$key]['capture_time'], $expectedData['transactions'][$key]['capture_time']);
\ksort($actualData['transactions'][$key]);
Expand Down Expand Up @@ -2172,7 +2172,7 @@ public static function historyTestDataProvider(): array
'status' => 'approved',
'error_code' => null,
'status_detail' => 'approved',
'capture' => false,
'capture' => false,
'currency' => 'TRY',
'masked_number' => '415565******6111',
],
Expand Down Expand Up @@ -2217,7 +2217,7 @@ public static function historyTestDataProvider(): array
],
],
],
'success_pay' => [
'success_pay' => [
'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/success_pay_response.json'), true),
'expectedData' => [
'order_id' => '202401212A22',
Expand Down Expand Up @@ -2250,7 +2250,7 @@ public static function historyTestDataProvider(): array
],
],
],
'success_pre_pay' => [
'success_pre_pay' => [
'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/success_pre_pay_response.json'), true),
'expectedData' => [
'order_id' => '2024012186F9',
Expand Down Expand Up @@ -2283,7 +2283,7 @@ public static function historyTestDataProvider(): array
],
],
],
'success_pay_refund_fail' => [
'success_pay_refund_fail' => [
'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/success_pay_refund_fail_response.json'), true),
'expectedData' => [
'order_id' => '202401211C79',
Expand Down Expand Up @@ -2335,7 +2335,7 @@ public static function historyTestDataProvider(): array
],
],
],
'fail_order_not_found' => [
'fail_order_not_found' => [
'responseData' => \json_decode(\file_get_contents(__DIR__.'/../../test_data/payfor/history/fail_order_not_found_response.json'), true),
'expectedData' => [
'order_id' => '202401010C2022',
Expand Down

0 comments on commit 09248b6

Please sign in to comment.