Skip to content

Commit

Permalink
Merge pull request #202 from larabook/dev
Browse files Browse the repository at this point in the history
laravel 6.0 support
  • Loading branch information
hpakdaman committed Nov 1, 2019
2 parents 676dfe5 + af541c9 commit 30272bc
Show file tree
Hide file tree
Showing 28 changed files with 1,267 additions and 328 deletions.
259 changes: 160 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,128 +1,189 @@
<div dir="rtl">

سایت مرجع پکیج: [larabook.ir](http://larabook.ir/اتصال-درگاه-بانک-لاراول/)

پکیج اتصال به تمامی IPG ها و بانک های ایرانی.

این پکیج با ورژن های
( ۴ و ۵ و ۶ لاراول )
لاراول سازگار می باشد

package's home : [larabook.ir](http://larabook.ir/اتصال-درگاه-بانک-لاراول/)

by this package we are able to connect to all Iranian bank with one unique API.

( This Package is now compatible with both **4.\* and 5.\* versions of Laravel** )

Please inform us once you've encountered [bug](https://github.com/larabook/gateway/issues) or [issue](https://github.com/larabook/gateway/issues) .

Available Banks:
پشتیبانی تنها از درگاهای زیر می باشد:
1. MELLAT
2. SADAD (MELLI)
3. SAMAN
4. PARSIAN
5. PASARGAD
6. ZARINPAL
7. PAYPAL (**New**)
8. ASAN PARDAKHT (**New**)
9. PAY.IR (**New**) (to use : new \Payir())
7. PAYPAL
8. ASAN PARDAKHT
9. PAY.IR ( برای فراخوانی از 'payir' استفاده نمایید)
10. Irankish (**جدید** - برای فراخوانی از 'irankish' استفاده نمایید)
----------


**Installation**:
**نصب**:

Run below statements on your terminal :
دستورات زیر را جهت نصب دنبال کنید :

STEP 1 :
**مرحله ۱)**

composer require larabook/gateway

STEP 2 : Add `provider` and `facade` in config/app.php

'providers' => [
...
Larabookir\Gateway\GatewayServiceProvider::class, // <-- add this line at the end of provider array
],
**مرحله ۲)**

تغییرات زیر را در فایل config/app.php اعمال نمایید:

**توجه برای نسخه های لاراول ۶ به بعد این مرحله نیاز به انجام نمی باشد**

</div>

```php

'providers' => [
...
Larabookir\Gateway\GatewayServiceProvider::class, // <-- add this line at the end of provider array
],


'aliases' => [
...
'Gateway' => Larabookir\Gateway\Gateway::class, // <-- add this line at the end of aliases array
]

```



<div dir="rtl">

**مرحله ۳) - انتقال فایل های مورد نیاز**

برای لاراول ۵ :
</div>

'aliases' => [
...
'Gateway' => Larabookir\Gateway\Gateway::class, // <-- add this line at the end of aliases array
]
php artisan vendor:publish --provider=Larabookir\Gateway\GatewayServiceProviderLaravel5

Step 3:

php artisan vendor:publish --provider=Larabookir\Gateway\GatewayServiceProvider
<div dir="rtl">
برای لاراول ۶ به بعد :
</div>

Step 4:
php artisan vendor:publish


<div dir="rtl">
سپس این گزینه را انتخاب کنید : "Larabookir\Gateway\GatewayServiceProviderLaravel6"



**مرحله ۴) - ایجاد جداول**

php artisan migrate


Configuration file is placed in config/gateway.php , open it and enter your banks credential:

You can make connection to bank by several way (Facade , Service container):

try {
$gateway = \Gateway::make(new \Mellat());

// $gateway->setCallback(url('/path/to/callback/route')); You can also change the callback
$gateway
->price(1000)
// setShipmentPrice(10) // optional - just for paypal
// setProductName("My Product") // optional - just for paypal
->ready();

$refId = $gateway->refId(); // شماره ارجاع بانک
$transID = $gateway->transactionId(); // شماره تراکنش

// در اینجا
// شماره تراکنش بانک را با توجه به نوع ساختار دیتابیس تان
// در جداول مورد نیاز و بسته به نیاز سیستم تان
// ذخیره کنید .
return $gateway->redirect();
} catch (\Exception $e) {
echo $e->getMessage();
}

you can call the gateway by these ways :
1. Gateway::make(new Mellat());
1. Gateway::mellat()
2. app('gateway')->make(new Mellat());
3. app('gateway')->mellat();

Instead of MELLAT you can enter other banks Name as we introduced above .

In `price` method you should enter the price in IRR (RIAL)

and in your callback :

try {
$gateway = \Gateway::verify();
$trackingCode = $gateway->trackingCode();
$refId = $gateway->refId();
$cardNumber = $gateway->cardNumber();
// تراکنش با موفقیت سمت بانک تایید گردید
// در این مرحله عملیات خرید کاربر را تکمیل میکنیم

} catch (\Larabookir\Gateway\Exceptions\RetryException $e) {

// تراکنش قبلا سمت بانک تاییده شده است و
// کاربر احتمالا صفحه را مجددا رفرش کرده است
// لذا تنها فاکتور خرید قبل را مجدد به کاربر نمایش میدهیم
echo $e->getMessage() . "<br>";
} catch (\Exception $e) {
// نمایش خطای بانک
echo $e->getMessage();
}

If you are intrested to developing this package you can help us by these ways :

1. Improving documents.
2. Reporting issue or bugs.
3. Collaboration in writing codes and other banks modules.

This package is extended from PoolPort but we've changed some functionality and improved it .

**مرحله ۵)**

