PHP code example of payracash / payra-sdk-php

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

    

payracash / payra-sdk-php example snippets




use App\Payra\PayraSignature;
use App\Payra\PayraUtils;

// Load environment
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

// Convert USD to Wei
$amountWei = PayraUtils::toWei(3.45, 'polygon', 'usdt'); // in smallest token unit (Wei for USDT/USDC)

$payraSignature = new PayraSignature();

$signature = $payraSignature->generate(
    $network,         	// e.g. "polygon"
    $tokenAddress,    	// ERC-20 USDT or USDC
    $orderId,         	// string (unique per merchantId)
    $amountWei,       	// in Wei $1 = 1_000_000
    (int) $timestamp,
    $payerAddress     	// Public payer wallet address
);

use App\Payra\PayraOrderService;

// Load environment
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$orderService = new PayraOrderService();

$orderDetails = $orderService->getDetails(
    $network,   // e.g. "polygon"
    $orderId    // string (unique per merchantId)
);

echo  json_encode([
	$orderDetails,
]);

[
	{
	    "success"   => true,   // boolean: whether the RPC request succeeded
	    "error"     => null,   // string|null: error message if the request failed
	    "paid"      => true,   // boolean: whether the order is marked as paid on-chain
	    "token"     => '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', // payment token (USDT, USDC, etc.)
	    "amount"    => 400000, // amount in wei
	    "fee"       => 3600,   // fee in wei
	    "timestamp" => 1765138941 // UNIX timestamp
	}
]

use App\Payra\PayraOrderService;

// Load environment
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$orderService = new PayraOrderService();

$result = $orderService->isPaid(
    $network,   // e.g. "polygon"
    $orderId    // string (unique per merchantId)
);

// Return result to frontend
echo  json_encode([
	$result,
]);

[
	{
	    "success" => true,   // boolean: whether the RPC request succeeded
	    "paid"    => true,   // boolean: whether the order is marked as paid on-chain
	    "error"   => null,   // string|null: error message if the request failed, otherwise null
	}
]

use  App\Payra\PayraUtils;

$decimals = PayraUtils::getTokenDecimals('polygon', 'usdt');
echo  $decimals; // e.g., 6

use App\Payra\PayraUtils;

$amountWei = PayraUtils::toWei(3.34, 'polygon', 'usdt');
echo $amountWei; // "3340000" amount in USD converted to Wei

use App\Payra\PayraUtils;

// Convert from smallest token unit (Wei) to readable amount in USD
$amount = PayraUtils::fromWei('3340000', 'polygon', 'usdt', 2);
echo $amount; // "3.34" amount in USD (formatted to 2 decimals)

PayraUtils::fromWei('3340000', 'polygon', 'usdt', 4); // "3.3400"

use App\Payra\PayraUtils;

// Convert 120.43 EUR to USD
$amountUSD = PayraUtils::convertToUSD(120.43, 'EUR'); // converted amount in USD

PAYRA_EXCHANGE_RATE_API_KEY=your_api_key_here
bash
composer 
bash
git clone https://github.com/payracash/payra-sdk-php.git
cd payra-sdk-php
composer install
composer dump-autoload