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' => [
...
engalirock\PayMob\PayMobServiceProvider::class,
...
];
'aliases' => [
...
'PayMob' => engalirock\PayMob\Facades\PayMob::class,
...
];
return [
'username' => env('PAYMOB_USERNAME', ''),
'password' => env('PAYMOB_PASSWORD', ''),
'api_key' => env('PAYMOB_API_KEY', ''),
'integration_id' => env('PAYMOB_INTEGRATION_ID', ''),
'iframe_id' => env('PAYMOB_IFRAME_ID', ''),
// IP resolution setting to bypass SSL Handshake Issues (Default: force IPv4)
'ip_resolve' => defined('CURL_IPRESOLVE_V4') ? CURL_IPRESOLVE_V4 : 1,
];
use engalirock\PayMob\Facades\PayMob;
$auth = PayMob::authPaymob();
$token = $auth->token;
$data = [
'amount' => 15000, // Amount in cents/piasters (e.g. 150.00 EGP)
'currency' => 'EGP',
'payment_methods' => [12345, 67890], // Array of integration IDs (Card, Wallet, etc.)
'billing' => [
'email' => '[email protected] ',
'first_name' => 'John',
'last_name' => 'Doe',
'phone_number' => '+201000000000',
'city' => 'Cairo',
'country' => 'EG',
],
'customer' => [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected] ',
]
];
$intention = PayMob::intention($token, $data);
$checkoutUrl = PayMob::unifiedcheckout($publicKey, $intention->client_secret);
return redirect()->away($checkoutUrl);
$auth = PayMob::authPaymob();
$paymobOrder = PayMob::makeOrderPaymob(
$auth->token,
$auth->profile->id,
$order->totalCost * 100, // Total amount in cents
$order->id // Your order ID
);
$paymentKey = PayMob::getPaymentKeyPaymob(
$integrationId, // Card integration ID
$auth->token,
$order->totalCost * 100,
$paymobOrder->id,
$user->email,
$user->firstname,
$user->lastname,
$user->phone,
$city->name,
$country->name
);
use engalirock\PayMob\Facades\PayMob;
$response = PayMob::authPaymob();
if (!$response || isset($response->detail)) {
Log::error('PayMob Auth Failed', [
'http_code' => PayMob::last_http_code,
'curl_error' => PayMob::last_curl_error,
'headers' => PayMob::last_response_headers,
]);
}
$inquiry = PayMob::transaction_inquiry($token, $orderId);
$orders = PayMob::getOrders($token, $page = 1);
$order = PayMob::getOrder($token, $orderId);
$transactions = PayMob::getTransactions($token, $page = 1);
$transaction = PayMob::getTransaction($token, $transactionId);
$capture = PayMob::capture($token, $transactionId, $amountCents);
bash
php artisan vendor:publish --provider="engalirock\PayMob\PayMobServiceProvider"