From 1dd6772cb77b1be269b38204b0767055a86f29c0 Mon Sep 17 00:00:00 2001 From: Omar Date: Sun, 27 Jun 2021 18:58:48 +0300 Subject: [PATCH 1/3] comply laravel-pos to the new interface of mews/pos --- README.md | 32 ++++++++++++++------------------ src/LaravelPos.php | 42 ++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index a66c95b..1bde9fb 100644 --- a/README.md +++ b/README.md @@ -44,20 +44,22 @@ $ php artisan vendor:publish --provider="Mews\LaravelPos\LaravelPosServiceProvid ### Kullanım ```php - $pos = \Mews\LaravelPos\Facades\LaravelPos::instance(); -$pos->account([ - 'bank' => 'akbank', - 'model' => 'regular', - 'client_id' => 'XXXXX', - 'username' => 'XXXXX', - 'password' => 'XXXXX', - 'env' => 'test', -]); +$account = \Mews\Pos\Factory\AccountFactory::createGarantiPosAccount( + 'garanti', + 'clientId', + 'username', + 'password', + 'terminalId', + 'regular', + \Mews\Pos\Gateways\GarantiPos::LANG_TR +); + +$pos->account($account); $order = [ - 'id' => 'unique-order-id-' . str_random(16), + 'id' => 'unique-order-id-' . Str::random(16), 'name' => 'John Doe', // optional 'email' => 'mail@customer.com', // optional 'user_id' => '12', // optional @@ -68,19 +70,13 @@ $order = [ 'transaction' => 'pay', // pay => Auth, pre PreAuth ]; -$card = [ - 'number' => 'XXXXXXXXXXXXXXXX', - 'month' => 'XX', - 'year' => 'XX', - 'cvv' => 'XXX', -]; +$card = new \Mews\Pos\Entity\Card\CreditCardGarantiPos('1111222233334444', '20', '01', '000'); -$pos->prepare($order); +$pos->prepare($order, \Mews\Pos\Gateways\AbstractGateway::TX_PAY); $payment = $pos->payment($card); dd($payment->response); - ``` License diff --git a/src/LaravelPos.php b/src/LaravelPos.php index 12aa019..4fed901 100644 --- a/src/LaravelPos.php +++ b/src/LaravelPos.php @@ -3,9 +3,11 @@ namespace Mews\LaravelPos; use Illuminate\Config\Repository; +use Mews\Pos\Entity\Account\AbstractPosAccount; +use Mews\Pos\Entity\Card\AbstractCreditCard; use Mews\Pos\Exceptions\BankClassNullException; use Mews\Pos\Exceptions\BankNotFoundException; -use Mews\Pos\Pos; +use Mews\Pos\Factory\PosFactory; use Mews\Pos\PosInterface; /** @@ -77,17 +79,16 @@ public function config(array $config) /** * Set account and create Pos Object * - * @param array $account + * @param AbstractPosAccount $account * @return $this * @throws BankClassNullException * @throws BankNotFoundException */ - public function account(array $account) + public function account(AbstractPosAccount $account) { $this->account = $account; - $this->pos = new Pos($this->account, $this->config); - $this->bank = $this->pos->bank; + $this->bank = PosFactory::createPosGateway($account); return $this; } @@ -95,13 +96,15 @@ public function account(array $account) /** * Prepare Order * - * @param array $order - * @param array $card + * @param array $order + * @param string $txType + * @param AbstractCreditCard|null $card + * * @return $this */ - public function prepare(array $order, array $card = []) + public function prepare(array $order, string $txType, AbstractCreditCard $card = null) { - $this->pos->prepare($order, $card); + $this->bank->prepare($order, $txType, $card); return $this; } @@ -109,14 +112,17 @@ public function prepare(array $order, array $card = []) /** * Payment * - * @param array $card + * @param AbstractCreditCard|null $card + * * @return $this + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \Mews\Pos\Exceptions\UnsupportedPaymentModelException */ - public function payment(array $card = []) + public function payment(AbstractCreditCard $card = null) { - $this->pos->payment($card); + $this->bank->payment($card); - $this->response = $this->pos->bank->response; + $this->response = $this->bank->getResponse(); return $this; } @@ -128,7 +134,7 @@ public function payment(array $card = []) */ public function getGatewayUrl() { - return $this->pos->bank->gateway ?? 'null'; + return $this->bank->gateway ?? 'null'; } /** @@ -141,8 +147,8 @@ public function get3dFormData() $data = []; try { - $data = $this->pos->bank->get3dFormData(); - } catch (Exception $e) {} + $data = $this->bank->get3dFormData(); + } catch (\Exception $e) {} return $data; } @@ -154,7 +160,7 @@ public function get3dFormData() */ public function isSuccess() { - return $this->pos->bank->isSuccess(); + return $this->bank->isSuccess(); } /** @@ -164,6 +170,6 @@ public function isSuccess() */ public function isError() { - return $this->pos->bank->isError(); + return $this->bank->isError(); } } From 32707c57444a1416bbeb3065acd0a871dd43df89 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 28 Jun 2021 15:21:17 +0300 Subject: [PATCH 2/3] add account and card factories, add missing banks to configuration --- config/laravel-pos.php | 82 ++++++++++++++++++++++++++++++---- src/Factory/AccountFactory.php | 77 +++++++++++++++++++++++++++++++ src/Factory/CardFactory.php | 46 +++++++++++++++++++ src/LaravelPos.php | 42 ++++++++++++----- 4 files changed, 228 insertions(+), 19 deletions(-) create mode 100644 src/Factory/AccountFactory.php create mode 100644 src/Factory/CardFactory.php diff --git a/config/laravel-pos.php b/config/laravel-pos.php index 4936cf0..b18515f 100644 --- a/config/laravel-pos.php +++ b/config/laravel-pos.php @@ -16,7 +16,7 @@ 'banks' => [ 'akbank' => [ 'name' => 'AKBANK T.A.S.', - 'class' => \Mews\Pos\EstPos::class, + 'class' => Mews\Pos\Gateways\EstPos::class, 'urls' => [ 'production' => 'https://www.sanalakpos.com/fim/api', 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api', @@ -28,7 +28,7 @@ ], 'ziraat' => [ 'name' => 'Ziraat Bankası', - 'class' => \Mews\Pos\EstPos::class, + 'class' => Mews\Pos\Gateways\EstPos::class, 'urls' => [ 'production' => 'https://sanalpos2.ziraatbank.com.tr/fim/api', 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api', @@ -38,9 +38,45 @@ ], ] ], + 'finansbank' => [ + 'name' => 'QNB Finansbank', + 'class' => Mews\Pos\Gateways\EstPos::class, + 'urls' => [ + 'production' => 'https://www.fbwebpos.com/fim/api', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api', + 'gateway' => [ + 'production' => 'https://www.fbwebpos.com/fim/est3dgate', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', + ], + ] + ], + 'halkbank' => [ + 'name' => 'Halkbank', + 'class' => Mews\Pos\Gateways\EstPos::class, + 'urls' => [ + 'production' => 'https://sanalpos.halkbank.com.tr/fim/api', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api', + 'gateway' => [ + 'production' => 'https://sanalpos.halkbank.com.tr/fim/est3dgate', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', + ], + ] + ], + 'teb' => [ + 'name' => 'TEB', + 'class' => Mews\Pos\Gateways\EstPos::class, + 'urls' => [ + 'production' => 'https://sanalpos.teb.com.tr/fim/api', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api', + 'gateway' => [ + 'production' => 'https://sanalpos.teb.com.tr/fim/est3Dgate', + 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', + ], + ] + ], 'isbank' => [ 'name' => 'İşbank', - 'class' => \Mews\Pos\EstPos::class, + 'class' => Mews\Pos\Gateways\EstPos::class, 'urls' => [ 'production' => 'https://sanalpos.isbank.com.tr/fim/api', 'test' => 'https://entegrasyon.asseco-see.com.tr/fim/api', @@ -52,19 +88,19 @@ ], 'yapikredi' => [ 'name' => 'Yapıkredi', - 'class' => \Mews\Pos\PosNet::class, + 'class' => Mews\Pos\Gateways\PosNet::class, 'urls' => [ 'production' => 'https://posnet.yapikredi.com.tr/PosnetWebService/XML', - 'test' => 'http://setmpos.ykb.com/PosnetWebService/XML', + 'test' => 'https://setmpos.ykb.com/PosnetWebService/XML', 'gateway' => [ - 'production' => 'http://posnet.ykb.com/3DSWebService/YKBPaymentService', - 'test' => 'http://setmpos.ykb.com/3DSWebService/YKBPaymentService', + 'production' => 'https://posnet.yapikredi.com.tr/3DSWebService/YKBPaymentService', + 'test' => 'https://setmpos.ykb.com/3DSWebService/YKBPaymentService', ], - ] + ], ], 'garanti' => [ 'name' => 'Garanti', - 'class' => \Mews\Pos\GarantiPos::class, + 'class' => Mews\Pos\Gateways\GarantiPos::class, 'urls' => [ 'production' => 'https://sanalposprov.garanti.com.tr/VPServlet', 'test' => 'https://sanalposprovtest.garanti.com.tr/VPServlet', @@ -74,6 +110,34 @@ ], ] ], + 'qnbfinansbank-payfor' => [ + 'name' => 'QNBFinansbank-PayFor', + 'class' => Mews\Pos\Gateways\PayForPos::class, + 'urls' => [ + 'production' => 'https://vpos.qnbfinansbank.com/Gateway/XMLGate.aspx', + 'test' => 'https://vpostest.qnbfinansbank.com/Gateway/XmlGate.aspx', + 'gateway' => [ + 'production' => 'https://vpos.qnbfinansbank.com/Gateway/Default.aspx', + 'test' => 'https://vpostest.qnbfinansbank.com/Gateway/Default.aspx', + ], + 'gateway_3d_host' => [ + 'production' => 'https://vpos.qnbfinansbank.com/Gateway/3DHost.aspx', + 'test' => 'https://vpostest.qnbfinansbank.com/Gateway/3DHost.aspx', + ], + ] + ], + 'vakifbank' => [ + 'name' => 'VakifBank-VPOS', + 'class' => Mews\Pos\Gateways\VakifBankPos::class, + 'urls' => [ + 'production' => 'https://onlineodeme.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx', + 'test' => 'https://onlineodemetest.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx', + 'gateway' => [ + 'production' => 'https://3dsecure.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspx', + 'test' => 'https://3dsecuretest.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspx', + ], + ], + ], ], ]; diff --git a/src/Factory/AccountFactory.php b/src/Factory/AccountFactory.php new file mode 100644 index 0000000..563b243 --- /dev/null +++ b/src/Factory/AccountFactory.php @@ -0,0 +1,77 @@ + EstPosAccount::class, + 'ziraat' => EstPosAccount::class, + 'isbank' => EstPosAccount::class, + 'finansbank' => EstPosAccount::class, + 'halkbank' => EstPosAccount::class, + 'teb' => EstPosAccount::class, + 'yapikredi' => PosNetAccount::class, + 'garanti' => GarantiPosAccount::class, + 'qnbfinansbank-payfor' => PayForAccount::class, + 'vakifbank' => VakifBankAccount::class, + ]; + + public static function create(array $account) + { + $class = self::ACCOUNTS[$account['bank']] ?? null; + + if (! $class) { + throw new BankNotFoundException(); + } + + $params = [ + $account['bank'], + $account['model'], + $account['client_id'], + ]; + + if ($account['bank'] != 'vakifbank') { + $params[] = $account['username']; + } + + $params[] = $account['password']; + + if ($account['bank'] != 'vakifbank') { + $params[] = $account['lang'] ?? 'tr'; + } + + switch ($account['bank']) { + case "garanti": + $params[] = $account['terminal_id']; + $params[] = $account['store_key'] ?? null; + $params[] = $account['refund_username'] ?? null; + $params[] = $account['refund_password'] ?? null; + break; + case "yapikredi": + $params[] = $account['terminal_id']; + $params[] = $account['pos_net_id']; + $params[] = $account['store_key']; + break; + case "vakifbank": + $params[] = $account['terminal_id']; + $params[] = $account['merchant_type'] ?? 0; + $params[] = $account['sub_merchant_id'] ?? null; + } + + if ($account['bank'] != 'vakifbank') { + $params[] = $account['store_key'] ?? null; + } + + return new $class(...$params); + } +} \ No newline at end of file diff --git a/src/Factory/CardFactory.php b/src/Factory/CardFactory.php new file mode 100644 index 0000000..b760da8 --- /dev/null +++ b/src/Factory/CardFactory.php @@ -0,0 +1,46 @@ + CreditCardEstPos::class, + 'ziraat' => CreditCardEstPos::class, + 'isbank' => CreditCardEstPos::class, + 'finansbank' => CreditCardEstPos::class, + 'halkbank' => CreditCardEstPos::class, + 'teb' => CreditCardEstPos::class, + 'yapikredi' => CreditCardPosNet::class, + 'garanti' => CreditCardGarantiPos::class, + 'qnbfinansbank-payfor' => CreditCardPayFor::class, + 'vakifbank' => CreditCardVakifBank::class, + ]; + + public static function create(array $card) + { + $class = self::CARDS[$card['bank']]; + + if (! $class) { + throw new BankNotFoundException(); + } + + $number = $card['number']; + $expireMonth = $card['month']; + $expireYear = $card['year']; + $cvv = $card['cvv']; + $cardHolderName = $card['name'] ?? null; + $cardType = $card['type'] ?? null; + + return new $class($number, $expireYear, $expireMonth, $cvv, $cardHolderName, $cardType); + } +} \ No newline at end of file diff --git a/src/LaravelPos.php b/src/LaravelPos.php index 4fed901..d66d756 100644 --- a/src/LaravelPos.php +++ b/src/LaravelPos.php @@ -3,8 +3,8 @@ namespace Mews\LaravelPos; use Illuminate\Config\Repository; -use Mews\Pos\Entity\Account\AbstractPosAccount; -use Mews\Pos\Entity\Card\AbstractCreditCard; +use Mews\LaravelPos\Factory\AccountFactory; +use Mews\LaravelPos\Factory\CardFactory; use Mews\Pos\Exceptions\BankClassNullException; use Mews\Pos\Exceptions\BankNotFoundException; use Mews\Pos\Factory\PosFactory; @@ -43,6 +43,8 @@ class LaravelPos */ public $response; + public $bankName; + /** * Constructor * @@ -67,6 +69,7 @@ public function instance() * Set custom configuration * * @param array $config + * * @return LaravelPos */ public function config(array $config) @@ -79,31 +82,46 @@ public function config(array $config) /** * Set account and create Pos Object * - * @param AbstractPosAccount $account + * @param array $account + * * @return $this * @throws BankClassNullException * @throws BankNotFoundException */ - public function account(AbstractPosAccount $account) + public function account(array $account) { + $env = $account['env'] ?? null; + + $this->bankName = $account['bank']; + + $account = AccountFactory::create($account); + $this->account = $account; $this->bank = PosFactory::createPosGateway($account); + if ($env == 'test') { + $this->bank->setTestMode(true); + } + return $this; } /** * Prepare Order * - * @param array $order - * @param string $txType - * @param AbstractCreditCard|null $card + * @param array $order + * @param string $txType + * @param array|null $card * * @return $this */ - public function prepare(array $order, string $txType, AbstractCreditCard $card = null) + public function prepare(array $order, string $txType, array $card = null) { + $card['bank'] = $this->bankName; + + $card = CardFactory::create($card); + $this->bank->prepare($order, $txType, $card); return $this; @@ -112,14 +130,18 @@ public function prepare(array $order, string $txType, AbstractCreditCard $card = /** * Payment * - * @param AbstractCreditCard|null $card + * @param array|null $card * * @return $this * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Mews\Pos\Exceptions\UnsupportedPaymentModelException */ - public function payment(AbstractCreditCard $card = null) + public function payment(array $card = null) { + $card['bank'] = $this->bankName; + + $card = CardFactory::create($card); + $this->bank->payment($card); $this->response = $this->bank->getResponse(); From 772132131850bc4b5c861a4e6d003cb9bc8e53a0 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 28 Jun 2021 15:23:51 +0300 Subject: [PATCH 3/3] update readme --- README.md | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1bde9fb..7011452 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ [Pos](https://github.com/mewebstudio/pos) ### Minimum Gereksinimler - - PHP >= 7.1.3 - - ext-dom - - ext-json - - ext-openssl - - ext-SimpleXML +- PHP >= 7.1.3 +- ext-dom +- ext-json +- ext-openssl +- ext-SimpleXML ### Kurulum ```sh @@ -44,22 +44,20 @@ $ php artisan vendor:publish --provider="Mews\LaravelPos\LaravelPosServiceProvid ### Kullanım ```php -$pos = \Mews\LaravelPos\Facades\LaravelPos::instance(); -$account = \Mews\Pos\Factory\AccountFactory::createGarantiPosAccount( - 'garanti', - 'clientId', - 'username', - 'password', - 'terminalId', - 'regular', - \Mews\Pos\Gateways\GarantiPos::LANG_TR -); +$pos = \Mews\LaravelPos\Facades\LaravelPos::instance(); -$pos->account($account); +$pos->account([ + 'bank' => 'akbank', + 'model' => 'regular', + 'client_id' => 'XXXXX', + 'username' => 'XXXXX', + 'password' => 'XXXXX', + 'env' => 'test', +]); $order = [ - 'id' => 'unique-order-id-' . Str::random(16), + 'id' => 'unique-order-id-' . str_random(16), 'name' => 'John Doe', // optional 'email' => 'mail@customer.com', // optional 'user_id' => '12', // optional @@ -70,13 +68,19 @@ $order = [ 'transaction' => 'pay', // pay => Auth, pre PreAuth ]; -$card = new \Mews\Pos\Entity\Card\CreditCardGarantiPos('1111222233334444', '20', '01', '000'); +$card = [ + 'number' => 'XXXXXXXXXXXXXXXX', + 'month' => 'XX', + 'year' => 'XX', + 'cvv' => 'XXX', +]; -$pos->prepare($order, \Mews\Pos\Gateways\AbstractGateway::TX_PAY); +$pos->prepare($order); $payment = $pos->payment($card); dd($payment->response); + ``` License