Laravel | plisio-sdk-laravel |
---|---|
5.6.* - 8.* (PHP 7 required) | 1.0.0 |
Use the package manager composer to install Plisio SDK package.
composer require plisio/plisio-sdk-laravel
Publish config file.
php artisan vendor:publish --provider="Plisio\PlisioSdkLaravel\Providers\PlisioProvider"
Edit the config file located in app/config/plisio.php
and enter your Plisio Api Key
To use Plisio sdk functionality you need to initialize it. The following examples will take into account that the initialization of the sdk has already taken place.
use Plisio\PlisioSdkLaravel\Payment;
//Initializing payment gateway with api_key in app/config .
$plisioGateway = new Payment(config('plisio.api_key'));
Get information about shop which api key is specified in the config file.
$shopInfo = $plisioGateway->getShopInfo();
Get balance of the specified wallet.
$btcWalletBalance = $plisioGateway->getBalances('BTC');
Get information about the cryptocurrencies that are enabled in the store. Specify $source_currency to get fiat/crypto rate otherwise USD/crypto will be shown.
$currencies = $plisioGateway->getCurrencies('CAD');
//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();
}
In this case you should check if white label is enabled in the store:
$shopInfo = $plisioGateway->getShopInfo();
$isWhiteLabel = $shopInfo['data']['white_label'];
If the white label is enabled, then when you create an invoice, you will receive full information about it, which will allow you to render the invoice on any page of your site.
When creating an invoice and changing its status, Plisio will send a callback to the address specified when creating the invoice. To verify the authenticity of a callback, use the verifyCallbackData function.
//callback.php
$callbackData = $_POST;
if ($plisioGateway->verifyCallbackData($callbackData)) {
//Change invoice status, notify user etc.
} else {
//HTTP 403 error. Callback data is not valid!
}