mgamal / paymob-laravel
Paymob API with Laravel
Installs: 771
Dependents: 0
Suggesters: 0
Security: 0
Stars: 33
Watchers: 1
Forks: 13
Open Issues: 7
Requires
- php: ^8.1
- friendsofphp/php-cs-fixer: ^3.4
- guzzlehttp/guzzle: ^7.4
- laravel/framework: >=6.20
Requires (Dev)
- orchestra/testbench: ^7.17
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
README
This is an integration between Laravel framework and Paymob API to make it easier for developers to use Paymob functionalities in their applications.
Installation
You can install the package via composer:
composer require mgamal/paymob-laravel
Optionally, you can publish the config file with:
php artisan vendor:publish --tag=config --provider="MG\Paymob\PaymobServiceProvider"
Usage
- Set Paymob credentials
PAYMOB_API_KEY = xxxxxxxxxxxxxxxxxxxxxx PAYMOB_INTEGRATION_ID = xxxxxx PAYMOB_IFRAME_ID = xxxxx PAYMOB_HMAC_SECRET = xxxxxxxxx
Reference: Paymob integration
- Prepare order items
- Prepare billing data
- Prepare total order
- Make payment with the full details of the order: items, billing data and total order.
Example
use MG\Paymob\Paymob; public function checkout(){ // Prepare order items $orderItems = [ [ 'name' => 'Product x', 'amount_cents' => 100, 'description' => 'Product description', 'quantity' => 1 ] ]; // Prepare billing data: Fill empty keys with 'N/A'; required! $billingData = [ 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'someone@example.com', 'phone_number' => '+1xxxxxxxx', 'apartment' => 'N/A', 'floor' => 'N/A', 'building' => 'N/A', 'street' => 'N/A', 'city' => 'N/A', 'shipping_method' => 'N/A', 'country' => 'N/A', 'state' => 'N/A', ]; // Prepare order itself $orderToPrepare['amount_cents'] = 10; $orderToPrepare['merchant_order_id'] = 101; $orderToPrepare['items'] = $orderItems; $orderToPrepare['billing_data'] = $billingData; // Get payment URL $paymentUrl = $item->makePayment($orderToPrepare); return $paymentUrl; }