PHPackages                             amirex128/laravel-online-payment - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. amirex128/laravel-online-payment

ActiveLibrary

amirex128/laravel-online-payment
================================

Iranian payment gateways handler for laravel applications

01PHP

Since Jul 25Pushed 9mo agoCompare

[ Source](https://github.com/amirex128/laravel-online-payment)[ Packagist](https://packagist.org/packages/amirex128/laravel-online-payment)[ RSS](/packages/amirex128-laravel-online-payment/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Iranian Online Payment Component
========================================

[](#laravel-iranian-online-payment-component)

Online Payment Module handler for Laravel 5+ known as LaraPay component completely compatible with [BankTest](http://banktest.ir) sandbox. Larapay integrated all Iranian payment gateways into one component.

Here are a few short examples of what you can do:

- create new transaction form your order model and generate bank form

```
 $transaction = $order->createTransaction(Bank::MELLAT);
 $form = $transaction->generateForm();
```

- handle gateway callback (verify/settle/...)

```
 $transaction = Larapay::verifyTransaction($request);
 //if the gateway supports reverse method
 $transaction->reverseTransaction();
 $order = $transaction->model;
```

- get order transaction information

```
 $allTransactions = $order->transations;
 $accomplishedTransactions = $order->accomplishedTransactions;
 $isPaid = $order->isPaid();
 $paidAmount = $order->paidAmount();
```

Currenctly supports:
--------------------

[](#currenctly-supports)

- Mellat Bank Gateway - درگاه بانک ملت لاراول
- Saman Bank Gateway - درگاه بانک سامان لاراول
- Saderat/Sepehr Pay Bank Gateway - درگاه بانک صادرات / سپهر
- Pasargad Bank Gateway - درگاه بانک پاسارگاد لاراول
- Parsian Bank Gateway - درگاه بانک پارسیان لاراول
- Melli/Sadad Bank Gateway (Sadad) - درگاه بانک ملی / سداد لاراول
- Pay.ir Gateway / درگاه پرداخت پی
- Zarinpal Gateway / درگاه پرداخت زرین پال
- IDPay Gateway / درگاه آیدی پی
- Zibal Gateway / درگاه زیبال
- nextpay Gateway / درگاه نکست پی
- ...
- Other gateways, coming soon... لطفا شما هم در تکمیل پکیج مشارکت کنید

#### But what is B‌anktest sandbox?

[](#but-what-is-b‌anktest-sandbox)

- [BankTest](http://banktest.ir) is a sandbox service for all Iranian online payment gateways
- [بانک تست](http://banktest.ir) یک سرویس شبیه ساز درگاه های پرداخت آنلاین ایرانی برای اهداف توسعه و تست نرم افزار می باشد

Requirements
------------

[](#requirements)

Larapay Version 8+ requires PHP 8.2+ and Laravel 11+ or Laravel 12+

Installation
------------

[](#installation)

1. Installing via composer

```
composer require php-monsters/laravel-online-payment
```

2. Add package service provider to your app service providers (only for Laravel &lt; 5.5):

```
PhpMonsters\Larapay\LarapayServiceProvider::class,
PhpMonsters\Log\XLogServiceProvider::class,
```

3. Add package alias to your app aliases (only for Laravel &lt; 5.5):

```
'Larapay' => PhpMonsters\Larapay\Facades\Larapay::class,
'XLog'    => PhpMonsters\Log\Facades\XLog::class,
```

4. Publish package assets and configs

```
php artisan vendor:publish --provider="PhpMonsters\Larapay\LarapayServiceProvider"
```

5. Run migration

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

If you complete installation step correctly, you can find Larapay config file as larapay.php in you project config file.

For sandbox (banktest) you should set `LARAPAY_MODE=development` in your .env file otherwise set `LARAPAY_MODE=production`

If you choose development mode, Larapay use banktest.ir as its payment gateway.

Set your gateway(s) configs in your .env file. Here are some example:

```
LARAPAY_MODE=development

SAMAN_MERCHANT_ID=bmcf****
SAMAN_MERCHANT_PASS=98221***

MELLAT_USERNAME=user***
MELLAT_PASSWORD=80714***
MELLAT_TERMINAL_ID=747
```

### Setup callback route

[](#setup-callback-route)

you should create a route for handling callback from bank and set your route name in .env

For example create a POST route in routes folder, web.php like this:

```
Route::post('payment/callback', 'YourController@handleCallback')->name('payment.callback');
```

then set the route name in .env file:

```
LARAPAY_PAYMENT_CALLBACK=payment.callback
```

Usage
-----

[](#usage)

### Prepare payable model

[](#prepare-payable-model)

Use `Payable` trait in your order model or any other model like user which will get payment feature and implement it.

You can impalement getAmount() method to return `Iranian Rail` amount of your model.

```
use PhpMonsters\Larapay\Payable;

class Order extends Model
{
    use Payable;

    public function getAmount(){
        return intval($this->amount) * 10;
    }

}
```

Now you just have 3 steps to complete your payment:

### 1- create transaction

[](#1--create-transaction)

In your bank controller create a transaction for your order and generate bank for to transfer user to payment gateway.

```
use PhpMonsters\Larapay\Models\Enum\Bank;

class BankController extends Controller
{
    public function index()
    {
        //your logic and prepare your order
        // ...

        //if you implement getAmount() method you can set amount to null
        $amount = 1200000;  //Rial at least 1000
        //order or user description
        $description = 'I pay my order with Larapay
