PHP code example of engalirock / laravel-paymob

1. Go to this page and download the library: Download engalirock/laravel-paymob 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/ */

    

engalirock / laravel-paymob example snippets


'providers' => [
    ...
    aliRocK\PayMob\PayMobServiceProvider::class,
    ...
];

'aliases' => [
    ...
    'PayMob' => aliRocK\PayMob\Facades\PayMob::class,
    ...
];

$auth = PayMob::authPaymob();
// Run this method to get a sample response of auth request.
PayMob::sample('authPaymob');

$paymobOrder = PayMob::makeOrderPaymob(
    $auth->token, // this is token from step 1.
    $auth->profile->id, // this is the merchant id from step 1.
    $order->totalCost * 100, // total amount by cents/piasters.
    $order->id // your (merchant) order id.
);
// Run this method to get a sample response of make order request.
PayMob::sample('makeOrderPaymob');

$paymentKey = PayMob::getPaymentKeyPaymob(
    $auth->token, // from step 1.
    $order->totalCost * 100, // total amount by cents/piasters.
    $order->paymob_order_id, // paymob order id from step 2.
    // For billing data
    $user->email, // optional
    $user->firstname, // optional
    $user->lastname, // optional
    $user->phone, // optional
    $city->name, // optional
    $country->name // optional
);
// Run this method to get a sample response of payment key request.
PayMob::sample('getPaymentKeyPaymob');

$payment = PayMob::makePayment(
    $paymentKey->token, // payment key token from step 3.
    $request->card_number,
    $request->card_holdername,
    $request->card_expiry_mm,
    $request->card_expiry_yy,
    $request->card_cvn,
    $order->paymob_order_id, // PayMob order id from step 2.
    $user->firstname,
    $user->lastname,
    $user->email,
    $user->phone
);
// Run this method to get a sample response of make payment for API request.
// processedCallback is for the post response to your processed callback route from PayMob.
PayMob::sample('processedCallback');
// responseCallback is for the Get response to your response callback route from PayMob.
PayMob::sample('responseCallback');

PayMob::getOrders(
    $auth->token, // token from step 1.
    $page // optional for pagination, by default set to 1
);

PayMob::getOrder(
    $auth->token, // token from step 1.
    $order->paymob_order_id // PayMob order id from step 2.
);

PayMob::getTransactions(
    $auth->token, // token from step 1.
    $page // optional for pagination, by default set to 1
);

PayMob::getTransaction(
    $auth->token, // token from step 1.
    $transactionId // PayMob transaction id from step 4.
);

PayMob::capture(
    $auth->token, // token from step 1.
    $transactionId, // the returned id from step 4.
    $totalCost * 100 // total price/cost in cents/piasters.
);
bash
$ php artisan vendor:publish