Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
hpakdaman authored Nov 1, 2019
1 parent 3e9230d commit e2607fe
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 265 deletions.
259 changes: 99 additions & 160 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,189 +1,128 @@
<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
8. ASAN PARDAKHT
9. PAY.IR ( برای فراخوانی از 'payir' استفاده نمایید)
10. Irankish (**جدید** - برای فراخوانی از 'irankish' استفاده نمایید)
7. PAYPAL (**New**)
8. ASAN PARDAKHT (**New**)
9. PAY.IR (**New**) (to use : new \Payir())
----------


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

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

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

composer require larabook/gateway

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

**مرحله ۲)**

تغییرات زیر را در فایل 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">

**مرحله ۳) - انتقال فایل های مورد نیاز**
'providers' => [
...
Larabookir\Gateway\GatewayServiceProvider::class, // <-- add this line at the end of provider array
],

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

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

Step 3:

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

php artisan vendor:publish


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



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

php artisan migrate



**مرحله ۵)**

عملیات نصب پایان یافته است حال فایل 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>
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 .
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
69 changes: 37 additions & 32 deletions src/GatewayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Larabookir\Gateway;

use Larabookir\Gateway\Irankish\Irankish;
use Larabookir\Gateway\Parsian\Parsian;
use Larabookir\Gateway\Paypal\Paypal;
use Larabookir\Gateway\Sadad\Sadad;
Expand Down Expand Up @@ -126,36 +127,40 @@ public function verify()
* @throws PortNotFoundException
*/
function make($port)
{
if ($port InstanceOf Mellat) {
$name = Enum::MELLAT;
} elseif ($port InstanceOf Parsian) {
$name = Enum::PARSIAN;
} elseif ($port InstanceOf Saman) {
$name = Enum::SAMAN;
} elseif ($port InstanceOf Zarinpal) {
$name = Enum::ZARINPAL;
} elseif ($port InstanceOf Sadad) {
$name = Enum::SADAD;
} elseif ($port InstanceOf Asanpardakht) {
$name = Enum::ASANPARDAKHT;
} elseif ($port InstanceOf Paypal) {
$name = Enum::PAYPAL;
} elseif ($port InstanceOf Payir) {
$name = Enum::PAYIR;
} elseif(in_array(strtoupper($port),$this->getSupportedPorts())){
$port=ucfirst(strtolower($port));
$name=strtoupper($port);
$class=__NAMESPACE__.'\\'.$port.'\\'.$port;
$port=new $class;
} else
throw new PortNotFoundException;

$this->port = $port;
$this->port->setConfig($this->config); // injects config
$this->port->setPortName($name); // injects config
$this->port->boot();

return $this;
}
{
if ($port InstanceOf Mellat) {
$name = Enum::MELLAT;
} elseif ($port InstanceOf Parsian) {
$name = Enum::PARSIAN;
} elseif ($port InstanceOf Saman) {
$name = Enum::SAMAN;
} elseif ($port InstanceOf Zarinpal) {
$name = Enum::ZARINPAL;
} elseif ($port InstanceOf Sadad) {
$name = Enum::SADAD;
} elseif ($port InstanceOf Asanpardakht) {
$name = Enum::ASANPARDAKHT;
} elseif ($port InstanceOf Paypal) {
$name = Enum::PAYPAL;
} elseif ($port InstanceOf Payir) {
$name = Enum::PAYIR;
} elseif ($port InstanceOf Pasargad) {
$name = Enum::PASARGAD;
} elseif ($port InstanceOf Irankish) {
$name = Enum::IRANKISH;
} elseif (in_array(strtoupper($port), $this->getSupportedPorts())) {
$port = ucfirst(strtolower($port));
$name = strtoupper($port);
$class = __NAMESPACE__ . '\\' . $port . '\\' . $port;
$port = new $class;
} else
throw new PortNotFoundException;

$this->port = $port;
$this->port->setConfig($this->config); // injects config
$this->port->setPortName($name); // injects config
$this->port->boot();

return $this;
}
}
Loading

0 comments on commit e2607fe

Please sign in to comment.