Laravel integration with paymob (accept) payment gateway

Related tags

Miscellaneous paymob
Overview

Paymob Laravel Package

This is a laravel package to facilate integartion with paymob apis Paymob docs.

Installation

1- You can install the package via composer:

composer require skrskr/paymob

2- Publish config file for editing if needed:

php artisan vendor:publish --tag=config --provider="Skrskr\Paymob\PaymobServiceProvider"

Usage

  • Register new merchant account or login if you already have one (Register).
  • Get Paymob credentials from Paymob Dashboard (How) and update .env file.
PAYMOB_API_KEY             =
PAYMOB_CARD_INTEGRATION_ID =
PAYMOB_CARD_IFRAME_ID      =
PAYMOB_HMAC_SECRET         =
  • Make payment and get iframe url from paymob
<?php

use Illuminate\Support\Facades\Route;
use Skrskr\Paymob\Facades\Paymob;


Route::get('/test', function () {

    $orderData = [
        "amount_cents"=> "100", // required, integer value in cents
        "currency"=> "EGP", // required
        "merchant_order_id"=> 1243, //	optional, A unique alpha-numeric value for each transaction
        "expiration" => 3600, // required
        // optional fields in billing data, if it isn't available, please send it to be "NA",
        "billing_data" => [
            "first_name" => "Mohamed", // required
            "last_name" => "Sakr", // required
            "email" => "[email protected]", // required
            "phone_number" => "01234567890", // required 
            "apartment" => "NA", // optional
            "floor" => "NA", // optional
            "street" => "NA", //optional
            "building" => "NA",  // optional
            "shipping_method" => "NA", // optional
            "postal_code" => "NA",  //optional
            "city" => "NA",  // optional
            "country" => "NA", // optional
            "state" => "NA" // optional
        ],
    ];

    // Get payment iframe URL
    $iframeUrl = Paymob::pay($orderData);
    return $iframeUrl;
    //redirect to ifram url
    // return redirect()->to($iframeUrl);
});
  • Webhook transaction url:

    POST Request: (https://yourdomain.com/paymob/webhook)

    Replace your yourdomain.com with actual domain name

    For testing callback, you can use tool like Ngrok

  • Add Paymob trasaction callback to integration card How

  • For handling webhook events, you should create two listeners for each event and then register events and listeners in EventServiceProvider

# Events:
- Skrskr\Paymob\Events\TransactionSuccessedEvent::class
- Skrskr\Paymob\Events\TransactionFailedEvent::class

# Create two listeners for each event 
# run two commands
php artisan make:listener PaymobTransactionSuccessedListener
php artisan make:listener PaymobTransactionFailedListener

1- in App\ListenersPaymobTransactionSuccessedListener.php replace file content with class below

<?php

namespace App\Listeners;

use Skrskr\Paymob\Events\TransactionSuccessedEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class PaymobTransactionSuccessedListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  Skrskr\Paymob\Events\TransactionSuccessedEvent  $event
     * @return void
     */
    public function handle(TransactionSuccessedEvent $event)
    {
        \Log::info($event->payload);
    }
}

2- in App\Listeners\PaymobTransactionFailedListener.php replace file content with class content below

<?php

namespace App\Listeners;

use Skrskr\Paymob\Events\TransactionFailedEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class PaymobTransactionFailedListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  Skrskr\Paymob\Events\TransactionFailedEvent  $event
     * @return void
     */
    public function handle(TransactionFailedEvent $event)
    {
        \Log::info($event->payload);
    }
}

3- Register events and listeners in App\Providers\EventServiceProvider

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Skrskr\Paymob\Events\TransactionFailedEvent;
use Skrskr\Paymob\Events\TransactionSuccessedEvent;

