devinweb/payment
Composer 安装命令:
composer require devinweb/payment
包简介
README 文档
README
Payment Package provide a simple way to handle payment gateway in MENA.
Installation
This package requires Laravel 5.4 or higher. if your laravel is > 5.4 you can skip the two steps (2, 3) below (Package Auto Discovery 5.5+).
- You can install the package via composer:
composer require devinweb/payment
- Open your
config/app.phpand add the following to the providers array
Devinweb\Payment\PaymentServiceProvider::class,
- In the same
config/app.phpand add the following to the aliases array:
'Payment' => Devinweb\Payment\Facades\Payment::class,
- Run the command below to publish the package config file
config/payfort-payment.php:
php artisan vendor:publish --provider="Devinweb\Payment\PaymentServiceProvider" --tag="config"
Payfort
To pay via payfort it's simple, but before process the payment it's requiered to setup your FrontEnd, you can check the payment-boilerplate Repository.
Configuration (Payfort)
Now you can add your payfort credentiels to app/config/payments/php
<?php 'payfort' => [ 'callback_urls' => [ 'error-page' => '/api/error', 'success-page' => '/api/success', ], 'sandboxMode' => env('PAYFORT_SAND_BOX_MODE', true), /** * language used to specify the response language returned from payfort */ 'language' => env('LANGUAGE', 'en'), /** * your Merchant Identifier account (mid) */ 'merchantIdentifier' => env('MERCHANT_IDENTIFIER', ''), /** * your access code */ 'accessCode' => env('ACCESS_CODE', ''), /** * SHA Request passphrase */ 'SHARequestPhrase' => env('SHA_REQUEST_PASSPHRASE', ''), /** * SHA Response passphrase */ 'SHAResponsePhrase' => env('SHA_RESPONSE_PASSPHRASE', ''), /** * SHA Type (Hash Algorith) * expected Values ("sha1", "sha256", "sha512") */ 'SHAType' => env('SHA_TYPE', 'sha256'), /** * command * expected Values ("AUTHORIZATION", "PURCHASE") */ 'command' => env('COMMAND', 'AUTHORIZATION'), /** * order currency */ 'currency' => env('CURRENCY', 'USD'), ]
Routing (Payfort)
Next to use Payfort, you need three Routes:
- Used to submit data from the front end to the backend.
- The second if the payment is successfuly.
- For redirecting if payfort response with error.
<?php // App\Config\payments.php // you can configure you callback routes here 'payfort' => [ 'callback_urls' => [ 'error-page' => '', // redirection to error page 'success-page' => '', // redirection to success page ], // ... ]
you can access to Payment using Payment facade.
<?php use Illuminate\Http\Request; Route::post('/payment', function (Request $request) { // ... $merchant_reference = rand(0, getrandmax()); return Payment::use('payfort', $merchant_reference)->pay(); });
Required Parameters (Payfort)
Each request should be contains amount, email, hold_name
<?php $request->add([ 'amount' => '', 'email' => '', 'hold_name' => '' ])
Payfort Apple Pay
You can use this package to handle the apple pay transactions via Payfort.
Configuration (Payfort Apple Pay)
you should add payfort apple pay credentiels to the app/confing/payments/php
<?php 'payfort_apple_pay' => [ 'sandboxMode' => true, 'language' => 'ar', 'merchantIdentifier' => '', 'accessCode' => '', 'SHARequestPhrase' => '', 'SHAResponsePhrase' => '', 'SHAType' => 'sha256', 'command' => 'PURCHASE', 'currency' => 'SAR', ]
Usage (Payfort Apple Pay)
To pay via Payfort apple pay is the the same as before you can use.
return Payment::use('payfort_apple_pay', $merchant_reference)->pay();
Required Parameters (Payfort Apple Pay)
The parameters required to be attached in your request payload to use Apple Pay is:
{
"apple_data": "",
"apple_header": {
"apple_ephemeralPublicKey": "",
"apple_publicKeyHash": "",
"apple_transactionId": "-"
},
"apple_paymentMethod": {
"apple_displayName": "",
"apple_network": "",
"apple_type": ""
},
"apple_signature": "",
"apple_version": "EC_v1",
"digital_wallet": "APPLE_PAY",
//package requirements
"amount": 240,
// optional data if you need them
"email": "",
"name": "",
"phone": ""
}
Pay With ReactNative
if you want to process the payment via webView in your react native mobile app
function onNavigationStateChange() { // this method will be invoked each time the url changed } function onMessage() { // here you can handle the final result } return ( <WebView source={{ html: html() }} onNavigationStateChange={onNavigationStateChange} javaScriptEnabled={true} domStorageEnabled={true} onMessage={onMessage} startInLoadingState /> );
In your php controller or route you can use
<?php return Payment::use('payfort')->viaReactNative()->pay();
Payfort Events
As we know payfort can notify the merchant, for all events you subscribed for on an transaction. we need the first to add your callback into payfort dashboard, then you can implement this callback in your application
<?php use Illuminate\Http\Request; Route::match(['get', 'post'], '/payfort-callback', function(Request $request) { return Payment::use('payfort')->webHook(); });
This webHook can invoks two events build in. There are two events available for you to listen for.
| Event | Fired | Parameter |
|---|---|---|
Devinweb\Payment\Events\SuccessTransaction |
when payfort response with the successful data | array success response |
Devinweb\Payment\Events\FailTransaction |
when payfort response with the Fail data | array fail_response |
exemple
check this repos payment-boilerplate.
Success response
[ "response_code" => "18000", "card_number" => "400555******0001", "card_holder_name" => "CUSTOMER_HOLDER_NAME", "signature" => "d641d71c13da959cba92371d70c686b602e2b62796dfca5286c760c6b5d9e3b1", "merchant_identifier" => "YOUR_MERCHANT_IDENTIFIER", "expiry_date" => "2105", "access_code" => "YOUR_ACCESS_CODE", "language" => "ar", "service_command" => "TOKENIZATION", "response_message" => "عملية ناجحة", "merchant_reference" => "278245857", "token_name" => "dced12c0eeeb444185dcc450b917d987", "return_url" => "YOUR_RETURN_URL" "card_bin" => "400555" "status" => "18" ]
Fail response
[ "response_code" => "00016", "card_number" => "400550******0001", "card_holder_name" => "CUSTOMER_HOLDER_NAME", "signature" => "signature_value", "merchant_identifier" => "YOUR_MERCHANT_IDENTIFIER", "expiry_date" => "2105", "access_code" => "YOUR_ACCESS_CODE", "language" => "ar", "service_command" => "TOKENIZATION", "response_message" => "رقم البطاقة غير صحيح", "merchant_reference" => "158151963", "return_url" => "YOUR_RETURN_URL", "status" => "00", "error_msg" => "رقم البطاقة غير صحيح", ]
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
About Devinweb
Devinweb is a web app agency in Tetouan, Morocco. our website.
License
The MIT License (MIT). Please see License File for more information.
devinweb/payment 适用场景与选型建议
devinweb/payment 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 369 次下载、GitHub Stars 达 14, 最近一次更新时间为 2020 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「devinweb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 devinweb/payment 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 devinweb/payment 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 devinweb/payment 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel package for Hyperpay payment gateway in MENA.
YouCanPay packages for Laravel that provides an easy way to reach the best experience.
Laravel package for Paytabs payment gateway
TrinkPOS Sanal POS (Virtual POS) API client for PHP
Merchant-side PHP SDK for YoPay Pay Open API.
Laravel Cashier Bachs provides an expressive, fluent interface to Bachs' subscription billing services.
统计信息
- 总下载量: 369
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-19