From c907a912d9f1939a4035e0d70bf6207cb988e6fa Mon Sep 17 00:00:00 2001 From: Milad Kianmehr Date: Sun, 29 Dec 2019 15:12:39 +0330 Subject: [PATCH 1/4] add new field to store user additional params --- .../migrations/create_larapay_transaction_table.php.stub | 2 +- src/Models/LarapayTransaction.php | 8 ++++---- src/Payable.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/database/migrations/create_larapay_transaction_table.php.stub b/database/migrations/create_larapay_transaction_table.php.stub index fc44dc3..5bcd361 100644 --- a/database/migrations/create_larapay_transaction_table.php.stub +++ b/database/migrations/create_larapay_transaction_table.php.stub @@ -40,7 +40,7 @@ class CreateLarapayTransactionTable extends Migration $table->text('description')->nullable(); $table->bigInteger('amount')->default(0); $table->jsonb('extra_params')->nullable()->default('{}'); - $table->jsonb('gateway_properties')->nullable()->default('{}'); + $table->jsonb('additional_data')->nullable()->default('{}'); $table->dateTime('paid_at')->nullable(); $table->timestamps(); diff --git a/src/Models/LarapayTransaction.php b/src/Models/LarapayTransaction.php index 3b1a103..66274b1 100644 --- a/src/Models/LarapayTransaction.php +++ b/src/Models/LarapayTransaction.php @@ -102,10 +102,10 @@ public function reverseTransaction() return true; } - public function generateForm($autoSubmit = false, $callback = null) + public function generateForm($autoSubmit = false, $callback = null, $adapterConfig = []) { - $paymentGatewayHandler = $this->gatewayHandler(); + $paymentGatewayHandler = $this->gatewayHandler($adapterConfig); $callbackRoute = route(config("larapay.payment_callback"), [ 'gateway' => $this->gate_name, @@ -140,9 +140,9 @@ public function generateForm($autoSubmit = false, $callback = null) } } - public function gatewayHandler() + public function gatewayHandler($adapterConfig = []) { - return Larapay::make($this->gate_name, $this, json_decode($this->gateway_properties, true)); + return Larapay::make($this->gate_name, $this, json_decode($adapterConfig, true)); } } \ No newline at end of file diff --git a/src/Payable.php b/src/Payable.php index 1bf934b..5eb4653 100644 --- a/src/Payable.php +++ b/src/Payable.php @@ -45,7 +45,7 @@ public function createTransaction( $paymentGateway, $amount = null, $description = null, - array $adapterConfig = [] + array $additionalData = [] ) { $transactionData = []; @@ -66,7 +66,7 @@ public function createTransaction( $transactionData['submitted'] = true; $transactionData['bank_order_id'] = $this->generateBankOrderId($paymentGateway); $transactionData['payment_method'] = 'ONLINE'; - $transactionData['gateway_properties'] = json_encode($adapterConfig, JSON_UNESCAPED_UNICODE); + $transactionData['additional_data'] = json_encode($additionalData, JSON_UNESCAPED_UNICODE); $transaction = $this->transactions()->create($transactionData); From 3b0dc159715ec0ef03278420ffe46ad075ce97e6 Mon Sep 17 00:00:00 2001 From: Milad Kianmehr Date: Sun, 29 Dec 2019 15:21:41 +0330 Subject: [PATCH 2/4] update docs --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7ee6ecd..3b39582 100644 --- a/README.md +++ b/README.md @@ -145,15 +145,19 @@ class BankController extends Controller $amount = 1200000; //Rial at least 1000 //order or user description $description = 'I pay my order with Larapay <3'; + //some additional data that you need store on transaction + $additionalData = []; //create transaction - $transaction = $order->createTransaction(Bank::MELLAT, $amount, $description); + $transaction = $order->createTransaction(Bank::MELLAT, $amount, $description, $additionalData); //auto submit bank form and transfer user to gateway $autoSubmit = true; //callback route name. if you set it on your .env file you can set this to null $callbackRouteName = 'payment.callback'; + //adapter config + $adapterConfig = []; //generate bank form - $form = $transaction->generateForm($autoSubmit, $callbackRouteName); + $form = $transaction->generateForm($autoSubmit, $callbackRouteName, $adapterConfig); return view('go-to-bank',[ 'form' => $form, @@ -217,7 +221,7 @@ $transaction->reverseTransaction(); $paymentGateway, $amount = null, $description = null, - array $adapterConfig = [] + array $additionalData = [] )`: create a transaction. @@ -249,7 +253,7 @@ Status in boolean: * `gate_refid` * `gate_status` * `extra_params` - * `gateway_properties` + * `additional_data` Order information: * `amount` From 81f8ee6852b368113f364ef7d9d1ecd5cf8573e4 Mon Sep 17 00:00:00 2001 From: Milad Kianmehr Date: Sun, 29 Dec 2019 15:26:49 +0330 Subject: [PATCH 3/4] add adapter config to verify transaction --- README-old.md | 783 ------------------------------ README.md | 3 +- src/Factory.php | 5 +- src/Models/LarapayTransaction.php | 2 +- 4 files changed, 5 insertions(+), 788 deletions(-) delete mode 100644 README-old.md diff --git a/README-old.md b/README-old.md deleted file mode 100644 index 27e6e2b..0000000 --- a/README-old.md +++ /dev/null @@ -1,783 +0,0 @@ -# LaraPay :: Laravel Online Payment Component - -Online Payment Module handler for Laravel 5+ known as LaraPay component completely compatible with [banktest.ir](http://banktest.ir) simulator - -پکیج لاراپی یک کامپونتت لاراول برای اتصال به درگاه های پرداخت ایرانی و انجام تراکنشهای آنلاین است. معماری این پکیج به شما اجازه می دهد به سادگی درگاه -های جدید به پکیج اضافه کنید. همچنین در صورت استفاده از پکیج لاراپی شما نیاز به انجام کمترین تغییرات در ساختار کد خود خواهید داشت و با ویرایش تنها یک مدل در پروژه لاراول خود می توانید با پکیج لاراپی هماهنگ شوید. - -پکیج لاراپی کاملا همانگ با سرویس شبیه ساز درگاه های پرداخت ایرانی »بانک تست« طراحی شده و شما میتوانید تنها با تغییر یک پارامتر در تنظمیات پکیج محیط پرداخت خود را از یک درگاه واقعی به درگاه پرداخت شبیه سازی شده ی »بانک تست« تغییر دهید. - -## What is B‌anktest? -- [BankTest](http://banktest.ir) is a sandbox service for all Iranian online payment gateways -- [بانک تست](http://banktest.ir) یک سرویس شبیه ساز درگاه های پرداخت آنلاین ایرانی برای اهداف توسعه و تست نرم افزار می باشد - - -## Currenctly support: - -- Mellat Bank Gateway - درگاه بانک ملت لاراول -- Saman Bank Gateway - درگاه بانک سامان لاراول -- Saderat/Mabna Card Bank Gateway - درگاه بانک صادرات / مبناکارت لاراول -- Pasargad Bank Gateway - درگاه بانک پاسارگاد لاراول -- Parsian Bank Gateway - درگاه بانک پارسیان لاراول -- Melli/Sadad Bank Gateway (Sadad) - درگاه بانک ملی / سداد لاراول -- Pay.ir Gateway / درگاه پرداخت پی -- ... -- Other gateways, coming soon... لطفا شما هم در تکمیل پکیج مشارکت کنید - - -## Vote Up -Please star the repository if you like it -لطفا در صورتیکه از لاراپی استفاده کردید یا آن را پسندیدید به پکیج ستاره بدهید - -## Installation - -### [Part 1] -- Install the Larapay package - -Larapay Version 6+ required PHP 7+ - -1. Installing via composer - -```bash -composer require tartan/laravel-online-payment -``` -2. Add package service provider to your app service providers: - -```php -Tartan\Larapay\LarapayServiceProvider::class, -``` -3. Add package alias to your app aliases: - -```php -'Larapay' => Tartan\Larapay\Facades\Larapay::class, -``` -4. Publish package assets and configs - -```bash -php artisan vendor:publish --provider="Tartan\Larapay\LarapayServiceProvider" -``` - -## [Part 2] -- Config Larapay - -1. config Larapay package and set variables in your project's `.env` file -```ini -LARAPAY_MODE=development - -MELLAT_USERNAME=yourMerchantUsername -MELLAT_PASSWORD=yourMerchantPassword -MELLAT_TERMINAL_ID=12345 -``` - -You can find all available configuration in package config file at config/larapay.php - -```php - -return [ - - /* - |-------------------------------------------------------------------------- - | Tartan e-payment component`s operation mode - |-------------------------------------------------------------------------- - | - | *** very important config *** - | please do not change it if you don't know what BankTest is - | > production: component operates with real payments gateways - | > development: component operates with simulated "BankTest" (banktest.ir) gateways - | - */ - 'mode' => env('LARAPAY_MODE', 'production'), - - /* - |-------------------------------------------------------------------------- - | ready to serve gateways - |-------------------------------------------------------------------------- - | - | specifies ready to serve gateways. - | gateway characters are case sensitive and should be exactly same as their folder name. - | eg, "Jahanpay" is correct not "JahanPay" or "jahanpay" - | the gateways list is comma separated - | - */ - 'gateways' => env('LARAPAY_GATES', 'Mellat,Saman,Pasargad'), - - /* - |-------------------------------------------------------------------------- - | Mellat gateway configuration - |-------------------------------------------------------------------------- - */ - 'mellat' => [ - 'username' => env('MELLAT_USERNAME', ''), - 'password' => env('MELLAT_PASSWORD',''), - 'terminal_id' => env('MELLAT_TERMINAL_ID', ''), - ], - - /* - |-------------------------------------------------------------------------- - | Parsian gateway configuration - |-------------------------------------------------------------------------- - */ - 'parsian' => [ - 'pin' => env('PARSIAN_PIN', ''), - ], - /* - |-------------------------------------------------------------------------- - | Pasargad gateway configuration - |-------------------------------------------------------------------------- - */ - 'pasargad' => [ - 'terminalId' => env('PASARGAD_TERMINAL_ID', ''), - 'merchantId' => env('PASARGAD_MERCHANT_ID', ''), - 'certificate_path' => storage_path(env('PASARGAD_CERT_PATH', 'payment/pasargad/certificate.xml')), - ], - - /* - |-------------------------------------------------------------------------- - | Sadad gateway configuration - |-------------------------------------------------------------------------- - */ - 'sadad' => [ - 'merchant' => env('SADAD_MERCHANT', ''), - 'transaction_key' => env('SADAD_TRANS_KEY', ''), - 'terminal_id' => env('SADAD_TERMINAL_ID', ''), - ], - - 'saderat' => [ - 'MID' => env('SADERAT_MID', ''), - 'TID' => env('SADERAT_TID', ''), - 'public_key_path' => storage_path(env('SADERAT_CERT_PATH', 'payment/saderat/public.key')), - 'private_key_path' => storage_path(env('SADERAT_CERT_PATH', 'payment/saderat/private.key')), - ], - - /* - |-------------------------------------------------------------------------- - | Saman gateway configuration - |-------------------------------------------------------------------------- - */ - 'saman' => [ - 'merchant_id' => env('SAMAN_MERCHANT_ID', ''), - 'merchant_pass' => env('SAMAN_MERCHANT_PASS', ''), - ], - - /* - |-------------------------------------------------------------------------- - | Zarinpal gateway configuration - |-------------------------------------------------------------------------- - | - | types: acceptable values --- zarin-gate or normal - | server: acceptable values --- germany or iran or test - | - */ - 'zarinpal' => [ - 'merchant_id' => env('ZARINPAL_MERCHANT_ID', ''), - 'type' => env('ZARINPAL_TYPE', 'zarin-gate'), - 'server' => env('ZARINPAL_SERVER', 'germany'), - 'email' => env('ZARINPAL_EMAIL', ''), - 'mobile' => env('ZARINPAL_MOBILE', '09xxxxxxxxx'), - 'description' => env('ZARINPAL_MOBILE', 'powered-by-TartanPayment'), - ], - /* - |-------------------------------------------------------------------------- - | Pay.ir gateway configuration - |-------------------------------------------------------------------------- - */ - 'pay_ir' => [ - 'api' => env('PAY_IR_API_KEY', ''), - ], - - /* - |-------------------------------------------------------------------------- - | SoapClient Options - |-------------------------------------------------------------------------- - | - | useOptions: true/false - | options: soapClient Options - | - */ - 'soap' => [ - 'useOptions' => env('SOAP_HAS_OPTIONS', false), - 'options' => [ - 'proxy_host' => env('SOAP_PROXY_HOST', ''), - 'proxy_port' => env('SOAP_PROXY_PORT', ''), - 'stream_context' => stream_context_create( - [ - 'ssl' => [ - 'verify_peer' => false, - 'verify_peer_name' => false, - ], - ] - ), - ] - ] -]; -``` - - - -### [Part 3] -- Prepare your transaction/invoice model -1. Preparing your db (eloquent) model for larapay integration - - * Your Transaction/Invoice model MUST implements Larapay's TransactionInterface class - -```php -input('payment_gateway'); - - // Your desired transaction/invoice id. for example: 10 - $transaction = Trannsaction::find($request->input('transaction_id')); - - /** - * make larapay payment gateway instance - * example: $paymentGatewayHandler = Larapay::make('saman', $transaction); - **/ - $paymentGatewayHandler = Larapay::make($paymentGateway, $transaction); - - - // set payment params - $paymentParams = [ - 'order_id' => $transaction->getBankOrderId(), // شماره تراکنش/فاکتور برای ارسال به درگاه پرداخت - 'redirect_url' => route('payment.callback', [ // نمونه ایجاد url برگشت بعد از پرداخت - 'bank' => $paymentGateway, - 'transactionId' => $transaction->id - ]), - 'amount' => $transaction->amount, // مبلغ تراکنش/فاکتور برای ارسال به درگاه به ریال - 'submit_label' => trans('larapay::larapay.goto_gate') // متن دلخواه دکمه ی انتقال به درگاه پرداخت - ]; - - try { - // get goto gate form - // دریافت فرم از طریق لاراپی - - $form = $paymentGatewayHandler->form($paymentParams); - } catch (\Exception $e) { - // could not generate goto gate form - // در صورتیکه خطایی در ایجاد فرم ایجاد شود خطای مربوطه لاگ شده و پیغام خطا به کاربر نمایش داده شود - - Log::emergency($paymentGateway . ' #' . $e->getCode() . '-' . $e->getMessage()); - Session::flash('alert-danger', trans('trans.could_not_create_goto_bank_form', ['gateway' => $paymentGateway])); - - return redirect()->back()->withInput(); - } - - if (is_null($form)) { - // اگر به هر دلیلی فرم درست ایجاد نشده بود و برنامه قادر به ادامه عملیات پرداخت نبود - return redirect()->back()->withInput(); - } - - - // view goto gate form/view - // نمایش صفحه انتقال به درگاه پرداخت به کاربر - return view('gateway.gotogate', [ - 'gateway' => $paymentGateway, - 'form' => $form, - ]); - } - - - /** - * - * sample rendered form by Larapay that passed to $form variable - * نمونه فرم ایجاد شده توسط لاراپی برای درگاه بانک ملت * - * -
- -
-
- -
-
-
- **/ -``` -2. Prepare your view file - -example: `resources/views/gateway.gotogate.blade.php` -فرم تولید شده توسط کامپوننت لاراپی را داخل ویو نمایش دهید تا کاربر بتوانید دکمه انتقال به درگاه پرداخت را دیده و روی آن کلیک کند - -```php -
- {!! $form !!} -
-``` - -- If you want to hide the submit form from the user and redirect him/her to payment gateway directly you can use javascript in same view and submit the form without any user action -اگر میخواهید فرم انتقال به درگاه پرداخت به کاربر نمایش داده نشود میتوانید فرم تولید شده را بصورت اتوماتیک توسط جاوا اسکریپت سابمیت کنید و دکمه انتقال به درگاه بانک هم توسط سی اس اس مخفی نمایید مانند مثال زیر - -```html - - - -``` - -در این مرحله عملا شما کاربر را به درگاه پرداخت منتقل کرده اید و باید بخش برگشت کاربر از درگاه پرداخت به سایت را مطابق مراحل زیر آماده کنید - -### [Part 5] -- Prepare an online payment requirement in your app - -1. In order to verify or reverse the transaction you shoul prepare ac action as callback action - -قبل از هر چیز یک روت بعنوان روت برگشت کاربر از درگاه پرداخت به سایت ایجاد کنید. -این روت باید هر دو متد پست و گت را پشتیبانی کند و از چک شدن سی اس آر اف در آن نیز جلوگیری کنید و همچنین ترجیحا این روت نباید احراز هویت کاربر را چک کند -بعنوان مثال: - -```php -// gateway callback route -Route::any('/{gateway}/callback/{invoiceId}', ['as' => 'payment::callback', 'uses' => 'GatewayController@callback']); -``` -2. Create callback action in your desired controller -در این اکشن شما باید تراکنش کاربر را با درگه پرداخت تایید کنید و در صورتیکه نتوانستید به مشتری خدمات بدهید تراکنش کاربر را مرجوع کنید. -دقت کنید که تمام درگاه های پرداخت مرجوعی تراکنش را پشتیبانی نمی کنند -```php -all()); - - $referenceId = ''; - $paidTime = ''; - $amount = ''; - - do { - try { - - $validator = Validator::make([ - 'transactionId' => $transactionId, - 'gateway' => $gateway, - ], [ - 'transactionId' => [ - 'required', - 'numeric', - ], - 'gateway' => [ - 'required', - 'exists:gateways,name' - ], - ]); - - // validate required route parameters - if ($validator->fails()) { - return view('gateway.callback')->withErrors([__('Code N1 - Transaction not found')]); - } - - // find the transaction by token - $transaction = $transaction->find($transactionId); - if (!$transaction) { - return view('gateway.callback')->withErrors([__('Code N2 - Transaction not found')]); - } - - $gateway = Gateway::fingByName($gateway); - - // basic check - if ($transaction->bank != $gateway->bank) { - return view('gateway.callback')->withErrors([__('Code N3 - Transaction not found')]); - } - - // update transaction`s callback parameter - $transaction->setCallBackParameters($request->all()); - - // load payment gateway properties - $gatewayProperties = json_decode($transaction->gateway->properties, true); - - // ایجاد یک instance از کامپوننت Larapay - $paymentGatewayHandler = Larapay::make($gateway, $transaction, $gatewayProperties); - - // با توجه به پارمترهای بازگشتی از درگاه پرداخت آیا امکان ادامه فرایند وجود دارد یا خیر؟ - if ($paymentGatewayHandler->canContinueWithCallbackParameters($request->all()) !== true) { - Session::flash('alert-danger', trans('gate.could_not_continue_because_of_callback_params')); - break; - } - - // گرفتن Reference Number از پارامترهای دریافتی از درگاه پرداخت - $referenceId = $paymentGatewayHandler->getGatewayReferenceId($request->all()); - - // جلوگیری از double spending یک شناسه مرجع تراکنش - $doubleInvoice = Transaction::where('gateway_ref_id', $referenceId) - ->where('verified', true)//قبلا وریفای شده - ->where('gateway_id', $transaction->gateway_id) - ->where('bank_id', $transaction->bank_id) - ->first(); - - if (!empty($doubleInvoice)) { - // double spending شناسایی شد - Xlog::emergency('referenceId double spending detected', [ - 'tag' => $referenceId, - 'order_id' => $transaction->gateway_order_id, - 'ips' => $request->ips(), - 'gateway' => $gateway, - ]); - Session::flash('alert-danger', trans('gate.double_spending')); - // آپدیت کردن توصیحات فاکتور - if (!preg_match('/DOUBLE_SPENDING/i', $transaction->description)) { - $transaction->description = "#DOUBLE_SPENDING_BY_{$doubleInvoice->id}#\n" . $transaction->description; - $transaction->save(); - } - break; - } - - $transaction->setReferenceId($referenceId); - - // verify start ---------------------------------------------------------------------------------------- - $verified = false; - // سه بار تلاش برای تایید تراکنش - for ($i = 1; $i <= 3; $i++) { - try { - XLog::info('trying to verify payment', - ['try' => $i, 'tag' => $referenceId, 'gateway' => $gateway]); - - $verifyResult = $paymentGatewayHandler->verify($request->all()); - if ($verifyResult) { - $verified = true; - } - XLog::info('verify result', - ['result' => $verifyResult, 'try' => $i, 'tag' => $referenceId, 'gateway' => $gateway]); - break; - } catch (\Exception $e) { - XLog::error('Exception: ' . $e->getMessage(), - ['try' => $i, 'tag' => $referenceId, 'gateway' => $gateway]); - continue; - } - } - - if ($verified !== true) { - XLog::error('transaction verification failed', ['tag' => $referenceId, 'gateway' => $gateway]); - break; - } else { - XLog::info('invoice verified successfully', ['tag' => $referenceId, 'gateway' => $gateway]); - } - - // verify end ------------------------------------------------------------------------------------------ - - // after verify start ---------------------------------------------------------------------------------- - $afterVerified = false; - for ($i = 1; $i <= 3; $i++) { - try { - XLog::info('trying to after verify payment', - ['try' => $i, 'tag' => $referenceId, 'gateway' => $gateway]); - - $afterVerifyResult = $paymentGatewayHandler->afterVerify($request->all()); - if ($afterVerifyResult) { - $afterVerified = true; - } - XLog::info('after verify result', [ - 'result' => $afterVerifyResult, - 'try' => $i, - 'tag' => $referenceId, - 'gateway' => $gateway, - ]); - break; - } catch (\Exception $e) { - XLog::error('Exception: ' . $e->getMessage(), - ['try' => $i, 'tag' => $referenceId, 'gateway' => $gateway]); - continue; - } - } - - if ($afterVerified !== true) { - XLog::error('transaction after verification failed', - ['tag' => $referenceId, 'gateway' => $gateway]); - break; - } else { - XLog::info('invoice after verified successfully', ['tag' => $referenceId, 'gateway' => $gateway]); - } - // after verify end ------------------------------------------------------------------------------------ - - $paidSuccessfully = true; - - } catch (Exception $e) { - XLog::emergency($e->getMessage() . ' code:' . $e->getCode() . ' ' . $e->getFile() . ':' . $e->getLine()); - break; - } - - // Start to serve to customer ----------------------------------------------------------------------------- - - $ifCustomerServed = false; - // write your code login and serve to your customer and set $ifCustomerServed to TRUE - - // End customer serve ------------------------------------------------------------------------------------- - - if (!$ifCustomerServed) { - // خدمات به مشتری ارائه نشد - // reverse start --------------------------------------------------------------------------------- - // سه بار تلاش برای برگشت زدن تراکنش - $reversed = false; - for ($i = 1; $i <= 3; $i++) { - try { - // ایجاد پازامترهای مورد نیاز برای برگشت زدن فاکتور - $reverseParameters = $request->all(); - - $reverseResult = $paymentGatewayHandler->reverse($reverseParameters); - if ($reverseResult) { - $reversed = true; - } - - break; - } catch (Exception $e) { - XLog::error('Exception: ' . $e->getMessage(), ['try' => $i, 'tag' => $referenceId]); - continue; - } - } - - if ($reversed !== true) { - XLog::error('invoice reverse failed', ['tag' => $referenceId]); - Flash::error(trans('gate.transaction_reversed_failed')); - break; - } - else { - XLog::info('invoice reversed successfully', ['tag' => $referenceId]); - Flash::success(trans('gate.transaction_reversed_successfully')); - } - // end reverse ----------------------------------------------------------------------------------- - } - else { - // خدمات به مشتری ارائه شد - Flash::success(trans('gate.invoice_paid_successfully')); - Log::info('invoice completed successfully', ['tag' => $referenceId, 'gateway' => $paidGateway->slug]); - // فلگ زدن فاکتور بعنوان فاکتور موفق - $transaction->setAccomplished(true); - } - - } while (false); // do not repeat - - return view('gateway.callback', [ - 'gateway' => $gateway, - 'referenceId' => $referenceId, - 'transaction' => $transaction, - 'paidTime' => $paidTime, - 'amount' => $amount, - ]); - } -``` - - -## Team - -This component is developed by the following person(s) and a bunch of [awesome contributors](https://github.com/iamtartan/laravel-online-payment/graphs/contributors). - -[![Aboozar Ghaffari](https://avatars2.githubusercontent.com/u/502961?v=3&s=130)](https://github.com/iamtartan) | [![Sina Miandashti](https://avatars3.githubusercontent.com/u/195868?v=3&s=130)](https://github.com/sinamiandashti) | [![Milad Kianmehr](https://avatars3.githubusercontent.com/u/4578704?v=3&s=130)](https://github.com/miladkian) ---- | --- | --- | -[Aboozar Ghaffari](https://github.com/iamtartan) |[Sina Miandashti](https://github.com/sinamiandashti)| [Milad Kianmehr](https://github.com/miladkian) - - -## Support This Project - -Please contribute in package completion. This is the best support. - -### License - -The Laravel Online Payment Module is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) diff --git a/README.md b/README.md index 3b39582..24df190 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,8 @@ class YourController extends Controller public function handleCallback(Request $request) { try{ - $transaction = Larapay::verifyTransaction($request); + $adapterConfig = []; + $transaction = Larapay::verifyTransaction($request, $adapterConfig); $order = $transaction->model; //transaction done. payment is successful } catch (\Exception $e){ diff --git a/src/Factory.php b/src/Factory.php index c84342c..487c226 100755 --- a/src/Factory.php +++ b/src/Factory.php @@ -70,7 +70,7 @@ public function make(string $adapter, TransactionInterface $invoice, array $adap return $this; } - public function verifyTransaction(Request $request) + public function verifyTransaction(Request $request,array $adapterConfig = []) { //get gateway and transaction id from request $gateway = $request->input('gateway'); @@ -117,8 +117,7 @@ public function verifyTransaction(Request $request) $transaction->setCallBackParameters($request->all(), true); //read gateway property from transaction and make payment gateway handler - $gatewayProperties = json_decode($transaction->gateway_properties, true); - $paymentGatewayHandler = $this->make($gateway, $transaction, $gatewayProperties); + $paymentGatewayHandler = $this->make($gateway, $transaction, $adapterConfig); //check that it's correct data and we can continue with this parameters if ($paymentGatewayHandler->canContinueWithCallbackParameters($request->all()) !== true) { diff --git a/src/Models/LarapayTransaction.php b/src/Models/LarapayTransaction.php index 66274b1..efcc339 100644 --- a/src/Models/LarapayTransaction.php +++ b/src/Models/LarapayTransaction.php @@ -36,7 +36,7 @@ class LarapayTransaction extends Model implements TransactionInterface 'description', 'extra_params', 'model', - 'gateway_properties', + 'additional_data', ]; protected $attributes = [ From ed2c7ba4a5f6ae2bdc79a835c85fa87c759545db Mon Sep 17 00:00:00 2001 From: Milad Kianmehr Date: Sun, 29 Dec 2019 15:27:55 +0330 Subject: [PATCH 4/4] reformat code --- src/Factory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Factory.php b/src/Factory.php index 487c226..e2a7b93 100755 --- a/src/Factory.php +++ b/src/Factory.php @@ -70,7 +70,7 @@ public function make(string $adapter, TransactionInterface $invoice, array $adap return $this; } - public function verifyTransaction(Request $request,array $adapterConfig = []) + public function verifyTransaction(Request $request, array $adapterConfig = []) { //get gateway and transaction id from request $gateway = $request->input('gateway'); @@ -105,11 +105,11 @@ public function verifyTransaction(Request $request,array $adapterConfig = []) $transaction = LarapayTransaction::find($transactionId); //transaction not found in our database if (!$transaction) { - throw new TransactionNotFoundException(trans('larapay::larapay.transaction_not_found'),2); + throw new TransactionNotFoundException(trans('larapay::larapay.transaction_not_found'), 2); } //transaction gateway conflict if ($transaction->gate_name != $gateway) { - throw new TransactionNotFoundException(trans('larapay::larapay.transaction_not_found'),3); + throw new TransactionNotFoundException(trans('larapay::larapay.transaction_not_found'), 3); } try {