chargily / epay-php
此包已被弃用且不再维护。未建议替代包。
Chargily ePay网关集成PHP库
3.0.0
2022-07-17 13:45 UTC
Requires
- php: ^8.0.2
- guzzlehttp/guzzle: ^7.0
- laravel/helpers: ^1.5
- rakit/validation: ^1.4
Requires (Dev)
- phpunit/phpunit: ^9
README
轻松集成e支付网关。
要求
- PHP 7.2.5或更高版本。
- 从ePay by Chargily仪表板免费获取您的API密钥/密码。
安装
- 通过Composer(推荐)
composer require chargily/epay-php
- 下载ZIP版本。我们不推荐此选项。但请注意,要定期下载更新版本下载
快速入门
- 创建配置文件epay_config.php。这是存储您的API凭证的位置。
// Configurations file return [ 'key' => 'your-api-key', // you can you found it on your epay.chargily.com.dz Dashboard 'secret' => 'your-api-secret', // you can you found it on your epay.chargily.com.dz Dashboard ];
- 创建支付重定向文件redirect.php
use Chargily\ePay\Chargily; require 'path-to-vendor/vendor/autoload.php'; $epay_config = require 'epay_config.php'; $chargily = new Chargily([ //credentials 'api_key' => $epay_config['key'], 'api_secret' => $epay_config['secret'], //urls 'urls' => [ 'back_url' => "valid-url-to-redirect-after-payment", // this is where client redirected after payment processing 'webhook_url' => "valid-url-to-receive-payment-informations", // this is where you receive payment informations ], //mode 'mode' => 'EDAHABIA', //OR CIB //payment details 'payment' => [ 'number' => 'payment-number-from-your-side', // Payment or order number 'client_name' => 'client name', // Client name 'client_email' => 'client_email@mail.com', // This is where client receive payment receipt after confirmation 'amount' => 75, //this the amount must be greater than or equal 75 'discount' => 0, //this is discount percentage between 0 and 99 'description' => 'payment-description', // this is the payment description ] ]); // get redirect url $redirectUrl = $chargily->getRedirectUrl(); //like : https://epay.chargily.com.dz/checkout/random_token_here // if($redirectUrl){ //redirect header('Location: '.$redirectUrl); }else{ echo "We cant redirect to your payment now"; }
- 创建支付处理文件process.php
use Chargily\ePay\Chargily; require 'path-to-vendor/vendor/autoload.php'; $epay_config = require 'epay_config.php'; $chargily = new Chargily([ //credentials 'api_key' => $epay_config['key'], 'api_secret' => $epay_config['secret'], ]); if ($chargily->checkResponse()) { $response = $chargily->getResponseDetails(); //@ToDo: Validate order status by $response['invoice']['invoice_number']. If it is not already approved, approve it. //something else /* $response like the follwing array $response = array( "invoice" => array( "id" => 5566321, "client" => "Client name", "invoice_number" => "123456789", "due_date" => "2022-01-01 00:00:00", "status" => "paid", "amount" => 75, "fee" => 25, "discount" => 0, "comment" => "Payment description", "tos" => 1, "mode" => "EDAHABIA", "invoice_token" => "randoom_token_here", "due_amount" => 10000, "created_at" => "2022-01-01 06:10:38", "updated_at" => "2022-01-01 06:13:00", "back_url" => "https://www.mydomain.com/success", "new" => 1, ); ) */ exit('OK'); }
- 测试您的webhook(处理)URL的指南 点击这里
配置
- 可用的配置
key | 描述 | redirect url | process url |
---|---|---|---|
api_key | 必须是由组织提供的字符串 | 必需 | 必需 |
api_secret | 必须是由组织提供的字符串 | 必需 | 必需 |
urls | 必须是一个数组 | 必需 | 非必需 |
urls[back_url] | 必须是一个字符串和有效的URL | 必需 | 非必需 |
urls[process_url] | 必须是一个字符串和有效的URL | 必需 | 非必需 |
mode | 必须是CIB或EDAHABIA之一 | 必需 | 非必需 |
payment[number] | 必须是字符串或整数 | 必需 | 非必需 |
payment[client_name] | 必须是字符串 | 必需 | 非必需 |
payment[client_email] | 必须是字符串和有效的电子邮件。这是客户端在确认后接收付款收据的位置。 | 必需 | 非必需 |
payment[amount] | 必须是数字,且大于等于75 | 必需 | 非必需 |
payment[discount] | 必须是数字,介于0和99.99之间(折扣百分比) | 必需 | 非必需 |
payment[description] | 必须是字符串 | 必需 | 非必需 |
选项 | 必须是一个数组 | 必需 | 非必需 |
options[headers] | 必须是一个数组 | 必需 | 非必需 |
options[timeout] | 必须是数字 | 必需 | 非必需 |
注意
- 如果您遇到问题,请点击此处打开问题