inwebuz/uzumbank-merchant

与 Laravel 的 Uzumbank Merchant 集成

v1.0.0 2024-09-20 07:10 UTC

This package is auto-updated.

Last update: 2024-09-20 07:10:54 UTC


README

此包是用于 Uzumbank Merchant 的 Laravel 扩展包。

安装

您可以通过 composer 安装此包

composer require inwebuz/uzumbank-merchant

使用

发布配置和迁移

php artisan vendor:publish --tag=uzumbankmerchant
php artisan migrate

添加配置

为 Uzumbank Merchant 创建登录名和密码,并在 .env 文件中添加 service_id

UZUMBANK_MERCHANT_LOGIN="your_login"
UZUMBANK_MERCHANT_PASSWORD="your_password"
UZUMBANK_MERCHANT_SERVICE_ID="uzumbank_service_id"

在 uzumbankmerchant.php 配置文件中写入您的应付模型

例如

'payable_models' => [
    'order' => 'App\\Models\\Order',
],

"order" 是deeplink的参数名

添加模型

创建一个实现 Inwebuz\UzumbankMerchant\Interfaces\UzumbankPayableInterface 接口的应付模型。

<?php

namespace Inwebuz\UzumbankMerchant\Interfaces;

use Inwebuz\UzumbankMerchant\Models\UzumbankTransaction;

interface UzumbankPayableInterface
{
    /**
     * Check if payable is already paid.
     *
     * @return bool Returns true if payable is already paid.
     */
    public function uzumbankIsPaid(): bool;

    /**
     * Check if payable is cancelled.
     *
     * @return bool Returns true if payable is cancelled.
     */
    public function uzumbankIsCancelled(): bool;

    /**
     * Retruns info about payable and transaction
     *
     * @return array An array of key object pairs, each object contains "value" key and value of that key.
     * 
     * Example:
     * [
     *    'type' => [
     *        'value' => 'Order,
     *    ],
     *    'id' => [
     *        'value' => 1,
     *    ],
     * ]
     */
    public function uzumbankPaymentData(): array;

    /**
     * Returns payable amount in UZS tiyins.
     *
     * @return float Returns amount of payable in uzs tiyins or return 0 to allow any amount.
     */
    public function uzumbankAmount(): float;

    /**
     * Called after transaction is successfully confirmes.
     *
     * You have to set your payable status to "paid".
     * 
     * @param UzumbankTransaction $uzumbankTransaction
     * @return void.
     */
    public function uzumbankSetPaid(UzumbankTransaction $uzumbankTransaction): void;

    /**
     * Check if payable can be reversed (cancelled);
     *
     * @param UzumbankTransaction $uzumbankTransaction
     * @return bool Returns true if payable can be reversed.
     */
    public function uzumbankCanBeReversed(UzumbankTransaction $uzumbankTransaction): bool;

    /**
     * Called after transaction is successfully reversed.
     *
     * You have to set your payable status to "reversed".
     * 
     * @param UzumbankTransaction $uzumbankTransaction
     * @return void.
     */
    public function uzumbankReverse(UzumbankTransaction $uzumbankTransaction): void;
}

生成到 Uzumbank 的deeplink

例如

https://uzumbank.uz/uzumbank/merchant/deeplink?type=order&id=1

type - uzumbankmerchant 配置中 payable_models 键的应付模型类型

id - 应付模型id