telepaycash/sdk-telepay-php

此包已被放弃且不再维护。未建议替代包。

用于接收TelePay支付的库

v1.2.0 2023-02-05 13:55 UTC

This package is not auto-updated.

Last update: 2023-04-30 15:11:39 UTC


README

TelePay PHP

PHP语言的TelePay客户端库,让您可以轻松处理使用REST API的加密货币支付。

License: MIT CI Last commit GitHub commit activity Github Stars Github Forks Github Watchers GitHub contributors Telegram Blog

安装

使用Composer安装包

composer require telepaycash/sdk-telepay-php

使用库

使用Composer自动加载导入库类

require 'vendor/autoload.php';

use TelePay\TelePayClient;
use TelePay\TelePayEnvironment;

使用您的商家密钥配置TelePay客户端

$clientSecret = "YOUR API SECRET KEY";

$environment = new TelePayEnvironment($clientSecret);

$telepay = new TelePayClient($environment);

获取当前商家

$me = $telepay->getMe();
print_r($me);

响应

Array
(
    [version] => 1.0
    [merchant] => Array
        (
            [name] => MyMerchant
            [url] => https://mymerchant.com/
            [logo_url] => https://ik.imagekit.io/telepay/merchants/descarga_-k4ehiTd5.jpeg
            [logo_thumbnail_url] => https://ik.imagekit.io/telepay/tr:n-media_library_thumbnail/merchants/descarga_-k4ehiTd5.jpeg
            [verified] => 
            [username] => merchant_username
            [public_profile] => https://telepay.cash/to/merchant_username
            [owner] => Array
                (
                    [first_name] => Raubel
                    [last_name] => Guerra
                    [username] => raubel1993
                )

            [created_at] => 2022-04-13T00:51:37.802614Z
            [updated_at] => 
        )
)

阅读文档

获取所有商家钱包的余额

$balances = $telepay->getAllBalances();
print_r($balances);

响应

Array
(
    [wallets] => Array
        (
            [0] => Array
                (
                    [asset] => TON
                    [blockchain] => TON
                    [balance] => 10.005
                    [network] => mainnet
                )

            [1] => Array
                (
                    [asset] => TON
                    [blockchain] => TON
                    [balance] => 0
                    [network] => testnet
                )

        )

)

阅读文档

获取某个商家钱包的余额

$asset = new TelePayAssetInput("TON", "TON", "mainnet");
$balance = $telepay->getBalance($asset);
print_r($balance);

响应

Array
(
    [wallets] => Array
        (
            [0] => Array
                (
                    [asset] => TON
                    [blockchain] => TON
                    [balance] => 0
                    [network] => mainnet
                )

        )

)

阅读文档

获取资产

获取TelePay支持的资产。 阅读文档

$assets = $telepay->getAssets();
print_r($assers);

响应

Array
(
    [assets] => Array
        (
            [0] => Array
                (
                    [asset] => TON
                    [blockchain] => TON
                    [usd_price] => 1.050999999999999934
                    [url] => https://ton.org
                    [networks] => Array
                        (
                            [0] => mainnet
                            [1] => testnet
                        )

                    [coingecko_id] => the-open-network
                )

        )

)

您可以获取单个资产的详细信息。 阅读文档

$asset = new TelePayAssetInput("TON", "TON", "mainnet");
$assetDetail = $telepay->getAsset($asset);

创建一个发票

$orderId = 56;
$invoice = new TelePayInvoiceInput("TON", "TON", "testnet", "0.2");
$invoice->setDescription("Test using SDK TelePay PHP");
$invoice->setMetadata([
    "my_reference_id" => $orderId,
    "other_metadata" => "any value"
]);
$invoice->setSuccessUrl("https://www.example.com/payment_success?order_id=$orderId");
$invoice->setCancelUrl("https://www.example.com/payment_cancelled?order_id=$orderId");

$respCreateInvoice = $telepay->createInvoice($invoice);
print_r($respCreateInvoice);

响应

Array
(
    [number] => YJ1EJO9PLA
    [asset] => TON
    [blockchain] => TON
    [network] => mainnet
    [status] => pending
    [amount] => 2.000000000000000000
    [amount_remaining] => 0.000000000000000000
    [amount_real] => 0.000000000000000000
    [description] => Test using SDK TelePay PHP
    [metadata] => Array
        (
            [my_reference_id] => 56
            [other_metadata] => any value
        )

    [checkout_url] => https://telepay.cash/checkout/YJ1EJO9PLA
    [onchain_url] => ton://transfer/UQDoFjaqMtuxkJV-caGiEdxMxjkTAWU9oskjpfAA1uwHbe4u?amount=2000000000
    [success_url] => https://www.example.com/payment_success?order_id=56
    [cancel_url] => https://www.example.com/payment_cancelled?order_id=56
    [explorer_url] => 
    [expires_at] => 2022-06-28T00:09:52.038782Z
    [created_at] => 2022-06-27T14:09:52.038908Z
    [updated_at] => 
)

