Testing Your Integration
Test your Uplef integration before going live.
Test Environment
Uplef provides a sandbox environment for testing:
| Environment | API Base URL | Key Prefix |
|---|---|---|
| Sandbox | https://sandbox.api.uplef.com/api/v1 | pk_test_, sk_test_ |
| Production | https://api.uplef.com/api/v1 | pk_live_, sk_live_ |
Always use test keys during development. Test transactions are free and don't process real payments.
Getting Test Credentials
- Log in to Uplef Dashboard
- Toggle to Test Mode (switch in the top-right corner)
- Go to Settings → API Keys
- Generate test API keys
Test Payment Methods
Test Card Numbers
| Card Number | Description |
|---|---|
4111 1111 1111 1111 | Successful payment |
4000 0000 0000 0002 | Card declined |
4000 0000 0000 9995 | Insufficient funds |
4000 0000 0000 0069 | Expired card |
Use any future expiry date and any 3-digit CVV.
Integration Checklist
Order Creation
- Can create orders with minimum fields (amount only)
- Can create orders with all optional fields
- Handles validation errors correctly
- Stores order ID for later reference
- Redirects customer to payment page
Payment Flow
- Payment page loads correctly
- Customer can select payment method
- Successful payments redirect to
successUrl - Failed payments redirect to
failureUrl - Order status updates correctly
Webhooks
- Webhook endpoint is accessible
- Signature verification works
- Handles
payment.successevent - Handles
payment.failedevent - Returns 200 response quickly
- Idempotency handling works
Error Handling
- Handles authentication errors (401)
- Handles validation errors (400)
- Handles not found errors (404)
- Handles rate limits (429)
- Shows user-friendly error messages
Testing Webhooks Locally
Using ngrok
ngrok exposes your local server to the internet:
# Start your local server
npm start
# In another terminal, start ngrok
ngrok http 3000
Copy the ngrok URL (e.g., https://abc123.ngrok.io) and add it as your webhook URL in the dashboard.
Using the Dashboard
- Go to Settings → Webhooks
- Enter your ngrok/tunnel URL
- Click Test to send a test webhook
Simulating Events
Create test orders and complete payments to trigger real webhook events:
// Create a test order
const order = await createOrder({
amount: 100.00,
currency: 'USD',
});
// Complete payment on the payment page
// Webhook will be triggered automatically
Automated Testing
Unit Tests
Test your API integration logic:
// Jest example
describe('Uplef Integration', () => {
test('creates order with valid data', async () => {
const order = await createOrder({
amount: 100.00,
currency: 'USD',
});
expect(order.success).toBe(true);
expect(order.data.order.orderId).toBeDefined();
expect(order.data.paymentPageUrl).toBeDefined();
});
test('handles validation error', async () => {
await expect(createOrder({ amount: -100 }))
.rejects.toThrow('Amount must be a positive number');
});
test('handles missing credentials', async () => {
const originalKey = process.env.UPLEF_API_KEY;
delete process.env.UPLEF_API_KEY;
await expect(createOrder({ amount: 100.00 }))
.rejects.toThrow('Invalid API credentials');
process.env.UPLEF_API_KEY = originalKey;
});
});
Webhook Handler Tests
describe('Webhook Handler', () => {
test('verifies valid signature', () => {
const payload = { event: 'payment.success', data: {} };
const secret = 'test_secret';
const signature = generateSignature(payload, secret);
expect(verifySignature(payload, signature, secret)).toBe(true);
});
test('rejects invalid signature', () => {
const payload = { event: 'payment.success', data: {} };
const signature = 'invalid_signature';
expect(verifySignature(payload, signature, 'secret')).toBe(false);
});
test('handles payment.success event', async () => {
const req = mockRequest({
body: {
event: 'payment.success',
data: { orderId: 'ORD_123' },
},
headers: { 'x-uplef-signature': validSignature },
});
const res = mockResponse();
await webhookHandler(req, res);
expect(res.status).toHaveBeenCalledWith(200);
expect(updateOrderStatus).toHaveBeenCalledWith('ORD_123', 'paid');
});
});
Integration Tests
Test the full payment flow:
describe('Full Payment Flow', () => {
test('complete payment flow', async () => {
// 1. Create order
const order = await createOrder({
amount: 100.00,
customer: { email: 'test@example.com' },
successUrl: 'https://example.com/success',
});
expect(order.success).toBe(true);
// 2. Simulate webhook (in real tests, complete payment on payment page)
await simulateWebhook('payment.success', {
orderId: order.data.order.orderId,
});
// 3. Verify order status updated
const updatedOrder = await getOrder(order.data.order.orderId);
expect(updatedOrder.data.status).toBe('success');
});
});
Load Testing
Before going live, test your integration under load:
// Using k6
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10, // 10 virtual users
duration: '30s',
};
export default function () {
const res = http.post(
'https://sandbox.api.uplef.com/api/v1/orders',
JSON.stringify({ amount: 100.00 }),
{
headers: {
'X-API-Key': __ENV.API_KEY,
'X-API-Secret': __ENV.API_SECRET,
'Content-Type': 'application/json',
},
}
);
check(res, {
'status is 201': (r) => r.status === 201,
'response time < 500ms': (r) => r.timings.duration < 500,
});
sleep(1);
}
Going Live Checklist
Before switching to production:
- All tests pass with test credentials
- Webhook endpoint is production-ready (HTTPS, reliable hosting)
- Error handling and logging in place
- Monitoring and alerting configured
- Production API keys generated
- Environment variables set for production
- KYC verification completed
- Bank account added for settlements
- Team tested the full payment flow
Common Testing Mistakes
1. Using Live Keys in Development
Always use test keys during development to avoid accidental charges.
2. Not Testing Error Cases
Test all error scenarios:
- Invalid card numbers
- Insufficient funds
- Network timeouts
- Rate limits
3. Not Testing Webhooks
Webhooks are critical for payment confirmation. Test thoroughly:
- Valid signatures
- Invalid signatures
- Duplicate events
- Out-of-order events
4. Not Testing Idempotency
Create orders with the same externalOrderId to ensure idempotency works correctly.
5. Hardcoding Test Data
Use environment variables for all configuration:
// Bad
const API_KEY = 'pk_test_abc123';
// Good
const API_KEY = process.env.UPLEF_API_KEY;