मुख्य सामग्री पर जाएँ
गाइड

Add a Crypto Payment Gateway in Laravel, Node.js & Python

One integration pattern, three backends. Real SDK code for Laravel, Node.js and Python to create crypto payments and verify webhooks, plus pointers for Flutter and React Native apps.

RazCrypto टीम8 मिनट पढ़ें
15व्यू
Add a Crypto Payment Gateway in Laravel, Node.js & Python

Updated November 2026

Adding a crypto payment gateway to a Laravel, Node.js or Python backend takes three pieces of code: create a payment on your server, send the customer to the checkout_url it returns, and mark the order paid when a signed webhook arrives. This guide gives you working code for all three stacks using the official RazCrypto SDKs, plus how a Flutter or React Native app fits on top.

The pattern is the same everywhere, so read the first section once and then jump to your stack.

How the integration works

  1. Your server creates a payment with the secret key (sk_test_… or sk_live_…): amount, currency, your order id as reference_id, and an idempotency key.
  2. The customer pays on the hosted checkout (redirect or checkout.js popup). They pick a network and coin, and the money goes straight to your wallet. RazCrypto is a non-custodial crypto payment gateway, so it never holds the funds.
  3. RazCrypto sends a signed webhook (payment.paid) to your server. You verify the signature and fulfil the order once.

Three rules apply on every stack:

  • The secret key and the webhook signing secret (whsec_…) live on the server only, in environment variables. Never in the browser or in a mobile app.
  • Only paid means the money arrived. The status is one of pending, confirming, paid, underpaid, expired, cancelled.
  • Webhooks verify against the raw body. Parsed JSON will not match the signature.

Before you write code, create a test app: sign up, switch the dashboard to Test, add a BNB Smart Chain wallet (test wallets activate instantly), then API apps → New app. Copy the secret key (shown once), set the webhook URL and copy the signing secret.

Shell
# .env (server only)
RAZCRYPTO_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxx
RAZCRYPTO_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxx

The raw API call

Every SDK wraps one endpoint. If your stack has no SDK, this is all you need:

Shell
curl https://razcryptogateway.com/v1/payments \
  -H "Authorization: Bearer $RAZCRYPTO_SECRET_KEY" \
  -H "Idempotency-Key: order_1042" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "25.00",
    "currency": "USD",
    "reference_id": "order_1042",
    "redirect_url": "https://shop.example/thanks"
  }'

The response contains id (pay_…) and checkout_url. currency can be fiat (USD, INR, EUR and others, converted at a locked rate) or a coin such as USDT for an exact crypto amount. The same Idempotency-Key never creates a second payment, so retries are safe. The full parameter list is in the crypto payment API overview.

Laravel (PHP)

The PHP SDK needs PHP 8.1+ with cURL and no other Composer packages. It works in Laravel, Symfony, CodeIgniter or plain PHP.

Shell
composer require worldxgrowth/razcrypto-php-sdk

Add the keys to config/services.php:

PHP
'razcrypto' => [
    'secret_key'     => env('RAZCRYPTO_SECRET_KEY'),
    'webhook_secret' => env('RAZCRYPTO_WEBHOOK_SECRET'),
],

Create a payment

PHP
use RazCrypto\Client;

$rc = new Client(config('services.razcrypto.secret_key'));

$payment = $rc->payments()->create([
    'amount'       => number_format((float) $order->amount, 2, '.', ''), // decimal string
    'currency'     => 'INR',
    'reference_id' => (string) $order->id,
    'description'  => 'Order #' . $order->id,
    'redirect_url' => 'https://shop.example/thanks',
], 'order_' . $order->id);   // idempotency key

$order->update(['gateway_payment_id' => $payment['id']]);

return redirect()->away($payment['checkout_url']);

Verify the webhook

PHP
use Illuminate\Http\Request;
use RazCrypto\Webhook;
use RazCrypto\Exception\SignatureVerificationError;

public function webhook(Request $request)
{
    try {
        $event = Webhook::verify(
            $request->getContent(),            // raw body, not $request->all()
            $request->headers->all(),
            config('services.razcrypto.webhook_secret')
        );
    } catch (SignatureVerificationError $e) {
        return response('invalid signature', 400);
    }

    $payment = $event['data']['object'];       // the full payment object
    if ($event['type'] === 'payment.paid') {
        markOrderPaid($payment['reference_id'], $payment['id']);
    }
    return response('ok', 200);
}

