From a320934c1c5c839d95359c6c94bb38ec76b7b673 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 16:38:14 +0200 Subject: [PATCH 01/14] issue #60 added $ignorePiNode argument to createXML() method --- src/Gateways/AbstractGateway.php | 21 +++++++++++---------- src/Gateways/EstPos.php | 5 ++--- src/Gateways/GarantiPos.php | 4 ++-- src/Gateways/PayForPos.php | 4 ++-- src/Gateways/PosNet.php | 8 ++++---- src/Gateways/VakifBankPos.php | 4 ++-- src/PosInterface.php | 3 ++- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index 3b267f2c..268018e8 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -182,22 +182,23 @@ public function getOrder() } /** - * Create XML DOM Document - * - * @param array $nodes - * @param string $encoding - * - * @return string the XML, or false if an error occurred. + * @inheritDoc */ - public function createXML(array $nodes, $encoding = 'UTF-8') + public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignorePiNode = false): string { $rootNodeName = array_keys($nodes)[0]; $encoder = new XmlEncoder(); - - return $encoder->encode($nodes[$rootNodeName], 'xml', [ + $context = [ XmlEncoder::ROOT_NODE_NAME => $rootNodeName, XmlEncoder::ENCODING => $encoding, - ]); + ]; + if ($ignorePiNode) { + $context[XmlEncoder::ENCODER_IGNORED_NODE_TYPES] = [ + XML_PI_NODE, + ]; + } + + return $encoder->encode($nodes[$rootNodeName], 'xml', $context); } /** diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index ee7dd436..3f1383de 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -5,7 +5,6 @@ use GuzzleHttp\Client; use Mews\Pos\Entity\Account\EstPosAccount; use Mews\Pos\Entity\Card\CreditCardEstPos; -use Mews\Pos\Exceptions\NotImplementedException; use Symfony\Component\HttpFoundation\Request; /** @@ -103,9 +102,9 @@ public function __construct($config, $account, array $currencies = []) /** * @inheritDoc */ - public function createXML(array $data, $encoding = 'ISO-8859-9'): string + public function createXML(array $nodes, string $encoding = 'ISO-8859-9', bool $ignorePiNode = false): string { - return parent::createXML(['CC5Request' => $data], $encoding); + return parent::createXML(['CC5Request' => $nodes], $encoding, $ignorePiNode); } /** diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 1f9348b6..4e1ea2ea 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -128,9 +128,9 @@ public function setCard($card) /** * @inheritDoc */ - public function createXML(array $data, $encoding = 'UTF-8'): string + public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignorePiNode = false): string { - return parent::createXML(['GVPSRequest' => $data], $encoding); + return parent::createXML(['GVPSRequest' => $nodes], $encoding, $ignorePiNode); } /** diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index 331cc307..5afa7424 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -267,9 +267,9 @@ public function send($postData) /** * @inheritDoc */ - public function createXML(array $data, $encoding = 'UTF-8'): string + public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignorePiNode = false): string { - return parent::createXML(['PayforRequest' => $data], $encoding); + return parent::createXML(['PayforRequest' => $nodes], $encoding, $ignorePiNode); } diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index cf58a938..f1893478 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -131,9 +131,9 @@ public function __construct($config, $account, array $currencies) /** * @inheritDoc */ - public function createXML(array $data, $encoding = 'ISO-8859-9'): string + public function createXML(array $nodes, string $encoding = 'ISO-8859-9', bool $ignorePiNode = false): string { - return parent::createXML(['posnetRequest' => $data], $encoding); + return parent::createXML(['posnetRequest' => $nodes], $encoding, $ignorePiNode); } /** @@ -255,7 +255,7 @@ public function get3DFormData() if(isset($this->order->koiCode) && $this->order->koiCode > 0){ $inputs['useJokerVadaa'] = 1; } - + return [ 'gateway' => $this->get3DGatewayURL(), 'inputs' => $inputs, @@ -446,7 +446,7 @@ public function createRegularPaymentXML() 'cvc' => $this->card->getCvv(), ], ]; - + if(isset($this->order->koiCode) && $this->order->koiCode > 0){ $requestData[strtolower($this->type)]['koiCode'] = $this->order->koiCode; } diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index d6923f94..856e18e6 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -236,9 +236,9 @@ public static function amountFormat(float $amount): string /** * @inheritDoc */ - public function createXML(array $data, $encoding = 'UTF-8'): string + public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignorePiNode = true): string { - return parent::createXML($data, $encoding); + return parent::createXML($nodes, $encoding, $ignorePiNode); } /** diff --git a/src/PosInterface.php b/src/PosInterface.php index b8dfdb03..d7a507a7 100644 --- a/src/PosInterface.php +++ b/src/PosInterface.php @@ -27,10 +27,11 @@ public function __construct($config, $account, array $currencies); * * @param array $nodes * @param string $encoding + * @param bool $ignorePiNode when true it will not wrap it with this node * * @return string the XML, or false if an error occurred. */ - public function createXML(array $nodes, $encoding = 'UTF-8'); + public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignorePiNode = false); /** * Print Data From fd6fd27c4cc61263470cee572d00126debecb290 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 16:41:44 +0200 Subject: [PATCH 02/14] issue #60 VakifBankPos send XML data with prmstr key --- src/Gateways/VakifBankPos.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 856e18e6..72c999cb 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -244,26 +244,26 @@ public function createXML(array $nodes, string $encoding = 'UTF-8', bool $ignore /** * @inheritDoc */ - public function send($postData, $url = null) + public function send($contents, ?string $url = null) { $client = new Client(); - $url = $url ? $url : $this->getApiURL(); + $url = $url ?: $this->getApiURL(); - $isXML = is_string($postData); - $body = $isXML ? ['body' => $postData] : ['form_params' => $postData]; + $isXML = is_string($contents); + $body = $isXML ? ['form_params' => ['prmstr' => $contents]] : ['form_params' => $contents]; $response = $client->request('POST', $url, $body); - $contents = $response->getBody()->getContents(); + $responseBody = $response->getBody()->getContents(); try { - $this->data = $this->XMLStringToObject($contents); + $this->data = $this->XMLStringToObject($responseBody); } catch (NotEncodableValueException $e) { - if ($this->isHTML($contents)) { + if ($this->isHTML($responseBody)) { // if something wrong server responds with HTML content - throw new Exception($contents); + throw new Exception($responseBody); } - $this->data = (object) json_decode($contents); + $this->data = (object) json_decode($responseBody); } return $this; From a87c5826dd7ecb812fcafbd1e6efdf336196b255 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 16:42:10 +0200 Subject: [PATCH 03/14] issue #60 VakifBankPos fix 3d payment response evaluated wrong --- src/Gateways/VakifBankPos.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 72c999cb..dc2ec8a1 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -114,7 +114,7 @@ public function make3DPayment() $request = Request::createFromGlobals()->request; // 3D authorization failed - if ('Y' !== $request->get('Status') || 'A' !== $request->get('Status')) { + if ('Y' !== $request->get('Status') && 'A' !== $request->get('Status')) { $this->response = $this->map3DPaymentData($request->all(), (object) []); return $this; From 694099b4d448c095864a84355f5f038a7c8280df Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 16:42:40 +0200 Subject: [PATCH 04/14] issue #60 VakifBankPos fix undefined index errors --- src/Gateways/VakifBankPos.php | 62 ++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index dc2ec8a1..0cb07aef 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -184,7 +184,7 @@ public function get3DFormData() * E:Hata durumu */ if ('E' === $data->Message->VERes->Status) { - throw new Exception($data->ErrorMessage, $data->ErrorCode); + throw new Exception($data->ErrorMessage, $data->MessageErrorCode); } if ('N' === $data->Message->VERes->Status) { // todo devam half secure olarak devam et yada satisi iptal et. @@ -519,27 +519,17 @@ protected function mapCancelResponse($rawResponseData) */ protected function mapPaymentResponse($responseData) { - $status = 'declined'; - if ('0000' === $responseData->ResultCode) { - $status = 'approved'; + $commonResponse = $this->getCommonPaymentResponse($responseData); + if ('approved' === $commonResponse['status']) { + $commonResponse['id'] = $responseData->AuthCode; + $commonResponse['trans_id'] = $responseData->TransactionId; + $commonResponse['auth_code'] = $responseData->AuthCode; + $commonResponse['host_ref_num'] = $responseData->Rrn; + $commonResponse['order_id'] = $responseData->OrderId; + $commonResponse['transaction_type'] = $responseData->TransactionType; } - return [ - 'id' => $responseData->AuthCode, - 'trans_id' => $responseData->TransactionId, - 'auth_code' => $responseData->AuthCode, - 'host_ref_num' => $responseData->Rrn, - 'order_id' => $responseData->OrderId, - 'transaction' => $this->type, - 'transaction_type' => $responseData->TransactionType, - 'proc_return_code' => $responseData->ResultCode, - 'code' => $responseData->ResultCode, - 'status' => $status, - 'status_detail' => $responseData->ResultDetail, - 'error_code' => ('declined' === $status) ? $responseData->ResultCode : null, - 'error_message' => ('declined' === $status) ? $responseData->ResultDetail : null, - 'all' => $responseData, - ]; + return $commonResponse; } /** @@ -634,4 +624,36 @@ protected function prepareRefundOrder(array $order) return (object) $order; } + + /** + * @param $responseData + * + * @return array + */ + private function getCommonPaymentResponse($responseData): array + { + $status = 'declined'; + $resultCode = $responseData->ResultCode; + if ('0000' === $resultCode) { + $status = 'approved'; + } + + return [ + 'id' => null, + 'trans_id' => null, + 'auth_code' => null, + 'host_ref_num' => null, + 'order_id' => null, + 'transaction' => $this->type, + 'transaction_type' => null, + 'response' => null, + 'proc_return_code' => $resultCode, + 'code' => $resultCode, + 'status' => $status, + 'status_detail' => $responseData->ResultDetail, + 'error_code' => ('declined' === $status) ? $resultCode : null, + 'error_message' => ('declined' === $status) ? $responseData->ResultDetail : null, + 'all' => $responseData, + ]; + } } From 26a1293f3803eeb8ae31cdbd875d47f08c75f08c Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 21:49:44 +0200 Subject: [PATCH 05/14] issue #60 VakifBankPos fix undefined index on cancel --- src/Gateways/VakifBankPos.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 0cb07aef..9a616fdb 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -496,16 +496,17 @@ protected function mapRefundResponse($rawResponseData) protected function mapCancelResponse($rawResponseData) { $status = 'declined'; - if ('0000' === $rawResponseData->ResultCode) { + $resultCode = $rawResponseData->ResultCode; + if ('0000' === $resultCode) { $status = 'approved'; } return (object) [ - 'order_id' => $rawResponseData->TransactionId, + 'order_id' => isset($rawResponseData->TransactionId) ? $rawResponseData->TransactionId : null, 'auth_code' => ('declined' !== $status) ? $rawResponseData->AuthCode : null, 'host_ref_num' => isset($rawResponseData->Rrn) ? $rawResponseData->Rrn : null, - 'proc_return_code' => $rawResponseData->ResultCode, - 'trans_id' => $rawResponseData->TransactionId, + 'proc_return_code' => $resultCode, + 'trans_id' => isset($rawResponseData->TransactionId) ? $rawResponseData->TransactionId : null, 'error_code' => ('declined' === $status) ? $rawResponseData->ResultDetail : null, 'error_message' => ('declined' === $status) ? $rawResponseData->ResultDetail : null, 'status' => $status, From fd0ce7bf0b40f0fa66086e5153b2a006e959ea9c Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 21:50:47 +0200 Subject: [PATCH 06/14] issue #60 CreditCardVakifBank added getExpirationDateLong method --- src/Entity/Card/CreditCardVakifBank.php | 19 +++++++++++++++++++ tests/Entity/Card/CreditCardVakifBankTest.php | 1 + 2 files changed, 20 insertions(+) diff --git a/src/Entity/Card/CreditCardVakifBank.php b/src/Entity/Card/CreditCardVakifBank.php index 9bd16262..6815c17e 100644 --- a/src/Entity/Card/CreditCardVakifBank.php +++ b/src/Entity/Card/CreditCardVakifBank.php @@ -3,6 +3,7 @@ namespace Mews\Pos\Entity\Card; /** + * VakifBank credit card class for secure payments * Class CreditCardVakifBank */ class CreditCardVakifBank extends AbstractCreditCard @@ -22,6 +23,24 @@ public function getExpirationDate(): string return $this->getExpireYear().$this->getExpireMonth(); } + /** + * yyyymm de formatinda tarih dondurur + * @return string + */ + public function getExpirationDateLong(): string + { + return $this->getExpireYearLong().$this->getExpireMonth(); + } + + /** + * returns exp year in 4 digit format + * @return string + */ + public function getExpireYearLong(): string + { + return $this->expireYear->format('Y'); + } + /** * @return string */ diff --git a/tests/Entity/Card/CreditCardVakifBankTest.php b/tests/Entity/Card/CreditCardVakifBankTest.php index dfb600c6..d6111a12 100644 --- a/tests/Entity/Card/CreditCardVakifBankTest.php +++ b/tests/Entity/Card/CreditCardVakifBankTest.php @@ -12,6 +12,7 @@ public function testGetExpirationDate() { $card = new CreditCardVakifBank('1111222233334444', '02', '03', '111', 'ahmet mehmet'); $this->assertEquals('0203', $card->getExpirationDate()); + $this->assertEquals('200203', $card->getExpirationDateLong()); } public function testTypeCode() From 767fad562c58afefa508a5539a95aacd5f68b07d Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 21:52:44 +0200 Subject: [PATCH 07/14] issue #60 VakifBankPos use getExpirationDateLong for insecure payment --- src/Gateways/VakifBankPos.php | 2 +- tests/Gateways/VakifBankPosTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 9a616fdb..208a6332 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -285,7 +285,7 @@ public function createRegularPaymentXML() 'ClientIp' => $this->order->ip, 'TransactionDeviceSource' => 0, 'Pan' => $this->card->getNumber(), - 'Expiry' => $this->card->getExpirationDate(), + 'Expiry' => $this->card->getExpirationDateLong(), 'Cvv' => $this->card->getCvv(), ]; diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index 5b162bbb..8a1b0e84 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -219,7 +219,7 @@ public function testCreateRegularPaymentXML() 'ClientIp' => $order['ip'], 'TransactionDeviceSource' => 0, 'Pan' => $this->card->getNumber(), - 'Expiry' => $this->card->getExpirationDate(), + 'Expiry' => $this->card->getExpirationDateLong(), 'Cvv' => $this->card->getCvv(), ]; From ec66dd86dd7490320e894acec2267eb10d503c6d Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 21:54:01 +0200 Subject: [PATCH 08/14] issue #60 VakifBankPos fix missing request data in method create3DPaymentXML --- src/Gateways/VakifBankPos.php | 7 ++++++- tests/Gateways/VakifBankPosTest.php | 18 +++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index 208a6332..dcc7546e 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -357,6 +357,7 @@ public function create3DEnrollmentCheckData() } /** + * NOT: diger gatewaylerden farkli olarak vakifbank kredit bilgilerini bu asamada istiyor. * @inheritDoc */ public function create3DPaymentXML($responseData) @@ -366,9 +367,13 @@ public function create3DPaymentXML($responseData) 'Password' => $this->account->getPassword(), 'TerminalNo' => $this->account->getTerminalId(), 'TransactionType' => $this->type, - 'TransactionId' => $this->order->rand, + 'TransactionId' => $this->order->id, + 'CurrencyAmount' => $this->order->amount, + 'CurrencyCode' => $this->order->currency, 'CardHoldersName' => $this->card->getHolderName(), 'Cvv' => $this->card->getCvv(), + 'Pan' => $this->card->getNumber(), + 'Expiry' => $this->card->getExpirationDateLong(), 'ECI' => $responseData['Eci'], 'CAVV' => $responseData['Cavv'], 'MpiTransactionId' => $responseData['VerifyEnrollmentRequestId'], diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index 8a1b0e84..d8ce6b72 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -163,23 +163,27 @@ public function testCreate3DPaymentXML() $order = $this->order; $order['amount'] = 1000; $this->pos->prepare($order, AbstractGateway::TX_PAY, $this->card); - + $preparedOrder = $this->pos->getOrder(); $gatewayResponse = [ - 'Eci' => rand(1, 100), - 'Cavv' => rand(1, 100), - 'VerifyEnrollmentRequestId' => rand(1, 100), + 'Eci' => (string) rand(1, 100), + 'Cavv' => (string) rand(1, 100), + 'VerifyEnrollmentRequestId' => (string) rand(1, 100), ]; $expectedValue = [ 'MerchantId' => $this->account->getClientId(), 'Password' => $this->account->getPassword(), 'TerminalNo' => $this->account->getTerminalId(), 'TransactionType' => 'Sale', - 'OrderId' => $order['id'], - 'ClientIp' => $order['ip'], + 'OrderId' => $preparedOrder->id, + 'ClientIp' => $preparedOrder->ip, + 'CurrencyCode' => $preparedOrder->currency, + 'CurrencyAmount' => $preparedOrder->amount, 'OrderDescription' => '', - 'TransactionId' => $order['rand'], + 'TransactionId' => $preparedOrder->id, + 'Pan' => $this->card->getNumber(), 'Cvv' => $this->card->getCvv(), 'CardHoldersName' => $this->card->getHolderName(), + 'Expiry' => $this->card->getExpirationDateLong(), 'ECI' => $gatewayResponse['Eci'], 'CAVV' => $gatewayResponse['Cavv'], 'MpiTransactionId' => $gatewayResponse['VerifyEnrollmentRequestId'], From 2c626ce7bd0f1882f6397398743a3da6b7ee742b Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 2 Apr 2022 22:09:04 +0200 Subject: [PATCH 09/14] issue #60 VakifBankPos update code examples --- examples/_main_config.php | 19 ++- examples/vakifbank/3d/_config.php | 38 ++---- examples/vakifbank/3d/credit-card-form.php | 89 ------------- examples/vakifbank/3d/form.php | 47 +++++++ examples/vakifbank/3d/index.php | 11 ++ .../vakifbank/3d/process-credit-card-form.php | 55 -------- examples/vakifbank/3d/response.php | 124 ++---------------- examples/vakifbank/_credit_card_form.php | 60 +++++++++ examples/vakifbank/_header.php | 9 ++ examples/vakifbank/_payment_config.php | 72 ++++++++++ .../response.php => _payment_response.php} | 95 ++++++++------ examples/vakifbank/_redirect_form.php | 10 ++ examples/vakifbank/index.php | 7 + examples/vakifbank/regular/_config.php | 39 ++---- examples/vakifbank/regular/cancel.php | 13 +- .../vakifbank/regular/credit-card-form.php | 83 ------------ examples/vakifbank/regular/form.php | 18 +++ examples/vakifbank/regular/index.php | 11 ++ examples/vakifbank/regular/post-auth.php | 28 ++-- examples/vakifbank/regular/refund.php | 14 +- 20 files changed, 380 insertions(+), 462 deletions(-) delete mode 100644 examples/vakifbank/3d/credit-card-form.php create mode 100644 examples/vakifbank/3d/form.php create mode 100644 examples/vakifbank/3d/index.php delete mode 100644 examples/vakifbank/3d/process-credit-card-form.php create mode 100644 examples/vakifbank/_credit_card_form.php create mode 100644 examples/vakifbank/_header.php create mode 100644 examples/vakifbank/_payment_config.php rename examples/vakifbank/{regular/response.php => _payment_response.php} (54%) create mode 100644 examples/vakifbank/_redirect_form.php create mode 100644 examples/vakifbank/index.php delete mode 100644 examples/vakifbank/regular/credit-card-form.php create mode 100644 examples/vakifbank/regular/form.php create mode 100644 examples/vakifbank/regular/index.php diff --git a/examples/_main_config.php b/examples/_main_config.php index 514b1093..d0c3b5c8 100644 --- a/examples/_main_config.php +++ b/examples/_main_config.php @@ -3,10 +3,25 @@ ini_set('display_startup_errors', 1); error_reporting(E_ALL); -$root = realpath($_SERVER["DOCUMENT_ROOT"]); +$root = realpath(__DIR__); require_once "$root/../vendor/autoload.php"; -$redis = new Redis(); +/*$redis = new Redis(); $redis->connect('pos_redis', 6379); +$sessionHandler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler($redis); +$sessionHandler = new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([ + 'cookie_samesite' => 'None' +], $sessionHandler); +*/ + +$sessionHandler = new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([ + 'cookie_samesite' => 'None' +]); +$session = new \Symfony\Component\HttpFoundation\Session\Session($sessionHandler); +//banktan donuste eski session'a devam edemiyor, yeni session olusturuluyor +//eski session'deki order bilgiler kayboluyor. +//session id vererek, yeni session olusmasini engelliyoruz +$session->setId('mbu0tkd5vkbkksrkk824f1ib4a'); + $hostUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')."://$_SERVER[HTTP_HOST]"; diff --git a/examples/vakifbank/3d/_config.php b/examples/vakifbank/3d/_config.php index 16c27f3a..50bf5d74 100644 --- a/examples/vakifbank/3d/_config.php +++ b/examples/vakifbank/3d/_config.php @@ -1,34 +1,24 @@ getClientIp(); +$pos = getGateway($account); -try { - /** - * @var VakifBankPos $pos - */ - $pos = PosFactory::createPosGateway($account); - $pos->setTestMode(true); -} catch (BankNotFoundException $e) { - dump($e->getCode(), $e->getMessage()); -} catch (BankClassNullException $e) { - dump($e->getCode(), $e->getMessage()); -} +$transaction = \Mews\Pos\Gateways\AbstractGateway::TX_PAY; $templateTitle = '3D Model Payment'; diff --git a/examples/vakifbank/3d/credit-card-form.php b/examples/vakifbank/3d/credit-card-form.php deleted file mode 100644 index 67438ba8..00000000 --- a/examples/vakifbank/3d/credit-card-form.php +++ /dev/null @@ -1,89 +0,0 @@ - $orderId, - 'amount' => $amount, - 'installment' => $installment, - 'currency' => 'TRY', - 'success_url' => $successUrl, - 'fail_url' => $failUrl, - 'rand' => time(), - 'ip' => $ip, - - //tekrarlanan odemeler icin (optional): - 'recurringFrequency' => 3, - 'recurringFrequencyType' => 'MONTH', //DAY|MONTH|YEAR - //recurring işlemin toplamda kaç kere tekrar edeceği bilgisini içerir - 'recurringInstallmentCount' => 4, - 'recurringEndDate' => '202112', //optional -]; -?> - -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - - - - - - -
-
- -
-
- -getMethod() !== 'POST') { + echo new RedirectResponse($baseUrl.'index.php'); + exit(); +} + +$order = getNewOrder($baseUrl, $request->get('installment')); +$session->set('order', $order); + +$card = new CreditCardVakifBank( + $request->get('number'), + $request->get('year'), + $request->get('month'), + $request->get('cvv'), + $request->get('name'), + $request->get('type') +); + +/** + * provizyonu (odemeyi) tamamlamak icin tekrar kredi kart bilgileri isteniyor, bu yuzden kaydediyoruz + */ +$session->set('card', [ + 'number' => $request->get('number'), + 'year' => $request->get('year'), + 'month' => $request->get('month'), + 'cvv' => $request->get('cvv'), + 'name' => $request->get('name'), + 'type' => $request->get('type'), +]); + +$pos->prepare($order, $transaction, $card); +try { + $formData = $pos->get3DFormData(); +} catch (\Exception $e) { + dd($e); +} + +require '../_redirect_form.php'; +require '../../template/_footer.php'; diff --git a/examples/vakifbank/3d/index.php b/examples/vakifbank/3d/index.php new file mode 100644 index 00000000..498081e2 --- /dev/null +++ b/examples/vakifbank/3d/index.php @@ -0,0 +1,11 @@ +getMethod() !== 'POST') { - echo new RedirectResponse($baseUrl.'credit-card-form.php'); - exit(); -} - -$order = [ - 'id' => $_POST['order_id'], - 'name' => $_POST['name'], - 'amount' => $_POST['amount'], - 'currency' => $_POST['currency'], - 'success_url' => $_POST['success_url'], - 'fail_url' => $_POST['fail_url'], - 'rand' => $_POST['rand'], - 'ip' => $request->getClientIp(), -]; - -$redis->lPush('order', json_encode($order)); - -$card = new CreditCardVakifBank( - $request->get('number'), - $request->get('year'), - $request->get('month'), - $request->get('cvv'), - $request->get('name'), - $request->get('type') -); - -$pos->prepare($order, $_POST['transaction'], $card); -try { - $formData = $pos->get3DFormData(); -} catch (\Exception $e) { - echo $e->getMessage(); -} -?> - - Redirecting... -
- $value) : ?> - - -
- -
- -getMethod() !== 'POST') { - echo new RedirectResponse($baseUrl.'credit-card-form.php'); - exit(); -} - -$order = (array) json_decode($redis->lPop('order')); - -$pos->prepare($order, AbstractGateway::TX_PAY); -$pos->payment(); -$response = $pos->getResponse(); -?> - -
-

