DEV Community

Cover image for Supercharge Your Backend: Seamless Crypto Payments with the Official Payra Cash PHP SDK
Wraith
Wraith

Posted on

Supercharge Your Backend: Seamless Crypto Payments with the Official Payra Cash PHP SDK

Introduction: The New Frontier of On-Chain Payments

Cryptocurrency payments are no longer a niche feature; they are becoming a vital component of modern e-commerce and web applications. Payra Cash offers a robust, decentralized solution for accepting on-chain payments directly on the blockchain, cutting out intermediaries and reducing transaction costs.

Historically, integrating crypto payments required deep expertise in cryptography, ABI encoding, and smart contract interactions. This changes today with the official release of the Payra Cash PHP SDK.

This article is a deep dive for PHP developers, showing how this new SDK transforms the complex process of ECDSA signature generation and payment verification into simple function calls on your server.


What is the Payra Cash PHP SDK?

The Payra Cash PHP SDK is the official library designed to securely and seamlessly connect your PHP backend (whether Laravel, Symfony, or pure PHP) to the Payra payment protocol.

Its core functionalities include:

  1. Secure ECDSA Signature Generation: Creating the cryptographic signatures required to authorize transactions in the Payra smart contract.

  2. On-Chain Payment Verification: Checking the order status directly on the blockchain (e.g., Polygon, Ethereum, Linea) to confirm a payment has been successfully completed.

  3. Built-in Utilities: Simplifying token precision handling (USD ⇄ WEI conversions) and offering optional fiat currency conversion (e.g., EUR to USD).

Why PHP?

PHP remains the bedrock of millions of websites and e-commerce applications globally. This SDK empowers developers within this massive ecosystem to join the DeFi revolution without needing to change their tech stack.


The Core Transaction Flow: Backend in Action

Integrating Payra Cash with the PHP SDK revolves around one critical task: securely generating a cryptographic signature on your backend.

Here is the simplified flow for a Payra transaction:

  1. Frontend Prepares Data: The user's browser collects all necessary payment parameters (network, token address, Order ID, Amount in Wei, Timestamp, Payer's wallet address).

  2. Request to Backend: The frontend sends this data to your PHP application.

  3. Backend Generates Signature: This is where the PHP SDK shines. Using your confidential Private Key (which never leaves your server!), the SDK generates a unique ECDSA signature compatible with the Payra smart contract.

  4. Signature Returned to Frontend: The backend sends the generated signature back to the user's browser.

  5. On-Chain Transaction: The frontend submits all data plus the signature to the Payra smart contract (payOrder). The contract validates the signature and executes the payment.

Security is Non-Negotiable

The crucial security benefit is that signature generation happens offline on your server. Your private key is protected within your environment, and the SDK ensures cryptographic correctness.


Step-by-Step Integration Guide

1. Installation

The SDK is available via Composer, making installation swift:

composer require payracash/payra-sdk-php
Enter fullscreen mode Exit fullscreen mode

2. Environment Configuration

For the SDK to operate, it needs your merchant keys and contract addresses for each network (e.g., Polygon, Ethereum).

In your .env file, define the essential variables:

# Polygon Network Configuration
PAYRA_POLYGON_PRIVATE_KEY=Your_Private_Key_for_sign_orders
PAYRA_POLYGON_MERCHANT_ID=Your_Merchant_ID
PAYRA_POLYGON_RPC_URL_1=Your_RPC_Endpoint_from_QuickNode
# ... similar configuration for other networks (Ethereum, Linea)

# Optional for Fiat -> USD conversion
PAYRA_EXCHANGE_RATE_API_KEY=Your_key_from_exchangerate-api.com
Enter fullscreen mode Exit fullscreen mode

Security Notice: Remember to never commit your .env file to version control. This SDK is server-side only and must be used securely on your backend.

3. Generating the Signature (The Heart of the SDK)

With the built-in utilities, you can effortlessly handle amount conversions (e.g., USD to Wei) and generate the required signature:

use App\Payra\PayraSignatureGenerator;
use App\Payra\PayraUtils;

// 1. Convert $3.45 USD into Wei (the smallest token unit) on Polygon/USDT
$amountWei = PayraUtils::toWei(3.45, 'polygon', 'usdt'); 

$generator = new PayraSignatureGenerator();

$signature = $generator->generateSignature(
    "polygon", 
    $tokenAddress,      // ERC-20 token contract address (e.g., USDT/USDC)
    "ORDER-123",        // Unique Order ID
    $amountWei,         // Amount in Wei
    time(),             // Current Unix Timestamp
    $payerAddress       // Public Payer Wallet Address
);

// Return $signature to the frontend for the on-chain call
Enter fullscreen mode Exit fullscreen mode

4. Verifying Order Status

Once the user attempts the transaction, you must confirm the order has been paid. The SDK does this by reading the payment status directly from the smart contract, using your configured RPC endpoints:

use App\Payra\PayraOrderVerification;

$orderVerification = new PayraOrderVerification();

$verify = $orderVerification->isOrderPaid("polygon", "ORDER-123");

if ($verify['paid']) {
    // Update the order status in your database!
    echo "Payment successful. Order-123 is paid!";
} else {
    echo "Payment pending or failed.";
}
Enter fullscreen mode Exit fullscreen mode

Conclusion: Entering Web3 with PHP Power

The Payra Cash PHP SDK eliminates the steep learning curve for PHP developers entering the Web3 payments space. It turns complex cryptographic operations and on-chain interactions into straightforward server-side tasks.

If your business relies on PHP and you are looking for a secure, scalable, and decentralized way to accept crypto, this SDK is the tool you need.

I encourage you to explore the full documentation and begin your integration:

GitHub Project: https://github.com/payracash/payra-sdk-php

Payra Cash: https://payra.cash


Follow Payra on Twix (X) and join our Telegram Group for updates and support!

Top comments (0)