Payra Crypto Payments signature generator SDK for Laravel
payracash/payra-sdk-laravel is a Laravel package for payra crypto payments signature generator sdk for laravel.
It currently has 0 GitHub stars and 8 downloads on Packagist (latest version v1.2.4).
Install it with composer require payracash/payra-sdk-laravel.
Discover more Laravel packages by payracash
or browse all Laravel packages to compare alternatives.
Last updated
Official Laravel SDK for integrating Payra's on-chain payment system into your backend applications.
This SDK provides:
The typical flow for signing and verifying a Payra transaction:
payOrder) with all parameters plus the signature.This process ensures full compatibility between your backend and Payra’s on-chain verification logic.
secp256k1 curve.ERC-1155 payment verification).web3.php..env and config/payra.php configuration for multiple blockchain networks.Before installing this package, make sure you have an active Payra account:
https://payra.cash/products/on-chain-payments/registration
Before installing this package, make sure you have a MerchantID
Additionally: To obtain your RPC URLs which are required for reading on-chain order details directly from the blockchain, you can use the public free endpoints provided with this package or create an account on one of the following services for better performance and reliability:
QuickNode – Extremely fast and excellent for Polygon/Mainnet. (quicknode.com)
Alchemy – Offers a great developer dashboard and high reliability. (alchemy.com)
DRPC – Decentralized RPC with a generous free tier and a strict no-log policy. (drpc.org)
Infura – The industry standard; very stable, especially for Ethereum. (infura.io)
Optional (recommended):
.env file for environment configurationcomposer require payracash/payra-sdk-laravel
Laravel will auto-discover the service provider.
You can also publish the configuration file:
php artisan vendor:publish --tag=payra-config
Create a .env file in your project root (you can copy from example):
cp .env.example .env
This file stores your private configuration and connection settings for all supported networks. Never commit .env to version control.
Exchange Rate (optional) used for automatic fiat → USD conversions via the built-in Payra utilities.
# (Optional) API key required for authenticating backend requests
PAYRA_API_KEY=
# Optional: used by PayraUtils::convertToUSD() for fiat conversions
PAYRA_EXCHANGE_RATE_API_KEY=
PAYRA_EXCHANGE_RATE_CACHE_TIME=720 # in minutes
# Polygon network configuration
PAYRA_POLYGON_OCP_GATEWAY_CONTRACT_ADDRESS=0xc56c55D9cF0FF05c85A2DF5BFB9a65b34804063b
PAYRA_POLYGON_SIGNATURE_KEY=
PAYRA_POLYGON_MERCHANT_ID=
PAYRA_POLYGON_RPC_URL_1=https://polygon-rpc.com
# Ethereum network configuration
PAYRA_ETHEREUM_OCP_GATEWAY_CONTRACT_ADDRESS=
PAYRA_ETHEREUM_SIGNATURE_KEY=
PAYRA_ETHEREUM_MERCHANT_ID=
PAYRA_ETHEREUM_RPC_URL_1=
PAYRA_ETHEREUM_RPC_URL_2=
# Linea network configuration
PAYRA_LINEA_OCP_GATEWAY_CONTRACT_ADDRESS=
PAYRA_LINEA_SIGNATURE_KEY=
PAYRA_LINEA_MERCHANT_ID=
PAYRA_LINEA_RPC_URL_1=
PAYRA_LINEA_RPC_URL_2=
These values will be loaded into config/payra.php.
PAYRA_EXCHANGE_RATE_CACHE_TIME:
5 → cache for 5 minutes60 → cache for 1 hour720 → cache for 12 hours (default)This package uses a simple API key to protect backend HTTP endpoints (for example /api/payra/generate/signature and /api/payra/convert/to/usd).
You create this key yourself and keep it secret, it is not issued by Payra. The backend (your Laravel app) validates the key in the X-Payra-Key header.
Note: The API key is only required if you expose Payra endpoints via HTTP (for example, when your frontend calls your backend). If you are using the SDK internally in your Laravel app or services (without calling API routes), you can safely omit this variable.
Generate a long random key (do not handcraft a short password). Examples:
# recommended: 32 bytes hex
php -r "echo bin2hex(random_bytes(32));"
# or using openssl
openssl rand -hex 32
Put the generated key into your .env:
# API key required for authenticating backend requests
PAYRA_API_KEY=your_generated_hex_key_here
Include the key in the X-Payra-Key header:
curl -X POST "https://your-domain.com/api/payra/generate/signature" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-Payra-Key: your_generated_hex_key_here" \
-d '{"network":"polygon","token_address":"0x...","order_id":"order_1","amount":"1000000","timestamp":1234567890,"payer_address":"0x..."}'
https://your-domain.com/payra/generate/signature
https://your-domain.com/payra/order/details
https://your-domain.com/payra/order/is-paid
https://your-domain.com/payra/convert/to/usd
.env (never in client-side code or public repositories)..env (and deployed configs).PAYRA_API_KEY is missing from .env, middleware will return an explicit configuration error (500), if it is present but mismatched, requests return 401 Unauthorized.use Payra\PayraSignature;
class PayraController extends Controller
{
public function generateSignature()
{
$payraSignature = app(PayraSignature::class);
$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, // now()->timestamp
$payerAddress // Public payer wallet address
);
return response()->json(['signature' => $signature]);
}
}
{
"status": "success",
"signature": "0x2772922237f8960627760c568965903c9ea25f76bd63320fc6c03bc8f614905036837347c8ed7e94b93c570ebe5e6abb0272b3096fce065e000d5413a8c3561c1c",
"message": "Signature generated successfully."
}
| Field | Type | Description |
|--------------|----------|----------------------------------------------|
| network | string | Selected network name |
| tokenAddress | string | ERC20 token contract address |
| orderId | string | Unique order reference (e.g. ORDER-123) |
| amountWei | string or integer | Token amount in smallest unit (e.g. wei) |
| timestamp | number | Unix timestamp of signature creation |
| payerAddress | string | Payer Wallet Address
Retrieve full transaction details for a specific order from the Payra smart contract. This method returns the complete on-chain payment data associated with the order, including:
Use this method when you need detailed information about the payment or want to display full transaction data.
use Payra\PayraOrderService;
class PayraController extends Controller
{
public function getDetails()
{
$orderService = app(PayraOrderService::class);
$orderDetails = $orderService->getDetails(
$network, // e.g. "polygon"
$orderId, // string (unique per merchantId)
);
return response()->json(['result' => $orderDetails]);
}
}
{
"result": {
"success": true,
"error": null,
"paid": true,
"token": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
"amount": 400000,
"fee": 3600,
"timestamp": 1765138941
}
}
Perform a simple payment check for a specific order. This method only verifies whether the order has been paid (true or false) and does not return any additional payment details.
Use this method when you only need a quick boolean confirmation of the payment status.
use Payra\PayraOrderService;
class PayraController extends Controller
{
public function isPaid()
{
$orderService = app(PayraOrderService::class);
$isPaid = $orderService->isPaid(
$network, // e.g. "polygon"
$orderId, // string (unique per merchantId)
);
return response()->json(['result' => $isPaid]);
}
}
{
"result": {
"success": true,
"paid": true,
"error": null
}
}
The SDK includes helper functions for working with token amounts and currency conversion.
use Payra\PayraUtils;
class PaymentController extends Controller
{
public function convertToUSD()
{
$utils = app(PayraUtils::class);
$tokenDecimals = $utils->getTokenDecimals('polygon', 'USDT');
return response()->json(['token_decimals' => $tokenDecimals]);
}
}
{
"token_decimals": 6
}
Returns the number of decimal places for a given token on a specific network.
use Payra\PayraUtils;
class PaymentController extends Controller
{
public function convertToUSD()
{
$utils = app(PayraUtils::class);
$toWei = $utils->toWei(14.33, 'polygon', 'USDT');
return response()->json(['to_wei' => $toWei]);
}
}
{
"to_wei": 14330000
}
use Payra\PayraUtils;
class PaymentController extends Controller
{
public function convertToUSD()
{
$utils = app(PayraUtils::class);
$fromWei = $utils->fromWei(34345230, 'polygon', 'USDT');
return response()->json(['from_wei' => $fromWei]);
}
}
{
"from_wei": 34.35
}
Payra processes all payments in USD. If your store uses another currency (like EUR, AUD, or GBP), you can:
use Payra\PayraUtils;
class PaymentController extends Controller
{
public function convertToUSD()
{
$utils = app(PayraUtils::class);
$convertedAmount = $utils->convertToUSD(
$amount, // e.g. 232.23
$from_currency // e.g. EUR
);
return response()->json(['converted_amount' => $convertedAmount]);
}
}
{
"converted_amount": 177.64 # in USD
}
To use the conversion helper, you need a free API key from exchangerate-api.com.
.env file:PAYRA_EXCHANGE_RATE_API_KEY=your_api_key_here
Note: The free plan allows 1,500 requests per month, which is sufficient for most stores. Exchange rates on this plan are updated every 24 hours, so with caching, it’s more than enough. Paid plans offer faster update intervals.
use Payra\PayraSignature;
use Payra\PayraOrderService;
use Payra\PayraUtils;
class PaymentController extends Controller
{
public function __construct(
private PayraSignature $signature,
private PayraOrderService $order,
private PayraUtils $utils
) {}
public function generateSignature()
{
// $network, $tokenAddress, $orderId, $amountWei, $timestamp, $payerAddress
// should come from request / your business logic
$signature = $this->signature->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, // now()->timestamp
$payerAddress // Public payer wallet address
);
return response()->json([
'status' => 'success',
'signature' => $signature,
'message' => 'Signature generated successfully.'
]);
}
public function getDetails()
{
$orderDetails = $this->order->getDetails(
$network, // e.g. "polygon"
$orderId // string (unique per merchantId)
);
return response()->json(['order_details' => $orderDetails]);
}
public function isPaid()
{
$isPaid = $this->order->isPaid(
$network, // e.g. "polygon"
$orderId // string (unique per merchantId)
);
return response()->json(['is_paid' => $isPaid]);
}
public function convertToUSD()
{
$convertedAmount = $this->utils->convertToUSD(
$amount, // e.g. 232.23
$from_currency // e.g. EUR
);
return response()->json(['converted_amount' => $convertedAmount]);
}
}
Never expose your signature key in frontend or client-side code.
This SDK is server-side only and must be used securely on your backend. Never use it in frontend or browser environments. Also, never commit your .env file to version control.
MIT © Payra