- isSuccess() ? 'Payment is successful!' : 'Payment is not successful'; ?> -

-
-
-
Response:
-
response ? $response->response : '-'; ?>
-
-
-
-
Status:
-
status; ?>
-
-
-
-
Transaction:
-
transaction; ?>
-
-
-
-
Transaction Type:
-
transaction_type; ?>
-
-
-
-
Transaction Security:
-
transaction_security; ?>
-
-
-
-
Hash:
-
- hash as $key => $hash) : ?> - - -
-
-
-
-
Order ID:
-
id; ?>
-
-
-
-
AuthCode:
-
auth_code ? $response->auth_code : '-'; ?>
-
-
-
-
HostRefNum:
-
host_ref_num ? $response->host_ref_num : '-'; ?>
-
-
-
-
ProcReturnCode:
-
code ? $response->code : '-'; ?>
-
-
-
-
mdStatus:
-
md_status ? $response->md_status : '-'; ?>
-
-
-
-
Error Code:
-
error_code ? $response->error_code : '-'; ?>
-
-
-
-
Error Message:
-
error_message ? $response->error_message : '-'; ?>
-
-
-
-
Md Error Message:
-
md_error_message ? $response->md_error_message : '-'; ?>
-
-
-
-
All Data Dump:
-
-
-
-
-
- -
- -get('card'); + +$card = new \Mews\Pos\Entity\Card\CreditCardVakifBank( + $savedCard['number'], + $savedCard['year'], + $savedCard['month'], + $savedCard['cvv'], + $savedCard['name'], + $savedCard['type'] +); +require '../_payment_response.php'; diff --git a/examples/vakifbank/_credit_card_form.php b/examples/vakifbank/_credit_card_form.php new file mode 100644 index 00000000..ec120a5a --- /dev/null +++ b/examples/vakifbank/_credit_card_form.php @@ -0,0 +1,60 @@ +
+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+
+
+ +
+ diff --git a/examples/vakifbank/_header.php b/examples/vakifbank/_header.php new file mode 100644 index 00000000..40efe6c4 --- /dev/null +++ b/examples/vakifbank/_header.php @@ -0,0 +1,9 @@ + +
diff --git a/examples/vakifbank/_payment_config.php b/examples/vakifbank/_payment_config.php new file mode 100644 index 00000000..def7a883 --- /dev/null +++ b/examples/vakifbank/_payment_config.php @@ -0,0 +1,72 @@ +getClientIp(); + +$installments = [ + 0 => 'Peşin', + 2 => '2 Taksit', + 6 => '6 Taksit', + 12 => '12 Taksit', +]; + +function getGateway(\Mews\Pos\Entity\Account\AbstractPosAccount $account): ?\Mews\Pos\PosInterface +{ + try { + $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account); + $pos->setTestMode(true); + + return $pos; + } catch (\Mews\Pos\Exceptions\BankNotFoundException $e) { + dump($e->getCode(), $e->getMessage()); + } catch (\Mews\Pos\Exceptions\BankClassNullException $e) { + dump($e->getCode(), $e->getMessage()); + } + + return null; +} + +function getNewOrder(string $baseUrl, string $ip, ?int $installment = 0, bool $tekrarlanan = false) +{ + $successUrl = $baseUrl.'response.php'; + $failUrl = $baseUrl.'response.php'; + + $orderId = date('Ymd').strtoupper(substr(uniqid(sha1(time())), 0, 4)); + $amount = 1.01; + + $order = [ + 'id' => $orderId, + 'amount' => $amount, + 'installment' => $installment, + 'currency' => 'TRY', + 'success_url' => $successUrl, + 'fail_url' => $failUrl, + 'rand' => time(), + 'ip' => $ip, + ]; + if ($tekrarlanan) { + $order = array_merge($order, [ + //tekrarlanan odemeler icin (optional): + 'recurringFrequency' => 3, + 'recurringFrequencyType' => 'MONTH', //DAY|MONTH|YEAR + //recurring işlemin toplamda kaç kere tekrar edeceği bilgisini içerir + 'recurringInstallmentCount' => 4, + 'recurringEndDate' => '202112', //optional + ]); + } + + return $order; +} + +$testCards = [ + 'visa1' => new \Mews\Pos\Entity\Card\CreditCardVakifBank( + '4543600299100712', + 23, + 11, + 454, + 'John Doe', + 'visa' + ), +]; diff --git a/examples/vakifbank/regular/response.php b/examples/vakifbank/_payment_response.php similarity index 54% rename from examples/vakifbank/regular/response.php rename to examples/vakifbank/_payment_response.php index 461f02d1..4e752895 100644 --- a/examples/vakifbank/regular/response.php +++ b/examples/vakifbank/_payment_response.php @@ -1,47 +1,34 @@ getMethod() !== 'POST') { - echo new RedirectResponse($baseUrl.'credit-card-form.php'); +if ($request->getMethod() !== 'POST' && AbstractGateway::TX_POST_PAY !== $transaction) { + echo new RedirectResponse($baseUrl); exit(); } -$order = (array) json_decode($redis->lPop('order')); -$transaction = AbstractGateway::TX_PAY; +$order = $session->get('order'); $pos->prepare($order, $transaction); -$card = new CreditCardVakifBank( - $request->get('number'), - $request->get('year'), - $request->get('month'), - $request->get('cvv'), - $request->get('name'), - $request->get('type') -); -try { - $pos->payment($card); -} catch (\Exception $e) { - dump($e->getMessage()); -} - -$response = $pos->getResponse(); - -if ($pos->isSuccess()) { - $redis->lPush('order', json_encode($order)); +if (AbstractGateway::TX_POST_PAY !== $transaction) { + /** + * diger banklaradan farkli olarak 3d islemler icin de Vakifbank bu asamada kredi kart bilgileri istiyor + */ + $payment = $pos->payment($card); +} else { + $payment = $pos->payment(); } +$response = $payment->getResponse(); ?>
-

isSuccess() ? 'Payment is successful!' : 'Payment is not successful!'; ?> @@ -50,6 +37,11 @@

+
+
+
Response:
+
response; ?>
+

Status:
@@ -68,38 +60,59 @@
Order ID:
-
order_id ? $response->order_id : '-'; ?>
+
order_id ?: '-'; ?>

AuthCode:
-
auth_code ? $response->auth_code : '-'; ?>
+
auth_code ?: '-'; ?>

HostRefNum:
-
host_ref_num ? $response->host_ref_num : '-'; ?>
-
-
-
-
TransactionId:
-
trans_id ? $response->trans_id : '-'; ?>
+
host_ref_num ?: '-'; ?>

ProcReturnCode:
-
code; ?>
+
code ?: '-'; ?>

Error Code:
-
error_code ? $response->error_code : '-'; ?>
+
error_code ?: '-'; ?>
-
-
Error Message:
-
error_message ? $response->error_message : '-'; ?>
+
Status Detail:
+
status_detail ?: '-'; ?>
+ getAccount()->getModel()): ?> +
+
+
Error Message:
+
error_message ?: '-'; ?>
+
+
+
mdStatus:
+
md_status ?: '-'; ?>
+
+
+
+
+
Md Error Message:
+
md_error_message ?: '-'; ?>
+
+
+
+
Transaction Security:
+
transaction_security; ?>
+
+
+
+
Hash:
+
hash; ?>
+
+
All Data Dump:
@@ -119,10 +132,8 @@ Order Status - < Click to payment form + < Click to payment form
-
" class="redirect-form" role="form"> + $value) : ?> + + +
Redirecting...
+
+
+ +
+ diff --git a/examples/vakifbank/index.php b/examples/vakifbank/index.php new file mode 100644 index 00000000..fdc1f83d --- /dev/null +++ b/examples/vakifbank/index.php @@ -0,0 +1,7 @@ +getClientIp(); - -try { - /** - * @var VakifBankPos $pos - */ - $pos = PosFactory::createPosGateway($account); - $pos->setTestMode(true); -} catch (BankNotFoundException $e) { - dump($e->getCode(), $e->getMessage()); -} catch (BankClassNullException $e) { - dump($e->getCode(), $e->getMessage()); -} +$pos = getGateway($account); $templateTitle = 'Regular Payment'; diff --git a/examples/vakifbank/regular/cancel.php b/examples/vakifbank/regular/cancel.php index 7c9bde82..a2e50bf8 100644 --- a/examples/vakifbank/regular/cancel.php +++ b/examples/vakifbank/regular/cancel.php @@ -2,17 +2,16 @@ use Mews\Pos\Gateways\AbstractGateway; -require '_config.php'; - $templateTitle = 'Cancel Order'; - +require '_config.php'; require '../../template/_header.php'; +require '../_header.php'; -$ord = (array) json_decode($redis->lPop('order')); +$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip); $order = [ - 'id' => $ord['id'], //ReferenceTransactionId - 'ip' => $ip, + 'id' => $order['id'], //ReferenceTransactionId + 'ip' => $order['ip'], ]; $pos->prepare($order, AbstractGateway::TX_CANCEL); @@ -36,7 +35,7 @@
diff --git a/examples/vakifbank/regular/credit-card-form.php b/examples/vakifbank/regular/credit-card-form.php deleted file mode 100644 index 556595ed..00000000 --- a/examples/vakifbank/regular/credit-card-form.php +++ /dev/null @@ -1,83 +0,0 @@ - $orderId, - 'amount' => $amount, - 'installment' => $installment, - 'currency' => 'TRY', - 'success_url' => $successUrl, - 'fail_url' => $failUrl, - 'rand' => time(), - 'ip' => $ip, -]; -$redis->lPush('order', json_encode($order)); -?> - -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - - - - - - -
-
- -
-
- -get('installment')); +$session->set('order', $order); +$transaction = \Mews\Pos\Gateways\AbstractGateway::TX_PAY; + +$card = new \Mews\Pos\Entity\Card\CreditCardVakifBank( + $request->get('number'), + $request->get('year'), + $request->get('month'), + $request->get('cvv'), + $request->get('name'), + $request->get('type') +); + +require '../_payment_response.php'; diff --git a/examples/vakifbank/regular/index.php b/examples/vakifbank/regular/index.php new file mode 100644 index 00000000..498081e2 --- /dev/null +++ b/examples/vakifbank/regular/index.php @@ -0,0 +1,11 @@ +lPop('order')); -/*$order = [ - 'id' => '332323', - 'amount' => 100, - 'currency' => 'TRY', - 'ip' => $ip, -];*/ +$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip); + +$order = [ + 'id' => $order['id'], + 'amount' => $order['amount'], + 'currency' => $order['currency'], + 'ip' => $order['ip'], +]; try { $pos->prepare($order, AbstractGateway::TX_POST_PAY); } catch (\Mews\Pos\Exceptions\UnsupportedTransactionTypeException $e) { - dump($e->getCode(), $e->getMessage()); + dd($e); } $pos->payment(); $response = $pos->getResponse(); - -if ($pos->isSuccess()) { - $redis->lPush('order', json_encode($order)); -} ?>
@@ -45,7 +41,7 @@ isSuccess()) : ?> < Cancel payment - < Click to payment form + < Click to payment form
diff --git a/examples/vakifbank/regular/refund.php b/examples/vakifbank/regular/refund.php index c53e4c32..80a03a8b 100644 --- a/examples/vakifbank/regular/refund.php +++ b/examples/vakifbank/regular/refund.php @@ -2,17 +2,17 @@ use Mews\Pos\Gateways\AbstractGateway; -require '_config.php'; - $templateTitle = 'Refund Order'; - +require '_config.php'; require '../../template/_header.php'; +require '../_header.php'; +$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip); // Refund Order $order = [ - 'id' => '20201101C02D', //ReferenceTransactionId - 'amount' => 100, - 'ip' => $ip, + 'id' => $order['id'], //ReferenceTransactionId + 'amount' => $order['amount'], + 'ip' => $order['ip'], ]; $pos->prepare($order, AbstractGateway::TX_REFUND); @@ -34,7 +34,7 @@
From 7cbaec23162ae8d8026801f6f90f6e7a1b07f18c Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Mon, 4 Apr 2022 22:47:38 +0200 Subject: [PATCH 10/14] VakifBankPos fix undefined index errors --- src/Gateways/VakifBankPos.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index dcc7546e..dd62ed50 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -1,6 +1,5 @@ $raw3DAuthResponseData['AuthCode'], + 'id' => null, 'eci' => $raw3DAuthResponseData['Eci'], 'cavv' => $raw3DAuthResponseData['Cavv'], 'auth_code' => null, 'order_id' => $raw3DAuthResponseData['VerifyEnrollmentRequestId'], 'status' => $threeDAuthStatus, 'status_detail' => null, - 'error_code' => 'declined' === $threeDAuthStatus ? $raw3DAuthResponseData['Status'] : null, - 'error_message' => null, + 'error_code' => 'declined' === $threeDAuthStatus ? $raw3DAuthResponseData['ErrorCode'] : null, + 'error_message' => 'declined' === $threeDAuthStatus ? $raw3DAuthResponseData['ErrorMessage'] : null, 'all' => $rawPaymentResponseData, - 'ed_all' => $raw3DAuthResponseData, + '3d_all' => $raw3DAuthResponseData, ]; if (empty($paymentResponseData)) { @@ -533,6 +532,7 @@ protected function mapPaymentResponse($responseData) $commonResponse['host_ref_num'] = $responseData->Rrn; $commonResponse['order_id'] = $responseData->OrderId; $commonResponse['transaction_type'] = $responseData->TransactionType; + $commonResponse['eci'] = $responseData->ECI; } return $commonResponse; @@ -653,6 +653,7 @@ private function getCommonPaymentResponse($responseData): array 'transaction' => $this->type, 'transaction_type' => null, 'response' => null, + 'eci' => null, 'proc_return_code' => $resultCode, 'code' => $resultCode, 'status' => $status, From 0496d13c4ee7d581951454d4687a5ff7e2c5dc0e Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Mon, 4 Apr 2022 23:03:47 +0200 Subject: [PATCH 11/14] VakifBankPos replace empty strings with NULL --- src/Gateways/VakifBankPos.php | 41 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/Gateways/VakifBankPos.php b/src/Gateways/VakifBankPos.php index dd62ed50..8c7bab04 100644 --- a/src/Gateways/VakifBankPos.php +++ b/src/Gateways/VakifBankPos.php @@ -111,25 +111,25 @@ public function setCard($card) public function make3DPayment() { $request = Request::createFromGlobals()->request; - + $gatewayResponse = $this->emptyStringsToNull($request->all()); // 3D authorization failed - if ('Y' !== $request->get('Status') && 'A' !== $request->get('Status')) { - $this->response = $this->map3DPaymentData($request->all(), (object) []); + if ('Y' !== $gatewayResponse['Status'] && 'A' !== $gatewayResponse['Status']) { + $this->response = $this->map3DPaymentData($gatewayResponse, (object) []); return $this; } - if ('A' === $request->get('Status')) { + if ('A' === $gatewayResponse['Status']) { // TODO Half 3D Secure - $this->response = $this->map3DPaymentData($request->all(), (object) []); + $this->response = $this->map3DPaymentData($gatewayResponse, (object) []); return $this; } - $contents = $this->create3DPaymentXML($request->all()); + $contents = $this->create3DPaymentXML($gatewayResponse); $this->send($contents); - $this->response = $this->map3DPaymentData($request->all(), $this->data); + $this->response = $this->map3DPaymentData($gatewayResponse, $this->data); return $this; } @@ -265,6 +265,8 @@ public function send($contents, ?string $url = null) $this->data = (object) json_decode($responseBody); } + $this->data = $this->emptyStringsToNull($this->data); + return $this; } @@ -663,4 +665,29 @@ private function getCommonPaymentResponse($responseData): array 'all' => $responseData, ]; } + + /** + * bankadan gelen response'da bos string degerler var. + * bu metod ile bos string'leri null deger olarak degistiriyoruz + * + * @param string|object|array $data + * + * @return string|object|array + */ + private function emptyStringsToNull($data) + { + if (is_string($data)) { + $data = '' === $data ? null : $data; + } elseif (is_array($data)) { + foreach ($data as $key => $value) { + $data[$key] = '' === $value ? null : $value; + } + } elseif (is_object($data)) { + foreach ($data as $key => $value) { + $data->{$key} = '' === $value ? null : $value; + } + } + + return $data; + } } From 9b838510eb455e8a6be58af2106d2f2805aabee2 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Mon, 4 Apr 2022 23:05:20 +0200 Subject: [PATCH 12/14] VakifBankPosTest added test for map3DPaymentData() method --- tests/Gateways/VakifBankPosTest.php | 159 +++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/tests/Gateways/VakifBankPosTest.php b/tests/Gateways/VakifBankPosTest.php index d8ce6b72..1ffd2b7c 100644 --- a/tests/Gateways/VakifBankPosTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -9,6 +9,7 @@ use Mews\Pos\Gateways\AbstractGateway; use Mews\Pos\Gateways\VakifBankPos; use PHPUnit\Framework\TestCase; +use ReflectionClass; use Symfony\Component\Serializer\Encoder\XmlEncoder; class VakifBankPosTest extends TestCase @@ -27,6 +28,8 @@ class VakifBankPosTest extends TestCase * @var CreditCardVakifBank */ private $card; + + /** @var array */ private $order; /** * @var XmlEncoder @@ -52,7 +55,8 @@ protected function setUp(): void 'currency' => 'TRY', 'success_url' => 'https://domain.com/success', 'fail_url' => 'https://domain.com/fail_url', - 'rand' => microtime(), + 'rand' => microtime(true), + 'extraData' => microtime(true), 'ip' => '127.0.0.1', ]; @@ -102,6 +106,7 @@ public function testCreate3DEnrollmentCheckData() 'Currency' => $order->currency, 'SuccessUrl' => $order->success_url, 'FailureUrl' => $order->fail_url, + 'SessionInfo' => $order->extraData, 'Pan' => $this->card->getNumber(), 'ExpiryDate' => $this->card->getExpirationDate(), 'BrandName' => $this->card->getCardCode(), @@ -145,6 +150,7 @@ public function testRecurringCreate3DEnrollmentCheckData() 'RecurringFrequency' => $posOrder->recurringFrequency, 'RecurringFrequencyType' => $posOrder->recurringFrequencyType, 'RecurringInstallmentCount' => $posOrder->recurringInstallmentCount, + 'SessionInfo' => $posOrder->extraData, ]; $this->assertEquals($expectedValue, $this->pos->create3DEnrollmentCheckData()); @@ -297,4 +303,155 @@ public function testCreateRefundXML() $this->assertEquals($expectedValue, $actualData); } + + /** + * @covers \Mews\Pos\Gateways\VakifBankPos::map3DPaymentData + * + * @return void + */ + public function testMap3DPaymentData3DSuccess() + { + $card = $this->card; + $order = $this->order; + $this->pos->prepare($order, AbstractGateway::TX_PAY); + $preparedOrder = (array) $this->pos->getOrder(); + $threeDResponse = [ + 'MerchantId' => $this->account->getClientId(), + 'SubMerchantNo' => $this->account->getSubMerchantId(), + 'SubMerchantName' => null, + 'SubMerchantNumber' => null, + 'PurchAmount' => $preparedOrder['amount'] * 100, + 'PurchCurrency' => $preparedOrder['currency'], + 'VerifyEnrollmentRequestId' => $preparedOrder['id'], + 'SessionInfo' => $preparedOrder['extraData'], + 'InstallmentCount' => null, + 'Pan' => $card->getNumber(), + 'Expiry' => $card->getExpirationDate(), + 'Xid' => md5(uniqid(rand(), true)), + 'Status' => 'Y', + 'Cavv' => 'AAABBBBBBBBBBBBBBBIIIIII=', + 'Eci' => '02', + 'ExpSign' => null, + 'ErrorCode' => null, + 'ErrorMessage' => null, + ]; + + $provisionResponse = [ + 'MerchantId' => $this->account->getClientId(), + 'TerminalNo' => $this->account->getTerminalId(), + 'TransactionType' => 'Sale', + 'TransactionId' => $preparedOrder['extraData'], //todo why it is equal to extraData? + 'ResultCode' => '0000', + 'ResultDetail' => 'İŞLEM BAŞARILI', + 'CustomItems' => (object) [], + 'InstallmentTable' => null, + 'CampaignResult' => null, + 'AuthCode' => '822641', + 'HostDate' => '20220404123456', + 'Rrn' => '209411062014', + 'CurrencyAmount' => $preparedOrder['amount'], + 'CurrencyCode' => $preparedOrder['currency'], + 'OrderId' => $preparedOrder['id'], + 'TLAmount' => $preparedOrder['amount'], + 'ECI' => '02', + 'ThreeDSecureType' => '2', + 'TransactionDeviceSource' => '0', + 'BatchNo' => '1', + ]; + + $method = $this->getMethod('map3DPaymentData'); + $result = $method->invoke($this->pos, $threeDResponse, (object) $provisionResponse); + + $expected = [ + 'eci' => $provisionResponse['ECI'], + 'cavv' => $threeDResponse['Cavv'], + 'auth_code' => $provisionResponse['AuthCode'], + 'order_id' => $provisionResponse['OrderId'], + 'status' => 'approved', + 'status_detail' => $provisionResponse['ResultDetail'], + 'error_code' => null, + 'error_message' => null, + 'all' => (object) $provisionResponse, + '3d_all' => $threeDResponse, + 'id' => $provisionResponse['AuthCode'], + 'trans_id' => $provisionResponse['TransactionId'], + 'host_ref_num' => $provisionResponse['Rrn'], + 'transaction' => $provisionResponse['TransactionType'], + 'transaction_type' => $provisionResponse['TransactionType'], + 'response' => null, + 'proc_return_code' => $provisionResponse['ResultCode'], + 'code' => $provisionResponse['ResultCode'], + ]; + + $this->assertEquals($expected, (array) $result); + } + + /** + * @covers \Mews\Pos\Gateways\VakifBankPos::map3DPaymentData + * + * @return void + */ + public function testMap3DPaymentData3DFail() + { + $card = $this->card; + $order = $this->order; + $this->pos->prepare($order, AbstractGateway::TX_PAY); + $preparedOrder = (array) $this->pos->getOrder(); + $threeDResponse = [ + 'MerchantId' => $this->account->getClientId(), + 'SubMerchantNo' => $this->account->getSubMerchantId(), + 'SubMerchantName' => null, + 'SubMerchantNumber' => null, + 'PurchAmount' => $preparedOrder['amount'] * 100, + 'PurchCurrency' => $preparedOrder['currency'], + 'VerifyEnrollmentRequestId' => $preparedOrder['id'], + 'SessionInfo' => $preparedOrder['extraData'], + 'InstallmentCount' => null, + 'Pan' => $card->getNumber(), + 'Expiry' => $card->getExpirationDate(), + 'Xid' => md5(uniqid(rand(), true)), + 'Status' => 'E', //diger hata durumlari N, U + 'Cavv' => 'AAABBBBBBBBBBBBBBBIIIIII=', + 'Eci' => '02', + 'ExpSign' => '', + 'ErrorCode' => '1105', + 'ErrorMessage' => 'Üye isyeri IP si sistemde tanimli degil', + ]; + + $provisionResponse = []; + + $method = $this->getMethod('map3DPaymentData'); + $result = $method->invoke($this->pos, $threeDResponse, (object) $provisionResponse); + + $expected = [ + 'eci' => $threeDResponse['Eci'], + 'cavv' => $threeDResponse['Cavv'], + 'auth_code' => null, + 'order_id' => $threeDResponse['VerifyEnrollmentRequestId'], + 'status' => 'declined', + 'status_detail' => null, + 'error_code' => $threeDResponse['ErrorCode'], + 'error_message' => $threeDResponse['ErrorMessage'], + 'all' => (object) $provisionResponse, + '3d_all' => $threeDResponse, + 'id' => null, + 'trans_id' => null, + 'host_ref_num' => null, + 'transaction_type' => 'Sale', + 'transaction' => 'Sale', + 'proc_return_code' => null, + 'code' => null, + ]; + + $this->assertEquals($expected, (array) $result); + } + + private static function getMethod(string $name): \ReflectionMethod + { + $class = new ReflectionClass(VakifBankPos::class); + $method = $class->getMethod($name); + $method->setAccessible(true); + + return $method; + } } From 67768793407e052965924d47f88ad15b01dc2c27 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Mon, 4 Apr 2022 23:08:35 +0200 Subject: [PATCH 13/14] VakifBankPos examples added extraData to order --- examples/vakifbank/3d/form.php | 2 +- examples/vakifbank/_payment_config.php | 10 ++++++++-- examples/vakifbank/regular/cancel.php | 2 +- examples/vakifbank/regular/form.php | 2 +- examples/vakifbank/regular/post-auth.php | 2 +- examples/vakifbank/regular/refund.php | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/vakifbank/3d/form.php b/examples/vakifbank/3d/form.php index d156ceee..5c782736 100644 --- a/examples/vakifbank/3d/form.php +++ b/examples/vakifbank/3d/form.php @@ -12,7 +12,7 @@ exit(); } -$order = getNewOrder($baseUrl, $request->get('installment')); +$order = getNewOrder($baseUrl, $ip, $session, $request->get('installment')); $session->set('order', $order); $card = new CreditCardVakifBank( diff --git a/examples/vakifbank/_payment_config.php b/examples/vakifbank/_payment_config.php index def7a883..15084382 100644 --- a/examples/vakifbank/_payment_config.php +++ b/examples/vakifbank/_payment_config.php @@ -28,8 +28,13 @@ function getGateway(\Mews\Pos\Entity\Account\AbstractPosAccount $account): ?\Mew return null; } -function getNewOrder(string $baseUrl, string $ip, ?int $installment = 0, bool $tekrarlanan = false) -{ +function getNewOrder( + string $baseUrl, + string $ip, + \Symfony\Component\HttpFoundation\Session\Session $session, + ?int $installment = 0, + bool $tekrarlanan = false +): array { $successUrl = $baseUrl.'response.php'; $failUrl = $baseUrl.'response.php'; @@ -45,6 +50,7 @@ function getNewOrder(string $baseUrl, string $ip, ?int $installment = 0, bool $t 'fail_url' => $failUrl, 'rand' => time(), 'ip' => $ip, + 'extraData' => $session->getId(), //optional, istekte SessionInfo degere atanir ]; if ($tekrarlanan) { $order = array_merge($order, [ diff --git a/examples/vakifbank/regular/cancel.php b/examples/vakifbank/regular/cancel.php index a2e50bf8..e1960ca7 100644 --- a/examples/vakifbank/regular/cancel.php +++ b/examples/vakifbank/regular/cancel.php @@ -7,7 +7,7 @@ require '../../template/_header.php'; require '../_header.php'; -$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip); +$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip, $session); $order = [ 'id' => $order['id'], //ReferenceTransactionId diff --git a/examples/vakifbank/regular/form.php b/examples/vakifbank/regular/form.php index d85070aa..b5bbdcf3 100644 --- a/examples/vakifbank/regular/form.php +++ b/examples/vakifbank/regular/form.php @@ -2,7 +2,7 @@ require_once '_config.php'; -$order = getNewOrder($baseUrl, $ip, $request->get('installment')); +$order = getNewOrder($baseUrl, $ip, $session, $request->get('installment')); $session->set('order', $order); $transaction = \Mews\Pos\Gateways\AbstractGateway::TX_PAY; diff --git a/examples/vakifbank/regular/post-auth.php b/examples/vakifbank/regular/post-auth.php index 382ed82e..b95fd8d7 100644 --- a/examples/vakifbank/regular/post-auth.php +++ b/examples/vakifbank/regular/post-auth.php @@ -7,7 +7,7 @@ require '../../template/_header.php'; require '../_header.php'; -$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip); +$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip, $session); $order = [ 'id' => $order['id'], diff --git a/examples/vakifbank/regular/refund.php b/examples/vakifbank/regular/refund.php index 80a03a8b..f1b0223e 100644 --- a/examples/vakifbank/regular/refund.php +++ b/examples/vakifbank/regular/refund.php @@ -7,7 +7,7 @@ require '../../template/_header.php'; require '../_header.php'; -$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip); +$order = $session->get('order') ? $session->get('order') : getNewOrder($baseUrl, $ip, $session); // Refund Order $order = [ 'id' => $order['id'], //ReferenceTransactionId From 95bfa2f4aeba8c3de23950afae4c102c265af7cd Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sat, 9 Apr 2022 13:39:01 +0200 Subject: [PATCH 14/14] updated README.md --- README.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0ff13dbc..7f4d292e 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,24 @@ Bu paket ile amaçlanan; ortak bir arayüz sınıfı ile, tüm Türk banka sanal pos sistemlerinin kullanılabilmesidir. -EST altyapısı tam olarak test edilmiş ve kullanıma hazırdır. Garanti Ödeme sistemi çalışmaktadır, fakat 3D ödeme kısmının üretim ortamında test edilmesi gerekiyor. +- **EST POS** 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. -YapıKredi Posnet sistemi 3D ödeme çalışmaktadır, fakat `cancel`, `refund` işlemleri test edilmedi. +- **YapıKredi PosNet** sistemi 3D ödeme çalışmaktadır, fakat `cancel`, `refund` işlemleri test edilmedi. -Finansbank'ın PayFor sanal pos sistemini desteklemektedir, Finansbank'ın IP kısıtlaması olmadığı için localhost'ta test `examples` klasöründeki örnek kodları çalıştırabilirsiniz. +- **Finansbank PayFor** sanal pos sistemini desteklemektedir, Finansbank'ın IP kısıtlaması olmadığı için localhost'ta test `examples` klasöründeki örnek kodları çalıştırabilirsiniz. -VakifBank GET 7/24 MPI ve VPOS 7/24 eklendi ama test ortami olmadigi icin test edilemedi, gelen geri donuslere gore hatalar giderilecek. -> EST altyapısında olan Akbank, TEB ve Ziraat bankası test edilmiştir. +- **VakifBank GET 7/24 MPI ve VPOS 7/24** 3D Secure ödemesi çalışır durumda, diğer işlemlerde sorunlar ortaya çıktıkça giderilecek. ### Özellikler - - Standart E-Commerce modeliyle ödeme (model => regular) - - 3D modeliyle ödeme (model => 3d) - - 3D Pay modeliyle ödeme (model => 3d_pay) - - Sipariş/Ödeme sorgulama (status) - - Sipariş/Ödeme geçmişi sorgulama (history) - - Sipariş/Para iadesi yapma (refund) - - Sipariş iptal etme (cancel) + - Standart E-Commerce modeliyle ödeme (model => `regular`) + - 3D Secure modeliyle ödeme (model => `3d`) + - 3D Pay modeliyle ödeme (model => `3d_pay`) + - 3D Host modeliyle ödeme (model => `3d_host`) + - Sipariş/Ödeme sorgulama (`status`) + - Sipariş/Ödeme geçmişi sorgulama (`history`) + - Sipariş/Para iadesi yapma (`refund`) + - Sipariş iptal etme (`cancel`) ### Minimum Gereksinimler - PHP >= 7.1.3