plisio/plisio-api-php

1.0.2 2020-08-18 12:48 UTC

This package is auto-updated.

Last update: 2024-09-23 16:36:16 UTC


README

# 这是用于Plisio Api支持的PHP SDK项目

这是一个完全面向对象的PHP composer包,用于与Plisio的加密货币支付网关协同工作。

interface InteractionInterface
{
    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return null on errors (If silent mode turn on)
     * @return BalanceApiResponse on success
     */
    public function getBalance(string $currency): ?BalanceApiResponse;

    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return null on errors (If silent mode turn on)
     * @return OperationApiResponse on success
     */
    public function getOperationById(string $id): ?OperationApiResponse;

    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return null on errors (If silent mode turn on)
     * @return CommissionApiResponse on success
     */
    public function getCommission(CommissionQuery $query): ?CommissionApiResponse;

    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return null on errors (If silent mode turn on)
     * @return CryptocurrencyApiResponse on success
     */
    public function getCurrencyInfoByFiat(string $fiat): ?CryptocurrencyApiResponse;

    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return null on errors (If silent mode turn on)
     * @return FeePlanApiResponse on success
     */
    public function getFeePlanByPsyscid(string $psyscid): ?FeePlanApiResponse;

    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return null on errors (If silent mode turn on)
     * @return WithdrawApiResponse on success
     */
    public function withdraw(WithdrawQuery $withdrawQuery): ?WithdrawApiResponse;

    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return null on errors (If silent mode turn on)
     * @return InvoiceWhiteLabelResponse on success
     */
    public function createInvoice(InvoiceQuery $invoiceQuery): ?InvoiceWhiteLabelResponse;

    /**
     * @throws Throwable on errors (If silent mode turn off)
     * @return FeeApiResponse on success
     * @return null on errors (If silent mode turn on)
     */
    public function getFee(FeeQuery $feeQuery): ?FeeApiResponse;
}

