paywithterra/php-backend-library

用于公共界面上交易验证的PHP库

1.0.1 2022-09-15 18:20 UTC

This package is auto-updated.

Last update: 2024-09-15 23:07:36 UTC


README

用于验证Terra区块链上支付交易的PHP库。

先决条件

PHP版本 5.6, 7.0, 7.1, 7.2, 7.3, 或 7.4
PHP扩展:ext-json, ext-curl

安装

您可以使用Composer。如果您还没有安装Composer,请遵循安装说明

composer require paywithterra/php-backend-library

在您的PHP脚本中,确保您已包含Composer的自动加载器

require __DIR__ . '/vendor/autoload.php';

或者,如果您不使用Composer,您可以下载GitHub上的发布版本并直接使用库

require __DIR__ . '/src/autoload-legacy.php';

使用库

请求和验证交易

// Prepare client (see all options below)
$client = new \PaywithTerra\TerraTxValidator([
    "merchantAddress" => "terra12abcdefg1234512345123451234512345abc",
    "chainId" => "pisco-1",
    "LCD" => "https://pisco-lcd.terra.dev/cosmos/tx/v1beta1/txs/{txHash}",
]);

// Request transaction information from public facade (by txHash)
$client->lookupTx("TynpStpmcovsgsNpqlchimy9cydlc83bwudgrBigShTksrzczfvxnf9q4kkvcek4");

// Check if transaction comply with our requirements (throw exception if not)
$client->assertTx([
    "memo" => '#order-1234',
    "denom" => "uluna",
    "amount" => "280000",
]);

客户端选项(初始化变体)

变体1:使用精确的LCD和chainId

$client = new \PaywithTerra\TerraTxValidator([
    "merchantAddress" => "terra12abcdefg1234512345123451234512345abc",
    "chainId" => "pisco-1",
    "LCD" => "https://pisco-lcd.terra.dev/cosmos/tx/v1beta1/txs/{txHash}",
]);

变体2:使用精确的FCD和chainId

$client = new \PaywithTerra\TerraTxValidator([
    "merchantAddress" => "terra12abcdefg1234512345123451234512345abc",
    "chainId" => "pisco-1",
    "FCD" => "https://pisco-fcd.terra.dev/v1/tx/{txHash}",
]);

变体3:使用网络名称(请求链信息+从Terra网络获取LCD URL并缓存它)

$client = new \PaywithTerra\TerraTxValidator([
    "merchantAddress" => "terra12abcdefg1234512345123451234512345abc",
    "networkName" => "testnet", // or "mainnet" or "classic"
    "cache" => new \PaywithTerra\Cache\FileCache(),
]);

支持资产(代币)

备注

我们不使用任何现代库(如Guzzle或Symphony HTTP客户端)作为传输,因为我们希望尽可能降低最低支持的PHP版本。
这种方法甚至允许老式和遗留的PHP项目连接到Terra。如果您确实想使用HTTP客户端作为传输,请提交一个问题。

许可证

MIT许可证(MIT)