From 098fef59195b5839b5a8ba35df806d73746f2e5c Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 22 Apr 2022 18:25:58 +0200 Subject: [PATCH 01/40] created PayForPosRequestDataMapper and refactored PayForPos --- src/DataMapper/PayForPosRequestDataMapper.php | 255 +++++++++ src/Gateways/PayForPos.php | 232 +-------- .../PayForPosRequestDataMapperTest.php | 486 ++++++++++++++++++ tests/Gateways/PayForTest.php | 377 +------------- 4 files changed, 787 insertions(+), 563 deletions(-) create mode 100644 src/DataMapper/PayForPosRequestDataMapper.php create mode 100644 tests/DataMapper/PayForPosRequestDataMapperTest.php diff --git a/src/DataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/PayForPosRequestDataMapper.php new file mode 100644 index 00000000..6b636c46 --- /dev/null +++ b/src/DataMapper/PayForPosRequestDataMapper.php @@ -0,0 +1,255 @@ + '3DModel', + AbstractGateway::MODEL_3D_PAY => '3DPay', + AbstractGateway::MODEL_3D_HOST => '3DHost', + AbstractGateway::MODEL_NON_SECURE => 'NonSecure', + ]; + + /** + * @inheritdoc + */ + protected $txTypeMappings = [ + AbstractGateway::TX_PAY => 'Auth', + AbstractGateway::TX_PRE_PAY => 'PreAuth', + AbstractGateway::TX_POST_PAY => 'PostAuth', + AbstractGateway::TX_CANCEL => 'Void', + AbstractGateway::TX_REFUND => 'Refund', + AbstractGateway::TX_HISTORY => 'TxnHistory', + AbstractGateway::TX_STATUS => 'OrderInquiry', + ]; + + /** + * @inheritdoc + */ + protected $currencyMappings = [ + 'TRY' => 949, + 'USD' => 840, + 'EUR' => 978, + 'GBP' => 826, + 'JPY' => 392, + 'RUB' => 643, + ]; + + /** + * @inheritDoc + */ + public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData): array + { + return [ + 'RequestGuid' => $responseData['RequestGuid'], + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrderId' => $order->id, + 'SecureType' => '3DModelPayment', + ]; + } + + /** + * @inheritDoc + */ + public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array + { + return [ + 'MbrId' => self::MBR_ID, + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'MOTO' => self::MOTO, + 'OrderId' => $order->id, + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'TxnType' => $txType, + 'PurchAmount' => $order->amount, + 'Currency' => $order->currency, + 'InstallmentCount' => $order->installment, + 'Lang' => $this->getLang($account, $order), + 'CardHolderName' => $card->getHolderName(), + 'Pan' => $card->getNumber(), + 'Expiry' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), + 'Cvv2' => $card->getCvv(), + ]; + } + + /** + * @inheritDoc + */ + public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array + { + return [ + 'MbrId' => self::MBR_ID, + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrgOrderId' => $order->id, + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'PurchAmount' => $order->amount, + 'Currency' => $order->currency, + 'Lang' => $this->getLang($account, $order), + ]; + } + + /** + * @inheritDoc + */ + public function createStatusRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'MbrId' => self::MBR_ID, + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrgOrderId' => $order->id, + 'SecureType' => 'Inquiry', + 'Lang' => $this->getLang($account, $order), + 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_STATUS], + ]; + } + + /** + * @inheritDoc + */ + public function createCancelRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'MbrId' => self::MBR_ID, + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrgOrderId' => $order->id, + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], + 'Currency' => $order->currency, + 'Lang' => $this->getLang($account, $order), + ]; + } + + /** + * @inheritDoc + */ + public function createRefundRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'MbrId' => self::MBR_ID, + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'Lang' => $this->getLang($account, $order), + 'OrgOrderId' => $order->id, + 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_REFUND], + 'PurchAmount' => $order->amount, + 'Currency' => $order->currency, + ]; + } + + /** + * @inheritDoc + */ + public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array + { + $requestData = [ + 'MbrId' => self::MBR_ID, + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'SecureType' => 'Report', + 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_HISTORY], + 'Lang' => $this->getLang($account, $order), + ]; + + if (isset($extraData['orderId'])) { + $requestData['OrderId'] = $extraData['orderId']; + } elseif (isset($extraData['reqDate'])) { + //ReqData YYYYMMDD format + $requestData['ReqDate'] = $extraData['reqDate']; + } + + return $requestData; + } + + + /** + * @inheritDoc + */ + public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null): array + { + $hash = $this->create3DHash($account, $order, $txType); + + $inputs = [ + 'MbrId' => self::MBR_ID, + 'MerchantID' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'OrderId' => $order->id, + 'Lang' => $this->getLang($account, $order), + 'SecureType' => $this->secureTypeMappings[$account->getModel()], + 'TxnType' => $txType, + 'PurchAmount' => $order->amount, + 'InstallmentCount' => $order->installment, + 'Currency' => $order->currency, + 'OkUrl' => $order->success_url, + 'FailUrl' => $order->fail_url, + 'Rnd' => $order->rand, + 'Hash' => $hash, + ]; + + if ($card) { + $inputs['CardHolderName'] = $card->getHolderName(); + $inputs['Pan'] = $card->getNumber(); + $inputs['Expiry'] = $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT); + $inputs['Cvv2'] = $card->getCvv(); + } + + return [ + 'gateway' => $gatewayURL, //to be filled by the caller + 'inputs' => $inputs, + ]; + } + + /** + * @inheritDoc + */ + public function create3DHash(AbstractPosAccount $account, $order, string $txType): string + { + $hashData = [ + self::MBR_ID, + $order->id, + $order->amount, + $order->success_url, + $order->fail_url, + $txType, + $order->installment, + $order->rand, + $account->getStoreKey(), + ]; + $hashStr = implode(static::HASH_SEPARATOR, $hashData); + + return $this->hashString($hashStr); + } +} diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index c6663b21..00ac47d5 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -1,9 +1,11 @@ 'Auth', - self::TX_PRE_PAY => 'PreAuth', - self::TX_POST_PAY => 'PostAuth', - self::TX_CANCEL => 'Void', - self::TX_REFUND => 'Refund', - self::TX_HISTORY => 'TxnHistory', - self::TX_STATUS => 'OrderInquiry', - ]; - - protected $secureTypeMappings = [ - self::MODEL_3D_SECURE => '3DModel', - self::MODEL_3D_PAY => '3DPay', - self::MODEL_3D_HOST => '3DHost', - self::MODEL_NON_SECURE => 'NonSecure', - ]; - - /** - * currency mapping - * - * @var array - */ - protected $currencies = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 643, - ]; + private $requestDataMapper; /** * @inheritDoc @@ -115,6 +74,10 @@ class PayForPos extends AbstractGateway */ public function __construct($config, $account, array $currencies) { + $this->requestDataMapper = new PayForPosRequestDataMapper($currencies); + $this->types = $this->requestDataMapper->getTxTypeMappings(); + $this->currencies = $this->requestDataMapper->getCurrencyMappings(); + $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); parent::__construct($config, $account, $currencies); } @@ -205,18 +168,12 @@ public function get3DFormData(): array return []; } - $this->order->hash = $this->create3DHash($this->account, $this->order, $this->type); - - $formData = $this->getCommon3DFormData(); - if (self::MODEL_3D_PAY === $this->account->getModel()) { - $formData['gateway'] = $this->get3DGatewayURL(); - } elseif (self::MODEL_3D_SECURE === $this->account->getModel()) { - $formData['gateway'] = $this->get3DGatewayURL(); - } else { - $formData['gateway'] = $this->get3DHostGatewayURL(); + $gatewayURL = $this->get3DGatewayURL(); + if (self::MODEL_3D_HOST === $this->account->getModel()) { + $gatewayURL = $this->get3DHostGatewayURL(); } - return $formData; + return $this->requestDataMapper->create3DFormData($this->account, $this->order, $this->type, $gatewayURL, $this->card); } @@ -243,9 +200,9 @@ public function send($postData, ?string $url = null) * \r\n * \r\n * \r\n - * redundant whitespaces causes non empty value for response properties + * redundant whitespaces causes non-empty value for response properties */ - $contents = preg_replace('/\\r\\n /', '', $contents); + $contents = preg_replace('/\\r\\n\s*/', '', $contents); try { $this->data = $this->XMLStringToObject($contents); @@ -265,32 +222,6 @@ public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignore return parent::createXML(['PayforRequest' => $nodes], $encoding, $ignorePiNode); } - - /** - * @param AbstractPosAccount $account - * @param $order - * @param string $txType - * - * @return string - */ - public function create3DHash(AbstractPosAccount $account, $order, string $txType): string - { - $hashData = [ - self::MBR_ID, - $order->id, - $order->amount, - $order->success_url, - $order->fail_url, - $txType, - $order->installment, - $order->rand, - $account->getStoreKey(), - ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); - - return $this->hashString($hashStr); - } - /** * validates response hash * @@ -324,24 +255,7 @@ public function check3DHash(AbstractPosAccount $account, array $data): bool */ public function createRegularPaymentXML() { - $requestData = [ - 'MbrId' => self::MBR_ID, - 'MerchantId' => $this->account->getClientId(), - 'UserCode' => $this->account->getUsername(), - 'UserPass' => $this->account->getPassword(), - 'MOTO' => self::MOTO, - 'OrderId' => $this->order->id, - 'SecureType' => $this->secureTypeMappings[self::MODEL_NON_SECURE], - 'TxnType' => $this->type, - 'PurchAmount' => $this->order->amount, - 'Currency' => $this->order->currency, - 'InstallmentCount' => $this->order->installment, - 'Lang' => $this->getLang(), - 'CardHolderName' => $this->card->getHolderName(), - 'Pan' => $this->card->getNumber(), - 'Expiry' => $this->card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), - 'Cvv2' => $this->card->getCvv(), - ]; + $requestData = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $this->order, $this->type, $this->card); return $this->createXML($requestData); } @@ -351,18 +265,7 @@ public function createRegularPaymentXML() */ public function createRegularPostXML() { - $requestData = [ - 'MbrId' => self::MBR_ID, - 'MerchantId' => $this->account->getClientId(), - 'UserCode' => $this->account->getUsername(), - 'UserPass' => $this->account->getPassword(), - 'OrgOrderId' => $this->order->id, - 'SecureType' => $this->secureTypeMappings[self::MODEL_NON_SECURE], - 'TxnType' => $this->type, - 'PurchAmount' => $this->order->amount, - 'Currency' => $this->order->currency, - 'Lang' => $this->getLang(), - ]; + $requestData = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -372,13 +275,7 @@ public function createRegularPostXML() */ public function create3DPaymentXML($responseData) { - $requestData = [ - 'RequestGuid' => $responseData['RequestGuid'], - 'UserCode' => $this->account->getUsername(), - 'UserPass' => $this->account->getPassword(), - 'OrderId' => $this->order->id, - 'SecureType' => '3DModelPayment', - ]; + $requestData = $this->requestDataMapper->create3DPaymentRequestData($this->account, $this->order, '', $responseData); return $this->createXML($requestData); } @@ -388,16 +285,7 @@ public function create3DPaymentXML($responseData) */ public function createStatusXML() { - $requestData = [ - 'MbrId' => self::MBR_ID, - 'MerchantId' => $this->account->getClientId(), - 'UserCode' => $this->account->getUsername(), - 'UserPass' => $this->account->getPassword(), - 'OrgOrderId' => $this->order->id, - 'SecureType' => 'Inquiry', - 'Lang' => $this->getLang(), - 'TxnType' => $this->types[self::TX_STATUS], - ]; + $requestData = $this->requestDataMapper->createStatusRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -407,23 +295,7 @@ public function createStatusXML() */ public function createHistoryXML($customQueryData) { - $requestData = [ - 'MbrId' => self::MBR_ID, - 'MerchantId' => $this->account->getClientId(), - 'UserCode' => $this->account->getUsername(), - 'UserPass' => $this->account->getPassword(), - 'SecureType' => 'Report', - 'TxnType' => $this->types[self::TX_HISTORY], - 'Lang' => $this->getLang(), - ]; - - if (isset($customQueryData['orderId'])) { - $requestData['OrderId'] = $customQueryData['orderId']; - } elseif (isset($customQueryData['reqDate'])) { - //ReqData YYYYMMDD format - $requestData['ReqDate'] = $customQueryData['reqDate']; - } - + $requestData = $this->requestDataMapper->createHistoryRequestData($this->account, $this->order, $customQueryData); return $this->createXML($requestData); } @@ -433,18 +305,7 @@ public function createHistoryXML($customQueryData) */ public function createRefundXML() { - $requestData = [ - 'MbrId' => self::MBR_ID, - 'MerchantId' => $this->account->getClientId(), - 'UserCode' => $this->account->getUsername(), - 'UserPass' => $this->account->getPassword(), - 'SecureType' => $this->secureTypeMappings[self::MODEL_NON_SECURE], - 'Lang' => $this->getLang(), - 'OrgOrderId' => $this->order->id, - 'TxnType' => $this->types[self::TX_REFUND], - 'PurchAmount' => $this->order->amount, - 'Currency' => $this->order->currency, - ]; + $requestData = $this->requestDataMapper->createRefundRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -454,17 +315,7 @@ public function createRefundXML() */ public function createCancelXML() { - $requestData = [ - 'MbrId' => self::MBR_ID, - 'MerchantId' => $this->account->getClientId(), - 'UserCode' => $this->account->getUsername(), - 'UserPass' => $this->account->getPassword(), - 'OrgOrderId' => $this->order->id, - 'SecureType' => $this->secureTypeMappings[self::MODEL_NON_SECURE], - 'TxnType' => $this->types[self::TX_CANCEL], - 'Currency' => $this->order->currency, - 'Lang' => $this->getLang(), - ]; + $requestData = $this->requestDataMapper->createCancelRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -656,43 +507,6 @@ protected function mapStatusResponse($rawResponseData) ]; } - /** - * returns common form data used by all 3D payment gates - * - * @return array - */ - protected function getCommon3DFormData(): array - { - $inputs = [ - 'MbrId' => self::MBR_ID, - 'MerchantID' => $this->account->getClientId(), - 'UserCode' => $this->account->getUsername(), - 'OrderId' => $this->order->id, - 'Lang' => $this->getLang(), - 'SecureType' => $this->secureTypeMappings[$this->account->getModel()], - 'TxnType' => $this->type, - 'PurchAmount' => $this->order->amount, - 'InstallmentCount' => $this->order->installment, - 'Currency' => $this->order->currency, - 'OkUrl' => $this->order->success_url, - 'FailUrl' => $this->order->fail_url, - 'Rnd' => $this->order->rand, - 'Hash' => $this->order->hash, - ]; - - if ($this->card) { - $inputs['CardHolderName'] = $this->card->getHolderName(); - $inputs['Pan'] = $this->card->getNumber(); - $inputs['Expiry'] = $this->card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT); - $inputs['Cvv2'] = $this->card->getCvv(); - } - - return [ - 'gateway' => null, //to be filled by the caller - 'inputs' => $inputs, - ]; - } - /** * @inheritDoc */ diff --git a/tests/DataMapper/PayForPosRequestDataMapperTest.php b/tests/DataMapper/PayForPosRequestDataMapperTest.php new file mode 100644 index 00000000..5df8aee7 --- /dev/null +++ b/tests/DataMapper/PayForPosRequestDataMapperTest.php @@ -0,0 +1,486 @@ +config = require __DIR__.'/../../config/pos.php'; + + $this->threeDAccount = AccountFactory::createPayForAccount( + 'qnbfinansbank-payfor', + '085300000009704', + 'QNB_API_KULLANICI_3DPAY', + 'UcBN0', + AbstractGateway::MODEL_3D_SECURE, + '12345678' + ); + + $this->order = [ + 'id' => '2020110828BC', + 'email' => 'mail@customer.com', // optional + 'name' => 'John Doe', // optional + 'amount' => 100.01, + 'installment' => '0', + 'currency' => 'TRY', + 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', + 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', + 'rand' => '0.43625700 1604831630', + 'lang' => PayForPos::LANG_TR, + ]; + + $this->pos = PosFactory::createPosGateway($this->threeDAccount); + $this->pos->setTestMode(true); + $this->requestDataMapper = new PayForPosRequestDataMapper(); + $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet'); + } + + /** + * @return void + */ + public function testCreateNonSecurePostAuthPaymentRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'amount' => 100.01, + 'installment' => '0', + 'currency' => 'TRY', + 'lang' => PayForPos::LANG_TR, + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_POST_PAY); + + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleNonSecurePaymentPostRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreateNonSecurePaymentRequestData() + { + $order = $this->order; + $pos = $this->pos; + $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet'); + $pos->prepare($order, AbstractGateway::TX_PAY, $card); + + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $card); + + $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DHash() + { + $order = [ + 'id' => '2020110828BC', + 'amount' => 100.01, + 'installment' => '0', + 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', + 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', + 'rand' => '0.43625700 1604831630', + ]; + $expected = 'zmSUxYPhmCj7QOzqpk/28LuE1Oc='; + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_PAY); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), 'Auth'); + $this->assertSame($expected, $actual); + } + + /** + * @return void + */ + public function testCreateCancelRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'currency' => 'TRY', + ]; + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_CANCEL); + + $actual = $this->requestDataMapper->createCancelRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleCancelXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreateHistoryRequestData() + { + $order = [ + 'orderId' => '2020110828BC', + 'reqDate' => '20220518', + ]; + $pos = $this->pos; + + $actual = $this->requestDataMapper->createHistoryRequestData($pos->getAccount(), (object) [], $order); + + $expectedData = $this->getSampleHistoryRequestData($pos->getAccount(), $order); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DPaymentRequestData() + { + $order = [ + 'id' => '2020110828BC', + ]; + $responseData = ['RequestGuid' => '1000000057437884']; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_PAY); + + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), '', $responseData); + + $expectedData = $this->getSample3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), $responseData); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testGet3DFormData() + { + $order = (object) $this->order; + $account = $this->threeDAccount; + $this->pos->prepare($this->order, AbstractGateway::TX_PAY); + $hash = $this->requestDataMapper->create3DHash($account, $this->pos->getOrder(), 'Auth'); + $card = $this->card; + $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test']; + + $inputs = [ + 'MbrId' => '5', + 'MerchantID' => $this->threeDAccount->getClientId(), + 'UserCode' => $this->threeDAccount->getUsername(), + 'OrderId' => $order->id, + 'Lang' => $order->lang, + 'SecureType' => '3DModel', + 'TxnType' => 'Auth', + 'PurchAmount' => $order->amount, + 'InstallmentCount' => 0, + 'Currency' => 949, + 'OkUrl' => $order->success_url, + 'FailUrl' => $order->fail_url, + 'Rnd' => $order->rand, + 'Hash' => $hash, + ]; + $form = [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + //test without card + $this->assertEquals($form, $this->requestDataMapper->create3DFormData( + $this->pos->getAccount(), + $this->pos->getOrder(), + 'Auth', + $gatewayURL + )); + + //test with card + if ($card) { + $form['inputs']['CardHolderName'] = $card->getHolderName(); + $form['inputs']['Pan'] = $card->getNumber(); + $form['inputs']['Expiry'] = '0122'; + $form['inputs']['Cvv2'] = $card->getCvv(); + } + + $this->assertEquals($form, $this->requestDataMapper->create3DFormData( + $this->pos->getAccount(), + $this->pos->getOrder(), + 'Auth', + $gatewayURL, + $card + )); + } + + /** + * @return void + */ + public function testGet3DHostFormData() + { + $account = AccountFactory::createPayForAccount( + 'qnbfinansbank-payfor', + '085300000009704', + 'QNB_API_KULLANICI_3DPAY', + 'UcBN0', + AbstractGateway::MODEL_3D_HOST, + '12345678' + ); + /** @var PayForPos $pos */ + $pos = PosFactory::createPosGateway($account); + $pos->setTestMode(true); + $pos->prepare($this->order, AbstractGateway::TX_PAY); + $order = $pos->getOrder(); + $hash = $this->requestDataMapper->create3DHash($account, $order, 'Auth'); + $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway_3d_host']['test']; + $inputs = [ + 'MbrId' => '5', + 'MerchantID' => $this->threeDAccount->getClientId(), + 'UserCode' => $this->threeDAccount->getUsername(), + 'OrderId' => $order->id, + 'Lang' => 'tr', + 'SecureType' => '3DHost', + 'TxnType' => 'Auth', + 'PurchAmount' => $order->amount, + 'InstallmentCount' => 0, + 'Currency' => 949, + 'OkUrl' => $order->success_url, + 'FailUrl' => $order->fail_url, + 'Rnd' => $order->rand, + 'Hash' => $hash, + ]; + $form = [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + + $this->assertEquals($form, $this->requestDataMapper->create3DFormData( + $pos->getAccount(), + $pos->getOrder(), + 'Auth', + $gatewayURL + )); + } + + /** + * @return void + */ + public function testCreateStatusRequestData() + { + $order = [ + 'id' => '2020110828BC', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_STATUS); + + $actualData = $this->requestDataMapper->createStatusRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleStatusRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actualData); + } + + /** + * @return void + */ + public function testCreateRefundRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'currency' => 'TRY', + 'amount' => 10.1, + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_REFUND); + + $actual = $this->requestDataMapper->createRefundRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleRefundXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @param AbstractPosAccount $account + * @param $order + * @param array $responseData + * + * @return array + */ + private function getSample3DPaymentRequestData(AbstractPosAccount $account, $order, array $responseData): array + { + return [ + 'RequestGuid' => $responseData['RequestGuid'], + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrderId' => $order->id, + 'SecureType' => '3DModelPayment', + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleCancelXMLData(AbstractPosAccount $account, $order): array + { + return [ + 'MbrId' => '5', + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrgOrderId' => $order->id, + 'SecureType' => 'NonSecure', + 'Lang' => 'tr', + 'TxnType' => 'Void', + 'Currency' => 949, + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * @param AbstractCreditCard $card + * + * @return array + */ + private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $account, $order, AbstractCreditCard $card): array + { + return [ + 'MbrId' => '5', + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'MOTO' => '0', + 'OrderId' => $order->id, + 'SecureType' => 'NonSecure', + 'TxnType' => 'Auth', + 'PurchAmount' => $order->amount, + 'Currency' => 949, + 'InstallmentCount' => 0, + 'Lang' => 'tr', + 'CardHolderName' => $card->getHolderName(), + 'Pan' => $card->getNumber(), + 'Expiry' => '0122', + 'Cvv2' => $card->getCvv(), + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'MbrId' => '5', + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrgOrderId' => $order->id, + 'SecureType' => 'NonSecure', + 'TxnType' => 'PostAuth', + 'PurchAmount' => $order->amount, + 'Currency' => 949, + 'Lang' => 'tr', + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleStatusRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'MbrId' => '5', + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrgOrderId' => $order->id, + 'SecureType' => 'Inquiry', + 'Lang' => 'tr', + 'TxnType' => 'OrderInquiry', + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleRefundXMLData(AbstractPosAccount $account, $order): array + { + return [ + 'MbrId' => '5', + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'OrgOrderId' => $order->id, + 'SecureType' => 'NonSecure', + 'Lang' => 'tr', + 'TxnType' => 'Refund', + 'PurchAmount' => $order->amount, + 'Currency' => 949, + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $customQueryData + * + * @return array + */ + private function getSampleHistoryRequestData(AbstractPosAccount $account, $customQueryData): array + { + $requestData = [ + 'MbrId' => '5', + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'SecureType' => 'Report', + 'TxnType' => 'TxnHistory', + 'Lang' => 'tr', + ]; + + if (isset($customQueryData['orderId'])) { + $requestData['OrderId'] = $customQueryData['orderId']; + } elseif (isset($customQueryData['reqDate'])) { + //ReqData YYYYMMDD format + $requestData['ReqDate'] = $customQueryData['reqDate']; + } + + return $requestData; + } +} diff --git a/tests/Gateways/PayForTest.php b/tests/Gateways/PayForTest.php index 3fcc78a6..e57594cd 100644 --- a/tests/Gateways/PayForTest.php +++ b/tests/Gateways/PayForTest.php @@ -1,5 +1,7 @@ 'http://localhost/finansbank-payfor/3d/response.php', 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'rand' => '0.43625700 1604831630', - 'hash' => 'zmSUxYPhmCj7QOzqpk/28LuE1Oc=', 'lang' => PayForPos::LANG_TR, ]; @@ -70,20 +62,24 @@ protected function setUp(): void $this->pos->setTestMode(true); $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet'); - - $this->xmlDecoder = new XmlEncoder(); } + /** + * @return void + */ public function testInit() { $this->assertEquals($this->config['banks'][$this->threeDAccount->getBank()], $this->pos->getConfig()); $this->assertEquals($this->threeDAccount, $this->pos->getAccount()); $this->assertNotEmpty($this->pos->getCurrencies()); + $this->assertEquals($this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway_3d_host']['test'], $this->pos->get3DHostGatewayURL()); $this->assertEquals($this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test'], $this->pos->get3DGatewayURL()); $this->assertEquals($this->config['banks'][$this->threeDAccount->getBank()]['urls']['test'], $this->pos->getApiURL()); - } + /** + * @return void + */ public function testSetTestMode() { $this->pos->setTestMode(false); @@ -92,85 +88,19 @@ public function testSetTestMode() $this->assertTrue($this->pos->isTestMode()); } - + /** + * @return void + */ public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); + $this->assertNotEmpty($this->pos->getOrder()); } - public function testGet3DFormDataWithCard() - { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $order = $this->pos->getOrder(); - $form = [ - 'gateway' => $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test'], - 'inputs' => [ - 'MbrId' => PayForPos::MBR_ID, - 'MerchantID' => $this->threeDAccount->getClientId(), - 'UserCode' => $this->threeDAccount->getUsername(), - 'OrderId' => $order->id, - 'Lang' => $order->lang, - 'SecureType' => '3DModel', - 'TxnType' => 'Auth', - 'PurchAmount' => $order->amount, - 'InstallmentCount' => $order->installment, - 'Currency' => $order->currency, - 'OkUrl' => $order->success_url, - 'FailUrl' => $order->fail_url, - 'Rnd' => $order->rand, - 'Hash' => $this->pos->create3DHash($this->pos->getAccount(), $this->pos->getOrder(), 'Auth'), - 'CardHolderName' => 'ahmet', - 'Pan' => '5555444433332222', - 'Expiry' => '0122', - 'Cvv2' => '123', - ], - ]; - $this->assertEquals($form, $this->pos->get3DFormData()); - } - - public function testGet3DFormDataWithoutCard() - { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY); - $order = $this->pos->getOrder(); - $form = [ - 'gateway' => $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test'], - 'inputs' => [ - 'MbrId' => PayForPos::MBR_ID, - 'MerchantID' => $this->threeDAccount->getClientId(), - 'UserCode' => $this->threeDAccount->getUsername(), - 'OrderId' => $order->id, - 'Lang' => $order->lang, - 'SecureType' => '3DModel', - 'TxnType' => 'Auth', - 'PurchAmount' => $order->amount, - 'InstallmentCount' => $order->installment, - 'Currency' => $order->currency, - 'OkUrl' => $order->success_url, - 'FailUrl' => $order->fail_url, - 'Rnd' => $order->rand, - 'Hash' => $this->pos->create3DHash($this->pos->getAccount(), $this->pos->getOrder(), 'Auth'), - ], - ]; - $this->assertEquals($form, $this->pos->get3DFormData()); - } - - public function testCreate3DHash() - { - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => '0', - 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'rand' => '0.43625700 1604831630', - ]; - $hash = 'zmSUxYPhmCj7QOzqpk/28LuE1Oc='; - $pos = $this->pos; - $pos->prepare($order, AbstractGateway::TX_PAY); - $this->assertEquals($hash, $this->pos->create3DHash($pos->getAccount(), $pos->getOrder(), 'Auth')); - } - + /** + * @return void + */ public function testCheck3DHash() { $data = [ @@ -187,265 +117,4 @@ public function testCheck3DHash() $data['3DStatus'] = ''; $this->assertFalse($this->pos->check3DHash($this->pos->getAccount(), $data)); } - - public function testCreateRegularPaymentXML() - { - - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - 'lang' => PayForPos::LANG_TR, - ]; - - /** - * @var PayForPos $pos - */ - $pos = PosFactory::createPosGateway($this->threeDAccount); - $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet'); - $pos->prepare($order, AbstractGateway::TX_PAY, $card); - - $actualXML = $pos->createRegularPaymentXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPaymentXMLData($pos->getOrder(), $pos->getCard(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateRegularPostXML() - { - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - 'lang' => PayForPos::LANG_TR, - ]; - - /** - * @var PayForPos $pos - */ - $pos = PosFactory::createPosGateway($this->threeDAccount); - $pos->prepare($order, AbstractGateway::TX_POST_PAY); - - $actualXML = $pos->createRegularPostXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPostXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreate3DPaymentXML() - { - - $order = [ - 'id' => '2020110828BC', - ]; - $responseData = ['RequestGuid' => '1000000057437884']; - - /** - * @var PayForPos $pos - */ - $pos = PosFactory::createPosGateway($this->threeDAccount); - $pos->prepare($order, AbstractGateway::TX_PAY); - - $actualXML = $pos->create3DPaymentXML($responseData); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSample3DPaymentXMLData($pos->getOrder(), $pos->getAccount(), $responseData); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateStatusXML() - { - $order = [ - 'id' => '2020110828BC', - ]; - - /** - * @var PayForPos $pos - */ - $pos = PosFactory::createPosGateway($this->threeDAccount); - $pos->prepare($order, AbstractGateway::TX_STATUS); - - $actualXML = $pos->createStatusXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleStatusXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateCancelXML() - { - $order = [ - 'id' => '2020110828BC', - 'currency' => 'TRY', - ]; - - /** - * @var PayForPos $pos - */ - $pos = PosFactory::createPosGateway($this->threeDAccount); - $pos->prepare($order, AbstractGateway::TX_CANCEL); - - $actualXML = $pos->createCancelXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleCancelXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateRefundXML() - { - $order = [ - 'id' => '2020110828BC', - 'currency' => 'TRY', - 'amount' => 10.1, - ]; - - /** - * @var PayForPos $pos - */ - $pos = PosFactory::createPosGateway($this->threeDAccount); - $pos->prepare($order, AbstractGateway::TX_REFUND); - - $actualXML = $pos->createRefundXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRefundXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - /** - * @param $order - * @param AbstractCreditCard $card - * @param PayForAccount $account - * - * @return array - */ - private function getSampleRegularPaymentXMLData($order, $card, $account) - { - return [ - 'MbrId' => PayForPos::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'MOTO' => PayForPos::MOTO, - 'OrderId' => $order->id, - 'SecureType' => 'NonSecure', - 'TxnType' => 'Auth', - 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, - 'InstallmentCount' => $order->installment, - 'Lang' => 'tr', - 'CardHolderName' => $card->getHolderName(), - 'Pan' => $card->getNumber(), - 'Expiry' => '0122', - 'Cvv2' => $card->getCvv(), - ]; - } - - /** - * @param $order - * @param PayForAccount $account - * - * @return array - */ - private function getSampleRegularPostXMLData($order, $account) - { - return [ - 'MbrId' => PayForPos::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'OrgOrderId' => $order->id, - 'SecureType' => 'NonSecure', - 'TxnType' => 'PostAuth', - 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, - 'Lang' => 'tr', - ]; - } - - /** - * @param $order - * @param PayForAccount $account - * @param array $responseData - * - * @return array - */ - private function getSample3DPaymentXMLData($order, $account, array $responseData) - { - return [ - 'RequestGuid' => $responseData['RequestGuid'], - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'OrderId' => $order->id, - 'SecureType' => '3DModelPayment', - ]; - } - - /** - * @param $order - * @param PayForAccount $account - * - * @return array - */ - private function getSampleStatusXMLData($order, $account) - { - return [ - 'MbrId' => PayForPos::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'OrgOrderId' => $order->id, - 'SecureType' => 'Inquiry', - 'Lang' => 'tr', - 'TxnType' => 'OrderInquiry', - ]; - } - - /** - * @param $order - * @param PayForAccount $account - * - * @return array - */ - private function getSampleCancelXMLData($order, $account) - { - return [ - 'MbrId' => PayForPos::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'OrgOrderId' => $order->id, - 'SecureType' => 'NonSecure', - 'Lang' => 'tr', - 'TxnType' => 'Void', - 'Currency' => $order->currency, - ]; - } - - /** - * @param $order - * @param PayForAccount $account - * - * @return array - */ - private function getSampleRefundXMLData($order, $account) - { - return [ - 'MbrId' => PayForPos::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'OrgOrderId' => $order->id, - 'SecureType' => 'NonSecure', - 'Lang' => 'tr', - 'TxnType' => 'Refund', - 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, - ]; - } } From ea707f70556bf0c242bb8f77b7270ee6671a12d1 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 23 Apr 2022 14:50:49 +0200 Subject: [PATCH 02/40] AbstractRequestDataMapper added mapCurrency() method --- src/DataMapper/AbstractRequestDataMapper.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/DataMapper/AbstractRequestDataMapper.php b/src/DataMapper/AbstractRequestDataMapper.php index db48ad79..b58e083c 100644 --- a/src/DataMapper/AbstractRequestDataMapper.php +++ b/src/DataMapper/AbstractRequestDataMapper.php @@ -1,5 +1,7 @@ currencyMappings; } + /** + * @param string $currency TRY, USD + * + * @return string currency code that is accepted by bank + */ + public function mapCurrency(string $currency): string + { + return $this->currencyMappings[$currency] ?? $currency; + } + /** * @return array */ From 8f9d8ea22a86e1f55abf436da1810ee08a790a25 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 23 Apr 2022 14:51:50 +0200 Subject: [PATCH 03/40] created PosNetRequestDataMapper and refactored PosNet --- src/DataMapper/PosNetRequestDataMapper.php | 407 +++++++++++++ src/Gateways/PosNet.php | 408 ++----------- .../PosNetRequestDataMapperTest.php | 551 ++++++++++++++++++ tests/Gateways/PosNetTest.php | 456 ++------------- 4 files changed, 1055 insertions(+), 767 deletions(-) create mode 100644 src/DataMapper/PosNetRequestDataMapper.php create mode 100644 tests/DataMapper/PosNetRequestDataMapperTest.php diff --git a/src/DataMapper/PosNetRequestDataMapper.php b/src/DataMapper/PosNetRequestDataMapper.php new file mode 100644 index 00000000..941482d2 --- /dev/null +++ b/src/DataMapper/PosNetRequestDataMapper.php @@ -0,0 +1,407 @@ + 'Sale', + AbstractGateway::TX_PRE_PAY => 'Auth', + AbstractGateway::TX_POST_PAY => 'Capt', + AbstractGateway::TX_CANCEL => 'reverse', + AbstractGateway::TX_REFUND => 'return', + AbstractGateway::TX_STATUS => 'agreement', + ]; + + /** + * @inheritdoc + */ + protected $currencyMappings = [ + 'TRY' => 'TL', + 'USD' => 'US', + 'EUR' => 'EU', + 'GBP' => 'GB', + 'JPY' => 'JP', + 'RUB' => 'RU', + ]; + + /** + * @param PosNetAccount $account + * + * @inheritDoc + */ + public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'oosTranData' => [ + 'bankData' => $responseData['BankPacket'], + 'merchantData' => $responseData['MerchantPacket'], + 'sign' => $responseData['Sign'], + 'wpAmount' => 0, + 'mac' => $this->create3DHash($account, $order, $txType), + ], + ]; + } + + /** + * @param PosNetAccount $account + * + * @inheritDoc + */ + public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array + { + $requestData = [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + strtolower($txType) => [ + 'orderID' => self::formatOrderId($order->id), + 'installment' => $order->installment, + 'amount' => $order->amount, + 'currencyCode' => $order->currency, + 'ccno' => $card->getNumber(), + 'expDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), + 'cvc' => $card->getCvv(), + ], + ]; + + if (isset($order->koiCode) && $order->koiCode > 0) { + $requestData[strtolower($txType)]['koiCode'] = $order->koiCode; + } + + return $requestData; + } + + /** + * @param PosNetAccount $account + * + * @inheritDoc + */ + public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + strtolower($this->txTypeMappings[AbstractGateway::TX_POST_PAY]) => [ + 'hostLogKey' => $order->host_ref_num, + 'amount' => $order->amount, + 'currencyCode' => $order->currency, + 'installment' => $order->installment, + ], + ]; + } + + /** + * @param PosNetAccount $account + * + * @inheritDoc + */ + public function createStatusRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + $this->txTypeMappings[AbstractGateway::TX_STATUS] => [ + 'orderID' => $order->id, + ], + ]; + } + + /** + * @param PosNetAccount $account + * + * @inheritDoc + */ + public function createCancelRequestData(AbstractPosAccount $account, $order): array + { + $txType = $this->txTypeMappings[AbstractGateway::TX_CANCEL]; + $requestData = [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + $txType => [ + 'transaction' => 'sale', + ], + ]; + + if (isset($order->auth_code)) { + $requestData[$txType]['authCode'] = $order->auth_code; + } + + //either will work + if (isset($order->host_ref_num)) { + $requestData[$txType]['hostLogKey'] = $order->host_ref_num; + } else { + $requestData[$txType]['orderID'] = $order->id; + } + + return $requestData; + } + + /** + * @param PosNetAccount $account + * + * @inheritDoc + */ + public function createRefundRequestData(AbstractPosAccount $account, $order): array + { + $requestData = [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + $this->txTypeMappings[AbstractGateway::TX_REFUND] => [ + 'amount' => $order->amount, + 'currencyCode' => $order->currency, + ], + ]; + + if (isset($order->host_ref_num)) { + $requestData[$this->txTypeMappings[AbstractGateway::TX_REFUND]]['hostLogKey'] = $order->host_ref_num; + } else { + $requestData[$this->txTypeMappings[AbstractGateway::TX_REFUND]]['orderID'] = $order->id; + } + + return $requestData; + } + + /** + * @inheritDoc + */ + public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array + { + throw new NotImplementedException(); + } + + + /** + * @param PosNetAccount $account + * + * @inheritDoc + * + * @throws Exception + */ + public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null, $extraData = null): array + { + $inputs = [ + 'mid' => $account->getClientId(), + 'posnetID' => $account->getPosNetId(), + 'vftCode' => $account->promotion_code ?? null, //todo bunun account icine veya order icin tasinmasi gerekiyor + 'posnetData' => $extraData['data1'], //Ödeme bilgilerini içermektedir. + 'posnetData2' => $extraData['data2'], //Kart bilgileri request içerisinde bulunuyorsa bu alan oluşturulmaktadır + 'digest' => $extraData['sign'], //Servis imzası. + 'merchantReturnURL' => $order->success_url, + 'url' => '', //todo belki kaldirabiliriz + 'lang' => $this->getLang($account, $order), + ]; + + if (isset($order->koiCode) && $order->koiCode > 0) { + $inputs['useJokerVadaa'] = 1; + } + + return [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + } + + /** + * @param PosNetAccount $account + * @param $order + * @param string $txType + * @param AbstractCreditCard $card + * + * @return array + */ + public function create3DEnrollmentCheckRequestData(AbstractPosAccount $account, $order, string $txType, AbstractCreditCard $card): array + { + if (null === $card->getHolderName() && isset($order->name)) { + $card->setHolderName($order->name); + } + + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'oosRequestData' => [ + 'posnetid' => $account->getPosNetId(), + 'ccno' => $card->getNumber(), + 'expDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), + 'cvc' => $card->getCvv(), + 'amount' => $order->amount, + 'currencyCode' => $order->currency, + 'installment' => $order->installment, + 'XID' => self::formatOrderId($order->id), + 'cardHolderName' => $card->getHolderName(), + 'tranType' => $txType, + ], + ]; + } + + /** + * @param PosNetAccount $account + * @param $order + * @param array $responseData + * + * @return array + */ + public function create3DResolveMerchantRequestData(AbstractPosAccount $account, $order, array $responseData): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'oosResolveMerchantData' => [ + 'bankData' => $responseData['BankPacket'], + 'merchantData' => $responseData['MerchantPacket'], + 'sign' => $responseData['Sign'], + 'mac' => $this->create3DHash($account, $order, ''), + ], + ]; + } + + + /** + * @param PosNetAccount $account + * + * @inheritDoc + */ + public function create3DHash(AbstractPosAccount $account, $order, string $txType): string + { + if ($account->getModel() === AbstractGateway::MODEL_3D_SECURE || $account->getModel() === AbstractGateway::MODEL_3D_PAY) { + $secondHashData = [ + self::formatOrderId($order->id), + $order->amount, + $order->currency, + $account->getClientId(), + $this->createSecurityData($account), + ]; + $hashStr = implode(static::HASH_SEPARATOR, $secondHashData); + + return $this->hashString($hashStr); + } + + return ''; + } + + /** + * Make Security Data + * + * @param PosNetAccount $account + * + * @return string + */ + public function createSecurityData(PosNetAccount $account): string + { + $hashData = [ + $account->getStoreKey(), + $account->getTerminalId(), + ]; + $hashStr = implode(static::HASH_SEPARATOR, $hashData); + + return $this->hashString($hashStr); + } + + /** + * Get amount + * formats 10.01 to 1001 + * + * @param float $amount + * + * @return int + */ + public static function amountFormat($amount): int + { + return round($amount, 2) * 100; + } + + /** + * formats installment in 00, 02, 06 format + * + * @param int|string $installment + * + * @return string + */ + public static function formatInstallment($installment): string + { + if ($installment > 1) { + return str_pad($installment, 2, '0', STR_PAD_LEFT); + } + + return '00'; + } + + /** + * Get PrefixedOrderId + * To check the status of an order or cancel/refund order Yapikredi + * - requires the order length to be 24 + * - and order id prefix which is "TDSC" for 3D payments + * + * @param string $orderId + * @param string $accountModel + * + * @return string + */ + public static function mapOrderIdToPrefixedOrderId(string $orderId, string $accountModel): string + { + $prefix = self::ORDER_ID_REGULAR_PREFIX; + if (AbstractGateway::MODEL_3D_SECURE === $accountModel) { + $prefix = self::ORDER_ID_3D_PREFIX; + } elseif (AbstractGateway::MODEL_3D_PAY === $accountModel) { + $prefix = self::ORDER_ID_3D_PAY_PREFIX; + } + + return $prefix.self::formatOrderId($orderId, self::ORDER_ID_TOTAL_LENGTH - strlen($prefix)); + } + + + /** + * formats order id by adding 0 pad to the left + * + * @param string $orderId + * @param int|null $padLength + * + * @return string + */ + public static function formatOrderId(string $orderId, int $padLength = null): string + { + if (null === $padLength) { + $padLength = self::ORDER_ID_LENGTH; + } + + return str_pad($orderId, $padLength, '0', STR_PAD_LEFT); + } +} diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 6b4898fd..d4d6bfcf 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -4,6 +4,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use Mews\Pos\DataMapper\PosNetRequestDataMapper; use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; use Mews\Pos\Exceptions\NotImplementedException; @@ -17,26 +18,8 @@ class PosNet extends AbstractGateway const LANG_TR = 'tr'; const LANG_EN = 'en'; - public const CREDIT_CARD_EXP_DATE_FORMAT = 'ym'; - - /** - * PosNet requires order id with specific length - */ - private const ORDER_ID_LENGTH = 20; - /** - * order Id total length including prefix; - */ - private const ORDER_ID_TOTAL_LENGTH = 24; - private const ORDER_ID_3D_PREFIX = 'TDSC'; - private const ORDER_ID_3D_PAY_PREFIX = ''; //? - private const ORDER_ID_REGULAR_PREFIX = ''; //? - protected const HASH_ALGORITHM = 'sha256'; protected const HASH_SEPARATOR = ';'; - - /** - * @const string - */ public const NAME = 'PosNet'; /** @@ -69,56 +52,20 @@ class PosNet extends AbstractGateway '0444' => 'bank_call', ]; - /** - * Transaction Types - * - * @var array - */ - protected $types = [ - self::TX_PAY => 'Sale', - self::TX_PRE_PAY => 'Auth', - self::TX_POST_PAY => 'Capt', - self::TX_CANCEL => 'reverse', - self::TX_REFUND => 'return', - self::TX_STATUS => 'agreement', - ]; - - /** - * Fixed Currencies - * @var array - */ - protected $currencies = [ - 'TRY' => 'TL', - 'USD' => 'US', - 'EUR' => 'EU', - 'GBP' => 'GB', - 'JPY' => 'JP', - 'RUB' => 'RU', - ]; + /** @var PosNetAccount */ + protected $account; - /** - * API Account - * - * @var PosNetAccount - */ - protected $account = []; - - /** - * @var AbstractCreditCard|null - */ + /** @var AbstractCreditCard|null */ protected $card; - /** - * Request - * - * @var Request - */ + /** @var Request */ protected $request; - /** - * @var PosNetCrypt|null - */ - public $crypt; + /** @var PosNetCrypt|null */ + private $crypt; + + /** @var PosNetRequestDataMapper */ + private $requestDataMapper; /** * PosNet constructor. @@ -129,7 +76,11 @@ class PosNet extends AbstractGateway */ public function __construct($config, $account, array $currencies) { - $this->crypt = new PosNetCrypt(); + $this->crypt = new PosNetCrypt(); + $this->requestDataMapper = new PosNetRequestDataMapper($currencies); + $this->types = $this->requestDataMapper->getTxTypeMappings(); + $this->currencies = $this->requestDataMapper->getCurrencyMappings(); + $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); parent::__construct($config, $account, $currencies); } @@ -151,59 +102,34 @@ public function make3DHostPayment(Request $request) /** * Get OOS transaction data - * + * siparis bilgileri ve kart bilgilerinin şifrelendiği adımdır. * @return object * * @throws GuzzleException */ public function getOosTransactionData() { - $requestData = $this->getOosTransactionRequestData($this->account, $this->card, $this->order, $this->type); + $requestData = $this->requestDataMapper->create3DEnrollmentCheckRequestData($this->account, $this->order, $this->type, $this->card); $xml = $this->createXML($requestData); return $this->send($xml); } /** - * @param PosNetAccount $account - * @param AbstractCreditCard $card - * @param $order - * @param string $txType - * - * @return array - */ - public function getOosTransactionRequestData(PosNetAccount $account, AbstractCreditCard $card, $order, string $txType): array - { - if (null === $card->getHolderName() && isset($order->name)) { - $card->setHolderName($order->name); - } - - return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'oosRequestData' => [ - 'posnetid' => $account->getPosNetId(), - 'ccno' => $card->getNumber(), - 'expDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), - 'cvc' => $card->getCvv(), - 'amount' => $order->amount, - 'currencyCode' => $order->currency, - 'installment' => $order->installment, - 'XID' => self::formatOrderId($order->id), - 'cardHolderName' => $card->getHolderName(), - 'tranType' => $txType, - ], - ]; - } - - /** + * Kullanıcı doğrulama sonucunun sorgulanması ve verilerin doğruluğunun teyit edilmesi için kullanılır. * @inheritDoc */ public function make3DPayment(Request $request) { $bankResponse = null; if ($this->check3DHash($request->request->all())) { - $contents = $this->create3DResolveMerchantDataXML($request->request->all()); + $requestData = $this->requestDataMapper->create3DResolveMerchantRequestData( + $this->account, + $this->order, + $request->request->all() + ); + + $contents = $this->createXML($requestData); $bankResponse = $this->send($contents); } else { goto end; @@ -249,30 +175,13 @@ public function get3DFormData(): array } $data = $this->getOosTransactionData(); - if (!$data->approved) { - throw new \Exception($data->respText, $data->respCode); - } - - $inputs = [ - 'posnetData' => $data->oosRequestDataResponse->data1 ?? '', - 'posnetData2' => $data->oosRequestDataResponse->data2 ?? '', - 'mid' => $this->account->getClientId(), - 'posnetID' => $this->account->getPosNetId(), - 'digest' => $data->oosRequestDataResponse->sign ?? '', - 'vftCode' => $this->account->promotion_code ?? null, - 'merchantReturnURL' => $this->order->success_url, - 'url' => '', - 'lang' => $this->getLang(), - ]; + $data = parent::emptyStringsToNull($data); - if (isset($this->order->koiCode) && $this->order->koiCode > 0) { - $inputs['useJokerVadaa'] = 1; + if ('0' === $data['approved']) { + throw new \Exception($data['respText'], $data['respCode']); } - return [ - 'gateway' => $this->get3DGatewayURL(), - 'inputs' => $inputs, - ]; + return $this->requestDataMapper->create3DFormData($this->account, $this->order, $this->type, $this->get3DGatewayURL(), $this->card, $data['oosRequestDataResponse']); } /** @@ -304,32 +213,6 @@ public function getAccount() return $this->account; } - /** - * Create 3D Hash (MAC) - * - * @param PosNetAccount $account - * @param $order - * - * @return string - */ - public function create3DHash(PosNetAccount $account, $order): string - { - if ($account->getModel() === self::MODEL_3D_SECURE || $account->getModel() === self::MODEL_3D_PAY) { - $secondHashData = [ - self::formatOrderId($order->id), - $order->amount, - $order->currency, - $account->getClientId(), - $this->createSecurityData($account), - ]; - $hashStr = implode(static::HASH_SEPARATOR, $secondHashData); - - return $this->hashString($hashStr); - } - - return ''; - } - /** * verifies the if request came from bank * @@ -346,11 +229,11 @@ public function verifyResponseMAC(PosNetAccount $account, $order, $data): bool if ($account->getModel() === self::MODEL_3D_SECURE || $account->getModel() === self::MODEL_3D_PAY) { $secondHashData = [ $data->mdStatus, - self::formatOrderId($order->id), + $this->requestDataMapper::formatOrderId($order->id), $order->amount, $order->currency, $account->getClientId(), - $this->createSecurityData($account), + $this->requestDataMapper->createSecurityData($account), ]; $hashStr = implode(static::HASH_SEPARATOR, $secondHashData); } @@ -358,99 +241,12 @@ public function verifyResponseMAC(PosNetAccount $account, $order, $data): bool return $this->hashString($hashStr) === $data->mac; } - /** - * formats order id by adding 0 pad to the left - * - * @param $orderId - * @param int|null $padLength - * - * @return string - */ - public static function formatOrderId($orderId, int $padLength = null): string - { - if (null === $padLength) { - $padLength = self::ORDER_ID_LENGTH; - } - - return str_pad($orderId, $padLength, '0', STR_PAD_LEFT); - } - - /** - * Get amount - * formats 10.01 to 1001 - * - * @param float $amount - * - * @return int - */ - public static function amountFormat($amount): int - { - return round($amount, 2) * 100; - } - - /** - * Get PrefixedOrderId - * To check the status of an order or cancel/refund order Yapikredi - * - requires the order length to be 24 - * - and order id prefix which is "TDSC" for 3D payments - * - * @param string $orderId - * @param string $accountModel - * - * @return string - */ - public static function mapOrderIdToPrefixedOrderId(string $orderId, string $accountModel): string - { - $prefix = self::ORDER_ID_REGULAR_PREFIX; - if (self::MODEL_3D_SECURE === $accountModel) { - $prefix = self::ORDER_ID_3D_PREFIX; - } elseif (self::MODEL_3D_PAY === $accountModel) { - $prefix = self::ORDER_ID_3D_PAY_PREFIX; - } - - return $prefix.self::formatOrderId($orderId, self::ORDER_ID_TOTAL_LENGTH - strlen($prefix)); - } - - - /** - * formats installment in 00, 02, 06 format - * - * @param int|string $installment - * - * @return string - */ - public static function formatInstallment($installment): string - { - if ($installment > 1) { - return str_pad($installment, 2, '0', STR_PAD_LEFT); - } - - return '00'; - } - /** * @inheritDoc */ public function createRegularPaymentXML() { - $requestData = [ - 'mid' => $this->account->getClientId(), - 'tid' => $this->account->getTerminalId(), - 'tranDateRequired' => '1', - strtolower($this->type) => [ - 'orderID' => self::formatOrderId($this->order->id), - 'installment' => $this->order->installment, - 'amount' => $this->order->amount, - 'currencyCode' => $this->order->currency, - 'ccno' => $this->card->getNumber(), - 'expDate' => $this->card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), - 'cvc' => $this->card->getCvv(), - ], - ]; - - if (isset($this->order->koiCode) && $this->order->koiCode > 0) { - $requestData[strtolower($this->type)]['koiCode'] = $this->order->koiCode; - } + $requestData = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $this->order, $this->type, $this->card); return $this->createXML($requestData); } @@ -460,17 +256,7 @@ public function createRegularPaymentXML() */ public function createRegularPostXML() { - $requestData = [ - 'mid' => $this->account->getClientId(), - 'tid' => $this->account->getTerminalId(), - 'tranDateRequired' => '1', - strtolower($this->types[self::TX_POST_PAY]) => [ - 'hostLogKey' => $this->order->host_ref_num, - 'amount' => $this->order->amount, - 'currencyCode' => $this->order->currency, - 'installment' => $this->order->installment, - ], - ]; + $requestData = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -480,38 +266,7 @@ public function createRegularPostXML() */ public function create3DPaymentXML($responseData) { - $requestData = [ - 'mid' => $this->account->getClientId(), - 'tid' => $this->account->getTerminalId(), - 'oosTranData' => [ - 'bankData' => $responseData['BankPacket'], - 'merchantData' => $responseData['MerchantPacket'], - 'sign' => $responseData['Sign'], - 'wpAmount' => 0, - 'mac' => $this->create3DHash($this->account, $this->order), - ], - ]; - - return $this->createXML($requestData); - } - - /** - * @param $responseData - * - * @return string - */ - public function create3DResolveMerchantDataXML($responseData) - { - $requestData = [ - 'mid' => $this->account->getClientId(), - 'tid' => $this->account->getTerminalId(), - 'oosResolveMerchantData' => [ - 'bankData' => $responseData['BankPacket'], - 'merchantData' => $responseData['MerchantPacket'], - 'sign' => $responseData['Sign'], - 'mac' => $this->create3DHash($this->account, $this->order), - ], - ]; + $requestData = $this->requestDataMapper->create3DPaymentRequestData($this->account, $this->order, '', $responseData); return $this->createXML($requestData); } @@ -531,13 +286,7 @@ public function createHistoryXML($customQueryData) */ public function createStatusXML() { - $requestData = [ - 'mid' => $this->account->getClientId(), - 'tid' => $this->account->getTerminalId(), - $this->types[self::TX_STATUS] => [ - 'orderID' => $this->order->id, - ], - ]; + $requestData = $this->requestDataMapper->createStatusRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -547,25 +296,7 @@ public function createStatusXML() */ public function createCancelXML() { - $requestData = [ - 'mid' => $this->account->getClientId(), - 'tid' => $this->account->getTerminalId(), - 'tranDateRequired' => '1', - $this->types[self::TX_CANCEL] => [ - 'transaction' => 'sale', - ], - ]; - - if (isset($this->order->auth_code)) { - $requestData[$this->types[self::TX_CANCEL]]['authCode'] = $this->order->auth_code; - } - - //either will work - if (isset($this->order->host_ref_num)) { - $requestData[$this->types[self::TX_CANCEL]]['hostLogKey'] = $this->order->host_ref_num; - } else { - $requestData[$this->types[self::TX_CANCEL]]['orderID'] = $this->order->id; - } + $requestData = $this->requestDataMapper->createCancelRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -575,21 +306,7 @@ public function createCancelXML() */ public function createRefundXML() { - $requestData = [ - 'mid' => $this->account->getClientId(), - 'tid' => $this->account->getTerminalId(), - 'tranDateRequired' => '1', - $this->types[self::TX_REFUND] => [ - 'amount' => $this->order->amount, - 'currencyCode' => $this->order->currency, - ], - ]; - - if (isset($this->order->host_ref_num)) { - $requestData[$this->types[self::TX_REFUND]]['hostLogKey'] = $this->order->host_ref_num; - } else { - $requestData[$this->types[self::TX_REFUND]]['orderID'] = $this->order->id; - } + $requestData = $this->requestDataMapper->createRefundRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -636,7 +353,7 @@ protected function check3DHash(array $data): bool $this->account->getTerminalId(), $this->order->amount, ((int) $this->order->installment), - self::formatOrderId($this->order->id), + $this->requestDataMapper::formatOrderId($this->order->id), ]); $decryptedDataList = array_map('strval', [ @@ -733,7 +450,7 @@ protected function mapPaymentResponse($responseData): array return [ 'id' => isset($responseData->authCode) ? $this->printData($responseData->authCode) : null, 'order_id' => $this->order->id, - 'fixed_order_id' => self::formatOrderId($this->order->id), + 'fixed_order_id' => $this->requestDataMapper::formatOrderId($this->order->id), 'group_id' => isset($responseData->groupID) ? $this->printData($responseData->groupID) : null, 'trans_id' => isset($responseData->authCode) ? $this->printData($responseData->authCode) : null, 'response' => $this->getStatusDetail(), @@ -870,7 +587,7 @@ protected function mapStatusResponse($rawResponseData) return (object) [ 'id' => $authCode, 'order_id' => isset($this->order->id) ? $this->printData($this->order->id) : null, - 'fixed_order_id' => self::formatOrderId($this->order->id), + 'fixed_order_id' => $this->requestDataMapper::formatOrderId($this->order->id), 'group_id' => isset($rawResponseData->transactions->transaction->groupID) ? $this->printData($rawResponseData->transactions->transaction->groupID) : null, 'trans_id' => $authCode, 'response' => $this->getStatusDetail(), @@ -998,10 +715,10 @@ protected function preparePaymentOrder(array $order) } return (object) array_merge($order, [ - 'id' => self::formatOrderId($order['id']), - 'installment' => self::formatInstallment($installment), - 'amount' => self::amountFormat($order['amount']), - 'currency' => $this->mapCurrency($order['currency']), + 'id' => $this->requestDataMapper::formatOrderId($order['id']), + 'installment' => $this->requestDataMapper::formatInstallment($installment), + 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), ]); } @@ -1017,11 +734,11 @@ protected function preparePostPaymentOrder(array $order) } return (object) [ - 'id' => self::formatOrderId($order['id']), + 'id' => $this->requestDataMapper::formatOrderId($order['id']), + 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'installment' => $this->requestDataMapper::formatInstallment($installment), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), 'host_ref_num' => $order['host_ref_num'], - 'amount' => self::amountFormat($order['amount']), - 'currency' => $this->mapCurrency($order['currency']), - 'installment' => self::formatInstallment($installment), ]; } @@ -1031,7 +748,7 @@ protected function preparePostPaymentOrder(array $order) protected function prepareStatusOrder(array $order) { return (object) [ - 'id' => self::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()), + 'id' => $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()), ]; } @@ -1050,7 +767,7 @@ protected function prepareCancelOrder(array $order) { return (object) [ //id or host_ref_num - 'id' => isset($order['id']) ? self::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, + 'id' => isset($order['id']) ? $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, 'host_ref_num' => $order['host_ref_num'] ?? null, //optional 'auth_code' => $order['auth_code'] ?? null, @@ -1064,29 +781,10 @@ protected function prepareRefundOrder(array $order) { return (object) [ //id or host_ref_num - 'id' => isset($order['id']) ? self::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, + 'id' => isset($order['id']) ? $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, 'host_ref_num' => $order['host_ref_num'] ?? null, - 'amount' => self::amountFormat($order['amount']), - 'currency' => self::mapCurrency($order['currency']), - ]; - } - - - /** - * Make Security Data - * - * @param PosNetAccount $account - * - * @return string - */ - private function createSecurityData(PosNetAccount $account): string - { - $hashData = [ - $account->getStoreKey(), - $account->getTerminalId(), + 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), ]; - $hashStr = implode(static::HASH_SEPARATOR, $hashData); - - return$this->hashString($hashStr); } } diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php new file mode 100644 index 00000000..3c2d6de3 --- /dev/null +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -0,0 +1,551 @@ +config = require __DIR__.'/../../config/pos.php'; + + $this->threeDAccount = AccountFactory::createPosNetAccount( + 'yapikredi', + '6706598320', + 'XXXXXX', + 'XXXXXX', + '67005551', + '27426', + AbstractGateway::MODEL_3D_SECURE, + '10,10,10,10,10,10,10,10' + ); + + $this->order = [ + 'id' => 'YKB_TST_190620093100_024', + 'name' => 'siparis veren', + 'email' => 'test@test.com', + 'amount' => '1.75', + 'installment' => 0, + 'currency' => 'TL', + 'success_url' => 'https://domain.com/success', + 'fail_url' => 'https://domain.com/fail_url', + 'rand' => '0.43625700 1604831630', + 'lang' => PosNet::LANG_TR, + ]; + + $this->pos = PosFactory::createPosGateway($this->threeDAccount); + $this->pos->setTestMode(true); + $this->requestDataMapper = new PosNetRequestDataMapper(); + $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet'); + } + + /** + * @return void + */ + public function testAmountFormat() + { + $this->assertSame(100000, PosNetRequestDataMapper::amountFormat(1000)); + $this->assertSame(100000, PosNetRequestDataMapper::amountFormat(1000.00)); + $this->assertSame(100001, PosNetRequestDataMapper::amountFormat(1000.01)); + } + + /** + * @return void + */ + public function testFormatInstallment() + { + $this->assertSame('00', PosNetRequestDataMapper::formatInstallment(0)); + $this->assertSame('00', PosNetRequestDataMapper::formatInstallment(1)); + $this->assertSame('02', PosNetRequestDataMapper::formatInstallment(2)); + } + + /** + * @return void + */ + public function testMapOrderIdToPrefixedOrderId() + { + $this->assertSame('TDSC00000000000000000010', PosNetRequestDataMapper::mapOrderIdToPrefixedOrderId(10, AbstractGateway::MODEL_3D_SECURE)); + $this->assertSame('000000000000000000000010', PosNetRequestDataMapper::mapOrderIdToPrefixedOrderId(10, AbstractGateway::MODEL_3D_PAY)); + $this->assertSame('000000000000000000000010', PosNetRequestDataMapper::mapOrderIdToPrefixedOrderId(10, AbstractGateway::MODEL_NON_SECURE)); + } + + /** + * @return void + */ + public function testCreateSecurityData() + { + $this->assertSame('c1PPl+2UcdixyhgLYnf4VfJyFGaNQNOwE0uMkci7Uag=', $this->requestDataMapper->createSecurityData($this->threeDAccount)); + } + + /** + * @return void + */ + public function testFormatOrderIdd() + { + $this->assertSame('0010', PosNetRequestDataMapper::formatOrderId(10, 4)); + $this->assertSame('12345', PosNetRequestDataMapper::formatOrderId(12345, 4)); + } + + /** + * @return void + */ + public function testCreateNonSecurePostAuthPaymentRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'host_ref_num' => '019676067890000191', + 'amount' => 10.02, + 'currency' => 'TRY', + 'installment' => '2', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_POST_PAY); + + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleNonSecurePaymentPostRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreateNonSecurePaymentRequestData() + { + $order = $this->order; + $pos = $this->pos; + $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet'); + $pos->prepare($order, AbstractGateway::TX_PAY, $card); + + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'sale', $card); + + $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DHash() + { + $expected = 'J/7/Xprj7F/KDf98luVfIGyUPRQzUCqGwpmvz3KT7oQ='; + $pos = $this->pos; + $pos->prepare($this->order, AbstractGateway::TX_PAY); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), ''); + $this->assertSame($expected, $actual); + } + + /** + * @return void + */ + public function testCreateCancelRequestData() + { + $pos = $this->pos; + $order = [ + 'id' => '2020110828BC', + ]; + $pos->prepare($order, AbstractGateway::TX_CANCEL); + $actual = $this->requestDataMapper->createCancelRequestData($pos->getAccount(), $pos->getOrder()); + $expectedData = $this->getSampleCancelXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + + $order = [ + 'host_ref_num' => '2020110828BCNUM', + ]; + $pos->prepare($order, AbstractGateway::TX_CANCEL); + $actual = $this->requestDataMapper->createCancelRequestData($pos->getAccount(), $pos->getOrder()); + $expectedData = $this->getSampleCancelXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DPaymentRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'amount' => 100.01, + 'installment' => '0', + 'currency' => 'TRY', + ]; + $responseData = [ + 'BankPacket' => 'F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', + 'MerchantPacket' => 'E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', + 'Sign' => '9998F61E1D0C0FB6EC5203A748124F30', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_PAY); + + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), '', $responseData); + + $expectedData = $this->getSample3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), $responseData); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DEnrollmentCheckRequestData() + { + $pos = $this->pos; + $pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $expected = $this->getSample3DEnrollmentCheckRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); + $actual = $this->requestDataMapper->create3DEnrollmentCheckRequestData($pos->getAccount(), $pos->getOrder(), 'Sale', $pos->getCard()); + $this->assertEquals($expected, $actual); + } + + /** + * @return void + */ + public function testCreate3DResolveMerchantRequestData() + { + $pos = $this->pos; + $order = [ + 'id' => '2020110828BC', + 'amount' => 100.01, + 'installment' => '0', + 'currency' => 'TRY', + ]; + $responseData = [ + 'BankPacket' => 'F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', + 'MerchantPacket' => 'E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', + 'Sign' => '9998F61E1D0C0FB6EC5203A748124F30', + ]; + + $pos->prepare($order, AbstractGateway::TX_PAY); + + $actualData = $this->requestDataMapper->create3DResolveMerchantRequestData($pos->getAccount(), $pos->getOrder(), $responseData); + $expectedData = $this->getSampleResolveMerchantDataXMLData($pos->getAccount(), $responseData); + $this->assertEquals($expectedData, $actualData); + } + + /** + * @return void + * + * @throws Exception + */ + public function testCreate3DFormData() + { + $gatewayURL = 'https://setmpos.ykb.com/3DSWebService/YKBPaymentService'; + $ooTxSuccessData = $this->getSample3DEnrollmentCheckResponseData(); + $pos = $this->pos; + $pos->prepare($this->order, AbstractGateway::TX_PAY); + + $expected = $this->requestDataMapper->create3DFormData( + $pos->getAccount(), + $pos->getOrder(), + '', + $gatewayURL, + null, + $ooTxSuccessData['oosRequestDataResponse'] + ); + $actual = $this->getSample3DFormData($pos->getAccount(), $pos->getOrder(), $ooTxSuccessData['oosRequestDataResponse'], $gatewayURL); + $this->assertEquals($expected, $actual); + } + + /** + * @return void + */ + public function testCreateStatusRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'type' => 'status', + ]; + + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_STATUS); + + $actualData = $this->requestDataMapper->createStatusRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleStatusRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actualData); + } + + /** + * @return void + */ + public function testCreateRefundRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'amount' => 50, + 'currency' => 'TRY', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_REFUND); + + $actual = $this->requestDataMapper->createRefundRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleRefundXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @param PosNetAccount $account + * @param $order + * @param $oosTxResponseData + * @param string $gatewayURL + * + * @return array + */ + private function getSample3DFormData(AbstractPosAccount $account, $order, $oosTxResponseData, string $gatewayURL): array + { + $inputs = [ + 'posnetData' => $oosTxResponseData['data1'], + 'posnetData2' => $oosTxResponseData['data2'], + 'mid' => $account->getClientId(), + 'posnetID' => $account->getPosNetId(), + 'digest' => $oosTxResponseData['sign'], + 'vftCode' => $account->promotion_code ?? null, + 'merchantReturnURL' => $order->success_url, + 'url' => '', + 'lang' => 'tr', + ]; + + return [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + } + + /** + * @return array + */ + private function getSample3DEnrollmentCheckResponseData(): array + { + return [ + 'approved' => '1', //1:Başarılı + 'respCode' => '', + 'respText' => '', + 'oosRequestDataResponse' => [ + 'data1' => 'AEFE78BFC852867FF57078B723E284D1BD52EED8264C6CBD110A1A9EA5EAA7533D1A82EFD614032D686C507738FDCDD2EDD00B22DEFEFE0795DC4674C16C02EBBFEC9DF0F495D5E23BE487A798BF8293C7C1D517D9600C96CBFD8816C9D8F8257442906CB9B10D8F1AABFBBD24AA6FB0E5533CDE67B0D9EA5ED621B91BF6991D5362182302B781241B56E47BAE1E86BC3D5AE7606212126A4E97AFC2', + 'data2' => '69D04861340091B7014B15158CA3C83413031B406F08B3792A0114C9958E6F0F216966C5EE32EAEEC7158BFF59DFCB77E20CD625', + 'sign' => '9998F61E1D0C0FB6EC5203A748124F30', + ], + ]; + } + + /** + * @param PosNetAccount $account + * @param $order + * @param array $responseData + * + * @return array + */ + private function getSample3DPaymentRequestData(AbstractPosAccount $account, $order, array $responseData): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'oosTranData' => [ + 'bankData' => $responseData['BankPacket'], + 'merchantData' => $responseData['MerchantPacket'], + 'sign' => $responseData['Sign'], + 'wpAmount' => 0, + 'mac' => $this->requestDataMapper->create3DHash($account, $order, ''), + ], + ]; + } + + /** + * @param PosNetAccount $account + * @param $order + * + * @return array + */ + private function getSampleCancelXMLData(AbstractPosAccount $account, $order): array + { + $requestData = [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + 'reverse' => [ + 'transaction' => 'sale', + ], + ]; + + //either will work + if (isset($order->host_ref_num)) { + $requestData['reverse']['hostLogKey'] = $order->host_ref_num; + } else { + $requestData['reverse']['orderID'] = $order->id; + } + + return $requestData; + } + + /** + * @param PosNetAccount $account + * @param $order + * @param AbstractCreditCard $card + * + * @return array + */ + private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $account, $order, AbstractCreditCard $card): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + 'sale' => [ + 'orderID' => $order->id, + 'installment' => $order->installment, + 'amount' => 175, + 'currencyCode' => 'TL', + 'ccno' => $card->getNumber(), + 'expDate' => '2201', + 'cvc' => $card->getCvv(), + ], + ]; + } + + /** + * @param PosNetAccount $account + * @param $order + * + * @return array + */ + private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + 'capt' => [ + 'hostLogKey' => $order->host_ref_num, + 'amount' => $order->amount, + 'currencyCode' => $order->currency, + 'installment' => $order->installment, + ], + ]; + } + + /** + * @param PosNetAccount $account + * @param $order + * + * @return array + */ + private function getSampleStatusRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'agreement' => [ + 'orderID' => $order->id, + ], + ]; + } + + /** + * @param PosNetAccount $account + * @param $order + * + * @return array + */ + private function getSampleRefundXMLData(AbstractPosAccount $account, $order): array + { + $requestData = [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + 'return' => [ + 'amount' => 5000, + 'currencyCode' => 'TL', + ], + ]; + + if (isset($order->host_ref_num)) { + $requestData['return']['hostLogKey'] = $order->host_ref_num; + } else { + $requestData['return']['orderID'] = $order->id; + } + + return $requestData; + } + + /** + * @param PosNetAccount $account + * @param $order + * @param AbstractCreditCard $card + * + * @return array + */ + private function getSample3DEnrollmentCheckRequestData(PosNetAccount $account, $order, AbstractCreditCard $card): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'oosRequestData' => [ + 'posnetid' => $account->getPosNetId(), + 'ccno' => $card->getNumber(), + 'expDate' => '2201', + 'cvc' => $this->card->getCvv(), + 'amount' => 175, + 'currencyCode' => 'TL', + 'installment' => $order->installment, + 'XID' => $this->requestDataMapper::formatOrderId($order->id), + 'cardHolderName' => $card->getHolderName(), + 'tranType' => 'Sale', + ], + ]; + } + + /** + * @param PosNetAccount $account + * @param array $responseData + * + * @return array + */ + private function getSampleResolveMerchantDataXMLData(AbstractPosAccount $account, array $responseData): array + { + return [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'oosResolveMerchantData' => [ + 'bankData' => $responseData['BankPacket'], + 'merchantData' => $responseData['MerchantPacket'], + 'sign' => $responseData['Sign'], + 'mac' => 'oE7zwV87uOc2DFpGPlr4jQRQ0z9LsxGw56c7vaiZkTo=', + ], + ]; + } +} diff --git a/tests/Gateways/PosNetTest.php b/tests/Gateways/PosNetTest.php index c541ff85..0db09f3b 100644 --- a/tests/Gateways/PosNetTest.php +++ b/tests/Gateways/PosNetTest.php @@ -1,7 +1,10 @@ pos->setTestMode(true); $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '21', '12', '122', 'ahmet'); - - $this->xmlDecoder = new XmlEncoder(); } + /** + * @return void + */ public function testInit() { $this->assertEquals($this->config['banks'][$this->account->getBank()], $this->pos->getConfig()); @@ -81,52 +77,53 @@ public function testInit() $this->assertNotEmpty($this->pos->getCurrencies()); } + /** + * @return void + */ public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); } - public function testCreate3DHash() + /** + * @return void + * + * @throws Exception + */ + public function testGet3DFormDataOosTransactionFail() { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $actual = $this->pos->create3DHash($this->pos->getAccount(), $this->pos->getOrder()); - $this->assertEquals('J/7/Xprj7F/KDf98luVfIGyUPRQzUCqGwpmvz3KT7oQ=', $actual); - } + $this->expectException(Exception::class); + $this->expectExceptionCode(3); - public function testCreate3DHashForNon3DSecure() - { - $account = AccountFactory::createPosNetAccount( - 'yapikredi', - '6706598320', - 'XXXXXX', - 'XXXXXX', - '67005551', - '27426', - AbstractGateway::MODEL_NON_SECURE, - '10,10,10,10,10,10,10,10' - ); - /** @var PosNet $pos */ - $pos = PosFactory::createPosGateway($account); + $posMock = $this->getMockBuilder(PosNet::class) + ->setConstructorArgs([[], $this->account, []]) + ->onlyMethods(['getOosTransactionData']) + ->getMock(); + $posMock->setTestMode(true); + $posMock->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $posMock->expects($this->once())->method('getOosTransactionData')->willReturn($this->getSampleOoTransactionFailResponseData()); - $pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $actual = $pos->create3DHash($pos->getAccount(), $pos->getOrder()); - $this->assertEquals('', $actual); + $posMock->get3DFormData(); } - public function testAmountFormat() + /** + * @return string[] + */ + private function getSampleOoTransactionFailResponseData(): array { - $this->assertEquals(100000, PosNet::amountFormat(1000)); - $this->assertEquals(100000, PosNet::amountFormat(1000.00)); - $this->assertEquals(100001, PosNet::amountFormat(1000.01)); + return [ + 'approved' => '0', + 'respCode' => '0003', + 'respText' => '148 MID,TID,IP HATALI:89.244.149.137', + ]; } public function testVerifyResponseMAC() { - - $newOrder = $this->order; - $newOrder['id'] = '895'; - $newOrder['amount'] = 1; + $newOrder = $this->order; + $newOrder['id'] = '895'; + $newOrder['amount'] = 1; $newOrder['currency'] = 'TL'; $account = AccountFactory::createPosNetAccount( @@ -158,369 +155,4 @@ public function testVerifyResponseMAC() ]; $this->assertFalse($pos->verifyResponseMAC($pos->getAccount(), $pos->getOrder(), $data)); } - - public function testCreateRegularPaymentXML() - { - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => '2', - 'currency' => 'TRY', - ]; - - - /** - * @var PosNet $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet'); - $pos->prepare($order, AbstractGateway::TX_PAY, $card); - - $actualXML = $pos->createRegularPaymentXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPaymentXMLData($pos->getOrder(), $pos->getCard(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - //$this->assertEquals([], $actualData['sale']); - } - - public function testCreateRegularPostXML() - { - $order = [ - 'id' => '2020110828BC', - 'host_ref_num' => '019676067890000191', - 'amount' => 10.02, - 'currency' => 'TRY', - 'installment' => '2', - ]; - - /** - * @var PosNet $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_POST_PAY); - - $actualXML = $pos->createRegularPostXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPostXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - //$this->assertEquals([], $actualData['capt']); - } - - public function testCreate3DPaymentXML() - { - - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - ]; - $responseData = [ - 'BankPacket' => 'F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', - 'MerchantPacket' => 'E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', - 'Sign' => '9998F61E1D0C0FB6EC5203A748124F30', - ]; - - /** - * @var PosNet $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_PAY); - - $actualXML = $pos->create3DPaymentXML($responseData); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSample3DPaymentXMLData($pos->getAccount(), $responseData); - $this->assertEquals($expectedData, $actualData); - //$this->assertEquals([], $actualData['oosTranData']); - } - - public function testGetOosTransactionRequestData() - { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $order = $this->pos->getOrder(); - $expected = $this->getSampleOosTransactionRequestData($order, $this->card, $this->pos->getAccount()); - $this->assertEquals($expected, $this->pos->getOosTransactionRequestData($this->pos->getAccount(), $this->card, $order, 'Sale')); - } - - - public function testCreate3DResolveMerchantDataXML() - { - - $order = [ - 'id' => '2020110828BC', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - ]; - $responseData = [ - 'BankPacket' => 'F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', - 'MerchantPacket' => 'E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F309998F61E1D0C0FB6EC5203A748124F30', - 'Sign' => '9998F61E1D0C0FB6EC5203A748124F30', - ]; - - /** - * @var PosNet $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_PAY); - - $actualXML = $pos->create3DResolveMerchantDataXML($responseData); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleResolveMerchantDataXMLData($pos->getAccount(), $responseData); - $this->assertEquals($expectedData, $actualData); - //$this->assertEquals([], $actualData['oosResolveMerchantData']); - } - - public function testCreateStatusXML() - { - $order = [ - 'id' => '2020110828BC', - 'type' => 'status', - ]; - - /** - * @var PosNet $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_STATUS); - - $actualXML = $pos->createStatusXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleStatusXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - //$this->assertEquals([], $actualData['agreement']); - } - - - public function testCreateCancelXML() - { - $order = [ - 'id' => '2020110828BC', - 'host_ref_num' => '2020110828BCNUM', - ]; - - /** - * @var PosNet $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_CANCEL); - - $actualXML = $pos->createCancelXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleCancelXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - //$this->assertEquals([], $actualData['reverse']); - } - - public function testCreateRefundXML() - { - $order = [ - 'id' => '2020110828BC', - 'amount' => 50, - 'currency' => 'TRY', - ]; - - /** - * @var PosNet $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_REFUND); - - $actualXML = $pos->createRefundXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRefundXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - /** - * @param $order - * @param AbstractCreditCard $card - * @param PosNetAccount $account - * - * @return array - */ - private function getSampleRegularPaymentXMLData($order, AbstractCreditCard $card, PosNetAccount $account) - { - return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'tranDateRequired' => '1', - 'sale' => [ - 'orderID' => $order->id, - 'installment' => $order->installment, - 'amount' => $order->amount, - 'currencyCode' => $order->currency, - 'ccno' => $card->getNumber(), - 'expDate' => '2201', - 'cvc' => $card->getCvv(), - ], - ]; - } - - /** - * @param $order - * @param PosNetAccount $account - * - * @return array - */ - private function getSampleRegularPostXMLData($order, $account) - { - return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'tranDateRequired' => '1', - 'capt' => [ - 'hostLogKey' => $order->host_ref_num, - 'amount' => $order->amount, - 'currencyCode' => $order->currency, - 'installment' => $order->installment, - ], - ]; - } - - /** - * @param PosNetAccount $account - * @param array $responseData - * - * @return array - */ - private function getSample3DPaymentXMLData($account, array $responseData) - { - return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'oosTranData' => [ - 'bankData' => $responseData['BankPacket'], - 'merchantData' => $responseData['MerchantPacket'], - 'sign' => $responseData['Sign'], - 'wpAmount' => 0, - 'mac' => 'oE7zwV87uOc2DFpGPlr4jQRQ0z9LsxGw56c7vaiZkTo=', - ], - ]; - } - - /** - * @param PosNetAccount $account - * @param array $responseData - * - * @return array - */ - private function getSampleResolveMerchantDataXMLData($account, array $responseData) - { - return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'oosResolveMerchantData' => [ - 'bankData' => $responseData['BankPacket'], - 'merchantData' => $responseData['MerchantPacket'], - 'sign' => $responseData['Sign'], - 'mac' => 'oE7zwV87uOc2DFpGPlr4jQRQ0z9LsxGw56c7vaiZkTo=', - ], - ]; - } - - /** - * @param $order - * @param PosNetAccount $account - * - * @return array - */ - private function getSampleStatusXMLData($order, $account) - { - return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'agreement' => [ - 'orderID' => $order->id, - ], - ]; - } - - /** - * @param $order - * @param AbstractCreditCard $card - * @param PosNetAccount $account - * - * @return array - */ - private function getSampleOosTransactionRequestData($order, AbstractCreditCard $card, PosNetAccount $account): array - { - return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'oosRequestData' => [ - 'posnetid' => $account->getPosNetId(), - 'ccno' => $card->getNumber(), - 'expDate' => '2112', - 'cvc' => $this->card->getCvv(), - 'amount' => $order->amount, - 'currencyCode' => $order->currency, - 'installment' => $order->installment, - 'XID' => PosNet::formatOrderId($order->id), - 'cardHolderName' => $card->getHolderName(), - 'tranType' => 'Sale', - ], - ]; - } - - /** - * @param $order - * @param PosNetAccount $account - * - * @return array - */ - private function getSampleCancelXMLData($order, $account) - { - $requestData = [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'tranDateRequired' => '1', - 'reverse' => [ - 'transaction' => 'sale', - ], - ]; - - //either will work - if (isset($order->host_ref_num)) { - $requestData['reverse']['hostLogKey'] = $order->host_ref_num; - } else { - $requestData['reverse']['orderID'] = PosNet::mapOrderIdToPrefixedOrderId($order->id, $account->getModel()); - } - - return $requestData; - } - - /** - * @param $order - * @param PosNetAccount $account - * - * @return array - */ - private function getSampleRefundXMLData($order, $account) - { - $requestData = [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'tranDateRequired' => '1', - 'return' => [ - 'amount' => $order->amount, - 'currencyCode' => $order->currency, - ], - ]; - - if (isset($order->host_ref_num)) { - $requestData['return']['hostLogKey'] = $order->host_ref_num; - } else { - $requestData['return']['orderID'] = $order->id; - } - - return $requestData; - } } From 65c6c35bdb59b29502fdfa3772e89cf9d0967f2b Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 23 Apr 2022 15:13:08 +0200 Subject: [PATCH 04/40] updated some gateways to use AbstractRequestDataMapper::mapCurrency() --- src/Gateways/InterPos.php | 6 ++++-- src/Gateways/KuveytPos.php | 6 ++++-- src/Gateways/PayForPos.php | 8 ++++---- src/Gateways/PosNet.php | 6 ++++-- src/Gateways/VakifBankPos.php | 8 +++++--- tests/Gateways/InterPosTest.php | 5 ++++- tests/Gateways/KuveytPosTest.php | 11 ++++------- tests/Gateways/PayForTest.php | 10 ++++++++++ tests/Gateways/PosNetTest.php | 8 ++++++++ tests/Gateways/VakifBankPosTest.php | 8 +++++++- 10 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index da546854..cc94bdc8 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -1,5 +1,7 @@ $installment, - 'currency' => $this->mapCurrency($order['currency']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), ]); } diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index 682ca58a..cdc3f9e5 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -1,5 +1,7 @@ $installment, - 'currency' => $this->mapCurrency($order['currency']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), ]); } diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index 00ac47d5..6bfe0a72 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -531,7 +531,7 @@ protected function preparePaymentOrder(array $order) // Order return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->mapCurrency($currency), + 'currency' => $this->requestDataMapper->mapCurrency($currency), ]); } @@ -543,7 +543,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $order['amount'], - 'currency' => $this->mapCurrency($order['currency']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), ]; } @@ -572,7 +572,7 @@ protected function prepareHistoryOrder(array $order) */ protected function prepareCancelOrder(array $order) { - $order['currency'] = $this->mapCurrency($order['currency']); + $order['currency'] = $this->requestDataMapper->mapCurrency($order['currency']); return (object) $order; } @@ -582,7 +582,7 @@ protected function prepareCancelOrder(array $order) */ protected function prepareRefundOrder(array $order) { - $order['currency'] = $this->mapCurrency($order['currency']); + $order['currency'] = $this->requestDataMapper->mapCurrency($order['currency']); return (object) $order; } diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index d4d6bfcf..28835df8 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -1,5 +1,7 @@ $this->requestDataMapper::formatOrderId($order['id']), 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'installment' => $this->requestDataMapper::formatInstallment($installment), - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), 'host_ref_num' => $order['host_ref_num'], ]; } diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 0ceb7e89..6ecae107 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -1,5 +1,7 @@ $installment, - 'currency' => $this->mapCurrency($currency), + 'currency' => $this->requestDataMapper->mapCurrency($currency), 'amount' => $order['amount'], ]); } @@ -406,7 +408,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $order['amount'], - 'currency' => $this->mapCurrency($order['currency']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), 'ip' => $order['ip'], ]; } diff --git a/tests/Gateways/InterPosTest.php b/tests/Gateways/InterPosTest.php index 443e37a3..9ed778c4 100644 --- a/tests/Gateways/InterPosTest.php +++ b/tests/Gateways/InterPosTest.php @@ -1,5 +1,7 @@ pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $this->assertSame('949', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); } diff --git a/tests/Gateways/KuveytPosTest.php b/tests/Gateways/KuveytPosTest.php index f32ee0eb..31191909 100644 --- a/tests/Gateways/KuveytPosTest.php +++ b/tests/Gateways/KuveytPosTest.php @@ -1,9 +1,10 @@ requestDataMapper = new KuveytPosRequestDataMapper(); - $this->xmlDecoder = new XmlEncoder(); } @@ -124,6 +120,7 @@ public function testSetTestMode() public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $this->assertSame('0949', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); } diff --git a/tests/Gateways/PayForTest.php b/tests/Gateways/PayForTest.php index e57594cd..9f010dfb 100644 --- a/tests/Gateways/PayForTest.php +++ b/tests/Gateways/PayForTest.php @@ -96,6 +96,16 @@ public function testPrepare() $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); $this->assertNotEmpty($this->pos->getOrder()); + $this->assertSame('949', $this->pos->getOrder()->currency); + + $this->pos->prepare($this->order, AbstractGateway::TX_POST_PAY); + $this->assertSame('949', $this->pos->getOrder()->currency); + + $this->pos->prepare($this->order, AbstractGateway::TX_CANCEL); + $this->assertSame('949', $this->pos->getOrder()->currency); + + $this->pos->prepare($this->order, AbstractGateway::TX_REFUND); + $this->assertSame('949', $this->pos->getOrder()->currency); } /** diff --git a/tests/Gateways/PosNetTest.php b/tests/Gateways/PosNetTest.php index 0db09f3b..c3ee3635 100644 --- a/tests/Gateways/PosNetTest.php +++ b/tests/Gateways/PosNetTest.php @@ -83,7 +83,15 @@ public function testInit() public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $this->assertSame('TL', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); + + $this->order['host_ref_num'] = 'zz'; + $this->pos->prepare($this->order, AbstractGateway::TX_POST_PAY); + $this->assertSame('TL', $this->pos->getOrder()->currency); + + $this->pos->prepare($this->order, AbstractGateway::TX_REFUND); + $this->assertSame('TL', $this->pos->getOrder()->currency); } /** diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index c30db394..1a41de3e 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -1,5 +1,7 @@ pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $this->assertSame('949', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); + + $this->pos->prepare($this->order, AbstractGateway::TX_POST_PAY); + $this->assertSame('949', $this->pos->getOrder()->currency); } /** From 322a6d1a85fdb9988fe3caa18297f61d0032493f Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 23 Apr 2022 15:47:20 +0200 Subject: [PATCH 05/40] refactord VakifBankPos and VakifBankPosRequestDataMapper --- .../VakifBankPosRequestDataMapper.php | 43 +++-------------- src/Gateways/VakifBankPos.php | 21 ++++++++- .../VakifBankPosRequestDataMapperTest.php | 13 +++++- tests/Gateways/VakifBankPosTest.php | 46 +++++++++++++++++-- 4 files changed, 81 insertions(+), 42 deletions(-) diff --git a/src/DataMapper/VakifBankPosRequestDataMapper.php b/src/DataMapper/VakifBankPosRequestDataMapper.php index b68076fe..a1e2c856 100644 --- a/src/DataMapper/VakifBankPosRequestDataMapper.php +++ b/src/DataMapper/VakifBankPosRequestDataMapper.php @@ -245,49 +245,20 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar } /** - * @inheritDoc - */ - public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null): array - { - throw new NotImplementedException(); - } - - /** - * @param array $data + * @param array $extraData * - * @return array - * - * @throws Exception + * @inheritDoc */ - public function create3DFormDataFromEnrollmentResponse(array $data): array + public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null, array $extraData = []): array { - $response = $data['Message']['VERes']; - /** - * Status values: - * Y:Kart 3-D Secure programına dâhil - * N:Kart 3-D Secure programına dâhil değil - * U:İşlem gerçekleştirilemiyor - * E:Hata durumu - */ - if ('E' === $response['Status']) { - throw new Exception($data['ErrorMessage'], $data['MessageErrorCode']); - } - if ('N' === $response['Status']) { - // todo devam half secure olarak devam et yada satisi iptal et. - throw new Exception('Kart 3-D Secure programına dâhil değil'); - } - if ('U' === $response['Status']) { - throw new Exception('İşlem gerçekleştirilemiyor'); - } - $inputs = [ - 'PaReq' => $response['PaReq'], - 'TermUrl' => $response['TermUrl'], - 'MD' => $response['MD'], + 'PaReq' => $extraData['PaReq'], + 'TermUrl' => $extraData['TermUrl'], + 'MD' => $extraData['MD'], ]; return [ - 'gateway' => $response['ACSUrl'], + 'gateway' => $extraData['ACSUrl'], 'inputs' => $inputs, ]; } diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 6ecae107..d86c0bc3 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -143,7 +143,26 @@ public function get3DFormData(): array $data = $this->sendEnrollmentRequest(); $data = parent::emptyStringsToNull($data); - return $this->requestDataMapper->create3DFormDataFromEnrollmentResponse($data); + $status = $data['Message']['VERes']['Status']; + /** + * Status values: + * Y:Kart 3-D Secure programına dâhil + * N:Kart 3-D Secure programına dâhil değil + * U:İşlem gerçekleştirilemiyor + * E:Hata durumu + */ + if ('E' === $status) { + throw new Exception($data['ErrorMessage'], $data['MessageErrorCode']); + } + if ('N' === $status) { + //half secure olarak devam et yada satisi iptal et. + throw new Exception('Kart 3-D Secure programına dâhil değil'); + } + if ('U' === $status) { + throw new Exception('İşlem gerçekleştirilemiyor'); + } + + return $this->requestDataMapper->create3DFormData($this->account, $this->order, $this->type, '', $data['Message']['VERes']); } /** diff --git a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php index 61dab807..1f420998 100644 --- a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php +++ b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php @@ -206,10 +206,19 @@ public function testCreateRefundRequestData() /** * @return void */ - public function testCreate3DFormDataFromEnrollmentResponse() + public function testCreate3DFormData() { + $pos = $this->pos; + $pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $expectedValue = $this->getSample3DFormDataFromEnrollmentResponse(); - $actualData = $this->requestDataMapper->create3DFormDataFromEnrollmentResponse($this->getSampleEnrollmentSuccessResponseData()); + $actualData = $this->requestDataMapper->create3DFormData( + $pos->getAccount(), + $pos->getOrder(), + '', + '', + $pos->getCard(), + $this->getSampleEnrollmentSuccessResponseData()['Message']['VERes'] + ); $this->assertEquals($expectedValue, $actualData); } diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index 1a41de3e..df399e2c 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -4,6 +4,8 @@ */ namespace Mews\Pos\Tests\Gateways; +use Exception; +use GuzzleHttp\Exception\GuzzleException; use Mews\Pos\Entity\Account\VakifBankAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; use Mews\Pos\Factory\AccountFactory; @@ -150,7 +152,7 @@ public function testMap3DPaymentData3DSuccess() 'BatchNo' => '1', ]; - $method = $this->getMethod('map3DPaymentData'); + $method = $this->getMethod('map3DPaymentData'); $result = $method->invoke($this->pos, $threeDResponse, (object) $provisionResponse); $expected = [ @@ -211,7 +213,7 @@ public function testMap3DPaymentData3DFail() $provisionResponse = []; - $method = $this->getMethod('map3DPaymentData'); + $method = $this->getMethod('map3DPaymentData'); $result = $method->invoke($this->pos, $threeDResponse, (object) $provisionResponse); $expected = [ @@ -238,9 +240,47 @@ public function testMap3DPaymentData3DFail() $this->assertEquals($expected, (array) $result); } + /** + * @return void + * + * @throws Exception|GuzzleException + */ + public function testGet3DFormDataEnrollmentFail() + { + $this->expectException(Exception::class); + $this->expectExceptionCode(2005); + + $posMock = $this->getMockBuilder(VakifBankPos::class) + ->setConstructorArgs([[], $this->account, []]) + ->onlyMethods(['sendEnrollmentRequest']) + ->getMock(); + $posMock->setTestMode(true); + $posMock->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $posMock->expects($this->once())->method('sendEnrollmentRequest')->willReturn($this->getSampleEnrollmentFailResponseData()); + + $posMock->get3DFormData(); + } + + /** + * @return string[] + */ + private function getSampleEnrollmentFailResponseData(): array + { + return [ + 'Message' => [ + 'VERes' => [ + 'Status' => 'E', + ], + ], + 'VerifyEnrollmentRequestId' => '0aebb0757acccae6fba75b2e4d78cecf', + 'MessageErrorCode' => '2005', + 'ErrorMessage' => 'Merchant cannot be found for this bank', + ]; + } + private static function getMethod(string $name): \ReflectionMethod { - $class = new ReflectionClass(VakifBankPos::class); + $class = new ReflectionClass(VakifBankPos::class); $method = $class->getMethod($name); $method->setAccessible(true); From b7d54993a97b7c18cbaa7a96453831277aa93451 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 24 Apr 2022 20:42:53 +0200 Subject: [PATCH 06/40] InterPosRequestDataMapper added MOTO constant --- src/DataMapper/InterPosRequestDataMapper.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/DataMapper/InterPosRequestDataMapper.php b/src/DataMapper/InterPosRequestDataMapper.php index 6738c683..6fb3a4de 100644 --- a/src/DataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/InterPosRequestDataMapper.php @@ -1,5 +1,7 @@ '3DModel', AbstractGateway::MODEL_3D_PAY => '3DPay', @@ -74,7 +81,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'PayerTxnId' => $responseData['PayerTxnId'], 'Eci' => $responseData['Eci'], 'PayerAuthenticationCode' => $responseData['PayerAuthenticationCode'], - 'MOTO' => '0', + 'MOTO' => self::MOTO, 'Lang' => $this->getLang($account, $order), ]; } @@ -94,7 +101,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'PurchAmount' => $order->amount, 'Currency' => $order->currency, 'InstallmentCount' => $order->installment, - 'MOTO' => '0', + 'MOTO' => self::MOTO, 'Lang' => $this->getLang($account, $order), ]; @@ -123,7 +130,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'orgOrderId' => $order->id, 'PurchAmount' => $order->amount, 'Currency' => $order->currency, - 'MOTO' => '0', + 'MOTO' => self::MOTO, ]; } @@ -176,7 +183,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_REFUND], 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'Lang' => $this->getLang($account, $order), - 'MOTO' => '0', + 'MOTO' => self::MOTO, ]; } From 460b2df074024d663b17fcbc2efce3c2262aecd5 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 24 Apr 2022 20:54:30 +0200 Subject: [PATCH 07/40] added test mode for AbstractRequestDataMapper --- src/DataMapper/AbstractRequestDataMapper.php | 26 +++++++++++++- src/Gateways/AbstractGateway.php | 38 ++++++++++++-------- src/Gateways/InterPos.php | 2 +- src/Gateways/KuveytPos.php | 2 +- src/Gateways/PayForPos.php | 2 +- src/Gateways/PosNet.php | 2 +- src/Gateways/VakifBankPos.php | 2 +- 7 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/DataMapper/AbstractRequestDataMapper.php b/src/DataMapper/AbstractRequestDataMapper.php index b58e083c..91f1f6e1 100644 --- a/src/DataMapper/AbstractRequestDataMapper.php +++ b/src/DataMapper/AbstractRequestDataMapper.php @@ -40,6 +40,9 @@ abstract class AbstractRequestDataMapper */ protected $recurringOrderFrequencyMapping = []; + /** @var bool */ + protected $testMode = false; + /** * @param array $currencyMappings */ @@ -128,10 +131,18 @@ abstract public function create3DHash(AbstractPosAccount $account, $order, strin * @param $order * @param array $extraData bankaya gore degisen ozel degerler * - * @return string + * @return array */ abstract public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array; + /** + * @return bool + */ + public function isTestMode(): bool + { + return $this->testMode; + } + /** * @param string $period * @@ -174,6 +185,19 @@ public function getCurrencyMappings(): array return $this->currencyMappings; } + + /** + * @param bool $testMode + * + * @return AbstractRequestDataMapper + */ + public function setTestMode(bool $testMode): self + { + $this->testMode = $testMode; + + return $this; + } + /** * @param string $currency TRY, USD * diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index beefe9ff..3153e942 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -1,7 +1,10 @@ testMode = $testMode; + if (isset($this->requestDataMapper)) { + //todo remove if check after all gateways has requestDataMapper + $this->requestDataMapper->setTestMode($testMode); + } return $this; } diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index cc94bdc8..637abf89 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -44,7 +44,7 @@ class InterPos extends AbstractGateway protected $card; /** @var InterPosRequestDataMapper */ - private $requestDataMapper; + protected $requestDataMapper; /** * @param array $config diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index cdc3f9e5..377158aa 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -45,7 +45,7 @@ class KuveytPos extends AbstractGateway protected $card; /** @var KuveytPosRequestDataMapper */ - private $requestDataMapper; + protected $requestDataMapper; /** * @param array $config diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index 6bfe0a72..d75fdee5 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -65,7 +65,7 @@ class PayForPos extends AbstractGateway /** * @var PayForPosRequestDataMapper */ - private $requestDataMapper; + protected $requestDataMapper; /** * @inheritDoc diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 28835df8..5e7bd570 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -67,7 +67,7 @@ class PosNet extends AbstractGateway private $crypt; /** @var PosNetRequestDataMapper */ - private $requestDataMapper; + protected $requestDataMapper; /** * PosNet constructor. diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index d86c0bc3..c8c4f012 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -45,7 +45,7 @@ class VakifBankPos extends AbstractGateway ]; /** @var VakifBankPosRequestDataMapper */ - private $requestDataMapper; + protected $requestDataMapper; /** * @inheritDoc From bcc4c8419b8f73d08a818c0e9626d519f2ea2f40 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 24 Apr 2022 21:07:54 +0200 Subject: [PATCH 08/40] created GarantiPosRequestDataMapper and refactored GarantiPos --- .../GarantiPosRequestDataMapper.php | 503 ++++++++++++ src/Gateways/GarantiPos.php | 482 +---------- .../GarantiPosRequestDataMapperTest.php | 655 +++++++++++++++ tests/Gateways/GarantiPosTest.php | 774 +++--------------- 4 files changed, 1292 insertions(+), 1122 deletions(-) create mode 100644 src/DataMapper/GarantiPosRequestDataMapper.php create mode 100644 tests/DataMapper/GarantiPosRequestDataMapperTest.php diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php new file mode 100644 index 00000000..b3ae4554 --- /dev/null +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -0,0 +1,503 @@ + '3D', + AbstractGateway::MODEL_3D_PAY => '3D_PAY', + AbstractGateway::MODEL_3D_HOST => null, //todo + AbstractGateway::MODEL_NON_SECURE => null, + ]; + + /** + * @inheritdoc + */ + protected $txTypeMappings = [ + AbstractGateway::TX_PAY => 'sales', + AbstractGateway::TX_PRE_PAY => 'preauth', + AbstractGateway::TX_POST_PAY => 'postauth', + AbstractGateway::TX_CANCEL => 'void', + AbstractGateway::TX_REFUND => 'refund', + AbstractGateway::TX_HISTORY => 'orderhistoryinq', + AbstractGateway::TX_STATUS => 'orderinq', + ]; + + /** + * @inheritdoc + */ + protected $currencyMappings = [ + 'TRY' => 949, + 'USD' => 840, + 'EUR' => 978, + 'GBP' => 826, + 'JPY' => 392, + 'RUB' => 643, + ]; + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData): array + { + $hash = $this->createHash($account, $order, $txType); + + return [ + 'Mode' => $this->getMode(), + 'Version' => self::API_VERSION, + 'ChannelCode' => '', + 'Terminal' => $this->getTerminalData($account, $hash), + 'Customer' => [ + 'IPAddress' => $responseData['customeripaddress'], + 'EmailAddress' => $responseData['customeremailaddress'], + ], + 'Card' => $this->getCardData(), + 'Order' => [ + 'OrderID' => $responseData['orderid'], + 'GroupID' => '', + 'AddressList' => $this->getOrderAddressData($order), + ], + 'Transaction' => [ + 'Type' => $responseData['txntype'], + 'InstallmentCnt' => $order->installment, + 'Amount' => $responseData['txnamount'], + 'CurrencyCode' => $responseData['txncurrencycode'], + 'CardholderPresentCode' => '13', //13 for 3D secure payment + 'MotoInd' => 'N', + 'Secure3D' => [ + 'AuthenticationCode' => $responseData['cavv'], + 'SecurityLevel' => $responseData['eci'], + 'TxnID' => $responseData['xid'], + 'Md' => $responseData['md'], + ], + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array + { + $hash = $this->createHash($account, $order, $txType, $card); + + return [ + 'Mode' => $this->getMode(), + 'Version' => self::API_VERSION, + 'Terminal' => $this->getTerminalData($account, $hash), + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Card' => $this->getCardData($card), + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + 'AddressList' => $this->getOrderAddressData($order), + ], + 'Transaction' => [ + 'Type' => $txType, + 'InstallmentCnt' => $order->installment, + 'Amount' => $order->amount, + 'CurrencyCode' => $order->currency, + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'Description' => '', + 'OriginalRetrefNum' => '', //todo try removing it + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array + { + $hash = $this->createHash($account, $order, $this->txTypeMappings[AbstractGateway::TX_POST_PAY], $card); + + return [ + 'Mode' => $this->getMode(), + 'Version' => self::API_VERSION, + 'Terminal' => $this->getTerminalData($account, $hash), + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + ], + 'Transaction' => [ + 'Type' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'Amount' => $order->amount, + 'CurrencyCode' => $order->currency, + 'OriginalRetrefNum' => $order->ref_ret_num, + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function createStatusRequestData(AbstractPosAccount $account, $order): array + { + $hash = $this->createHash($account, $order, $this->txTypeMappings[AbstractGateway::TX_STATUS]); + + return [ + 'Mode' => $this->getMode(), + 'Version' => self::API_VERSION, + 'ChannelCode' => '', + 'Terminal' => $this->getTerminalData($account, $hash), + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, //TODO we need this data? + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Card' => $this->getCardData(), + 'Transaction' => [ + 'Type' => $this->txTypeMappings[AbstractGateway::TX_STATUS], + 'InstallmentCnt' => $order->installment, + 'Amount' => $order->amount, //TODO we need it? + 'CurrencyCode' => $order->currency, //TODO we need it? + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function createCancelRequestData(AbstractPosAccount $account, $order): array + { + $hash = $this->createHash($account, $order, $this->txTypeMappings[AbstractGateway::TX_CANCEL]); + + return [ + 'Mode' => $this->getMode(), + 'Version' => self::API_VERSION, + 'ChannelCode' => '', + 'Terminal' => $this->getTerminalData($account, $hash, true), + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Transaction' => [ + 'Type' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], + 'InstallmentCnt' => $order->installment, + 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek + 'CurrencyCode' => $order->currency, + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'OriginalRetrefNum' => $order->ref_ret_num, + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function createRefundRequestData(AbstractPosAccount $account, $order): array + { + $txType = $this->txTypeMappings[AbstractGateway::TX_REFUND]; + $hash = $this->createHash($account, $order, $txType); + + return [ + 'Mode' => $this->getMode(), + 'Version' => self::API_VERSION, + 'ChannelCode' => '', + 'Terminal' => $this->getTerminalData($account, $hash, true), + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Transaction' => [ + 'Type' => $txType, + 'InstallmentCnt' => $order->installment, + 'Amount' => $order->amount, + 'CurrencyCode' => $order->currency, + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'OriginalRetrefNum' => $order->ref_ret_num, + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array + { + $txType = $this->txTypeMappings[AbstractGateway::TX_HISTORY]; + $hash = $this->createHash($account, $order, $txType); + + return [ + 'Mode' => $this->getMode(), + 'Version' => self::API_VERSION, + 'ChannelCode' => '', + 'Terminal' => $this->getTerminalData($account, $hash), + 'Customer' => [ + //TODO we need this data? + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Card' => $this->getCardData(), + 'Transaction' => [ + 'Type' => $txType, + 'InstallmentCnt' => $order->installment, + 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek + 'CurrencyCode' => $order->currency, + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + ], + ]; + } + + + /** + * @inheritDoc + */ + public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null): array + { + $hashData = $this->create3DHash($account, $order, $txType); + + $inputs = [ + 'secure3dsecuritylevel' => $this->secureTypeMappings[$account->getModel()], + 'mode' => $this->getMode(), + 'apiversion' => self::API_VERSION, + 'terminalprovuserid' => $account->getUsername(), + 'terminaluserid' => $account->getUsername(), + 'terminalmerchantid' => $account->getClientId(), + 'terminalid' => $account->getTerminalId(), + 'txntype' => $txType, + 'txnamount' => $order->amount, + 'txncurrencycode' => $order->currency, + 'txninstallmentcount' => $order->installment, + 'orderid' => $order->id, + 'successurl' => $order->success_url, + 'errorurl' => $order->fail_url, + 'customeremailaddress' => $order->email ?? null, + 'customeripaddress' => $order->ip, + 'secure3dhash' => $hashData, + ]; + + if ($card) { + $inputs['cardnumber'] = $card->getNumber(); + $inputs['cardexpiredatemonth'] = $card->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT); + $inputs['cardexpiredateyear'] = $card->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT); + $inputs['cardcvv2'] = $card->getCvv(); + } + + return [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + } + + /** + * @param GarantiPosAccount $account + * + * @inheritDoc + */ + public function create3DHash(AbstractPosAccount $account, $order, string $txType): string + { + $map = [ + $account->getTerminalId(), + $order->id, + $order->amount, + $order->success_url, + $order->fail_url, + $txType, + $order->installment, + $account->getStoreKey(), + $this->createSecurityData($account, $txType), + ]; + + return $this->hashString(implode(static::HASH_SEPARATOR, $map)); + } + + /** + * Make Hash Data + * + * @param GarantiPosAccount $account + * @param $order + * @param string $txType + * @param AbstractCreditCard|null $card + * + * @return string + */ + public function createHash(GarantiPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): string + { + $map = [ + $order->id, + $account->getTerminalId(), + isset($card) ? $card->getNumber() : null, + $order->amount, + $this->createSecurityData($account, $txType), + ]; + + return $this->hashString(implode(static::HASH_SEPARATOR, $map)); + } + + /** + * Amount Formatter + * converts 100 to 10000, or 10.01 to 1001 + * @param float $amount + * + * @return int + */ + public static function amountFormat($amount): int + { + return round($amount, 2) * 100; + } + + /** + * @param string $str + * + * @return string + */ + protected function hashString(string $str): string + { + return strtoupper(hash(static::HASH_ALGORITHM, $str)); + } + + /** + * @return string + */ + private function getMode(): string + { + return !$this->isTestMode() ? 'PROD' : 'TEST'; + } + + /** + * Make Security Data + * + * @param GarantiPosAccount $account + * @param string $txType + * + * @return string + */ + private function createSecurityData(AbstractPosAccount $account, string $txType): string + { + if ($txType === $this->txTypeMappings[AbstractGateway::TX_REFUND] || $txType === $this->txTypeMappings[AbstractGateway::TX_CANCEL]) { + $password = $account->getRefundPassword(); + } else { + $password = $account->getPassword(); + } + + $map = [ + $password, + str_pad((int) $account->getTerminalId(), 9, 0, STR_PAD_LEFT), + ]; + + return $this->hashString(implode(static::HASH_SEPARATOR, $map)); + } + + /** + * @param GarantiPosAccount $account + * @param string $hash + * @param bool $isRefund + * + * @return array + */ + private function getTerminalData(AbstractPosAccount $account, string $hash, bool $isRefund = false): array + { + return [ + 'ProvUserID' => $isRefund ? $account->getRefundUsername() : $account->getUsername(), + 'UserID' => $isRefund ? $account->getRefundUsername() : $account->getUsername(), + 'HashData' => $hash, + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ]; + } + + /** + * @param AbstractCreditCard|null $card + * + * @return array + */ + private function getCardData(?AbstractCreditCard $card = null): array + { + if ($card) { + return [ + 'Number' => $card->getNumber(), + 'ExpireDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), + 'CVV2' => $card->getCvv(), + ]; + } + + return [ + 'Number' => '', + 'ExpireDate' => '', + 'CVV2' => '', + ]; + } + + /** + * @param $order + * + * @return array + */ + private function getOrderAddressData($order): array + { + return [ + 'Address' => [ + 'Type' => 'B', //S - shipping, B - billing + 'Name' => $order->name, + 'LastName' => '', + 'Company' => '', + 'Text' => '', + 'District' => '', + 'City' => '', + 'PostalCode' => '', + 'Country' => '', + 'PhoneNumber' => '', + ], + ]; + } +} diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 8c70854a..df5651a7 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -1,8 +1,11 @@ 'general_error', ]; - /** - * Transaction Types - * - * @var array - */ - protected $types = [ - self::TX_PAY => 'sales', - self::TX_PRE_PAY => 'preauth', - self::TX_POST_PAY => 'postauth', - self::TX_CANCEL => 'void', - self::TX_REFUND => 'refund', - self::TX_HISTORY => 'orderhistoryinq', - self::TX_STATUS => 'orderinq', - ]; - - protected $secureTypeMappings = [ - self::MODEL_3D_SECURE => '3D', - self::MODEL_3D_PAY => '3D_PAY', - self::MODEL_3D_HOST => null, //todo - self::MODEL_NON_SECURE => null, //todo - ]; - - /** - * currency mapping - * - * @var array - */ - protected $currencies = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 643, - ]; - - /** - * @var GarantiPosAccount - */ + /** @var GarantiPosAccount */ protected $account; - /** - * @var AbstractCreditCard - */ + /**4 @var AbstractCreditCard */ protected $card; + /** @var GarantiPosRequestDataMapper */ + protected $requestDataMapper; + /** * GarantiPost constructor. * @@ -107,6 +63,11 @@ class GarantiPos extends AbstractGateway */ public function __construct($config, $account, array $currencies = []) { + $this->requestDataMapper = new GarantiPosRequestDataMapper($currencies); + $this->types = $this->requestDataMapper->getTxTypeMappings(); + $this->currencies = $this->requestDataMapper->getCurrencyMappings(); + $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); + $this->requestDataMapper->setTestMode(true); parent::__construct($config, $account, $currencies); } @@ -132,7 +93,7 @@ public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignore public function make3DPayment(Request $request) { $bankResponse = null; - //TODO hash check + //TODO add hash check if (in_array($request->get('mdstatus'), [1, 2, 3, 4])) { $contents = $this->create3DPaymentXML($request->request->all()); $bankResponse = $this->send($contents); @@ -153,7 +114,6 @@ public function make3DPayPayment(Request $request) return $this; } - /** * @inheritDoc */ @@ -193,39 +153,7 @@ public function get3DFormData(): array return []; } - $hashData = $this->create3DHash($this->account, $this->order, $this->type); - - $inputs = [ - 'secure3dsecuritylevel' => $this->secureTypeMappings[$this->account->getModel()], - 'mode' => $this->getMode(), - 'apiversion' => self::API_VERSION, - 'terminalprovuserid' => $this->account->getUsername(), - 'terminaluserid' => $this->account->getUsername(), - 'terminalmerchantid' => $this->account->getClientId(), - 'txntype' => $this->type, - 'txnamount' => $this->order->amount, - 'txncurrencycode' => $this->order->currency, - 'txninstallmentcount' => $this->order->installment, - 'orderid' => $this->order->id, - 'terminalid' => $this->account->getTerminalId(), - 'successurl' => $this->order->success_url, - 'errorurl' => $this->order->fail_url, - 'customeremailaddress' => $this->order->email ?? null, - 'customeripaddress' => $this->order->ip, - 'secure3dhash' => $hashData, - ]; - - if ($this->card) { - $inputs['cardnumber'] = $this->card->getNumber(); - $inputs['cardexpiredatemonth'] = $this->card->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT); - $inputs['cardexpiredateyear'] = $this->card->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT); - $inputs['cardcvv2'] = $this->card->getCvv(); - } - - return [ - 'gateway' => $this->get3DGatewayURL(), - 'inputs' => $inputs, - ]; + return $this->requestDataMapper->create3DFormData($this->account, $this->order, $this->type, $this->get3DGatewayURL(), $this->card); } /** @@ -242,54 +170,7 @@ public function make3DHostPayment(Request $request) */ public function createRegularPaymentXML() { - $requestData = [ - 'Mode' => $this->getMode(), - 'Version' => self::API_VERSION, - 'Terminal' => [ - 'ProvUserID' => $this->account->getUsername(), - 'UserID' => $this->account->getUsername(), - 'HashData' => $this->createHashData($this->account, $this->order, $this->type, $this->card), - 'ID' => $this->account->getTerminalId(), - 'MerchantID' => $this->account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $this->order->ip, - 'EmailAddress' => $this->order->email, - ], - 'Card' => [ - 'Number' => $this->card->getNumber(), - 'ExpireDate' => $this->card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), - 'CVV2' => $this->card->getCvv(), - ], - 'Order' => [ - 'OrderID' => $this->order->id, - 'GroupID' => '', - 'AddressList' => [ - 'Address' => [ - 'Type' => 'S', - 'Name' => $this->order->name, - 'LastName' => '', - 'Company' => '', - 'Text' => '', - 'District' => '', - 'City' => '', - 'PostalCode' => '', - 'Country' => '', - 'PhoneNumber' => '', - ], - ], - ], - 'Transaction' => [ - 'Type' => $this->type, - 'InstallmentCnt' => $this->order->installment, - 'Amount' => $this->order->amount, - 'CurrencyCode' => $this->order->currency, - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - 'Description' => '', - 'OriginalRetrefNum' => '', - ], - ]; + $requestData = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $this->order, $this->type, $this->card); return $this->createXML($requestData); } @@ -299,30 +180,7 @@ public function createRegularPaymentXML() */ public function createRegularPostXML() { - $requestData = [ - 'Mode' => $this->getMode(), - 'Version' => self::API_VERSION, - 'Terminal' => [ - 'ProvUserID' => $this->account->getUsername(), - 'UserID' => $this->account->getUsername(), - 'HashData' => $this->createHashData($this->account, $this->order, $this->type, $this->card), - 'ID' => $this->account->getTerminalId(), - 'MerchantID' => $this->account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $this->order->ip, - 'EmailAddress' => $this->order->email, - ], - 'Order' => [ - 'OrderID' => $this->order->id, - ], - 'Transaction' => [ - 'Type' => $this->types[self::TX_POST_PAY], - 'Amount' => $this->order->amount, - 'CurrencyCode' => $this->order->currency, - 'OriginalRetrefNum' => $this->order->ref_ret_num, - ], - ]; + $requestData = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -332,59 +190,7 @@ public function createRegularPostXML() */ public function create3DPaymentXML($responseData) { - $requestData = [ - 'Mode' => $this->getMode(), - 'Version' => self::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $this->account->getUsername(), - 'UserID' => $this->account->getUsername(), - 'HashData' => $this->createHashData($this->account, $this->order, $this->type, $this->card), - 'ID' => $this->account->getTerminalId(), - 'MerchantID' => $this->account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $responseData['customeripaddress'], - 'EmailAddress' => $responseData['customeremailaddress'], - ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', - ], - 'Order' => [ - 'OrderID' => $responseData['orderid'], - 'GroupID' => '', - 'AddressList' => [ - 'Address' => [ - 'Type' => 'B', - 'Name' => $this->order->name, - 'LastName' => '', - 'Company' => '', - 'Text' => '', - 'District' => '', - 'City' => '', - 'PostalCode' => '', - 'Country' => '', - 'PhoneNumber' => '', - ], - ], - ], - 'Transaction' => [ - 'Type' => $responseData['txntype'], - 'InstallmentCnt' => $this->order->installment, - 'Amount' => $responseData['txnamount'], - 'CurrencyCode' => $responseData['txncurrencycode'], - 'CardholderPresentCode' => '13', - 'MotoInd' => 'N', - 'Secure3D' => [ - 'AuthenticationCode' => $responseData['cavv'], - 'SecurityLevel' => $responseData['eci'], - 'TxnID' => $responseData['xid'], - 'Md' => $responseData['md'], - ], - ], - ]; + $requestData = $this->requestDataMapper->create3DPaymentRequestData($this->account, $this->order, $this->type, $responseData); return $this->createXML($requestData); } @@ -394,35 +200,7 @@ public function create3DPaymentXML($responseData) */ public function createCancelXML() { - $requestData = [ - 'Mode' => $this->getMode(), - 'Version' => self::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $this->account->getRefundUsername(), - 'UserID' => $this->account->getRefundUsername(), - 'HashData' => $this->createHashData($this->account, $this->order, $this->type), - 'ID' => $this->account->getTerminalId(), - 'MerchantID' => $this->account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $this->order->ip, - 'EmailAddress' => $this->order->email, - ], - 'Order' => [ - 'OrderID' => $this->order->id, - 'GroupID' => '', - ], - 'Transaction' => [ - 'Type' => $this->types[self::TX_CANCEL], - 'InstallmentCnt' => $this->order->installment, - 'Amount' => $this->order->amount, //TODO we need this field here? - 'CurrencyCode' => $this->order->currency, - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - 'OriginalRetrefNum' => $this->order->ref_ret_num, - ], - ]; + $requestData = $this->requestDataMapper->createCancelRequestData($this->getAccount(), $this->getOrder()); return $this->createXML($requestData); } @@ -432,35 +210,7 @@ public function createCancelXML() */ public function createRefundXML() { - $requestData = [ - 'Mode' => $this->getMode(), - 'Version' => self::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $this->account->getRefundUsername(), - 'UserID' => $this->account->getRefundUsername(), - 'HashData' => $this->createHashData($this->account, $this->order, $this->type), - 'ID' => $this->account->getTerminalId(), - 'MerchantID' => $this->account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $this->order->ip, - 'EmailAddress' => $this->order->email, - ], - 'Order' => [ - 'OrderID' => $this->order->id, - 'GroupID' => '', - ], - 'Transaction' => [ - 'Type' => $this->types[self::TX_REFUND], - 'InstallmentCnt' => $this->order->installment, - 'Amount' => $this->order->amount, - 'CurrencyCode' => $this->order->currency, - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - 'OriginalRetrefNum' => $this->order->ref_ret_num, - ], - ]; + $requestData = $this->requestDataMapper->createRefundRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -470,39 +220,7 @@ public function createRefundXML() */ public function createHistoryXML($customQueryData) { - $requestData = [ - 'Mode' => $this->getMode(), - 'Version' => self::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $this->account->getUsername(), - 'UserID' => $this->account->getUsername(), - 'HashData' => $this->createHashData($this->account, $this->order, $this->type), - 'ID' => $this->account->getTerminalId(), - 'MerchantID' => $this->account->getClientId(), - ], - 'Customer' => [ //TODO we need this data? - 'IPAddress' => $this->order->ip, - 'EmailAddress' => $this->order->email, - ], - 'Order' => [ - 'OrderID' => $this->order->id, - 'GroupID' => '', - ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', - ], - 'Transaction' => [ - 'Type' => $this->types[self::TX_HISTORY], - 'InstallmentCnt' => $this->order->installment, - 'Amount' => $this->order->amount, - 'CurrencyCode' => $this->order->currency, //TODO we need it? - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - ], - ]; + $requestData = $this->requestDataMapper->createHistoryRequestData($this->account, $this->order, $customQueryData); return $this->createXML($requestData); } @@ -512,115 +230,11 @@ public function createHistoryXML($customQueryData) */ public function createStatusXML() { - $hashData = $this->createHashData($this->account, $this->order, $this->type); - - $requestData = [ - 'Mode' => $this->getMode(), - 'Version' => self::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $this->account->getUsername(), - 'UserID' => $this->account->getUsername(), - 'HashData' => $hashData, - 'ID' => $this->account->getTerminalId(), - 'MerchantID' => $this->account->getClientId(), - ], - 'Customer' => [ //TODO we need this data? - 'IPAddress' => $this->order->ip, - 'EmailAddress' => $this->order->email, - ], - 'Order' => [ - 'OrderID' => $this->order->id, - 'GroupID' => '', - ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', - ], - 'Transaction' => [ - 'Type' => $this->types[self::TX_STATUS], - 'InstallmentCnt' => $this->order->installment, - 'Amount' => $this->order->amount, //TODO we need it? - 'CurrencyCode' => $this->order->currency, //TODO we need it? - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - ], - ]; + $requestData = $this->requestDataMapper->createStatusRequestData($this->account, $this->order); return $this->createXML($requestData); } - /** - * Make Hash Data - * - * @param GarantiPosAccount $account - * @param $order - * @param string $txType - * @param AbstractCreditCard|null $card - * - * @return string - */ - public function createHashData(GarantiPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): string - { - $map = [ - $order->id, - $account->getTerminalId(), - isset($card) ? $card->getNumber() : null, - $order->amount, - $this->createSecurityData($account, $txType), - ]; - - return $this->hashString(implode(static::HASH_SEPARATOR, $map)); - } - - - /** - * Make 3d Hash Data - * - * @param GarantiPosAccount $account - * @param $order - * @param string $txType - * - * @return string - */ - public function create3DHash(GarantiPosAccount $account, $order, string $txType): string - { - $map = [ - $account->getTerminalId(), - $order->id, - $order->amount, - $order->success_url, - $order->fail_url, - $txType, - $order->installment, - $account->getStoreKey(), - $this->createSecurityData($account, $txType), - ]; - - return $this->hashString(implode(static::HASH_SEPARATOR, $map)); - } - - /** - * Amount Formatter - * converts 100 to 10000, or 10.01 to 1001 - * @param float $amount - * - * @return int - */ - public static function amountFormat($amount): int - { - return round($amount, 2) * 100; - } - - /** - * @return string - */ - protected function getMode(): string - { - return !$this->isTestMode() ? 'PROD' : 'TEST'; - } - /** * todo use tDPayResponseCommon() method to map response * @inheritDoc @@ -924,8 +538,8 @@ protected function preparePaymentOrder(array $order) // Order return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->mapCurrency($order['currency']), - 'amount' => self::amountFormat($order['amount']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', ]); @@ -939,8 +553,8 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'ref_ret_num' => $order['ref_ret_num'], - 'currency' => $this->mapCurrency($order['currency']), - 'amount' => self::amountFormat($order['amount']), + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', ]; @@ -953,8 +567,8 @@ protected function prepareStatusOrder(array $order) { return (object) [ 'id' => $order['id'], - 'amount' => self::amountFormat(1), - 'currency' => $this->mapCurrency($order['currency']), + 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', 'installment' => '', @@ -976,8 +590,8 @@ protected function prepareCancelOrder(array $order) { return (object) [ 'id' => $order['id'], - 'amount' => self::amountFormat(1), - 'currency' => $this->mapCurrency($order['currency']), + 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor + 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), 'ref_ret_num' => $order['ref_ret_num'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', @@ -992,38 +606,4 @@ protected function prepareRefundOrder(array $order) { return $this->prepareCancelOrder($order); } - - /** - * @param string $str - * - * @return string - */ - protected function hashString(string $str): string - { - return strtoupper(hash(static::HASH_ALGORITHM, $str)); - } - - /** - * Make Security Data - * - * @param GarantiPosAccount $account - * @param string $txType - * - * @return string - */ - private function createSecurityData(GarantiPosAccount $account, string $txType): string - { - if ($txType === $this->types[self::TX_REFUND] || $txType === $this->types[self::TX_CANCEL]) { - $password = $account->getRefundPassword(); - } else { - $password = $account->getPassword(); - } - - $map = [ - $password, - str_pad((int) $account->getTerminalId(), 9, 0, STR_PAD_LEFT), - ]; - - return $this->hashString(implode(static::HASH_SEPARATOR, $map)); - } } diff --git a/tests/DataMapper/GarantiPosRequestDataMapperTest.php b/tests/DataMapper/GarantiPosRequestDataMapperTest.php new file mode 100644 index 00000000..d233bb11 --- /dev/null +++ b/tests/DataMapper/GarantiPosRequestDataMapperTest.php @@ -0,0 +1,655 @@ +config = require __DIR__.'/../../config/pos.php'; + + $this->threeDAccount = AccountFactory::createGarantiPosAccount( + 'garanti', + '7000679', + 'PROVAUT', + '123qweASD/', + '30691298', + AbstractGateway::MODEL_3D_SECURE, + '12345678', + 'PROVRFN', + '123qweASD/' + ); + + $this->order = [ + 'id' => 'order222', + 'name' => 'siparis veren', + 'email' => 'test@test.com', + 'amount' => '100.25', + 'installment' => 0, + 'currency' => 'TRY', + 'success_url' => 'https://domain.com/success', + 'fail_url' => 'https://domain.com/fail_url', + 'lang' => 'tr', + 'ip' => '156.155.154.153', + ]; + + $this->pos = PosFactory::createPosGateway($this->threeDAccount); + $this->pos->setTestMode(true); + $this->requestDataMapper = new GarantiPosRequestDataMapper(); + $this->requestDataMapper->setTestMode(true); + $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet'); + } + + /** + * @return void + */ + public function testAmountFormat() + { + $this->assertEquals(100000, $this->requestDataMapper::amountFormat(1000)); + $this->assertEquals(100000, $this->requestDataMapper::amountFormat(1000.00)); + $this->assertEquals(100001, $this->requestDataMapper::amountFormat(1000.01)); + } + + /** + * @return void + */ + public function testMapCurrency() + { + $this->assertEquals('949', $this->requestDataMapper->mapCurrency('TRY')); + $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); + } + + /** + * @return void + */ + public function testCreateNonSecurePostAuthPaymentRequestData() + { + $this->order['ref_ret_num'] = '831803579226'; + $order = $this->order; + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_POST_PAY); + + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleNonSecurePaymentPostRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreateNonSecurePaymentRequestData() + { + $order = $this->order; + $pos = $this->pos; + $card = $this->card; + $pos->prepare($order, AbstractGateway::TX_PAY, $card); + + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'sales', $card); + + $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DHash() + { + $expected = '1D319D5EA945F5730FF5BCC970FF96690993F4BD'; + $pos = $this->pos; + $pos->prepare($this->order, AbstractGateway::TX_PAY); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), 'sales'); + $this->assertSame($expected, $actual); + } + + /** + * @return void + */ + public function testCreateHash() + { + $expected = '00CD5B6C29D4CEA1F3002D785A9F9B09974AD51D'; + $pos = $this->pos; + $pos->prepare($this->order, AbstractGateway::TX_PAY); + $actual = $this->requestDataMapper->createHash($pos->getAccount(), $pos->getOrder(), 'sales'); + $this->assertEquals($expected, $actual); + + $pos->prepare($this->order, AbstractGateway::TX_PRE_PAY); + $actual = $this->requestDataMapper->createHash($pos->getAccount(), $pos->getOrder(), 'preauth'); + $this->assertEquals($expected, $actual); + } + + /** + * @return void + */ + public function testCreateHashForCancelAndRefund() + { + $order = [ + 'id' => '4499996', + 'ref_ret_num' => '446ss', + 'amount' => '1.00', + 'currency' => 'TRY', + ]; + $expected = '9788649A0C3AE14C082783CEA6775E08A7EFB311'; + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_CANCEL); + $actual = $this->requestDataMapper->createHash($pos->getAccount(), $pos->getOrder(), 'void'); + $this->assertEquals($expected, $actual); + + $pos->prepare($order, AbstractGateway::TX_REFUND); + $actual = $this->requestDataMapper->createHash($pos->getAccount(), $pos->getOrder(), 'refund'); + $this->assertEquals($expected, $actual); + } + + /** + * @return void + */ + public function testCreateCancelRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'currency' => 'TRY', + 'amount' => '1.00', + 'ref_ret_num' => '831803579226', + ]; + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_CANCEL); + + $actual = $this->requestDataMapper->createCancelRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleCancelXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreateHistoryRequestData() + { + $order = $this->order; + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_HISTORY); + $actual = $this->requestDataMapper->createHistoryRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleHistoryRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DPaymentRequestData() + { + $pos = $this->pos; + $order = $this->order; + $responseData = $this->getSample3DResponseData(); + $pos->prepare($order, AbstractGateway::TX_PAY); + + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), '', $responseData); + + $expectedData = $this->getSample3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), $responseData); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testGet3DFormData() + { + $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); + $pos = $this->pos; + $account = $pos->getAccount(); + $order = $pos->getOrder(); + $card = $pos->getCard(); + $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test']; + $inputs = [ + 'secure3dsecuritylevel' => '3D', + 'mode' => 'TEST', + 'apiversion' => 'v0.01', + 'terminalprovuserid' => $account->getUsername(), + 'terminaluserid' => $account->getUsername(), + 'terminalmerchantid' => $account->getClientId(), + 'terminalid' => $account->getTerminalId(), + 'txntype' => 'sales', + 'txnamount' => 10025, + 'txncurrencycode' => '949', + 'txninstallmentcount' => $order->installment, + 'orderid' => $this->order['id'], + 'successurl' => $this->order['success_url'], + 'errorurl' => $this->order['fail_url'], + 'customeremailaddress' => $order->email, + 'customeripaddress' => $this->order['ip'], + 'secure3dhash' => '1D319D5EA945F5730FF5BCC970FF96690993F4BD', + 'cardnumber' => $card->getNumber(), + 'cardexpiredatemonth' => '01', + 'cardexpiredateyear' => '22', + 'cardcvv2' => $card->getCvv(), + ]; + + $form = [ + 'inputs' => $inputs, + 'gateway' => $gatewayURL, + ]; + + //test without card + $this->assertEquals($form, $this->requestDataMapper->create3DFormData( + $this->pos->getAccount(), + $this->pos->getOrder(), + 'sales', + $gatewayURL, + $this->card + )); + } + + /** + * @return void + */ + public function testCreateStatusRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'currency' => 'TRY', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_STATUS); + + $actualData = $this->requestDataMapper->createStatusRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleStatusRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actualData); + } + + /** + * @return void + */ + public function testCreateRefundRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'currency' => 'TRY', + 'ref_ret_num' => '831803579226', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_REFUND); + + $actual = $this->requestDataMapper->createRefundRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleRefundXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @param GarantiPosAccount $account + * @param $order + * @param array $responseData + * + * @return array + */ + private function getSample3DPaymentRequestData(AbstractPosAccount $account, $order, array $responseData): array + { + return [ + 'Mode' => 'TEST', + 'Version' => 'v0.01', + 'ChannelCode' => '', + 'Terminal' => [ + 'ProvUserID' => $account->getUsername(), + 'UserID' => $account->getUsername(), + 'HashData' => '00CD5B6C29D4CEA1F3002D785A9F9B09974AD51D', + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ], + 'Customer' => [ + 'IPAddress' => $responseData['customeripaddress'], + 'EmailAddress' => $responseData['customeremailaddress'], + ], + 'Card' => [ + 'Number' => '', + 'ExpireDate' => '', + 'CVV2' => '', + ], + 'Order' => [ + 'OrderID' => $responseData['orderid'], + 'GroupID' => '', + 'AddressList' => [ + 'Address' => [ + 'Type' => 'B', + 'Name' => $order->name, + 'LastName' => '', + 'Company' => '', + 'Text' => '', + 'District' => '', + 'City' => '', + 'PostalCode' => '', + 'Country' => '', + 'PhoneNumber' => '', + ], + ], + ], + 'Transaction' => [ + 'Type' => $responseData['txntype'], + 'InstallmentCnt' => $order->installment, + 'Amount' => $responseData['txnamount'], + 'CurrencyCode' => $responseData['txncurrencycode'], + 'CardholderPresentCode' => '13', + 'MotoInd' => 'N', + 'Secure3D' => [ + 'AuthenticationCode' => $responseData['cavv'], + 'SecurityLevel' => $responseData['eci'], + 'TxnID' => $responseData['xid'], + 'Md' => $responseData['md'], + ], + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleCancelXMLData(AbstractPosAccount $account, $order): array + { + return [ + 'Mode' => 'TEST', + 'Version' => 'v0.01', + 'ChannelCode' => '', + 'Terminal' => [ + 'ProvUserID' => $account->getRefundUsername(), + 'UserID' => $account->getRefundUsername(), + 'HashData' => '8DD74209DEEB7D333105E1C69998A827419A3B04', + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ], + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Transaction' => [ + 'Type' => 'void', + 'InstallmentCnt' => $order->installment, + 'Amount' => 100, + 'CurrencyCode' => '949', + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'OriginalRetrefNum' => $order->ref_ret_num, + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * @param $order + * @param AbstractCreditCard $card + * + * @return array + */ + private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $account, $order, AbstractCreditCard $card): array + { + return [ + 'Mode' => 'TEST', + 'Version' => 'v0.01', + 'Terminal' => [ + 'ProvUserID' => $account->getUsername(), + 'UserID' => $account->getUsername(), + 'HashData' => '3732634F78053D42304B0966E263629FE44E258B', + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ], + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Card' => [ + 'Number' => $card->getNumber(), + 'ExpireDate' => '0122', + 'CVV2' => $card->getCvv(), + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + 'AddressList' => [ + 'Address' => [ + 'Type' => 'B', + 'Name' => $order->name, + 'LastName' => '', + 'Company' => '', + 'Text' => '', + 'District' => '', + 'City' => '', + 'PostalCode' => '', + 'Country' => '', + 'PhoneNumber' => '', + ], + ], + ], + 'Transaction' => [ + 'Type' => 'sales', + 'InstallmentCnt' => $order->installment, + 'Amount' => 10025, + 'CurrencyCode' => 949, + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'Description' => '', + 'OriginalRetrefNum' => '', + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'Mode' => 'TEST', + 'Version' => 'v0.01', + 'Terminal' => [ + 'ProvUserID' => $account->getUsername(), + 'UserID' => $account->getUsername(), + 'HashData' => '00CD5B6C29D4CEA1F3002D785A9F9B09974AD51D', + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ], + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + ], + 'Transaction' => [ + 'Type' => 'postauth', + 'Amount' => 10025, + 'CurrencyCode' => '949', + 'OriginalRetrefNum' => $order->ref_ret_num, + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleStatusRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'Mode' => 'TEST', + 'Version' => 'v0.01', + 'ChannelCode' => '', + 'Terminal' => [ + 'ProvUserID' => $account->getUsername(), + 'UserID' => $account->getUsername(), + 'HashData' => '8DD74209DEEB7D333105E1C69998A827419A3B04', + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ], + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Card' => [ + 'Number' => '', + 'ExpireDate' => '', + 'CVV2' => '', + ], + 'Transaction' => [ + 'Type' => 'orderinq', + 'InstallmentCnt' => '', + 'Amount' => 100, + 'CurrencyCode' => '949', + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + ], + ]; + } + + /** + * @param GarantiPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleRefundXMLData(AbstractPosAccount $account, $order): array + { + return [ + 'Mode' => 'TEST', + 'Version' => 'v0.01', + 'ChannelCode' => '', + 'Terminal' => [ + 'ProvUserID' => $account->getRefundUsername(), + 'UserID' => $account->getRefundUsername(), + 'HashData' => '8DD74209DEEB7D333105E1C69998A827419A3B04', + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ], + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Transaction' => [ + 'Type' => 'refund', + 'InstallmentCnt' => '', + 'Amount' => 100, + 'CurrencyCode' => '949', + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'OriginalRetrefNum' => $order->ref_ret_num, + ], + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleHistoryRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'Mode' => 'TEST', + 'Version' => 'v0.01', + 'ChannelCode' => '', + 'Terminal' => [ + 'ProvUserID' => $account->getUsername(), + 'UserID' => $account->getUsername(), + 'HashData' => '19460C02029180F8F7E19A4835D62E4118600A34', + 'ID' => $account->getTerminalId(), + 'MerchantID' => $account->getClientId(), + ], + 'Customer' => [ + 'IPAddress' => $order->ip, + 'EmailAddress' => $order->email, + ], + 'Order' => [ + 'OrderID' => $order->id, + 'GroupID' => '', + ], + 'Card' => [ + 'Number' => '', + 'ExpireDate' => '', + 'CVV2' => '', + ], + 'Transaction' => [ + 'Type' => 'orderhistoryinq', + 'InstallmentCnt' => '', + 'Amount' => 100, + 'CurrencyCode' => '949', + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + ], + ]; + } + + /** + * @return string[] + */ + private function getSample3DResponseData(): array + { + return [ + 'orderid' => '2020110828BC', + 'md' => '1', + 'xid' => '100000005xid', + 'eci' => '100000005eci', + 'cavv' => 'cavv', + 'txncurrencycode' => 'txncurrencycode', + 'txnamount' => 'txnamount', + 'txntype' => 'txntype', + 'customeripaddress' => 'customeripaddress', + 'customeremailaddress' => 'customeremailaddress', + ]; + } +} diff --git a/tests/Gateways/GarantiPosTest.php b/tests/Gateways/GarantiPosTest.php index 9e884dfc..687d688a 100644 --- a/tests/Gateways/GarantiPosTest.php +++ b/tests/Gateways/GarantiPosTest.php @@ -1,5 +1,7 @@ pos = PosFactory::createPosGateway($this->account); $this->pos->setTestMode(true); $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '21', '12', '122'); - - $this->xmlDecoder = new XmlEncoder(); } + /** + * @return void + */ public function testInit() { $this->assertEquals($this->config['banks'][$this->account->getBank()], $this->pos->getConfig()); @@ -82,312 +78,76 @@ public function testInit() $this->assertNotEmpty($this->pos->getCurrencies()); } + /** + * @return void + */ public function testPrepare() { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); - } - - public function testAmountFormat() - { - $this->assertEquals(100000, GarantiPos::amountFormat(1000)); - $this->assertEquals(100000, GarantiPos::amountFormat(1000.00)); - $this->assertEquals(100001, GarantiPos::amountFormat(1000.01)); - } - - public function testGet3DFormWithCardData() - { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - - $form = [ - 'gateway' => $this->config['banks'][$this->account->getBank()]['urls']['gateway']['test'], - 'inputs' => [ - 'secure3dsecuritylevel' => $this->account->getModel() === AbstractGateway::MODEL_3D_PAY ? '3D_PAY' : '3D', - 'mode' => 'TEST', - 'apiversion' => GarantiPos::API_VERSION, - 'terminalprovuserid' => $this->account->getUsername(), - 'terminaluserid' => $this->account->getUsername(), - 'terminalmerchantid' => $this->account->getClientId(), - 'txntype' => 'sales', - 'txnamount' => GarantiPos::amountFormat($this->order['amount']), - 'txncurrencycode' => $this->pos->mapCurrency($this->order['currency']), - 'txninstallmentcount' => empty($this->order['installment']) ? '' : $this->order['installment'], - 'orderid' => $this->order['id'], - 'terminalid' => $this->account->getTerminalId(), - 'successurl' => $this->order['success_url'], - 'errorurl' => $this->order['fail_url'], - 'customeremailaddress' => isset($this->order['email']) ? $this->order['email'] : null, - 'customeripaddress' => $this->order['ip'], - 'secure3dhash' => '1D319D5EA945F5730FF5BCC970FF96690993F4BD', - 'cardnumber' => $this->card->getNumber(), - 'cardexpiredatemonth' => '12', - 'cardexpiredateyear' => '21', - 'cardcvv2' => $this->card->getCvv(), - ], - ]; - - $actualForm = $this->pos->get3DFormData(); - $this->assertNotEmpty($actualForm['inputs']); - - $this->assertEquals($form, $actualForm); - } - - - public function testGet3DFormWithoutCardData() - { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY); - - $form = [ - 'gateway' => $this->config['banks'][$this->account->getBank()]['urls']['gateway']['test'], - 'inputs' => [ - 'secure3dsecuritylevel' => $this->account->getModel() === AbstractGateway::MODEL_3D_PAY ? '3D_PAY' : '3D', - 'mode' => 'TEST', - 'apiversion' => GarantiPos::API_VERSION, - 'terminalprovuserid' => $this->account->getUsername(), - 'terminaluserid' => $this->account->getUsername(), - 'terminalmerchantid' => $this->account->getClientId(), - 'txntype' => 'sales', - 'txnamount' => GarantiPos::amountFormat($this->order['amount']), - 'txncurrencycode' => $this->pos->mapCurrency($this->order['currency']), - 'txninstallmentcount' => empty($this->order['installment']) ? '' : $this->order['installment'], - 'orderid' => $this->order['id'], - 'terminalid' => $this->account->getTerminalId(), - 'successurl' => $this->order['success_url'], - 'errorurl' => $this->order['fail_url'], - 'customeremailaddress' => isset($this->order['email']) ? $this->order['email'] : null, - 'customeripaddress' => $this->order['ip'], - 'secure3dhash' => '1D319D5EA945F5730FF5BCC970FF96690993F4BD', - ], - ]; - - $actualForm = $this->pos->get3DFormData(); - $this->assertNotEmpty($actualForm['inputs']); - - $this->assertEquals($form, $actualForm); - } - - public function testCreateRegularPaymentXML() - { - $order = [ - 'id' => '2020110828BC', - 'email' => 'samp@iexample.com', - 'name' => 'john doe', - 'user_id' => '1535', - 'ip' => '192.168.1.0', - 'amount' => 100.01, - 'installment' => 0, - 'currency' => 'TRY', - ]; - - /** - * @var GarantiPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->setTestMode(true); - $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet'); - $pos->prepare($order, AbstractGateway::TX_PAY, $card); - - $actualXML = $pos->createRegularPaymentXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPaymentXMLData($pos->getOrder(), $pos->getCard(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateRegularPostXML() - { - $order = [ - 'id' => '2020110828BC', - 'ref_ret_num' => '831803579226', - 'currency' => 'TRY', - 'amount' => 100.01, - 'email' => 'samp@iexample.com', - 'ip' => '192.168.1.0', - ]; - - /** - * @var GarantiPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->setTestMode(true); - $pos->prepare($order, AbstractGateway::TX_POST_PAY); - - $actualXML = $pos->createRegularPostXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPostXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreate3DPaymentXML() - { - $order = [ - 'id' => '2020110828BC', - 'email' => 'samp@iexample.com', - 'name' => 'john doe', - 'user_id' => '1535', - 'ip' => '192.168.1.0', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', - ]; - $responseData = [ - 'orderid' => '2020110828BC', - 'md' => '1', - 'xid' => '100000005xid', - 'eci' => '100000005eci', - 'cavv' => 'cavv', - 'txncurrencycode' => 'txncurrencycode', - 'txnamount' => 'txnamount', - 'txntype' => 'txntype', - 'customeripaddress' => 'customeripaddress', - 'customeremailaddress' => 'customeremailaddress', - ]; - - /** - * @var GarantiPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->setTestMode(true); - $pos->prepare($order, AbstractGateway::TX_PAY); - - $actualXML = $pos->create3DPaymentXML($responseData); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSample3DPaymentXMLData($pos->getOrder(), $pos->getAccount(), $responseData); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateStatusXML() - { - $order = [ - 'id' => '2020110828BC', - 'currency' => 'TRY', - ]; - - /** - * @var GarantiPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->setTestMode(true); - $pos->prepare($order, AbstractGateway::TX_STATUS); - - $actualXML = $pos->createStatusXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleStatusXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - - public function testCreateCancelXML() - { - $order = [ - 'id' => '2020110828BC', - 'currency' => 'TRY', - 'amount' => 10.01, - 'ref_ret_num' => '831803579226', - ]; - - /** - * @var GarantiPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->setTestMode(true); - $pos->prepare($order, AbstractGateway::TX_CANCEL); - - $actualXML = $pos->createCancelXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleCancelXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateRefundXML() - { - $order = [ - 'id' => '2020110828BC', - 'currency' => 'TRY', - 'amount' => 10.01, - 'ref_ret_num' => '831803579226', - ]; - - /** - * @var GarantiPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->setTestMode(true); - $pos->prepare($order, AbstractGateway::TX_REFUND); - - $actualXML = $pos->createRefundXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRefundXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - //$this->assertEquals([], $actualData['Transaction']); + $this->assertSame(10025, $this->pos->getOrder()->amount); + $this->assertSame('949', $this->pos->getOrder()->currency); + $this->assertSame('', $this->pos->getOrder()->installment); } /** - * @uses \Mews\Pos\Gateways\GarantiPos::map3DPayResponseData() - * * @return void + * + * @uses \Mews\Pos\Gateways\GarantiPos::map3DPayResponseData() */ public function testMap3DPayResponseDataSuccess() { $gatewayResponse = [ - "xid" => "bVi+A/h6SjXabcde=", - "mdstatus" => "1", - "mderrormessage" => "TROY Gateway Result: [Code: '000', Message: 'Success', Description: 'Successful']", - "txnstatus" => "", - "eci" => "", - "cavv" => "ABIBBDYABBBBBAAABAAAAAAAAAAA=", - "paressyntaxok" => "", - "paresverified" => "", - "version" => "", - "ireqcode" => "", - "ireqdetail" => "", - "vendorcode" => "", - "cavvalgorithm" => "", - "md" => "longstring", - "terminalid" => "10012345", - "oid" => "1221513409", - "authcode" => "", - "response" => "", - "errmsg" => "", - "hostmsg" => "", - "procreturncode" => "", - "transid" => "1001513409", - "hostrefnum" => "", - "rnd" => "vNOc4abcde2aCL/HBzs", - "hash" => "1I9zDunx0hashTRI816trOG0Ao0=", - "hashparams" => "clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:", - "hashparamsval" => "longstring", - "clientid" => "10012345", - "MaskedPan" => "454311***7965", - "customeripaddress" => "134.170.165.149", - "orderid" => "1221513409", - "txntype" => "sales", - "terminalprovuserid" => "PROVAUT", - "secure3dhash" => "BE3C507794AhashE021E8EA239415D774EEF2", - "mode" => "PROD", - "txncurrencycode" => "949", - "customeremailaddress" => "admin@admin.com", - "terminaluserid" => "PROVAUT", - "terminalmerchantid" => "1234567", - "secure3dsecuritylevel" => "3D", - "user_id" => "1", - "errorurl" => "https://example.com/odeme_basarisiz", - "apiversion" => "v0.01", - "txnamount" => "100", - "txninstallmentcount" => "", - "successurl" => "https://example.com/odeme_basarili", - ]; - $expected = '{"id":"","order_id":"1221513409","trans_id":"1001513409","auth_code":"","host_ref_num":"","response":"Approved","transaction_type":null,"transaction":null,"transaction_security":"Full 3D Secure","proc_return_code":"","code":"","md_status":"1","status":"approved","status_detail":null,"hash":"BE3C507794AhashE021E8EA239415D774EEF2","rand":"vNOc4abcde2aCL\/HBzs","hash_params":"clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:","hash_params_val":"longstring","masked_number":"454311***7965","amount":"100","currency":"949","tx_status":"","eci":"","cavv":"ABIBBDYABBBBBAAABAAAAAAAAAAA=","xid":"bVi+A\/h6SjXabcde=","error_code":null,"error_message":"","md_error_message":"TROY Gateway Result: [Code: \'000\', Message: \'Success\', Description: \'Successful\']","campaign_url":null,"email":"admin@admin.com","extra":null,"3d_all":{"xid":"bVi+A\/h6SjXabcde=","mdstatus":"1","mderrormessage":"TROY Gateway Result: [Code: \'000\', Message: \'Success\', Description: \'Successful\']","txnstatus":"","eci":"","cavv":"ABIBBDYABBBBBAAABAAAAAAAAAAA=","paressyntaxok":"","paresverified":"","version":"","ireqcode":"","ireqdetail":"","vendorcode":"","cavvalgorithm":"","md":"longstring","terminalid":"10012345","oid":"1221513409","authcode":"","response":"","errmsg":"","hostmsg":"","procreturncode":"","transid":"1001513409","hostrefnum":"","rnd":"vNOc4abcde2aCL\/HBzs","hash":"1I9zDunx0hashTRI816trOG0Ao0=","hashparams":"clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:","hashparamsval":"longstring","clientid":"10012345","MaskedPan":"454311***7965","customeripaddress":"134.170.165.149","orderid":"1221513409","txntype":"sales","terminalprovuserid":"PROVAUT","secure3dhash":"BE3C507794AhashE021E8EA239415D774EEF2","mode":"PROD","txncurrencycode":"949","customeremailaddress":"admin@admin.com","terminaluserid":"PROVAUT","terminalmerchantid":"1234567","secure3dsecuritylevel":"3D","user_id":"1","errorurl":"https:\/\/example.com\/odeme_basarisiz","apiversion":"v0.01","txnamount":"100","txninstallmentcount":"","successurl":"https:\/\/example.com\/odeme_basarili"}}'; - $method = $this->getMethod('map3DPayResponseData'); - $result1 = $method->invoke($this->pos, $gatewayResponse); + 'xid' => 'bVi+A/h6SjXabcde=', + 'mdstatus' => '1', + 'mderrormessage' => 'TROY Gateway Result: [Code: \'000\', Message: \'Success\', Description: \'Successful\']', + 'txnstatus' => '', + 'eci' => '', + 'cavv' => 'ABIBBDYABBBBBAAABAAAAAAAAAAA=', + 'paressyntaxok' => '', + 'paresverified' => '', + 'version' => '', + 'ireqcode' => '', + 'ireqdetail' => '', + 'vendorcode' => '', + 'cavvalgorithm' => '', + 'md' => 'longstring', + 'terminalid' => '10012345', + 'oid' => '1221513409', + 'authcode' => '', + 'response' => '', + 'errmsg' => '', + 'hostmsg' => '', + 'procreturncode' => '', + 'transid' => '1001513409', + 'hostrefnum' => '', + 'rnd' => 'vNOc4abcde2aCL/HBzs', + 'hash' => '1I9zDunx0hashTRI816trOG0Ao0=', + 'hashparams' => 'clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:', + 'hashparamsval' => 'longstring', + 'clientid' => '10012345', + 'MaskedPan' => '454311***7965', + 'customeripaddress' => '134.170.165.149', + 'orderid' => '1221513409', + 'txntype' => 'sales', + 'terminalprovuserid' => 'PROVAUT', + 'secure3dhash' => 'BE3C507794AhashE021E8EA239415D774EEF2', + 'mode' => 'PROD', + 'txncurrencycode' => '949', + 'customeremailaddress' => 'admin@admin.com', + 'terminaluserid' => 'PROVAUT', + 'terminalmerchantid' => '1234567', + 'secure3dsecuritylevel' => '3D', + 'user_id' => '1', + 'errorurl' => 'https://example.com/odeme_basarisiz', + 'apiversion' => 'v0.01', + 'txnamount' => '100', + 'txninstallmentcount' => '', + 'successurl' => 'https://example.com/odeme_basarili', + ]; + $expected = '{"id":"","order_id":"1221513409","trans_id":"1001513409","auth_code":"","host_ref_num":"","response":"Approved","transaction_type":null,"transaction":null,"transaction_security":"Full 3D Secure","proc_return_code":"","code":"","md_status":"1","status":"approved","status_detail":null,"hash":"BE3C507794AhashE021E8EA239415D774EEF2","rand":"vNOc4abcde2aCL\/HBzs","hash_params":"clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:","hash_params_val":"longstring","masked_number":"454311***7965","amount":"100","currency":"949","tx_status":"","eci":"","cavv":"ABIBBDYABBBBBAAABAAAAAAAAAAA=","xid":"bVi+A\/h6SjXabcde=","error_code":null,"error_message":"","md_error_message":"TROY Gateway Result: [Code: \'000\', Message: \'Success\', Description: \'Successful\']","campaign_url":null,"email":"admin@admin.com","extra":null,"3d_all":{"xid":"bVi+A\/h6SjXabcde=","mdstatus":"1","mderrormessage":"TROY Gateway Result: [Code: \'000\', Message: \'Success\', Description: \'Successful\']","txnstatus":"","eci":"","cavv":"ABIBBDYABBBBBAAABAAAAAAAAAAA=","paressyntaxok":"","paresverified":"","version":"","ireqcode":"","ireqdetail":"","vendorcode":"","cavvalgorithm":"","md":"longstring","terminalid":"10012345","oid":"1221513409","authcode":"","response":"","errmsg":"","hostmsg":"","procreturncode":"","transid":"1001513409","hostrefnum":"","rnd":"vNOc4abcde2aCL\/HBzs","hash":"1I9zDunx0hashTRI816trOG0Ao0=","hashparams":"clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:","hashparamsval":"longstring","clientid":"10012345","MaskedPan":"454311***7965","customeripaddress":"134.170.165.149","orderid":"1221513409","txntype":"sales","terminalprovuserid":"PROVAUT","secure3dhash":"BE3C507794AhashE021E8EA239415D774EEF2","mode":"PROD","txncurrencycode":"949","customeremailaddress":"admin@admin.com","terminaluserid":"PROVAUT","terminalmerchantid":"1234567","secure3dsecuritylevel":"3D","user_id":"1","errorurl":"https:\/\/example.com\/odeme_basarisiz","apiversion":"v0.01","txnamount":"100","txninstallmentcount":"","successurl":"https:\/\/example.com\/odeme_basarili"}}'; + $method = $this->getMethod('map3DPayResponseData'); + $result1 = $method->invoke($this->pos, $gatewayResponse); $this->assertIsArray($result1); $this->assertSame(json_decode($expected, true), $result1); @@ -395,375 +155,47 @@ public function testMap3DPayResponseDataSuccess() /** * @return void - */ - public function testCreate3DHashFor3DSecure() - { - $expected = '1D319D5EA945F5730FF5BCC970FF96690993F4BD'; - $pos = $this->pos; - $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $pos->create3DHash($pos->getAccount(), $pos->getOrder(), 'sales'); - $this->assertEquals($expected, $actual); - } - - /** - * @return void - */ - public function testCreateHashForPayment() - { - $expected = '00CD5B6C29D4CEA1F3002D785A9F9B09974AD51D'; - $pos = $this->pos; - $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $pos->createHashData($pos->getAccount(), $pos->getOrder(), 'sales'); - $this->assertEquals($expected, $actual); - - $pos->prepare($this->order, AbstractGateway::TX_PRE_PAY); - $actual = $pos->createHashData($pos->getAccount(), $pos->getOrder(), 'preauth'); - $this->assertEquals($expected, $actual); - } - - /** - * @return void - */ - public function testCreateHashForCancelAndRefund() - { - $order = [ - 'id' => '4499996', - 'ref_ret_num' => '446ss', - 'currency' => 'TRY', - ]; - $expected = '9788649A0C3AE14C082783CEA6775E08A7EFB311'; - $pos = $this->pos; - $pos->prepare($order, AbstractGateway::TX_CANCEL); - $actual = $pos->createHashData($pos->getAccount(), $pos->getOrder(), 'void'); - $this->assertEquals($expected, $actual); - - $pos->prepare($order, AbstractGateway::TX_REFUND); - $actual = $pos->createHashData($pos->getAccount(), $pos->getOrder(), 'refund'); - $this->assertEquals($expected, $actual); - } - - /** - * @uses \Mews\Pos\Gateways\GarantiPos::map3DPayResponseData() * - * @return void + * @uses \Mews\Pos\Gateways\GarantiPos::map3DPayResponseData() */ public function testMap3DPayResponseDataFail() { - $failResponse = [ - "mdstatus" => "0", - "mderrormessage" => "User Gave Up", - "errmsg" => "User Gave Up", - "clientid" => "10012345", - "oid" => "1221166825", - "response" => "Error", - "procreturncode" => "99", - "customeripaddress" => "111.222.333.444", - "orderid" => "1221166825", - "txntype" => "sales", - "terminalprovuserid" => "PROVAUT", - "secure3dhash" => "hashhash", - "mode" => "PROD", - "terminalid" => "10012345", - "txncurrencycode" => "949", - "customeremailaddress" => "admin@admin.com", - "terminaluserid" => "PROVAUT", - "terminalmerchantid" => "5220607", - "secure3dsecuritylevel" => "3D", - "user_id" => "1", - "errorurl" => "https://example.com/odeme_basarisiz", - "apiversion" => "v0.01", - "txnamount" => "9000", - "txninstallmentcount" => "", - "successurl" => "https://example.com/odeme_basarili", - ]; - $expected = '{"id":null,"order_id":"1221166825","trans_id":null,"auth_code":null,"host_ref_num":null,"response":"Declined","transaction_type":null,"transaction":null,"transaction_security":"MPI fallback","proc_return_code":"99","code":"99","md_status":"0","status":"declined","status_detail":"99","hash":"hashhash","rand":null,"hash_params":null,"hash_params_val":null,"masked_number":null,"amount":"9000","currency":"949","tx_status":null,"eci":null,"cavv":null,"xid":null,"error_code":"99","error_message":"User Gave Up","md_error_message":"User Gave Up","campaign_url":null,"email":"admin@admin.com","extra":null,"3d_all":{"mdstatus":"0","mderrormessage":"User Gave Up","errmsg":"User Gave Up","clientid":"10012345","oid":"1221166825","response":"Error","procreturncode":"99","customeripaddress":"111.222.333.444","orderid":"1221166825","txntype":"sales","terminalprovuserid":"PROVAUT","secure3dhash":"hashhash","mode":"PROD","terminalid":"10012345","txncurrencycode":"949","customeremailaddress":"admin@admin.com","terminaluserid":"PROVAUT","terminalmerchantid":"5220607","secure3dsecuritylevel":"3D","user_id":"1","errorurl":"https:\/\/example.com\/odeme_basarisiz","apiversion":"v0.01","txnamount":"9000","txninstallmentcount":"","successurl":"https:\/\/example.com\/odeme_basarili"}}'; - $method = $this->getMethod('map3DPayResponseData'); - $result1 = $method->invoke($this->pos, $failResponse); + $failResponse = [ + 'mdstatus' => '0', + 'mderrormessage' => 'User Gave Up', + 'errmsg' => 'User Gave Up', + 'clientid' => '10012345', + 'oid' => '1221166825', + 'response' => 'Error', + 'procreturncode' => '99', + 'customeripaddress' => '111.222.333.444', + 'orderid' => '1221166825', + 'txntype' => 'sales', + 'terminalprovuserid' => 'PROVAUT', + 'secure3dhash' => 'hashhash', + 'mode' => 'PROD', + 'terminalid' => '10012345', + 'txncurrencycode' => '949', + 'customeremailaddress' => 'admin@admin.com', + 'terminaluserid' => 'PROVAUT', + 'terminalmerchantid' => '5220607', + 'secure3dsecuritylevel' => '3D', + 'user_id' => '1', + 'errorurl' => 'https://example.com/odeme_basarisiz', + 'apiversion' => 'v0.01', + 'txnamount' => '9000', + 'txninstallmentcount' => '', + 'successurl' => 'https://example.com/odeme_basarili', + ]; + $expected = '{"id":null,"order_id":"1221166825","trans_id":null,"auth_code":null,"host_ref_num":null,"response":"Declined","transaction_type":null,"transaction":null,"transaction_security":"MPI fallback","proc_return_code":"99","code":"99","md_status":"0","status":"declined","status_detail":"99","hash":"hashhash","rand":null,"hash_params":null,"hash_params_val":null,"masked_number":null,"amount":"9000","currency":"949","tx_status":null,"eci":null,"cavv":null,"xid":null,"error_code":"99","error_message":"User Gave Up","md_error_message":"User Gave Up","campaign_url":null,"email":"admin@admin.com","extra":null,"3d_all":{"mdstatus":"0","mderrormessage":"User Gave Up","errmsg":"User Gave Up","clientid":"10012345","oid":"1221166825","response":"Error","procreturncode":"99","customeripaddress":"111.222.333.444","orderid":"1221166825","txntype":"sales","terminalprovuserid":"PROVAUT","secure3dhash":"hashhash","mode":"PROD","terminalid":"10012345","txncurrencycode":"949","customeremailaddress":"admin@admin.com","terminaluserid":"PROVAUT","terminalmerchantid":"5220607","secure3dsecuritylevel":"3D","user_id":"1","errorurl":"https:\/\/example.com\/odeme_basarisiz","apiversion":"v0.01","txnamount":"9000","txninstallmentcount":"","successurl":"https:\/\/example.com\/odeme_basarili"}}'; + $method = $this->getMethod('map3DPayResponseData'); + $result1 = $method->invoke($this->pos, $failResponse); $this->assertSame(json_decode($expected, true), $result1); } - /** - * @param $order - * @param AbstractCreditCard $card - * @param GarantiPosAccount $account - * - * @return array - */ - private function getSampleRegularPaymentXMLData($order, AbstractCreditCard $card, GarantiPosAccount $account) - { - return [ - 'Mode' => 'TEST', - 'Version' => GarantiPos::API_VERSION, - 'Terminal' => [ - 'ProvUserID' => $account->getUsername(), - 'UserID' => $account->getUsername(), - 'HashData' => 'F0641E566B7B98260FD1608D1DF81E8D55461877', - 'ID' => $account->getTerminalId(), - 'MerchantID' => $account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, - ], - 'Card' => [ - 'Number' => $card->getNumber(), - 'ExpireDate' => '0122', - 'CVV2' => $card->getCvv(), - ], - 'Order' => [ - 'OrderID' => $order->id, - 'GroupID' => '', - 'AddressList' => [ - 'Address' => [ - 'Type' => 'S', - 'Name' => $order->name, - 'LastName' => '', - 'Company' => '', - 'Text' => '', - 'District' => '', - 'City' => '', - 'PostalCode' => '', - 'Country' => '', - 'PhoneNumber' => '', - ], - ], - ], - 'Transaction' => [ - 'Type' => 'sales', - 'InstallmentCnt' => $order->installment, - 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - 'Description' => '', - 'OriginalRetrefNum' => '', - ], - ]; - } - - /** - * @param $order - * @param GarantiPosAccount $account - * - * @return array - */ - private function getSampleRegularPostXMLData($order, $account) - { - return [ - 'Mode' => 'TEST', - 'Version' => GarantiPos::API_VERSION, - 'Terminal' => [ - 'ProvUserID' => $account->getUsername(), - 'UserID' => $account->getUsername(), - 'HashData' => '7598B3D1A15C45095CD139E9CFD780B050D1C4AA', - 'ID' => $account->getTerminalId(), - 'MerchantID' => $account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, - ], - 'Order' => [ - 'OrderID' => $order->id, - ], - 'Transaction' => [ - 'Type' => 'postauth', - 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, - 'OriginalRetrefNum' => $order->ref_ret_num, - ], - ]; - } - - /** - * @param $order - * @param GarantiPosAccount $account - * @param array $responseData - * - * @return array - */ - private function getSample3DPaymentXMLData($order, $account, array $responseData) - { - return [ - 'Mode' => 'TEST', - 'Version' => GarantiPos::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $account->getUsername(), - 'UserID' => $account->getUsername(), - 'HashData' => '7598B3D1A15C45095CD139E9CFD780B050D1C4AA', - 'ID' => $account->getTerminalId(), - 'MerchantID' => $account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $responseData['customeripaddress'], - 'EmailAddress' => $responseData['customeremailaddress'], - ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', - ], - 'Order' => [ - 'OrderID' => $responseData['orderid'], - 'GroupID' => '', - 'AddressList' => [ - 'Address' => [ - 'Type' => 'B', - 'Name' => $order->name, - 'LastName' => '', - 'Company' => '', - 'Text' => '', - 'District' => '', - 'City' => '', - 'PostalCode' => '', - 'Country' => '', - 'PhoneNumber' => '', - ], - ], - ], - 'Transaction' => [ - 'Type' => $responseData['txntype'], - 'InstallmentCnt' => $order->installment, - 'Amount' => $responseData['txnamount'], - 'CurrencyCode' => $responseData['txncurrencycode'], - 'CardholderPresentCode' => '13', - 'MotoInd' => 'N', - 'Secure3D' => [ - 'AuthenticationCode' => $responseData['cavv'], - 'SecurityLevel' => $responseData['eci'], - 'TxnID' => $responseData['xid'], - 'Md' => $responseData['md'], - ], - ], - ]; - } - - /** - * @param $order - * @param GarantiPosAccount $account - * - * @return array - */ - private function getSampleStatusXMLData($order, $account) - { - return [ - 'Mode' => 'TEST', - 'Version' => GarantiPos::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $account->getUsername(), - 'UserID' => $account->getUsername(), - 'HashData' => '8DD74209DEEB7D333105E1C69998A827419A3B04', - 'ID' => $account->getTerminalId(), - 'MerchantID' => $account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, - ], - 'Order' => [ - 'OrderID' => $order->id, - 'GroupID' => '', - ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', - ], - 'Transaction' => [ - 'Type' => 'orderinq', - 'InstallmentCnt' => '', - 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - ], - ]; - } - - /** - * @param $order - * @param GarantiPosAccount $account - * - * @return array - */ - private function getSampleCancelXMLData($order, $account) - { - return [ - 'Mode' => 'TEST', - 'Version' => GarantiPos::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $account->getRefundUsername(), - 'UserID' => $account->getRefundUsername(), - 'HashData' => '8DD74209DEEB7D333105E1C69998A827419A3B04', - 'ID' => $account->getTerminalId(), - 'MerchantID' => $account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, - ], - 'Order' => [ - 'OrderID' => $order->id, - 'GroupID' => '', - ], - 'Transaction' => [ - 'Type' => 'void', - 'InstallmentCnt' => $order->installment, - 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - 'OriginalRetrefNum' => $order->ref_ret_num, - ], - ]; - - } - - /** - * @param $order - * @param GarantiPosAccount $account - * - * @return array - */ - private function getSampleRefundXMLData($order, $account) - { - return [ - 'Mode' => 'TEST', - 'Version' => GarantiPos::API_VERSION, - 'ChannelCode' => '', - 'Terminal' => [ - 'ProvUserID' => $account->getRefundUsername(), - 'UserID' => $account->getRefundUsername(), - 'HashData' => '8DD74209DEEB7D333105E1C69998A827419A3B04', - 'ID' => $account->getTerminalId(), - 'MerchantID' => $account->getClientId(), - ], - 'Customer' => [ - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, - ], - 'Order' => [ - 'OrderID' => $order->id, - 'GroupID' => '', - ], - 'Transaction' => [ - 'Type' => 'refund', - 'InstallmentCnt' => '', - 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, - 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', - 'OriginalRetrefNum' => $order->ref_ret_num, - ], - ]; - } - private static function getMethod(string $name): ReflectionMethod { - $class = new ReflectionClass(GarantiPos::class); + $class = new ReflectionClass(GarantiPos::class); $method = $class->getMethod($name); $method->setAccessible(true); From f55f1499737c1bb848e25000709871f236f42fbb Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Wed, 27 Apr 2022 21:43:47 +0200 Subject: [PATCH 09/40] GarantiPosRequestDataMapper removed unnecessary fields --- .../GarantiPosRequestDataMapper.php | 34 +++++-------------- .../GarantiPosRequestDataMapperTest.php | 28 --------------- 2 files changed, 9 insertions(+), 53 deletions(-) diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index b3ae4554..d9b6d917 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -28,6 +28,7 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper AbstractGateway::MODEL_NON_SECURE => null, ]; + /** * @inheritdoc */ @@ -65,16 +66,13 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, return [ 'Mode' => $this->getMode(), 'Version' => self::API_VERSION, - 'ChannelCode' => '', 'Terminal' => $this->getTerminalData($account, $hash), 'Customer' => [ 'IPAddress' => $responseData['customeripaddress'], 'EmailAddress' => $responseData['customeremailaddress'], ], - 'Card' => $this->getCardData(), 'Order' => [ 'OrderID' => $responseData['orderid'], - 'GroupID' => '', 'AddressList' => $this->getOrderAddressData($order), ], 'Transaction' => [ @@ -114,7 +112,6 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'Card' => $this->getCardData($card), 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', 'AddressList' => $this->getOrderAddressData($order), ], 'Transaction' => [ @@ -124,8 +121,6 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'CurrencyCode' => $order->currency, 'CardholderPresentCode' => '0', 'MotoInd' => 'N', - 'Description' => '', - 'OriginalRetrefNum' => '', //todo try removing it ], ]; } @@ -171,22 +166,19 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar return [ 'Mode' => $this->getMode(), 'Version' => self::API_VERSION, - 'ChannelCode' => '', 'Terminal' => $this->getTerminalData($account, $hash), 'Customer' => [ - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, //TODO we need this data? + 'IPAddress' => $order->ip ?? '', + 'EmailAddress' => $order->email ?? '', ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', ], - 'Card' => $this->getCardData(), 'Transaction' => [ 'Type' => $this->txTypeMappings[AbstractGateway::TX_STATUS], 'InstallmentCnt' => $order->installment, - 'Amount' => $order->amount, //TODO we need it? - 'CurrencyCode' => $order->currency, //TODO we need it? + 'Amount' => $order->amount, + 'CurrencyCode' => $order->currency, 'CardholderPresentCode' => '0', 'MotoInd' => 'N', ], @@ -205,15 +197,13 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar return [ 'Mode' => $this->getMode(), 'Version' => self::API_VERSION, - 'ChannelCode' => '', 'Terminal' => $this->getTerminalData($account, $hash, true), 'Customer' => [ - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, + 'IPAddress' => $order->ip ?? '', + 'EmailAddress' => $order->email ?? '', ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', ], 'Transaction' => [ 'Type' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], @@ -240,7 +230,6 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar return [ 'Mode' => $this->getMode(), 'Version' => self::API_VERSION, - 'ChannelCode' => '', 'Terminal' => $this->getTerminalData($account, $hash, true), 'Customer' => [ 'IPAddress' => $order->ip, @@ -248,7 +237,6 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', ], 'Transaction' => [ 'Type' => $txType, @@ -275,18 +263,14 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar return [ 'Mode' => $this->getMode(), 'Version' => self::API_VERSION, - 'ChannelCode' => '', 'Terminal' => $this->getTerminalData($account, $hash), 'Customer' => [ - //TODO we need this data? - 'IPAddress' => $order->ip, - 'EmailAddress' => $order->email, + 'IPAddress' => $order->ip ?? '', + 'EmailAddress' => $order->email ?? '', ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', ], - 'Card' => $this->getCardData(), 'Transaction' => [ 'Type' => $txType, 'InstallmentCnt' => $order->installment, diff --git a/tests/DataMapper/GarantiPosRequestDataMapperTest.php b/tests/DataMapper/GarantiPosRequestDataMapperTest.php index d233bb11..ee6bc609 100644 --- a/tests/DataMapper/GarantiPosRequestDataMapperTest.php +++ b/tests/DataMapper/GarantiPosRequestDataMapperTest.php @@ -325,7 +325,6 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord return [ 'Mode' => 'TEST', 'Version' => 'v0.01', - 'ChannelCode' => '', 'Terminal' => [ 'ProvUserID' => $account->getUsername(), 'UserID' => $account->getUsername(), @@ -337,14 +336,8 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord 'IPAddress' => $responseData['customeripaddress'], 'EmailAddress' => $responseData['customeremailaddress'], ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', - ], 'Order' => [ 'OrderID' => $responseData['orderid'], - 'GroupID' => '', 'AddressList' => [ 'Address' => [ 'Type' => 'B', @@ -388,7 +381,6 @@ private function getSampleCancelXMLData(AbstractPosAccount $account, $order): ar return [ 'Mode' => 'TEST', 'Version' => 'v0.01', - 'ChannelCode' => '', 'Terminal' => [ 'ProvUserID' => $account->getRefundUsername(), 'UserID' => $account->getRefundUsername(), @@ -402,7 +394,6 @@ private function getSampleCancelXMLData(AbstractPosAccount $account, $order): ar ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', ], 'Transaction' => [ 'Type' => 'void', @@ -446,7 +437,6 @@ private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $accoun ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', 'AddressList' => [ 'Address' => [ 'Type' => 'B', @@ -469,8 +459,6 @@ private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $accoun 'CurrencyCode' => 949, 'CardholderPresentCode' => '0', 'MotoInd' => 'N', - 'Description' => '', - 'OriginalRetrefNum' => '', ], ]; } @@ -520,7 +508,6 @@ private function getSampleStatusRequestData(AbstractPosAccount $account, $order) return [ 'Mode' => 'TEST', 'Version' => 'v0.01', - 'ChannelCode' => '', 'Terminal' => [ 'ProvUserID' => $account->getUsername(), 'UserID' => $account->getUsername(), @@ -534,12 +521,6 @@ private function getSampleStatusRequestData(AbstractPosAccount $account, $order) ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', - ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', ], 'Transaction' => [ 'Type' => 'orderinq', @@ -563,7 +544,6 @@ private function getSampleRefundXMLData(AbstractPosAccount $account, $order): ar return [ 'Mode' => 'TEST', 'Version' => 'v0.01', - 'ChannelCode' => '', 'Terminal' => [ 'ProvUserID' => $account->getRefundUsername(), 'UserID' => $account->getRefundUsername(), @@ -577,7 +557,6 @@ private function getSampleRefundXMLData(AbstractPosAccount $account, $order): ar ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', ], 'Transaction' => [ 'Type' => 'refund', @@ -602,7 +581,6 @@ private function getSampleHistoryRequestData(AbstractPosAccount $account, $order return [ 'Mode' => 'TEST', 'Version' => 'v0.01', - 'ChannelCode' => '', 'Terminal' => [ 'ProvUserID' => $account->getUsername(), 'UserID' => $account->getUsername(), @@ -616,12 +594,6 @@ private function getSampleHistoryRequestData(AbstractPosAccount $account, $order ], 'Order' => [ 'OrderID' => $order->id, - 'GroupID' => '', - ], - 'Card' => [ - 'Number' => '', - 'ExpireDate' => '', - 'CVV2' => '', ], 'Transaction' => [ 'Type' => 'orderhistoryinq', From bfbab3f7392ffd6ee2288ade86d6c47f5e753b6b Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Wed, 27 Apr 2022 21:45:50 +0200 Subject: [PATCH 10/40] GarantiPosRequestDataMapper removed MotoInd value with constant --- src/DataMapper/GarantiPosRequestDataMapper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index d9b6d917..e8f70624 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -54,6 +54,8 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper 'RUB' => 643, ]; + private const MOTO = 'N'; + /** * @param GarantiPosAccount $account * @@ -81,7 +83,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'Amount' => $responseData['txnamount'], 'CurrencyCode' => $responseData['txncurrencycode'], 'CardholderPresentCode' => '13', //13 for 3D secure payment - 'MotoInd' => 'N', + 'MotoInd' => self::MOTO, 'Secure3D' => [ 'AuthenticationCode' => $responseData['cavv'], 'SecurityLevel' => $responseData['eci'], @@ -120,7 +122,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'Amount' => $order->amount, 'CurrencyCode' => $order->currency, 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', + 'MotoInd' => self::MOTO, ], ]; } @@ -180,7 +182,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar 'Amount' => $order->amount, 'CurrencyCode' => $order->currency, 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', + 'MotoInd' => self::MOTO, ], ]; } @@ -211,7 +213,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $order->currency, 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', + 'MotoInd' => self::MOTO, 'OriginalRetrefNum' => $order->ref_ret_num, ], ]; @@ -244,7 +246,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'Amount' => $order->amount, 'CurrencyCode' => $order->currency, 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', + 'MotoInd' => self::MOTO, 'OriginalRetrefNum' => $order->ref_ret_num, ], ]; @@ -277,7 +279,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $order->currency, 'CardholderPresentCode' => '0', - 'MotoInd' => 'N', + 'MotoInd' => self::MOTO, ], ]; } From ecfc6300cd3bb9eb652144bc5ae464043f82f78e Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Wed, 27 Apr 2022 21:47:53 +0200 Subject: [PATCH 11/40] GarantiPosRequestDataMapper added recurring order support --- examples/garanti/_payment_config.php | 9 +++- .../GarantiPosRequestDataMapper.php | 54 +++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/examples/garanti/_payment_config.php b/examples/garanti/_payment_config.php index 3bff73a1..6c3cb345 100644 --- a/examples/garanti/_payment_config.php +++ b/examples/garanti/_payment_config.php @@ -52,7 +52,14 @@ function getNewOrder( ?int $installment = 0, bool $tekrarlanan = false ): array { - return createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, \Mews\Pos\Gateways\GarantiPos::LANG_TR); + $order = createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, \Mews\Pos\Gateways\GarantiPos::LANG_TR); + if ($tekrarlanan) { + $order['recurringFrequencyType'] = 'MONTH'; + $order['recurringFrequency'] = 2; + $order['recurringInstallmentCount'] = 3; + } + + return $order; } function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\Entity\Card\AbstractCreditCard $card) diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index e8f70624..17660863 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -10,7 +10,6 @@ use Mews\Pos\Gateways\AbstractGateway; /** - * todo tekrarlanan odemeyi ekle * Creates request data for GarantiPos Gateway requests */ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper @@ -56,6 +55,12 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper private const MOTO = 'N'; + protected $recurringOrderFrequencyMapping = [ + 'DAY' => 'D', + 'WEEK' => 'W', + 'MONTH' => 'M', + ]; + /** * @param GarantiPosAccount $account * @@ -65,7 +70,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, { $hash = $this->createHash($account, $order, $txType); - return [ + $result = [ 'Mode' => $this->getMode(), 'Version' => self::API_VERSION, 'Terminal' => $this->getTerminalData($account, $hash), @@ -92,6 +97,12 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, ], ], ]; + + if (isset($order->recurringInstallmentCount)) { + $result['Recurring'] = $this->createRecurringData($order); + } + + return $result; } /** @@ -103,7 +114,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ { $hash = $this->createHash($account, $order, $txType, $card); - return [ + $result = [ 'Mode' => $this->getMode(), 'Version' => self::API_VERSION, 'Terminal' => $this->getTerminalData($account, $hash), @@ -125,6 +136,12 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'MotoInd' => self::MOTO, ], ]; + + if (isset($order->recurringInstallmentCount)) { + $result['Recurring'] = $this->createRecurringData($order); + } + + return $result; } /** @@ -486,4 +503,35 @@ private function getOrderAddressData($order): array ], ]; } + + /** + * ornek: + * + * G veya R R:Sabit Tutarli G:Degisken Tutar + * + * M , W , D Monthly, weekly, daily + * + * + * + * + * + * + * YYYYMMDD + * + * + * + * @param $order + * + * @return array + */ + private function createRecurringData($order): array + { + return [ + 'TotalPaymentNum' => $order->recurringInstallmentCount, //kac kere tekrarlanacak + 'FrequencyType' => $this->mapRecurringFrequency($order->recurringFrequencyType), //Monthly, weekly, daily + 'FrequencyInterval' => $order->recurringFrequency, + 'Type' => $order->recurringType ?? 'R', //R:Sabit Tutarli G:Degisken Tuta + 'StartDate' => $order->startDate ?? '', + ]; + } } From 832b6015c9d12758b6d4699959ead89b059ee359 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Thu, 28 Apr 2022 21:13:55 +0200 Subject: [PATCH 12/40] GarantiPos removed forgotten code --- src/Gateways/GarantiPos.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index df5651a7..2890fe65 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -67,7 +67,6 @@ public function __construct($config, $account, array $currencies = []) $this->types = $this->requestDataMapper->getTxTypeMappings(); $this->currencies = $this->requestDataMapper->getCurrencyMappings(); $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - $this->requestDataMapper->setTestMode(true); parent::__construct($config, $account, $currencies); } From 71ce46cc3e69b137b3e22cb4284a628adaa7d49d Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 19:10:17 +0200 Subject: [PATCH 13/40] created EstPosRequestDataMapper --- src/DataMapper/EstPosRequestDataMapper.php | 312 +++++++++ src/Gateways/EstPos.php | 230 +------ .../EstPosRequestDataMapperTest.php | 594 ++++++++++++++++++ tests/Factory/CreditCardFactoryTest.php | 8 +- tests/Gateways/EstPostTest.php | 512 +-------------- 5 files changed, 933 insertions(+), 723 deletions(-) create mode 100644 src/DataMapper/EstPosRequestDataMapper.php create mode 100644 tests/DataMapper/EstPosRequestDataMapperTest.php diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php new file mode 100644 index 00000000..0d42cdfd --- /dev/null +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -0,0 +1,312 @@ + 'Auth', + AbstractGateway::TX_PRE_PAY => 'PreAuth', + AbstractGateway::TX_POST_PAY => 'PostAuth', + AbstractGateway::TX_CANCEL => 'Void', + AbstractGateway::TX_REFUND => 'Credit', + AbstractGateway::TX_STATUS => 'ORDERSTATUS', + AbstractGateway::TX_HISTORY => 'ORDERHISTORY', + ]; + + protected $cardTypeMapping = [ + AbstractCreditCard::CARD_TYPE_VISA => '1', + AbstractCreditCard::CARD_TYPE_MASTERCARD => '2', + ]; + + protected $recurringOrderFrequencyMapping = [ + 'DAY' => 'D', + 'WEEK' => 'W', + 'MONTH' => 'M', + 'YEAR' => 'Y', + ]; + //todo store type degerleri ekle + + protected $secureTypeMappings = [ + AbstractGateway::MODEL_3D_SECURE => '3d', + AbstractGateway::MODEL_3D_PAY => '3d_pay', + AbstractGateway::MODEL_3D_HOST => '3d_host', + AbstractGateway::MODEL_NON_SECURE => 'regular', + ]; + + /** + * @inheritdoc + */ + protected $currencyMappings = [ + 'TRY' => 949, + 'USD' => 840, + 'EUR' => 978, + 'GBP' => 826, + 'JPY' => 392, + 'RUB' => 643, + ]; + + /** + * @inheritDoc + */ + public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData): array + { + $requestData = [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'Type' => $txType, + 'IPAddress' => $order->ip, + 'Email' => $order->email, + 'OrderId' => $order->id, + 'UserId' => $order->user_id ?? null, + 'Total' => $order->amount, + 'Currency' => $order->currency, + 'Taksit' => $order->installment, + 'Number' => $responseData['md'], + 'Expires' => '', //todo + 'Cvv2Val' => '', //todo + 'PayerTxnId' => $responseData['xid'], + 'PayerSecurityLevel' => $responseData['eci'], + 'PayerAuthenticationCode' => $responseData['cavv'], + 'CardholderPresentCode' => '13', + 'Mode' => 'P', + 'GroupId' => '', + 'TransId' => '', + ]; + + if ($order->name) { + $requestData['BillTo'] = [ + 'Name' => $order->name, + ]; + } + + if (isset($order->recurringFrequency)) { + $requestData['PbOrder'] = [ + 'OrderType' => 0, + // Periyodik İşlem Frekansı + 'OrderFrequencyInterval' => $order->recurringFrequency, + //D|M|Y + 'OrderFrequencyCycle' => $this->mapRecurringFrequency($order->recurringFrequencyType), + 'TotalNumberPayments' => $order->recurringInstallmentCount, + ]; + } + + return $requestData; + } + + /** + * @inheritDoc + */ + public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'Type' => $txType, + 'IPAddress' => $order->ip, + 'Email' => $order->email, + 'OrderId' => $order->id, + 'UserId' => $order->user_id ?? null, + 'Total' => $order->amount, + 'Currency' => $order->currency, + 'Taksit' => $order->installment, + 'CardType' => $card->getType(), //todo remove + 'Number' => $card->getNumber(), + 'Expires' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), + 'Cvv2Val' => $card->getCvv(), + 'Mode' => 'P', //TODO what is this constant for? + 'GroupId' => '', + 'TransId' => '', + 'BillTo' => [ + 'Name' => $order->name ?: null, + ], + ]; + } + + /** + * @inheritDoc + */ + public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'Type' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'OrderId' => $order->id, + ]; + } + + /** + * @inheritDoc + */ + public function createStatusRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $order->id, + 'Extra' => [ + $this->txTypeMappings[AbstractGateway::TX_STATUS] => 'QUERY', + ], + ]; + } + + /** + * todo + * @inheritDoc + */ + public function createCancelRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $order->id, + 'Type' => 'Void', + ]; + } + + /** + * @inheritDoc + */ + public function createRefundRequestData(AbstractPosAccount $account, $order): array + { + $requestData = [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $order->id, + 'Currency' => $order->currency, + 'Type' => $this->txTypeMappings[AbstractGateway::TX_REFUND], + ]; + + if (isset($order->amount)) { + $requestData['Total'] = $order->amount; + } + + return $requestData; + } + + /** + * todo + * @inheritDoc + */ + public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array + { + $requestData = [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $extraData['order_id'], //todo orderId ya da id olarak degistirilecek, Payfor'da orderId, Garanti'de id + 'Extra' => [ + $this->txTypeMappings[AbstractGateway::TX_HISTORY] => 'QUERY', + ], + ]; + + return $requestData; + } + + + /** + * todo + * @inheritDoc + */ + public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null): array + { + if (!$order) { + return []; + } + + $order->hash = $this->create3DHash($account, $order, $txType); + + $inputs = [ + 'clientid' => $account->getClientId(), + 'storetype' => $account->getModel(), + 'hash' => $order->hash, + 'firmaadi' => $order->name, + 'Email' => $order->email, + 'amount' => $order->amount, + 'oid' => $order->id, + 'okUrl' => $order->success_url, + 'failUrl' => $order->fail_url, + 'rnd' => $order->rand, + 'lang' => $this->getLang($account, $order), + 'currency' => $order->currency, + ]; + + if ($account->getModel() === AbstractGateway::MODEL_3D_PAY || $account->getModel() === AbstractGateway::MODEL_3D_HOST) { + $inputs = array_merge($inputs, [ + 'islemtipi' => $txType, + 'taksit' => $order->installment, + ]); + } + + if ($card) { + //todo check card type + $inputs['cardType'] = $this->cardTypeMapping[$card->getType()]; + $inputs['pan'] = $card->getNumber(); + $inputs['Ecom_Payment_Card_ExpDate_Month'] = $card->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT); + $inputs['Ecom_Payment_Card_ExpDate_Year'] = $card->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT); + $inputs['cv2'] = $card->getCvv(); + } + + return [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + } + + /** + * @inheritDoc + */ + public function create3DHash(AbstractPosAccount $account, $order, string $txType): string + { + $hashData = []; + if ($account->getModel() === AbstractGateway::MODEL_3D_SECURE) { + $hashData = [ + $account->getClientId(), + $order->id, + $order->amount, + $order->success_url, + $order->fail_url, + $order->rand, + $account->getStoreKey(), + ]; + } elseif ($account->getModel() === AbstractGateway::MODEL_3D_PAY || $account->getModel() === AbstractGateway::MODEL_3D_HOST) { + $hashData = [ + $account->getClientId(), + $order->id, + $order->amount, + $order->success_url, + $order->fail_url, + $txType, + $order->installment, + $order->rand, + $account->getStoreKey(), + ]; + } + $hashStr = implode(static::HASH_SEPARATOR, $hashData); + + return $this->hashString($hashStr); + } +} diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index ac68dbaf..b3ad685c 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -3,6 +3,7 @@ namespace Mews\Pos\Gateways; use GuzzleHttp\Client; +use Mews\Pos\DataMapper\EstPosRequestDataMapper; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\EstPosAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; @@ -22,15 +23,6 @@ class EstPos extends AbstractGateway * @const string */ public const NAME = 'EstPos'; - public const CREDIT_CARD_EXP_DATE_FORMAT = 'm/y'; - public const CREDIT_CARD_EXP_MONTH_FORMAT = 'm'; - public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y'; - - protected $cardTypeMapping = [ - AbstractCreditCard::CARD_TYPE_VISA => '1', - AbstractCreditCard::CARD_TYPE_MASTERCARD => '2', - ]; - /** * Response Codes @@ -53,42 +45,6 @@ class EstPos extends AbstractGateway '99' => 'general_error', ]; - /** - * Transaction Types - * - * @var array - */ - protected $types = [ - self::TX_PAY => 'Auth', - self::TX_PRE_PAY => 'PreAuth', - self::TX_POST_PAY => 'PostAuth', - self::TX_CANCEL => 'Void', - self::TX_REFUND => 'Credit', - self::TX_STATUS => 'ORDERSTATUS', - self::TX_HISTORY => 'ORDERHISTORY', - ]; - - protected $recurringOrderFrequencyMapping = [ - 'DAY' => 'D', - 'WEEK' => 'W', - 'MONTH' => 'M', - 'YEAR' => 'Y', - ]; - - /** - * Currency mapping - * - * @var array - */ - protected $currencies = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 643, - ]; - /** * @var EstPosAccount */ @@ -108,6 +64,11 @@ class EstPos extends AbstractGateway */ public function __construct($config, $account, array $currencies = []) { + $this->requestDataMapper = new EstPosRequestDataMapper($currencies); + $this->types = $this->requestDataMapper->getTxTypeMappings(); + $this->currencies = $this->requestDataMapper->getCurrencyMappings(); + $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); + parent::__construct($config, $account, $currencies); } @@ -130,33 +91,7 @@ public function createXML(array $nodes, string $encoding = 'ISO-8859-9', bool $i */ public function create3DHash(AbstractPosAccount $account, $order, string $txType): string { - $hashData = []; - if ($account->getModel() === self::MODEL_3D_SECURE) { - $hashData = [ - $account->getClientId(), - $order->id, - $order->amount, - $order->success_url, - $order->fail_url, - $order->rand, - $account->getStoreKey(), - ]; - } elseif ($account->getModel() === self::MODEL_3D_PAY || $account->getModel() === self::MODEL_3D_HOST) { - $hashData = [ - $account->getClientId(), - $order->id, - $order->amount, - $order->success_url, - $order->fail_url, - $txType, - $order->installment, - $order->rand, - $account->getStoreKey(), - ]; - } - $hashStr = implode(static::HASH_SEPARATOR, $hashData); - - return $this->hashString($hashStr); + return $this->requestDataMapper->create3DHash($account, $order, $txType); } /** @@ -245,42 +180,7 @@ public function get3DFormData(): array return []; } - $this->order->hash = $this->create3DHash($this->account, $this->order, $this->type); - - $inputs = [ - 'clientid' => $this->account->getClientId(), - 'storetype' => $this->account->getModel(), - 'hash' => $this->order->hash, - 'firmaadi' => $this->order->name, - 'Email' => $this->order->email, - 'amount' => $this->order->amount, - 'oid' => $this->order->id, - 'okUrl' => $this->order->success_url, - 'failUrl' => $this->order->fail_url, - 'rnd' => $this->order->rand, - 'lang' => $this->getLang(), - 'currency' => $this->order->currency, - ]; - - if ($this->account->getModel() === self::MODEL_3D_PAY || $this->account->getModel() === self::MODEL_3D_HOST) { - $inputs = array_merge($inputs, [ - 'islemtipi' => $this->type, - 'taksit' => $this->order->installment, - ]); - } - - if ($this->card) { - $inputs['cardType'] = $this->cardTypeMapping[$this->card->getType()]; - $inputs['pan'] = $this->card->getNumber(); - $inputs['Ecom_Payment_Card_ExpDate_Month'] = $this->card->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT); - $inputs['Ecom_Payment_Card_ExpDate_Year'] = $this->card->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT); - $inputs['cv2'] = $this->card->getCvv(); - } - - return [ - 'gateway' => $this->get3DGatewayURL(), - 'inputs' => $inputs, - ]; + return $this->requestDataMapper->create3DFormData($this->account, $this->order, $this->type, $this->get3DGatewayURL(), $this->card); } /** @@ -326,29 +226,7 @@ public function getAccount() */ public function createRegularPaymentXML() { - $requestData = [ - 'Name' => $this->account->getUsername(), - 'Password' => $this->account->getPassword(), - 'ClientId' => $this->account->getClientId(), - 'Type' => $this->type, - 'IPAddress' => $this->order->ip, - 'Email' => $this->order->email, - 'OrderId' => $this->order->id, - 'UserId' => $this->order->user_id ?? null, - 'Total' => $this->order->amount, - 'Currency' => $this->order->currency, - 'Taksit' => $this->order->installment, - 'CardType' => $this->card->getType(), - 'Number' => $this->card->getNumber(), - 'Expires' => $this->card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), - 'Cvv2Val' => $this->card->getCvv(), - 'Mode' => 'P', //TODO what is this constant for? - 'GroupId' => '', - 'TransId' => '', - 'BillTo' => [ - 'Name' => $this->order->name ?: null, - ], - ]; + $requestData = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $this->order, $this->type, $this->card); return $this->createXML($requestData); } @@ -358,13 +236,7 @@ public function createRegularPaymentXML() */ public function createRegularPostXML() { - $requestData = [ - 'Name' => $this->account->getUsername(), - 'Password' => $this->account->getPassword(), - 'ClientId' => $this->account->getClientId(), - 'Type' => $this->types[self::TX_POST_PAY], - 'OrderId' => $this->order->id, - ]; + $requestData = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -374,46 +246,7 @@ public function createRegularPostXML() */ public function create3DPaymentXML($responseData) { - $requestData = [ - 'Name' => $this->account->getUsername(), - 'Password' => $this->account->getPassword(), - 'ClientId' => $this->account->getClientId(), - 'Type' => $this->type, - 'IPAddress' => $this->order->ip, - 'Email' => $this->order->email, - 'OrderId' => $this->order->id, - 'UserId' => $this->order->user_id ?? null, - 'Total' => $this->order->amount, - 'Currency' => $this->order->currency, - 'Taksit' => $this->order->installment, - 'Number' => $responseData['md'], - 'Expires' => '', - 'Cvv2Val' => '', - 'PayerTxnId' => $responseData['xid'], - 'PayerSecurityLevel' => $responseData['eci'], - 'PayerAuthenticationCode' => $responseData['cavv'], - 'CardholderPresentCode' => '13', - 'Mode' => 'P', - 'GroupId' => '', - 'TransId' => '', - ]; - - if ($this->order->name) { - $requestData['BillTo'] = [ - 'Name' => $this->order->name, - ]; - } - - if (isset($this->order->recurringFrequency)) { - $requestData['PbOrder'] = [ - 'OrderType' => 0, - // Periyodik İşlem Frekansı - 'OrderFrequencyInterval' => $this->order->recurringFrequency, - //D|M|Y - 'OrderFrequencyCycle' => $this->order->recurringFrequencyType, - 'TotalNumberPayments' => $this->order->recurringInstallmentCount, - ]; - } + $requestData = $this->requestDataMapper->create3DPaymentRequestData($this->account, $this->order, $this->type, $responseData); return $this->createXML($requestData); } @@ -423,15 +256,7 @@ public function create3DPaymentXML($responseData) */ public function createStatusXML() { - $requestData = [ - 'Name' => $this->account->getUsername(), - 'Password' => $this->account->getPassword(), - 'ClientId' => $this->account->getClientId(), - 'OrderId' => $this->order->id, - 'Extra' => [ - $this->types[self::TX_STATUS] => 'QUERY', - ], - ]; + $requestData = $this->requestDataMapper->createStatusRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -441,15 +266,7 @@ public function createStatusXML() */ public function createHistoryXML($customQueryData) { - $requestData = [ - 'Name' => $this->account->getUsername(), - 'Password' => $this->account->getPassword(), - 'ClientId' => $this->account->getClientId(), - 'OrderId' => $customQueryData['order_id'], - 'Extra' => [ - $this->types[self::TX_HISTORY] => 'QUERY', - ], - ]; + $requestData = $this->requestDataMapper->createHistoryRequestData($this->account, $this->order, $customQueryData); return $this->createXML($requestData); } @@ -459,13 +276,7 @@ public function createHistoryXML($customQueryData) */ public function createCancelXML() { - $requestData = [ - 'Name' => $this->account->getUsername(), - 'Password' => $this->account->getPassword(), - 'ClientId' => $this->account->getClientId(), - 'OrderId' => $this->order->id, - 'Type' => $this->types[self::TX_CANCEL], - ]; + $requestData = $this->requestDataMapper->createCancelRequestData($this->account, $this->order); return $this->createXML($requestData); } @@ -475,18 +286,7 @@ public function createCancelXML() */ public function createRefundXML() { - $requestData = [ - 'Name' => $this->account->getUsername(), - 'Password' => $this->account->getPassword(), - 'ClientId' => $this->account->getClientId(), - 'OrderId' => $this->order->id, - 'Currency' => $this->order->currency, - 'Type' => $this->types[self::TX_REFUND], - ]; - - if (isset($this->order->amount)) { - $requestData['Total'] = $this->order->amount; - } + $requestData = $this->requestDataMapper->createRefundRequestData($this->account, $this->order); return $this->createXML($requestData); } diff --git a/tests/DataMapper/EstPosRequestDataMapperTest.php b/tests/DataMapper/EstPosRequestDataMapperTest.php new file mode 100644 index 00000000..433231f8 --- /dev/null +++ b/tests/DataMapper/EstPosRequestDataMapperTest.php @@ -0,0 +1,594 @@ +config = require __DIR__.'/../../config/pos.php'; + + $this->threeDAccount = AccountFactory::createEstPosAccount( + 'akbank', + '700655000200', + 'ISBANKAPI', + 'ISBANK07', + AbstractGateway::MODEL_3D_SECURE, + 'TRPS0200', + EstPos::LANG_TR + ); + + $this->order = [ + 'id' => 'order222', + 'ip' => '127.0.0.1', + 'name' => 'siparis veren', + 'email' => 'test@test.com', + 'amount' => '100.25', + 'installment' => 0, + 'currency' => 'TRY', + 'success_url' => 'https://domain.com/success', + 'fail_url' => 'https://domain.com/fail_url', + 'lang' => 'tr', + 'rand' => microtime(), + ]; + + $this->pos = PosFactory::createPosGateway($this->threeDAccount); + $this->pos->setTestMode(true); + $this->requestDataMapper = new EstPosRequestDataMapper(); + $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet', AbstractCreditCard::CARD_TYPE_VISA); + } + + /** + * @return void + */ + public function testMapRecurringFrequency() + { + $this->assertEquals('M', $this->requestDataMapper->mapRecurringFrequency('MONTH')); + $this->assertEquals('M', $this->requestDataMapper->mapRecurringFrequency('M')); + } + + /** + * @return void + */ + public function testMapCurrency() + { + $this->assertEquals('949', $this->requestDataMapper->mapCurrency('TRY')); + $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); + } + + /** + * @return void + */ + public function testCreateNonSecurePostAuthPaymentRequestData() + { + $order = [ + 'id' => '2020110828BC', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_POST_PAY); + + $actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleNonSecurePaymentPostRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreateNonSecurePaymentRequestData() + { + $order = $this->order; + $pos = $this->pos; + $card = $this->card; + $pos->prepare($order, AbstractGateway::TX_PAY, $card); + + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $card); + + $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DHashFor3DSecure() + { + $this->order['rand'] = 'rand'; + $pos = $this->pos; + + $expected = 'mJReAoQNtx0G+nWUGA/BHLx/+BI='; + $pos->prepare($this->order, AbstractGateway::TX_PAY); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), 'Auth'); + $this->assertEquals($expected, $actual); + } + + /** + * @return void + */ + public function testCreate3DHashForNon3DSecure() + { + $this->order['rand'] = 'rand'; + + $account = AccountFactory::createEstPosAccount( + 'akbank', + 'XXXXXXX', + 'XXXXXXX', + 'XXXXXXX', + AbstractGateway::MODEL_3D_PAY, + 'VnM5WZ3sGrPusmWP' + ); + $pos = PosFactory::createPosGateway($account); + $expected = 'zW2HEQR/H0mpo1jrztIgmIPFFEU='; + $pos->prepare($this->order, AbstractGateway::TX_PAY); + $actual = $this->requestDataMapper->create3DHash($account, $pos->getOrder(), 'Auth'); + $this->assertEquals($expected, $actual); + } + + /** + * @return void + */ + public function testCreateCancelRequestData() + { + $order = [ + 'id' => '2020110828BC', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_CANCEL); + + $actual = $this->requestDataMapper->createCancelRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleCancelXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreateHistoryRequestData() + { + $order = [ + 'order_id' => '2020110828BC', + ]; + $pos = $this->pos; + + $actual = $this->requestDataMapper->createHistoryRequestData($pos->getAccount(), (object) [], $order); + + $expectedData = $this->getSampleHistoryRequestData($pos->getAccount(), $order); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DPaymentRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'email' => 'samp@iexample.com', + 'name' => 'john doe', + 'user_id' => '1535', + 'ip' => '192.168.1.0', + 'amount' => 100.01, + 'installment' => '0', + 'currency' => 'TRY', + 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', + 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', + ]; + $responseData = [ + 'md' => '1', + 'xid' => '100000005xid', + 'eci' => '100000005eci', + 'cavv' => 'cavv', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_PAY); + + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $responseData); + + $expectedData = $this->getSample3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), $responseData); + $this->assertEquals($expectedData, $actual); + } + + /** + * @return void + */ + public function testCreate3DPaymentRequestDataRecurringOrder() + { + $order = [ + 'id' => '2020110828BC', + 'email' => 'samp@iexample.com', + 'name' => 'john doe', + 'user_id' => '1535', + 'ip' => '192.168.1.0', + 'amount' => 100.01, + 'installment' => '0', + 'currency' => 'TRY', + 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', + 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', + 'recurringFrequency' => 3, + 'recurringFrequencyType' => 'MONTH', + 'recurringInstallmentCount' => 4, + ]; + + $responseData = [ + 'md' => '1', + 'xid' => '100000005xid', + 'eci' => '100000005eci', + 'cavv' => 'cavv', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_PAY); + + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $responseData); + + $expectedData = $this->getSample3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), $responseData); + $this->assertEquals($expectedData, $actual); + } + + + /** + * @return void + */ + public function testGet3DFormData() + { + $account = $this->threeDAccount; + $this->pos->prepare($this->order, AbstractGateway::TX_PAY); + $txType = 'Auth'; + $hash = $this->requestDataMapper->create3DHash($account, $this->pos->getOrder(), $txType); + $card = $this->card; + $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test']; + + $inputs = [ + 'clientid' => $account->getClientId(), + 'storetype' => $account->getModel(), + 'hash' => $hash, + 'firmaadi' => $this->order['name'], + 'Email' => $this->order['email'], + 'amount' => $this->order['amount'], + 'oid' => $this->order['id'], + 'okUrl' => $this->order['success_url'], + 'failUrl' => $this->order['fail_url'], + 'rnd' => $this->order['rand'], + 'lang' => 'tr', + 'currency' => 949, + ]; + $form = [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + //test without card + $this->assertEquals($form, $this->requestDataMapper->create3DFormData( + $this->pos->getAccount(), + $this->pos->getOrder(), + 'Auth', + $gatewayURL + )); + + //test with card + if ($card) { + $form['inputs']['cardType'] = '1'; + $form['inputs']['pan'] = $card->getNumber(); + $form['inputs']['Ecom_Payment_Card_ExpDate_Month'] = '01'; + $form['inputs']['Ecom_Payment_Card_ExpDate_Year'] = '22'; + $form['inputs']['cv2'] = $card->getCvv(); + } + + $this->assertEquals($form, $this->requestDataMapper->create3DFormData( + $this->pos->getAccount(), + $this->pos->getOrder(), + 'Auth', + $gatewayURL, + $card + )); + } + + /** + * todo + * @return void + */ + public function testGet3DHostFormData() + { + $account = AccountFactory::createEstPosAccount( + 'akbank', + 'XXXXXXX', + 'XXXXXXX', + 'XXXXXXX', + AbstractGateway::MODEL_3D_HOST, + 'VnM5WZ3sGrPusmWP', + EstPos::LANG_TR + ); + + /** @var EstPos $pos */ + $pos = PosFactory::createPosGateway($account); + $pos->setTestMode(true); + $pos->prepare($this->order, AbstractGateway::TX_PAY); + $order = $pos->getOrder(); + $hash = $this->requestDataMapper->create3DHash($account, $order, 'Auth'); + $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway_3d_host']['test']; + $inputs = [ + 'clientid' => $account->getClientId(), + 'storetype' => $account->getModel(), + 'hash' => $hash, + 'firmaadi' => $this->order['name'], + 'Email' => $this->order['email'], + 'amount' => $this->order['amount'], + 'oid' => $this->order['id'], + 'okUrl' => $this->order['success_url'], + 'failUrl' => $this->order['fail_url'], + 'rnd' => $this->order['rand'], + 'lang' => 'tr', + 'currency' => '949', + 'islemtipi' => 'Auth', + 'taksit' => $this->order['installment'], + ]; + $form = [ + 'gateway' => $gatewayURL, + 'inputs' => $inputs, + ]; + + $this->assertEquals($form, $this->requestDataMapper->create3DFormData( + $pos->getAccount(), + $pos->getOrder(), + 'Auth', + $gatewayURL + )); + } + + /** + * @return void + */ + public function testCreateStatusRequestData() + { + $order = [ + 'id' => '2020110828BC', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_STATUS); + + $actualData = $this->requestDataMapper->createStatusRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleStatusRequestData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actualData); + } + + /** + * todo + * @return void + */ + public function testCreateRefundRequestData() + { + $order = [ + 'id' => '2020110828BC', + 'amount' => 50, + 'currency' => 'TRY', + ]; + + $pos = $this->pos; + $pos->prepare($order, AbstractGateway::TX_REFUND); + + $actual = $this->requestDataMapper->createRefundRequestData($pos->getAccount(), $pos->getOrder()); + + $expectedData = $this->getSampleRefundXMLData($pos->getAccount(), $pos->getOrder()); + $this->assertEquals($expectedData, $actual); + } + + /** + * @param AbstractPosAccount $account + * @param $order + * @param array $responseData + * + * @return array + */ + private function getSample3DPaymentRequestData(AbstractPosAccount $account, $order, array $responseData): array + { + $requestData = [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'Type' => 'Auth', + 'IPAddress' => $order->ip, + 'Email' => $order->email, + 'OrderId' => $order->id, + 'UserId' => isset($order->user_id) ? $order->user_id : null, + 'Total' => 100.01, + 'Currency' => '949', + 'Taksit' => '0', + 'Number' => $responseData['md'], + 'Expires' => '', + 'Cvv2Val' => '', + 'PayerTxnId' => $responseData['xid'], + 'PayerSecurityLevel' => $responseData['eci'], + 'PayerAuthenticationCode' => $responseData['cavv'], + 'CardholderPresentCode' => '13', + 'Mode' => 'P', + 'GroupId' => '', + 'TransId' => '', + ]; + if (isset($order->name)) { + $requestData['BillTo'] = [ + 'Name' => $order->name, + ]; + } + + if (isset($order->recurringFrequency)) { + $requestData['PbOrder'] = [ + 'OrderType' => 0, + 'OrderFrequencyInterval' => $order->recurringFrequency, + 'OrderFrequencyCycle' => 'M', + 'TotalNumberPayments' => $order->recurringInstallmentCount, + ]; + } + + return $requestData; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleCancelXMLData(AbstractPosAccount $account, $order): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $order->id, + 'Type' => 'Void', + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * @param AbstractCreditCard $card + * + * @return array + */ + private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $account, $order, AbstractCreditCard $card): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'Type' => 'Auth', + 'IPAddress' => $order->ip, + 'Email' => $order->email, + 'OrderId' => $order->id, + 'UserId' => $order->user_id ?? null, + 'Total' => '100.25', + 'Currency' => '949', + 'Taksit' => '0', + 'CardType' => 'visa', + 'Number' => $card->getNumber(), + 'Expires' => '01/22', + 'Cvv2Val' => $card->getCvv(), + 'Mode' => 'P', + 'GroupId' => '', + 'TransId' => '', + 'BillTo' => [ + 'Name' => $order->name ?: null, + ], + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'Type' => 'PostAuth', + 'OrderId' => $order->id, + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleStatusRequestData(AbstractPosAccount $account, $order): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $order->id, + 'Extra' => [ + 'ORDERSTATUS' => 'QUERY', + ], + ]; + } + + /** + * @param AbstractPosAccount $account + * @param $order + * + * @return array + */ + private function getSampleRefundXMLData(AbstractPosAccount $account, $order): array + { + $data = [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $order->id, + 'Currency' => 949, + 'Type' => 'Credit', + ]; + + if ($order->amount) { + $data['Total'] = $order->amount; + } + + return $data; + } + + /** + * @param AbstractPosAccount $account + * @param $customQueryData + * + * @return array + */ + private function getSampleHistoryRequestData(AbstractPosAccount $account, $customQueryData): array + { + $requestData = [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + 'OrderId' => $customQueryData['order_id'], + 'Extra' => [ + 'ORDERHISTORY' => 'QUERY', + ], + ]; + + return $requestData; + } +} diff --git a/tests/Factory/CreditCardFactoryTest.php b/tests/Factory/CreditCardFactoryTest.php index 0294753f..9ed7b2d5 100644 --- a/tests/Factory/CreditCardFactoryTest.php +++ b/tests/Factory/CreditCardFactoryTest.php @@ -67,11 +67,13 @@ public function testCreateWithEmptyTypeMapping() } /** + * todo * @return void */ public function testCreateUnSupportedCardTypeException() { - $this->expectException(CardTypeNotSupportedException::class); + $this->markTestSkipped('pos factory guncellendikten sonra tekrar calistirilacak bu test'); + //$this->expectException(CardTypeNotSupportedException::class); $pos = $this->getMockBuilder(EstPos::class)->disableOriginalConstructor() //just any method ->onlyMethods(['send']) @@ -89,11 +91,13 @@ public function testCreateUnSupportedCardTypeException() } /** + * todo * @return void */ public function testCreateCardTypeRequiredException() { - $this->expectException(CardTypeRequiredException::class); + $this->markTestSkipped('pos factory guncellendikten sonra tekrar calistirilacak bu test'); + //$this->expectException(CardTypeRequiredException::class); $pos = $this->getMockBuilder(EstPos::class)->disableOriginalConstructor() //just any method ->onlyMethods(['send']) diff --git a/tests/Gateways/EstPostTest.php b/tests/Gateways/EstPostTest.php index 68484642..3fc7b215 100644 --- a/tests/Gateways/EstPostTest.php +++ b/tests/Gateways/EstPostTest.php @@ -1,5 +1,7 @@ pos->setTestMode(true); $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '21', '12', '122', 'ahmet', AbstractCreditCard::CARD_TYPE_VISA); - - $this->xmlDecoder = new XmlEncoder(); } /** @@ -95,106 +84,6 @@ public function testPrepare() $this->assertEquals($this->card, $this->pos->getCard()); } - /** - * @return void - */ - public function testMapRecurringFrequency() - { - $this->assertEquals('M', $this->pos->mapRecurringFrequency('MONTH')); - $this->assertEquals('M', $this->pos->mapRecurringFrequency('M')); - } - - public function testGet3DFormWithCardData() - { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - - $form = [ - 'gateway' => $this->config['banks'][$this->account->getBank()]['urls']['gateway']['test'], - 'inputs' => [ - 'clientid' => $this->account->getClientId(), - 'storetype' => $this->account->getModel(), - 'hash' => $this->pos->create3DHash($this->pos->getAccount(), $this->pos->getOrder(), 'Auth'), - 'cardType' => '1', - 'pan' => $this->card->getNumber(), - 'Ecom_Payment_Card_ExpDate_Month' => '12', - 'Ecom_Payment_Card_ExpDate_Year' => '21', - 'cv2' => $this->card->getCvv(), - 'firmaadi' => $this->order['name'], - 'Email' => $this->order['email'], - 'amount' => $this->order['amount'], - 'oid' => $this->order['id'], - 'okUrl' => $this->order['success_url'], - 'failUrl' => $this->order['fail_url'], - 'rnd' => $this->order['rand'], - 'lang' => $this->order['lang'], - 'currency' => 949, - ], - ]; - $this->assertEquals($form, $this->pos->get3DFormData()); - } - - public function testGet3DFormWithoutCardData() - { - $this->pos->prepare($this->order, AbstractGateway::TX_PAY); - - $form = [ - 'gateway' => $this->config['banks'][$this->account->getBank()]['urls']['gateway']['test'], - 'inputs' => [ - 'clientid' => $this->account->getClientId(), - 'storetype' => $this->account->getModel(), - 'hash' => $this->pos->create3DHash($this->pos->getAccount(), $this->pos->getOrder(), 'Auth'), - 'firmaadi' => $this->order['name'], - 'Email' => $this->order['email'], - 'amount' => $this->order['amount'], - 'oid' => $this->order['id'], - 'okUrl' => $this->order['success_url'], - 'failUrl' => $this->order['fail_url'], - 'rnd' => $this->order['rand'], - 'lang' => $this->order['lang'], - 'currency' => 949, - ], - ]; - $this->assertEquals($form, $this->pos->get3DFormData()); - } - - public function testGet3DHostFormData() - { - $account = AccountFactory::createEstPosAccount( - 'akbank', - 'XXXXXXX', - 'XXXXXXX', - 'XXXXXXX', - AbstractGateway::MODEL_3D_HOST, - 'VnM5WZ3sGrPusmWP', - EstPos::LANG_TR - ); - $pos = PosFactory::createPosGateway($account); - $pos->setTestMode(true); - - $pos->prepare($this->order, AbstractGateway::TX_PAY); - - $form = [ - 'gateway' => $this->config['banks'][$account->getBank()]['urls']['gateway']['test'], - 'inputs' => [ - 'clientid' => $account->getClientId(), - 'storetype' => $account->getModel(), - 'hash' => $pos->create3DHash($pos->getAccount(), $pos->getOrder(), 'Auth'), - 'firmaadi' => $this->order['name'], - 'Email' => $this->order['email'], - 'amount' => $this->order['amount'], - 'oid' => $this->order['id'], - 'okUrl' => $this->order['success_url'], - 'failUrl' => $this->order['fail_url'], - 'rnd' => $this->order['rand'], - 'lang' => $this->order['lang'], - 'currency' => 949, - 'islemtipi' => 'Auth', - 'taksit' => $this->order['installment'], - ], - ]; - $this->assertEquals($form, $pos->get3DFormData()); - } - /** * @return void */ @@ -207,233 +96,6 @@ public function testCheck3DHash() $this->assertFalse($this->pos->check3DHash($data)); } - public function testCreateRegularPaymentXML() - { - $order = [ - 'id' => '2020110828BC', - 'email' => 'samp@iexample.com', - 'name' => 'john doe', - 'user_id' => '1535', - 'ip' => '192.168.1.0', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - ]; - - /** - * @var EstPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet', AbstractCreditCard::CARD_TYPE_VISA); - - $pos->prepare($order, AbstractGateway::TX_PAY, $card); - - $actualXML = $pos->createRegularPaymentXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPaymentXMLData($pos->getOrder(), $pos->getCard(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateRegularPostXML() - { - $order = [ - 'id' => '2020110828BC', - ]; - - /** - * @var EstPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_POST_PAY); - - $actualXML = $pos->createRegularPostXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRegularPostXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreate3DPaymentXML() - { - - $order = [ - 'id' => '2020110828BC', - 'email' => 'samp@iexample.com', - 'name' => 'john doe', - 'user_id' => '1535', - 'ip' => '192.168.1.0', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', - ]; - $responseData = [ - 'md' => '1', - 'xid' => '100000005xid', - 'eci' => '100000005eci', - 'cavv' => 'cavv', - ]; - - /** - * @var EstPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_PAY); - - $actualXML = $pos->create3DPaymentXML($responseData); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSample3DPaymentXMLData($pos->getOrder(), $pos->getAccount(), $responseData); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreate3DPaymentXMLForRecurringOrder() - { - - $order = [ - 'id' => '2020110828BC', - 'email' => 'samp@iexample.com', - 'name' => 'john doe', - 'user_id' => '1535', - 'ip' => '192.168.1.0', - 'amount' => 100.01, - 'installment' => '0', - 'currency' => 'TRY', - 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'recurringFrequency' => 3, - 'recurringFrequencyType' => 'MONTH', - 'recurringInstallmentCount' => 4, - ]; - - $responseData = [ - 'md' => '1', - 'xid' => '100000005xid', - 'eci' => '100000005eci', - 'cavv' => 'cavv', - ]; - - /** - * @var EstPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_PAY); - - $actualXML = $pos->create3DPaymentXML($responseData); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSample3DPaymentXMLData($pos->getOrder(), $pos->getAccount(), $responseData); - $this->assertEquals($expectedData, $actualData); - $this->assertEquals($expectedData['PbOrder'], $actualData['PbOrder']); - } - - public function testCreateStatusXML() - { - $order = [ - 'id' => '2020110828BC', - ]; - - /** - * @var EstPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_STATUS); - - $actualXML = $pos->createStatusXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleStatusXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - - public function testCreateCancelXML() - { - $order = [ - 'id' => '2020110828BC', - ]; - - /** - * @var EstPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_CANCEL); - - $actualXML = $pos->createCancelXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleCancelXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - public function testCreateRefundXML() - { - $order = [ - 'id' => '2020110828BC', - 'amount' => 50, - 'currency' => 'TRY', - ]; - - /** - * @var EstPos $pos - */ - $pos = PosFactory::createPosGateway($this->account); - $pos->prepare($order, AbstractGateway::TX_REFUND); - - $actualXML = $pos->createRefundXML(); - $actualData = $this->xmlDecoder->decode($actualXML, 'xml'); - - $expectedData = $this->getSampleRefundXMLData($pos->getOrder(), $pos->getAccount()); - $this->assertEquals($expectedData, $actualData); - } - - /** - * @return void - */ - public function testCreate3DHashFor3DSecure() - { - $this->order['rand'] = 'rand'; - - $account = AccountFactory::createEstPosAccount( - 'akbank', - 'XXXXXXX', - 'XXXXXXX', - 'XXXXXXX', - AbstractGateway::MODEL_3D_SECURE, - 'VnM5WZ3sGrPusmWP' - ); - $pos = PosFactory::createPosGateway($account); - - $expected = '3Wb9YCz1uz3OCFHEI0u2Djga294='; - $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $pos->create3DHash($account, $pos->getOrder(), 'Auth'); - $this->assertEquals($expected, $actual); - } - - /** - * @return void - */ - public function testCreate3DHashForNon3DSecure() - { - $this->order['rand'] = 'rand'; - - $account = AccountFactory::createEstPosAccount( - 'akbank', - 'XXXXXXX', - 'XXXXXXX', - 'XXXXXXX', - AbstractGateway::MODEL_3D_PAY, - 'VnM5WZ3sGrPusmWP' - ); - $pos = PosFactory::createPosGateway($account); - $expected = 'zW2HEQR/H0mpo1jrztIgmIPFFEU='; - $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $pos->create3DHash($account, $pos->getOrder(), 'Auth'); - $this->assertEquals($expected, $actual); - } - /** * @return void */ @@ -1308,166 +970,4 @@ private function get3DHostPaymentFailResponseData(): array 'HASHPARAMSVAL' => '700655000200202204175A830435508:524D8E0D689F6F5E1DD0C737ED160B6073038B4FBBC73E6D7C69341793A2DC0E:3379:##700655000200g+XYZKbjrxFj5EgZNZFj', ]; } - - - /** - * @param $order - * @param AbstractCreditCard $card - * @param EstPosAccount $account - * - * @return array - */ - private function getSampleRegularPaymentXMLData($order, AbstractCreditCard $card, EstPosAccount $account) - { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), - 'Type' => 'Auth', - 'IPAddress' => $order->ip, - 'Email' => $order->email, - 'OrderId' => $order->id, - 'UserId' => isset($order->user_id) ? $order->user_id : null, - 'Total' => $order->amount, - 'Currency' => $order->currency, - 'Taksit' => $order->installment, - 'CardType' => AbstractCreditCard::CARD_TYPE_VISA, - 'Number' => $card->getNumber(), - 'Expires' => '01/22', - 'Cvv2Val' => $card->getCvv(), - 'Mode' => 'P', - 'GroupId' => '', - 'TransId' => '', - 'BillTo' => [ - 'Name' => $order->name ?: null, - ], - ]; - } - - /** - * @param $order - * @param EstPosAccount $account - * - * @return array - */ - private function getSampleRegularPostXMLData($order, EstPosAccount $account) - { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), - 'Type' => 'PostAuth', - 'OrderId' => $order->id, - ]; - } - - /** - * @param $order - * @param EstPosAccount $account - * @param array $responseData - * - * @return array - */ - private function getSample3DPaymentXMLData($order, EstPosAccount $account, array $responseData) - { - $requestData = [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), - 'Type' => 'Auth', - 'IPAddress' => $order->ip, - 'Email' => $order->email, - 'OrderId' => $order->id, - 'UserId' => isset($order->user_id) ? $order->user_id : null, - 'Total' => $order->amount, - 'Currency' => $order->currency, - 'Taksit' => $order->installment, - 'Number' => $responseData['md'], - 'Expires' => '', - 'Cvv2Val' => '', - 'PayerTxnId' => $responseData['xid'], - 'PayerSecurityLevel' => $responseData['eci'], - 'PayerAuthenticationCode' => $responseData['cavv'], - 'CardholderPresentCode' => '13', - 'Mode' => 'P', - 'GroupId' => '', - 'TransId' => '', - ]; - if (isset($order->name)) { - $requestData['BillTo'] = [ - 'Name' => $order->name, - ]; - } - - if (isset($order->recurringFrequency)) { - $requestData['PbOrder'] = [ - 'OrderType' => 0, - 'OrderFrequencyInterval' => $order->recurringFrequency, - 'OrderFrequencyCycle' => $order->recurringFrequencyType, - 'TotalNumberPayments' => $order->recurringInstallmentCount, - ]; - } - - return $requestData; - } - - /** - * @param $order - * @param EstPosAccount $account - * - * @return array - */ - private function getSampleStatusXMLData($order, EstPosAccount $account) - { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), - 'OrderId' => $order->id, - 'Extra' => [ - 'ORDERSTATUS' => 'QUERY', - ], - ]; - } - - /** - * @param $order - * @param EstPosAccount $account - * - * @return array - */ - private function getSampleCancelXMLData($order, EstPosAccount $account) - { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), - 'OrderId' => $order->id, - 'Type' => 'Void', - ]; - } - - /** - * @param $order - * @param EstPosAccount $account - * - * @return array - */ - private function getSampleRefundXMLData($order, EstPosAccount $account) - { - $data = [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), - 'OrderId' => $order->id, - 'Currency' => 949, - 'Type' => 'Credit', - ]; - - if ($order->amount) { - $data['Total'] = $order->amount; - } - - return $data; - } } From ef8efee94f252cea3c3a4c28c750eb09985a5e27 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 19:15:31 +0200 Subject: [PATCH 14/40] EstPosRequestDataMapper - make IP address optional --- src/DataMapper/EstPosRequestDataMapper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index 0d42cdfd..e65b5f0c 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -72,7 +72,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'Password' => $account->getPassword(), 'ClientId' => $account->getClientId(), 'Type' => $txType, - 'IPAddress' => $order->ip, + 'IPAddress' => $order->ip ?? null, 'Email' => $order->email, 'OrderId' => $order->id, 'UserId' => $order->user_id ?? null, @@ -121,7 +121,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'Password' => $account->getPassword(), 'ClientId' => $account->getClientId(), 'Type' => $txType, - 'IPAddress' => $order->ip, + 'IPAddress' => $order->ip ?? null, 'Email' => $order->email, 'OrderId' => $order->id, 'UserId' => $order->user_id ?? null, From 5d2c23d797afeecc98ba6e9032ff368913314ad4 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 19:21:19 +0200 Subject: [PATCH 15/40] EstPosRequestDataMapper - remove unnecessary request data --- src/DataMapper/EstPosRequestDataMapper.php | 22 ++++--------------- .../EstPosRequestDataMapperTest.php | 8 ------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index e65b5f0c..0d14abf4 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -41,7 +41,6 @@ class EstPosRequestDataMapper extends AbstractRequestDataMapper 'MONTH' => 'M', 'YEAR' => 'Y', ]; - //todo store type degerleri ekle protected $secureTypeMappings = [ AbstractGateway::MODEL_3D_SECURE => '3d', @@ -80,15 +79,10 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'Currency' => $order->currency, 'Taksit' => $order->installment, 'Number' => $responseData['md'], - 'Expires' => '', //todo - 'Cvv2Val' => '', //todo 'PayerTxnId' => $responseData['xid'], 'PayerSecurityLevel' => $responseData['eci'], 'PayerAuthenticationCode' => $responseData['cavv'], - 'CardholderPresentCode' => '13', 'Mode' => 'P', - 'GroupId' => '', - 'TransId' => '', ]; if ($order->name) { @@ -128,13 +122,10 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'Total' => $order->amount, 'Currency' => $order->currency, 'Taksit' => $order->installment, - 'CardType' => $card->getType(), //todo remove 'Number' => $card->getNumber(), 'Expires' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), 'Cvv2Val' => $card->getCvv(), - 'Mode' => 'P', //TODO what is this constant for? - 'GroupId' => '', - 'TransId' => '', + 'Mode' => 'P', 'BillTo' => [ 'Name' => $order->name ?: null, ], @@ -233,16 +224,12 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar */ public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null): array { - if (!$order) { - return []; - } - - $order->hash = $this->create3DHash($account, $order, $txType); + $hash = $this->create3DHash($account, $order, $txType); $inputs = [ 'clientid' => $account->getClientId(), - 'storetype' => $account->getModel(), - 'hash' => $order->hash, + 'storetype' => $this->secureTypeMappings[$account->getModel()], + 'hash' => $hash, 'firmaadi' => $order->name, 'Email' => $order->email, 'amount' => $order->amount, @@ -262,7 +249,6 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx } if ($card) { - //todo check card type $inputs['cardType'] = $this->cardTypeMapping[$card->getType()]; $inputs['pan'] = $card->getNumber(); $inputs['Ecom_Payment_Card_ExpDate_Month'] = $card->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT); diff --git a/tests/DataMapper/EstPosRequestDataMapperTest.php b/tests/DataMapper/EstPosRequestDataMapperTest.php index 433231f8..345d6ae1 100644 --- a/tests/DataMapper/EstPosRequestDataMapperTest.php +++ b/tests/DataMapper/EstPosRequestDataMapperTest.php @@ -432,15 +432,10 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord 'Currency' => '949', 'Taksit' => '0', 'Number' => $responseData['md'], - 'Expires' => '', - 'Cvv2Val' => '', 'PayerTxnId' => $responseData['xid'], 'PayerSecurityLevel' => $responseData['eci'], 'PayerAuthenticationCode' => $responseData['cavv'], - 'CardholderPresentCode' => '13', 'Mode' => 'P', - 'GroupId' => '', - 'TransId' => '', ]; if (isset($order->name)) { $requestData['BillTo'] = [ @@ -498,13 +493,10 @@ private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $accoun 'Total' => '100.25', 'Currency' => '949', 'Taksit' => '0', - 'CardType' => 'visa', 'Number' => $card->getNumber(), 'Expires' => '01/22', 'Cvv2Val' => $card->getCvv(), 'Mode' => 'P', - 'GroupId' => '', - 'TransId' => '', 'BillTo' => [ 'Name' => $order->name ?: null, ], From 6c6684c5b05fc0668f1903c0176b02c7327eaf5d Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 19:26:00 +0200 Subject: [PATCH 16/40] EstPosRequestDataMapper - refactoring --- src/DataMapper/EstPosRequestDataMapper.php | 46 ++++++++++------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index 0d14abf4..f9b30b13 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -110,10 +110,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, */ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), + return $this->getRequestAccountData($account) + [ 'Type' => $txType, 'IPAddress' => $order->ip ?? null, 'Email' => $order->email, @@ -137,10 +134,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), + return $this->getRequestAccountData($account) + [ 'Type' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], 'OrderId' => $order->id, ]; @@ -151,10 +145,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac */ public function createStatusRequestData(AbstractPosAccount $account, $order): array { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), + return $this->getRequestAccountData($account) + [ 'OrderId' => $order->id, 'Extra' => [ $this->txTypeMappings[AbstractGateway::TX_STATUS] => 'QUERY', @@ -168,12 +159,9 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar */ public function createCancelRequestData(AbstractPosAccount $account, $order): array { - return [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), + return $this->getRequestAccountData($account) + [ 'OrderId' => $order->id, - 'Type' => 'Void', + 'Type' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], ]; } @@ -183,9 +171,6 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar public function createRefundRequestData(AbstractPosAccount $account, $order): array { $requestData = [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), 'OrderId' => $order->id, 'Currency' => $order->currency, 'Type' => $this->txTypeMappings[AbstractGateway::TX_REFUND], @@ -195,7 +180,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar $requestData['Total'] = $order->amount; } - return $requestData; + return $this->getRequestAccountData($account) + $requestData; } /** @@ -205,16 +190,13 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array { $requestData = [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), 'OrderId' => $extraData['order_id'], //todo orderId ya da id olarak degistirilecek, Payfor'da orderId, Garanti'de id 'Extra' => [ $this->txTypeMappings[AbstractGateway::TX_HISTORY] => 'QUERY', ], ]; - return $requestData; + return $this->getRequestAccountData($account) + $requestData; } @@ -295,4 +277,18 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType return $this->hashString($hashStr); } + + /** + * @param AbstractPosAccount $account + * + * @return array + */ + private function getRequestAccountData(AbstractPosAccount $account): array + { + return [ + 'Name' => $account->getUsername(), + 'Password' => $account->getPassword(), + 'ClientId' => $account->getClientId(), + ]; + } } From d7530918a62c34b64088d8bce931875e26dd9c25 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 19:35:42 +0200 Subject: [PATCH 17/40] RequestDataMappers - remove duplicate currency code definitions --- src/DataMapper/AbstractRequestDataMapper.php | 11 ++++++++++- src/DataMapper/EstPosRequestDataMapper.php | 15 --------------- src/DataMapper/GarantiPosRequestDataMapper.php | 12 ------------ src/DataMapper/InterPosRequestDataMapper.php | 14 -------------- src/DataMapper/PayForPosRequestDataMapper.php | 12 ------------ src/DataMapper/VakifBankPosRequestDataMapper.php | 14 -------------- .../DataMapper/InterPosRequestDataMapperTest.php | 13 ++++++++++++- .../DataMapper/KuveytPosRequestDataMapperTest.php | 13 ++++++++++++- .../DataMapper/PayForPosRequestDataMapperTest.php | 9 +++++++++ tests/DataMapper/PosNetRequestDataMapperTest.php | 9 +++++++++ .../VakifBankPosRequestDataMapperTest.php | 9 +++++++++ 11 files changed, 61 insertions(+), 70 deletions(-) diff --git a/src/DataMapper/AbstractRequestDataMapper.php b/src/DataMapper/AbstractRequestDataMapper.php index 91f1f6e1..79fda2c8 100644 --- a/src/DataMapper/AbstractRequestDataMapper.php +++ b/src/DataMapper/AbstractRequestDataMapper.php @@ -28,11 +28,20 @@ abstract class AbstractRequestDataMapper protected $cardTypeMapping = []; /** + * default olarak ISO 4217 kodlar tanimliyoruz. + * fakat bazi banklar ISO standarti kullanmiyorlar. * Currency mapping * * @var array */ - protected $currencyMappings = []; + protected $currencyMappings = [ + 'TRY' => 949, + 'USD' => 840, + 'EUR' => 978, + 'GBP' => 826, + 'JPY' => 392, + 'RUB' => 643, + ]; /** * period mapping for recurring orders diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index f9b30b13..594912d8 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -49,18 +49,6 @@ class EstPosRequestDataMapper extends AbstractRequestDataMapper AbstractGateway::MODEL_NON_SECURE => 'regular', ]; - /** - * @inheritdoc - */ - protected $currencyMappings = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 643, - ]; - /** * @inheritDoc */ @@ -154,7 +142,6 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar } /** - * todo * @inheritDoc */ public function createCancelRequestData(AbstractPosAccount $account, $order): array @@ -184,7 +171,6 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar } /** - * todo * @inheritDoc */ public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array @@ -201,7 +187,6 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar /** - * todo * @inheritDoc */ public function create3DFormData(AbstractPosAccount $account, $order, string $txType, string $gatewayURL, ?AbstractCreditCard $card = null): array diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index 17660863..29c42e86 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -41,18 +41,6 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper AbstractGateway::TX_STATUS => 'orderinq', ]; - /** - * @inheritdoc - */ - protected $currencyMappings = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 643, - ]; - private const MOTO = 'N'; protected $recurringOrderFrequencyMapping = [ diff --git a/src/DataMapper/InterPosRequestDataMapper.php b/src/DataMapper/InterPosRequestDataMapper.php index 6fb3a4de..1e1ba0fd 100644 --- a/src/DataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/InterPosRequestDataMapper.php @@ -48,20 +48,6 @@ class InterPosRequestDataMapper extends AbstractRequestDataMapper AbstractCreditCard::CARD_TYPE_AMEX => '3', ]; - /** - * Currency mapping - * - * @var array - */ - protected $currencyMappings = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 810, - ]; - /** * @inheritDoc */ diff --git a/src/DataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/PayForPosRequestDataMapper.php index 6b636c46..a612e664 100644 --- a/src/DataMapper/PayForPosRequestDataMapper.php +++ b/src/DataMapper/PayForPosRequestDataMapper.php @@ -45,18 +45,6 @@ class PayForPosRequestDataMapper extends AbstractRequestDataMapper AbstractGateway::TX_STATUS => 'OrderInquiry', ]; - /** - * @inheritdoc - */ - protected $currencyMappings = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 643, - ]; - /** * @inheritDoc */ diff --git a/src/DataMapper/VakifBankPosRequestDataMapper.php b/src/DataMapper/VakifBankPosRequestDataMapper.php index a1e2c856..b15c407a 100644 --- a/src/DataMapper/VakifBankPosRequestDataMapper.php +++ b/src/DataMapper/VakifBankPosRequestDataMapper.php @@ -39,20 +39,6 @@ class VakifBankPosRequestDataMapper extends AbstractRequestDataMapper AbstractCreditCard::CARD_TYPE_AMEX => '400', ]; - /** - * Currency mapping - * - * @var array - */ - protected $currencyMappings = [ - 'TRY' => 949, - 'USD' => 840, - 'EUR' => 978, - 'GBP' => 826, - 'JPY' => 392, - 'RUB' => 643, - ]; - protected $recurringOrderFrequencyMapping = [ 'DAY' => 'Day', 'MONTH' => 'Month', diff --git a/tests/DataMapper/InterPosRequestDataMapperTest.php b/tests/DataMapper/InterPosRequestDataMapperTest.php index 5fa67396..61921b10 100644 --- a/tests/DataMapper/InterPosRequestDataMapperTest.php +++ b/tests/DataMapper/InterPosRequestDataMapperTest.php @@ -1,5 +1,7 @@ card = CreditCardFactory::create($this->pos, '5555444433332222', '21', '12', '122', 'ahmet', AbstractCreditCard::CARD_TYPE_VISA); } + /** + * @return void + */ + public function testMapCurrency() + { + $this->assertEquals('949', $this->requestDataMapper->mapCurrency('TRY')); + $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); + } + /** * @return void */ diff --git a/tests/DataMapper/KuveytPosRequestDataMapperTest.php b/tests/DataMapper/KuveytPosRequestDataMapperTest.php index 549471e4..e2cf8cde 100644 --- a/tests/DataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/DataMapper/KuveytPosRequestDataMapperTest.php @@ -1,5 +1,7 @@ requestDataMapper = new KuveytPosRequestDataMapper(); } + /** + * @return void + */ + public function testMapCurrency() + { + $this->assertEquals('0949', $this->requestDataMapper->mapCurrency('TRY')); + $this->assertEquals('0978', $this->requestDataMapper->mapCurrency('EUR')); + } + /** * @return void */ diff --git a/tests/DataMapper/PayForPosRequestDataMapperTest.php b/tests/DataMapper/PayForPosRequestDataMapperTest.php index 5df8aee7..32132541 100644 --- a/tests/DataMapper/PayForPosRequestDataMapperTest.php +++ b/tests/DataMapper/PayForPosRequestDataMapperTest.php @@ -68,6 +68,15 @@ protected function setUp(): void $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet'); } + /** + * @return void + */ + public function testMapCurrency() + { + $this->assertEquals('949', $this->requestDataMapper->mapCurrency('TRY')); + $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); + } + /** * @return void */ diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php index 3c2d6de3..9132ef79 100644 --- a/tests/DataMapper/PosNetRequestDataMapperTest.php +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -71,6 +71,15 @@ protected function setUp(): void $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet'); } + /** + * @return void + */ + public function testMapCurrency() + { + $this->assertEquals('TL', $this->requestDataMapper->mapCurrency('TRY')); + $this->assertEquals('EU', $this->requestDataMapper->mapCurrency('EUR')); + } + /** * @return void */ diff --git a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php index 1f420998..06abf4cc 100644 --- a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php +++ b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php @@ -82,6 +82,15 @@ public function testMapRecurringFrequency() $this->assertEquals('Month', $this->requestDataMapper->mapRecurringFrequency('Month')); } + /** + * @return void + */ + public function testMapCurrency() + { + $this->assertEquals('949', $this->requestDataMapper->mapCurrency('TRY')); + $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); + } + /** * @return void */ From 126dd58326eba46d0f1ed416b514750ac5a87718 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 20:41:48 +0200 Subject: [PATCH 18/40] PosFactory inject RequestDataMappers into gateway constructors --- src/Factory/PosFactory.php | 62 +++++++++++++++++++++---- src/Gateways/AbstractGateway.php | 19 ++++---- src/Gateways/EstPos.php | 20 ++++---- src/Gateways/GarantiPos.php | 15 +++--- src/Gateways/InterPos.php | 16 +++---- src/Gateways/KuveytPos.php | 16 +++---- src/Gateways/PayForPos.php | 9 ++-- src/Gateways/PosNet.php | 16 +++---- src/Gateways/VakifBankPos.php | 12 ++--- src/PosInterface.php | 13 ++++-- tests/Factory/CreditCardFactoryTest.php | 26 ++++------- tests/Gateways/EstPostTest.php | 20 ++++---- tests/Gateways/KuveytPosTest.php | 6 +-- tests/Gateways/PosNetTest.php | 2 +- tests/Gateways/VakifBankPosTest.php | 2 +- 15 files changed, 138 insertions(+), 116 deletions(-) diff --git a/src/Factory/PosFactory.php b/src/Factory/PosFactory.php index 73988de1..efa0f1d8 100644 --- a/src/Factory/PosFactory.php +++ b/src/Factory/PosFactory.php @@ -1,26 +1,45 @@ getBank()], $posAccount, $currencies); + return new $class($config['banks'][$posAccount->getBank()], $posAccount, self::getGatewayMapper($class, $currencies)); + } + + /** + * @param string $gatewayClass + * @param array $currencies + * + * @return AbstractRequestDataMapper + */ + public static function getGatewayMapper(string $gatewayClass, array $currencies = []): AbstractRequestDataMapper + { + switch ($gatewayClass) { + case EstPos::class: + return new EstPosRequestDataMapper($currencies); + case GarantiPos::class: + return new GarantiPosRequestDataMapper($currencies); + case InterPos::class: + return new InterPosRequestDataMapper($currencies); + case KuveytPos::class: + return new KuveytPosRequestDataMapper($currencies); + case PayForPos::class: + return new PayForPosRequestDataMapper($currencies); + case PosNet::class: + return new PosNetRequestDataMapper($currencies); + case VakifBankPos::class: + return new VakifBankPosRequestDataMapper($currencies); + } + throw new DomainException('unsupported gateway'); } } diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index 3153e942..60f1145f 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -39,6 +39,7 @@ abstract class AbstractGateway implements PosInterface protected $cardTypeMapping = []; + /** @var array */ private $config; /** @@ -106,18 +107,20 @@ abstract class AbstractGateway implements PosInterface /** * AbstractGateway constructor. * - * @param $config - * @param AbstractPosAccount $account - * @param array|null $currencies + * @param array $config + * @param AbstractPosAccount $account + * @param AbstractRequestDataMapper $requestDataMapper */ - public function __construct($config, $account, ?array $currencies) + public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { + $this->requestDataMapper = $requestDataMapper; + $this->types = $requestDataMapper->getTxTypeMappings(); + $this->currencies = $requestDataMapper->getCurrencyMappings(); + $this->cardTypeMapping = $requestDataMapper->getCardTypeMapping(); + $this->recurringOrderFrequencyMapping = $requestDataMapper->getRecurringOrderFrequencyMapping(); + $this->config = $config; $this->account = $account; - - if (count($currencies) > 0) { - $this->currencies = $currencies; - } } /** diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index b3ad685c..5ba51bd3 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -1,9 +1,11 @@ requestDataMapper = new EstPosRequestDataMapper($currencies); - $this->types = $this->requestDataMapper->getTxTypeMappings(); - $this->currencies = $this->requestDataMapper->getCurrencyMappings(); - $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - - parent::__construct($config, $account, $currencies); + parent::__construct($config, $account, $requestDataMapper); } /** diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 2890fe65..5def27e9 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -5,7 +5,9 @@ namespace Mews\Pos\Gateways; use GuzzleHttp\Client; +use Mews\Pos\DataMapper\AbstractRequestDataMapper; use Mews\Pos\DataMapper\GarantiPosRequestDataMapper; +use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\GarantiPosAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; use Mews\Pos\Exceptions\NotImplementedException; @@ -56,18 +58,13 @@ class GarantiPos extends AbstractGateway /** * GarantiPost constructor. + * @inheritdoc * - * @param array $config - * @param GarantiPosAccount $account - * @param array $currencies + * @param GarantiPosAccount $account */ - public function __construct($config, $account, array $currencies = []) + public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { - $this->requestDataMapper = new GarantiPosRequestDataMapper($currencies); - $this->types = $this->requestDataMapper->getTxTypeMappings(); - $this->currencies = $this->requestDataMapper->getCurrencyMappings(); - $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - parent::__construct($config, $account, $currencies); + parent::__construct($config, $account, $requestDataMapper); } /** diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index 637abf89..2aa18258 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -5,6 +5,7 @@ namespace Mews\Pos\Gateways; use GuzzleHttp\Client; +use Mews\Pos\DataMapper\AbstractRequestDataMapper; use Mews\Pos\DataMapper\InterPosRequestDataMapper; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\InterPosAccount; @@ -47,18 +48,13 @@ class InterPos extends AbstractGateway protected $requestDataMapper; /** - * @param array $config - * @param InterPosAccount $account - * @param array $currencies + * @inheritdoc + * + * @param InterPosAccount $account */ - public function __construct($config, $account, array $currencies = []) + public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { - $this->requestDataMapper = new InterPosRequestDataMapper($currencies); - $this->types = $this->requestDataMapper->getTxTypeMappings(); - $this->currencies = $this->requestDataMapper->getCurrencyMappings(); - $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - - parent::__construct($config, $account, $currencies); + parent::__construct($config, $account, $requestDataMapper); } /** diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index 377158aa..8f9ea947 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -9,6 +9,7 @@ use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use Mews\Pos\DataMapper\AbstractRequestDataMapper; use Mews\Pos\DataMapper\KuveytPosRequestDataMapper; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\KuveytPosAccount; @@ -48,18 +49,13 @@ class KuveytPos extends AbstractGateway protected $requestDataMapper; /** - * @param array $config - * @param KuveytPosAccount $account - * @param array $currencies + * @inheritdoc + * + * @param KuveytPosAccount $account */ - public function __construct($config, $account, array $currencies = []) + public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { - $this->requestDataMapper = new KuveytPosRequestDataMapper($currencies); - $this->types = $this->requestDataMapper->getTxTypeMappings(); - $this->currencies = $this->requestDataMapper->getCurrencyMappings(); - $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - - parent::__construct($config, $account, $currencies); + parent::__construct($config, $account, $requestDataMapper); } /** diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index d75fdee5..d3b29233 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -5,6 +5,7 @@ namespace Mews\Pos\Gateways; use GuzzleHttp\Client; +use Mews\Pos\DataMapper\AbstractRequestDataMapper; use Mews\Pos\DataMapper\PayForPosRequestDataMapper; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\PayForAccount; @@ -72,13 +73,9 @@ class PayForPos extends AbstractGateway * * @param PayForAccount $account */ - public function __construct($config, $account, array $currencies) + public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { - $this->requestDataMapper = new PayForPosRequestDataMapper($currencies); - $this->types = $this->requestDataMapper->getTxTypeMappings(); - $this->currencies = $this->requestDataMapper->getCurrencyMappings(); - $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - parent::__construct($config, $account, $currencies); + parent::__construct($config, $account, $requestDataMapper); } /** diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 5e7bd570..f87a7db5 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -6,7 +6,9 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use Mews\Pos\DataMapper\AbstractRequestDataMapper; use Mews\Pos\DataMapper\PosNetRequestDataMapper; +use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; use Mews\Pos\Exceptions\NotImplementedException; @@ -71,19 +73,15 @@ class PosNet extends AbstractGateway /** * PosNet constructor. + * @inheritdoc * - * @param array $config * @param PosNetAccount $account - * @param array $currencies */ - public function __construct($config, $account, array $currencies) + public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { - $this->crypt = new PosNetCrypt(); - $this->requestDataMapper = new PosNetRequestDataMapper($currencies); - $this->types = $this->requestDataMapper->getTxTypeMappings(); - $this->currencies = $this->requestDataMapper->getCurrencyMappings(); - $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - parent::__construct($config, $account, $currencies); + $this->crypt = new PosNetCrypt(); + + parent::__construct($config, $account, $requestDataMapper); } /** diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index c8c4f012..b11b660d 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -7,7 +7,9 @@ use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use Mews\Pos\DataMapper\AbstractRequestDataMapper; use Mews\Pos\DataMapper\VakifBankPosRequestDataMapper; +use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\VakifBankAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; use Mews\Pos\Exceptions\UnsupportedPaymentModelException; @@ -52,15 +54,9 @@ class VakifBankPos extends AbstractGateway * * @param VakifBankAccount $account */ - public function __construct($config, $account, array $currencies) + public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { - $this->requestDataMapper = new VakifBankPosRequestDataMapper($currencies); - $this->types = $this->requestDataMapper->getTxTypeMappings(); - $this->currencies = $this->requestDataMapper->getCurrencyMappings(); - $this->cardTypeMapping = $this->requestDataMapper->getCardTypeMapping(); - $this->recurringOrderFrequencyMapping = $this->requestDataMapper->getRecurringOrderFrequencyMapping(); - - parent::__construct($config, $account, $currencies); + parent::__construct($config, $account, $requestDataMapper); } /** diff --git a/src/PosInterface.php b/src/PosInterface.php index 6d0971d6..d1e3436e 100644 --- a/src/PosInterface.php +++ b/src/PosInterface.php @@ -1,8 +1,11 @@ markTestSkipped('pos factory guncellendikten sonra tekrar calistirilacak bu test'); - //$this->expectException(CardTypeNotSupportedException::class); - $pos = $this->getMockBuilder(EstPos::class)->disableOriginalConstructor() - //just any method - ->onlyMethods(['send']) - ->getMock(); + $this->expectException(CardTypeNotSupportedException::class); + $pos = $this->getMockBuilder(EstPos::class)->disableOriginalConstructor()->getMock(); + $pos->expects($this->once())->method('getCardTypeMapping')->willReturn(['visa' => 'visa']); CreditCardFactory::create( $pos, @@ -91,17 +88,14 @@ public function testCreateUnSupportedCardTypeException() } /** - * todo * @return void */ public function testCreateCardTypeRequiredException() { - $this->markTestSkipped('pos factory guncellendikten sonra tekrar calistirilacak bu test'); - //$this->expectException(CardTypeRequiredException::class); - $pos = $this->getMockBuilder(EstPos::class)->disableOriginalConstructor() - //just any method - ->onlyMethods(['send']) - ->getMock(); + $this->expectException(CardTypeRequiredException::class); + $pos = $this->getMockBuilder(EstPos::class)->disableOriginalConstructor()->getMock(); + + $pos->expects($this->once())->method('getCardTypeMapping')->willReturn(['visa' => 'visa']); CreditCardFactory::create( $pos, diff --git a/tests/Gateways/EstPostTest.php b/tests/Gateways/EstPostTest.php index 3fc7b215..98102962 100644 --- a/tests/Gateways/EstPostTest.php +++ b/tests/Gateways/EstPostTest.php @@ -104,7 +104,7 @@ public function testMake3DPaymentAuthFail() $request = Request::create('', 'POST', $this->get3DMakePaymentFailResponseData()); $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send']) ->getMock(); @@ -141,7 +141,7 @@ public function testMake3DPaymentAuthSuccessAndPaymentFail() $request = Request::create('', 'POST', $this->get3DMakePaymentAuthSuccessResponseData()); $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'check3DHash', 'create3DPaymentXML', 'getProcReturnCode']) ->getMock(); @@ -182,7 +182,7 @@ public function testMake3DPaymentAuthSuccessAndPaymentSuccess() $request = Request::create('', 'POST', $this->get3DMakePaymentAuthSuccessResponseData()); $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'check3DHash', 'create3DPaymentXML', 'getProcReturnCode']) ->getMock(); @@ -285,7 +285,7 @@ public function testMake3DHostPaymentFail() public function testStatusSuccess() { $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'createStatusXML', 'getProcReturnCode']) ->getMock(); @@ -318,7 +318,7 @@ public function testStatusSuccess() public function testStatusFail() { $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'createStatusXML', 'getProcReturnCode']) ->getMock(); @@ -351,7 +351,7 @@ public function testStatusFail() public function testHistorySuccess() { $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'createHistoryXML', 'getProcReturnCode']) ->getMock(); @@ -382,7 +382,7 @@ public function testHistorySuccess() public function testHistoryFail() { $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'createHistoryXML', 'getProcReturnCode']) ->getMock(); @@ -413,7 +413,7 @@ public function testHistoryFail() public function testCancelSuccess() { $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'createCancelXML', 'getProcReturnCode']) ->getMock(); @@ -447,7 +447,7 @@ public function testCancelSuccess() public function testCancelFail() { $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'createCancelXML', 'getProcReturnCode']) ->getMock(); @@ -481,7 +481,7 @@ public function testCancelFail() public function testRefundFail() { $posMock = $this->getMockBuilder(EstPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(EstPos::class)]) ->onlyMethods(['send', 'createRefundXML', 'getProcReturnCode']) ->getMock(); diff --git a/tests/Gateways/KuveytPosTest.php b/tests/Gateways/KuveytPosTest.php index 31191909..67143ab5 100644 --- a/tests/Gateways/KuveytPosTest.php +++ b/tests/Gateways/KuveytPosTest.php @@ -177,7 +177,7 @@ public function testGetCommon3DFormDataSuccessResponse() 'gateway' => [ 'test' => $testGateway, ], - ], ], $this->threeDAccount, [], ]) + ], ], $this->threeDAccount, PosFactory::getGatewayMapper(KuveytPos::class), ]) ->onlyMethods(['send']) ->getMock(); $posMock->setTestMode(true); @@ -225,7 +225,7 @@ public function testMake3DPaymentAuthSuccessProvisionFail() ]); $posMock = $this->getMockBuilder(KuveytPos::class) - ->setConstructorArgs([[], $this->threeDAccount, []]) + ->setConstructorArgs([[], $this->threeDAccount, PosFactory::getGatewayMapper(KuveytPos::class)]) ->onlyMethods(['send', 'check3DHash']) ->getMock(); @@ -274,7 +274,7 @@ public function testMake3DPaymentAuthSuccessProvisionSuccess() ]); $posMock = $this->getMockBuilder(KuveytPos::class) - ->setConstructorArgs([[], $this->threeDAccount, []]) + ->setConstructorArgs([[], $this->threeDAccount, PosFactory::getGatewayMapper(KuveytPos::class)]) ->onlyMethods(['send', 'check3DHash']) ->getMock(); diff --git a/tests/Gateways/PosNetTest.php b/tests/Gateways/PosNetTest.php index c3ee3635..9140db2a 100644 --- a/tests/Gateways/PosNetTest.php +++ b/tests/Gateways/PosNetTest.php @@ -105,7 +105,7 @@ public function testGet3DFormDataOosTransactionFail() $this->expectExceptionCode(3); $posMock = $this->getMockBuilder(PosNet::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(PosNet::class)]) ->onlyMethods(['getOosTransactionData']) ->getMock(); $posMock->setTestMode(true); diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index df399e2c..89e92aa5 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -251,7 +251,7 @@ public function testGet3DFormDataEnrollmentFail() $this->expectExceptionCode(2005); $posMock = $this->getMockBuilder(VakifBankPos::class) - ->setConstructorArgs([[], $this->account, []]) + ->setConstructorArgs([[], $this->account, PosFactory::getGatewayMapper(VakifBankPos::class)]) ->onlyMethods(['sendEnrollmentRequest']) ->getMock(); $posMock->setTestMode(true); From 6a24d86f99cb804e15b37a658a5ae61beb1d1a18 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 21:39:07 +0200 Subject: [PATCH 19/40] now order currency does not change when order is prepared in gateway --- src/DataMapper/EstPosRequestDataMapper.php | 8 ++++---- .../GarantiPosRequestDataMapper.php | 14 ++++++------- src/DataMapper/InterPosRequestDataMapper.php | 8 ++++---- src/DataMapper/KuveytPosRequestDataMapper.php | 6 ++++-- src/DataMapper/PayForPosRequestDataMapper.php | 10 +++++----- src/DataMapper/PosNetRequestDataMapper.php | 10 +++++----- .../VakifBankPosRequestDataMapper.php | 8 ++++---- src/Gateways/AbstractGateway.php | 20 +------------------ src/Gateways/EstPos.php | 8 ++++---- src/Gateways/GarantiPos.php | 8 ++++---- src/Gateways/InterPos.php | 4 ++-- src/Gateways/KuveytPos.php | 6 +++--- src/Gateways/PayForPos.php | 12 ++++------- src/Gateways/PosNet.php | 10 +++++----- src/Gateways/VakifBankPos.php | 4 ++-- .../InterPosRequestDataMapperTest.php | 6 +++--- .../KuveytPosRequestDataMapperTest.php | 2 +- .../PosNetRequestDataMapperTest.php | 2 +- .../VakifBankPosRequestDataMapperTest.php | 4 ++-- tests/Gateways/GarantiPosTest.php | 1 - tests/Gateways/InterPosTest.php | 1 - tests/Gateways/KuveytPosTest.php | 1 - tests/Gateways/PayForTest.php | 4 ---- tests/Gateways/PosNetTest.php | 7 ++----- tests/Gateways/VakifBankPosTest.php | 8 +++----- 25 files changed, 70 insertions(+), 102 deletions(-) diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index 594912d8..0c0972c7 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -64,7 +64,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'OrderId' => $order->id, 'UserId' => $order->user_id ?? null, 'Total' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'Taksit' => $order->installment, 'Number' => $responseData['md'], 'PayerTxnId' => $responseData['xid'], @@ -105,7 +105,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'OrderId' => $order->id, 'UserId' => $order->user_id ?? null, 'Total' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'Taksit' => $order->installment, 'Number' => $card->getNumber(), 'Expires' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), @@ -159,7 +159,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar { $requestData = [ 'OrderId' => $order->id, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'Type' => $this->txTypeMappings[AbstractGateway::TX_REFUND], ]; @@ -205,7 +205,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'failUrl' => $order->fail_url, 'rnd' => $order->rand, 'lang' => $this->getLang($account, $order), - 'currency' => $order->currency, + 'currency' => $this->mapCurrency($order->currency), ]; if ($account->getModel() === AbstractGateway::MODEL_3D_PAY || $account->getModel() === AbstractGateway::MODEL_3D_HOST) { diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index 29c42e86..8520e365 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -119,7 +119,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'Type' => $txType, 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, ], @@ -155,7 +155,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'Transaction' => [ 'Type' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'OriginalRetrefNum' => $order->ref_ret_num, ], ]; @@ -185,7 +185,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar 'Type' => $this->txTypeMappings[AbstractGateway::TX_STATUS], 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, ], @@ -216,7 +216,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar 'Type' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, 'OriginalRetrefNum' => $order->ref_ret_num, @@ -249,7 +249,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'Type' => $txType, 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, 'OriginalRetrefNum' => $order->ref_ret_num, @@ -282,7 +282,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar 'Type' => $txType, 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, ], @@ -307,7 +307,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'terminalid' => $account->getTerminalId(), 'txntype' => $txType, 'txnamount' => $order->amount, - 'txncurrencycode' => $order->currency, + 'txncurrencycode' => $this->mapCurrency($order->currency), 'txninstallmentcount' => $order->installment, 'orderid' => $order->id, 'successurl' => $order->success_url, diff --git a/src/DataMapper/InterPosRequestDataMapper.php b/src/DataMapper/InterPosRequestDataMapper.php index 1e1ba0fd..ac162f58 100644 --- a/src/DataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/InterPosRequestDataMapper.php @@ -61,7 +61,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'OrderId' => $order->id, 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'InstallmentCount' => $order->installment, 'MD' => $responseData['MD'], 'PayerTxnId' => $responseData['PayerTxnId'], @@ -85,7 +85,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'OrderId' => $order->id, 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'InstallmentCount' => $order->installment, 'MOTO' => self::MOTO, 'Lang' => $this->getLang($account, $order), @@ -115,7 +115,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'OrderId' => null, 'orgOrderId' => $order->id, 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'MOTO' => self::MOTO, ]; } @@ -200,7 +200,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'FailUrl' => $order->fail_url, 'Rnd' => $order->rand, 'Lang' => $this->getLang($account, $order), - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'InstallmentCount' => $order->installment, ]; diff --git a/src/DataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/KuveytPosRequestDataMapper.php index c7fafc48..27920eef 100644 --- a/src/DataMapper/KuveytPosRequestDataMapper.php +++ b/src/DataMapper/KuveytPosRequestDataMapper.php @@ -1,5 +1,7 @@ self::amountFormat($order->amount), //DisplayAmount: Amount değeri ile aynı olacak şekilde gönderilmelidir. 'DisplayAmount' => self::amountFormat($order->amount), - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'MerchantOrderId' => $order->id, 'OkUrl' => $order->success_url, 'FailUrl' => $order->fail_url, diff --git a/src/DataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/PayForPosRequestDataMapper.php index a612e664..dc43ea60 100644 --- a/src/DataMapper/PayForPosRequestDataMapper.php +++ b/src/DataMapper/PayForPosRequestDataMapper.php @@ -74,7 +74,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'TxnType' => $txType, 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'InstallmentCount' => $order->installment, 'Lang' => $this->getLang($account, $order), 'CardHolderName' => $card->getHolderName(), @@ -98,7 +98,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'Lang' => $this->getLang($account, $order), ]; } @@ -133,7 +133,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar 'OrgOrderId' => $order->id, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'Lang' => $this->getLang($account, $order), ]; } @@ -153,7 +153,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'OrgOrderId' => $order->id, 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_REFUND], 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), ]; } @@ -200,7 +200,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'TxnType' => $txType, 'PurchAmount' => $order->amount, 'InstallmentCount' => $order->installment, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'OkUrl' => $order->success_url, 'FailUrl' => $order->fail_url, 'Rnd' => $order->rand, diff --git a/src/DataMapper/PosNetRequestDataMapper.php b/src/DataMapper/PosNetRequestDataMapper.php index 941482d2..df6eedb6 100644 --- a/src/DataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/PosNetRequestDataMapper.php @@ -93,7 +93,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'orderID' => self::formatOrderId($order->id), 'installment' => $order->installment, 'amount' => $order->amount, - 'currencyCode' => $order->currency, + 'currencyCode' => $this->mapCurrency($order->currency), 'ccno' => $card->getNumber(), 'expDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), 'cvc' => $card->getCvv(), @@ -121,7 +121,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac strtolower($this->txTypeMappings[AbstractGateway::TX_POST_PAY]) => [ 'hostLogKey' => $order->host_ref_num, 'amount' => $order->amount, - 'currencyCode' => $order->currency, + 'currencyCode' => $this->mapCurrency($order->currency), 'installment' => $order->installment, ], ]; @@ -187,7 +187,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'tranDateRequired' => '1', $this->txTypeMappings[AbstractGateway::TX_REFUND] => [ 'amount' => $order->amount, - 'currencyCode' => $order->currency, + 'currencyCode' => $this->mapCurrency($order->currency), ], ]; @@ -263,7 +263,7 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $account, 'expDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), 'cvc' => $card->getCvv(), 'amount' => $order->amount, - 'currencyCode' => $order->currency, + 'currencyCode' => $this->mapCurrency($order->currency), 'installment' => $order->installment, 'XID' => self::formatOrderId($order->id), 'cardHolderName' => $card->getHolderName(), @@ -305,7 +305,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $secondHashData = [ self::formatOrderId($order->id), $order->amount, - $order->currency, + $this->mapCurrency($order->currency), $account->getClientId(), $this->createSecurityData($account), ]; diff --git a/src/DataMapper/VakifBankPosRequestDataMapper.php b/src/DataMapper/VakifBankPosRequestDataMapper.php index b15c407a..f6784fb2 100644 --- a/src/DataMapper/VakifBankPosRequestDataMapper.php +++ b/src/DataMapper/VakifBankPosRequestDataMapper.php @@ -63,7 +63,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'TransactionType' => $txType, 'TransactionId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardHoldersName' => $card->getHolderName(), 'Cvv' => $card->getCvv(), 'Pan' => $card->getNumber(), @@ -99,7 +99,7 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $account, 'MerchantType' => $account->getMerchantType(), 'PurchaseAmount' => self::amountFormat($order->amount), 'VerifyEnrollmentRequestId' => $order->rand, - 'Currency' => $order->currency, + 'Currency' => $this->mapCurrency($order->currency), 'SuccessUrl' => $order->success_url, 'FailureUrl' => $order->fail_url, 'Pan' => $card->getNumber(), @@ -150,7 +150,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'TransactionType' => $txType, 'OrderId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'ClientIp' => $order->ip, 'TransactionDeviceSource' => 0, ]; @@ -180,7 +180,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'TransactionType' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], 'ReferenceTransactionId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => $this->mapCurrency($order->currency), 'ClientIp' => $order->ip, ]; } diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index 60f1145f..fdc8156a 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -73,13 +73,6 @@ abstract class AbstractGateway implements PosInterface */ protected $recurringOrderFrequencyMapping = []; - /** - * Currency mapping - * - * @var array - */ - protected $currencies; - /** * @var object */ @@ -115,7 +108,6 @@ public function __construct(array $config, AbstractPosAccount $account, Abstract { $this->requestDataMapper = $requestDataMapper; $this->types = $requestDataMapper->getTxTypeMappings(); - $this->currencies = $requestDataMapper->getCurrencyMappings(); $this->cardTypeMapping = $requestDataMapper->getCardTypeMapping(); $this->recurringOrderFrequencyMapping = $requestDataMapper->getRecurringOrderFrequencyMapping(); @@ -168,7 +160,7 @@ public function getResponse() */ public function getCurrencies(): array { - return $this->currencies; + return $this->requestDataMapper->getCurrencyMappings(); } /** @@ -439,16 +431,6 @@ public function setTestMode(bool $testMode): self return $this; } - /** - * @param string $currency TRY, USD - * - * @return string - */ - public function mapCurrency(string $currency): string - { - return $this->currencies[$currency] ?? $currency; - } - /** * @param string $period * diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 5ba51bd3..79a0d272 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -339,7 +339,7 @@ protected function map3DPaymentData($raw3DAuthResponseData, $rawPaymentResponseD 'month' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Month'], 'year' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Year'], 'amount' => $raw3DAuthResponseData['amount'], - 'currency' => array_search($raw3DAuthResponseData['currency'], $this->currencies), + 'currency' => array_search($raw3DAuthResponseData['currency'], $this->requestDataMapper->getCurrencyMappings()), 'eci' => $raw3DAuthResponseData['eci'], 'tx_status' => null, 'cavv' => $raw3DAuthResponseData['cavv'], @@ -456,7 +456,7 @@ protected function map3DHostResponseData($raw3DAuthResponseData) 'month' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Month'], 'year' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Year'], 'amount' => $raw3DAuthResponseData['amount'], - 'currency' => array_search($raw3DAuthResponseData['currency'], $this->currencies), + 'currency' => array_search($raw3DAuthResponseData['currency'], $this->requestDataMapper->getCurrencyMappings()), 'tx_status' => null, 'eci' => $raw3DAuthResponseData['eci'], 'cavv' => $raw3DAuthResponseData['cavv'], @@ -653,7 +653,7 @@ protected function preparePaymentOrder(array $order) // Order return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->mapCurrency($order['currency']), + 'currency' => $order['currency'], ]); } @@ -698,7 +698,7 @@ protected function prepareRefundOrder(array $order) { return (object) [ 'id' => $order['id'], - 'currency' => $this->mapCurrency($order['currency']), + 'currency' => $order['currency'], 'amount' => $order['amount'], ]; } diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 5def27e9..81e08982 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -534,7 +534,7 @@ protected function preparePaymentOrder(array $order) // Order return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', @@ -549,7 +549,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'ref_ret_num' => $order['ref_ret_num'], - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', @@ -564,7 +564,7 @@ protected function prepareStatusOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', 'installment' => '', @@ -587,7 +587,7 @@ protected function prepareCancelOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], 'ref_ret_num' => $order['ref_ret_num'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index 2aa18258..a690329d 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -305,7 +305,7 @@ protected function map3DPaymentData($raw3DAuthResponseData, $rawPaymentResponseD 'month' => null, 'year' => null, 'amount' => $raw3DAuthResponseData['PurchAmount'], - 'currency' => array_search($raw3DAuthResponseData['Currency'], $this->currencies), + 'currency' => array_search($raw3DAuthResponseData['Currency'], $this->requestDataMapper->getCurrencyMappings()), 'eci' => $raw3DAuthResponseData['Eci'], 'tx_status' => $raw3DAuthResponseData['TxnStat'], 'cavv' => null, @@ -474,7 +474,7 @@ protected function preparePaymentOrder(array $order) return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], ]); } diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index 8f9ea947..f541a4cb 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -303,7 +303,7 @@ protected function mapPaymentResponse($responseData): array $result['order_id'] = $responseData['MerchantOrderId']; $result['host_ref_num'] = $responseData['RRN']; $result['amount'] = $responseData['VPosMessage']['Amount']; - $result['currency'] = array_search($responseData['VPosMessage']['CurrencyCode'], $this->currencies); + $result['currency'] = array_search($responseData['VPosMessage']['CurrencyCode'], $this->requestDataMapper->getCurrencyMappings()); $result['masked_number'] = $responseData['VPosMessage']['CardNumber']; return $result; @@ -362,7 +362,7 @@ protected function preparePaymentOrder(array $order) return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], ]); } @@ -543,7 +543,7 @@ private function tDPayResponseCommon(array $raw3DAuthResponseData): array if ('approved' === $status) { $default['hash'] = $raw3DAuthResponseData['VPosMessage']['HashData']; $default['amount'] = $raw3DAuthResponseData['VPosMessage']['Amount']; - $default['currency'] = array_search($raw3DAuthResponseData['VPosMessage']['CurrencyCode'], $this->currencies); + $default['currency'] = array_search($raw3DAuthResponseData['VPosMessage']['CurrencyCode'], $this->requestDataMapper->getCurrencyMappings()); $default['masked_number'] = $raw3DAuthResponseData['VPosMessage']['CardNumber']; } diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index d3b29233..f67a8b5c 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -393,7 +393,7 @@ protected function map3DCommonResponseData($raw3DAuthResponseData): array 'rand' => $raw3DAuthResponseData['ResponseRnd'], 'masked_number' => $raw3DAuthResponseData['CardMask'], 'amount' => $raw3DAuthResponseData['PurchAmount'], - 'currency' => array_search($raw3DAuthResponseData['Currency'], $this->currencies), + 'currency' => array_search($raw3DAuthResponseData['Currency'], $this->requestDataMapper->getCurrencyMappings()), 'tx_status' => $raw3DAuthResponseData['TxnResult'], 'xid' => $raw3DAuthResponseData['PayerTxnId'], 'md_code' => $raw3DAuthResponseData['ProcReturnCode'], @@ -497,7 +497,7 @@ protected function mapStatusResponse($rawResponseData) 'process_type' => isset($rawResponseData->TxnType) ? array_search($rawResponseData->TxnType, $this->types, true) : null, 'masked_number' => $rawResponseData->CardMask ?? null, 'amount' => $rawResponseData->PurchAmount ?? null, - 'currency' => isset($rawResponseData->Currency) ? array_search($rawResponseData->Currency, $this->currencies) : null, + 'currency' => isset($rawResponseData->Currency) ? array_search($rawResponseData->Currency, $this->requestDataMapper->getCurrencyMappings()) : null, 'status' => $status, 'status_detail' => $this->codes[$rawResponseData->ProcReturnCode] ?? null, 'all' => $rawResponseData, @@ -528,7 +528,7 @@ protected function preparePaymentOrder(array $order) // Order return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->requestDataMapper->mapCurrency($currency), + 'currency' => $currency, ]); } @@ -540,7 +540,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $order['amount'], - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], ]; } @@ -569,8 +569,6 @@ protected function prepareHistoryOrder(array $order) */ protected function prepareCancelOrder(array $order) { - $order['currency'] = $this->requestDataMapper->mapCurrency($order['currency']); - return (object) $order; } @@ -579,8 +577,6 @@ protected function prepareCancelOrder(array $order) */ protected function prepareRefundOrder(array $order) { - $order['currency'] = $this->requestDataMapper->mapCurrency($order['currency']); - return (object) $order; } } diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index f87a7db5..8dc362d7 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -231,7 +231,7 @@ public function verifyResponseMAC(PosNetAccount $account, $order, $data): bool $data->mdStatus, $this->requestDataMapper::formatOrderId($order->id), $order->amount, - $order->currency, + $this->requestDataMapper->mapCurrency($order->currency), $account->getClientId(), $this->requestDataMapper->createSecurityData($account), ]; @@ -641,7 +641,7 @@ protected function mapHistoryResponse($rawResponseData) $authCode = $rawResponseData->transactions->transaction[0]->authCode; if (count($rawResponseData->transactions->transaction) > 1) { - $currencies = array_flip($this->currencies); + $currencies = array_flip($this->requestDataMapper->getCurrencyMappings()); foreach ($rawResponseData->transactions->transaction as $key => $_transaction) { if ($key > 0) { @@ -718,7 +718,7 @@ protected function preparePaymentOrder(array $order) 'id' => $this->requestDataMapper::formatOrderId($order['id']), 'installment' => $this->requestDataMapper::formatInstallment($installment), 'amount' => $this->requestDataMapper::amountFormat($order['amount']), - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], ]); } @@ -737,7 +737,7 @@ protected function preparePostPaymentOrder(array $order) 'id' => $this->requestDataMapper::formatOrderId($order['id']), 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'installment' => $this->requestDataMapper::formatInstallment($installment), - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], 'host_ref_num' => $order['host_ref_num'], ]; } @@ -784,7 +784,7 @@ protected function prepareRefundOrder(array $order) 'id' => isset($order['id']) ? $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, 'host_ref_num' => $order['host_ref_num'] ?? null, 'amount' => $this->requestDataMapper::amountFormat($order['amount']), - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], ]; } } diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index b11b660d..d87d4401 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -410,7 +410,7 @@ protected function preparePaymentOrder(array $order) // Order return (object) array_merge($order, [ 'installment' => $installment, - 'currency' => $this->requestDataMapper->mapCurrency($currency), + 'currency' => $currency, 'amount' => $order['amount'], ]); } @@ -423,7 +423,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $order['amount'], - 'currency' => $this->requestDataMapper->mapCurrency($order['currency']), + 'currency' => $order['currency'], 'ip' => $order['ip'], ]; } diff --git a/tests/DataMapper/InterPosRequestDataMapperTest.php b/tests/DataMapper/InterPosRequestDataMapperTest.php index 61921b10..f8d5b408 100644 --- a/tests/DataMapper/InterPosRequestDataMapperTest.php +++ b/tests/DataMapper/InterPosRequestDataMapperTest.php @@ -339,7 +339,7 @@ private function getSample3DPaymentRequestData($order, InterPosAccount $account, 'SecureType' => 'NonSecure', 'OrderId' => $order->id, 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => '949', 'InstallmentCount' => $order->installment, 'MD' => $responseData['MD'], 'PayerTxnId' => $responseData['PayerTxnId'], @@ -387,7 +387,7 @@ private function getSampleNonSecurePaymentRequestData($order, AbstractCreditCard 'SecureType' => 'NonSecure', 'OrderId' => $order->id, 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => '949', 'InstallmentCount' => $order->installment, 'MOTO' => '0', 'Lang' => $order->lang, @@ -418,7 +418,7 @@ private function getSampleNonSecurePaymentPostRequestData($order, InterPosAccoun 'OrderId' => null, 'orgOrderId' => $order->id, 'PurchAmount' => $order->amount, - 'Currency' => $order->currency, + 'Currency' => '949', 'MOTO' => '0', ]; } diff --git a/tests/DataMapper/KuveytPosRequestDataMapperTest.php b/tests/DataMapper/KuveytPosRequestDataMapperTest.php index e2cf8cde..e5237dbc 100644 --- a/tests/DataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/DataMapper/KuveytPosRequestDataMapperTest.php @@ -108,7 +108,7 @@ public function testCompose3DFormData() 'InstallmentCount' => $order->installment, 'Amount' => KuveytPosRequestDataMapper::amountFormat($order->amount), 'DisplayAmount' => KuveytPosRequestDataMapper::amountFormat($order->amount), - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => '0949', 'MerchantOrderId' => $order->id, 'OkUrl' => $order->success_url, 'FailUrl' => $order->fail_url, diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php index 9132ef79..68568a4b 100644 --- a/tests/DataMapper/PosNetRequestDataMapperTest.php +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -461,7 +461,7 @@ private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $ac 'capt' => [ 'hostLogKey' => $order->host_ref_num, 'amount' => $order->amount, - 'currencyCode' => $order->currency, + 'currencyCode' => 'TL', 'installment' => $order->installment, ], ]; diff --git a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php index 06abf4cc..3b9a57c2 100644 --- a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php +++ b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php @@ -267,7 +267,7 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord 'TransactionType' => $txType, 'OrderId' => $order->id, 'ClientIp' => $order->ip, - 'CurrencyCode' => $order->currency, + 'CurrencyCode' => '949', 'CurrencyAmount' => $order->amount, 'OrderDescription' => '', 'TransactionId' => $order->id, @@ -303,7 +303,7 @@ private function getSample3DEnrollmentRequestData(AbstractPosAccount $account, $ 'MerchantType' => $account->getMerchantType(), 'PurchaseAmount' => $order->amount, 'VerifyEnrollmentRequestId' => $order->rand, - 'Currency' => $order->currency, + 'Currency' => '949', 'SuccessUrl' => $order->success_url, 'FailureUrl' => $order->fail_url, 'SessionInfo' => $order->extraData, diff --git a/tests/Gateways/GarantiPosTest.php b/tests/Gateways/GarantiPosTest.php index 687d688a..323406d5 100644 --- a/tests/Gateways/GarantiPosTest.php +++ b/tests/Gateways/GarantiPosTest.php @@ -86,7 +86,6 @@ public function testPrepare() $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); $this->assertSame(10025, $this->pos->getOrder()->amount); - $this->assertSame('949', $this->pos->getOrder()->currency); $this->assertSame('', $this->pos->getOrder()->installment); } diff --git a/tests/Gateways/InterPosTest.php b/tests/Gateways/InterPosTest.php index 9ed778c4..8360a36c 100644 --- a/tests/Gateways/InterPosTest.php +++ b/tests/Gateways/InterPosTest.php @@ -83,7 +83,6 @@ public function testInit() public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $this->assertSame('949', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); } diff --git a/tests/Gateways/KuveytPosTest.php b/tests/Gateways/KuveytPosTest.php index 67143ab5..f524fa8a 100644 --- a/tests/Gateways/KuveytPosTest.php +++ b/tests/Gateways/KuveytPosTest.php @@ -120,7 +120,6 @@ public function testSetTestMode() public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $this->assertSame('0949', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); } diff --git a/tests/Gateways/PayForTest.php b/tests/Gateways/PayForTest.php index 9f010dfb..036d2d7e 100644 --- a/tests/Gateways/PayForTest.php +++ b/tests/Gateways/PayForTest.php @@ -96,16 +96,12 @@ public function testPrepare() $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); $this->assertNotEmpty($this->pos->getOrder()); - $this->assertSame('949', $this->pos->getOrder()->currency); $this->pos->prepare($this->order, AbstractGateway::TX_POST_PAY); - $this->assertSame('949', $this->pos->getOrder()->currency); $this->pos->prepare($this->order, AbstractGateway::TX_CANCEL); - $this->assertSame('949', $this->pos->getOrder()->currency); $this->pos->prepare($this->order, AbstractGateway::TX_REFUND); - $this->assertSame('949', $this->pos->getOrder()->currency); } /** diff --git a/tests/Gateways/PosNetTest.php b/tests/Gateways/PosNetTest.php index 9140db2a..239d24cb 100644 --- a/tests/Gateways/PosNetTest.php +++ b/tests/Gateways/PosNetTest.php @@ -54,7 +54,7 @@ protected function setUp(): void 'email' => 'test@test.com', 'amount' => '1.75', 'installment' => 0, - 'currency' => 'TL', + 'currency' => 'TRY', 'success_url' => 'https://domain.com/success', 'fail_url' => 'https://domain.com/fail_url', 'lang' => 'tr', @@ -83,15 +83,12 @@ public function testInit() public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $this->assertSame('TL', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); $this->order['host_ref_num'] = 'zz'; $this->pos->prepare($this->order, AbstractGateway::TX_POST_PAY); - $this->assertSame('TL', $this->pos->getOrder()->currency); $this->pos->prepare($this->order, AbstractGateway::TX_REFUND); - $this->assertSame('TL', $this->pos->getOrder()->currency); } /** @@ -132,7 +129,7 @@ public function testVerifyResponseMAC() $newOrder = $this->order; $newOrder['id'] = '895'; $newOrder['amount'] = 1; - $newOrder['currency'] = 'TL'; + $newOrder['currency'] = 'TRY'; $account = AccountFactory::createPosNetAccount( 'yapikredi', diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index 89e92aa5..3e1b249a 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -90,11 +90,9 @@ public function testInit() public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $this->assertSame('949', $this->pos->getOrder()->currency); $this->assertEquals($this->card, $this->pos->getCard()); $this->pos->prepare($this->order, AbstractGateway::TX_POST_PAY); - $this->assertSame('949', $this->pos->getOrder()->currency); } /** @@ -114,7 +112,7 @@ public function testMap3DPaymentData3DSuccess() 'SubMerchantName' => null, 'SubMerchantNumber' => null, 'PurchAmount' => $preparedOrder['amount'] * 100, - 'PurchCurrency' => $preparedOrder['currency'], + 'PurchCurrency' => '949', 'VerifyEnrollmentRequestId' => $preparedOrder['id'], 'SessionInfo' => $preparedOrder['extraData'], 'InstallmentCount' => null, @@ -143,7 +141,7 @@ public function testMap3DPaymentData3DSuccess() 'HostDate' => '20220404123456', 'Rrn' => '209411062014', 'CurrencyAmount' => $preparedOrder['amount'], - 'CurrencyCode' => $preparedOrder['currency'], + 'CurrencyCode' => '949', 'OrderId' => $preparedOrder['id'], 'TLAmount' => $preparedOrder['amount'], 'ECI' => '02', @@ -196,7 +194,7 @@ public function testMap3DPaymentData3DFail() 'SubMerchantName' => null, 'SubMerchantNumber' => null, 'PurchAmount' => $preparedOrder['amount'] * 100, - 'PurchCurrency' => $preparedOrder['currency'], + 'PurchCurrency' => '949', 'VerifyEnrollmentRequestId' => $preparedOrder['id'], 'SessionInfo' => $preparedOrder['extraData'], 'InstallmentCount' => null, From f256c26bae0afe47e70e2b41290afbdfedcbb37b Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 22:04:41 +0200 Subject: [PATCH 20/40] KuveytPos - move API_VERSION into KuveytPosRequestDataMapper --- src/DataMapper/KuveytPosRequestDataMapper.php | 6 +++--- src/Gateways/KuveytPos.php | 1 - tests/DataMapper/KuveytPosRequestDataMapperTest.php | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/DataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/KuveytPosRequestDataMapper.php index 27920eef..dfa70539 100644 --- a/src/DataMapper/KuveytPosRequestDataMapper.php +++ b/src/DataMapper/KuveytPosRequestDataMapper.php @@ -9,13 +9,13 @@ use Mews\Pos\Entity\Card\AbstractCreditCard; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\Gateways\AbstractGateway; -use Mews\Pos\Gateways\KuveytPos; /** * Creates request data for KuveytPos Gateway requests */ class KuveytPosRequestDataMapper extends AbstractRequestDataMapper { + public const API_VERSION = '1.0.0'; public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y'; public const CREDIT_CARD_EXP_MONTH_FORMAT = 'm'; @@ -79,7 +79,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, $hash = $this->create3DHash($account, $order, $txType, true); return [ - 'APIVersion' => KuveytPos::API_VERSION, + 'APIVersion' => self::API_VERSION, 'HashData' => $hash, 'MerchantId' => $account->getClientId(), 'CustomerId' => $account->getCustomerId(), @@ -114,7 +114,7 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $account, $o $hash = $this->create3DHash($account, $order, $txType); $inputs = [ - 'APIVersion' => KuveytPos::API_VERSION, + 'APIVersion' => self::API_VERSION, 'MerchantId' => $account->getClientId(), 'UserName' => $account->getUsername(), 'CustomerId' => $account->getCustomerId(), diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index f541a4cb..2226ce06 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -26,7 +26,6 @@ class KuveytPos extends AbstractGateway const LANG_EN = 'en'; public const NAME = 'KuveytPos'; - public const API_VERSION = '1.0.0'; /** * Response Codes diff --git a/tests/DataMapper/KuveytPosRequestDataMapperTest.php b/tests/DataMapper/KuveytPosRequestDataMapperTest.php index e5237dbc..d6fa2065 100644 --- a/tests/DataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/DataMapper/KuveytPosRequestDataMapperTest.php @@ -98,7 +98,7 @@ public function testCompose3DFormData() $card = $this->pos->getCard(); $inputs = [ - 'APIVersion' => KuveytPos::API_VERSION, + 'APIVersion' => KuveytPosRequestDataMapper::API_VERSION, 'MerchantId' => $account->getClientId(), 'UserName' => $account->getUsername(), 'CustomerId' => $account->getCustomerId(), @@ -205,7 +205,7 @@ private function getSample3DPaymentXMLData(KuveytPos $pos, string $txType, $resp $hash = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), $txType, true); return [ - 'APIVersion' => KuveytPos::API_VERSION, + 'APIVersion' => KuveytPosRequestDataMapper::API_VERSION, 'HashData' => $hash, 'MerchantId' => $account->getClientId(), 'CustomerId' => $account->getCustomerId(), From 3c1069de8f8878f9aaa372aebc9999e4efbdfed6 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 29 Apr 2022 22:28:44 +0200 Subject: [PATCH 21/40] fix 3dhost test is failing --- config/pos.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/config/pos.php b/config/pos.php index f18201f1..18334ed1 100644 --- a/config/pos.php +++ b/config/pos.php @@ -18,6 +18,10 @@ 'production' => 'https://www.sanalakpos.com/fim/est3Dgate', 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', ], + 'gateway_3d_host' => [ + 'production' => 'https://sanalpos.isbank.com.tr/fim/est3Dgate', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', + ], ], ], 'ziraat' => [ @@ -78,6 +82,10 @@ 'production' => 'https://sanalpos.isbank.com.tr/fim/est3Dgate', 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', ], + 'gateway_3d_host' => [ + 'production' => 'https://sanalpos.isbank.com.tr/fim/est3Dgate', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', + ], ], ], 'yapikredi' => [ From 1ec2211fd2f051ff90bc1a31ec886de037bc91d4 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 1 May 2022 14:41:04 +0200 Subject: [PATCH 22/40] moved language mapping into data mappers --- examples/_common-codes/3d-host/index.php | 10 +++++++- examples/_common-codes/3d/form.php | 11 +++++++- examples/_common-codes/regular/form.php | 10 +++++++- examples/akbank/3d-host/_config.php | 4 ++- examples/akbank/3d-pay/_config.php | 4 ++- examples/akbank/3d/_config.php | 4 ++- examples/akbank/_payment_config.php | 5 ++-- .../finansbank-payfor/_payment_config.php | 5 ++-- examples/garanti/_payment_config.php | 5 ++-- examples/interpos/3d-host/_config.php | 8 +++--- examples/interpos/3d-pay/_config.php | 8 +++--- examples/interpos/3d/_config.php | 8 +++--- examples/interpos/_payment_config.php | 5 ++-- examples/kuveytpos/_payment_config.php | 5 ++-- examples/template/_credit_card_form.php | 7 ++++++ examples/vakifbank/_payment_config.php | 5 ++-- examples/ykb/_payment_config.php | 11 ++++++-- src/DataMapper/AbstractRequestDataMapper.php | 12 ++++++--- src/Factory/AccountFactory.php | 25 +++++++++---------- src/Gateways/AbstractGateway.php | 25 ++++++++----------- src/Gateways/EstPos.php | 3 --- src/Gateways/GarantiPos.php | 3 --- src/Gateways/InterPos.php | 3 --- src/Gateways/KuveytPos.php | 3 --- src/Gateways/PayForPos.php | 3 --- src/Gateways/PosNet.php | 3 --- .../EstPosRequestDataMapperTest.php | 4 +-- .../InterPosRequestDataMapperTest.php | 12 ++++----- .../KuveytPosRequestDataMapperTest.php | 2 +- .../PayForPosRequestDataMapperTest.php | 4 +-- .../PosNetRequestDataMapperTest.php | 2 +- tests/Gateways/EstPostTest.php | 2 +- tests/Gateways/InterPosTest.php | 4 +-- tests/Gateways/KuveytPosTest.php | 2 +- tests/Gateways/PayForTest.php | 2 +- 35 files changed, 135 insertions(+), 94 deletions(-) diff --git a/examples/_common-codes/3d-host/index.php b/examples/_common-codes/3d-host/index.php index d1ca1eee..c9ee9956 100644 --- a/examples/_common-codes/3d-host/index.php +++ b/examples/_common-codes/3d-host/index.php @@ -3,7 +3,15 @@ require '_config.php'; require '../../template/_header.php'; -$order = getNewOrder($baseUrl, $ip, $request->get('currency', 'TRY'), $session); +$order = getNewOrder( + $baseUrl, + $ip, + $request->get('currency', 'TRY'), + $session, + $request->get('installment'), + false, + $request->get('lang', \Mews\Pos\Gateways\AbstractGateway::LANG_TR) +); $session->set('order', $order); $pos->prepare($order, $transaction); diff --git a/examples/_common-codes/3d/form.php b/examples/_common-codes/3d/form.php index 44872a2b..69c7ae93 100644 --- a/examples/_common-codes/3d/form.php +++ b/examples/_common-codes/3d/form.php @@ -10,7 +10,15 @@ exit(); } $transaction = $request->get('tx', \Mews\Pos\Gateways\AbstractGateway::TX_PAY); -$order = getNewOrder($baseUrl, $ip, $request->get('currency', 'TRY'), $session, $request->get('installment')); +$order = getNewOrder( + $baseUrl, + $ip, + $request->get('currency', 'TRY'), + $session, + $request->get('installment'), + false, + $request->get('lang', \Mews\Pos\Gateways\AbstractGateway::LANG_TR) +); $session->set('order', $order); $card = createCard($pos, $request->request->all()); @@ -24,6 +32,7 @@ try { $formData = $pos->get3DFormData(); + //dd($formData); } catch (\Throwable $e) { dd($e); } diff --git a/examples/_common-codes/regular/form.php b/examples/_common-codes/regular/form.php index 7f75ca95..3ccf12e3 100644 --- a/examples/_common-codes/regular/form.php +++ b/examples/_common-codes/regular/form.php @@ -2,7 +2,15 @@ require_once '_config.php'; -$order = getNewOrder($baseUrl, $ip, $request->get('currency', 'TRY'), $session, $request->get('installment')); +$order = getNewOrder( + $baseUrl, + $ip, + $request->get('currency', 'TRY'), + $session, + $request->get('installment'), + false, + $request->get('lang', \Mews\Pos\Gateways\AbstractGateway::LANG_TR) +); $session->set('order', $order); $transaction = $request->get('tx', \Mews\Pos\Gateways\AbstractGateway::TX_PAY); diff --git a/examples/akbank/3d-host/_config.php b/examples/akbank/3d-host/_config.php index 7147ba1d..6a31f900 100644 --- a/examples/akbank/3d-host/_config.php +++ b/examples/akbank/3d-host/_config.php @@ -1,5 +1,7 @@ 1, //'PaymentFrequency' => 2, - return createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, \Mews\Pos\Gateways\InterPos::LANG_TR); + return createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, $lang); } function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\Entity\Card\AbstractCreditCard $card) diff --git a/examples/kuveytpos/_payment_config.php b/examples/kuveytpos/_payment_config.php index 325feee8..7509fcd8 100644 --- a/examples/kuveytpos/_payment_config.php +++ b/examples/kuveytpos/_payment_config.php @@ -27,9 +27,10 @@ function getNewOrder( string $currency, \Symfony\Component\HttpFoundation\Session\Session $session, ?int $installment = 0, - bool $tekrarlanan = false + bool $tekrarlanan = false, + string $lang = AbstractGateway::LANG_TR ): array { - return createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, \Mews\Pos\Gateways\KuveytPos::LANG_TR); + return createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, $lang); } diff --git a/examples/template/_credit_card_form.php b/examples/template/_credit_card_form.php index abdf2903..0ada898f 100644 --- a/examples/template/_credit_card_form.php +++ b/examples/template/_credit_card_form.php @@ -67,6 +67,13 @@ +
+ +

diff --git a/examples/vakifbank/_payment_config.php b/examples/vakifbank/_payment_config.php index 0c3d3b05..0abc240a 100644 --- a/examples/vakifbank/_payment_config.php +++ b/examples/vakifbank/_payment_config.php @@ -40,9 +40,10 @@ function getNewOrder( string $currency, \Symfony\Component\HttpFoundation\Session\Session $session, ?int $installment = 0, - bool $tekrarlanan = false + bool $tekrarlanan = false, + string $lang = AbstractGateway::LANG_TR ): array { - $order = createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment); + $order = createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, $lang); $order['extraData'] = $session->getId(); //optional, istekte SessionInfo degere atanir if ($tekrarlanan) { diff --git a/examples/ykb/_payment_config.php b/examples/ykb/_payment_config.php index ef35fe38..9ce8549e 100644 --- a/examples/ykb/_payment_config.php +++ b/examples/ykb/_payment_config.php @@ -43,9 +43,16 @@ function getNewOrder( string $currency, \Symfony\Component\HttpFoundation\Session\Session $session, ?int $installment = 0, - bool $tekrarlanan = false + bool $tekrarlanan = false, + string $lang = AbstractGateway::LANG_TR ): array { - return createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, \Mews\Pos\Gateways\InterPos::LANG_TR); + /** + * useJokerVadaa: Sadece TDS sistemini kullanacak Üye İşyerleri için, 3D-Secure doğrulamasından + * önce Joker Vadaa(üye işyerlerine özel ek taksit ve öteleme kampanyaları) + * sorgulamasını ve kullanımını aktif etmek için kullanılır. Opsiyoneldir. + * useJokerVadaa degeri $order->koiCode = 1; sekilde set etebilirsiniz. + */ + return createNewPaymentOrderCommon($baseUrl, $ip, $currency, $installment, $lang); } function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\Entity\Card\AbstractCreditCard $card) diff --git a/src/DataMapper/AbstractRequestDataMapper.php b/src/DataMapper/AbstractRequestDataMapper.php index 79fda2c8..dabe4247 100644 --- a/src/DataMapper/AbstractRequestDataMapper.php +++ b/src/DataMapper/AbstractRequestDataMapper.php @@ -6,9 +6,10 @@ use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; +use Mews\Pos\Gateways\AbstractGateway; /** - * todo move txType, currency, installment mapping to here from all gateways + * todo move txType, installment mapping to here from all gateways * AbstractRequestDataMapper */ abstract class AbstractRequestDataMapper @@ -27,6 +28,11 @@ abstract class AbstractRequestDataMapper protected $cardTypeMapping = []; + protected $langMappings = [ + AbstractGateway::LANG_TR => 'tr', + AbstractGateway::LANG_EN => 'en', + ]; + /** * default olarak ISO 4217 kodlar tanimliyoruz. * fakat bazi banklar ISO standarti kullanmiyorlar. @@ -247,9 +253,9 @@ protected function hashString(string $str): string protected function getLang(AbstractPosAccount $account, $order): string { if ($order && isset($order->lang)) { - return $order->lang; + return $this->langMappings[$order->lang]; } - return $account->getLang(); + return $this->langMappings[$account->getLang()]; } } diff --git a/src/Factory/AccountFactory.php b/src/Factory/AccountFactory.php index 1c29f4c6..85b021d5 100644 --- a/src/Factory/AccountFactory.php +++ b/src/Factory/AccountFactory.php @@ -1,5 +1,7 @@ cardTypeMapping; } + /** + * @return string[] + */ + public function getLanguages(): array + { + return [self::LANG_TR, self::LANG_EN]; + } + /** * Create Regular Payment XML * @@ -638,20 +649,6 @@ protected function getDefaultPaymentResponse(): array ]; } - /** - * bank returns error messages for specified language value - * usually accepted values are tr,en - * @return string - */ - protected function getLang(): string - { - if ($this->order && isset($this->order->lang)) { - return $this->order->lang; - } - - return $this->account->getLang(); - } - /** * @param string $str * diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 79a0d272..99ac27e3 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -18,9 +18,6 @@ */ class EstPos extends AbstractGateway { - const LANG_TR = 'tr'; - const LANG_EN = 'en'; - /** * @const string */ diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 81e08982..576c94f3 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -18,9 +18,6 @@ */ class GarantiPos extends AbstractGateway { - const LANG_TR = 'tr'; - const LANG_EN = 'en'; - /** * @const string */ diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index a690329d..5df690b3 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -19,9 +19,6 @@ */ class InterPos extends AbstractGateway { - const LANG_TR = 'tr'; - const LANG_EN = 'en'; - /** * @const string */ diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index 2226ce06..d63fbda6 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -22,9 +22,6 @@ */ class KuveytPos extends AbstractGateway { - const LANG_TR = 'tr'; - const LANG_EN = 'en'; - public const NAME = 'KuveytPos'; /** diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index f67a8b5c..443a0b01 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -23,9 +23,6 @@ class PayForPos extends AbstractGateway */ public const NAME = 'PayForPOS'; - const LANG_TR = 'tr'; - const LANG_EN = 'en'; - /** * @var PayForAccount */ diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 8dc362d7..fad7d2e8 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -19,9 +19,6 @@ */ class PosNet extends AbstractGateway { - const LANG_TR = 'tr'; - const LANG_EN = 'en'; - protected const HASH_ALGORITHM = 'sha256'; protected const HASH_SEPARATOR = ';'; public const NAME = 'PosNet'; diff --git a/tests/DataMapper/EstPosRequestDataMapperTest.php b/tests/DataMapper/EstPosRequestDataMapperTest.php index 345d6ae1..59dd63a0 100644 --- a/tests/DataMapper/EstPosRequestDataMapperTest.php +++ b/tests/DataMapper/EstPosRequestDataMapperTest.php @@ -47,7 +47,7 @@ protected function setUp(): void 'ISBANK07', AbstractGateway::MODEL_3D_SECURE, 'TRPS0200', - EstPos::LANG_TR + AbstractGateway::LANG_TR ); $this->order = [ @@ -332,7 +332,7 @@ public function testGet3DHostFormData() 'XXXXXXX', AbstractGateway::MODEL_3D_HOST, 'VnM5WZ3sGrPusmWP', - EstPos::LANG_TR + AbstractGateway::LANG_TR ); /** @var EstPos $pos */ diff --git a/tests/DataMapper/InterPosRequestDataMapperTest.php b/tests/DataMapper/InterPosRequestDataMapperTest.php index f8d5b408..95896d85 100644 --- a/tests/DataMapper/InterPosRequestDataMapperTest.php +++ b/tests/DataMapper/InterPosRequestDataMapperTest.php @@ -53,7 +53,7 @@ protected function setUp(): void $userPass, AbstractGateway::MODEL_3D_SECURE, $merchantPass, - InterPos::LANG_TR + AbstractGateway::LANG_TR ); $this->order = [ @@ -63,7 +63,7 @@ protected function setUp(): void 'currency' => 'TRY', 'success_url' => 'https://domain.com/success', 'fail_url' => 'https://domain.com/fail_url', - 'lang' => InterPos::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, 'rand' => microtime(true), ]; @@ -140,7 +140,7 @@ public function testCreateCancelRequestData() { $order = [ 'id' => '2020110828BC', - 'lang' => InterPos::LANG_EN, + 'lang' => AbstractGateway::LANG_EN, ]; $pos = $this->pos; $pos->prepare($order, AbstractGateway::TX_CANCEL); @@ -163,7 +163,7 @@ public function testCreate3DPaymentRequestData() 'currency' => 'TRY', 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', - 'lang' => InterPos::LANG_EN, + 'lang' => AbstractGateway::LANG_EN, ]; $responseData = [ 'MD' => '1', @@ -248,7 +248,7 @@ public function testGet3DHostFormData() 'XXXXXXX', AbstractGateway::MODEL_3D_HOST, 'VnM5WZ3sGrPusmWP', - InterPos::LANG_TR + AbstractGateway::LANG_TR ); /** @var InterPos $pos */ $pos = PosFactory::createPosGateway($account); @@ -291,7 +291,7 @@ public function testCreateStatusRequestData() { $order = [ 'id' => '2020110828BC', - 'lang' => InterPos::LANG_EN, + 'lang' => AbstractGateway::LANG_EN, ]; $pos = $this->pos; diff --git a/tests/DataMapper/KuveytPosRequestDataMapperTest.php b/tests/DataMapper/KuveytPosRequestDataMapperTest.php index d6fa2065..e72fcaf2 100644 --- a/tests/DataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/DataMapper/KuveytPosRequestDataMapperTest.php @@ -59,7 +59,7 @@ protected function setUp(): void 'rand' => '0.43625700 1604831630', 'hash' => 'zmSUxYPhmCj7QOzqpk/28LuE1Oc=', 'ip' => '127.0.0.1', - 'lang' => KuveytPos::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, ]; $this->pos = PosFactory::createPosGateway($this->threeDAccount); diff --git a/tests/DataMapper/PayForPosRequestDataMapperTest.php b/tests/DataMapper/PayForPosRequestDataMapperTest.php index 32132541..a9d7ba88 100644 --- a/tests/DataMapper/PayForPosRequestDataMapperTest.php +++ b/tests/DataMapper/PayForPosRequestDataMapperTest.php @@ -59,7 +59,7 @@ protected function setUp(): void 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'rand' => '0.43625700 1604831630', - 'lang' => PayForPos::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, ]; $this->pos = PosFactory::createPosGateway($this->threeDAccount); @@ -87,7 +87,7 @@ public function testCreateNonSecurePostAuthPaymentRequestData() 'amount' => 100.01, 'installment' => '0', 'currency' => 'TRY', - 'lang' => PayForPos::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, ]; $pos = $this->pos; diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php index 68568a4b..fb825e4a 100644 --- a/tests/DataMapper/PosNetRequestDataMapperTest.php +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -62,7 +62,7 @@ protected function setUp(): void 'success_url' => 'https://domain.com/success', 'fail_url' => 'https://domain.com/fail_url', 'rand' => '0.43625700 1604831630', - 'lang' => PosNet::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, ]; $this->pos = PosFactory::createPosGateway($this->threeDAccount); diff --git a/tests/Gateways/EstPostTest.php b/tests/Gateways/EstPostTest.php index 98102962..818335fd 100644 --- a/tests/Gateways/EstPostTest.php +++ b/tests/Gateways/EstPostTest.php @@ -42,7 +42,7 @@ protected function setUp(): void 'ISBANK07', AbstractGateway::MODEL_3D_SECURE, 'TRPS0200', - EstPos::LANG_TR + AbstractGateway::LANG_TR ); $this->order = [ diff --git a/tests/Gateways/InterPosTest.php b/tests/Gateways/InterPosTest.php index 8360a36c..a48be2a4 100644 --- a/tests/Gateways/InterPosTest.php +++ b/tests/Gateways/InterPosTest.php @@ -47,7 +47,7 @@ protected function setUp(): void $userPass, AbstractGateway::MODEL_3D_SECURE, $merchantPass, - InterPos::LANG_TR + AbstractGateway::LANG_TR ); $this->order = [ @@ -57,7 +57,7 @@ protected function setUp(): void 'currency' => 'TRY', 'success_url' => 'https://domain.com/success', 'fail_url' => 'https://domain.com/fail_url', - 'lang' => InterPos::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, 'rand' => microtime(true), ]; diff --git a/tests/Gateways/KuveytPosTest.php b/tests/Gateways/KuveytPosTest.php index f524fa8a..f36959d4 100644 --- a/tests/Gateways/KuveytPosTest.php +++ b/tests/Gateways/KuveytPosTest.php @@ -71,7 +71,7 @@ protected function setUp(): void 'rand' => '0.43625700 1604831630', 'hash' => 'zmSUxYPhmCj7QOzqpk/28LuE1Oc=', 'ip' => '127.0.0.1', - 'lang' => KuveytPos::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, ]; $this->pos = PosFactory::createPosGateway($this->threeDAccount); diff --git a/tests/Gateways/PayForTest.php b/tests/Gateways/PayForTest.php index 036d2d7e..da4e7fb8 100644 --- a/tests/Gateways/PayForTest.php +++ b/tests/Gateways/PayForTest.php @@ -55,7 +55,7 @@ protected function setUp(): void 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'rand' => '0.43625700 1604831630', - 'lang' => PayForPos::LANG_TR, + 'lang' => AbstractGateway::LANG_TR, ]; $this->pos = PosFactory::createPosGateway($this->threeDAccount); From 1d5756283dcff3131753f765a0453e3d1d56adbd Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 1 May 2022 14:54:10 +0200 Subject: [PATCH 23/40] improved examples --- examples/garanti/regular/cancel.php | 2 +- examples/template/_payment_response.php | 3 +++ examples/vakifbank/_payment_config.php | 1 + examples/ykb/3d/_config.php | 10 ++++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/garanti/regular/cancel.php b/examples/garanti/regular/cancel.php index 6b2b34e5..496b626c 100644 --- a/examples/garanti/regular/cancel.php +++ b/examples/garanti/regular/cancel.php @@ -14,7 +14,7 @@ 'email' => $ord['email'], 'amount' => $ord['amount'], 'currency' => $ord['currency'], - 'ref_ret_num' => '831803579226', + 'ref_ret_num' => $session->get('ref_ret_num'), ]; $transaction = AbstractGateway::TX_CANCEL; $pos->prepare($order, $transaction); diff --git a/examples/template/_payment_response.php b/examples/template/_payment_response.php index 6f77b812..04c851d1 100644 --- a/examples/template/_payment_response.php +++ b/examples/template/_payment_response.php @@ -24,6 +24,9 @@ $response = $pos->getResponse(); +if ($pos->isSuccess()) { + $session->set('ref_ret_num', $response->host_ref_num); +} ?>
diff --git a/examples/vakifbank/_payment_config.php b/examples/vakifbank/_payment_config.php index 0abc240a..f7d35bc2 100644 --- a/examples/vakifbank/_payment_config.php +++ b/examples/vakifbank/_payment_config.php @@ -54,6 +54,7 @@ function getNewOrder( //recurring işlemin toplamda kaç kere tekrar edeceği bilgisini içerir 'recurringInstallmentCount' => 4, 'recurringEndDate' => '202112', //optional + // yukardaki belirtilen ayarin anlami 3 ayda bir kesintip yap ve bunu toplam 4 kere tekrarla. ]); } diff --git a/examples/ykb/3d/_config.php b/examples/ykb/3d/_config.php index 4493da45..bcc1a676 100644 --- a/examples/ykb/3d/_config.php +++ b/examples/ykb/3d/_config.php @@ -18,6 +18,16 @@ '10,10,10,10,10,10,10,10' ); +/** + * vftCode: Vade Farklı işlemler için kullanılacak olan kampanya kodunu belirler. + * Üye İşyeri için tanımlı olan kampanya kodu, İşyeri Yönetici Ekranlarına giriş + * yapıldıktan sonra, Üye İşyeri bilgileri sayfasından öğrenilebilinir. + * vtfCode set etmek icin simdilik bu sekilde: + * $account->promotion_code = 'xxx'; + * + * ilerde vtfCode atanmasi duzgun ele alinacak + */ + $pos = getGateway($account); $transaction = \Mews\Pos\Gateways\AbstractGateway::TX_PAY; From 168e565439fada61a338b12374d7a5d38bd4ef12 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 6 May 2022 22:03:01 +0200 Subject: [PATCH 24/40] move transaction type mappings into data mappers --- src/DataMapper/AbstractRequestDataMapper.php | 35 ++++++++++++++++--- src/DataMapper/EstPosRequestDataMapper.php | 18 +++++----- .../GarantiPosRequestDataMapper.php | 30 ++++++++-------- src/DataMapper/InterPosRequestDataMapper.php | 16 ++++----- src/DataMapper/KuveytPosRequestDataMapper.php | 2 +- src/DataMapper/PayForPosRequestDataMapper.php | 16 ++++----- src/DataMapper/PosNetRequestDataMapper.php | 29 ++++++++------- .../VakifBankPosRequestDataMapper.php | 11 +++--- src/Gateways/AbstractGateway.php | 22 ++++-------- src/Gateways/EstPos.php | 6 ++-- src/Gateways/GarantiPos.php | 4 +-- src/Gateways/KuveytPos.php | 2 +- src/Gateways/PayForPos.php | 8 ++--- src/Gateways/PosNet.php | 22 ++++++------ src/Gateways/VakifBankPos.php | 4 +-- .../EstPosRequestDataMapperTest.php | 22 ++++++------ .../GarantiPosRequestDataMapperTest.php | 6 ++-- .../InterPosRequestDataMapperTest.php | 16 ++++----- .../KuveytPosRequestDataMapperTest.php | 13 ++++--- .../PayForPosRequestDataMapperTest.php | 14 ++++---- .../PosNetRequestDataMapperTest.php | 2 +- .../VakifBankPosRequestDataMapperTest.php | 10 +++--- tests/Gateways/EstPostTest.php | 15 +++++--- tests/Gateways/VakifBankPosTest.php | 2 +- 24 files changed, 173 insertions(+), 152 deletions(-) diff --git a/src/DataMapper/AbstractRequestDataMapper.php b/src/DataMapper/AbstractRequestDataMapper.php index dabe4247..9376014f 100644 --- a/src/DataMapper/AbstractRequestDataMapper.php +++ b/src/DataMapper/AbstractRequestDataMapper.php @@ -6,10 +6,11 @@ use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Gateways\AbstractGateway; /** - * todo move txType, installment mapping to here from all gateways + * todo move installment mapping to here from all gateways * AbstractRequestDataMapper */ abstract class AbstractRequestDataMapper @@ -71,7 +72,7 @@ public function __construct(array $currencyMappings = []) /** * @param AbstractPosAccount $account * @param $order - * @param string $txType mapped value from AbstractGateway::TX_PAY + * @param string $txType ex: AbstractGateway::TX_PAY * @param array $responseData gateway'den gelen cevap * * @return array @@ -81,7 +82,7 @@ abstract public function create3DPaymentRequestData(AbstractPosAccount $account, /** * @param AbstractPosAccount $account * @param $order - * @param string $txType mapped value from AbstractGateway::TX_PAY + * @param string $txType ex: AbstractGateway::TX_PAY * @param AbstractCreditCard|null $card * * @return array @@ -124,7 +125,7 @@ abstract public function createRefundRequestData(AbstractPosAccount $account, $o /** * @param AbstractPosAccount $account * @param $order - * @param string $txType mapped value from AbstractGateway::TX_PAY + * @param string $txType ex: AbstractGateway::TX_PAY * @param string $gatewayURL * @param AbstractCreditCard|null $card * @@ -223,6 +224,32 @@ public function mapCurrency(string $currency): string return $this->currencyMappings[$currency] ?? $currency; } + /** + * @param string $txType + * + * @return string + * + * @throws UnsupportedTransactionTypeException + */ + public function mapTxType(string $txType): string + { + if (!$this->isSupportedTxType($txType)) { + throw new UnsupportedTransactionTypeException(); + } + + return $this->txTypeMappings[$txType]; + } + + /** + * @param string $txType + * + * @return bool + */ + public function isSupportedTxType(string $txType): bool + { + return isset($this->txTypeMappings[$txType]); + } + /** * @return array */ diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index 0c0972c7..e128a865 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -58,7 +58,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'Name' => $account->getUsername(), 'Password' => $account->getPassword(), 'ClientId' => $account->getClientId(), - 'Type' => $txType, + 'Type' => $this->mapTxType($txType), 'IPAddress' => $order->ip ?? null, 'Email' => $order->email, 'OrderId' => $order->id, @@ -99,7 +99,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array { return $this->getRequestAccountData($account) + [ - 'Type' => $txType, + 'Type' => $this->mapTxType($txType), 'IPAddress' => $order->ip ?? null, 'Email' => $order->email, 'OrderId' => $order->id, @@ -123,7 +123,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array { return $this->getRequestAccountData($account) + [ - 'Type' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'Type' => $this->mapTxType(AbstractGateway::TX_POST_PAY), 'OrderId' => $order->id, ]; } @@ -136,7 +136,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar return $this->getRequestAccountData($account) + [ 'OrderId' => $order->id, 'Extra' => [ - $this->txTypeMappings[AbstractGateway::TX_STATUS] => 'QUERY', + $this->mapTxType(AbstractGateway::TX_STATUS) => 'QUERY', ], ]; } @@ -148,7 +148,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar { return $this->getRequestAccountData($account) + [ 'OrderId' => $order->id, - 'Type' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], + 'Type' => $this->mapTxType(AbstractGateway::TX_CANCEL), ]; } @@ -160,7 +160,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar $requestData = [ 'OrderId' => $order->id, 'Currency' => $this->mapCurrency($order->currency), - 'Type' => $this->txTypeMappings[AbstractGateway::TX_REFUND], + 'Type' => $this->mapTxType(AbstractGateway::TX_REFUND), ]; if (isset($order->amount)) { @@ -178,7 +178,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar $requestData = [ 'OrderId' => $extraData['order_id'], //todo orderId ya da id olarak degistirilecek, Payfor'da orderId, Garanti'de id 'Extra' => [ - $this->txTypeMappings[AbstractGateway::TX_HISTORY] => 'QUERY', + $this->mapTxType(AbstractGateway::TX_HISTORY) => 'QUERY', ], ]; @@ -210,7 +210,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx if ($account->getModel() === AbstractGateway::MODEL_3D_PAY || $account->getModel() === AbstractGateway::MODEL_3D_HOST) { $inputs = array_merge($inputs, [ - 'islemtipi' => $txType, + 'islemtipi' => $this->mapTxType($txType), 'taksit' => $order->installment, ]); } @@ -252,7 +252,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->amount, $order->success_url, $order->fail_url, - $txType, + $this->mapTxType($txType), $order->installment, $order->rand, $account->getStoreKey(), diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index 8520e365..3b8ed43c 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -116,7 +116,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'AddressList' => $this->getOrderAddressData($order), ], 'Transaction' => [ - 'Type' => $txType, + 'Type' => $this->mapTxType($txType), 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -139,7 +139,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array { - $hash = $this->createHash($account, $order, $this->txTypeMappings[AbstractGateway::TX_POST_PAY], $card); + $hash = $this->createHash($account, $order, AbstractGateway::TX_POST_PAY, $card); return [ 'Mode' => $this->getMode(), @@ -153,7 +153,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'OrderID' => $order->id, ], 'Transaction' => [ - 'Type' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'Type' => $this->mapTxType(AbstractGateway::TX_POST_PAY), 'Amount' => $order->amount, 'CurrencyCode' => $this->mapCurrency($order->currency), 'OriginalRetrefNum' => $order->ref_ret_num, @@ -168,7 +168,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac */ public function createStatusRequestData(AbstractPosAccount $account, $order): array { - $hash = $this->createHash($account, $order, $this->txTypeMappings[AbstractGateway::TX_STATUS]); + $hash = $this->createHash($account, $order,AbstractGateway::TX_STATUS); return [ 'Mode' => $this->getMode(), @@ -182,7 +182,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar 'OrderID' => $order->id, ], 'Transaction' => [ - 'Type' => $this->txTypeMappings[AbstractGateway::TX_STATUS], + 'Type' => $this->mapTxType(AbstractGateway::TX_STATUS), 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -199,7 +199,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar */ public function createCancelRequestData(AbstractPosAccount $account, $order): array { - $hash = $this->createHash($account, $order, $this->txTypeMappings[AbstractGateway::TX_CANCEL]); + $hash = $this->createHash($account, $order, AbstractGateway::TX_CANCEL); return [ 'Mode' => $this->getMode(), @@ -213,7 +213,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar 'OrderID' => $order->id, ], 'Transaction' => [ - 'Type' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], + 'Type' => $this->mapTxType(AbstractGateway::TX_CANCEL), 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -231,8 +231,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar */ public function createRefundRequestData(AbstractPosAccount $account, $order): array { - $txType = $this->txTypeMappings[AbstractGateway::TX_REFUND]; - $hash = $this->createHash($account, $order, $txType); + $hash = $this->createHash($account, $order, AbstractGateway::TX_REFUND); return [ 'Mode' => $this->getMode(), @@ -246,7 +245,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'OrderID' => $order->id, ], 'Transaction' => [ - 'Type' => $txType, + 'Type' => $this->mapTxType(AbstractGateway::TX_REFUND), 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -264,8 +263,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar */ public function createHistoryRequestData(AbstractPosAccount $account, $order, array $extraData = []): array { - $txType = $this->txTypeMappings[AbstractGateway::TX_HISTORY]; - $hash = $this->createHash($account, $order, $txType); + $hash = $this->createHash($account, $order, AbstractGateway::TX_HISTORY); return [ 'Mode' => $this->getMode(), @@ -279,7 +277,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar 'OrderID' => $order->id, ], 'Transaction' => [ - 'Type' => $txType, + 'Type' => $this->mapTxType(AbstractGateway::TX_HISTORY), 'InstallmentCnt' => $order->installment, 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -305,7 +303,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'terminaluserid' => $account->getUsername(), 'terminalmerchantid' => $account->getClientId(), 'terminalid' => $account->getTerminalId(), - 'txntype' => $txType, + 'txntype' => $this->mapTxType($txType), 'txnamount' => $order->amount, 'txncurrencycode' => $this->mapCurrency($order->currency), 'txninstallmentcount' => $order->installment, @@ -343,7 +341,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->amount, $order->success_url, $order->fail_url, - $txType, + $this->mapTxType($txType), $order->installment, $account->getStoreKey(), $this->createSecurityData($account, $txType), @@ -415,7 +413,7 @@ private function getMode(): string */ private function createSecurityData(AbstractPosAccount $account, string $txType): string { - if ($txType === $this->txTypeMappings[AbstractGateway::TX_REFUND] || $txType === $this->txTypeMappings[AbstractGateway::TX_CANCEL]) { + if (AbstractGateway::TX_REFUND === $txType || AbstractGateway::TX_CANCEL === $txType) { $password = $account->getRefundPassword(); } else { $password = $account->getPassword(); diff --git a/src/DataMapper/InterPosRequestDataMapper.php b/src/DataMapper/InterPosRequestDataMapper.php index ac162f58..fa2e2277 100644 --- a/src/DataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/InterPosRequestDataMapper.php @@ -57,7 +57,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'UserCode' => $account->getUsername(), 'UserPass' => $account->getPassword(), 'ClientId' => $account->getClientId(), - 'TxnType' => $txType, + 'TxnType' => $this->mapTxType($txType), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'OrderId' => $order->id, 'PurchAmount' => $order->amount, @@ -81,7 +81,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'UserCode' => $account->getUsername(), 'UserPass' => $account->getPassword(), 'ShopCode' => $account->getClientId(), - 'TxnType' => $txType, + 'TxnType' => $this->mapTxType($txType), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'OrderId' => $order->id, 'PurchAmount' => $order->amount, @@ -110,7 +110,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'UserCode' => $account->getUsername(), 'UserPass' => $account->getPassword(), 'ShopCode' => $account->getClientId(), - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_POST_PAY), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'OrderId' => null, 'orgOrderId' => $order->id, @@ -131,7 +131,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar 'ShopCode' => $account->getClientId(), 'OrderId' => null, //todo buraya hangi deger verilecek? 'orgOrderId' => $order->id, - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_STATUS], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_STATUS), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'Lang' => $this->getLang($account, $order), ]; @@ -148,7 +148,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar 'ShopCode' => $account->getClientId(), 'OrderId' => null, //todo buraya hangi deger verilecek? 'orgOrderId' => $order->id, - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_CANCEL), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'Lang' => $this->getLang($account, $order), ]; @@ -166,7 +166,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'OrderId' => null, 'orgOrderId' => $order->id, 'PurchAmount' => $order->amount, - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_REFUND], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_REFUND), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'Lang' => $this->getLang($account, $order), 'MOTO' => self::MOTO, @@ -191,7 +191,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx $inputs = [ 'ShopCode' => $account->getClientId(), - 'TxnType' => $txType, + 'TxnType' => $this->mapTxType($txType), 'SecureType' => $this->secureTypeMappings[$account->getModel()], 'Hash' => $hash, 'PurchAmount' => $order->amount, @@ -228,7 +228,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->amount, $order->success_url, $order->fail_url, - $txType, + $this->mapTxType($txType), $order->installment, $order->rand, $account->getStoreKey(), diff --git a/src/DataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/KuveytPosRequestDataMapper.php index dfa70539..a1d97e8a 100644 --- a/src/DataMapper/KuveytPosRequestDataMapper.php +++ b/src/DataMapper/KuveytPosRequestDataMapper.php @@ -119,7 +119,7 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $account, $o 'UserName' => $account->getUsername(), 'CustomerId' => $account->getCustomerId(), 'HashData' => $hash, - 'TransactionType' => $txType, + 'TransactionType' => $this->mapTxType($txType), 'TransactionSecurity' => $this->secureTypeMappings[$account->getModel()], 'InstallmentCount' => $order->installment, 'Amount' => self::amountFormat($order->amount), diff --git a/src/DataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/PayForPosRequestDataMapper.php index dc43ea60..7486421e 100644 --- a/src/DataMapper/PayForPosRequestDataMapper.php +++ b/src/DataMapper/PayForPosRequestDataMapper.php @@ -72,7 +72,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'MOTO' => self::MOTO, 'OrderId' => $order->id, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'TxnType' => $txType, + 'TxnType' => $this->mapTxType($txType), 'PurchAmount' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), 'InstallmentCount' => $order->installment, @@ -96,7 +96,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'UserPass' => $account->getPassword(), 'OrgOrderId' => $order->id, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_POST_PAY), 'PurchAmount' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), 'Lang' => $this->getLang($account, $order), @@ -116,7 +116,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar 'OrgOrderId' => $order->id, 'SecureType' => 'Inquiry', 'Lang' => $this->getLang($account, $order), - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_STATUS], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_STATUS), ]; } @@ -132,7 +132,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar 'UserPass' => $account->getPassword(), 'OrgOrderId' => $order->id, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_CANCEL), 'Currency' => $this->mapCurrency($order->currency), 'Lang' => $this->getLang($account, $order), ]; @@ -151,7 +151,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'Lang' => $this->getLang($account, $order), 'OrgOrderId' => $order->id, - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_REFUND], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_REFUND), 'PurchAmount' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), ]; @@ -168,7 +168,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar 'UserCode' => $account->getUsername(), 'UserPass' => $account->getPassword(), 'SecureType' => 'Report', - 'TxnType' => $this->txTypeMappings[AbstractGateway::TX_HISTORY], + 'TxnType' => $this->mapTxType(AbstractGateway::TX_HISTORY), 'Lang' => $this->getLang($account, $order), ]; @@ -197,7 +197,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'OrderId' => $order->id, 'Lang' => $this->getLang($account, $order), 'SecureType' => $this->secureTypeMappings[$account->getModel()], - 'TxnType' => $txType, + 'TxnType' => $this->mapTxType($txType), 'PurchAmount' => $order->amount, 'InstallmentCount' => $order->installment, 'Currency' => $this->mapCurrency($order->currency), @@ -231,7 +231,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->amount, $order->success_url, $order->fail_url, - $txType, + $this->mapTxType($txType), $order->installment, $order->rand, $account->getStoreKey(), diff --git a/src/DataMapper/PosNetRequestDataMapper.php b/src/DataMapper/PosNetRequestDataMapper.php index df6eedb6..e2d56c2f 100644 --- a/src/DataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/PosNetRequestDataMapper.php @@ -89,7 +89,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'mid' => $account->getClientId(), 'tid' => $account->getTerminalId(), 'tranDateRequired' => '1', - strtolower($txType) => [ + strtolower($this->mapTxType($txType)) => [ 'orderID' => self::formatOrderId($order->id), 'installment' => $order->installment, 'amount' => $order->amount, @@ -101,7 +101,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ ]; if (isset($order->koiCode) && $order->koiCode > 0) { - $requestData[strtolower($txType)]['koiCode'] = $order->koiCode; + $requestData[strtolower($this->mapTxType($txType))]['koiCode'] = $order->koiCode; } return $requestData; @@ -118,7 +118,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'mid' => $account->getClientId(), 'tid' => $account->getTerminalId(), 'tranDateRequired' => '1', - strtolower($this->txTypeMappings[AbstractGateway::TX_POST_PAY]) => [ + strtolower($this->mapTxType(AbstractGateway::TX_POST_PAY)) => [ 'hostLogKey' => $order->host_ref_num, 'amount' => $order->amount, 'currencyCode' => $this->mapCurrency($order->currency), @@ -134,10 +134,12 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac */ public function createStatusRequestData(AbstractPosAccount $account, $order): array { + $txType = $this->mapTxType(AbstractGateway::TX_STATUS); + return [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - $this->txTypeMappings[AbstractGateway::TX_STATUS] => [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + $txType => [ 'orderID' => $order->id, ], ]; @@ -150,7 +152,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar */ public function createCancelRequestData(AbstractPosAccount $account, $order): array { - $txType = $this->txTypeMappings[AbstractGateway::TX_CANCEL]; + $txType = $this->mapTxType(AbstractGateway::TX_CANCEL); $requestData = [ 'mid' => $account->getClientId(), 'tid' => $account->getTerminalId(), @@ -181,20 +183,21 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar */ public function createRefundRequestData(AbstractPosAccount $account, $order): array { + $txType = $this->mapTxType(AbstractGateway::TX_REFUND); $requestData = [ - 'mid' => $account->getClientId(), - 'tid' => $account->getTerminalId(), - 'tranDateRequired' => '1', - $this->txTypeMappings[AbstractGateway::TX_REFUND] => [ + 'mid' => $account->getClientId(), + 'tid' => $account->getTerminalId(), + 'tranDateRequired' => '1', + $txType => [ 'amount' => $order->amount, 'currencyCode' => $this->mapCurrency($order->currency), ], ]; if (isset($order->host_ref_num)) { - $requestData[$this->txTypeMappings[AbstractGateway::TX_REFUND]]['hostLogKey'] = $order->host_ref_num; + $requestData[$txType]['hostLogKey'] = $order->host_ref_num; } else { - $requestData[$this->txTypeMappings[AbstractGateway::TX_REFUND]]['orderID'] = $order->id; + $requestData[$txType]['orderID'] = $order->id; } return $requestData; diff --git a/src/DataMapper/VakifBankPosRequestDataMapper.php b/src/DataMapper/VakifBankPosRequestDataMapper.php index f6784fb2..5305d6d4 100644 --- a/src/DataMapper/VakifBankPosRequestDataMapper.php +++ b/src/DataMapper/VakifBankPosRequestDataMapper.php @@ -4,7 +4,6 @@ */ namespace Mews\Pos\DataMapper; -use Exception; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\VakifBankAccount; use Mews\Pos\Entity\Card\AbstractCreditCard; @@ -60,7 +59,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'MerchantId' => $account->getClientId(), 'Password' => $account->getPassword(), 'TerminalNo' => $account->getTerminalId(), - 'TransactionType' => $txType, + 'TransactionType' => $this->mapTxType($txType), 'TransactionId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -147,7 +146,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'MerchantId' => $account->getClientId(), 'Password' => $account->getPassword(), 'TerminalNo' => $account->getTerminalId(), - 'TransactionType' => $txType, + 'TransactionType' => $this->mapTxType($txType), 'OrderId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -177,7 +176,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'MerchantId' => $account->getClientId(), 'Password' => $account->getPassword(), 'TerminalNo' => $account->getTerminalId(), - 'TransactionType' => $this->txTypeMappings[AbstractGateway::TX_POST_PAY], + 'TransactionType' => $this->mapTxType(AbstractGateway::TX_POST_PAY), 'ReferenceTransactionId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), 'CurrencyCode' => $this->mapCurrency($order->currency), @@ -201,7 +200,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar return [ 'MerchantId' => $account->getClientId(), 'Password' => $account->getPassword(), - 'TransactionType' => $this->txTypeMappings[AbstractGateway::TX_CANCEL], + 'TransactionType' => $this->mapTxType(AbstractGateway::TX_CANCEL), 'ReferenceTransactionId' => $order->id, 'ClientIp' => $order->ip, ]; @@ -215,7 +214,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar return [ 'MerchantId' => $account->getClientId(), 'Password' => $account->getPassword(), - 'TransactionType' => $this->txTypeMappings[AbstractGateway::TX_REFUND], + 'TransactionType' => $this->mapTxType(AbstractGateway::TX_REFUND), 'ReferenceTransactionId' => $order->id, 'ClientIp' => $order->ip, 'CurrencyAmount' => self::amountFormat($order->amount), diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index f69de954..7292c9b7 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -55,13 +55,6 @@ abstract class AbstractGateway implements PosInterface */ protected $card; - /** - * Transaction Types - * - * @var array - */ - protected $types = []; - /** * Transaction Type * @@ -110,7 +103,6 @@ abstract class AbstractGateway implements PosInterface public function __construct(array $config, AbstractPosAccount $account, AbstractRequestDataMapper $requestDataMapper) { $this->requestDataMapper = $requestDataMapper; - $this->types = $requestDataMapper->getTxTypeMappings(); $this->cardTypeMapping = $requestDataMapper->getCardTypeMapping(); $this->recurringOrderFrequencyMapping = $requestDataMapper->getRecurringOrderFrequencyMapping(); @@ -313,11 +305,9 @@ public function isTestMode(): bool */ public function setTxType(string $txType) { - if (array_key_exists($txType, $this->types)) { - $this->type = $this->types[$txType]; - } else { - throw new UnsupportedTransactionTypeException(); - } + $this->requestDataMapper->mapTxType($txType); + + $this->type = $txType; } /** @@ -351,9 +341,9 @@ public function payment($card = null) public function makeRegularPayment() { $contents = ''; - if (in_array($this->type, [$this->types[self::TX_PAY], $this->types[self::TX_PRE_PAY]])) { + if (in_array($this->type, [self::TX_PAY, self::TX_PRE_PAY])) { $contents = $this->createRegularPaymentXML(); - } elseif ($this->types[self::TX_POST_PAY] === $this->type) { + } elseif (self::TX_POST_PAY === $this->type) { $contents = $this->createRegularPostXML(); } @@ -635,7 +625,7 @@ protected function getDefaultPaymentResponse(): array 'order_id' => null, 'trans_id' => null, 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'auth_code' => null, 'host_ref_num' => null, 'proc_return_code' => null, diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 99ac27e3..99002017 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -379,7 +379,7 @@ protected function map3DPayResponseData($raw3DAuthResponseData) 'response' => $raw3DAuthResponseData['Response'], 'order_id' => $raw3DAuthResponseData['oid'], 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'transaction_security' => $transactionSecurity, 'code' => $raw3DAuthResponseData['ProcReturnCode'], 'md_status' => $raw3DAuthResponseData['mdStatus'], @@ -439,7 +439,7 @@ protected function map3DHostResponseData($raw3DAuthResponseData) 'response' => null, 'order_id' => $raw3DAuthResponseData['oid'], 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'transaction_security' => $transactionSecurity, 'code' => null, 'md_status' => $raw3DAuthResponseData['mdStatus'], @@ -593,7 +593,7 @@ protected function mapPaymentResponse($responseData): array 'trans_id' => $responseData['TransId'], 'response' => $responseData['Response'], 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'auth_code' => $responseData['AuthCode'], 'host_ref_num' => $responseData['HostRefNum'], 'proc_return_code' => $responseData['ProcReturnCode'], diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 576c94f3..32a80070 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -332,7 +332,7 @@ protected function tDPayResponseCommon(array $raw3DAuthResponseData): array 'host_ref_num' => null, 'response' => $response, 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'transaction_security' => $transactionSecurity, 'proc_return_code' => $procReturnCode, 'code' => $procReturnCode, @@ -377,7 +377,7 @@ protected function mapPaymentResponse($responseData): array 'trans_id' => isset($responseData->Transaction->AuthCode) ? $this->printData($responseData->Transaction->AuthCode) : null, 'response' => isset($responseData->Transaction->Response->Message) ? $this->printData($responseData->Transaction->Response->Message) : null, 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'auth_code' => isset($responseData->Transaction->AuthCode) ? $this->printData($responseData->Transaction->AuthCode) : null, 'host_ref_num' => isset($responseData->Transaction->RetrefNum) ? $this->printData($responseData->Transaction->RetrefNum) : null, 'ret_ref_num' => isset($responseData->Transaction->RetrefNum) ? $this->printData($responseData->Transaction->RetrefNum) : null, diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index d63fbda6..817d2f5c 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -517,7 +517,7 @@ private function tDPayResponseCommon(array $raw3DAuthResponseData): array 'order_id' => $orderId, 'response' => $response, 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'transaction_security' => $transactionSecurity, 'proc_return_code' => $procReturnCode, 'code' => $procReturnCode, diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index 443a0b01..13207d19 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -366,8 +366,8 @@ protected function map3DPayResponseData($raw3DAuthResponseData) 'status_detail' => $this->codes[$raw3DAuthResponseData['ProcReturnCode']] ?? null, 'error_code' => ('approved' !== $status) ? $raw3DAuthResponseData['ProcReturnCode'] : null, 'error_message' => ('approved' !== $status) ? $raw3DAuthResponseData['ErrMsg'] : null, - 'transaction_type' => array_search($raw3DAuthResponseData['TxnType'], $this->types, true), - 'transaction' => $this->type, + 'transaction' => array_search($raw3DAuthResponseData['TxnType'], $this->requestDataMapper->getTxTypeMappings(), true), + 'transaction_type' => $this->type, ]; return (object) array_merge($threeDResponse, $this->map3DCommonResponseData($raw3DAuthResponseData)); @@ -451,7 +451,7 @@ protected function mapPaymentResponse($responseData): array 'order_id' => $responseData->TransId, 'trans_id' => $responseData->TransId, 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'auth_code' => $responseData->AuthCode, 'host_ref_num' => $responseData->HostRefNum, 'proc_return_code' => $responseData->ProcReturnCode, @@ -491,7 +491,7 @@ protected function mapStatusResponse($rawResponseData) 'error_message' => ('declined' === $status) ? $rawResponseData->ErrMsg : null, 'host_ref_num' => $rawResponseData->HostRefNum ?? null, 'order_status' => $orderStatus, - 'process_type' => isset($rawResponseData->TxnType) ? array_search($rawResponseData->TxnType, $this->types, true) : null, + 'process_type' => isset($rawResponseData->TxnType) ? array_search($rawResponseData->TxnType, $this->requestDataMapper->getTxTypeMappings(), true) : null, 'masked_number' => $rawResponseData->CardMask ?? null, 'amount' => $rawResponseData->PurchAmount ?? null, 'currency' => isset($rawResponseData->Currency) ? array_search($rawResponseData->Currency, $this->requestDataMapper->getCurrencyMappings()) : null, diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index fad7d2e8..70a2d2af 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -395,7 +395,7 @@ protected function map3DPaymentData($raw3DAuthResponseData, $rawPaymentResponseD 'trans_id' => isset($rawPaymentResponseData->authCode) ? $this->printData($rawPaymentResponseData->authCode) : null, 'response' => $this->getStatusDetail(), 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'transaction_security' => $transactionSecurity, 'auth_code' => isset($rawPaymentResponseData->authCode) ? $this->printData($rawPaymentResponseData->authCode) : null, 'host_ref_num' => isset($rawPaymentResponseData->hostlogkey) ? $this->printData($rawPaymentResponseData->hostlogkey) : null, @@ -452,7 +452,7 @@ protected function mapPaymentResponse($responseData): array 'trans_id' => isset($responseData->authCode) ? $this->printData($responseData->authCode) : null, 'response' => $this->getStatusDetail(), 'transaction_type' => $this->type, - 'transaction' => $this->type, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), 'auth_code' => isset($responseData->authCode) ? $this->printData($responseData->authCode) : null, 'host_ref_num' => isset($responseData->hostlogkey) ? $this->printData($responseData->hostlogkey) : null, 'ret_ref_num' => isset($responseData->hostlogkey) ? $this->printData($responseData->hostlogkey) : null, @@ -489,13 +489,13 @@ protected function mapRefundResponse($rawResponseData) $state = $rawResponseData->state ?? null; if ('Sale' === $state) { $transaction = 'pay'; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Authorization' === $state) { $transaction = 'pre'; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Capture' === $state) { $transaction = 'post'; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } return (object) [ @@ -566,15 +566,15 @@ protected function mapStatusResponse($rawResponseData) if ('Sale' === $state) { $transaction = 'pay'; $state = $transaction; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Authorization' === $state) { $transaction = 'pre'; $state = $transaction; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Capture' === $state) { $transaction = 'post'; $state = $transaction; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Bonus_Reverse' === $state) { $state = 'cancel'; } else { @@ -660,15 +660,15 @@ protected function mapHistoryResponse($rawResponseData) if ('Sale' === $state) { $transaction = 'pay'; $state = $transaction; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Authorization' === $state) { $transaction = 'pre'; $state = $transaction; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Capture' === $state) { $transaction = 'post'; $state = $transaction; - $transactionType = $this->types[$transaction]; + $transactionType = $this->requestDataMapper->mapTxType($transaction); } elseif ('Bonus_Reverse' === $state) { $state = 'cancel'; } else { diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index d87d4401..6a73f988 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -483,8 +483,8 @@ private function getCommonPaymentResponse($responseData): array 'auth_code' => null, 'host_ref_num' => null, 'order_id' => null, - 'transaction' => $this->type, - 'transaction_type' => null, + 'transaction' => empty($this->type) ? null : $this->requestDataMapper->mapTxType($this->type), + 'transaction_type' => $this->type, 'response' => null, 'eci' => null, 'proc_return_code' => $resultCode, diff --git a/tests/DataMapper/EstPosRequestDataMapperTest.php b/tests/DataMapper/EstPosRequestDataMapperTest.php index 59dd63a0..a5461cea 100644 --- a/tests/DataMapper/EstPosRequestDataMapperTest.php +++ b/tests/DataMapper/EstPosRequestDataMapperTest.php @@ -116,7 +116,7 @@ public function testCreateNonSecurePaymentRequestData() $card = $this->card; $pos->prepare($order, AbstractGateway::TX_PAY, $card); - $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $card); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $card); $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); $this->assertEquals($expectedData, $actual); @@ -132,7 +132,7 @@ public function testCreate3DHashFor3DSecure() $expected = 'mJReAoQNtx0G+nWUGA/BHLx/+BI='; $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), 'Auth'); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY); $this->assertEquals($expected, $actual); } @@ -154,7 +154,7 @@ public function testCreate3DHashForNon3DSecure() $pos = PosFactory::createPosGateway($account); $expected = 'zW2HEQR/H0mpo1jrztIgmIPFFEU='; $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DHash($account, $pos->getOrder(), 'Auth'); + $actual = $this->requestDataMapper->create3DHash($account, $pos->getOrder(), AbstractGateway::TX_PAY); $this->assertEquals($expected, $actual); } @@ -219,7 +219,7 @@ public function testCreate3DPaymentRequestData() $pos = $this->pos; $pos->prepare($order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $responseData); + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $responseData); $expectedData = $this->getSample3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), $responseData); $this->assertEquals($expectedData, $actual); @@ -256,7 +256,7 @@ public function testCreate3DPaymentRequestDataRecurringOrder() $pos = $this->pos; $pos->prepare($order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $responseData); + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $responseData); $expectedData = $this->getSample3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), $responseData); $this->assertEquals($expectedData, $actual); @@ -269,8 +269,8 @@ public function testCreate3DPaymentRequestDataRecurringOrder() public function testGet3DFormData() { $account = $this->threeDAccount; - $this->pos->prepare($this->order, AbstractGateway::TX_PAY); - $txType = 'Auth'; + $txType = AbstractGateway::TX_PAY; + $this->pos->prepare($this->order, $txType); $hash = $this->requestDataMapper->create3DHash($account, $this->pos->getOrder(), $txType); $card = $this->card; $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test']; @@ -297,7 +297,7 @@ public function testGet3DFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), $this->pos->getOrder(), - 'Auth', + $txType, $gatewayURL )); @@ -313,7 +313,7 @@ public function testGet3DFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), $this->pos->getOrder(), - 'Auth', + $txType, $gatewayURL, $card )); @@ -340,7 +340,7 @@ public function testGet3DHostFormData() $pos->setTestMode(true); $pos->prepare($this->order, AbstractGateway::TX_PAY); $order = $pos->getOrder(); - $hash = $this->requestDataMapper->create3DHash($account, $order, 'Auth'); + $hash = $this->requestDataMapper->create3DHash($account, $order, AbstractGateway::TX_PAY); $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway_3d_host']['test']; $inputs = [ 'clientid' => $account->getClientId(), @@ -366,7 +366,7 @@ public function testGet3DHostFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $pos->getAccount(), $pos->getOrder(), - 'Auth', + AbstractGateway::TX_PAY, $gatewayURL )); } diff --git a/tests/DataMapper/GarantiPosRequestDataMapperTest.php b/tests/DataMapper/GarantiPosRequestDataMapperTest.php index ee6bc609..39a3f7ba 100644 --- a/tests/DataMapper/GarantiPosRequestDataMapperTest.php +++ b/tests/DataMapper/GarantiPosRequestDataMapperTest.php @@ -118,7 +118,7 @@ public function testCreateNonSecurePaymentRequestData() $card = $this->card; $pos->prepare($order, AbstractGateway::TX_PAY, $card); - $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'sales', $card); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $card); $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); $this->assertEquals($expectedData, $actual); @@ -132,7 +132,7 @@ public function testCreate3DHash() $expected = '1D319D5EA945F5730FF5BCC970FF96690993F4BD'; $pos = $this->pos; $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), 'sales'); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY); $this->assertSame($expected, $actual); } @@ -268,7 +268,7 @@ public function testGet3DFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), $this->pos->getOrder(), - 'sales', + AbstractGateway::TX_PAY, $gatewayURL, $this->card )); diff --git a/tests/DataMapper/InterPosRequestDataMapperTest.php b/tests/DataMapper/InterPosRequestDataMapperTest.php index 95896d85..749ca721 100644 --- a/tests/DataMapper/InterPosRequestDataMapperTest.php +++ b/tests/DataMapper/InterPosRequestDataMapperTest.php @@ -114,7 +114,7 @@ public function testCreateNonSecurePaymentRequestData() $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet', AbstractCreditCard::CARD_TYPE_VISA); $pos->prepare($order, AbstractGateway::TX_PAY, $card); - $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $card); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $card); $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getOrder(), $pos->getCard(), $pos->getAccount()); $this->assertEquals($expectedData, $actual); @@ -129,7 +129,7 @@ public function testCreate3DHash() $pos = $this->pos; $expected = 'vEbwP8wnsGrBR9oCjfxP9wlho1g='; $pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), 'Auth'); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY); $this->assertEquals($expected, $actual); } @@ -175,7 +175,7 @@ public function testCreate3DPaymentRequestData() $pos = $this->pos; $pos->prepare($order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $responseData); + $actual = $this->requestDataMapper->create3DPaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $responseData); $expectedData = $this->getSample3DPaymentRequestData($pos->getOrder(), $pos->getAccount(), $responseData); $this->assertEquals($expectedData, $actual); @@ -189,7 +189,7 @@ public function testGet3DFormData() $order = (object) $this->order; $account = $this->account; $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); - $hash = $this->requestDataMapper->create3DHash($account, $this->pos->getOrder(), 'Auth'); + $hash = $this->requestDataMapper->create3DHash($account, $this->pos->getOrder(), AbstractGateway::TX_PAY); $card = $this->card; $gatewayURL = $this->config['banks'][$this->account->getBank()]['urls']['gateway']['test']; @@ -215,7 +215,7 @@ public function testGet3DFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), $this->pos->getOrder(), - 'Auth', + AbstractGateway::TX_PAY, $gatewayURL )); @@ -230,7 +230,7 @@ public function testGet3DFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), $this->pos->getOrder(), - 'Auth', + AbstractGateway::TX_PAY, $gatewayURL, $card )); @@ -255,7 +255,7 @@ public function testGet3DHostFormData() $pos->setTestMode(true); $pos->prepare($this->order, AbstractGateway::TX_PAY); $order = $pos->getOrder(); - $hash = $this->requestDataMapper->create3DHash($account, $pos->getOrder(), 'Auth'); + $hash = $this->requestDataMapper->create3DHash($account, $pos->getOrder(), AbstractGateway::TX_PAY); $gatewayURL = $this->config['banks'][$account->getBank()]['urls']['gateway_3d_host']['test']; $inputs = [ 'ShopCode' => $account->getClientId(), @@ -279,7 +279,7 @@ public function testGet3DHostFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $pos->getAccount(), $pos->getOrder(), - 'Auth', + AbstractGateway::TX_PAY, $gatewayURL )); } diff --git a/tests/DataMapper/KuveytPosRequestDataMapperTest.php b/tests/DataMapper/KuveytPosRequestDataMapperTest.php index e72fcaf2..a7e66cf8 100644 --- a/tests/DataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/DataMapper/KuveytPosRequestDataMapperTest.php @@ -102,7 +102,7 @@ public function testCompose3DFormData() 'MerchantId' => $account->getClientId(), 'UserName' => $account->getUsername(), 'CustomerId' => $account->getCustomerId(), - 'HashData' => $this->requestDataMapper->create3DHash($account, $order, 'Auth'), + 'HashData' => $this->requestDataMapper->create3DHash($account, $order, AbstractGateway::TX_PAY), 'TransactionType' => 'Sale', 'TransactionSecurity' => 3, 'InstallmentCount' => $order->installment, @@ -122,8 +122,8 @@ public function testCompose3DFormData() $inputs['CardExpireDateMonth'] = '01'; $inputs['CardCVV2'] = $card->getCvv(); } - $txType = 'Sale'; - $result = $this->requestDataMapper->create3DEnrollmentCheckRequestData($account, $order, $txType, $card); + + $result = $this->requestDataMapper->create3DEnrollmentCheckRequestData($account, $order, AbstractGateway::TX_PAY, $card); $this->assertEquals($inputs, $result); } @@ -132,11 +132,10 @@ public function testCompose3DFormData() */ public function testCreate3DPaymentXML() { - $txType = 'Sale'; $responseData = [ 'MD' => '67YtBfBRTZ0XBKnAHi8c/A==', 'VPosMessage' => [ - 'TransactionType' => $txType, + 'TransactionType' => 'Sale', 'InstallmentCount' => '0', 'Amount' => '100', 'DisplayAmount' => '100', @@ -146,9 +145,9 @@ public function testCreate3DPaymentXML() ], ]; $this->pos->prepare($this->order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DPaymentRequestData($this->pos->getAccount(), $this->pos->getOrder(), $txType, $responseData); + $actual = $this->requestDataMapper->create3DPaymentRequestData($this->pos->getAccount(), $this->pos->getOrder(), AbstractGateway::TX_PAY, $responseData); - $expectedData = $this->getSample3DPaymentXMLData($this->pos, $txType, $responseData); + $expectedData = $this->getSample3DPaymentXMLData($this->pos, AbstractGateway::TX_PAY, $responseData); $this->assertEquals($expectedData, $actual); } diff --git a/tests/DataMapper/PayForPosRequestDataMapperTest.php b/tests/DataMapper/PayForPosRequestDataMapperTest.php index a9d7ba88..032cb324 100644 --- a/tests/DataMapper/PayForPosRequestDataMapperTest.php +++ b/tests/DataMapper/PayForPosRequestDataMapperTest.php @@ -109,7 +109,7 @@ public function testCreateNonSecurePaymentRequestData() $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet'); $pos->prepare($order, AbstractGateway::TX_PAY, $card); - $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'Auth', $card); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $card); $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); $this->assertEquals($expectedData, $actual); @@ -131,7 +131,7 @@ public function testCreate3DHash() $expected = 'zmSUxYPhmCj7QOzqpk/28LuE1Oc='; $pos = $this->pos; $pos->prepare($order, AbstractGateway::TX_PAY); - $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), 'Auth'); + $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY); $this->assertSame($expected, $actual); } @@ -197,7 +197,7 @@ public function testGet3DFormData() $order = (object) $this->order; $account = $this->threeDAccount; $this->pos->prepare($this->order, AbstractGateway::TX_PAY); - $hash = $this->requestDataMapper->create3DHash($account, $this->pos->getOrder(), 'Auth'); + $hash = $this->requestDataMapper->create3DHash($account, $this->pos->getOrder(), AbstractGateway::TX_PAY); $card = $this->card; $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway']['test']; @@ -225,7 +225,7 @@ public function testGet3DFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), $this->pos->getOrder(), - 'Auth', + AbstractGateway::TX_PAY, $gatewayURL )); @@ -240,7 +240,7 @@ public function testGet3DFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), $this->pos->getOrder(), - 'Auth', + AbstractGateway::TX_PAY, $gatewayURL, $card )); @@ -264,7 +264,7 @@ public function testGet3DHostFormData() $pos->setTestMode(true); $pos->prepare($this->order, AbstractGateway::TX_PAY); $order = $pos->getOrder(); - $hash = $this->requestDataMapper->create3DHash($account, $order, 'Auth'); + $hash = $this->requestDataMapper->create3DHash($account, $order, AbstractGateway::TX_PAY); $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway_3d_host']['test']; $inputs = [ 'MbrId' => '5', @@ -290,7 +290,7 @@ public function testGet3DHostFormData() $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $pos->getAccount(), $pos->getOrder(), - 'Auth', + AbstractGateway::TX_PAY, $gatewayURL )); } diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php index fb825e4a..bf73ca62 100644 --- a/tests/DataMapper/PosNetRequestDataMapperTest.php +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -159,7 +159,7 @@ public function testCreateNonSecurePaymentRequestData() $card = CreditCardFactory::create($pos, '5555444433332222', '22', '01', '123', 'ahmet'); $pos->prepare($order, AbstractGateway::TX_PAY, $card); - $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), 'sale', $card); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY, $card); $expectedData = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $pos->getCard()); $this->assertEquals($expectedData, $actual); diff --git a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php index 3b9a57c2..f8d7700b 100644 --- a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php +++ b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php @@ -100,7 +100,7 @@ public function testCreate3DPaymentRequestData() $order['amount'] = 10.1; $pos = $this->pos; $pos->prepare($order, AbstractGateway::TX_PAY, $this->card); - $txType = 'Sale'; + $txType = AbstractGateway::TX_PAY; $gatewayResponse = [ 'Eci' => (string) rand(1, 100), 'Cavv' => (string) rand(1, 100), @@ -153,9 +153,9 @@ public function testCreateNonSecurePaymentRequestData() { $pos = $this->pos; $order = $this->order; - $txType = 'Sale'; + $txType = AbstractGateway::TX_PAY; $order['amount'] = 1000; - $pos->prepare($order, AbstractGateway::TX_PAY, $this->card); + $pos->prepare($order, $txType, $this->card); $expectedValue = $this->getSampleNonSecurePaymentRequestData($pos->getAccount(), $order, $txType, $pos->getCard()); $actualData = $this->requestDataMapper->createNonSecurePaymentRequestData($pos->getAccount(), $pos->getOrder(), $txType, $pos->getCard()); @@ -264,7 +264,7 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord 'MerchantId' => $account->getClientId(), 'Password' => $account->getPassword(), 'TerminalNo' => $account->getTerminalId(), - 'TransactionType' => $txType, + 'TransactionType' => $this->requestDataMapper->mapTxType($txType), 'OrderId' => $order->id, 'ClientIp' => $order->ip, 'CurrencyCode' => '949', @@ -344,7 +344,7 @@ private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $accoun 'MerchantId' => $account->getClientId(), 'Password' => $account->getPassword(), 'TerminalNo' => $account->getTerminalId(), - 'TransactionType' => $txType, + 'TransactionType' => $this->requestDataMapper->mapTxType($txType), 'OrderId' => $order['id'], 'CurrencyAmount' => '1000.00', 'CurrencyCode' => 949, diff --git a/tests/Gateways/EstPostTest.php b/tests/Gateways/EstPostTest.php index 818335fd..4552207b 100644 --- a/tests/Gateways/EstPostTest.php +++ b/tests/Gateways/EstPostTest.php @@ -125,7 +125,8 @@ public function testMake3DPaymentAuthFail() $this->assertSame('30', $result['year']); $this->assertSame('1.01', $result['amount']); $this->assertSame('TRY', $result['currency']); - $this->assertSame('Auth', $result['transaction_type']); + $this->assertSame('Auth', $result['transaction']); + $this->assertSame(AbstractGateway::TX_PAY, $result['transaction_type']); $this->assertSame(null, $result['auth_code']); $this->assertSame(null, $result['host_ref_num']); $this->assertSame(null, $result['status_detail']); @@ -166,7 +167,8 @@ public function testMake3DPaymentAuthSuccessAndPaymentFail() $this->assertSame('30', $result['year']); $this->assertSame('1.01', $result['amount']); $this->assertSame('TRY', $result['currency']); - $this->assertSame('Auth', $result['transaction_type']); + $this->assertSame('Auth', $result['transaction']); + $this->assertSame(AbstractGateway::TX_PAY, $result['transaction_type']); $this->assertSame(null, $result['auth_code']); $this->assertSame(null, $result['host_ref_num']); $this->assertSame('general_error', $result['status_detail']); @@ -207,7 +209,8 @@ public function testMake3DPaymentAuthSuccessAndPaymentSuccess() $this->assertSame('30', $result['year']); $this->assertSame('1.01', $result['amount']); $this->assertSame('TRY', $result['currency']); - $this->assertSame('Auth', $result['transaction_type']); + $this->assertSame('Auth', $result['transaction']); + $this->assertSame(AbstractGateway::TX_PAY, $result['transaction_type']); $this->assertSame('P65781', $result['auth_code']); $this->assertSame('210700616852', $result['host_ref_num']); $this->assertSame('approved', $result['status_detail']); @@ -239,7 +242,8 @@ public function testMake3DHostPaymentSuccess() $this->assertSame('30', $result['year']); $this->assertSame('1.01', $result['amount']); $this->assertSame('TRY', $result['currency']); - $this->assertSame('Auth', $result['transaction_type']); + $this->assertSame('Auth', $result['transaction']); + $this->assertSame(AbstractGateway::TX_PAY, $result['transaction_type']); $this->assertSame(null, $result['auth_code']); $this->assertSame(null, $result['host_ref_num']); $this->assertSame(null, $result['status_detail']); @@ -271,7 +275,8 @@ public function testMake3DHostPaymentFail() $this->assertSame('30', $result['year']); $this->assertSame('1.01', $result['amount']); $this->assertSame('TRY', $result['currency']); - $this->assertSame('Auth', $result['transaction_type']); + $this->assertSame('Auth', $result['transaction']); + $this->assertSame(AbstractGateway::TX_PAY, $result['transaction_type']); $this->assertSame(null, $result['auth_code']); $this->assertSame(null, $result['host_ref_num']); $this->assertSame(null, $result['status_detail']); diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index 3e1b249a..a89ac315 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -228,7 +228,7 @@ public function testMap3DPaymentData3DFail() 'id' => null, 'trans_id' => null, 'host_ref_num' => null, - 'transaction_type' => 'Sale', + 'transaction_type' => AbstractGateway::TX_PAY, 'transaction' => 'Sale', 'proc_return_code' => null, 'code' => null, From 567425af787f31706b9c914474736f6117b32df4 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 6 May 2022 22:25:31 +0200 Subject: [PATCH 25/40] EstPos fix installment not working for 3D Secure --- src/DataMapper/EstPosRequestDataMapper.php | 45 ++++++------------- src/Gateways/EstPos.php | 2 +- .../EstPosRequestDataMapperTest.php | 14 +++--- tests/Gateways/EstPostTest.php | 19 ++++++++ 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index e128a865..764f5654 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -206,15 +206,10 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'rnd' => $order->rand, 'lang' => $this->getLang($account, $order), 'currency' => $this->mapCurrency($order->currency), + 'taksit' => $order->installment, + 'islemtipi' => $this->mapTxType($txType), ]; - if ($account->getModel() === AbstractGateway::MODEL_3D_PAY || $account->getModel() === AbstractGateway::MODEL_3D_HOST) { - $inputs = array_merge($inputs, [ - 'islemtipi' => $this->mapTxType($txType), - 'taksit' => $order->installment, - ]); - } - if ($card) { $inputs['cardType'] = $this->cardTypeMapping[$card->getType()]; $inputs['pan'] = $card->getNumber(); @@ -234,30 +229,18 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx */ public function create3DHash(AbstractPosAccount $account, $order, string $txType): string { - $hashData = []; - if ($account->getModel() === AbstractGateway::MODEL_3D_SECURE) { - $hashData = [ - $account->getClientId(), - $order->id, - $order->amount, - $order->success_url, - $order->fail_url, - $order->rand, - $account->getStoreKey(), - ]; - } elseif ($account->getModel() === AbstractGateway::MODEL_3D_PAY || $account->getModel() === AbstractGateway::MODEL_3D_HOST) { - $hashData = [ - $account->getClientId(), - $order->id, - $order->amount, - $order->success_url, - $order->fail_url, - $this->mapTxType($txType), - $order->installment, - $order->rand, - $account->getStoreKey(), - ]; - } + $hashData = [ + $account->getClientId(), + $order->id, + $order->amount, + $order->success_url, + $order->fail_url, + $this->mapTxType($txType), + $order->installment, + $order->rand, + $account->getStoreKey(), + ]; + $hashStr = implode(static::HASH_SEPARATOR, $hashData); return $this->hashString($hashStr); diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 99002017..1aa54ba6 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -638,7 +638,7 @@ protected function mapHistoryResponse($rawResponseData) protected function preparePaymentOrder(array $order) { // Installment - $installment = 0; + $installment = ''; if (isset($order['installment']) && $order['installment'] > 1) { $installment = (int) $order['installment']; } diff --git a/tests/DataMapper/EstPosRequestDataMapperTest.php b/tests/DataMapper/EstPosRequestDataMapperTest.php index a5461cea..0f88900f 100644 --- a/tests/DataMapper/EstPosRequestDataMapperTest.php +++ b/tests/DataMapper/EstPosRequestDataMapperTest.php @@ -130,7 +130,7 @@ public function testCreate3DHashFor3DSecure() $this->order['rand'] = 'rand'; $pos = $this->pos; - $expected = 'mJReAoQNtx0G+nWUGA/BHLx/+BI='; + $expected = 'S7UxUAohxaxzl35WxHyDfuQx0sg='; $pos->prepare($this->order, AbstractGateway::TX_PAY); $actual = $this->requestDataMapper->create3DHash($pos->getAccount(), $pos->getOrder(), AbstractGateway::TX_PAY); $this->assertEquals($expected, $actual); @@ -152,7 +152,7 @@ public function testCreate3DHashForNon3DSecure() 'VnM5WZ3sGrPusmWP' ); $pos = PosFactory::createPosGateway($account); - $expected = 'zW2HEQR/H0mpo1jrztIgmIPFFEU='; + $expected = 'zQJGquP0/PXt6LeutjN1Qxq32Zg='; $pos->prepare($this->order, AbstractGateway::TX_PAY); $actual = $this->requestDataMapper->create3DHash($account, $pos->getOrder(), AbstractGateway::TX_PAY); $this->assertEquals($expected, $actual); @@ -237,7 +237,7 @@ public function testCreate3DPaymentRequestDataRecurringOrder() 'user_id' => '1535', 'ip' => '192.168.1.0', 'amount' => 100.01, - 'installment' => '0', + 'installment' => '', 'currency' => 'TRY', 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', @@ -288,6 +288,8 @@ public function testGet3DFormData() 'rnd' => $this->order['rand'], 'lang' => 'tr', 'currency' => 949, + 'islemtipi' => 'Auth', + 'taksit' => '', ]; $form = [ 'gateway' => $gatewayURL, @@ -356,7 +358,7 @@ public function testGet3DHostFormData() 'lang' => 'tr', 'currency' => '949', 'islemtipi' => 'Auth', - 'taksit' => $this->order['installment'], + 'taksit' => '', ]; $form = [ 'gateway' => $gatewayURL, @@ -430,7 +432,7 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord 'UserId' => isset($order->user_id) ? $order->user_id : null, 'Total' => 100.01, 'Currency' => '949', - 'Taksit' => '0', + 'Taksit' => '', 'Number' => $responseData['md'], 'PayerTxnId' => $responseData['xid'], 'PayerSecurityLevel' => $responseData['eci'], @@ -492,7 +494,7 @@ private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $accoun 'UserId' => $order->user_id ?? null, 'Total' => '100.25', 'Currency' => '949', - 'Taksit' => '0', + 'Taksit' => '', 'Number' => $card->getNumber(), 'Expires' => '01/22', 'Cvv2Val' => $card->getCvv(), diff --git a/tests/Gateways/EstPostTest.php b/tests/Gateways/EstPostTest.php index 4552207b..92af8d4c 100644 --- a/tests/Gateways/EstPostTest.php +++ b/tests/Gateways/EstPostTest.php @@ -84,6 +84,25 @@ public function testPrepare() $this->assertEquals($this->card, $this->pos->getCard()); } + /** + * @param string|null $installment + * @param string $expected + * + * @testWith ["", ""] + * ["0", ""] + * ["1", ""] + * ["2", "2"] + * + * @return void + */ + public function testPreparePaymentOrder(?string $installment, string $expected) + { + $this->order['installment'] = $installment; + $this->pos->prepare($this->order, AbstractGateway::TX_PAY); + $preparedOrder = $this->pos->getOrder(); + $this->assertEquals($expected, $preparedOrder->installment); + } + /** * @return void */ From db5f56bebf1d8f733e2fe13d5684b1648653892d Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 6 May 2022 22:30:06 +0200 Subject: [PATCH 26/40] EstPos fix undefined index error on invalid hash request --- src/Gateways/EstPos.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 1aa54ba6..653968c1 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -337,15 +337,20 @@ protected function map3DPaymentData($raw3DAuthResponseData, $rawPaymentResponseD 'year' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Year'], 'amount' => $raw3DAuthResponseData['amount'], 'currency' => array_search($raw3DAuthResponseData['currency'], $this->requestDataMapper->getCurrencyMappings()), - 'eci' => $raw3DAuthResponseData['eci'], + 'eci' => null, 'tx_status' => null, - 'cavv' => $raw3DAuthResponseData['cavv'], + 'cavv' => null, 'xid' => $raw3DAuthResponseData['oid'], 'md_error_message' => 'Authenticated' !== $raw3DAuthResponseData['mdErrorMsg'] ? $raw3DAuthResponseData['mdErrorMsg'] : null, 'name' => $raw3DAuthResponseData['firmaadi'], '3d_all' => $raw3DAuthResponseData, ]; + if ('Authenticated' === $raw3DAuthResponseData['mdErrorMsg']) { + $threeDResponse['eci'] = $raw3DAuthResponseData['eci']; + $threeDResponse['cavv'] = $raw3DAuthResponseData['cavv']; + } + return (object) $this->mergeArraysPreferNonNullValues($threeDResponse, $paymentResponseData); } From 15c4170b51f050c5bd37c5720ffe6bf6dda79c44 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 7 May 2022 19:03:02 +0200 Subject: [PATCH 27/40] posnet added test for check3DHash --- src/Gateways/PosNet.php | 74 +++++++++++++++++------------------ tests/Gateways/PosNetTest.php | 65 ++++++++++++++++++++++++------ 2 files changed, 90 insertions(+), 49 deletions(-) diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 70a2d2af..d368baae 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -308,6 +308,43 @@ public function createRefundXML() return $this->createXML($requestData); } + /** + * Check 3D Hash + * + * @param array $data + * + * @return bool + */ + public function check3DHash(array $data): bool + { + if (!($this->crypt instanceof PosNetCrypt)) { + return false; + } + $decryptedString = $this->crypt->decrypt($data['MerchantPacket'], $this->account->getStoreKey()); + if (!$decryptedString) { + return false; + } + $decryptedData = explode(';', $decryptedString); + + $originalData = array_map('strval', [ + $this->account->getClientId(), + $this->account->getTerminalId(), + $this->order->amount, + ((int) $this->order->installment), + $this->requestDataMapper::formatOrderId($this->order->id), + ]); + + $decryptedDataList = array_map('strval', [ + $decryptedData[0], + $decryptedData[1], + $decryptedData[2], + ((int) $decryptedData[3]), + $decryptedData[4], + ]); + + return $originalData === $decryptedDataList; + } + /** * Get ProcReturnCode * @@ -330,43 +367,6 @@ protected function getStatusDetail(): ?string return isset($this->codes[$procReturnCode]) ? (string) $this->codes[$procReturnCode] : null; } - - /** - * Check 3D Hash - * - * @param array $data - * - * @return bool - */ - protected function check3DHash(array $data): bool - { - if ($this->crypt instanceof PosNetCrypt) { - $decryptedString = $this->crypt->decrypt($data['MerchantPacket'], $this->account->getStoreKey()); - - $decryptedData = explode(';', $decryptedString); - - $originalData = array_map('strval', [ - $this->account->getClientId(), - $this->account->getTerminalId(), - $this->order->amount, - ((int) $this->order->installment), - $this->requestDataMapper::formatOrderId($this->order->id), - ]); - - $decryptedDataList = array_map('strval', [ - $decryptedData[0], - $decryptedData[1], - $decryptedData[2], - ((int) $decryptedData[3]), - $decryptedData[4], - ]); - - return $originalData === $decryptedDataList; - } - - return false; - } - /** * @inheritDoc */ diff --git a/tests/Gateways/PosNetTest.php b/tests/Gateways/PosNetTest.php index 239d24cb..68d90b8c 100644 --- a/tests/Gateways/PosNetTest.php +++ b/tests/Gateways/PosNetTest.php @@ -112,18 +112,6 @@ public function testGet3DFormDataOosTransactionFail() $posMock->get3DFormData(); } - /** - * @return string[] - */ - private function getSampleOoTransactionFailResponseData(): array - { - return [ - 'approved' => '0', - 'respCode' => '0003', - 'respText' => '148 MID,TID,IP HATALI:89.244.149.137', - ]; - } - public function testVerifyResponseMAC() { $newOrder = $this->order; @@ -160,4 +148,57 @@ public function testVerifyResponseMAC() ]; $this->assertFalse($pos->verifyResponseMAC($pos->getAccount(), $pos->getOrder(), $data)); } + + public function testCheck3DHash() + { + $account = AccountFactory::createPosNetAccount( + 'yapikredi', + '6706022701', + 'XXXXXX', + 'XXXXXX', + '67002706', + '27426', + AbstractGateway::MODEL_3D_SECURE, + '10,10,10,10,10,10,10,10' + ); + + $pos = PosFactory::createPosGateway($account); + + $data = [ + 'MerchantPacket' => 'F57E38055C280283044612E7338A314758CE0BB13FE9CFF2D1ACD415A979C1C65AD1FA664E561809F63262552496B491378DE688980EDFEF32785CB8090E0F3F618D560B4C2C089C7B9FBA8F91F1F4231D6725ECF8D94B18B0AA9EA206083D94BA1315DCC950E7E5BED2B3B5A1571C3E761E2364E590CC6BB95BF4F1165208FA55CE99BDE6C7ACDEFB5A2A6F16B6C3838B9876F00EDF1E7261B626532EE81C40C9DE94588ED36FC4D2E639FA89152D1590A0031416BA8A31A1300EE37E31BD54B6ADA2FF7D4D58EA0A4A1CC7', + ]; + $order = [ + 'id' => 'YKB_0000080603153823', + 'amount' => 56.96, + 'currency' => 'TRY', + 'installment' => 0, + ]; + $pos->prepare($order, AbstractGateway::TX_PAY); + $result = $pos->check3DHash($data); + $this->assertTrue($result); + + $order['amount'] = 56.97; + $pos->prepare($order, AbstractGateway::TX_PAY); + $result = $pos->check3DHash($data); + $this->assertFalse($result); + + $order['amount'] = 56.96; + $pos->prepare($order, AbstractGateway::TX_PAY); + $data['MerchantPacket'] = $data['MerchantPacket'].'2'; + $result = $pos->check3DHash($data); + $this->assertFalse($result); + } + + + /** + * @return string[] + */ + private function getSampleOoTransactionFailResponseData(): array + { + return [ + 'approved' => '0', + 'respCode' => '0003', + 'respText' => '148 MID,TID,IP HATALI:89.244.149.137', + ]; + } } From 763909f81bbc3d22eb75334dbf96766c587e7a6c Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 7 May 2022 20:32:00 +0200 Subject: [PATCH 28/40] move installment mapping into request data mappers --- src/DataMapper/AbstractRequestDataMapper.php | 8 ++++- src/DataMapper/EstPosRequestDataMapper.php | 16 ++++++--- .../GarantiPosRequestDataMapper.php | 24 ++++++++----- src/DataMapper/InterPosRequestDataMapper.php | 16 ++++++--- src/DataMapper/KuveytPosRequestDataMapper.php | 10 +++++- src/DataMapper/PayForPosRequestDataMapper.php | 14 ++++++-- src/DataMapper/PosNetRequestDataMapper.php | 35 +++++++++---------- .../VakifBankPosRequestDataMapper.php | 12 +++++-- src/Gateways/EstPos.php | 10 ++---- src/Gateways/GarantiPos.php | 15 +++----- src/Gateways/InterPos.php | 10 ++---- src/Gateways/KuveytPos.php | 10 ++---- src/Gateways/PayForPos.php | 13 ++----- src/Gateways/PosNet.php | 20 +++-------- src/Gateways/VakifBankPos.php | 13 ++----- .../EstPosRequestDataMapperTest.php | 19 +++++++++- .../GarantiPosRequestDataMapperTest.php | 25 ++++++++++--- .../InterPosRequestDataMapperTest.php | 23 ++++++++++-- .../KuveytPosRequestDataMapperTest.php | 17 +++++++++ .../PayForPosRequestDataMapperTest.php | 17 +++++++++ .../PosNetRequestDataMapperTest.php | 18 +++++++--- .../VakifBankPosRequestDataMapperTest.php | 21 +++++++++-- tests/Gateways/EstPostTest.php | 19 ---------- tests/Gateways/GarantiPosTest.php | 2 +- 24 files changed, 237 insertions(+), 150 deletions(-) diff --git a/src/DataMapper/AbstractRequestDataMapper.php b/src/DataMapper/AbstractRequestDataMapper.php index 9376014f..42e59cf5 100644 --- a/src/DataMapper/AbstractRequestDataMapper.php +++ b/src/DataMapper/AbstractRequestDataMapper.php @@ -10,7 +10,6 @@ use Mews\Pos\Gateways\AbstractGateway; /** - * todo move installment mapping to here from all gateways * AbstractRequestDataMapper */ abstract class AbstractRequestDataMapper @@ -258,6 +257,13 @@ public function getRecurringOrderFrequencyMapping(): array return $this->recurringOrderFrequencyMapping; } + /** + * @param int|null $installment + * + * @return int|string + */ + abstract public function mapInstallment(?int $installment); + /** * @param string $str * diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index 764f5654..ec52d332 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -65,7 +65,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'UserId' => $order->user_id ?? null, 'Total' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), - 'Taksit' => $order->installment, + 'Taksit' => $this->mapInstallment($order->installment), 'Number' => $responseData['md'], 'PayerTxnId' => $responseData['xid'], 'PayerSecurityLevel' => $responseData['eci'], @@ -106,7 +106,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'UserId' => $order->user_id ?? null, 'Total' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), - 'Taksit' => $order->installment, + 'Taksit' => $this->mapInstallment($order->installment), 'Number' => $card->getNumber(), 'Expires' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), 'Cvv2Val' => $card->getCvv(), @@ -206,7 +206,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'rnd' => $order->rand, 'lang' => $this->getLang($account, $order), 'currency' => $this->mapCurrency($order->currency), - 'taksit' => $order->installment, + 'taksit' => $this->mapInstallment($order->installment), 'islemtipi' => $this->mapTxType($txType), ]; @@ -236,7 +236,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->success_url, $order->fail_url, $this->mapTxType($txType), - $order->installment, + $this->mapInstallment($order->installment), $order->rand, $account->getStoreKey(), ]; @@ -246,6 +246,14 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType return $this->hashString($hashStr); } + /** + * @inheritdoc + */ + public function mapInstallment(?int $installment) + { + return $installment > 1 ? $installment : ''; + } + /** * @param AbstractPosAccount $account * diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index 3b8ed43c..0ab2dc95 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -72,7 +72,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, ], 'Transaction' => [ 'Type' => $responseData['txntype'], - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => $this->mapInstallment($order->installment), 'Amount' => $responseData['txnamount'], 'CurrencyCode' => $responseData['txncurrencycode'], 'CardholderPresentCode' => '13', //13 for 3D secure payment @@ -117,7 +117,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ ], 'Transaction' => [ 'Type' => $this->mapTxType($txType), - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => $this->mapInstallment($order->installment), 'Amount' => $order->amount, 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', @@ -183,7 +183,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar ], 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_STATUS), - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => $this->mapInstallment($order->installment), 'Amount' => $order->amount, 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', @@ -214,7 +214,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar ], 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_CANCEL), - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => $this->mapInstallment($order->installment), 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', @@ -246,7 +246,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar ], 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_REFUND), - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => $this->mapInstallment($order->installment), 'Amount' => $order->amount, 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', @@ -278,7 +278,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar ], 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_HISTORY), - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => $this->mapInstallment($order->installment), 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', @@ -306,7 +306,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'txntype' => $this->mapTxType($txType), 'txnamount' => $order->amount, 'txncurrencycode' => $this->mapCurrency($order->currency), - 'txninstallmentcount' => $order->installment, + 'txninstallmentcount' => $this->mapInstallment($order->installment), 'orderid' => $order->id, 'successurl' => $order->success_url, 'errorurl' => $order->fail_url, @@ -342,7 +342,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->success_url, $order->fail_url, $this->mapTxType($txType), - $order->installment, + $this->mapInstallment($order->installment), $account->getStoreKey(), $this->createSecurityData($account, $txType), ]; @@ -373,6 +373,14 @@ public function createHash(GarantiPosAccount $account, $order, string $txType, ? return $this->hashString(implode(static::HASH_SEPARATOR, $map)); } + /** + * @inheritdoc + */ + public function mapInstallment(?int $installment) + { + return $installment > 1 ? $installment : ''; + } + /** * Amount Formatter * converts 100 to 10000, or 10.01 to 1001 diff --git a/src/DataMapper/InterPosRequestDataMapper.php b/src/DataMapper/InterPosRequestDataMapper.php index fa2e2277..29b6eab9 100644 --- a/src/DataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/InterPosRequestDataMapper.php @@ -62,7 +62,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, 'OrderId' => $order->id, 'PurchAmount' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => $this->mapInstallment($order->installment), 'MD' => $responseData['MD'], 'PayerTxnId' => $responseData['PayerTxnId'], 'Eci' => $responseData['Eci'], @@ -86,7 +86,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'OrderId' => $order->id, 'PurchAmount' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => $this->mapInstallment($order->installment), 'MOTO' => self::MOTO, 'Lang' => $this->getLang($account, $order), ]; @@ -201,7 +201,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'Rnd' => $order->rand, 'Lang' => $this->getLang($account, $order), 'Currency' => $this->mapCurrency($order->currency), - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => $this->mapInstallment($order->installment), ]; if ($card) { @@ -229,7 +229,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->success_url, $order->fail_url, $this->mapTxType($txType), - $order->installment, + $this->mapInstallment($order->installment), $order->rand, $account->getStoreKey(), ]; @@ -238,4 +238,12 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType return $this->hashString($hashStr); } + + /** + * @inheritdoc + */ + public function mapInstallment(?int $installment) + { + return $installment > 1 ? $installment : ''; + } } diff --git a/src/DataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/KuveytPosRequestDataMapper.php index a1d97e8a..7fdee759 100644 --- a/src/DataMapper/KuveytPosRequestDataMapper.php +++ b/src/DataMapper/KuveytPosRequestDataMapper.php @@ -121,7 +121,7 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $account, $o 'HashData' => $hash, 'TransactionType' => $this->mapTxType($txType), 'TransactionSecurity' => $this->secureTypeMappings[$account->getModel()], - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => $this->mapInstallment($order->installment), 'Amount' => self::amountFormat($order->amount), //DisplayAmount: Amount değeri ile aynı olacak şekilde gönderilmelidir. 'DisplayAmount' => self::amountFormat($order->amount), @@ -225,6 +225,14 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar throw new NotImplementedException(); } + /** + * @inheritdoc + */ + public function mapInstallment(?int $installment) + { + return $installment > 1 ? $installment : 0; + } + /** * @param AbstractPosAccount $account * @param $order diff --git a/src/DataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/PayForPosRequestDataMapper.php index 7486421e..2863f410 100644 --- a/src/DataMapper/PayForPosRequestDataMapper.php +++ b/src/DataMapper/PayForPosRequestDataMapper.php @@ -75,7 +75,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'TxnType' => $this->mapTxType($txType), 'PurchAmount' => $order->amount, 'Currency' => $this->mapCurrency($order->currency), - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => $this->mapInstallment($order->installment), 'Lang' => $this->getLang($account, $order), 'CardHolderName' => $card->getHolderName(), 'Pan' => $card->getNumber(), @@ -199,7 +199,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'SecureType' => $this->secureTypeMappings[$account->getModel()], 'TxnType' => $this->mapTxType($txType), 'PurchAmount' => $order->amount, - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => $this->mapInstallment($order->installment), 'Currency' => $this->mapCurrency($order->currency), 'OkUrl' => $order->success_url, 'FailUrl' => $order->fail_url, @@ -232,7 +232,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $order->success_url, $order->fail_url, $this->mapTxType($txType), - $order->installment, + $this->mapInstallment($order->installment), $order->rand, $account->getStoreKey(), ]; @@ -240,4 +240,12 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType return $this->hashString($hashStr); } + + /** + * @inheritdoc + */ + public function mapInstallment(?int $installment) + { + return $installment > 1 ? $installment : 0; + } } diff --git a/src/DataMapper/PosNetRequestDataMapper.php b/src/DataMapper/PosNetRequestDataMapper.php index e2d56c2f..e97bdb59 100644 --- a/src/DataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/PosNetRequestDataMapper.php @@ -91,7 +91,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'tranDateRequired' => '1', strtolower($this->mapTxType($txType)) => [ 'orderID' => self::formatOrderId($order->id), - 'installment' => $order->installment, + 'installment' => $this->mapInstallment($order->installment), 'amount' => $order->amount, 'currencyCode' => $this->mapCurrency($order->currency), 'ccno' => $card->getNumber(), @@ -122,7 +122,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'hostLogKey' => $order->host_ref_num, 'amount' => $order->amount, 'currencyCode' => $this->mapCurrency($order->currency), - 'installment' => $order->installment, + 'installment' => $this->mapInstallment($order->installment), ], ]; } @@ -267,7 +267,7 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $account, 'cvc' => $card->getCvv(), 'amount' => $order->amount, 'currencyCode' => $this->mapCurrency($order->currency), - 'installment' => $order->installment, + 'installment' => $this->mapInstallment($order->installment), 'XID' => self::formatOrderId($order->id), 'cardHolderName' => $card->getHolderName(), 'tranType' => $txType, @@ -351,22 +351,6 @@ public static function amountFormat($amount): int return round($amount, 2) * 100; } - /** - * formats installment in 00, 02, 06 format - * - * @param int|string $installment - * - * @return string - */ - public static function formatInstallment($installment): string - { - if ($installment > 1) { - return str_pad($installment, 2, '0', STR_PAD_LEFT); - } - - return '00'; - } - /** * Get PrefixedOrderId * To check the status of an order or cancel/refund order Yapikredi @@ -407,4 +391,17 @@ public static function formatOrderId(string $orderId, int $padLength = null): st return str_pad($orderId, $padLength, '0', STR_PAD_LEFT); } + + /** + * formats installment in 00, 02, 06 format + * @inheritdoc + */ + public function mapInstallment(?int $installment) + { + if ($installment > 1) { + return str_pad($installment, 2, '0', STR_PAD_LEFT); + } + + return '00'; + } } diff --git a/src/DataMapper/VakifBankPosRequestDataMapper.php b/src/DataMapper/VakifBankPosRequestDataMapper.php index 5305d6d4..b53315a4 100644 --- a/src/DataMapper/VakifBankPosRequestDataMapper.php +++ b/src/DataMapper/VakifBankPosRequestDataMapper.php @@ -77,7 +77,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, ]; if ($order->installment) { - $requestData['NumberOfInstallments'] = $order->installment; + $requestData['NumberOfInstallments'] = $this->mapInstallment($order->installment); } return $requestData; @@ -107,7 +107,7 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $account, 'IsRecurring' => 'false', ]; if ($order->installment) { - $requestData['InstallmentCount'] = $order->installment; + $requestData['InstallmentCount'] = $this->mapInstallment($order->installment); } if (isset($order->extraData)) { $requestData['SessionInfo'] = $order->extraData; @@ -267,4 +267,12 @@ public static function amountFormat(float $amount): string { return number_format($amount, 2, '.', ''); } + + /** + * @inheritdoc + */ + public function mapInstallment(?int $installment) + { + return $installment > 1 ? $installment : 0; + } } diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 653968c1..69436b5a 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -642,20 +642,14 @@ protected function mapHistoryResponse($rawResponseData) */ protected function preparePaymentOrder(array $order) { - // Installment - $installment = ''; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = (int) $order['installment']; - } - if (isset($order['recurringFrequency'])) { $order['recurringFrequencyType'] = $this->mapRecurringFrequency($order['recurringFrequencyType']); } // Order return (object) array_merge($order, [ - 'installment' => $installment, - 'currency' => $order['currency'], + 'installment' => $order['installment'] ?? 0, + 'currency' => $order['currency'] ?? 'TRY', ]); } diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 32a80070..2d020881 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -522,16 +522,9 @@ protected function getStatusDetail(): ?string */ protected function preparePaymentOrder(array $order) { - // Installment - $installment = ''; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = $order['installment']; - } - - // Order return (object) array_merge($order, [ - 'installment' => $installment, - 'currency' => $order['currency'], + 'installment' => $order['installment'] ?? 0, + 'currency' => $order['currency'] ?? 'TRY', 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', @@ -564,7 +557,7 @@ protected function prepareStatusOrder(array $order) 'currency' => $order['currency'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', - 'installment' => '', + 'installment' => 0, ]; } @@ -588,7 +581,7 @@ protected function prepareCancelOrder(array $order) 'ref_ret_num' => $order['ref_ret_num'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', - 'installment' => '', + 'installment' => 0, ]; } diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index 5df690b3..a765d318 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -463,15 +463,9 @@ protected function mapHistoryResponse($rawResponseData) */ protected function preparePaymentOrder(array $order) { - // Installment - $installment = ''; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = (int) $order['installment']; - } - return (object) array_merge($order, [ - 'installment' => $installment, - 'currency' => $order['currency'], + 'installment' => $order['installment'] ?? 0, + 'currency' => $order['currency'] ?? 'TRY', ]); } diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index 817d2f5c..4ebcb1bb 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -350,15 +350,9 @@ protected function mapHistoryResponse($rawResponseData) */ protected function preparePaymentOrder(array $order) { - // Installment - $installment = 0; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = (int) $order['installment']; - } - return (object) array_merge($order, [ - 'installment' => $installment, - 'currency' => $order['currency'], + 'installment' => $order['installment'] ?? 0, + 'currency' => $order['currency'] ?? 'TRY', ]); } diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index 13207d19..1a2904a5 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -514,18 +514,9 @@ protected function mapHistoryResponse($rawResponseData) */ protected function preparePaymentOrder(array $order) { - // Installment - $installment = 0; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = (int) $order['installment']; - } - - $currency = $order['currency'] ?? 'TRY'; - - // Order return (object) array_merge($order, [ - 'installment' => $installment, - 'currency' => $currency, + 'installment' => $order['installment'] ?? 0, + 'currency' => $order['currency'] ?? 'TRY', ]); } diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index d368baae..27c74828 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -330,7 +330,7 @@ public function check3DHash(array $data): bool $this->account->getClientId(), $this->account->getTerminalId(), $this->order->amount, - ((int) $this->order->installment), + $this->order->installment, $this->requestDataMapper::formatOrderId($this->order->id), ]); @@ -705,15 +705,9 @@ protected function mapHistoryResponse($rawResponseData) */ protected function preparePaymentOrder(array $order) { - // Installment - $installment = 0; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = $order['installment']; - } - return (object) array_merge($order, [ 'id' => $this->requestDataMapper::formatOrderId($order['id']), - 'installment' => $this->requestDataMapper::formatInstallment($installment), + 'installment' => $order['installment'] ?? 0, 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'currency' => $order['currency'], ]); @@ -724,17 +718,11 @@ protected function preparePaymentOrder(array $order) */ protected function preparePostPaymentOrder(array $order) { - // Installment - $installment = 0; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = $order['installment']; - } - return (object) [ 'id' => $this->requestDataMapper::formatOrderId($order['id']), 'amount' => $this->requestDataMapper::amountFormat($order['amount']), - 'installment' => $this->requestDataMapper::formatInstallment($installment), - 'currency' => $order['currency'], + 'installment' => $order['installment'] ?? 0, + 'currency' => $order['currency'] ?? 'TRY', 'host_ref_num' => $order['host_ref_num'], ]; } diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 6a73f988..ca8b2566 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -399,18 +399,9 @@ protected function mapHistoryResponse($rawResponseData) */ protected function preparePaymentOrder(array $order) { - // Installment - $installment = 0; - if (isset($order['installment']) && $order['installment'] > 1) { - $installment = (int) $order['installment']; - } - - $currency = $order['currency'] ?? 'TRY'; - - // Order return (object) array_merge($order, [ - 'installment' => $installment, - 'currency' => $currency, + 'installment' => $order['installment'] ?? 0, + 'currency' => $order['currency'] ?? 'TRY', 'amount' => $order['amount'], ]); } diff --git a/tests/DataMapper/EstPosRequestDataMapperTest.php b/tests/DataMapper/EstPosRequestDataMapperTest.php index 0f88900f..829e524a 100644 --- a/tests/DataMapper/EstPosRequestDataMapperTest.php +++ b/tests/DataMapper/EstPosRequestDataMapperTest.php @@ -88,6 +88,23 @@ public function testMapCurrency() $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); } + /** + * @param string|int|null $installment + * @param string|int $expected + * + * @testWith ["0", ""] + * ["1", ""] + * ["2", 2] + * [2, 2] + * + * @return void + */ + public function testMapInstallment($installment, $expected) + { + $actual = $this->requestDataMapper->mapInstallment($installment); + $this->assertSame($expected, $actual); + } + /** * @return void */ @@ -237,7 +254,7 @@ public function testCreate3DPaymentRequestDataRecurringOrder() 'user_id' => '1535', 'ip' => '192.168.1.0', 'amount' => 100.01, - 'installment' => '', + 'installment' => 0, 'currency' => 'TRY', 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', diff --git a/tests/DataMapper/GarantiPosRequestDataMapperTest.php b/tests/DataMapper/GarantiPosRequestDataMapperTest.php index 39a3f7ba..5cfdfef6 100644 --- a/tests/DataMapper/GarantiPosRequestDataMapperTest.php +++ b/tests/DataMapper/GarantiPosRequestDataMapperTest.php @@ -92,6 +92,23 @@ public function testMapCurrency() $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); } + /** + * @param string|int|null $installment + * @param string|int $expected + * + * @testWith ["0", ""] + * ["1", ""] + * ["2", 2] + * [2, 2] + * + * @return void + */ + public function testMapInstallment($installment, $expected) + { + $actual = $this->requestDataMapper->mapInstallment($installment); + $this->assertSame($expected, $actual); + } + /** * @return void */ @@ -246,7 +263,7 @@ public function testGet3DFormData() 'txntype' => 'sales', 'txnamount' => 10025, 'txncurrencycode' => '949', - 'txninstallmentcount' => $order->installment, + 'txninstallmentcount' => '', 'orderid' => $this->order['id'], 'successurl' => $this->order['success_url'], 'errorurl' => $this->order['fail_url'], @@ -355,7 +372,7 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord ], 'Transaction' => [ 'Type' => $responseData['txntype'], - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => '', 'Amount' => $responseData['txnamount'], 'CurrencyCode' => $responseData['txncurrencycode'], 'CardholderPresentCode' => '13', @@ -397,7 +414,7 @@ private function getSampleCancelXMLData(AbstractPosAccount $account, $order): ar ], 'Transaction' => [ 'Type' => 'void', - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => '', 'Amount' => 100, 'CurrencyCode' => '949', 'CardholderPresentCode' => '0', @@ -454,7 +471,7 @@ private function getSampleNonSecurePaymentRequestData(AbstractPosAccount $accoun ], 'Transaction' => [ 'Type' => 'sales', - 'InstallmentCnt' => $order->installment, + 'InstallmentCnt' => '', 'Amount' => 10025, 'CurrencyCode' => 949, 'CardholderPresentCode' => '0', diff --git a/tests/DataMapper/InterPosRequestDataMapperTest.php b/tests/DataMapper/InterPosRequestDataMapperTest.php index 749ca721..7ce6e5cb 100644 --- a/tests/DataMapper/InterPosRequestDataMapperTest.php +++ b/tests/DataMapper/InterPosRequestDataMapperTest.php @@ -84,6 +84,23 @@ public function testMapCurrency() $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); } + /** + * @param string|int|null $installment + * @param string|int $expected + * + * @testWith ["0", ""] + * ["1", ""] + * ["2", 2] + * [2, 2] + * + * @return void + */ + public function testMapInstallment($installment, $expected) + { + $actual = $this->requestDataMapper->mapInstallment($installment); + $this->assertSame($expected, $actual); + } + /** * @return void */ @@ -159,7 +176,7 @@ public function testCreate3DPaymentRequestData() $order = [ 'id' => '2020110828BC', 'amount' => 100.01, - 'installment' => '', + 'installment' => 0, 'currency' => 'TRY', 'success_url' => 'http://localhost/finansbank-payfor/3d/response.php', 'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php', @@ -340,7 +357,7 @@ private function getSample3DPaymentRequestData($order, InterPosAccount $account, 'OrderId' => $order->id, 'PurchAmount' => $order->amount, 'Currency' => '949', - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => '', 'MD' => $responseData['MD'], 'PayerTxnId' => $responseData['PayerTxnId'], 'Eci' => $responseData['Eci'], @@ -388,7 +405,7 @@ private function getSampleNonSecurePaymentRequestData($order, AbstractCreditCard 'OrderId' => $order->id, 'PurchAmount' => $order->amount, 'Currency' => '949', - 'InstallmentCount' => $order->installment, + 'InstallmentCount' => '', 'MOTO' => '0', 'Lang' => $order->lang, ]; diff --git a/tests/DataMapper/KuveytPosRequestDataMapperTest.php b/tests/DataMapper/KuveytPosRequestDataMapperTest.php index a7e66cf8..c597181a 100644 --- a/tests/DataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/DataMapper/KuveytPosRequestDataMapperTest.php @@ -87,6 +87,23 @@ public function testMapCurrency() $this->assertEquals('0978', $this->requestDataMapper->mapCurrency('EUR')); } + /** + * @param string|int|null $installment + * @param string|int $expected + * + * @testWith ["0", 0] + * ["1", 0] + * ["2", 2] + * [2, 2] + * + * @return void + */ + public function testMapInstallment($installment, $expected) + { + $actual = $this->requestDataMapper->mapInstallment($installment); + $this->assertSame($expected, $actual); + } + /** * @return void */ diff --git a/tests/DataMapper/PayForPosRequestDataMapperTest.php b/tests/DataMapper/PayForPosRequestDataMapperTest.php index 032cb324..dd379084 100644 --- a/tests/DataMapper/PayForPosRequestDataMapperTest.php +++ b/tests/DataMapper/PayForPosRequestDataMapperTest.php @@ -77,6 +77,23 @@ public function testMapCurrency() $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); } + /** + * @param string|int|null $installment + * @param string|int $expected + * + * @testWith ["0", 0] + * ["1", 0] + * ["2", 2] + * [2, 2] + * + * @return void + */ + public function testMapInstallment($installment, $expected) + { + $actual = $this->requestDataMapper->mapInstallment($installment); + $this->assertSame($expected, $actual); + } + /** * @return void */ diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php index bf73ca62..244153f6 100644 --- a/tests/DataMapper/PosNetRequestDataMapperTest.php +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -91,13 +91,21 @@ public function testAmountFormat() } /** + * @param string|int|null $installment + * @param string|int $expected + * + * @testWith ["0", "00"] + * ["1", "00"] + * ["2", "02"] + * ["2", "02"] + * ["12", "12"] + * * @return void */ - public function testFormatInstallment() + public function testMapInstallment($installment, $expected) { - $this->assertSame('00', PosNetRequestDataMapper::formatInstallment(0)); - $this->assertSame('00', PosNetRequestDataMapper::formatInstallment(1)); - $this->assertSame('02', PosNetRequestDataMapper::formatInstallment(2)); + $actual = $this->requestDataMapper->mapInstallment($installment); + $this->assertSame($expected, $actual); } /** @@ -462,7 +470,7 @@ private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $ac 'hostLogKey' => $order->host_ref_num, 'amount' => $order->amount, 'currencyCode' => 'TL', - 'installment' => $order->installment, + 'installment' => '02', ], ]; } diff --git a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php index f8d7700b..88dfd896 100644 --- a/tests/DataMapper/VakifBankPosRequestDataMapperTest.php +++ b/tests/DataMapper/VakifBankPosRequestDataMapperTest.php @@ -91,6 +91,23 @@ public function testMapCurrency() $this->assertEquals('978', $this->requestDataMapper->mapCurrency('EUR')); } + /** + * @param string|int|null $installment + * @param string|int $expected + * + * @testWith ["0", 0] + * ["1", 0] + * ["2", 2] + * [2, 2] + * + * @return void + */ + public function testMapInstallment($installment, $expected) + { + $actual = $this->requestDataMapper->mapInstallment($installment); + $this->assertSame($expected, $actual); + } + /** * @return void */ @@ -281,7 +298,7 @@ private function getSample3DPaymentRequestData(AbstractPosAccount $account, $ord 'TransactionDeviceSource' => 0, ]; if ($order->installment) { - $expectedValue['NumberOfInstallments'] = $order->installment; + $expectedValue['NumberOfInstallments'] = $this->requestDataMapper->mapInstallment($order->installment); } return $expectedValue; @@ -314,7 +331,7 @@ private function getSample3DEnrollmentRequestData(AbstractPosAccount $account, $ ]; if ($order->installment) { - $expectedValue['InstallmentCount'] = $order->installment; + $expectedValue['InstallmentCount'] = $this->requestDataMapper->mapInstallment($order->installment); } if (isset($order->recurringFrequency)) { diff --git a/tests/Gateways/EstPostTest.php b/tests/Gateways/EstPostTest.php index 92af8d4c..4552207b 100644 --- a/tests/Gateways/EstPostTest.php +++ b/tests/Gateways/EstPostTest.php @@ -84,25 +84,6 @@ public function testPrepare() $this->assertEquals($this->card, $this->pos->getCard()); } - /** - * @param string|null $installment - * @param string $expected - * - * @testWith ["", ""] - * ["0", ""] - * ["1", ""] - * ["2", "2"] - * - * @return void - */ - public function testPreparePaymentOrder(?string $installment, string $expected) - { - $this->order['installment'] = $installment; - $this->pos->prepare($this->order, AbstractGateway::TX_PAY); - $preparedOrder = $this->pos->getOrder(); - $this->assertEquals($expected, $preparedOrder->installment); - } - /** * @return void */ diff --git a/tests/Gateways/GarantiPosTest.php b/tests/Gateways/GarantiPosTest.php index 323406d5..690ea1ab 100644 --- a/tests/Gateways/GarantiPosTest.php +++ b/tests/Gateways/GarantiPosTest.php @@ -86,7 +86,7 @@ public function testPrepare() $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); $this->assertSame(10025, $this->pos->getOrder()->amount); - $this->assertSame('', $this->pos->getOrder()->installment); + $this->assertSame(0, $this->pos->getOrder()->installment); } /** From a9f6906f49fe85211ec3659a8e3ee1cad021d3ad Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 7 May 2022 20:34:02 +0200 Subject: [PATCH 29/40] make order currency optional --- src/Gateways/EstPos.php | 2 +- src/Gateways/GarantiPos.php | 6 +++--- src/Gateways/InterPos.php | 2 +- src/Gateways/PayForPos.php | 2 +- src/Gateways/PosNet.php | 4 ++-- src/Gateways/VakifBankPos.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 69436b5a..9d5ad1a5 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -694,7 +694,7 @@ protected function prepareRefundOrder(array $order) { return (object) [ 'id' => $order['id'], - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', 'amount' => $order['amount'], ]; } diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 2d020881..2d0cf93d 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -539,7 +539,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'ref_ret_num' => $order['ref_ret_num'], - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', 'amount' => $this->requestDataMapper::amountFormat($order['amount']), 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', @@ -554,7 +554,7 @@ protected function prepareStatusOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', 'installment' => 0, @@ -577,7 +577,7 @@ protected function prepareCancelOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', 'ref_ret_num' => $order['ref_ret_num'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index a765d318..6f8a5a81 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -477,7 +477,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $order['amount'], - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', ]; } diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index 1a2904a5..e048cbd3 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -528,7 +528,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $order['amount'], - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', ]; } diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 27c74828..0093f140 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -709,7 +709,7 @@ protected function preparePaymentOrder(array $order) 'id' => $this->requestDataMapper::formatOrderId($order['id']), 'installment' => $order['installment'] ?? 0, 'amount' => $this->requestDataMapper::amountFormat($order['amount']), - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', ]); } @@ -769,7 +769,7 @@ protected function prepareRefundOrder(array $order) 'id' => isset($order['id']) ? $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, 'host_ref_num' => $order['host_ref_num'] ?? null, 'amount' => $this->requestDataMapper::amountFormat($order['amount']), - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', ]; } } diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index ca8b2566..c872f189 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -414,7 +414,7 @@ protected function preparePostPaymentOrder(array $order) return (object) [ 'id' => $order['id'], 'amount' => $order['amount'], - 'currency' => $order['currency'], + 'currency' => $order['currency'] ?? 'TRY', 'ip' => $order['ip'], ]; } From 9fb6afec1ebc9fcd9bcc9a87319330eb6aef5e60 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 7 May 2022 21:27:44 +0200 Subject: [PATCH 30/40] garant & posnet move amount format into request data mappers --- .../GarantiPosRequestDataMapper.php | 20 +++++++++---------- src/DataMapper/PosNetRequestDataMapper.php | 10 +++++----- src/Gateways/GarantiPos.php | 8 ++++---- src/Gateways/PosNet.php | 10 +++++----- .../PosNetRequestDataMapperTest.php | 2 +- tests/Gateways/GarantiPosTest.php | 1 - 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/DataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/GarantiPosRequestDataMapper.php index 0ab2dc95..acde24a6 100644 --- a/src/DataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/GarantiPosRequestDataMapper.php @@ -118,7 +118,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ 'Transaction' => [ 'Type' => $this->mapTxType($txType), 'InstallmentCnt' => $this->mapInstallment($order->installment), - 'Amount' => $order->amount, + 'Amount' => self::amountFormat($order->amount), 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, @@ -154,7 +154,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac ], 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_POST_PAY), - 'Amount' => $order->amount, + 'Amount' => self::amountFormat($order->amount), 'CurrencyCode' => $this->mapCurrency($order->currency), 'OriginalRetrefNum' => $order->ref_ret_num, ], @@ -168,7 +168,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac */ public function createStatusRequestData(AbstractPosAccount $account, $order): array { - $hash = $this->createHash($account, $order,AbstractGateway::TX_STATUS); + $hash = $this->createHash($account, $order, AbstractGateway::TX_STATUS); return [ 'Mode' => $this->getMode(), @@ -184,7 +184,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_STATUS), 'InstallmentCnt' => $this->mapInstallment($order->installment), - 'Amount' => $order->amount, + 'Amount' => self::amountFormat($order->amount), //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, @@ -215,7 +215,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_CANCEL), 'InstallmentCnt' => $this->mapInstallment($order->installment), - 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek + 'Amount' => self::amountFormat($order->amount), //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, @@ -247,7 +247,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_REFUND), 'InstallmentCnt' => $this->mapInstallment($order->installment), - 'Amount' => $order->amount, + 'Amount' => self::amountFormat($order->amount), //sabit olarak amount 100 gonderilecek, 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, @@ -279,7 +279,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar 'Transaction' => [ 'Type' => $this->mapTxType(AbstractGateway::TX_HISTORY), 'InstallmentCnt' => $this->mapInstallment($order->installment), - 'Amount' => $order->amount, //sabit olarak amount 100 gonderilecek + 'Amount' => self::amountFormat($order->amount), //sabit olarak amount 100 gonderilecek 'CurrencyCode' => $this->mapCurrency($order->currency), 'CardholderPresentCode' => '0', 'MotoInd' => self::MOTO, @@ -304,7 +304,7 @@ public function create3DFormData(AbstractPosAccount $account, $order, string $tx 'terminalmerchantid' => $account->getClientId(), 'terminalid' => $account->getTerminalId(), 'txntype' => $this->mapTxType($txType), - 'txnamount' => $order->amount, + 'txnamount' => self::amountFormat($order->amount), 'txncurrencycode' => $this->mapCurrency($order->currency), 'txninstallmentcount' => $this->mapInstallment($order->installment), 'orderid' => $order->id, @@ -338,7 +338,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType $map = [ $account->getTerminalId(), $order->id, - $order->amount, + self::amountFormat($order->amount), $order->success_url, $order->fail_url, $this->mapTxType($txType), @@ -366,7 +366,7 @@ public function createHash(GarantiPosAccount $account, $order, string $txType, ? $order->id, $account->getTerminalId(), isset($card) ? $card->getNumber() : null, - $order->amount, + self::amountFormat($order->amount), $this->createSecurityData($account, $txType), ]; diff --git a/src/DataMapper/PosNetRequestDataMapper.php b/src/DataMapper/PosNetRequestDataMapper.php index e97bdb59..7485243d 100644 --- a/src/DataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/PosNetRequestDataMapper.php @@ -92,7 +92,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ strtolower($this->mapTxType($txType)) => [ 'orderID' => self::formatOrderId($order->id), 'installment' => $this->mapInstallment($order->installment), - 'amount' => $order->amount, + 'amount' => self::amountFormat($order->amount), 'currencyCode' => $this->mapCurrency($order->currency), 'ccno' => $card->getNumber(), 'expDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), @@ -120,7 +120,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac 'tranDateRequired' => '1', strtolower($this->mapTxType(AbstractGateway::TX_POST_PAY)) => [ 'hostLogKey' => $order->host_ref_num, - 'amount' => $order->amount, + 'amount' => self::amountFormat($order->amount), 'currencyCode' => $this->mapCurrency($order->currency), 'installment' => $this->mapInstallment($order->installment), ], @@ -189,7 +189,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar 'tid' => $account->getTerminalId(), 'tranDateRequired' => '1', $txType => [ - 'amount' => $order->amount, + 'amount' => self::amountFormat($order->amount), 'currencyCode' => $this->mapCurrency($order->currency), ], ]; @@ -265,7 +265,7 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $account, 'ccno' => $card->getNumber(), 'expDate' => $card->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT), 'cvc' => $card->getCvv(), - 'amount' => $order->amount, + 'amount' => self::amountFormat($order->amount), 'currencyCode' => $this->mapCurrency($order->currency), 'installment' => $this->mapInstallment($order->installment), 'XID' => self::formatOrderId($order->id), @@ -307,7 +307,7 @@ public function create3DHash(AbstractPosAccount $account, $order, string $txType if ($account->getModel() === AbstractGateway::MODEL_3D_SECURE || $account->getModel() === AbstractGateway::MODEL_3D_PAY) { $secondHashData = [ self::formatOrderId($order->id), - $order->amount, + self::amountFormat($order->amount), $this->mapCurrency($order->currency), $account->getClientId(), $this->createSecurityData($account), diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 2d0cf93d..23adccb3 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -525,7 +525,7 @@ protected function preparePaymentOrder(array $order) return (object) array_merge($order, [ 'installment' => $order['installment'] ?? 0, 'currency' => $order['currency'] ?? 'TRY', - 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'amount' => $order['amount'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', ]); @@ -540,7 +540,7 @@ protected function preparePostPaymentOrder(array $order) 'id' => $order['id'], 'ref_ret_num' => $order['ref_ret_num'], 'currency' => $order['currency'] ?? 'TRY', - 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'amount' => $order['amount'], 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', ]; @@ -553,7 +553,7 @@ protected function prepareStatusOrder(array $order) { return (object) [ 'id' => $order['id'], - 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor + 'amount' => 1, //sabit deger gonderilmesi gerekiyor 'currency' => $order['currency'] ?? 'TRY', 'ip' => $order['ip'] ?? '', 'email' => $order['email'] ?? '', @@ -576,7 +576,7 @@ protected function prepareCancelOrder(array $order) { return (object) [ 'id' => $order['id'], - 'amount' => $this->requestDataMapper::amountFormat(1), //sabit deger gonderilmesi gerekiyor + 'amount' => 1, //sabit deger gonderilmesi gerekiyor 'currency' => $order['currency'] ?? 'TRY', 'ref_ret_num' => $order['ref_ret_num'], 'ip' => $order['ip'] ?? '', diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 0093f140..5d6115d4 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -227,7 +227,7 @@ public function verifyResponseMAC(PosNetAccount $account, $order, $data): bool $secondHashData = [ $data->mdStatus, $this->requestDataMapper::formatOrderId($order->id), - $order->amount, + $this->requestDataMapper::amountFormat($order->amount), $this->requestDataMapper->mapCurrency($order->currency), $account->getClientId(), $this->requestDataMapper->createSecurityData($account), @@ -329,7 +329,7 @@ public function check3DHash(array $data): bool $originalData = array_map('strval', [ $this->account->getClientId(), $this->account->getTerminalId(), - $this->order->amount, + $this->requestDataMapper::amountFormat($this->order->amount), $this->order->installment, $this->requestDataMapper::formatOrderId($this->order->id), ]); @@ -708,7 +708,7 @@ protected function preparePaymentOrder(array $order) return (object) array_merge($order, [ 'id' => $this->requestDataMapper::formatOrderId($order['id']), 'installment' => $order['installment'] ?? 0, - 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'amount' => $order['amount'], 'currency' => $order['currency'] ?? 'TRY', ]); } @@ -720,7 +720,7 @@ protected function preparePostPaymentOrder(array $order) { return (object) [ 'id' => $this->requestDataMapper::formatOrderId($order['id']), - 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'amount' => $order['amount'], 'installment' => $order['installment'] ?? 0, 'currency' => $order['currency'] ?? 'TRY', 'host_ref_num' => $order['host_ref_num'], @@ -768,7 +768,7 @@ protected function prepareRefundOrder(array $order) //id or host_ref_num 'id' => isset($order['id']) ? $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, 'host_ref_num' => $order['host_ref_num'] ?? null, - 'amount' => $this->requestDataMapper::amountFormat($order['amount']), + 'amount' => $order['amount'], 'currency' => $order['currency'] ?? 'TRY', ]; } diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php index 244153f6..d1f62244 100644 --- a/tests/DataMapper/PosNetRequestDataMapperTest.php +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -468,7 +468,7 @@ private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $ac 'tranDateRequired' => '1', 'capt' => [ 'hostLogKey' => $order->host_ref_num, - 'amount' => $order->amount, + 'amount' => 1002, 'currencyCode' => 'TL', 'installment' => '02', ], diff --git a/tests/Gateways/GarantiPosTest.php b/tests/Gateways/GarantiPosTest.php index 690ea1ab..47821256 100644 --- a/tests/Gateways/GarantiPosTest.php +++ b/tests/Gateways/GarantiPosTest.php @@ -85,7 +85,6 @@ public function testPrepare() { $this->pos->prepare($this->order, AbstractGateway::TX_PAY, $this->card); $this->assertEquals($this->card, $this->pos->getCard()); - $this->assertSame(10025, $this->pos->getOrder()->amount); $this->assertSame(0, $this->pos->getOrder()->installment); } From b1e1ad2476cdcb9ff7d6ad5fa4ea5ab743aa8a84 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 12:18:33 +0200 Subject: [PATCH 31/40] PosNet move order id format into request data mapper --- src/DataMapper/PosNetRequestDataMapper.php | 6 +++--- src/Gateways/PosNet.php | 10 +++++----- tests/DataMapper/PosNetRequestDataMapperTest.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DataMapper/PosNetRequestDataMapper.php b/src/DataMapper/PosNetRequestDataMapper.php index 7485243d..928048be 100644 --- a/src/DataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/PosNetRequestDataMapper.php @@ -140,7 +140,7 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar 'mid' => $account->getClientId(), 'tid' => $account->getTerminalId(), $txType => [ - 'orderID' => $order->id, + 'orderID' => self::mapOrderIdToPrefixedOrderId($order->id, $account->getModel()), ], ]; } @@ -170,7 +170,7 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar if (isset($order->host_ref_num)) { $requestData[$txType]['hostLogKey'] = $order->host_ref_num; } else { - $requestData[$txType]['orderID'] = $order->id; + $requestData[$txType]['orderID'] = self::mapOrderIdToPrefixedOrderId($order->id, $account->getModel()); } return $requestData; @@ -197,7 +197,7 @@ public function createRefundRequestData(AbstractPosAccount $account, $order): ar if (isset($order->host_ref_num)) { $requestData[$txType]['hostLogKey'] = $order->host_ref_num; } else { - $requestData[$txType]['orderID'] = $order->id; + $requestData[$txType]['orderID'] = self::mapOrderIdToPrefixedOrderId($order->id, $account->getModel()); } return $requestData; diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 5d6115d4..4ade27b7 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -706,7 +706,7 @@ protected function mapHistoryResponse($rawResponseData) protected function preparePaymentOrder(array $order) { return (object) array_merge($order, [ - 'id' => $this->requestDataMapper::formatOrderId($order['id']), + 'id' => $order['id'], 'installment' => $order['installment'] ?? 0, 'amount' => $order['amount'], 'currency' => $order['currency'] ?? 'TRY', @@ -719,7 +719,7 @@ protected function preparePaymentOrder(array $order) protected function preparePostPaymentOrder(array $order) { return (object) [ - 'id' => $this->requestDataMapper::formatOrderId($order['id']), + 'id' => $order['id'], 'amount' => $order['amount'], 'installment' => $order['installment'] ?? 0, 'currency' => $order['currency'] ?? 'TRY', @@ -733,7 +733,7 @@ protected function preparePostPaymentOrder(array $order) protected function prepareStatusOrder(array $order) { return (object) [ - 'id' => $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()), + 'id' => $order['id'], ]; } @@ -752,7 +752,7 @@ protected function prepareCancelOrder(array $order) { return (object) [ //id or host_ref_num - 'id' => isset($order['id']) ? $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, + 'id' => $order['id'] ?? null, 'host_ref_num' => $order['host_ref_num'] ?? null, //optional 'auth_code' => $order['auth_code'] ?? null, @@ -766,7 +766,7 @@ protected function prepareRefundOrder(array $order) { return (object) [ //id or host_ref_num - 'id' => isset($order['id']) ? $this->requestDataMapper::mapOrderIdToPrefixedOrderId($order['id'], $this->account->getModel()) : null, + 'id' => $order['id'] ?? null, 'host_ref_num' => $order['host_ref_num'] ?? null, 'amount' => $order['amount'], 'currency' => $order['currency'] ?? 'TRY', diff --git a/tests/DataMapper/PosNetRequestDataMapperTest.php b/tests/DataMapper/PosNetRequestDataMapperTest.php index d1f62244..8c0809db 100644 --- a/tests/DataMapper/PosNetRequestDataMapperTest.php +++ b/tests/DataMapper/PosNetRequestDataMapperTest.php @@ -423,7 +423,7 @@ private function getSampleCancelXMLData(AbstractPosAccount $account, $order): ar if (isset($order->host_ref_num)) { $requestData['reverse']['hostLogKey'] = $order->host_ref_num; } else { - $requestData['reverse']['orderID'] = $order->id; + $requestData['reverse']['orderID'] = 'TDSC000000002020110828BC'; } return $requestData; @@ -487,7 +487,7 @@ private function getSampleStatusRequestData(AbstractPosAccount $account, $order) 'mid' => $account->getClientId(), 'tid' => $account->getTerminalId(), 'agreement' => [ - 'orderID' => $order->id, + 'orderID' => 'TDSC000000002020110828BC', ], ]; } @@ -513,7 +513,7 @@ private function getSampleRefundXMLData(AbstractPosAccount $account, $order): ar if (isset($order->host_ref_num)) { $requestData['return']['hostLogKey'] = $order->host_ref_num; } else { - $requestData['return']['orderID'] = $order->id; + $requestData['return']['orderID'] = 'TDSC000000002020110828BC'; } return $requestData; From 1d3980f39a7d394fc7f61f51c059a8c9bdecf196 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 12:20:18 +0200 Subject: [PATCH 32/40] EstPos remove forgotten create3DHash method --- src/Gateways/EstPos.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 9d5ad1a5..e89e4daf 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -73,20 +73,6 @@ public function createXML(array $nodes, string $encoding = 'ISO-8859-9', bool $i return parent::createXML(['CC5Request' => $nodes], $encoding, $ignorePiNode); } - /** - * Create 3D Hash - * - * @param AbstractPosAccount $account - * @param $order - * @param string $txType - * - * @return string - */ - public function create3DHash(AbstractPosAccount $account, $order, string $txType): string - { - return $this->requestDataMapper->create3DHash($account, $order, $txType); - } - /** * Check 3D Hash * From 9f24b548f75207ea769cc64037d468684ea39f4f Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 20:05:31 +0200 Subject: [PATCH 33/40] examples - added comments --- examples/akbank/3d-host/_config.php | 2 +- examples/akbank/3d-pay/_config.php | 2 +- examples/akbank/3d/_config.php | 2 +- examples/akbank/regular/_config.php | 2 +- examples/finansbank-payfor/3d-host/_config.php | 2 +- examples/finansbank-payfor/3d-pay/_config.php | 2 +- examples/finansbank-payfor/3d/_config.php | 2 +- examples/finansbank-payfor/regular/_config.php | 2 +- examples/garanti/3d-pay/_config.php | 2 +- examples/garanti/3d/_config.php | 2 +- examples/garanti/regular/_config.php | 2 +- examples/interpos/3d-host/_config.php | 2 +- examples/interpos/3d-pay/_config.php | 2 +- examples/interpos/3d/_config.php | 2 +- examples/interpos/regular/_config.php | 1 + examples/kuveytpos/3d/_config.php | 2 +- examples/vakifbank/3d/_config.php | 1 + examples/vakifbank/regular/_config.php | 2 +- examples/ykb/3d/_config.php | 2 +- examples/ykb/regular/_config.php | 2 +- 20 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/akbank/3d-host/_config.php b/examples/akbank/3d-host/_config.php index 6a31f900..a872fd25 100644 --- a/examples/akbank/3d-host/_config.php +++ b/examples/akbank/3d-host/_config.php @@ -5,7 +5,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d-host/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', '700655000200', diff --git a/examples/akbank/3d-pay/_config.php b/examples/akbank/3d-pay/_config.php index d556f9a0..5b42baba 100644 --- a/examples/akbank/3d-pay/_config.php +++ b/examples/akbank/3d-pay/_config.php @@ -5,7 +5,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d-pay/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', '700655000200', diff --git a/examples/akbank/3d/_config.php b/examples/akbank/3d/_config.php index b5dcf365..c574e9e2 100644 --- a/examples/akbank/3d/_config.php +++ b/examples/akbank/3d/_config.php @@ -5,7 +5,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', '700655000200', diff --git a/examples/akbank/regular/_config.php b/examples/akbank/regular/_config.php index b3cea0e7..ebaa5aa3 100644 --- a/examples/akbank/regular/_config.php +++ b/examples/akbank/regular/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/regular/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', '700655000200', diff --git a/examples/finansbank-payfor/3d-host/_config.php b/examples/finansbank-payfor/3d-host/_config.php index 1950acd2..1372e9a7 100644 --- a/examples/finansbank-payfor/3d-host/_config.php +++ b/examples/finansbank-payfor/3d-host/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d-host/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createPayForAccount( 'qnbfinansbank-payfor', '085300000009704', diff --git a/examples/finansbank-payfor/3d-pay/_config.php b/examples/finansbank-payfor/3d-pay/_config.php index 826667b4..6a8911b9 100644 --- a/examples/finansbank-payfor/3d-pay/_config.php +++ b/examples/finansbank-payfor/3d-pay/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d-pay/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createPayForAccount( 'qnbfinansbank-payfor', '085300000009704', diff --git a/examples/finansbank-payfor/3d/_config.php b/examples/finansbank-payfor/3d/_config.php index 3c2d4386..0fc2ab2a 100644 --- a/examples/finansbank-payfor/3d/_config.php +++ b/examples/finansbank-payfor/3d/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createPayForAccount( 'qnbfinansbank-payfor', '085300000009704', diff --git a/examples/finansbank-payfor/regular/_config.php b/examples/finansbank-payfor/regular/_config.php index 187338c7..4d04cb3c 100644 --- a/examples/finansbank-payfor/regular/_config.php +++ b/examples/finansbank-payfor/regular/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/regular/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createPayForAccount( 'qnbfinansbank-payfor', '085300000009704', diff --git a/examples/garanti/3d-pay/_config.php b/examples/garanti/3d-pay/_config.php index 7f0e547b..d361a610 100644 --- a/examples/garanti/3d-pay/_config.php +++ b/examples/garanti/3d-pay/_config.php @@ -5,7 +5,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d-pay/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = AccountFactory::createGarantiPosAccount( 'garanti', '7000679', diff --git a/examples/garanti/3d/_config.php b/examples/garanti/3d/_config.php index 7a416c0f..e5898e3f 100644 --- a/examples/garanti/3d/_config.php +++ b/examples/garanti/3d/_config.php @@ -5,7 +5,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = AccountFactory::createGarantiPosAccount( 'garanti', '7000679', diff --git a/examples/garanti/regular/_config.php b/examples/garanti/regular/_config.php index 40a0edd5..a5f2bb73 100644 --- a/examples/garanti/regular/_config.php +++ b/examples/garanti/regular/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/regular/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createGarantiPosAccount( 'garanti', '7000679', diff --git a/examples/interpos/3d-host/_config.php b/examples/interpos/3d-host/_config.php index 53287495..e1ff97d7 100644 --- a/examples/interpos/3d-host/_config.php +++ b/examples/interpos/3d-host/_config.php @@ -11,7 +11,7 @@ $userPass = ''; $shopCode = '3123'; $merchantPass = 'gDg1N'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createInterPosAccount( 'denizbank', $shopCode, diff --git a/examples/interpos/3d-pay/_config.php b/examples/interpos/3d-pay/_config.php index 8428bc57..483fba2a 100644 --- a/examples/interpos/3d-pay/_config.php +++ b/examples/interpos/3d-pay/_config.php @@ -5,7 +5,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d-pay/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $userCode = 'InterTestApi'; $userPass = '3'; $shopCode = '3123'; diff --git a/examples/interpos/3d/_config.php b/examples/interpos/3d/_config.php index 58355119..64ef54e5 100644 --- a/examples/interpos/3d/_config.php +++ b/examples/interpos/3d/_config.php @@ -5,7 +5,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $userCode = 'InterTestApi'; $userPass = '3'; $shopCode = '3123'; diff --git a/examples/interpos/regular/_config.php b/examples/interpos/regular/_config.php index f293ccd7..192d11dc 100644 --- a/examples/interpos/regular/_config.php +++ b/examples/interpos/regular/_config.php @@ -8,6 +8,7 @@ $userPass = '3'; $shopCode = '3123'; //$merchantPass non secure islemler icin kullanilmiyor +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createInterPosAccount('denizbank', $shopCode, $userCode, $userPass); $pos = getGateway($account); diff --git a/examples/kuveytpos/3d/_config.php b/examples/kuveytpos/3d/_config.php index 049a1c21..84585126 100644 --- a/examples/kuveytpos/3d/_config.php +++ b/examples/kuveytpos/3d/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createKuveytPosAccount( 'kuveytpos', '496', diff --git a/examples/vakifbank/3d/_config.php b/examples/vakifbank/3d/_config.php index f3e77d20..9588b16e 100644 --- a/examples/vakifbank/3d/_config.php +++ b/examples/vakifbank/3d/_config.php @@ -7,6 +7,7 @@ $merchantId = '000000000111111'; $terminalId = 'VP000095'; $isyeriSifre = '3XTgER89as'; +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createVakifBankAccount( 'vakifbank', $merchantId, diff --git a/examples/vakifbank/regular/_config.php b/examples/vakifbank/regular/_config.php index 7d72b5f1..ac5f7edf 100644 --- a/examples/vakifbank/regular/_config.php +++ b/examples/vakifbank/regular/_config.php @@ -7,7 +7,7 @@ $merchantId = '000000000111111'; $terminalId = 'VP000095'; $isyeriSifre = '3XTgER89as'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createVakifBankAccount( 'vakifbank', $merchantId, diff --git a/examples/ykb/3d/_config.php b/examples/ykb/3d/_config.php index bcc1a676..5cfabe7c 100644 --- a/examples/ykb/3d/_config.php +++ b/examples/ykb/3d/_config.php @@ -6,7 +6,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/3d/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = AccountFactory::createPosNetAccount( 'yapikredi', '6706598320', diff --git a/examples/ykb/regular/_config.php b/examples/ykb/regular/_config.php index 61259924..724228c2 100644 --- a/examples/ykb/regular/_config.php +++ b/examples/ykb/regular/_config.php @@ -3,7 +3,7 @@ require '../_payment_config.php'; $baseUrl = $bankTestsUrl.'/regular/'; - +//account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createPosNetAccount( 'yapikredi', '6706598320', From 6eb25e46a88bc607c82c27a486fa7085ef894344 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 20:05:55 +0200 Subject: [PATCH 34/40] AccountFactory added some comments --- src/Factory/AccountFactory.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Factory/AccountFactory.php b/src/Factory/AccountFactory.php index 85b021d5..244a228c 100644 --- a/src/Factory/AccountFactory.php +++ b/src/Factory/AccountFactory.php @@ -21,8 +21,8 @@ class AccountFactory { /** * @param string $bank - * @param string $clientId - * @param string $username + * @param string $clientId Üye iş yeri numarası + * @param string $kullaniciAdi * @param string $password * @param string $model * @param string|null $storeKey @@ -32,11 +32,11 @@ class AccountFactory * * @throws MissingAccountInfoException */ - public static function createEstPosAccount(string $bank, string $clientId, string $username, string $password, string $model = AbstractGateway::MODEL_NON_SECURE, ?string $storeKey = null, string $lang = AbstractGateway::LANG_TR): EstPosAccount + public static function createEstPosAccount(string $bank, string $clientId, string $kullaniciAdi, string $password, string $model = AbstractGateway::MODEL_NON_SECURE, ?string $storeKey = null, string $lang = AbstractGateway::LANG_TR): EstPosAccount { self::checkParameters($model, $storeKey); - return new EstPosAccount($bank, $model, $clientId, $username, $password, $lang, $storeKey); + return new EstPosAccount($bank, $model, $clientId, $kullaniciAdi, $password, $lang, $storeKey); } /** @@ -61,9 +61,9 @@ public static function createPayForAccount(string $bank, string $merchantId, str /** * @param string $bank - * @param string $clientId - * @param string $username - * @param string $password + * @param string $merchantId Üye işyeri Numarası + * @param string $userId + * @param string $password Terminal UserID şifresi * @param string $terminalId * @param string $model * @param string|null $storeKey @@ -75,11 +75,11 @@ public static function createPayForAccount(string $bank, string $merchantId, str * * @throws MissingAccountInfoException */ - public static function createGarantiPosAccount(string $bank, string $clientId, string $username, string $password, string $terminalId, string $model = AbstractGateway::MODEL_NON_SECURE, ?string $storeKey = null, ?string $refundUsername = null, ?string $refundPassword = null, string $lang = AbstractGateway::LANG_TR): GarantiPosAccount + public static function createGarantiPosAccount(string $bank, string $merchantId, string $userId, string $password, string $terminalId, string $model = AbstractGateway::MODEL_NON_SECURE, ?string $storeKey = null, ?string $refundUsername = null, ?string $refundPassword = null, string $lang = AbstractGateway::LANG_TR): GarantiPosAccount { self::checkParameters($model, $storeKey); - return new GarantiPosAccount($bank, $model, $clientId, $username, $password, $lang, $terminalId, $storeKey, $refundUsername, $refundPassword); + return new GarantiPosAccount($bank, $model, $merchantId, $userId, $password, $lang, $terminalId, $storeKey, $refundUsername, $refundPassword); } @@ -124,9 +124,9 @@ public static function createPosNetAccount(string $bank, string $merchantId, str /** * @param string $bank - * @param string $clientId - * @param string $password - * @param string $terminalId + * @param string $merchantId Üye işyeri numarası + * @param string $password Üye işyeri şifres + * @param string $terminalNo İşlemin hangi terminal üzerinden gönderileceği bilgisi. VB007000... * @param string $model * @param int $merchantType * @param null $subMerchantId @@ -135,11 +135,11 @@ public static function createPosNetAccount(string $bank, string $merchantId, str * * @throws MissingAccountInfoException */ - public static function createVakifBankAccount(string $bank, string $clientId, string $password, string $terminalId, string $model = AbstractGateway::MODEL_NON_SECURE, int $merchantType = VakifBankAccount::MERCHANT_TYPE_STANDARD, $subMerchantId = null): VakifBankAccount + public static function createVakifBankAccount(string $bank, string $merchantId, string $password, string $terminalNo, string $model = AbstractGateway::MODEL_NON_SECURE, int $merchantType = VakifBankAccount::MERCHANT_TYPE_STANDARD, $subMerchantId = null): VakifBankAccount { self::checkVakifBankMerchantType($merchantType, $subMerchantId); - return new VakifBankAccount($bank, $model, $clientId, $password, $terminalId, $merchantType, $subMerchantId); + return new VakifBankAccount($bank, $model, $merchantId, $password, $terminalNo, $merchantType, $subMerchantId); } /** From 8823b023cc525d15f375603a2702b056c4bff559 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 20:06:28 +0200 Subject: [PATCH 35/40] updated docs --- README.md | 58 +++++++++++++++++++++++++++++------------------ docs/CHANGELOG.md | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 9f0291ef..19d325f6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal pos sistemlerinin kullanılabilmesidir. -- **EST POS** altyapısı tam olarak test edilmiş ve kullanıma hazırdır. Akbank, TEB ve Ziraat bankası test edilmiştir. +- **EST POS** (Asseco) altyapısı tam olarak test edilmiş ve kullanıma hazırdır. Akbank, TEB ve Ziraat bankası test edilmiştir. - **Garanti Virtual POS** ödeme sistemi çalışmaktadır, fakat 3D ödeme kısmının üretim ortamında test edilmesi gerekiyor. @@ -16,6 +16,17 @@ Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal - **Kuveyt POS** 3d secure ödeme desteği eklenmiştir, test edildikçe, sorunları bulundukça hatalar giderilecek. +### Ana başlıklar +- [Özellikler](#zellikler) +- [Latest updates](#latest-updates) +- [Minimum Gereksinimler](#minimum-gereksinimler) +- [Kurulum](#kurulum) +- [Farklı Banka Sanal Poslarını Eklemek](#farkl-gatewayler-tek-ilem-ak) +- [Örnek Kodlar](#rnek-kodlar) +- [Troubleshoots](#troubleshoots) +- [Genel Kültür](#genel-kltr) +- [Docker ile test ortamı](#docker-ile-test-ortam) + ### Özellikler - Standart E-Commerce modeliyle ödeme (`AbstractGateway::MODEL_NON_SECURE`) - 3D Secure modeliyle ödeme (`AbstractGateway::MODEL_3D_SECURE`) @@ -27,7 +38,7 @@ Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal - Sipariş iptal etme (`AbstractGateway::TX_CANCEL`) #### Farklı Gateway'ler Tek işlem akışı -* Farklı bankaya geçiş yapmak için sadece doğru `AccountFactory` method'u kullanarak account degistirmek. +* Farklı bankaya geçiş yapmak için sadece doğru `AccountFactory` method'u kullanarak account degistirmek yeterli. * **3D**, **3DPay**, **3DHost** ödemeler arasında geçiş yapmak için tek yapmanız gereken Account konfigurasyonunda account tipini değiştirmek (`AbstractGateway::MODEL_3D_PAY` vs.). İşlem akışı aynı olduğu için kod değiştirmenize gerek kalmıyor. * Aynı tip işlem için farklı POS Gateway'lerden dönen değerler aynı formata normalize edilmiş durumda. Yani kod güncellemenize gerek yok. * Aynı tip işlem için farklı Gateway gönderilecek değerler de genel olarak aynı formatta olacak şekilde normalize edişmiştir. @@ -67,12 +78,12 @@ require './vendor/autoload.php'; // API kullanıcı bilgileri $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i -'XXXXXXX', -'XXXXXXX', -'XXXXXXX', -AbstractGateway::MODEL_3D_SECURE, -'XXXXXXX', -\Mews\Pos\Gateways\EstPos::LANG_TR +'yourClientID', +'yourKullaniciAdi', +'yourSifre', +AbstractGateway::MODEL_3D_SECURE, //storetype +'yourStoreKey', +AbstractGateway::LANG_TR ); // API kullanıcı hesabı ile paket bir değişkene aktarılıyor @@ -95,8 +106,8 @@ require 'config.php'; $order = [ 'id' => 'BENZERSIZ-SIPERIS-ID', 'amount' => 1.01, - 'currency' => 'TRY', //TRY|USD|EUR - 'installment' => 0, //0 ya da 1'den büyük değer + 'currency' => 'TRY', //TRY|USD|EUR, optional. default: TRY + 'installment' => 0, //0 ya da 1'den büyük değer, optional. default: 0 //MODEL_3D_SECURE, MODEL_3D_PAY, MODEL_3D_HOST odemeler icin zorunlu //Success ve Fail URL'ler farklı olabilir ama kütüphane success ve fail için aynı kod çalıştırır. @@ -111,7 +122,7 @@ $order = [ 'rand' => md5(uniqid(time())), // EstPos, Garanti, PayFor, InterPos, VakifBank. Rastegele değer. //lang degeri verilmezse account (EstPosAccount) dili kullanılacak - 'lang' => 'tr', //tr|en. Kullanıcının yönlendirileceği banka gateway sayfasının ve gateway'den dönen mesajların dili. + 'lang' => AbstractGateway::LANG_TR, //LANG_TR|LANG_EN. Kullanıcının yönlendirileceği banka gateway sayfasının ve gateway'den dönen mesajların dili. ]; $session->set('order', $order); @@ -233,28 +244,32 @@ Fakat, ## Troubleshoots -### session sıfırlanması +### Session sıfırlanması Cookie session kullanığınızda, kullanıcı gatewayden geri websitenize yönlendirilidiğinde session'nin sıfırlanabilir. Bu durumda PHP header'de `samesite=None` set etmeyi deneyin. Bu header'ı set ettikten sonra, taraycıda yeni session oluşturun, çünkü bu değişiklik var olan session'i etkilemez. - - -## NonSecure, 3D, 3DPay ve 3DHost ödeme modeller arasındaki farklar -- **3D** - Gateway'den (3D şifre girdiginiz sayfadan) döndükten sonra ödemeyi tamamlamak için banka gateway'ne 1 istek daha (_provizyon_ isteği) gönderir. +###Shared hosting'lerde IP tanımsız hatası +Shared hosting'lerde Cpanel'de gördüğünüz IP'den farklı olarak fiziksel sunucun bir tane daha IP'si olur. +O IP adres Cpanel'de gözükmez, hosting firmanızdan sorup öğrenmeniz gerekmekte. +Bu hatayı alırsanız hosting firmanın verdiği IP adrese'de banka gateway'i tarafından izin verilmesini sağlayın. + +## Genel Kültür +### NonSecure, 3D Secure, 3DPay ve 3DHost ödeme modeller arasındaki farklar +- **3D** - Bankaya göre farklı isimler verilebilir, örn. 3D Full. Gateway'den (3D şifre girdiginiz sayfadan) döndükten sonra ödemeyi tamamlamak için banka gateway'ne 1 istek daha (_provizyon_ isteği) gönderir. Bu isteği göndermeden ödeme tamamlanmaz. -- **3DPay** - Gateway'den (3D şifre girdiginiz sayfadan) döndükten sonra ödeme bitmiş sayılır. 3D ödeme yapıldığı gibi ekstra provizyon istek gönderilmez. +- **3DPay** - Bankaya göre farklı isimler verilebilir, örn. 3D Half. Gateway'den (3D şifre girdiginiz sayfadan) döndükten sonra ödeme bitmiş sayılır. 3D ödeme yapıldığı gibi ekstra provizyon istek gönderilmez. - **3DHost** - Kredi kart girişi için kullanıcı bankanın sayfasına yönledirilir, kredi kart bilgileri girdikten sonra bankanın 3D gateway sayfasına yönlendirilir, ordan da websitenize geri yönlendirilir. Yönlendirme sonucunda ödeme tamanlanmış olur. - **NonSecure** - Ödeme işlemi kullanıcı 3D onay işlemi yapmadan gerçekleşir. - **NonSecure, 3D ve 3DPay** - Ödemede kredi kart bilgisi websiteniz tarafından alınır. **3DHost** ödemede ise banka websayfasından alınır. - -## Otorizasyon, Ön Otorizasyon, Post Otorizasyon İşlemler arasındaki farklar + +### Otorizasyon, Ön Otorizasyon, Ön Provizyon Kapama İşlemler arasındaki farklar - **Otorizasyon** - bildiğimiz ve genel olarak kullandığımız işlem. Tek seferde ödeme işlemi biter. Bu işlem için kullanıcıdan hep kredi kart bilgisini _alınır_. İşlemin kütüphanedeli karşılığı `AbstractGateway::TX_PAY` - **Ön Otorizasyon** - müşteriden parayı direk çekmek yerine, işlem sonucunda para bloke edilir. Bu işlem için kullanıcıdan hep kredi kart bilgisini _alınır_. İşlemin kütüphanedeli karşılığı `AbstractGateway::TX_PRE_PAY` -- **Post Otorizasyon** - ön provizyon sonucunda bloke edilen miktarın satışını tamamlar. +- **Ön Provizyon Kapama** - ön provizyon sonucunda bloke edilen miktarın satışını tamamlar. Ön otorizasyon yapıldıktan sonra, örneğin 1 hafta sonra, Post Otorizasyon isteği gönderilebilinir. Bu işlem için kullanıcıdan kredi kart bilgisi _alınmaz_. Onun yerine bazı gateway'ler `orderId` degeri isteri, bazıları ise ön provizyon sonucu ödenen banka tarafındaki `orderId`'yi ister. @@ -262,8 +277,7 @@ Satıcı _ön otorizasyon_ isteği iptal etmek isterse de `cancel` (Post Otoriza Post Otorizasyon İşlemin kütüphanedeli karşılığı `AbstractGateway::TX_POST_PAY` - Bu 3 çeşit işlemler bütün ödeme modelleri (NonSecure, 3D, 3DPay ve 3DHost) tarafından desteklenir. - -##Refund ve Cancel işlemler arasındaki farklar +### Refund ve Cancel işlemler arasındaki farklar - **Refund** - Tamamlanan ödemeyi iade etmek için kullanılır. Bu işlemi yapabilmek için ödeme yapıldıktan belli bir süre _sonra_ (örn. 12 saat) yapılabilir. İade işlemi için _miktar zorunlu_, çünkü ödenen ve iade edilen miktarı aynı olmayabilir. diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bd9af970..97bced8c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,60 @@ # Changelog +## [0.7.0] - 2022-05-18 +### Changed +- `\Mews\Pos\PosInterface::prepare()` method artık sipariş verilerini (_currency, id, amount, installment, transaction type_) değiştirmez/formatlamaz. + Sipariş verilerinin formatlanmasını artık Data Request Mapper'de (örn. `PosNetRequestDataMapper`) istek göndermeden önce yapılır. + + Önce: + ```php + protected function preparePaymentOrder(array $order) + { + $installment = 0; + if (isset($order['installment']) && $order['installment'] > 1) { + $installment = $order['installment']; + } + + return (object) array_merge($order, [ + 'id' => self::formatOrderId($order['id']), + 'installment' => self::formatInstallment($installment), + 'amount' => self::amountFormat($order['amount']), + 'currency' => $this->mapCurrency($order['currency']), + ]); + } + ``` + Şimdi: + ```php + protected function preparePaymentOrder(array $order) + { + return (object) array_merge($order, [ + 'id' => $order['id'], + 'installment' => $order['installment'] ?? 0, + 'amount' => $order['amount'], + 'currency' => $order['currency'] ?? 'TRY', + ]); + } + ``` +- **GarantiPos** - tekrarlanan (`recurring`) ödeme desteği teklendi. +- **EstPos** - IP adres artık zorunlu değil. +- Language degerleri artık Gateway bazlı tanımlanmıyor. Önceden gateway bazlı: + ```php + \Mews\Pos\Gateways\EstPos::LANG_TR; + \Mews\Pos\Gateways\EstPos::LANG_EN; + \Mews\Pos\Gateways\GarantiPos::LANG_TR; + \Mews\Pos\Gateways\GarantiPos::LANG_EN; + ... + ``` + Şimdi sadece: + ```php + \Mews\Pos\Gateways\AbstractGateway::LANG_TR; + \Mews\Pos\Gateways\AbstractGateway::LANG_EN; + ``` +- Siparişde `currency` ve `installment` artık zorunlu değil. Varsayılan olarak `currency=TRY`, `installment=0` olarak kabul edilir. +- Single Responsibility prensibe uygun olarak bütün gateway sınıflarında istek verilerini hazırlama Request Data Mapper'lere + (`EstPosRequestDataMapper`, `GarantiPosRequestDataMapper`, `InterPosRequestDataMapper`, `KuveytPosRequestDataMapper`, `PayForPosRequestDataMapper`, `PosNetRequestDataMapper`, `VakifBankPosRequestDataMapper`) taşındı. + Bununla birlikte bazı sabit değerler Gateway sınıflardan Request Data Mapper sınıflara taşındı. + + ## [0.6.0] - 2022-04-18 ### Changed - Kredi kart class'ları bütün gateway'ler için **tek** `Mews\Pos\Entity\Card\CreditCard` class'ı olacak şekilde güncellendi. From bc5d97510cf67f388d1b7078f3a3eee0de7d4e71 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 20:53:33 +0200 Subject: [PATCH 36/40] InterPosRequestDataMapper 3D payment fix ShopCode error --- src/DataMapper/InterPosRequestDataMapper.php | 2 +- tests/DataMapper/InterPosRequestDataMapperTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataMapper/InterPosRequestDataMapper.php b/src/DataMapper/InterPosRequestDataMapper.php index 29b6eab9..f14f149b 100644 --- a/src/DataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/InterPosRequestDataMapper.php @@ -56,7 +56,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, return [ 'UserCode' => $account->getUsername(), 'UserPass' => $account->getPassword(), - 'ClientId' => $account->getClientId(), + 'ShopCode' => $account->getClientId(), 'TxnType' => $this->mapTxType($txType), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'OrderId' => $order->id, diff --git a/tests/DataMapper/InterPosRequestDataMapperTest.php b/tests/DataMapper/InterPosRequestDataMapperTest.php index 7ce6e5cb..ef4a2f4c 100644 --- a/tests/DataMapper/InterPosRequestDataMapperTest.php +++ b/tests/DataMapper/InterPosRequestDataMapperTest.php @@ -351,7 +351,7 @@ private function getSample3DPaymentRequestData($order, InterPosAccount $account, return [ 'UserCode' => $account->getUsername(), 'UserPass' => $account->getPassword(), - 'ClientId' => $account->getClientId(), + 'ShopCode' => $account->getClientId(), 'TxnType' => 'Auth', 'SecureType' => 'NonSecure', 'OrderId' => $order->id, From bd005d82ab18700f4604c3f8caa1b7366638580a Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 21:11:29 +0200 Subject: [PATCH 37/40] InterPosRequestDataMapper remove some duplications --- src/DataMapper/AbstractRequestDataMapper.php | 2 +- src/DataMapper/EstPosRequestDataMapper.php | 5 +- src/DataMapper/InterPosRequestDataMapper.php | 144 +++++++++--------- src/DataMapper/KuveytPosRequestDataMapper.php | 27 +++- src/DataMapper/PayForPosRequestDataMapper.php | 44 +++--- .../VakifBankPosRequestDataMapper.php | 29 ++-- 6 files changed, 128 insertions(+), 123 deletions(-) diff --git a/src/DataMapper/AbstractRequestDataMapper.php b/src/DataMapper/AbstractRequestDataMapper.php index 42e59cf5..0cc0ce36 100644 --- a/src/DataMapper/AbstractRequestDataMapper.php +++ b/src/DataMapper/AbstractRequestDataMapper.php @@ -135,7 +135,7 @@ abstract public function create3DFormData(AbstractPosAccount $account, $order, s /** * @param AbstractPosAccount $account * @param $order - * @param string $txType mapped value from AbstractGateway::TX_PAY + * @param string $txType ex: AbstractGateway::TX_PAY * * @return string */ diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index ec52d332..28ca66d7 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -54,10 +54,7 @@ class EstPosRequestDataMapper extends AbstractRequestDataMapper */ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData): array { - $requestData = [ - 'Name' => $account->getUsername(), - 'Password' => $account->getPassword(), - 'ClientId' => $account->getClientId(), + $requestData = $this->getRequestAccountData($account) + [ 'Type' => $this->mapTxType($txType), 'IPAddress' => $order->ip ?? null, 'Email' => $order->email, diff --git a/src/DataMapper/InterPosRequestDataMapper.php b/src/DataMapper/InterPosRequestDataMapper.php index f14f149b..02e1f27a 100644 --- a/src/DataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/InterPosRequestDataMapper.php @@ -53,23 +53,20 @@ class InterPosRequestDataMapper extends AbstractRequestDataMapper */ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData): array { - return [ - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'ShopCode' => $account->getClientId(), - 'TxnType' => $this->mapTxType($txType), - 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'OrderId' => $order->id, - 'PurchAmount' => $order->amount, - 'Currency' => $this->mapCurrency($order->currency), - 'InstallmentCount' => $this->mapInstallment($order->installment), - 'MD' => $responseData['MD'], - 'PayerTxnId' => $responseData['PayerTxnId'], - 'Eci' => $responseData['Eci'], - 'PayerAuthenticationCode' => $responseData['PayerAuthenticationCode'], - 'MOTO' => self::MOTO, - 'Lang' => $this->getLang($account, $order), - ]; + return $this->getRequestAccountData($account) + [ + 'TxnType' => $this->mapTxType($txType), + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'OrderId' => $order->id, + 'PurchAmount' => $order->amount, + 'Currency' => $this->mapCurrency($order->currency), + 'InstallmentCount' => $this->mapInstallment($order->installment), + 'MD' => $responseData['MD'], + 'PayerTxnId' => $responseData['PayerTxnId'], + 'Eci' => $responseData['Eci'], + 'PayerAuthenticationCode' => $responseData['PayerAuthenticationCode'], + 'MOTO' => self::MOTO, + 'Lang' => $this->getLang($account, $order), + ]; } /** @@ -77,19 +74,16 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, */ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array { - $requestData = [ - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'ShopCode' => $account->getClientId(), - 'TxnType' => $this->mapTxType($txType), - 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'OrderId' => $order->id, - 'PurchAmount' => $order->amount, - 'Currency' => $this->mapCurrency($order->currency), - 'InstallmentCount' => $this->mapInstallment($order->installment), - 'MOTO' => self::MOTO, - 'Lang' => $this->getLang($account, $order), - ]; + $requestData = $this->getRequestAccountData($account) + [ + 'TxnType' => $this->mapTxType($txType), + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'OrderId' => $order->id, + 'PurchAmount' => $order->amount, + 'Currency' => $this->mapCurrency($order->currency), + 'InstallmentCount' => $this->mapInstallment($order->installment), + 'MOTO' => self::MOTO, + 'Lang' => $this->getLang($account, $order), + ]; if ($card) { $requestData['CardType'] = $this->cardTypeMapping[$card->getType()]; @@ -106,18 +100,15 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array { - return [ - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'ShopCode' => $account->getClientId(), - 'TxnType' => $this->mapTxType(AbstractGateway::TX_POST_PAY), - 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'OrderId' => null, - 'orgOrderId' => $order->id, - 'PurchAmount' => $order->amount, - 'Currency' => $this->mapCurrency($order->currency), - 'MOTO' => self::MOTO, - ]; + return $this->getRequestAccountData($account) + [ + 'TxnType' => $this->mapTxType(AbstractGateway::TX_POST_PAY), + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'OrderId' => null, + 'orgOrderId' => $order->id, + 'PurchAmount' => $order->amount, + 'Currency' => $this->mapCurrency($order->currency), + 'MOTO' => self::MOTO, + ]; } /** @@ -125,16 +116,13 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac */ public function createStatusRequestData(AbstractPosAccount $account, $order): array { - return [ - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'ShopCode' => $account->getClientId(), - 'OrderId' => null, //todo buraya hangi deger verilecek? - 'orgOrderId' => $order->id, - 'TxnType' => $this->mapTxType(AbstractGateway::TX_STATUS), - 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'Lang' => $this->getLang($account, $order), - ]; + return $this->getRequestAccountData($account) + [ + 'OrderId' => null, //todo buraya hangi deger verilecek? + 'orgOrderId' => $order->id, + 'TxnType' => $this->mapTxType(AbstractGateway::TX_STATUS), + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'Lang' => $this->getLang($account, $order), + ]; } /** @@ -142,16 +130,13 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar */ public function createCancelRequestData(AbstractPosAccount $account, $order): array { - return [ - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'ShopCode' => $account->getClientId(), - 'OrderId' => null, //todo buraya hangi deger verilecek? - 'orgOrderId' => $order->id, - 'TxnType' => $this->mapTxType(AbstractGateway::TX_CANCEL), - 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'Lang' => $this->getLang($account, $order), - ]; + return $this->getRequestAccountData($account) + [ + 'OrderId' => null, //todo buraya hangi deger verilecek? + 'orgOrderId' => $order->id, + 'TxnType' => $this->mapTxType(AbstractGateway::TX_CANCEL), + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'Lang' => $this->getLang($account, $order), + ]; } /** @@ -159,18 +144,15 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar */ public function createRefundRequestData(AbstractPosAccount $account, $order): array { - return [ - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), - 'ShopCode' => $account->getClientId(), - 'OrderId' => null, - 'orgOrderId' => $order->id, - 'PurchAmount' => $order->amount, - 'TxnType' => $this->mapTxType(AbstractGateway::TX_REFUND), - 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], - 'Lang' => $this->getLang($account, $order), - 'MOTO' => self::MOTO, - ]; + return $this->getRequestAccountData($account) + [ + 'OrderId' => null, + 'orgOrderId' => $order->id, + 'PurchAmount' => $order->amount, + 'TxnType' => $this->mapTxType(AbstractGateway::TX_REFUND), + 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], + 'Lang' => $this->getLang($account, $order), + 'MOTO' => self::MOTO, + ]; } /** @@ -246,4 +228,18 @@ public function mapInstallment(?int $installment) { return $installment > 1 ? $installment : ''; } + + /** + * @param AbstractPosAccount $account + * + * @return array + */ + private function getRequestAccountData(AbstractPosAccount $account): array + { + return [ + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + 'ShopCode' => $account->getClientId(), + ]; + } } diff --git a/src/DataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/KuveytPosRequestDataMapper.php index 7fdee759..323f879d 100644 --- a/src/DataMapper/KuveytPosRequestDataMapper.php +++ b/src/DataMapper/KuveytPosRequestDataMapper.php @@ -62,6 +62,7 @@ class KuveytPosRequestDataMapper extends AbstractRequestDataMapper /** * Amount Formatter * converts 100 to 10000, or 10.01 to 1001 + * * @param float $amount * * @return int @@ -72,18 +73,17 @@ public static function amountFormat(float $amount): int } /** + * @param KuveytPosAccount $account + * * @inheritDoc */ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData): array { $hash = $this->create3DHash($account, $order, $txType, true); - return [ + return $this->getRequestAccountData($account) + [ 'APIVersion' => self::API_VERSION, 'HashData' => $hash, - 'MerchantId' => $account->getClientId(), - 'CustomerId' => $account->getCustomerId(), - 'UserName' => $account->getUsername(), 'CustomerIPAddress' => $order->ip, 'KuveytTurkVPosAdditionalData' => [ 'AdditionalData' => [ @@ -113,11 +113,8 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $account, $o { $hash = $this->create3DHash($account, $order, $txType); - $inputs = [ + $inputs = $this->getRequestAccountData($account) + [ 'APIVersion' => self::API_VERSION, - 'MerchantId' => $account->getClientId(), - 'UserName' => $account->getUsername(), - 'CustomerId' => $account->getCustomerId(), 'HashData' => $hash, 'TransactionType' => $this->mapTxType($txType), 'TransactionSecurity' => $this->secureTypeMappings[$account->getModel()], @@ -270,4 +267,18 @@ private function createHashDataForProvision(AbstractPosAccount $account, $order, $hashedPassword, ]; } + + /** + * @param KuveytPosAccount $account + * + * @return array + */ + private function getRequestAccountData(AbstractPosAccount $account): array + { + return [ + 'MerchantId' => $account->getClientId(), + 'CustomerId' => $account->getCustomerId(), + 'UserName' => $account->getUsername(), + ]; + } } diff --git a/src/DataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/PayForPosRequestDataMapper.php index 2863f410..597b23e6 100644 --- a/src/DataMapper/PayForPosRequestDataMapper.php +++ b/src/DataMapper/PayForPosRequestDataMapper.php @@ -64,11 +64,8 @@ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, */ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array { - return [ + return $this->getRequestAccountData($account) + [ 'MbrId' => self::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), 'MOTO' => self::MOTO, 'OrderId' => $order->id, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], @@ -89,11 +86,8 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array { - return [ + return $this->getRequestAccountData($account) + [ 'MbrId' => self::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), 'OrgOrderId' => $order->id, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'TxnType' => $this->mapTxType(AbstractGateway::TX_POST_PAY), @@ -108,11 +102,8 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $ac */ public function createStatusRequestData(AbstractPosAccount $account, $order): array { - return [ + return $this->getRequestAccountData($account) + [ 'MbrId' => self::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), 'OrgOrderId' => $order->id, 'SecureType' => 'Inquiry', 'Lang' => $this->getLang($account, $order), @@ -125,11 +116,8 @@ public function createStatusRequestData(AbstractPosAccount $account, $order): ar */ public function createCancelRequestData(AbstractPosAccount $account, $order): array { - return [ + return $this->getRequestAccountData($account) + [ 'MbrId' => self::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), 'OrgOrderId' => $order->id, 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'TxnType' => $this->mapTxType(AbstractGateway::TX_CANCEL), @@ -143,11 +131,8 @@ public function createCancelRequestData(AbstractPosAccount $account, $order): ar */ public function createRefundRequestData(AbstractPosAccount $account, $order): array { - return [ + return $this->getRequestAccountData($account) + [ 'MbrId' => self::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), 'SecureType' => $this->secureTypeMappings[AbstractGateway::MODEL_NON_SECURE], 'Lang' => $this->getLang($account, $order), 'OrgOrderId' => $order->id, @@ -164,9 +149,6 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar { $requestData = [ 'MbrId' => self::MBR_ID, - 'MerchantId' => $account->getClientId(), - 'UserCode' => $account->getUsername(), - 'UserPass' => $account->getPassword(), 'SecureType' => 'Report', 'TxnType' => $this->mapTxType(AbstractGateway::TX_HISTORY), 'Lang' => $this->getLang($account, $order), @@ -179,7 +161,7 @@ public function createHistoryRequestData(AbstractPosAccount $account, $order, ar $requestData['ReqDate'] = $extraData['reqDate']; } - return $requestData; + return $this->getRequestAccountData($account) + $requestData; } @@ -248,4 +230,18 @@ public function mapInstallment(?int $installment) { return $installment > 1 ? $installment : 0; } + + /** + * @param AbstractPosAccount $account + * + * @return array + */ + private function getRequestAccountData(AbstractPosAccount $account): array + { + return [ + 'MerchantId' => $account->getClientId(), + 'UserCode' => $account->getUsername(), + 'UserPass' => $account->getPassword(), + ]; + } } diff --git a/src/DataMapper/VakifBankPosRequestDataMapper.php b/src/DataMapper/VakifBankPosRequestDataMapper.php index b53315a4..3e14fac5 100644 --- a/src/DataMapper/VakifBankPosRequestDataMapper.php +++ b/src/DataMapper/VakifBankPosRequestDataMapper.php @@ -55,10 +55,7 @@ class VakifBankPosRequestDataMapper extends AbstractRequestDataMapper */ public function create3DPaymentRequestData(AbstractPosAccount $account, $order, string $txType, array $responseData, ?AbstractCreditCard $card = null): array { - $requestData = [ - 'MerchantId' => $account->getClientId(), - 'Password' => $account->getPassword(), - 'TerminalNo' => $account->getTerminalId(), + $requestData = $this->getRequestAccountData($account) + [ 'TransactionType' => $this->mapTxType($txType), 'TransactionId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), @@ -142,10 +139,7 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $account, */ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $order, string $txType, ?AbstractCreditCard $card = null): array { - $requestData = [ - 'MerchantId' => $account->getClientId(), - 'Password' => $account->getPassword(), - 'TerminalNo' => $account->getTerminalId(), + $requestData = $this->getRequestAccountData($account) + [ 'TransactionType' => $this->mapTxType($txType), 'OrderId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), @@ -172,10 +166,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $account, $ */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $account, $order, ?AbstractCreditCard $card = null): array { - return [ - 'MerchantId' => $account->getClientId(), - 'Password' => $account->getPassword(), - 'TerminalNo' => $account->getTerminalId(), + return $this->getRequestAccountData($account) + [ 'TransactionType' => $this->mapTxType(AbstractGateway::TX_POST_PAY), 'ReferenceTransactionId' => $order->id, 'CurrencyAmount' => self::amountFormat($order->amount), @@ -275,4 +266,18 @@ public function mapInstallment(?int $installment) { return $installment > 1 ? $installment : 0; } + + /** + * @param VakifBankAccount $account + * + * @return array + */ + private function getRequestAccountData(AbstractPosAccount $account): array + { + return [ + 'MerchantId' => $account->getClientId(), + 'Password' => $account->getPassword(), + 'TerminalNo' => $account->getTerminalId(), + ]; + } } From 442e5ed5e7deb422a45c4773a7ab58b95907a4bf Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 21:18:55 +0200 Subject: [PATCH 38/40] README.md fix links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 561ca0bb..08fc5d0d 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal - [Farklı Banka Sanal Poslarını Eklemek](#farkl-gatewayler-tek-ilem-ak) - [Örnek Kodlar](#rnek-kodlar) - [Troubleshoots](#troubleshoots) -- [Genel Kültür](#genel-kltr) -- [Docker ile test ortamı](#docker-ile-test-ortam) +- [Genel Kültür](#genel-kultur) +- [Docker ile test ortamı](#docker-ile-test-ortami) ### Özellikler - Standart E-Commerce modeliyle ödeme (`AbstractGateway::MODEL_NON_SECURE`) From f8915f66cfac6a39097d14669c4aaf7bc44ffa6e Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 8 May 2022 21:28:24 +0200 Subject: [PATCH 39/40] README.md fix links --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 08fc5d0d..24681398 100644 --- a/README.md +++ b/README.md @@ -17,17 +17,17 @@ Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal - **Kuveyt POS** 3d secure ödeme desteği eklenmiştir, test edildikçe, sorunları bulundukça hatalar giderilecek. ### Ana başlıklar -- [Özellikler](#zellikler) +- [Özellikler](#ozellikler) - [Latest updates](#latest-updates) - [Minimum Gereksinimler](#minimum-gereksinimler) - [Kurulum](#kurulum) -- [Farklı Banka Sanal Poslarını Eklemek](#farkl-gatewayler-tek-ilem-ak) -- [Örnek Kodlar](#rnek-kodlar) +- [Farklı Banka Sanal Poslarını Eklemek](#farkli-gatewayler-tek-islem-akisi) +- [Örnek Kodlar](#ornek-kodlar) - [Troubleshoots](#troubleshoots) - [Genel Kültür](#genel-kultur) - [Docker ile test ortamı](#docker-ile-test-ortami) -### Özellikler +### Ozellikler - Standart E-Commerce modeliyle ödeme (`AbstractGateway::MODEL_NON_SECURE`) - 3D Secure modeliyle ödeme (`AbstractGateway::MODEL_3D_SECURE`) - 3D Pay modeliyle ödeme (`AbstractGateway::MODEL_3D_PAY`) @@ -37,7 +37,7 @@ Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal - Sipariş/Para iadesi yapma (`AbstractGateway::TX_REFUND`) - Sipariş iptal etme (`AbstractGateway::TX_CANCEL`) -#### Farklı Gateway'ler Tek işlem akışı +#### Farkli Gateway'ler Tek islem akisi * Farklı bankaya geçiş yapmak için sadece doğru `AccountFactory` method'u kullanarak account degistirmek yeterli. * **3D**, **3DPay**, **3DHost** ödemeler arasında geçiş yapmak için tek yapmanız gereken Account konfigurasyonunda account tipini değiştirmek (`AbstractGateway::MODEL_3D_PAY` vs.). İşlem akışı aynı olduğu için kod değiştirmenize gerek kalmıyor. * Aynı tip işlem için farklı POS Gateway'lerden dönen değerler aynı formata normalize edilmiş durumda. Yani kod güncellemenize gerek yok. @@ -170,7 +170,7 @@ $pos->isSuccess(); dump($pos->getResponse()); //response içeriği için /examples/template/_payment_response.php dosyaya bakınız. ```` -### Farklı Banka Sanal Poslarını Eklemek +### Farkli Banka Sanal Poslarini Eklemek Kendi projenizin dizinindeyken ```sh $ cp ./vendor/mews/pos/config/pos.php ./pos_ayarlar.php @@ -230,7 +230,7 @@ $yeni_ayarlar = require './pos_ayarlar.php'; $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $yeni_ayarlar); ``` -## Örnek Kodlar +## Ornek Kodlar `/examples` dizini içerisinde. 3D ödeme örnek kodlar genel olarak kart bilgilerini website sunucusuna POST eder (`index.php` => `form.php`), @@ -253,7 +253,7 @@ Shared hosting'lerde Cpanel'de gördüğünüz IP'den farklı olarak fiziksel su O IP adres Cpanel'de gözükmez, hosting firmanızdan sorup öğrenmeniz gerekmekte. Bu hatayı alırsanız hosting firmanın verdiği IP adrese'de banka gateway'i tarafından izin verilmesini sağlayın. -## Genel Kültür +## Genel Kultur ### NonSecure, 3D Secure, 3DPay ve 3DHost ödeme modeller arasındaki farklar - **3D** - Bankaya göre farklı isimler verilebilir, örn. 3D Full. Gateway'den (3D şifre girdiginiz sayfadan) döndükten sonra ödemeyi tamamlamak için banka gateway'ne 1 istek daha (_provizyon_ isteği) gönderir. Bu isteği göndermeden ödeme tamamlanmaz. @@ -287,7 +287,7 @@ Belli bir süre _içinde_ (örn. 12 saat) yapılması gerekir. Gateway'ler tara Genel olarak _miktar_ bilgisi _istenmez_, ancak bazı Gateway'ler ister. İşlemin kütüphanedeki karşılığı `AbstractGateway::TX_CANCEL` -## Docker ile test ortamı +## Docker ile test ortami Makinenizde Docker kurulu olmasi gerekiyor. Projenin root klasöründe `docker-compose up` komutu çalıştırmanız yeterli. **Note**: localhost port 80 boş olması gerekiyor. From ce2c4e4267f0824c9c27ec76e51f6f589b0edfc5 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 15 May 2022 17:27:26 +0200 Subject: [PATCH 40/40] PosNetAccount remove redundant properties --- src/Entity/Account/PosNetAccount.php | 45 +++++++--------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/src/Entity/Account/PosNetAccount.php b/src/Entity/Account/PosNetAccount.php index 2e853df7..976b52df 100644 --- a/src/Entity/Account/PosNetAccount.php +++ b/src/Entity/Account/PosNetAccount.php @@ -1,26 +1,18 @@ posNetId = $posNetId; } - /** - * @return string - */ - public function getRefundPassword(): string - { - return $this->refundPassword; - } - - /** - * @return string - */ - public function getRefundUsername(): string - { - return $this->refundUsername; - } - /** * @return string */ @@ -71,5 +47,4 @@ public function getPosNetId(): string { return $this->posNetId; } - -} \ No newline at end of file +}