A simple Laravel package for Barion payment gateway
tomise/laravel-barion is a Laravel package for a simple laravel package for barion payment gateway.
It currently has 0 GitHub stars and 4 downloads on Packagist (latest version 0.9.4).
Install it with composer require tomise/laravel-barion.
Discover more Laravel packages by tomise
or browse all Laravel packages to compare alternatives.
Last updated
Tomise/Laravel-Barion is provides an easy way to use the Barion API with Laravel applications.Support Barion Smart Gateway operation and Barion Wallet operations.
composer require tomise/laravel-barion
app.php config fileTomise\Barion\Providers\BarionServiceProvider::class,
php artisan vendor:publish --provider="Tomise\Barion\Providers\BarionServiceProvider" --tag="config"
Package has a pre-configuration, but you set some data your .env file: Configuration details in config/barion-gateway.php
#required:
BARION_POST_KEY=<your pos key>
BARION_REDIRECT_URL=<your default redirect url>
BARION_CALLBACK_URL=<your default callback url>
#optional:
# only need for wallet operations
BARION_API_KEY=<your wallet api key>
BARION_PAYEE=<payee email>
#others:
BARION_ENVIRONMENT=<default test>
BARION_GUEST_CHECKOUT=<default true>
BARION_PAYMENT_TYPE=<default Immediate>
BARION_PAYMENT_WINDOW=<default 00:30:00>
If your BARION_ENVIRONMENT variable value is "test" every request send to sandbox server.
The $barion_casts property should be a key-value pair based array, the keys are given and the values are the fields of the model you want to pass to the Barion.
If you want to use Barion with your models only needs some simple step:
Add public $barion_casts = [] you Order or Cart or any class that extends from Model.
Example
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
...other properties
public $barion_casts = [
'payment_request_id' => 'id',
'payer_hint' => 'email',
'order_number' => 'reservation_number',
'phone_number' => 'phone_number',
'total' => 'total_price',
];
...other methods
}
public $barion_casts = [] you OrderItem or CartItem or any class that also extends from Model.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OrderItem extends Model
{
...other properties
public $barion_casts = [
"name" => "name",
"description" => "description",
"quantity" => "quantity",
"unit" => "unit",
"unit_price" => "unit_price",
"item_total" => "item_total",
];
...other methods
}
If you want to use this version, but you are missing one or more properties of a model, just attach it before passing it to the startPayment method or you can create a custom model directly for Barion e.g.: BarionOrderModel
<?php
use Tomise\Barion\Support\BarionGateway;
...
// Get payment gateway.
$gateway = BarionGateway::createPaymentGateway();
// Build barion payment data from your models
$preparedPayment = $gateway->startPayment($order, $items);
// Send data to Barion
$response = $preparedPayment->sendSinglePayment();
// Redirect user to the Barion Gateway
return redirect($response->getGatewayUrl());
startPayment method only assign minimal data to Payment/Start endpoint. But if you want to add some extra data just set before you call the sendSinglePayment.
Example
// Get payment gateway.
$gateway = BarionGateway::createPaymentGateway();
// Build barion payment data from your models
$preparedPayment = $gateway->startPayment($order, $items);
$paymentDto = $preparedPayment->getPaymentDto();
// Add billing address before send the request.
$paymentDto->setBillingAddress($address);
// Send data to Barion
$response = $preparedPayment->sendSinglePayment();
If you want to use the "model option" but are missing the locale or the currency from your "order" model, you can simply overwrite the default values.
Important: Changing the currency does not automatically convert the values, please note this!
...
$preparedPayment = $gateway->startPayment($order, $items);
$paymentDto = $preparedPayment->getPaymentDto();
// Modify the default currency and locale
$paymentDto->setCurrency(Currency::Huf);
$paymentDto->setLocale(Locale::Hu);
$response = $preparedPayment->sendSinglePayment();
In this case you will get an empty "PreparedPaymentService" object where you can set everything. The POSKey is automatically attached to the object.
<?php
use Tomise\Barion\Support\BarionGateway;
use Tomise\Barion\DataTransferObjects\Currency;
use Tomise\Barion\DataTransferObjects\Locale;
...
// Get payment gateway.
$gateway = BarionGateway::createPaymentGateway();
$preparedPayment = $gateway->startPaymentManual();
$paymentDto = $preparedPayment->getPaymentDto();
$paymentDto->setTransactions($transactions);
$paymentDto->setCurrency(Currency::Huf);
$paymentDto->setLocale(Locale::Hu);
...
$response = $preparedPayment->sendSinglePayment();
// Get payment gateway.
$gateway = BarionGateway::createPaymentGateway();
$preparedPayment = $gateway->startPaymentManual();
$response = $preparedPayment->sendPaymentState($paymentId);
// Get payment gateway.
$gateway = BarionGateway::createPaymentGateway();
$preparedPayment = $gateway->startPaymentManual();
// Set required parameter
$preparedPayment->setPaymentId($paymentId);
$response = $preparedPayment->sendCancelAuthorization($paymentId);
Available gateway endpoints:
Available Locales: https://docs.barion.com/Localisation
Available Currencies:https://docs.barion.com/Supported_currencies
Laravel-Barion is open source software licensed under the MIT License.