use App\Listeners\PaymobTransactionSuccessedListener;
use App\Listeners\PaymobTransactionFailedListener;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array<class-string, array<int, class-string>>
     */
    protected $listen = [        
        TransactionSuccessedEvent::class => [
            PaymobTransactionSuccessedListener::class
        ],
        
        TransactionFailedEvent::class => [
            PaymobTransactionFailedListener::class
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}
You might also like...
Integrate Paytm Payment gateway to php website.

paytm-integration-kit-project-for-PHP Integrate Paytm Payment gateway to php website. Copy PaytmKit folder in document root of your server (like /var/

Provides Bitcoin-Lightning payment gateway powered by Strike
Provides Bitcoin-Lightning payment gateway powered by Strike

Bitcoin Payments - Powered by Strike Drupal module to allow user to pay with bitcoin on your Commerce website using Strike API. Strike Js is used for

MOKA > Opencart 2.3 Payment Gateway
MOKA Opencart 2.3 Payment Gateway

Moka - Opencart Payment Gateway Requirements PHP 5.6.0 and later. Dependencies The bindings require the following extensions in order to work properly

software development kit for purwantara.id payment gateway
software development kit for purwantara.id payment gateway

PURWANTARA LARAVEL ✨ What is Purwantara? Purwantara is a digital payment service provider that helps businesses to accept digital payments with seamle

Empower your business to accept payments globally, earn rewards and invest in crypto with lazerpay laravel sdk in your laravel project.
Empower your business to accept payments globally, earn rewards and invest in crypto with lazerpay laravel sdk in your laravel project.

Lazerpay Laravel Package pipedev/lazerpay is a laravel sdk package that access to laravel api Installation PHP 5.4+ and Composer are required. To get

Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways like sslcommerz, greenweb, dianahost,metronet in Laravel framework

Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways for Laravel. You should use

一个支持在 Swoole 或其它非 Workerman 环境,开发 Gateway Worker 的组件。

Workerman Gateway SDK 一个支持在 Swoole 或其它非 Workerman 环境,开发 Gateway Worker 的组件。 支持用 Workerman Gateway 做网关,Swoole 编写业务代码。 安装 composer require yurunsoft/wor

This is Laravel Framework. Referral User Management System, Payment using Coinpayment.net. etc

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Lightweight abstraction layer for payment gateways
Lightweight abstraction layer for payment gateways

Slickpay is lightweight abstraction layer for payment gateways. Documentation Documentation for Slickpay can be found on official website. Licence The

Owner
Mohamed Sakr
Backend Software Engineer
Mohamed Sakr
The Laravel eCommerce ABA Payment Gateway module allows the admin to integrate the ABA payment gateway to the online store.

Introduction Bagisto ABA Payment Gateway. Requirements: Bagisto: v1.3.2. Installation with composer: Run the following command composer require bagist

Bagisto 3 May 31, 2022
With the help of the Laravel eCommerce CashU Payment Gateway, the admin can integrate the CashU payment method in the Bagisto store.

Introduction Bagisto CashU Payment add-on allow customers to pay for others using CashU payment gateway. Requirements: Bagisto: v1.3.2 Installation wi

Bagisto 2 Aug 22, 2022
The whmcs payment module for TigoPesa Payment Gateway.

whmcs-tigopesa INSTALLATION INSTRUCTIONS TIGOPESA WHMCS Please follow the instructions below to setup the whmcs-tigopesa gateway module. Download zipp

Medson Naftali 3 Dec 11, 2021
uPay(bangladesh) payment gateway integration package for laravel

uPay BD Payment Gateway Requirements PHP >=7.2 Laravel >= 6 Installation composer require codeboxr/upay vendor publish (config) php artisan vendor:pub

Codeboxr CodeHub 6 Sep 24, 2022
ShurjoPay payment gateway integration for PHP applications.

ShurjoPay PHP Library Using this library you can integrate ShurjoPay payment gateway into your PHP applications. If you face any problem then create i

Raziul Islam 6 Jun 17, 2022
Simple laravel package for 2C2P Payment Gateway.

Laravel 2C2P Payment Gateway Simple laravel package for 2C2P Payment Gateway. Installation You can install the package via composer: composer require

null 3 Dec 7, 2021
A framework agnostic, multi-gateway payment processing library for PHP 5.6+

Omnipay An easy to use, consistent payment processing library for PHP Omnipay is a payment processing library for PHP. It has been designed based on i

The League of Extraordinary Packages 5.7k Dec 30, 2022
WHMCS Payment Gateway Module for Coinify

vrcoinify WHMCS Payment Gateway Module for Coinify Installing guide You should copy all contents from module folder to your WHMCS application folder u

VR DEV TEAM 3 Mar 15, 2022
A site to sell an E-book with paystack payment gateway integrated

YoungAndGetRich This is a platform to sell the named book using paystack payment gateway. Technology used are: MySql database PHP HTML5 CSS3 Bootstrap

Abiodun Sam 1 Oct 26, 2021
A payment gateway plugin for WooCommerce to see if your checkout works.

=== Order Test For All for WooCommerce === Contributors: ikamal Donate link: https://kamal.pw/ Tags: wc order test, wc order, woocommerce, woocommerce

Kamal 3 Dec 7, 2021