Skip to content

Commit

Permalink
Merge pull request #231 from mewebstudio/229-payflex-issues
Browse files Browse the repository at this point in the history
fix payflexv4pos issues
  • Loading branch information
nuryagdym authored Aug 17, 2024
2 parents d01c78b + d740c95 commit 90236d9
Show file tree
Hide file tree
Showing 16 changed files with 587 additions and 341 deletions.
2 changes: 1 addition & 1 deletion config/pos_production.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
'gateway_endpoints' => [
'payment_api' => 'https://onlineodeme.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx',
'gateway_3d' => 'https://3dsecure.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspx',
'query_api' => 'https://sanalpos.vakifbank.com.tr/v4/UIWebService/Search.aspx',
'query_api' => 'https://onlineodeme.vakifbank.com.tr:4443/UIService/Search.aspx',
],
],
'ziraat-vpos' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Crypt/PayFlexCPV4Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $requestData)
*/
public function check3DHash(AbstractPosAccount $posAccount, array $data): bool
{
return true;
throw new NotImplementedException();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ protected function preparePostPaymentOrder(array $order): array
protected function prepareStatusOrder(array $order): array
{
return [
'id' => $order['id'],
'id' => $order['id'],
'transaction_id' => $order['transaction_id'] ?? null,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ private function mapHistoryOrderStatus(string $txStatus, ?string $txType): ?stri
if (null === $txType) {
return null;
}

// txStatus possible values:
// Basarili
// Basarisiz
Expand All @@ -648,19 +649,23 @@ private function mapHistoryOrderStatus(string $txStatus, ?string $txType): ?stri
if (PosInterface::TX_TYPE_CANCEL === $txType) {
return PosInterface::PAYMENT_STATUS_CANCELED;
}

if (PosInterface::TX_TYPE_REFUND === $txType) {
// todo how can we decide if order is partially or fully refunded?
return PosInterface::PAYMENT_STATUS_FULLY_REFUNDED;
}

if (PosInterface::TX_TYPE_PAY_AUTH === $txType || PosInterface::TX_TYPE_PAY_POST_AUTH === $txType) {
return PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED;
}

if (PosInterface::TX_TYPE_PAY_PRE_AUTH === $txType) {
return PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED;
}

return null;
}

if ('Iptal' === $txStatus) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen
*/
public function map3DPayResponseData(array $raw3DAuthResponseData, string $txType, array $order): array
{
return $this->map3DPaymentData($raw3DAuthResponseData, $raw3DAuthResponseData, $txType, $order);
throw new NotImplementedException();
}

/**
* {@inheritdoc}
*/
public function map3DHostResponseData(array $raw3DAuthResponseData, string $txType, array $order): array
{
return $this->map3DPayResponseData($raw3DAuthResponseData, $txType, $order);
throw new NotImplementedException();
}

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ public function mapStatusResponse(array $rawResponseData): array
$defaultResponse['order_status'] = $orderStatus;
$defaultResponse['transaction_type'] = $this->mapTxType($txResultInfo['TransactionType']);
$defaultResponse['currency'] = $this->mapCurrency($txResultInfo['AmountCode']);
$defaultResponse['first_amount'] = $this->formatAmount($txResultInfo['CurrencyAmount']);
$defaultResponse['first_amount'] = $this->formatAmount($txResultInfo['CurrencyAmount'] ?? $txResultInfo['Amount']);
$defaultResponse['capture_amount'] = null;
$defaultResponse['status'] = self::PROCEDURE_SUCCESS_CODE === $orderProcCode ? self::TX_APPROVED : self::TX_DECLINED;
$defaultResponse['error_code'] = self::PROCEDURE_SUCCESS_CODE !== $orderProcCode ? $txResultInfo['HostResultCode'] : null;
Expand All @@ -209,7 +209,12 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType

if (self::TX_APPROVED === $commonResponse['status']) {
$commonResponse['transaction_id'] = $rawPaymentResponseData['TransactionId'];
$commonResponse['transaction_time'] = new \DateTimeImmutable($rawPaymentResponseData['HostDate']);
$txTime = $rawPaymentResponseData['HostDate'];
if (\strlen($txTime) === 10) { // ziraat is sending host date without year
$txTime = date('Y').$txTime;
}

$commonResponse['transaction_time'] = new \DateTimeImmutable($txTime);
$commonResponse['auth_code'] = $rawPaymentResponseData['AuthCode'];
$commonResponse['ref_ret_num'] = $rawPaymentResponseData['TransactionId'];
$commonResponse['batch_num'] = $rawPaymentResponseData['BatchNo'];
Expand Down
1 change: 1 addition & 0 deletions src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public function refund(array $order): PosInterface
if (isset($order['order_amount']) && $order['amount'] < $order['order_amount']) {
$txType = PosInterface::TX_TYPE_REFUND_PARTIAL;
}

$requestData = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType);

$event = new RequestDataPreparedEvent(
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Crypt/AkbankPosCryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @covers \Mews\Pos\Crypt\AkbankPosCrypt
* @covers \Mews\Pos\Crypt\AbstractCrypt
*/
class AkbankPosCryptTest extends TestCase
{
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Crypt/InterPosCryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
namespace Mews\Pos\Tests\Unit\Crypt;

use Mews\Pos\Crypt\InterPosCrypt;
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Account\InterPosAccount;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

/**
* @covers \Mews\Pos\Crypt\InterPosCrypt
* @covers \Mews\Pos\Crypt\AbstractCrypt
*/
class InterPosCryptTest extends TestCase
{
Expand Down Expand Up @@ -48,6 +51,9 @@ protected function setUp(): void
public function testCheck3DHash(array $responseData): void
{
$this->assertTrue($this->crypt->check3DHash($this->account, $responseData));

$responseData['PurchAmount'] = '';
$this->assertFalse($this->crypt->check3DHash($this->account, $responseData));
}

/**
Expand All @@ -60,6 +66,22 @@ public function testCreate3DHash(array $requestData, string $expected): void
$this->assertSame($expected, $actual);
}

public function testCreateHash(): void
{
$this->expectException(NotImplementedException::class);
$this->crypt->createHash($this->account, []);
}

/**
* @dataProvider threeDHashCheckDataProvider
*/
public function testCheck3DHashException(): void
{
$account = $this->createMock(AbstractPosAccount::class);
$this->expectException(\LogicException::class);
$this->crypt->check3DHash($account, []);
}

public function threeDHashCheckDataProvider(): array
{
return [
Expand Down
19 changes: 17 additions & 2 deletions tests/Unit/Crypt/PayFlexCP4CryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

use Mews\Pos\Crypt\PayFlexCPV4Crypt;
use Mews\Pos\Entity\Account\PayFlexAccount;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

/**
* @covers \Mews\Pos\Crypt\PayFlexCPV4Crypt
* @covers \Mews\Pos\Crypt\AbstractCrypt
*/
class PayFlexCP4CryptTest extends TestCase
{
Expand Down Expand Up @@ -47,7 +49,20 @@ public function testCreate3DHash(array $requestData, string $expected): void
$this->assertSame($expected, $actual);
}

public function hashCreateDataProvider(): array
public function testCreateHash(): void
{
$this->expectException(NotImplementedException::class);
$this->crypt->createHash($this->account, []);
}

public function testCheck3DHash(): void
{
$this->expectException(NotImplementedException::class);

$this->crypt->check3DHash($this->account, []);
}

public static function hashCreateDataProvider(): array
{
return [
[
Expand All @@ -62,7 +77,7 @@ public function hashCreateDataProvider(): array
];
}

public function threeDHashCreateDataProvider(): array
public static function threeDHashCreateDataProvider(): array
{
return [
[
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Crypt/PosNetV1PosCryptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* @covers \Mews\Pos\Crypt\PosNetV1PosCrypt
* @covers \Mews\Pos\Crypt\AbstractCrypt
*/
class PosNetV1PosCryptTest extends TestCase
{
Expand Down Expand Up @@ -44,6 +45,17 @@ public function testHashFromParams(string $storeKey, array $data, string $expect
$this->assertSame($expected, $this->crypt->hashFromParams($storeKey, $data, 'MACParams', ':'));
}

public function testHashFromParamsWhenNotFound(): void
{
$data = self::hashFromParamsDataProvider()[0];
$this->assertSame('', $this->crypt->hashFromParams(
$data['storeKey'],
$data,
'NonExistingField',
':'
));
}

/**
* @dataProvider hashCreateDataProvider
*/
Expand Down
Loading

0 comments on commit 90236d9

Please sign in to comment.