baselrabia/paymob

A Package to help with Paymob integration

1.0.0 2021-08-19 01:07 UTC

This package is auto-updated.

Last update: 2024-10-19 08:32:03 UTC


README

Laravel PayMob
Latest Stable Version Total Downloads

Paymob integration for laravel.

Currently Supported

Installation

  • install the package

    composer require baselrabia/paymob
  • publish the package assets with

    php artisan vendor:publish --provider="Basel\PayMob\PayMobServiceProvider"

Config


  • Update your .env file
ACCEPT_API_KEY=
ACCEPT_MERCHANT_ID=
ACCEPT_CARD_IFRAME_ID=
ACCEPT_CARD_INTEGRATION_ID=
ACCEPT_MW_INTEGRATION_ID=

Setup

  • add the package routes to your routes/web.php ex.

    Route::group([
        'prefix'     => 'orders',
        'as'         => 'order.',
        'middleware' => 'auth',
    ], function () {
        Basel\PayMob\PayMobRoutes::routes();
    });
    
    // OR You Can Use your Own routes like this 
    // I used the package in Apis to provide Payment with the mobile APP
        Route::group([
          'prefix'     => 'payment',
          'as'         => 'order.',
          // 'middleware' => ,
      ],
          function () {
              // ctf0\PayMob\PayMobRoutes::routes();
    
              $controller = config('paymob.controller', '\Basel\PayMob\Controllers\DummyController');
    
              // Route::get('checkout', [
              //     'as'   => 'checkout',
              //     'uses' => "$controller@checkOut",
              // ]);
    
              Route::post('process', [
                  'as'   => 'process',
                  'uses' => "$controller@process",
              ])->middleware(['auth:student', 'scopes:student']);
    
              Route::get('complete', [
                  'as'   => 'complete',
                  'uses' => "$controller@complete",
              ]);
    
              Route::get('failed', [
                  'as'   => 'failed',
                  'uses' => "$controller@failed",
              ]);
          }
      );
  • add Billable to the model you will be billing.

  • next add getBillingData() which should return all the required fields for the order creation, check paymob requirements for more info.

    • all the optional fields has already been taken care of.
    use Basel\PayMob\Integrations\Contracts\Billable;
    
    class Client implements Billable
    {
        // ...
    
        public function getBillingData(): array
        {
            return [
                'email'        => $this->email,
                'first_name'   => $this->first_name,
                'last_name'    => $this->last_name,
                'street'       => $this->address ?? "NA",
                'phone_number' => $this->phone_number,
            ];
        }
    }

Usage

# Normal

# Refund

  • all you need to is to call PayMob::refund and pass to it the transaction_id & amount_in_pounds that will be refunded, ex.

    for more info check

    PayMob::refund(655, 10);