Skip to main content

Quick Start

Create your first payment in under 5 minutes.

Prerequisites​

  • A Uplef merchant account (Sign up here)
  • API keys from your dashboard

Step 1: Create an Order​

Create a payment order by calling the Create Order API:

curl -X POST https://api.uplef.com/api/v1/orders \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_api_secret" \
-H "Content-Type: application/json" \
-d '{
"amount": 100.00,
"currency": "USD",
"customer": {
"name": "John Doe",
"email": "john@example.com",
"phone": "+1234567890"
},
"successUrl": "https://yoursite.com/payment/success",
"failureUrl": "https://yoursite.com/payment/failure"
}'

Response​

{
"success": true,
"data": {
"order": {
"orderId": "ORD_1701234567890_abc123",
"transactionId": "TXN_1701234567890_789xyz",
"amount": 100.00,
"currency": "USD",
"status": "created",
"expiresAt": "2024-11-29T11:00:00.000Z"
},
"paymentPageUrl": "https://pay.uplef.com/pay/abc123def456...",
"accessToken": "abc123def456...",
"availablePaymentMethods": ["crypto", "card"]
}
}

Step 2: Redirect Customer to Payment Page​

Use the paymentPageUrl from the response to redirect your customer:

// Redirect to payment page
window.location.href = response.data.paymentPageUrl;

The customer will:

  1. See available payment methods (Crypto, Card, etc.)
  2. Select their preferred method
  3. Complete the payment
  4. Be redirected to your successUrl or failureUrl

While you can rely on the redirect URLs, webhooks provide a more reliable way to receive payment notifications. Set up a webhook endpoint:

// Express.js example
const express = require('express');
const crypto = require('crypto');
const app = express();

// Keep the raw body so the signature is checked against the exact bytes we sent.
app.use(express.json({
verify: (req, res, buf) => { req.rawBody = buf; },
}));

app.post('/webhooks/uplef', (req, res) => {
// Verify webhook signature against the RAW body.
// Do not use JSON.stringify(req.body) — parsing and re-serialising can change key
// order, spacing and number formatting, which produces a different hash and makes
// verification fail intermittently. See the Webhooks guide for details.
const signature = req.headers['x-uplef-signature'];
const expectedSignature = crypto
.createHmac('sha256', process.env.WEBHOOK_SECRET)
.update(req.rawBody)
.digest('hex');

if (signature !== expectedSignature) {
return res.status(401).send('Invalid signature');
}

// Handle the event
const { event, data } = req.body;

switch (event) {
case 'payment.success':
console.log('Payment successful:', data.orderId);
// Update your database, fulfill the order, etc.
break;
case 'payment.failed':
console.log('Payment failed:', data.orderId, data.failureReason);
// Handle failed payment
break;
default:
console.log('Unhandled event:', event);
}

// Always return 200 to acknowledge receipt
res.status(200).send('OK');
});

app.listen(3000);

Step 4: Verify Payment Status​

You can also verify payment status programmatically:

const verifyPayment = async (orderId) => {
const response = await fetch(
`https://api.uplef.com/api/v1/transactions/${orderId}/verify`,
{
method: 'POST',
headers: {
'X-API-Key': process.env.UPLEF_API_KEY,
'X-API-Secret': process.env.UPLEF_API_SECRET,
},
}
);

const data = await response.json();
console.log('Payment status:', data.data.status);
return data;
};

Complete Integration Example​

Here's a complete Node.js/Express example:

const express = require('express');
const app = express();

app.use(express.json());

// Create order endpoint
app.post('/api/checkout', async (req, res) => {
const { productId, quantity } = req.body;

// Calculate amount based on your business logic
const amount = calculateAmount(productId, quantity);

// Create Uplef order
const response = await fetch('https://api.uplef.com/api/v1/orders', {
method: 'POST',
headers: {
'X-API-Key': process.env.UPLEF_API_KEY,
'X-API-Secret': process.env.UPLEF_API_SECRET,
'Content-Type': 'application/json',
},
body: JSON.stringify({
amount,
currency: 'USD',
externalOrderId: `ORDER_${Date.now()}`, // Your order ID
customer: req.body.customer,
successUrl: `${process.env.BASE_URL}/payment/success`,
failureUrl: `${process.env.BASE_URL}/payment/failure`,
metadata: { productId, quantity },
}),
});

const data = await response.json();

// Store order in your database
await saveOrder({
orderId: data.data.order.orderId,
externalOrderId: data.data.order.externalOrderId,
amount,
status: 'pending',
});

// Return payment URL to frontend
res.json({ paymentUrl: data.data.paymentPageUrl });
});

// Webhook handler
app.post('/webhooks/uplef', async (req, res) => {
const { event, data } = req.body;

if (event === 'payment.success') {
await updateOrderStatus(data.orderId, 'paid');
await fulfillOrder(data.orderId);
}

res.status(200).send('OK');
});

// Success page
app.get('/payment/success', (req, res) => {
res.send('Payment successful! Thank you for your order.');
});

// Failure page
app.get('/payment/failure', (req, res) => {
res.send('Payment failed. Please try again.');
});

app.listen(3000);

Next Steps​