Put the route in routes/api.php so it has no CSRF check. In Laravel 11+ run php artisan install:api once if that file does not exist. A webhook in web.php returns 419. Store the webhook-id header and skip repeats, because retries reuse it. The PHP SDK docs include a full Laravel integration with a migration, encrypted admin-panel keys and a row-locked sync() method.

Node.js

The Node SDK needs Node.js 18+, has no runtime dependencies, ships TypeScript types and supports both ESM and CommonJS. It works in Express, NestJS, Fastify, Next.js API routes and serverless functions.

Shell
npm install razcrypto-node

Create a payment

JavaScript
import { RazCrypto } from 'razcrypto-node';

const rc = new RazCrypto(process.env.RAZCRYPTO_SECRET_KEY);

const payment = await rc.payments.create(
  {
    amount: '49.00',
    currency: 'USD',
    reference_id: 'order_1042',
    redirect_url: 'https://shop.example/thanks',
  },
  { idempotencyKey: 'order_1042' },
);

res.redirect(payment.checkout_url);

Verify the webhook

JavaScript
import express from 'express';
import { webhooks } from 'razcrypto-node';

// Raw body on this route only, registered before express.json()
app.post('/webhooks/razcrypto', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    event = webhooks.verify(req.body, req.headers, process.env.RAZCRYPTO_WEBHOOK_SECRET);
  } catch {
    return res.sendStatus(400);
  }
  const payment = event.data.object;
  if (event.type === 'payment.paid') await markOrderPaid(payment.reference_id, payment.id);
  res.sendStatus(200);
});

webhooks.verify throws SignatureVerificationError if the signature is wrong, the body changed or the timestamp is more than 5 minutes off. In NestJS enable rawBody: true in NestFactory.create and pass req.rawBody. Network errors, 429 and 5xx responses are retried automatically with the same idempotency key. See the Node.js SDK docs.

Python

The Python SDK needs Python 3.9+, uses only the standard library and is typed. It works with Django, Flask, FastAPI or a plain script.

Shell
pip install razcrypto

Create a payment

Python
import os
from razcrypto import RazCrypto

rc = RazCrypto(os.environ["RAZCRYPTO_SECRET_KEY"])

payment = rc.payments.create(
    amount="49.00",
    currency="USD",
    reference_id=str(order.id),
    redirect_url="https://shop.example/thanks",
    idempotency_key=f"order_{order.id}",
)
# redirect the customer to payment["checkout_url"]

Verify the webhook (Flask)

Python
from flask import request
from razcrypto import webhooks, SignatureVerificationError

@app.post("/webhooks/razcrypto")
def razcrypto_webhook():
    try:
        event = webhooks.verify(request.get_data(), request.headers, os.environ["RAZCRYPTO_WEBHOOK_SECRET"])
    except SignatureVerificationError:
        return "", 400
    payment = event["data"]["object"]
    if event["type"] == "payment.paid":
        mark_order_paid(payment["reference_id"], payment["id"])
    return "", 200

In Django call webhooks.verify(request.body, request.headers, secret) inside a @csrf_exempt view. In FastAPI pass await request.body(). Details are in the Python SDK docs.

Checking a payment yourself

The webhook is the main signal, but you can always ask the API for the current state, for example on your thank-you page:

StackCall
Laravel / PHP$rc->payments()->retrieve('pay_…')
Node.jsawait rc.payments.retrieve('pay_…')
Pythonrc.payments.retrieve("pay_…")

Treat the redirect back to redirect_url as a hint only. It carries payment_id, reference_id, status and a signature, which each SDK can check (CheckoutSignature::isValid, isValidCheckoutSignature, is_valid_checkout_signature), but still confirm with retrieve() or the webhook before you ship.

Mobile apps: Flutter and React Native

A mobile app never holds a secret. It asks your backend (any of the three above) to create the payment, opens the checkout_url inside the app, and sends the result back to the server for verification. Your backend exposes four endpoints: create, verify (signature plus retrieve), status (for polling while the payment confirms) and the webhook.

Flutter: flutter pub add razcrypto_checkout (Android and iOS, Flutter 3.24+). Open the checkout with:

Dart
final result = await RazCryptoCheckout.open(
  context,
  CheckoutOptions.fromCheckoutUrl(checkoutUrl, locale: 'en'), // 'hi' for Hindi
);

The result is CheckoutSuccess, CheckoutPending, CheckoutCancelled or CheckoutFailed. See the Flutter SDK docs.

