Skip to main content

Process Topup Order

Process a top-up order for a specific eSIM with automatic profit calculation.

Endpoint

POST /api/v1/business/topup/order

Authentication

This endpoint requires HMAC authentication. See Authentication for details.

Request Headers

HeaderTypeRequiredDescription
RT-AccessCodeStringYesYour API access code
RT-RequestIDStringYesUnique request ID (UUID v4)
RT-TimestampStringYesRequest timestamp in milliseconds
RT-SignatureStringYesHMAC-SHA256 signature
Content-TypeStringYesapplication/json

Request Body

FieldTypeRequiredDescription
iccidStringYeseSIM ICCID to top up
packageCodeStringYesPackage code from topup packages endpoint
packageNameStringYesPackage display name
priceNumberYesPackage price (for validation)
quantityIntegerNoNumber of packages (default: 1)

Example Request

{
"iccid": "8943108170002570328",
"packageCode": "TOPUP_PLGJ7UB3C",
"packageName": "Iraq 1GB 7Days",
"price": 3.68,
"quantity": 1
}

Response

Success Response (200 OK)

{
"success": true,
"message": "eSIM top-up processed successfully",
"orderReference": "topup_1755559183090_vyf9w",
"iccid": "8943108170002570328",
"packageName": "Iraq 1GB 7Days",
"newBalance": 550.68,
"status": "completed",
"amount": 3.68,
"profit": 0.35,
"processing_time_ms": 3724,
"esimData": {
"newTotalVolumeGB": 8.0,
"newRemainingVolumeGB": 8.0,
"expiredTime": "February 13, 2026 at 11:27 PM"
}
}

Response Fields

FieldTypeDescription
successBooleanOperation success status
messageStringSuccess message
orderReferenceStringUnique order reference for tracking
iccidStringeSIM ICCID that was topped up
packageNameStringName of the topup package applied
newBalanceNumberYour updated account balance
statusStringOrder status (always "completed" for successful orders)
amountNumberTotal amount charged
profitNumberYour profit from this transaction
processing_time_msIntegerProcessing time in milliseconds
esimDataObjectUpdated eSIM information

eSIM Data Object

FieldTypeDescription
newTotalVolumeGBNumberNew total data capacity in GB after topup
newRemainingVolumeGBNumberNew remaining data in GB (total - used)
expiredTimeStringHuman-readable expiry date and time

Error Responses

400 Bad Request

Missing required fields:

{
"success": false,
"error": "Missing required fields",
"code": "MISSING_FIELDS"
}

eSIM not found:

{
"success": false,
"error": "eSIM not found or access denied",
"code": "ESIM_NOT_FOUND"
}

eSIM cannot be topped up:

{
"success": false,
"error": "eSIM cannot be topped up. Current status: EXPIRED",
"message": "Only ACTIVE, DEPLETED, or USED_EXPIRED eSIMs can be topped up",
"code": "ESIM_NOT_TOPPABLE"
}

Insufficient balance:

{
"success": false,
"error": "Insufficient balance",
"message": "Your current balance is $2.50. Required: $3.68",
"code": "INSUFFICIENT_BALANCE"
}

Invalid topup package:

{
"success": false,
"error": "Invalid topup package",
"code": "INVALID_TOPUP_PACKAGE"
}

Topup not supported:

{
"success": false,
"error": "Top-ups not available for this eSIM",
"code": "TOPUP_NOT_SUPPORTED"
}

401 Unauthorized

See Authentication documentation for authentication errors.

500 Internal Server Error

{
"success": false,
"error": "Failed to process topup order"
}

Examples

Basic Topup Order

const orderData = {
iccid: '8943108170002570328',
packageCode: 'TOPUP_PLGJ7UB3C',
packageName: 'Iraq 1GB 7Days',
price: 3.68,
quantity: 1
};

const response = await fetch(
'https://esimfly.net/api/v1/business/topup/order',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
...generateHMACHeaders() // Your HMAC function
},
body: JSON.stringify(orderData)
}
);

const result = await response.json();
if (result.success) {
console.log(`Topup successful! Order: ${result.orderReference}`);
console.log(`New balance: $${result.newBalance}`);
console.log(`Profit earned: $${result.profit}`);
console.log(`eSIM now has ${result.esimData.newTotalVolumeGB}GB total`);
}

Error Handling

try {
const response = await fetch(/* ... */);
const result = await response.json();

if (!result.success) {
switch (result.code) {
case 'INSUFFICIENT_BALANCE':
console.log('Need to add funds to account');
break;
case 'ESIM_NOT_TOPPABLE':
console.log('eSIM cannot be topped up in current state');
break;
case 'INVALID_TOPUP_PACKAGE':
console.log('Package not valid for this eSIM');
break;
default:
console.log('Topup failed:', result.error);
}
}
} catch (error) {
console.error('Request failed:', error);
}

Important Notes

Automatic Processing

  • Balance deduction happens automatically upon successful topup
  • Profit calculation is handled server-side using your account settings
  • eSIM data is updated in real-time

Provider Compatibility

  • Cross-provider topups are supported (e.g., topping up any eSIM with any compatible package)
  • Provider detection is automatic based on package code format
  • All provider-specific logic is handled transparently

Security & Validation

  • Package prices are validated server-side to prevent manipulation
  • Only eSIMs you own can be topped up
  • Balance checks are performed before processing
  • All transactions are logged and auditable

Best Practices

  1. Get packages first: Always call Get Topup Packages to get available options
  2. Use exact codes: Use the exact package_code returned from the packages endpoint
  3. Handle errors gracefully: Always check for insufficient balance and eSIM status errors
  4. Store order reference: Keep orderReference for customer support and tracking
  5. Monitor profit: Track your earnings using the profit field in responses

Relationship to Other Endpoints