PHP code example of sarani / cryptopay

1. Go to this page and download the library: Download sarani/cryptopay 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/ */

    

sarani / cryptopay example snippets


// use Sarani\CryptoBot;

# init
$cryp_payment_token = 'token';
$mode = 'test'; // empty for real account 
$crypto = new Sarani\CryptoPay\Api($cryp_payment_token, 'test');

$me = $crypto->getMe();

# create invoice, return Invoices object 
  $inv = $crypto->createInvoice($params = [
    'asset'   => 'USDT',
    'amount'  => '2.50',
    'payload' =>  '11158', # subscription id
    'allow_comments' => False,
    'allow_anonymous' => True,
    'paid_btn_name' => 'openBot',
    'paid_btn_url' => 'https://t.me/demobot',
    'hidden_message' => 'Thanks for your payment',
    'description' => 'Monthly Subscription'
  ]);
  echo $inv->id();
  echo $inv->url();

# get invoice, return array of Invoices object 
$res = $crypto->getInvoices($params = [
  'asset'  =>  'TON', // Crypto symbols
  'invoice_ids'   => '12600,12626,12745', // ids seperated by comma
]);

# transfer to user, return Transfer object 
$transfer = $crypto->transfer($params = [
  'user_id'  =>  '1111111', // telegram user_id
  'asset'   => 'USDT', // Crypto
  'amount'  => '2.50', // amount
  'spend_id' =>  '1001', # reequest uniqe id to avoid double transfer
  'disable_send_notification'  =>  False,
  'comment' =>  'gift transfer'
]);

# webhook, return Webhook object with Update and Invoice 
$hook = new Sarani\CryptoPay\Webhook();
$update = $hook->getUpdate(); // Update object
$nvoice =   $update->getPayload(); // Invoice Object
echo( $nvoice->status());