v1.5.2 2021-12-22 14:30 UTC

This package is auto-updated.

Last update: 2024-12-22 20:54:07 UTC


README

Latest Version on Packagist GitHub issues GitHub stars GitHub forks Total Downloads Scrutinizer Code Quality Build Status GitHub license

A Laravel Package for Payment Gateway Integration.

💎 List of available drivers

How to install and config sinarajabpour1998/gateway package?

⬇️ Installation

composer require sinarajabpour1998/gateway

Publish Config file

php artisan vendor:publish --tag=gateway

Migrate tables, to add transactions table to database

php artisan migrate

📖 How to use exists drivers from package

  • Set the configs in /config/gateway.php

    • Use this sample code for Request Payment

      <?php
      
      // Parsian Driver
      $transaction = Transaction::driver('parsian')
              ->amount(2000)
              ->orderId(2000)
              ->callbackUrl('callback_parsian')
              ->detail(['auto_redirect' => false]) // if we want to get {token, url} and not auto redirect to Bank Gateway.
              ->pay();
      
      // Pasargad Driver
      $transaction = Transaction::driver('pasargad')
              ->amount(2000)
              ->orderId(2000)
              ->callbackUrl('callback_pasargad')
              ->detail(['auto_redirect' => false]) // if we want to get {token, url} and not auto redirect to Bank Gateway.
              ->pay();
      // Vandar Driver
      $transaction = Transaction::driver('vandar')
              ->amount(2000)
              ->orderId(2000)
              ->callbackUrl('callback_vandar')
              ->detail(['auto_redirect' => false]) // if we want to get {token, url} and not auto redirect to Bank Gateway.
              ->pay();
      • Use this sample code for Verify Payment

        // Parsian Driver, that use POST type
        Route::post('/callback_parsian', function () {
            $verify = Transaction::driver('parsian')->request(request()->all())->verify();
        });
        
        // Pasargad Driver, that use GET type
        Route::get('/callback_pasargad', function () {
            $verify = Transaction::driver('pasargad')->request(request()->all())->verify();
        });
        
        // Vandar Driver, that use GET type
        request()->merge(['transId' => $order->transaction->id]);
        $result = Transaction::driver('vandar')->request(request()->all())->verify();
  • Use this Trait in you'r Model (for example Payment, Invoice, Order, ...) that has many transactions and has relation with Transaction Model

    // Use the Trait
    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Database\Eloquent\Model;
    
    use Sinarajabpour1998\Gateway\Traits\HasTransaction;
    
    class Order extends Model
    {
        use HasFactory, HasTransaction;
    }
    
    // After add the Trait we can use this relations
    $order->transaction; // get latest transaction from this order
    $order->transactions; // get the all transactions for this order
    $order->pendingTransactions; // get the pending transactions for this order
    $order->successfulTransactions; // get the successful transactions for this order
    $order->failedTransactions; // get the failed transactions for this order
    $order->refundedTransactions; // get the refunded transactions for this order
  • Get the parent of a transaction or this transaction belongs to which model

    // Set the namespace of your model in /config/transaction.php
    'model' => 'App\Models\Order',
    
    // Use relation for get a parent of this transaction
    $transaction->parent;
  • Transaction model's data and appends

    // Default
    $transaction->id;
    $transaction->order_id;
    $transaction->amount;
    $transaction->driver;
    $transaction->status;
    $transaction->ref_no;
    $transaction->token;
    $transaction->created_at;
    $transaction->updated_at;
    // Appends
    $transaction->gateway; // Label of driver 
    $transaction->toman; // Get price to taman (convert rial to toman)
    $transaction->status_label; // Label of status

Requirements: