Giter Site home page Giter Site logo

laravel-online-payment's Introduction

Laravel Iranian Online Payment Component

Online Payment Module handler for Laravel 5+ known as LaraPay component completely compatible with BankTest 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:

  • 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?

  • BankTest is a sandbox service for all Iranian online payment gateways
  • بانک تست یک سرویس شبیه ساز درگاه های پرداخت آنلاین ایرانی برای اهداف توسعه و تست نرم افزار می باشد

Requirements

Larapay Version 6+ required PHP 7+

Installation

  1. Installing via composer
composer require php-monsters/laravel-online-payment
  1. Add package service provider to your app service providers (only for Laravel < 5.5):
PhpMonsters\Larapay\LarapayServiceProvider::class,
PhpMonsters\Log\XLogServiceProvider::class,
  1. Add package alias to your app aliases (only for Laravel < 5.5):
'Larapay' => PhpMonsters\Larapay\Facades\Larapay::class,
'XLog'    => PhpMonsters\Log\Facades\XLog::class,
  1. Publish package assets and configs
php artisan vendor:publish --provider="PhpMonsters\Larapay\LarapayServiceProvider"
  1. Run migration
php artisan migrate

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 it's 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

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

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

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 <3';
        //some additional data that you need store on transaction
        $additionalData = [];
        //create transaction 
        $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, $adapterConfig);
        
        return view('go-to-bank',[
            'form' => $form,
        ]);
    }
}

2- show bank transfer form

Now you can show you $form in your go-to-bank view file:

<div>
    {!! $form !!}
</div>

You can modify bank forms in:

resources/views/vendor/larapy

3- handle callback

After payment, bank call you callback route

use Illuminate\Http\Request;
use PhpMonsters\Larapay\Facades\Larapay;

class YourController extends Controller
{
    public function handleCallback(Request $request)
    {
         try{
            $adapterConfig = [];
            $transaction = Larapay::verifyTransaction($request, $adapterConfig);
            $order = $transaction->model;
            //transaction done. payment is successful         
         } catch (\Exception $e){
            // transaction not complete!!!
            // show error to your user
         }
    }
}

If you want to revers transaction and your bank support it, you can do this way:

$transaction->reverseTransaction();

Methods

Methods available in Paybel trait and your order model:

  • $order->transactions : get all transactions of this model
  • $order->accomplishedTransactions: get all accomplished transactions
  • $order->isPaid(): return true if this model has at least one accomplished transaction
  • $order->paidAmount(): return sum of accomplished transactions amount in Rial
  • $order->createTransaction( $paymentGateway, $amount = null, $description = null, array $additionalData = [] ): create a transaction.

Methods available in LarapayTransaction model:

  • $transaction->model: return the model that create this transaction. for example $order
  • $transaction->reverseTransaction(): reverse transaction and get back money to user. (if bank support reverse transaction)
  • $transaction->generateForm($autoSubmit = false, $callback = null): generate bank transfer form
  • $transaction->gatewayHandler(): get gatewayHandler for advance use.

Fields available in LarapayTransaction model:

  • id
  • created_at
  • updated_at

Status in boolean:

  • accomplished
  • verified
  • after_verified
  • reversed
  • submitted
  • approved
  • rejected

Gate information:

  • payment_method
  • bank_order_id
  • gate_name
  • gate_refid
  • gate_status
  • extra_params
  • additional_data

Order information:

  • amount
  • description
  • paid_at

LarapayTransaction

You can use LarapayTransaction model to find your transaction:

use PhpMonsters\Larapay\Models\LarapayTransaction;

public function getTransaction($transactionId){

    //find single transaction by transaction id
    $transaction = LarapayTransaction::find($transactionId);
    
    //get all accomplished transaction
    $accomplishedTransactions = LarapayTransaction::where('accomplished',true)->get();
    
    //get all reversed transaction
    $reversedTransactions = LarapayTransaction::where('reversed',true)->get();
}

This class use SoftDeletes. you can call delete() on your transaction model to softDelete it or forceDelete() to truly remove it from your database.

Security

If you discover any security related issues, please email [email protected] or [email protected] instead of using the issue tracker.

Team

This component is developed by the following person(s) and a bunch of awesome contributors.

Aboozar Ghaffari Milad Kianmehr Sina Miandashti XShaan
Aboozar Ghaffari Milad Kianmehr Sina Miandashti XShaan

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

laravel-online-payment's People

Contributors

farvisun avatar iamfarhad avatar imansarhaddi avatar miladkian avatar mokhosh avatar samuraee avatar sinamiandashti avatar xshaan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laravel-online-payment's Issues

Migration Error