阅读文档

查看发票

查找许多发票。 阅读文档

$invoicesResponse = $telepay->getInvoices();

通过编号查找一个发票。 阅读文档

$invoiceNumber = "UIOAXSSFNB";
$respGetInvoice = $telepay->getInvoice($invoiceNumber);

取消发票

$invoiceNumber = "8N1DLRKV5S";
$respCancelInvoice = $telepay->cancelInvoice($invoiceNumber);
print_r($respCancelInvoice);

响应

Array
(
    [number] => YJ1EJO9PLA
    [asset] => TON
    [blockchain] => TON
    [network] => mainnet
    [status] => cancelled
    [amount] => 2.000000000000000000
    [amount_remaining] => 0.000000000000000000
    [amount_real] => 0.000000000000000000
    [description] => Test using SDK TelePay PHP
    [metadata] => Array
        (
            [other_metadata] => any value
            [my_reference_id] => 56
        )
    [checkout_url] => https://telepay.cash/checkout/YJ1EJO9PLA
    [onchain_url] => 
    [success_url] => https://www.example.com/payment_success?order_id=56
    [cancel_url] => https://www.example.com/payment_cancelled?order_id=56
    [explorer_url] => 
    [expires_at] => 2022-06-28T00:09:52.038782Z
    [created_at] => 2022-06-27T14:09:52.038908Z
    [updated_at] => 2022-06-27T14:09:53.205920Z
)

删除发票

$invoiceNumber = "8N1DLRKV5S";
$respDeleteInvoice = $telepay->deleteInvoice($invoiceNumber);
print_r($respDeleteInvoice);

响应

Array
(
    [success] => invoice.deleted
    [message] => Invoice deleted.
)

转账

$transfer = new TelePayTransferInput("TON", "TON", "mainnet", "0.00005", "raubel1993");
$transfer->setMessage("Debt settled");

$respTransfer= $telepay->transfer($transfer);
print_r($respTransfer);

响应

Array
(
    [success] => transfer.ok
    [message] => Transfer performed.
)

阅读文档

提取费用

$withdraw = new TelePayWithdrawInput("TON", "TON", "mainnet", "0.2", "EQCwLtwjII1yBfO3m6T9I7__6CUXj60ZFmN3Ww2aiLQLicsO");
$withdraw->setMessage("for my savings account");

$respWithdrawFee = $telepay->getWithdrawFee($withdraw);
print_r($respWithdrawFee);

响应

Array
(
    [blockchain_fee] => 0.001824
    [processing_fee] => 0.01
    [total] => 0.011824
)

提取

$withdraw = new TelePayWithdrawInput("TON", "TON", "mainnet", "0.2", "EQCwLtwjII1yBfO3m6T9I7__6CUXj60ZFmN3Ww2aiLQLicsO");
$withdraw->setMessage("for my savings account");

$respWithdraw = $telepay->withdraw($withdraw);
print_r($respWithdraw);

响应

Array
(
    [success] => 1
)

查看webhooks

查找许多webhooks。 阅读文档

$webhooksResponse = $telepay->getWebhooks();

通过Id查找一个webhook。 阅读文档

$webhookId = 325;
$webhookResponse = $telepay->getWebhook($webhookId);
print_r($webhookResponse);

响应

Array
(
    [id] => 325
    [url] => https://www.example.com/webhook
    [secret] => secret
    [events] => Array
        (
            [0] => invoice.completed
        )

    [active] => 1
)

创建或更新一个webhook

为了创建一个webhook,需要提供url、密钥和关联的事件。 阅读文档

$urlWebhook = "https://www.example.com/webhook";
$secretWebhook = "secret";
$eventsWebhook = [
    TelePayEvents::INVOICE_COMPLETED
];
$webhookInput = new TelePayWebhookInput($urlWebhook, $secretWebhook, $eventsWebhook);

$responseCreateWebhook = $telepay->createWebhook($webhookInput);

为了更新一个webhook,需要提供webhookId和新的参数。 阅读文档

$webhookId = 325;
$responseUpdateWebhook = $telepay->updateWebhook($webhookId, $webhookInput);

激活或停用webhook

$webhookId = 325;

$telepay->activateWebhook($webhookId);

$telepay->deactivateWebhook($webhookId);

删除webhook

$webhookId = 325;

$telepay->deleteWebhook($webhookId);

测试

所有端点响应都已测试。要自行运行测试,您需要您的TelePay商家密钥以及至少3个testnet toncoins、一个将接收测试转账的Telepay用户,以及一个将接收测试提取的testnet钱包。

TELEPAY_SECRET_API_KEY= USERNAME_TELEPAY_TRANSFER= WHITDRAW_TO_WALLET= composer tests

贡献者 ✨

该库由 (emoji key)


Raubel Guerra

💻

Carlos Lugones

🧑‍🏫

本项目遵循 all-contributors 规范。欢迎所有类型的贡献!