paymob/php-library

Paymob PHP Library

1.0.4 2024-11-13 12:34 UTC

This package is not auto-updated.

Last update: 2025-04-30 12:54:09 UTC


README

Paymob PHP library is integrating Paymob Flash payment with PHP platforms.

Install

You can require it via Composer

composer require paymob/php-library

Usage

Configuration Array

$paymobKeys['apiKey'] = '';
$paymobKeys['pubKey'] = '';
$paymobKeys['secKey'] = '';

Get HMAC and Available integration IDs

$paymobReq = new Paymob();
$result = $paymobReq->authToken($paymobKeys);
echo "<pre>";
print_r($result);

Create an intention with Paymob

$cents = 100; // 100 for all countries and 1000 for Oman
$billing = [
        "email" => 'email@email.com',
        "first_name" => 'fname',
        "last_name" => 'lname',
        "street" => 'street',
        "phone_number" => '1234567890',
        "city" => 'city',
        "country" => 'country',
        "state" => 'state',
        "postal_code" => '12345',
    ];

    $data = [
        "amount" => 10 * $cents,
        "currency" => 'EGP',
        "payment_methods" => array(1234567), // replace this id 1234567 with your integration ID(s)
        "billing_data" => $billing,
        "extras" => ["merchant_intention_id" => '123_' . time()],
        "special_reference" => '123_' . time()
    ];

    $status = $paymobReq->createIntention($paymobKeys['secKey'], $data);
    echo "<pre/>";
    print_r($status);

Get Paymob Flash URL

$countryCode = $paymobReq->getCountryCode($paymobKeys['secKey']);
$apiUrl = $paymobReq->getApiUrl($countryCode);
$cs = $status['cs'];

$to = $apiUrl . "unifiedcheckout/?publicKey=" . $paymobKeys['pubKey'] . "&clientSecret=$cs";
echo "Pay using the URL $to";