InteractionInterface 方法描述

  1. getBalance(string $currency)

    让我们看看自己的加密货币 余额,例如比特币(BTC)。也支持9种 加密货币

    $balance = $this->interaction->getBalance(Currencies::BTC);

  2. getOperationById(string $id)

    通过交易标识符返回关于具体交易的信息,示例

    $operation = $this->interaction->getOperationById('61e9384388ecfd3ea775dfb2');

  3. getCommission(CommissionQuery $query)

    估计加密货币费用和Plisio佣金,接受CommissionQuery类,示例

    $commission = $this->interaction->getCommission(new CommissionQuery(Currencies::BTC));

    此外,佣金查询类还有可空的参数

     private ?string $addresses = null;
     private ?string $amounts = null;
     private ?string $type = null;
     private ?string $feePlan = null;
    • $addresses - 钱包地址或逗号分隔的地址,用于估算大量提款费用
    • $amounts - 金额或逗号分隔的金额,在大量提款的情况下将被发送
    • $type - 操作类型,例如:'cash_out' 或 'mass_cash_out'
    • $feePlan - 费用计划 的名称
  4. getCurrencyInfoByFiat(string $fiat)

    提供当前支持的加密货币与 特定法定货币 的汇率,需要通过选择法定货币的方法向API发送请求。

    让我们获取澳元(AUD)的汇率,例如。顺便说一下,如果没有选择任何法定货币,则默认为美元(USD)的汇率。 响应 是一个包含汇率模型的列表

    $info = $this->interaction->getCurrencyInfoByFiat(FiatCurrencies::AUD);

  5. getFeePlanByPsyscid(string $psyscid)

    通过选择的 加密货币 返回包含 费用计划 的模型。此外,此模型还有额外字段指明了您的费用计划。

    示例

    $feePlan = $this->interaction->getFeePlanByPsyscid(Currencies::BTC);

  6. withdraw(WithdrawQuery $withdrawQuery) 如果您想提款,应调用接受WithdrawQueryClass的withdraw方法

     private string $psyscid;
     private string $to;
     private string $amount;
     private int $feeRate;
     private string $feePlan;
    
     private ?string $type = null;
    • $psyscid — 加密货币的名称;
    • $to — 单个地址或用于 mass_cash_out 的多个逗号分隔的地址;
    • $amount — 在 mass_cash_out 中的任何逗号分隔的浮点值,顺序与 to 参数中的地址顺序相同;
    • $feePlan费用计划 的名称;
    • $feeRate — 自定义费用率。对于BTC等加密货币,如conf_target(区块)或基于ETH的加密货币的gasPrice;
    • $type — 操作类型(这是一个可选参数)。

    示例

    $withdraw = $this->interaction->withdraw(
            new WithdrawQuery(
                Currencies::BTC,
                '2N3cD7vQxBqmHFVFrgK2o7HonHnVoFxxDVB',
                '0.00031',
                FeePlans::NORMAL,
                1
            )
        );
  7. createInvoice(InvoiceQuery $invoiceQuery)

    让我们来看看创建发票,首先您需要构建InvoiceQuery类

    private string $currency;
    private string $orderName;
    private string $orderNumber;
    
    private ?string $amount = null;
    private ?string $sourceCurrency = null;
    private ?string $sourceAmount = null;
    private ?string $allowedPsyscids = null;
    private ?string $description = null;
    private ?string $callBackUrl = null;
    private ?string $email = null;
    private ?string $language = null;
    private ?string $plugin = null;
    private ?string $version = null;
    private ?bool $redirectToInvoice = null;
    private ?string $expireMin = null;

    查询需要接收以下 必需 参数

    • $currency — 加密货币的名称;
    • $orderName — 商户内部订单名称;
    • $orderNumber — 商户内部订单编号。

    除了这些参数外,还有一些 附加 参数,如

    • $amount — 任何加密货币浮点值。如果您想将法定货币转换为加密货币,应跳过当前字段并使用以下两个字段代替它;
    • $sourceCurrency — 法定货币名称;
    • $sourceAmount — 任意浮点值;
    • $allowedPsyscids — 允许支付的加密货币列表,以逗号分隔。您还可以从中选择一个。例如:'BTC,ETH,TZEC'
    • $description — 商家发票描述;
    • $callbackUrl — 获取发票更新的商家完整URL。将向此URL发送POST请求。如果此参数未设置,则将回调发送到API设置中可以设置的URL,该URL具有'状态URL'字段;
    • $email — 自动填充发票电子邮件。您将被要求插入发送通知的电子邮件地址;
    • $language — en_US(目前仅支持英语);
    • $plugin — Plisio的内部字段,用于确定集成插件;
    • $version — Plisio的内部字段,用于确定集成插件版本。

    示例

    $invoice = $this->interaction->createInvoice(
            (new InvoiceQuery(Currencies::BTC, 'some order', '234sdfsd'))
                ->setAmount('0.01')
        );
  8. getFee(FeeQuery $feeQuery)

    要估算费用,您应创建带有参数的FeeQuery类

    private string $psyscid;
    private string $addresses;
    private string $amounts;
    
    private ?string $feePlan = null;
    • $psyscid — 加密货币的名称;
    • $addresses — 钱包地址或估算大量提款费用时逗号分隔的地址;
    • $amounts — 金额或逗号分隔的金额,在大量提款的情况下将发送;
    • $feePlan — 一个费用计划的名称(不是必需的)。

    示例

    $fee = $this->interaction->getFee(
            new FeeQuery(
                Currencies::BTC,
                'tb1qfqtvgh97umdum8zwyah4ztzkwz8j7qyyalgwa4',
                '0.0003'
            )
        );

php的sdk入口点表示为单例类 PlisioPhpSdk,示例

$container = \PlisioPhpSdk\PlisioPhpSdk::get();
/** @var \PlisioPhpSdk\Http\InteractionInterface $interaction */
$interaction = $container->get(\PlisioPhpSdk\Http\InteractionInterface::class);

此外,此sdk提供了合适的配置可能性,您可以创建如下的 conf.yaml 文件

plisio-php-sdk:
  common:
    dev:
      api-key:
      base-uri:
      user: 
      password: 
    prod:
      api-key:
      base-uri:
  current-env: dev
  silent: false

要配置sdk,您需要在您的项目根目录中创建conf.yaml文件,并从供应商目录启动控制台命令

php cli/console.php plisio-php-sdk:load-conf "conf.yaml文件路径"

Sdk有两种默认的工作模式(此功能仅涉及与api的交互

  • 静默模式(不抛出异常,在某些情况下返回null),所有异常都写入.log文件
  • 非静默模式(抛出异常),同时所有异常都进行记录

sdk记录在plisio-php-sdk.log日志文件中,为了方便,您可以从根目录创建到此文件的符号链接。在演示中,所有sdk的功能(与测试资源的工作)都通过控制台命令进行复制

plisio-php-sdk:load-conf

plisio-php-sdk:test-balance

plisio-php-sdk:test-commission

plisio-php-sdk:test-create-invoice

plisio-php-sdk:test-currency-info

plisio-php-sdk:test-fee

plisio-php-sdk:test-fee-plan

plisio-php-sdk:test-operation

plisio-php-sdk:test-withdraw