React Native: npm install @razcrypto/react-native react-native-webview (React Native 0.72+, Expo dev builds supported). The useRazCryptoCheckout() hook returns open({ checkoutUrl, locale }), which resolves to success, pending, cancelled or failed.

There is also an Android/Kotlin SDK and a checkout.js popup for websites. Every option is listed on the SDKs overview.

Test every outcome before going live

With a test key, simulate any outcome. Real webhooks are sent, exactly as in live mode:

PHP
$rc->payments()->simulate('pay_…', 'paid');     // PHP
JavaScript
await rc.payments.simulate('pay_…', 'paid');    // Node.js
Python
rc.payments.simulate("pay_…", "paid")            # Python

Also try underpaid, expired and cancelled, then check Dashboard → API apps → Webhooks for your 200 responses. Failed deliveries are retried for 3 days. When everything passes, create a live app, add your real wallets and swap in the sk_live_… key. The test mode guide covers each case.

Production checklist

Before you switch to live keys, walk through this list. Each item comes from a problem developers actually hit.

  • Keys per mode. sk_test_… only works with test payments and sk_live_… only with live ones. A mixed key returns 401 api_key_invalid. Keep separate environment variables per environment.
  • Signing secret per app. Each API app has its own whsec_…. A webhook that verifies in test and fails in live usually means the test secret is still configured.
  • Raw body on the webhook route only. In Express, register express.raw() on the webhook route before the global express.json(). In Laravel, read $request->getContent(). In Django, read request.body.
  • Answer fast. Return 2xx within 10 seconds and do slow work (emails, invoices, stock updates) in a queue. A slow handler looks like a failure and triggers retries.
  • Fulfil once. Store the webhook-id header, lock the order row while you update it, and check that the payment's reference_id matches the order before you ship.
  • Handle every status. confirming means the transfer is on-chain but not final yet. underpaid means the customer sent less; they can top up before the payment expires. Show a clear message for each instead of a generic error.
  • Amounts as strings. Send "49.00", not 49. Fiat amounts allow 2 decimals at most.
  • Small orders. Each coin has a minimum amount (listed as min_amount in GET /v1/chains), so a very small order may not be payable in every coin.

FAQ

Which crypto can customers pay with?

USDT and USDC plus BNB, ETH, SOL and VDC, on BNB Smart Chain, Ethereum, Solana and VDChain. There is no Bitcoin and no Tron (TRC20). The live list comes from GET /v1/chains.

Do I need the SDK, or can I call the API directly?

Either works. The SDKs add retries, typed errors, pagination and webhook verification, but the REST API is plain JSON over HTTPS with a Bearer key, so any language can use it.

Why does my webhook always return 400?

Almost always because the body was parsed before verification. Use the raw body ($request->getContent(), express.raw, request.get_data()), and check that the signing secret matches the mode (test or live) of the app.

How do I stop an order being fulfilled twice?

Use the order id as the idempotency key when you create the payment, store the webhook-id header of each processed webhook, and fulfil only when the order is not already marked paid, inside a database transaction.

Is there a per-transaction fee on API payments?

No. API and checkout payments are unlimited on every plan with 0% per-transaction fee. The customer pays the network fee of the chain.

Are the SDKs open source?

Yes. The SDKs are MIT-licensed on GitHub, and the gateway itself is open source under AGPL-3.0.

Start building

Create a test app and run your first simulated payment in a few minutes. Sign up for the 7-day free trial, and check the pricing: Pro is $4.99/month with unlimited API payments and 0% transaction fees.

क्या आप नॉन-कस्टोडियल क्रिप्टो पेमेंट गेटवे ढूंढ रहे हैं? RazCrypto USDT और USDC सीधे आपके वॉलेट में भेजता है, 0% ट्रांज़ैक्शन फीस के साथ। फ्री शुरू करें →

  • #crypto payment gateway integration
  • #laravel crypto payment gateway
  • #node.js crypto payment api
  • #python crypto payment gateway
  • #accept usdt api
  • #crypto payment webhook
  • #crypto payment sdk

काम का लगा? लाइक या शेयर करें।

15व्यूWhatsAppXLinkedInFacebook

RazCrypto टीम

हम RazCrypto बनाते हैं, एक नॉन-कस्टोडियल क्रिप्टो पेमेंट गेटवे। हमारी गाइड वही लोग लिखते और जांचते हैं जो यह प्रोडक्ट चलाते हैं।

हमारे बारे में →

और लेख