The Paymob PHP library provides convenient access to the Paymob API from applications written in the PHP language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Paymob API.
PHP 7.2.0 and later.
You can install the bindings via Composer. Run the following command:
composer require paymob/paymob-phpTo use the bindings, use Composer's autoload:
require_once('../vendor/autoload.php');After installation run the command
composer dump-autoloadthen
composer updateThe bindings require the following extensions in order to work properly:
If you use Composer, these dependencies should be handled automatically
Paymob usage looks like:
$secret_key="skl_***";
$app=new Paymob($secret_key);
$body=array($amount=1000,
$currency="EGP",
$payment_methods=["card", "kiosk"],
$billing_data=[
"apartment"=> "803",
"email"=> "[email protected]",
"floor"=> "42",
"first_name"=> "Clifford",
"street"=> "Ethan Land",
"building"=> "8028",
"phone_number"=> "+86(8)9135210487",
"shipping_method"=> "PKG",
"postal_code"=> "01898",
"city"=> "Jaskolskiburgh",
"country"=> "CR",
"last_name"=> "Nicolas",
"state"=> "Utah",
],
$delivery_needed=False,);
echo $app->intent->create('',$body); $secret_key="skl_***";
$app=new Paymob($secret_key);
echo $app->intent->list(''); $secret_key="skl_***";
$app=new Paymob($secret_key);
echo $app->intent->retrieve(''); $secret_key="skl_***";
$app=new Paymob($secret_key);
$body=array($payment_reference="14394788");
echo $app->payment_reference->void('',$body); $secret_key="skl_***";
$app=new Paymob($secret_key);
$body=array($payment_reference="14394788",
$amount="300");
echo $app->payment_reference->refund('',$body); $secret_key="skl_***";
$app=new Paymob($secret_key);
$body=array($payment_reference="14394788",
$amount="300");
echo $app->payment_reference->capture('',$body);If you are using PHP 7.2 or later, you should consider upgrading your environment as those versions have been past end of life since September 2017.
Get Composer. For example, on Mac OS:
brew install composerInstall dependencies:
composer install