telepaycash/sdk-telepay-php

This package is abandoned and no longer maintained. No replacement package was suggested.

Library to receive payments with 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

TelePay client library for the PHP language, so you can easely process cryptocurrency payments using the REST API.

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

Installation

Install the package with composer:

composer require telepaycash/sdk-telepay-php

Using the library

Import the library classes using the Composer autoload:

require 'vendor/autoload.php';

use TelePay\TelePayClient;
use TelePay\TelePayEnvironment;

Configure the TelePay client using the secret of your merchant

$clientSecret = "YOUR API SECRET KEY";

$environment = new TelePayEnvironment($clientSecret);

$telepay = new TelePayClient($environment);

Get your current merchant

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

Response

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] => 
        )
)

Read docs

Get the balance of all merchant wallets

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

Response

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

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

        )

)

Read docs

Get the balance of one of the merchant wallets

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

Response

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

        )

)

Read docs

Get the assets

Get assets suported by TelePay. Read docs

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

Response

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
                )

        )

)

You can get the detail of a single asset. Read docs

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

Create one invoice

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

Response

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] => 
)

Read docs

View invoices

Find many invoices. Read docs

$invoicesResponse = $telepay->getInvoices();

Find one invoice by number. Read docs

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

Cancel invoice

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

Response

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
)

Delete invoice

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

Response

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

Transfer

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

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

Response

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

Read docs

Withdraw Fee

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

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

Response

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

Withdraw

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

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

Response

Array
(
    [success] => 1
)

View webhooks

Find many webhooks. Read docs

$webhooksResponse = $telepay->getWebhooks();

Find one webhook by Id. Read docs

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

Response

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

    [active] => 1
)

Create or update a webhook

For create a webhook is required the url, a secret and the events associated. Read docs

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

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

For update a webhook is required a webhookId and the new params. Read docs

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

Activate or deativate a webhook

$webhookId = 325;

$telepay->activateWebhook($webhookId);

$telepay->deactivateWebhook($webhookId);

Delete a webhook

$webhookId = 325;

$telepay->deleteWebhook($webhookId);

Tests

All endpoint responses were tested. To run the tests yourself, you need your TelePay merchant secret with at least 3 testnet toncoins, a Telepay user who will receive the test transfer, and a testnet wallet which will receive the test withdraw.

TELEPAY_SECRET_API_KEY= USERNAME_TELEPAY_TRANSFER= WHITDRAW_TO_WALLET= composer tests

Contributors ✨

The library is made by (emoji key):


Raubel Guerra

💻

Carlos Lugones

🧑‍🏫

This project follows the all-contributors specification. Contributions of any kind welcome!