PHP code example of telepaycash / sdk-telepay-php

1. Go to this page and download the library: Download telepaycash/sdk-telepay-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

telepaycash / sdk-telepay-php example snippets




use TelePay\TelePayClient;
use TelePay\TelePayEnvironment;

$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
                )

        )

)

$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
)

$webhooksResponse = $telepay->getWebhooks();

$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
)

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

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

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

$webhookId = 325;

$telepay->activateWebhook($webhookId);

$telepay->deactivateWebhook($webhookId);

$webhookId = 325;

$telepay->deleteWebhook($webhookId);
bash
composer