Hi
SQLSTATE[42000]: Syntax error or access violation: 1101 BLOB, TEXT, GEOMETRY or JSON column 'extra_params' can't have a default value

to fix this mysql issue just delete "->default('{}')" from "jsonb" columns.

  • Laravel 7
  • Windows 10
  • WampServer 3.2.0 64bit

How to fill the Data after transaction is completed

Hi
how to store other data (gate_refid, accomplished, gate_status,paid_at) and set transaction as completed in handleCallback after payment?

Update:
String data, right truncated: 1406 Data too long for column 'gate_refid' at row 1

نمونه کد

سلام

کاش داکیومنت های این پروژه رو کامل کنید

و یک آموزش کامل تر و یا یک نمونه کد و یا یک نمونه پروژه از آن را قرار بدهید

این گونه توسعه دهنده هایی که تازه میخواهند با این پکیج کار کنند ، فکر میکنم کارشون راحت تر باشه

مشکل اجرا در لاراول 5.8

این پکیت رو لاراول 5.8 نصب نمیشه
اگر هم نصب بشه فایل های وندور رو نمیشناسه
حتی به طور دستی رو پروایدر و الیاس معرفی شد اما همچنان کار نکرد
این پکیج روی لاراول 5.8 دچار مشکل هست

پرداخت های این ترمینال فقط از طریق توکن امکانپذیر است.

سلام خسته نباشید و تشکر از پکیج خیلی مفیدتون
من یک مشکلی دارم با درگاه بانک سامان، ظاهرا الان فقط با حالت توکن کار میکنه و داخل کدهاتون را نگاه کردم و دیدم که داخل فرم بانک سامان جا برای توکن گذاشته بودین ولی جایی رو که بشه انتخاب کرد که از روش توکن تراکنش انجام بشه رو پیدا نکردم

Error: Declaration of Tartan\Larapay\Models\LarapayTransaction::setReferenceId

Hi
in:
tartan/laravel-online-payment": "^7.0
laravel/framework": "5.8.*

I get this error:
Declaration of Tartan\Larapay\Models\LarapayTransaction::setReferenceId($referenceId, $save = true): bool must be compatible with Tartan\Larapay\Transaction\TransactionInterface::setReferenceId(string $referenceId, bool $save = true): bool

Class "Tartan\Log\XLogServiceProvider" not found

Hi my friends.
I add Tartan\Log\XLogServiceProvider::class in config/app.php and get error:

Class "Tartan\Log\XLogServiceProvider" not found,

Then i look at your codes and see:
XLogServiceProvider and XLog are in \PhpMonsters\Log namespace but you use it as Tartan\Log\Facades namespace.

عدم نصب در لاراول ۱۰

با سلام احترام

این پکیج با لاراول ۱۰ کار نمیکنه؟
موقع نصب خطا میده ‍

Could not find a matching version of package php-monsters/laravel-online-payment. Check the package spelling, your version constraint and that the package is available in a
  stability which matches your minimum-stability (stable).

ممنون میشم بررسی بفرمایید

SoapFault: SOAP-ERROR: Parsing WSDL

Hi
I started new project and use from bank test of Mellat.
but I got an error with this message
SoapFault: SOAP-ERROR: Parsing WSDL: Missing / with name 'bpVirtualPayRequest' #0

TransactionInterface

سلام، بنده به خطایی در رابطه با
TransactionInterface
برخوردم.

Class App\Transaction contains 15 abstract methods and must therefore be declared abstract or implement the remaining methods (Tartan\Larapay\Transaction\TransactionInterface::setGatewayToken, Tartan\Larapay\Transaction\TransactionInterface::setReferenceId, Tartan\Larapay\Transaction\TransactionInterface::checkForRequestToken, ...)

ممنون میشم راهنماییم کنید.

خطا در reverse و ساخت فرم. - بانک سامان

  • درگاه سامان - فرم ساز - object بر میگرداند : /tartan/laravel-online-payment/src/Adapter/Saman.php لاین 110
  • تابع getWSDL در فایل /home/farvisun/Projects/wolverine/vendor/tartan/laravel-online-payment/src/Adapter/Saman.php خطا دارد. type نال می باشد
  • برای Reverse transaction پارامتر هایی که gateway ساخته میشود ناکارآمد است.

Laravel 8

Update the following dependencies in your composer.json file:
illuminate/view
illuminate/support

Zarinpal not working

I can't use zarinpal gateway or banktest.ir zarinpal.
every time it returns an unknown error

 larapay::larapay.zarinapal.errors.error__1 

  +"Status": -1
  +"Authority": ""

Laravel: 8.61

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.