plisio / plisio-sdk-laravel
使用 Plisio API 构建自己的支付网关的 SDK 包。
v1.0.0
2023-03-28 19:57 UTC
Requires
- php: >=7.3
- ext-curl: *
README
Laravel 兼容性
安装
使用包管理器 composer 安装 Plisio SDK 包。
composer require plisio/plisio-sdk-laravel
发布配置文件。
php artisan vendor:publish --provider="Plisio\PlisioSdkLaravel\Providers\PlisioProvider"
编辑位于 app/config/plisio.php
的配置文件,并输入您的 Plisio API 密钥
用法
初始化 Plisio SDK
要使用 Plisio SDK 功能,您需要初始化它。以下示例将考虑 SDK 的初始化已经完成。
use Plisio\PlisioSdkLaravel\Payment; //Initializing payment gateway with api_key in app/config . $plisioGateway = new Payment(config('plisio.api_key'));
获取商店信息
获取配置文件中指定的 API 密钥的商店信息。
$shopInfo = $plisioGateway->getShopInfo();
获取余额信息
获取指定钱包的余额。
$btcWalletBalance = $plisioGateway->getBalances('BTC');
获取启用的加密货币
获取商店中启用的加密货币信息。指定 $source_currency 以获取法定货币/加密货币汇率,否则将显示 USD/加密货币。
$currencies = $plisioGateway->getCurrencies('CAD');
创建发票并处理 Plisio 响应
//Data about the client and his order, which must be inserted into the invoice. $params = [...]; $data = array( 'order_name' => 'Order #' . $params['invoiceid'], //Merchant internal order name. 'order_number' => $params['invoiceid'], //Merchant internal order number. Must be a unique number in your store for each new store`s order. 'description' => $params['order_description'], //Optional order description. 'source_amount' => number_format($params['amount'], 8, '.', ''), //Invoice total float value in fiat currency. 'source_currency' => $params['currency'], //Fiat currency code. For example: USD, BRL, CAD etc. 'cancel_url' => 'https://examplestore.com/failedOrder.php?id=' . $params['invoiceid'], //User will be redirected to this link in a case of invoice payment failure. 'callback_url' => 'https://examplestore.com/callback.php', //The link to which you will receive a notification about a change in the status of the order. 'success_url' => 'https://examplestore.com/successOrder.php?id=' . $params['invoiceid'], //User will be redirected to this link in a case of invoice payment success. 'email' => $params['clientdetails']['email'], //User's email. If not specified user will be asked to enter his email on the invoice page. 'plugin' => 'laravelSdk', //Payment gateway origin. This value will help Plisio to analyse any problem occurred with SDK functionality. 'version' => '1.0.0' //Consider updating this setting every time you update the functionality related to this sdk. ); //Create invoice and put response to the $response variable. $response = $plisioGateway->createTransaction($data); //Check the response and, depending on the result, redirect the user to Plisio for further payment or return to the checkout page with an error. if ($response && $response['status'] !== 'error' && !empty($response['data'])) { redirect($response['data']['invoice_url']); clearCart(); } else { $errorMessage = implode(',', json_decode($response['data']['message'], true)); redirectToCheckout(); }
创建白标签发票
在这种情况下,您应该检查商店是否启用了白标签
$shopInfo = $plisioGateway->getShopInfo(); $isWhiteLabel = $shopInfo['data']['white_label'];
如果启用了白标签,那么在创建发票时,您将收到关于它的全部信息,这将允许您在任何页面上渲染发票。
验证回调数据
在创建发票并更改其状态时,Plisio 将将回调发送到创建发票时指定的地址。要验证回调的真实性,请使用 verifyCallbackData 函数。
//callback.php $callbackData = $_POST; if ($plisioGateway->verifyCallbackData($callbackData)) { //Change invoice status, notify user etc. } else { //HTTP 403 error. Callback data is not valid! }
关于 Plisio API 的更多信息
https://plisio.net/documentation