PHP code example of tomise / laravel-barion

1. Go to this page and download the library: Download tomise/laravel-barion library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomise / laravel-barion example snippets


Tomise\Barion\Providers\BarionServiceProvider::class,

php artisan vendor:publish --provider="Tomise\Barion\Providers\BarionServiceProvider" --tag="config"

#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>



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
}



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
}



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());

// 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();

...
$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();



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