عملیات نصب پایان یافته است حال فایل gateway.php را در مسیر app/ را باز نموده و تنظیمات مربوط به درگاه بانکی مورد نظر خود را در آن وارد نمایید .

حال میتوایند برای اتصال به api بانک از یکی از روش های زیر به انتخاب خودتان استفاده نمایید . (Facade , Service container):
</div>

1. Gateway::make(new Mellat())
2. Gateway::make('mellat')
3. Gateway::mellat()
4. app('gateway')->make(new Mellat());
5. app('gateway')->mellat();

<div dir="rtl">

مثال :‌اتصال به بانک ملت (درخواست توکن و انتقال کاربر به درگاه بانک)
توجه :‌ مقدار متد price به ریال وارد شده است و معادل یکصد تومان می باشد

یک روت از نوع GET با آدرس /bank/request ایجاد نمایید و کد های زیر را در آن قرار دهید .

</div>


```php

try {

$gateway = \Gateway::make('mellat');

$gateway->setCallback(url('/bank/response')); // You can also change the callback
$gateway->price(1000)
// setShipmentPrice(10) // optional - just for paypal
// setProductName("My Product") // optional - just for paypal
->ready();

$refId = $gateway->refId(); // شماره ارجاع بانک
$transID = $gateway->transactionId(); // شماره تراکنش

// در اینجا
// شماره تراکنش بانک را با توجه به نوع ساختار دیتابیس تان
// در جداول مورد نیاز و بسته به نیاز سیستم تان
// ذخیره کنید .

return $gateway->redirect();

} catch (\Exception $e) {

echo $e->getMessage();
}

```

<div dir="rtl">

و سپس روت با مسیر /bank/response و از نوع post ایجاد نمایید و کد های زیر را در آن قرار دهید :

</div>


```php

try {

$gateway = \Gateway::verify();
$trackingCode = $gateway->trackingCode();
$refId = $gateway->refId();
$cardNumber = $gateway->cardNumber();

// تراکنش با موفقیت سمت بانک تایید گردید
// در این مرحله عملیات خرید کاربر را تکمیل میکنیم

} catch (\Larabookir\Gateway\Exceptions\RetryException $e) {

// تراکنش قبلا سمت بانک تاییده شده است و
// کاربر احتمالا صفحه را مجددا رفرش کرده است
// لذا تنها فاکتور خرید قبل را مجدد به کاربر نمایش میدهیم

echo $e->getMessage() . "<br>";

} catch (\Exception $e) {

// نمایش خطای بانک
echo $e->getMessage();
}

```

<div dir="rtl">

در صورت تمایل جهت همکاری در توسعه :

1. توسعه مستندات پکیج.
2. گزارش باگ و خطا.
3. همکاری در نوشتن ماژول دیگر بانک ها برای این پکیج .


درصورت بروز هر گونه
[باگ](https://github.com/larabook/gateway/issues) یا [خطا](https://github.com/larabook/gateway/issues) .
ما را آگاه سازید .

این پکیج از پکیج دیگری بنام poolport مشتق شده است اما برخی از عملیات آن متناسب با فریموورک لارول تغییر کرده است
</div>
11 changes: 10 additions & 1 deletion config/gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
'callback-url' => '/'
],

//--------------------------------
// IranKish gateway
//--------------------------------
'irankish' => [
'merchantId' => 'xxxxxxxxxxxxxxxxxxxx',
'sha1key' => 'xxxxxxxxxxxxxxxxxxxx',
'callback-url' => '/'
],

//--------------------------------
// Sadad gateway
//--------------------------------
Expand All @@ -57,7 +66,7 @@
'terminalId' => 000000000,
'callback-url' => '/'
],

//--------------------------------
// Parsian gateway
//--------------------------------
Expand Down
16 changes: 3 additions & 13 deletions migrations/2016_05_02_193213_create_gateway_transactions_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ function getTable()
*/
public function up()
{


Schema::create($this->getTable(), function (Blueprint $table) {
$table->engine = "innoDB";
$table->unsignedBigInteger('id', true);
$table->enum('port', [
Enum::MELLAT,
Enum::SADAD,
Enum::ZARINPAL,
Enum::PAYLINE,
Enum::JAHANPAY,
Enum::PARSIAN,
Enum::PASARGAD,
Enum::SAMAN,
Enum::ASANPARDAKHT,
Enum::PAYPAL,
Enum::PAYIR
]);
$table->enum('port', (array) Enum::getIPGs());
$table->decimal('price', 15, 2);
$table->string('ref_id', 100)->nullable();
$table->string('tracking_code', 50)->nullable();
Expand Down
4 changes: 2 additions & 2 deletions src/Asanpardakht/Asanpardakht.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Larabookir\Gateway\Asanpardakht;

use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Request;
use SoapClient;
use Larabookir\Gateway\PortAbstract;
use Larabookir\Gateway\PortInterface;
Expand Down Expand Up @@ -141,7 +141,7 @@ protected function sendPayRequest()
*/
protected function userPayment()
{
$ReturningParams = Input::get('ReturningParams');
$ReturningParams = Request::input('ReturningParams');
$ReturningParams = $this->decrypt($ReturningParams);

$paramsArray = explode(",", $ReturningParams);
Expand Down
3 changes: 1 addition & 2 deletions src/Asanpardakht/AsanpardakhtException.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ class AsanpardakhtException extends BankException
1101 => "هویت درخواست کننده نامعتبر است",
1102 => "خطا در پردازش",
1103 => "تراکنشی یافت نشد"



);

public function __construct($errorRef)
Expand Down

0 comments on commit 30272bc

Please sign in to comment.