elshaden / laravel-tlync
Tlync支付网关的Laravel SDK
3.0.3
2024-09-21 10:06 UTC
Requires
- illuminate/contracts: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.14.0
README
来自Tadawul数字解决方案提供商,(TDSP)
概述
此包是Tlync支付网关的Laravel SDK,您可以在Tlync API文档中了解更多关于Tlync API的信息。
要使用此包,您必须在Tlync上拥有账户,并拥有API密钥和API密钥。
您还需要在数据库中创建一个临时表来存储发送到Tlync之前的新订单。这将有助于确保已完成的付款订单不会再次发送到Tlync,并确保Tlync只会接收唯一的订单。
工作原理
- 客户在您的网站或购物车中下单
- 在数据数据库的临时表中创建新订单
- 将订单发送到Tlync,如下所述
- Tlync将发送带有订单状态的回调到您的网站
- 如果订单已付款,您现在可以在数据库中创建订单并将客户发送到成功页面
- 然后从临时表或标记为已付款的临时订单中删除
- 如果订单未付款,您可以发送客户到失败页面并从临时表中删除订单
安装
您可以通过composer安装此包
composer require elshaden/laravel-tlync
您必须使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-tlync-config"
这是发布配置文件的内容
/* * You can Force test environment even if you application is in production. * This will override the environment settings * This is useful for testing. * */ 'force_test_mode' => env('TLYNC_FORCE_TEST_MODE', false), /* * You can restrict the IP address that can access the callback url. * This is useful for security. * */ 'restrict_ip' => false, /* * You can add the IP address that can access the callback url. * You need to request the IP's from Tlync Support */ 'allowed_ips' => [env('TLYNC_ALLOWED_IPS')], /* * The url that will be used to send the request to Tlync. * This is for testing. */ 'tlync_test_url' => 'https://c7drkx2ege.execute-api.eu-west-2.amazonaws.com/', /* * The Store Id in test environment. * You must add this in the .env file, * do not add here. as this file can be pushed to git. */ 'api_test_key' => env('TLYNC_TEST_STORE_ID'), /* * The Store token that will be used to send the request to Tlync test environment. */ 'tlync_test_token' => env('TLYNC_TEST_TOKEN'), /* * Live Production Environment * The url that will be used to send the request to Tlync. * This is for live production. */ 'tlync_live_url' => 'https://wla3xiw497.execute-api.eu-central-1.amazonaws.com/', /* * The Store Id in live environment. * You must add this in the .env file, * do not add here. as this file can be pushed to git. */ 'api_live_key' => env('TLYNC_LIVE_STORE_ID'), /* * The Store token that will be used to send the request to Tlync live environment. * You must add this in the .env file, * do not add here. as this file can be pushed to git. */ 'tlync_live_token' => env('TLYNC_LIVE_TOKEN'), /* * If you want you can direct the call back coming from Tlync to a specific url. * This is useful if you want to handle the call back in a different controller. * Leave as it is the package will handle the call back. */ 'callback_url' => env('APP_URL') . '/api/tlync/callback', /* * This where the customer will be redirected after payment. * if you want to redirect to another page please add this here * example back to MyCart page. or My Orders Page */ 'frontend_url' => env('APP_URL') , /* * The model class that should be used to mark the payment as paid or failed. * Example class \App\Actions\ConfirmOrder\Class. * */ 'handel_call_back_class' => env('TLYNC_PAYMENT_CLASS', ''), /* * The Method in the handel_call_back_class that will be used to mark the payment as paid. * Example method 'confirm' in \App\Actions\ConfirmOrder\Class. * ``` * public function confirm($order, $request){ * // Change order from temporary to orders and deliver the order. * } * ``` * And completes the process if the payment is paid. * */ 'handel_method' => env('METHOD_TO_CONFIRM_PAYMENT', ''),
还发布Hashids文件,如果您已经有了,请将自定义连接添加到您的文件。Hashids配置负责为临时订单ID提供哈希ID,这样客户就不会看到真实的订单ID。
使用方法
发起支付
use Elshaden\Tlync\Facades\Tlync; $Response = Tlync::InitiatePayment ( float $Amount, // The amount of the order $para_1, // this can be the real temprory order id or the customer id $para_2, // this can be the value of the order int $para_3, // this must the real temprory order id, AND MUST BE UNIQUE & INTEGER string $UserPhone, // Customer Phone Number string $UserEmail // Customer Email Address OPTIONAL )
发起支付响应和重定向
成功响应
如果发起支付成功,您将得到一个数组响应
$Response = [ 'Response' => true, 'message' => 'redirect to url', 'url' => 'https://store.pay.net.ly/tdi/xxxxxxxxxxxxx......', ];
您应该将客户重定向到响应中提供的URL
如果发起支付不成功,您将得到一个数组响应
$Response = [ 'Response' => false, 'message' => 'Error Message', ];
回调
这是Tlync向您的服务器后端发送回调时的情况,其中包含支付状态。配置文件中设置的路线将接收POST回调并在Tlync控制器中处理。
回调验证由Tlync回调方法完成,因此您无需担心这一点。
完成后,此包将调用您在配置文件中设置的类
'handel_call_back_class' => env('TLYNC_PAYMENT_CLASS', ''), 'handel_method' => env('METHOD_TO_CONFIRM_PAYMENT', ''),
传递给它的参数是您在发起支付时发送的参数和Tlync响应
有关Tlync响应的更多信息,请查看Tlync文档
您需要在您的类和方法中处理回调,并对其进行任何操作。通常,如果成功,您需要在数据库中创建订单并将客户发送到成功页面;如果失败,您需要将客户发送到失败页面。
您可以创建自己的类和方法来处理回调,并将其添加到配置文件中。
贡献
有关详细信息,请参阅CONTRIBUTING
安全漏洞
请查阅我们的安全策略,了解如何报告安全漏洞。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅许可证文件。