系统/alet-systems / alet-payment
AletPayment Laravel API 包。
v1.1.0
2024-01-16 07:01 UTC
Requires
- php: ^7.2|^8.1
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
README
AletPayment Laravel API 包。
文档
查看开发者
API 文档。
安装
您可以通过 composer 安装此包
composer require alet-systems/alet-systems
对于 Laravel 版本 <= 5.4
在版本 5.4 或以下,您必须手动在 config/app.php 配置文件的别名部分注册您的外观。
"aliases": { "AletPayment": "AletPayment\\AletPayment\\Facades\\AletPayment" }
用法
该包需要使用您账户的 API 密钥进行配置,该密钥可在 AletPayment 控制台 中找到。使用密钥的值要求它。安装包后,您可以使用如下方式。
⚠️ 从 V2 开始
AletPayment->create()
已弃用,应使用AletPayment->checkout->create()
。
use AletPayment\AletPayment\AletPayment; ... $alet-systems = new AletPayment('your-api-key');
创建结账会话
导入 alet-systems
包后,使用 AletPayment 实例的结账属性来创建或获取 结账会话
。
use AletPayment\AletPayment\AletPayment; use AletPayment\AletPayment\Helper\AletPaymentSupport; use AletPayment\AletPayment\Lib\AletPaymentBeneficary; use AletPayment\AletPayment\Lib\AletPaymentCheckoutItem; use AletPayment\AletPayment\Lib\AletPaymentCheckoutRequest; use AletPayment\AletPayment\Lib\AletPaymentOptions; use Illuminate\Support\Carbon; $alet-systems = new AletPayment('your-api-key'); $d = new Carbon::now(); $d->setMonth(10); $expired = AletPaymentSupport::getExpireDateFromDate($d); $data = new AletPaymentCheckoutRequest( cancel_url: 'https://api.alet-systems.com', error_url: 'https://api.alet-systems.com', notify_url: 'https://gateway.alet-systems.net/test/callback', expireDate: $expired, nonce: floor(rand() * 10000) . "", beneficiaries: [ AletPaymentBeneficary::fromJson([ "accountNumber" => '01320811436100', "bank" => 'AWINETAA', "amount" => 10.0, ]), ], paymentMethods: ["CARD"], success_url: 'https://gateway.alet-systems.net', items: [ AletPaymentCheckoutItem::fromJson([ "name" => 'Bannana', "price" => 10.0, "quantity" => 1, ]), ], ); $session = $alet-systems->checkout->create($data, new AletPaymentOptions(sandbox: true)); echo $session->session_id;
::注意您必须使用 use Illuminate\Support\Carbon
而不是 use Carbon\Carbon
来获取过期日期
在设置您的 AletPaymentCheckoutRequest
后,只需调用 create
方法。注意传递 sandbox: true
选项将创建测试环境中的会话。
此会话响应对象包含以下字段
{ sessionId: string; paymentUrl: string; cancelUrl: string; totalAmount: number; }
通过会话 ID 获取会话
要跟踪结账会话的进度,可以使用以下方法使用 fetch 方法
$alet-systems = new AletPayment('API KEY...'); // A sessionId will be returned when creating a session. $session = $alet-systems->checkout->fetch('checkOutSessionID', new AletPaymentOptions(true));
以下对象表示一个会话
{ public int $id, public AletPaymentTransaction $transcation, public float $totalAmount, public bool $test, public string $uuid, public string $created_at, public string $update_at }
通过会话 ID 取消会话
如果商家想要取消结账会话,现在可以这样做。
$alet-systems = new AletPayment('API KEY...'); // A sessionId will be returned when creating a session. $session = $alet-systems->checkout->cancel('checkOutSessionID', new AletPaymentOptions(true));
返回 AletPaymentCheckoutSession
类。
直接支付
在这里了解有关 DirectPay 的更多信息
Telebirr 的直接支付
$session = $alet-systems->checkout->create($data, new AletPaymentOptions(true)); return $alet-systems->directPay->telebirr->pay($session->session_id);
awash 钱包的直接支付
$session = $alet-systems->checkout->create($data, new AletPaymentOptions(true)); return $alet-systems->directPay->awash_wallet->pay($session->session_id);
awash 的直接支付
$session = $alet-systems->checkout->create($data, new AletPaymentOptions(true)); return $alet-systems->directPay->awash->pay($session->session_id);
变更日志
发布日期:v1.0.0
2022年6月9日
- 初始发布
发布日期:v1.2.0
2022年6月30日
- 命名空间已更改。请使用 AletPayment/AletPayment
- 异常处理改进
发布日期:v1.3.0
2022年6月30日
- 结账会话创建表单中的
expiredate
参数格式已更改为 LocalDateTime 格式 - 非现有会话的异常处理
发布日期:v2.0.0
2022年8月10日
- 为 Telebirr 和 Awash 支付选项添加了
DirectPay
更多信息
致谢
许可协议
MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件。