DEV Community

Cover image for Send a Link, Get Paid: Building Payment Links with Afriex
0xSonOfUri for Afriex

Posted on

Send a Link, Get Paid: Building Payment Links with Afriex

Send a Link, Get Paid: Building Payment Links with the Afriex API

What if you could accept payments globally with just a link?

No checkout flows. No heavy integrations. Just a URL.


What This Guide Covers

This guide is about the Afriex API.

You’ll learn how to build a simple payment link system that allows you to:

  • Generate shareable payment links
  • Accept payments via bank transfer or crypto
  • Track payment status
  • Handle real payment confirmations

You do not need any specific framework. Your backend just needs to make secure HTTPS requests.


Afriex vs Your Application

Afriex provides the payment infrastructure.

You build the product layer.

Responsibility Who
Virtual accounts, crypto wallets, settlement rails Afriex
Payment link (URL), amount, expiry, status tracking Your App
Confirming payments securely Afriex Webhooks

System Architecture

Client → Backend → Afriex API → Payment Rails
Enter fullscreen mode Exit fullscreen mode
  • Your backend stores payment requests
  • Afriex handles payment execution
  • Your frontend displays payment instructions

Prerequisites

Before starting, you need:

  • An Afriex account
  • Your API key
  • A customerId (Afriex identifier for the recipient)

Every payment instruction you generate should be tied to a customerId.


Authentication

All Afriex API calls are made server-side.

GET {BASE_URL}/... HTTP/1.1
x-api-key: YOUR_AFRIEX_API_KEY
Content-Type: application/json
Enter fullscreen mode Exit fullscreen mode

Example:

curl -sS -G "{BASE_URL}/api/v1/payment-method/virtual-account" \
  -H "x-api-key: YOUR_AFRIEX_API_KEY" \
  --data-urlencode "currency=NGN" \
  --data-urlencode "amount=5000" \
  --data-urlencode "customerId=PAYEE_CUSTOMER_ID"
Enter fullscreen mode Exit fullscreen mode

Step 1: Create a Payment Link (Your Backend)

Afriex does not create “payment links” for you — you implement this.

Store:

  • amount
  • currency
  • description
  • expiry
  • customerId
  • unique token
import crypto from "crypto";

const linkId = crypto.randomBytes(16).toString("hex");

await db.payment.create({
  linkId,
  amount: 5000,
  currency: "NGN",
  customerId,
  expiresAt: new Date(Date.now() + 30 * 60 * 1000),
});
Enter fullscreen mode Exit fullscreen mode

Then generate:

https://yourapp.com/pay/{linkId}
Enter fullscreen mode Exit fullscreen mode

Step 2: Generate Payment Instructions

When a user opens the link:

  1. Load the payment request
  2. Call Afriex
  3. Return instructions

🇳🇬 Virtual Account (Bank Transfer)

curl -sS -G "{BASE_URL}/api/v1/payment-method/virtual-account" \
  -H "x-api-key: YOUR_AFRIEX_API_KEY" \
  --data-urlencode "currency=NGN" \
  --data-urlencode "amount=5000" \
  --data-urlencode "customerId=PAYEE_CUSTOMER_ID"
Enter fullscreen mode Exit fullscreen mode

Display:

  • Account number
  • Account name
  • Bank name

Crypto Wallet (USDC / USDT)

curl -sS -G "{BASE_URL}/api/v1/payment-method/crypto-wallet" \
  -H "x-api-key: YOUR_AFRIEX_API_KEY" \
  --data-urlencode "asset=USDC" \
  --data-urlencode "customerId=PAYEE_CUSTOMER_ID"
Enter fullscreen mode Exit fullscreen mode

Response:

{
  "data": [
    {
      "address": "0x...",
      "network": "ethereum"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

If USDC is unavailable, fallback to USDT.


Step 3: Choosing Payment Method

In your backend:

  • If currency = NGN → virtual account
  • If currency = USD → crypto wallet

This logic is controlled by your application, not Afriex.


Step 4: Confirm Payment (Production)

Do NOT rely on:

  • Button clicks
  • User confirmation

Use Afriex webhooks:

  1. Receive event
  2. Verify signature
  3. Match to payment record
  4. Mark as paid

Always handle this idempotently.


Security Checklist

  • Keep API keys server-side only
  • Use HTTPS
  • Use unguessable link tokens
  • Expire links
  • Verify webhooks

Why This Pattern Matters

This is the same pattern used by:

  • Stripe
  • Paystack
  • Flutterwave

Payment links are one of the fastest ways to start accepting payments globally.


Summary

To build payment links with Afriex:

  1. Create a customer → get customerId
  2. Store a payment request in your database
  3. Generate a shareable link
  4. Fetch payment instructions via Afriex
  5. Confirm payments via webhooks

Next Steps

  • Add webhook automation
  • Support more currencies
  • Build dashboards
  • Add notifications

Final Note

Afriex gives you the rails.

You build the product.

Top comments (0)