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-04-19 07:21:06 UTC


README

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

  • update controller with your own controller, which should have 3 methods

    you can check DummyController Or ApiDummyController for a more detailed overview.

    type @method return
    GET checkOut returns the view where the user will press the checkout btn
    POST process get the selected payment type & make a request to paymob server
    GET complete check for the transaction hmac & save it to your server, for more info check.
  • test Card

    MasterCard

    Key Value
    Card Number 2223000000000007
    Cardholder Name Test Account
    Expiry Month 01
    Expiry Year 39
    CVV 100

# 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);