tomise/laravel-barion
Composer 安装命令:
composer require tomise/laravel-barion
包简介
A simple Laravel package for Barion payment gateway
README 文档
README
Connect your webshop to the Barion Smart Gateway in just 5 minutes.
Development currently in progress!
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.
Installation
- Install the package using composer:
composer require tomise/laravel-barion
- Register the service provider in the
app.phpconfig file
Tomise\Barion\Providers\BarionServiceProvider::class,
- Publish config file (optional)
php artisan vendor:publish --provider="Tomise\Barion\Providers\BarionServiceProvider" --tag="config"
Configuration
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.
Documentation for Smart Gateway
There are 2 ways to use the BarionGateway (model options only available for payment start operation).
Usage with models
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.- Required keys: payment_request_id, payer_hint, order_number, phone_number, total
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 }
- Add
public $barion_casts = []you OrderItem or CartItem or any class that also extends from Model.- Required keys: name, description, quantity, unit, unit_price, item_total
<?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
Start single payment
<?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();
Different Locale and Currency
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();
Simple manual usage
Payment Start
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 Status
// Get payment gateway. $gateway = BarionGateway::createPaymentGateway(); $preparedPayment = $gateway->startPaymentManual(); $response = $preparedPayment->sendPaymentState($paymentId);
Cancel Authorization
// Get payment gateway. $gateway = BarionGateway::createPaymentGateway(); $preparedPayment = $gateway->startPaymentManual(); // Set required parameter $preparedPayment->setPaymentId($paymentId); $response = $preparedPayment->sendCancelAuthorization($paymentId);
Information
Available gateway endpoints:
- sendSinglePayment() -> Payment/Start
- sendPaymentState() -> Payment/:paymentId/paymentstate
- sendCompletePayment() -> Payment/Complete
- sendFinishReservation() -> Payment/FinishReservation
- sendCapture() -> Payment/Capture
- sendCancelAuthorization() -> Payment/CancelAuthorization
- sendRefund() -> Payment/Refund
Available Locales: https://docs.barion.com/Localisation
Available Currencies:https://docs.barion.com/Supported_currencies
Documentation for Barion Wallet
Examples
License
Laravel-Barion is open source software licensed under the MIT License.
tomise/laravel-barion 适用场景与选型建议
tomise/laravel-barion 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tomise/laravel-barion 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomise/laravel-barion 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-01