tomise/laravel-barion 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. Install the package using composer:

composer require tomise/laravel-barion

  1. Register the service provider in the app.php config file
Tomise\Barion\Providers\BarionServiceProvider::class,
  1. 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:

  1. Add public $barion_casts = [] you Order or Cart or any class that extends from Model.

    1. 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
}
  1. Add public $barion_casts = [] you OrderItem or CartItem or any class that also extends from Model.
    1. 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

Barion Wallet documentation

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 tomise/laravel-barion 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-01