egyjs/arb
Composer 安装命令:
composer require egyjs/arb
包简介
Laravel API for Al Rajhi Bank's payment gateway (ARB)
README 文档
README
This package is a wrapper around the Al Rajhi Bank payment gateway API, it allows you to initiate a payment request hosted on the Bank website or on the merchant website, and also allows you to refund a payment.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require egyjs/arb
You can publish the config file with:
php artisan vendor:publish --tag="arb-config"
This is the contents of the published config file:
return [ 'mode' => env('ARB_MODE', 'test'), // test or live 'test_merchant_endpoint' => 'https://securepayments.alrajhibank.com.sa/pg/payment/tranportal.htm', 'live_merchant_endpoint' => 'https://digitalpayments.alrajhibank.com.sa/pg/payment/tranportal.htm', 'test_bank_hosted_endpoint' => 'https://securepayments.alrajhibank.com.sa/pg/payment/hosted.htm', 'live_bank_hosted_endpoint' => 'https://digitalpayments.alrajhibank.com.sa/pg/payment/hosted.htm', 'tranportal_id' => env('ARB_TRANPORTAL_ID'), 'tranportal_password' => env('ARB_TRANPORTAL_PASSWORD'), "resource_key" => env('ARB_RESOURCE_KEY'), // your resource key "currency_code" => env('ARB_CURRENCY_CODE', '682'), ];
add the following to your .env file
ARB_MODE="test" # test or live ARB_TRANPORTAL_ID="your_tranportal_id" ARB_TRANPORTAL_PASSWORD="your_tranportal_password" ARB_RESOURCE_KEY="your_resource_key" ARB_CURRENCY_CODE="682" # "682" = SAR
Usage
Bank hosted payment
to initiate a payment request hosted on the Bank website
use Egyjs\Arb\Facades\Arb; $responce = Arb::initiatePayment(100); // 100 to be paid dd($responce); /** @example {# +"success": true +"url": "https://securepayments.alrajhibank.com.sa/pg/paymentpage.htm?PaymentID=?paymentId=000000000000000000" } */
merchant hosted payment
to initiate a payment request hosted on the merchant website, you need to create a form for the card details, and pass
the card details to the Arb::card() method, then call the Arb::initiatePayment() method as shown below
use Egyjs\Arb\Facades\Arb; use Egyjs\Arb\Objects\Card; Arb::card([ 'number' => '5105105105105100', 'year' => '20'.'24', 'month' => '12', 'name' => 'AbdulRahman', 'cvv' => '123', 'type' => Card::CREDIT // or Card::DEBIT ]); $responce = Arb::initiatePayment(100); // 100 to be paid dd($responce); /** @example {# +"success": true +"url": "https://securepayments.alrajhibank.com.sa/pg/payment/hosted.htm?paymentId=000000000000000000&id=000x0bAdcEF0HfZ" } */
Refund a payment
to refund a payment you need to call the Arb::refund() method as shown below
use Egyjs\Arb\Facades\Arb; $responce = Arb::refund('000000000000000000', 100); // 100 to be refunded dd($responce); /** @example {# +"success": true +"data": {} } */
manage data sent & received from the bank
to send custom data to the bank, you can use the Arb::data() method before any transaction as shown below
use Egyjs\Arb\Facades\Arb; Arb::data([ 'request_id' => 23, 'user_id' => 43, ]); // initiate a payment or make a refund
this data will be sent to the bank and will be returned in the response from the bank,
ArbPaymentSuccessEvent will be fired with the received data from the bank as shown below
use Egyjs\Arb\Events\ArbPaymentSuccessEvent; Event::listen(ArbPaymentSuccessEvent::class, function (ArbPaymentSuccessEvent $event) { $response = $event->response; // to get the data sent to the bank $data = $response->getOriginalData(); });
Note: you can listen to the
ArbPaymentSuccessEventin both ways:EventServiceProvider::$listenorEvent::listen()method
Handle the response
egyjs/arb has a built-in event driven architecture (EDA) system to handle the response from the bank;
you can listen to the ArbPaymentSuccessEvent event to handle the success response,
and the ArbPaymentFailedEvent event to handle the fail response,
The use of events allows for decoupling between the processing logic and the actions taken upon success or failure. By emitting events, the processing logic doesn't need to know about or be tightly coupled to the actions taken upon success or failure. you can listen to the events in 2 ways:
- using the
EventServiceProviderclass
use Egyjs\Arb\Events\ArbPaymentFailedEvent; use Egyjs\Arb\Events\ArbPaymentSuccessEvent; protected $listen = [ // ... ArbPaymentSuccessEvent::class => [ LogSuccessArbPaymentListener::class, // add any listener classes you want to handle the success payment ], ArbPaymentFailedEvent::class => [ LogFailedArbPaymentListener::class, // add any listener classes you want to handle the failed payment ], ];
- using the
Event::listen()method
use Egyjs\Arb\Events\ArbPaymentFailedEvent; use Egyjs\Arb\Events\ArbPaymentSuccessEvent; Event::listen(ArbPaymentSuccessEvent::class, function (ArbPaymentSuccessEvent $event) { // handle the success payment }); Event::listen(ArbPaymentFailedEvent::class, function (ArbPaymentFailedEvent $event) { // handle the failed payment });
handle the response in the controller
if you want to handle the using a custom route instead of the events,
you can pass the success and fail urls to the Arb::successUrl() and Arb::failUrl() methods as shown below
use Egyjs\Arb\Facades\Arb; Arb::successUrl('http://localhost:8000/arb/response') ->failUrl('http://localhost:8000/arb/response'); $responce = Arb::initiatePayment(100); // 100 to be paid dd($responce); /** @example {# +"success": true +"url": "http://localhost:8000/success/handle?paymentId=000000000000000000" } */
your /routes/web.php file should look like this
use Illuminate\Http\Request; Route::post('/arb/response', function (Request $request) { if ($request->status == 'success') { // handle the success payment } else { // handle the failed payment } });
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
egyjs/arb 适用场景与选型建议
egyjs/arb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.05k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2024 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「egyjs」 「arb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 egyjs/arb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 egyjs/arb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 egyjs/arb 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generate Laravel Eloquent models and migration files directly from your DBML (Database Markup Language) files with ease.
Alfabank REST API integration
Laravel API for Al Rajhi Bank's payment gateway (ARB)
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
统计信息
- 总下载量: 10.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-25