mtgofa/laravel-paymob
Composer 安装命令:
composer require mtgofa/laravel-paymob
包简介
Laravel PayMob online payment gateway package
README 文档
README
A Laravel online payment gateway.
Table of Contents
Installation
Require via composer
composer require mtgofa/laravel-paymob
Laravel<=5.* In config/app.php file
'providers' => [ ... MTGofa\PayMob\PayMobServiceProvider::class, ... ]; 'aliases' => [ ... 'PayMob' => MTGofa\PayMob\Facades\PayMob::class, ... ];
First of all, make an account on WeAccept portal, run this command to generate the PayMob configuration file
$ php artisan vendor:publish --provider="MTGofa\PayMob\PayMobServiceProvider"
Then fill in the credentials in config/paymob.php file. Make sure to make an iframe in your dashboard and get the integration id for payment requests.
Fill in the processed callback and response callback routes in integration details with the routes for processedCallback and invoice methods in PayMobController
Steps to make a transaction on PayMob servers
- API Authentication Request
- Order Registration Request
- Payment Key Generation Request
- Prepare Client Code to Perform Payment Request (Webclients and mobile apps)
- Merchant Notification Endpoint
- Transaction Response Endpoint
You can refer to PayMob online guide for more information.
1. API Authentication Request (server side)
In this step you are required to perform a post request to PayMob's authentication API to obtain authentication token
Use PayMob Facade to make requests.
$auth = PayMob::authPaymob(); // Run this method to get a sample response of auth request. PayMob::sample('authPaymob');
This method gets the credentials from config/paymob.php file, so fill in username and password first to make this auth request.
2. Order Registration Request (server side)
At this step you will register an order on Paymob Accept so that you can pay for it later using a transaction.
$paymobOrder = PayMob::makeOrderPaymob( $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');
Store the returned paymob order id in your DB to make transactions with using this id in future.
3. Payment Key Generation Request (server side)
At this step you will obtain a payment_key token. This key will be used to authenticate your payment request.
$paymentKey = PayMob::getPaymentKeyPaymob( $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');
4. Prepare Client Code to Perform Payment Request (Webclients and mobile apps) (client side)
Now that you have obtained payment key, you need to prepare your checkout experience (i.e. client-side code).
Iframe for websites/webapps
PayMob recommended iframe
<form id="paymob_checkout"> <label for="">Card number</label> <input type="text" value="4987654321098769" paymob_field="card_number"> <br> <label for="">Card holdername</label> <input type="text" value="Test Account" paymob_field="card_holdername"> <br> <label for="">Card month</label> <input type="text" value="05" paymob_field="card_expiry_mm"> <br> <label for="">Card year</label> <input type="text" value="21" paymob_field="card_expiry_yy"> <br> <label for="">Card cvn</label> <input type="text" value="123" paymob_field="card_cvn"> <input type="hidden" value="CARD" paymob_field="subtype"> <input type="checkbox" value="tokenize" name="save card"> <label for="save card">save card</label> <input type="submit" value="Pay"> <br> </form>
<iframe src="https://accept.paymobsolutions.com/api/acceptance/iframes/{{config('paymob.iframe_id')}}?payment_token={{$paymentKey->token}}"></iframe>
Mobile clients
In case of mobile apps, you will need to import Accept native IOS or Android SDK to proceed with the payment and/or save the card details.
Please request the needed SDK by emailing support@weaccept.co For more information visit PayMob mobile guid
$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');
You can use some test cards to make a test payment.
You can run PayMob::sample() to see available samples.
PayMobController
We have 4 methods in PayMobController.
First use checkingOut method to display the payment form page with the iframe. Or simply make payment using payAPI method for mobile clients.
Then, we have the processedCallback method to catch the POST callback response from PayMob servers, and invoice method to catch the GET callback response and display your invoice page.
Replace all #code ... with your logic.
Don't forget to make routes for these methods, and to save the processedCallback and invoice routes in the integration details in PayMob dashboard.
PayMob Postman Collection
There is a Postman collection for PayMob requests.
Other PayMob Methods
There are some GET methods to get your data from PayMob.
1. Get All Orders
PayMob::getOrders( $page // optional for pagination, by default set to 1 );
2. Get a Specific Order
PayMob::getOrder( $order->paymob_order_id // PayMob order id from step 2. );
3. Get All Transactions
PayMob::getTransactions( $page // optional for pagination, by default set to 1 );
4. Get a Specific Transaction
PayMob::getTransaction( $transactionId // PayMob transaction id from step 4. );
5. Capture For Auth Transactions
If your transactions is auth type (not standalone), then you have to capture your payment through capture method.
PayMob::capture( $transactionId, // the returned id from step 4. $totalCost * 100 // total price/cost in cents/piasters. );
TODO
- Invoice page.
- Sample transaction cycle.
- Get all orders/transactions page.
- Refund from backend.
- Iframe with JS validations.
- Top level redirect request for 3D secure.
License
Laravel PayMob is a free software distributed under the terms of the MIT license.
mtgofa/laravel-paymob 适用场景与选型建议
mtgofa/laravel-paymob 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 399 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「payment」 「gateway」 「laravel」 「online」 「Egypt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mtgofa/laravel-paymob 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mtgofa/laravel-paymob 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mtgofa/laravel-paymob 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
Client library to send SMS using Comilio SMS Gateway API (https://www.comilio.it)
Alfabank REST API integration
GovPayNet driver for the Omnipay payment processing library
BlueSnap driver for the Omnipay payment processing library
统计信息
- 总下载量: 399
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-30