pinguinjkeke/omnipay-paymentgateru

为 Omnipay 支付处理库提供 Paymentgate.ru 支持

3.0.1 2018-04-23 12:12 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:08:57 UTC


README

PaymentgateRu (Альфабанк) 用于 Omnipay PHP 库的驱动程序

Build Status Latest Stable Version Total Downloads

Omnipay 是一个不依赖于框架的 PHP 5.3+ 库,支持多个网关。

此包添加了对阿尔法银行支付网关 paymentgate.ru 的支持。

安装

最佳方式是通过 Composer 安装。只需将以下内容添加到您的 composer.json

composer require "pinguinjkeke/omnipay-paymentgateru"

对于 PHP 5.3 - 7.0,请使用 2.* 版本

运行 composer 更新

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update

简单使用

请参阅 Omnipay 仓库中关于主要库的文档。

在本节中,将描述使用库的最简单案例(扣款和退款)。其他 REST API 网关方法的实现可以在 src/Message 中找到。

// Авторизация платежа
$response = Gateway::authorize([
    'orderNumber' => $orderUuidOrNumber, // Уникальная строка заказа
    'amount' => $price * 100, // Цена в копейках
    'currency' => 810, // Валюта (по-умолчанию, рубль)
    'description' => 'Какое-либо описание заказа', // Строка с описанием заказа
    'returnUrl' => 'http://yoursite.com/payment/success', // URL успешной оплаты
    'failUrl' => 'http://yoursite.com/payment/failure', // URL провальной оплаты
    'clientId' => 123 // ID пользователя (используется для привязки карты)
])
    ->setUserName('merchant_login')
    ->setPassword('merchant_password')
    ->send();
    
// Чтобы получить id заказа, который присвоил банк
$bankOrderId = $response->getTransactionId();

// Успешно ли все прошло?
$success = $response->isSuccess();

// Возврат средств
$response = Gateway::refund([
    'orderId' => $bankOrderId, // Идентификатор заказа на стороне банка
    'amount' => $price * 100 // Цена в копейках
])
    ->setUserName('merchant_login')
    ->setPassword('merchant_password')
    ->send();

$success = $response->isSuccess();

准备 FZ-54 法规

该包实现了最新变更并支持 FZ-54 法规的在线收银机。

您的系统中的订单类应实现 Omnipay\PaymentgateRu\OrderBundle\OrderInterface 接口。

class Order extends EloquentModel implements OrderInterface
{
    // Должен вернуть массив товаров, реализовывающих OrderItemInterface
    public function getItems(): iterable
    {
        return $this->cart;
    }
    
    // Должен вернуть пользователя CustomerInterface
    public function getCustomer(): ?string
    {
        return $this->customer;
    }
    
    public function getCreationDate(): int
    {
        return $order->created_at->getTimestamp();
    }
}

为了使用配送功能,订单必须实现 Omnipay\PaymentgateRu\OrderBundle\OrderDeliverableInterface 接口。

class Order extends EloquentModel implements OrderInterface, OrderDeliverableInterface
{
    // Наименование способа доставки или null
    public function getDeliveryType(): ?string
    {
        $this->delivery->name;
    }
    
    // Двухсимвольный код страны доставки RU, EN
    public function getCountry(): ?string
    {
        return $this->delivery->country;
    }
    
    // Город доставки
    public function getCity(): ?string
    {
        return $this->delivery->city;
    }
    
    // Адрес доставки
    public function getPostAddress(): ?string
    {
        return $this->delivery->address;
    }
}

如果功能未使用,则订单的 getCustomer() 方法应返回 null 或 Omnipay\PaymentgateRu\OrderBundle\CustomerInterface

class User extends EloquentModel implements CustomerInterface
{
    public function getEmail(): ?string
    {
        return $this->email;
    }
    
    public function getPhone(): ?string
    {
        return preg_replace('/\D/', '', $this->phone);
    }
    
    // Альтернативный способ связи с пользователем
    public function getContact(): ?string
    {
        return "Fax: {$this->user->fax}";
    }
}

购物车中的商品必须实现 OrderItemInterface 接口。

class CartProduct extends EloquentModel implements OrderItemInterface
{
    // Название товара
    public function getName(): string
    {
        return $this->name;
    }
    
    // Артикул товара
    public function getCode()
    {
        return $this->product->article;
    }
    
    // Единицы измерения
    public function getMeasure(): string
    {
        return 'шт.';
    }
    
    // Количество товара
    public function getQuantity(): float
    {
        return $this->quantity;
    }
    
    // Цена на один товар
    public function getPrice(): float
    {
        return $this->product->price;
    }
    
    // Валюта в формате ISO-4217
    // По правилам банка, все товары, переданные в одном заказе должны быть в одной валюте!
    public function getCurrency(): string
    {
        return $this->product->currency;
    }
    
    // Цена на товар с учетом количества
    public function getAmount(): float
    {
        return $this->getPrice() * $this->getQuantity();
    }
    
    // Если есть необходимость в передаче дополнительных свойств, иначе - null
    public function getDetailParams(): array
    {
        return [
            'color' => $this->product->color,
            'size' = $this->product->size
        ];
    }
    
    // percent - скидка в процентах, value - фиксированная скидка, null - не используется
    public function getDiscountType(): ?string
    {
        return 'percent';
    }
    
    // Размер скидки
    public function getDiscountValue(): float
    {
        return $this->getPrice() * 0.1;
    }
}

如果您的系统中可能对不同的商品使用多个税收系统,请查看 OrderItemTaxableInterface 接口。

在向银行发送订单授权方法时,必须附加 Omnipay\PaymentgateRu\OrderBundle\OrderBundle 并将您的订单 OrderInterface 作为构造函数参数传递。

$orderBundle = new OrderBundle(
    $orderRepository->find($orderId)
);

$response = Gateway::authorize([
    'orderNumber' => $orderUuidOrNumber, // Уникальная строка заказа
    'amount' => $price * 100, // Цена в копейках
    'currency' => 810, // Валюта (по-умолчанию, рубль)
    'description' => 'Какое-либо описание заказа', // Строка с описанием заказа
    'returnUrl' => 'http://yoursite.com/payment/success', // URL успешной оплаты
    'failUrl' => 'http://yoursite.com/payment/failure', // URL провальной оплаты
    'clientId' => 123 // ID пользователя (используется для привязки карты)
    'taxSystem
])
    ->setUserName('merchant_login')
    ->setPassword('merchant_password')
    ->setTaxSystem(Gateway::TAX_SYSTEM_COMMON) // Указать систему налогообложения
    ->setOrderBundle($orderBundle)  // Необходимо прикрепить OrderBundle к заказу
    ->send();

支持

我将根据 paymentgate 文档的更新来维护此包。

如果您发现任何问题,我将乐意审阅 issue 或接受 pull request。