From 0aa33723c008149ebc3fa0113679050582e01ece Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 18 Nov 2023 17:03:55 +0100 Subject: [PATCH] issue #165 EstV3pos added callbackUrl --- examples/_templates/_payment_response.php | 14 ++++++++++++++ src/Crypt/EstPosCrypt.php | 1 + src/DataMapper/EstPosRequestDataMapper.php | 2 ++ tests/Crypt/EstPosCryptTest.php | 4 ++-- .../DataMapper/EstPosRequestDataMapperTest.php | 18 +++++++++++------- .../EstV3PosRequestDataMapperTest.php | 11 +++++++---- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/examples/_templates/_payment_response.php b/examples/_templates/_payment_response.php index dfb8126f..c2728800 100644 --- a/examples/_templates/_payment_response.php +++ b/examples/_templates/_payment_response.php @@ -7,6 +7,20 @@ require_once '_config.php'; require '../../_templates/_header.php'; +if ($pos instanceof \Mews\Pos\Gateways\EstV3Pos || $pos instanceof \Mews\Pos\Gateways\EstPos) { + /** + * Asseco'da callbackUrl == failUrl olarak tanimlidir. + * Eger kullanici 3D Auth sayfasinda islemini tamamlamadan tarayci sekmesini kapatirsa + * Asseco callbackUrl'a (yani failUrl'a) istek gonderir: https://github.com/mewebstudio/pos/issues/165 + */ + $logger->info('payment response', [ + 'method' => $request->getMethod(), + 'data_query' => $request->query->all(), + 'data_request' => $request->request->all(), + ]); +} + + if (($request->getMethod() !== 'POST' && AbstractGateway::TX_POST_PAY !== $transaction) // PayFlex-CP GET request ile cevapliyor && ($request->getMethod() === 'GET' && [] === $request->query->all()) diff --git a/src/Crypt/EstPosCrypt.php b/src/Crypt/EstPosCrypt.php index 0ef2e325..d462bcd2 100644 --- a/src/Crypt/EstPosCrypt.php +++ b/src/Crypt/EstPosCrypt.php @@ -23,6 +23,7 @@ public function create3DHash(AbstractPosAccount $account, array $requestData, ?s $txType, $requestData['installment'], $requestData['rand'], + $requestData['fail_url'], // callbackUrl $account->getStoreKey(), ]; diff --git a/src/DataMapper/EstPosRequestDataMapper.php b/src/DataMapper/EstPosRequestDataMapper.php index 24c3fd75..130809d6 100644 --- a/src/DataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/EstPosRequestDataMapper.php @@ -268,6 +268,8 @@ public function create3DFormDataCommon(AbstractPosAccount $account, $order, stri 'oid' => $order->id, 'okUrl' => $order->success_url, 'failUrl' => $order->fail_url, + // musteri 3D onay sayfasinda islemleri tamamlamadan kapatirsa, banka bu sayfaya bir istek gonderecek. + 'callbackUrl' => $order->fail_url, 'rnd' => $order->rand, 'lang' => $this->getLang($account, $order), 'currency' => $this->mapCurrency($order->currency), diff --git a/tests/Crypt/EstPosCryptTest.php b/tests/Crypt/EstPosCryptTest.php index dea6c084..59abfde4 100644 --- a/tests/Crypt/EstPosCryptTest.php +++ b/tests/Crypt/EstPosCryptTest.php @@ -53,7 +53,7 @@ public function testCreate3DHash() 'fail_url' => 'https://domain.com/fail_url', 'rand' => 'rand', ]; - $expected = 'S7UxUAohxaxzl35WxHyDfuQx0sg='; + $expected = 'TN+2/D8lijFd+5zAUar6SH6EiRY='; $actual = $this->crypt->create3DHash($this->threeDAccount, $order, 'Auth'); $this->assertEquals($expected, $actual); @@ -73,7 +73,7 @@ public function testCreate3DHashFor3DPay() 'fail_url' => 'https://domain.com/fail_url', 'rand' => 'rand', ]; - $expected = 'S7UxUAohxaxzl35WxHyDfuQx0sg='; + $expected = 'TN+2/D8lijFd+5zAUar6SH6EiRY='; $actual = $this->crypt->create3DHash($this->threeDAccount, $requestData, 'Auth'); $this->assertEquals($expected, $actual); diff --git a/tests/DataMapper/EstPosRequestDataMapperTest.php b/tests/DataMapper/EstPosRequestDataMapperTest.php index 7adf1350..06c4da8a 100644 --- a/tests/DataMapper/EstPosRequestDataMapperTest.php +++ b/tests/DataMapper/EstPosRequestDataMapperTest.php @@ -33,7 +33,7 @@ class EstPosRequestDataMapperTest extends TestCase private $requestDataMapper; private $order; - + private $config; protected function setUp(): void @@ -67,7 +67,7 @@ protected function setUp(): void $this->pos = PosFactory::createPosGateway($this->threeDAccount); $this->pos->setTestMode(true); - + $this->requestDataMapper = new EstPosRequestDataMapper(PosFactory::getGatewayCrypt(EstPos::class, new NullLogger())); $this->card = CreditCardFactory::create($this->pos, '5555444433332222', '22', '01', '123', 'ahmet', AbstractCreditCard::CARD_TYPE_VISA); } @@ -314,13 +314,14 @@ public function testGet3DFormData() $inputs = [ 'clientid' => $account->getClientId(), 'storetype' => $account->getModel(), - 'hash' => 'S7UxUAohxaxzl35WxHyDfuQx0sg=', + 'hash' => 'TN+2/D8lijFd+5zAUar6SH6EiRY=', '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'], + 'callbackUrl' => $this->order['fail_url'], 'rnd' => $this->order['rand'], 'lang' => 'tr', 'currency' => 949, @@ -393,18 +394,19 @@ public function testGet3DHostFormData() $pos = PosFactory::createPosGateway($account); $pos->setTestMode(true); $pos->prepare($this->order, AbstractGateway::TX_PAY); - + $gatewayURL = $this->config['banks'][$this->threeDAccount->getBank()]['urls']['gateway_3d_host']['test']; $inputs = [ 'clientid' => $account->getClientId(), 'storetype' => $account->getModel(), - 'hash' => 'zQJGquP0/PXt6LeutjN1Qxq32Zg=', + 'hash' => '4VS4GWS81j6YJWAuvJ0yEXvCsJM=', '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'], + 'callbackUrl' => $this->order['fail_url'], 'rnd' => $this->order['rand'], 'lang' => 'tr', 'currency' => '949', @@ -522,6 +524,7 @@ public static function threeDFormDataProvider(): iterable 'oid' => 'order222', 'okUrl' => 'https://domain.com/success', 'failUrl' => 'https://domain.com/fail_url', + 'callbackUrl' => 'https://domain.com/fail_url', 'rnd' => 'rand', 'lang' => 'tr', 'currency' => '949', @@ -534,7 +537,7 @@ public static function threeDFormDataProvider(): iterable 'Ecom_Payment_Card_ExpDate_Month' => '01', 'Ecom_Payment_Card_ExpDate_Year' => '22', 'cv2' => '123', - 'hash' => 'S7UxUAohxaxzl35WxHyDfuQx0sg=', + 'hash' => 'TN+2/D8lijFd+5zAUar6SH6EiRY=', ], ], ]; @@ -563,6 +566,7 @@ public static function threeDFormDataProvider(): iterable 'oid' => 'order222', 'okUrl' => 'https://domain.com/success', 'failUrl' => 'https://domain.com/fail_url', + 'callbackUrl' => 'https://domain.com/fail_url', 'rnd' => 'rand', 'lang' => 'tr', 'currency' => '949', @@ -577,7 +581,7 @@ public static function threeDFormDataProvider(): iterable 'cv2' => '123', 'IMCKOD' => 'İmece Ürün Bilgisi', 'FDONEM' => 'Faizsiz Dönem Bilgisi', - 'hash' => 'S7UxUAohxaxzl35WxHyDfuQx0sg=', + 'hash' => 'TN+2/D8lijFd+5zAUar6SH6EiRY=', ], ], ]; diff --git a/tests/DataMapper/EstV3PosRequestDataMapperTest.php b/tests/DataMapper/EstV3PosRequestDataMapperTest.php index 8026b831..22168d8f 100644 --- a/tests/DataMapper/EstV3PosRequestDataMapperTest.php +++ b/tests/DataMapper/EstV3PosRequestDataMapperTest.php @@ -61,7 +61,7 @@ protected function setUp(): void 'success_url' => 'https://domain.com/success', 'fail_url' => 'https://domain.com/fail_url', 'lang' => 'tr', - 'rand' => microtime(), + 'rand' => 'rand-21212', ]; $this->pos = PosFactory::createPosGateway($this->threeDAccount); @@ -92,6 +92,7 @@ public function testGet3DFormData() 'oid' => $this->order['id'], 'okUrl' => $this->order['success_url'], 'failUrl' => $this->order['fail_url'], + 'callbackUrl' => $this->order['fail_url'], 'rnd' => $this->order['rand'], 'hashAlgorithm' => 'ver3', 'lang' => 'tr', @@ -100,7 +101,7 @@ public function testGet3DFormData() 'taksit' => '', ]; - $hash = $this->requestDataMapper->getCrypt()->create3DHash($account, $inputs, $txType); + $hash = '7MGmDH2CY9jlFd4kVHwdvlyt07hIqkiBWVR8bkjAiaaRhK2XUHyvrDLqv0vlG6YY8bXChDkLfnDwVLi3Pvg5lQ=='; $inputs['hash'] = $hash; $form = [ 'gateway' => $gatewayURL, @@ -123,7 +124,7 @@ public function testGet3DFormData() $form['inputs']['cv2'] = $card->getCvv(); unset($form['inputs']['hash']); - $form['inputs']['hash'] = $this->requestDataMapper->getCrypt()->create3DHash($account, $form['inputs'], $txType); + $form['inputs']['hash'] = '7EgK2aMhS848ZMEkl2d0s1dFXlMhCy4LS5FFk+k/FbEmmVqBqx6TtQ1Yg7aW0KQa/5hrQODwBVT3SCUwfXHEsg=='; $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $this->pos->getAccount(), @@ -163,6 +164,7 @@ public function testGet3DHostFormData() 'oid' => $this->order['id'], 'okUrl' => $this->order['success_url'], 'failUrl' => $this->order['fail_url'], + 'callbackUrl' => $this->order['fail_url'], 'rnd' => $this->order['rand'], 'hashAlgorithm' => 'ver3', 'lang' => 'tr', @@ -175,7 +177,8 @@ public function testGet3DHostFormData() 'method' => 'POST', 'inputs' => $inputs, ]; - $form['inputs']['hash'] = $this->requestDataMapper->getCrypt()->create3DHash($account, $inputs, AbstractGateway::TX_PAY); + + $form['inputs']['hash'] = 'pxvr9oG9G6v2AU/Lci3qs7OiBAwcvAaLotG5rorJVe31DJN/wlVDReWpqFSJojTLPs6pPiS1L1U+QkE0dJJBKw=='; $this->assertEquals($form, $this->requestDataMapper->create3DFormData( $pos->getAccount(),