PHP code example of sinarajabpour1998 / gateway

1. Go to this page and download the library: Download sinarajabpour1998/gateway library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sinarajabpour1998 / gateway example snippets


      
  
      // 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();

      

        // 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 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
    

    // 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;
    

    // 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
    
bash
php artisan vendor:publish --tag=gateway
bash
php artisan migrate