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
- JavaScript
- Python
- PHP
- Ruby
- Go
- Java
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"
}'
const createOrder = async () => {
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: 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',
}),
});
const data = await response.json();
console.log(data);
return data;
};
import requests
import os
def create_order():
response = requests.post(
'https://api.uplef.com/api/v1/orders',
headers={
'X-API-Key': os.environ['UPLEF_API_KEY'],
'X-API-Secret': os.environ['UPLEF_API_SECRET'],
},
json={
'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',
},
)
return response.json()
<?php
$ch = curl_init('https://api.uplef.com/api/v1/orders');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . getenv('UPLEF_API_KEY'),
'X-API-Secret: ' . getenv('UPLEF_API_SECRET'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'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 = curl_exec($ch);
$data = json_decode($response, true);
print_r($data);
require 'net/http'
require 'json'
require 'uri'
def create_order
uri = URI('https://api.uplef.com/api/v1/orders')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['X-API-Key'] = ENV['UPLEF_API_KEY']
request['X-API-Secret'] = ENV['UPLEF_API_SECRET']
request['Content-Type'] = 'application/json'
request.body = {
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'
}.to_json
response = http.request(request)
JSON.parse(response.body)
end
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
type OrderRequest struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Customer Customer `json:"customer"`
SuccessUrl string `json:"successUrl"`
FailureUrl string `json:"failureUrl"`
}
type Customer struct {
Name string `json:"name"`
Email string `json:"email"`
Phone string `json:"phone"`
}
func createOrder() {
payload := OrderRequest{
Amount: 100.00,
Currency: "USD",
Customer: Customer{
Name: "John Doe",
Email: "john@example.com",
Phone: "+1234567890",
},
SuccessUrl: "https://yoursite.com/payment/success",
FailureUrl: "https://yoursite.com/payment/failure",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://api.uplef.com/api/v1/orders", bytes.NewBuffer(body))
req.Header.Set("X-API-Key", os.Getenv("UPLEF_API_KEY"))
req.Header.Set("X-API-Secret", os.Getenv("UPLEF_API_SECRET"))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
import java.net.http.*;
import java.net.URI;
public class CreateOrder {
public static void main(String[] args) throws Exception {
String json = """
{
"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"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.uplef.com/api/v1/orders"))
.header("X-API-Key", System.getenv("UPLEF_API_KEY"))
.header("X-API-Secret", System.getenv("UPLEF_API_SECRET"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
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:
- See available payment methods (Crypto, Card, etc.)
- Select their preferred method
- Complete the payment
- Be redirected to your
successUrlorfailureUrl
Step 3: Set Up Webhook (Recommended)
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
- API Reference - Complete API documentation
- Webhooks - Detailed webhook guide
- Error Handling - Handle errors gracefully
- Testing - Test your integration