Sabong API v1.0

Credit Balance API

Overview

The Credit Balance API adds funds to a user's wallet. This endpoint creates a credit transaction and updates the wallet balance atomically. Use this endpoint to deposit funds, award bonuses, or process refunds to user accounts.

Endpoint

MethodEndpointAuthentication
POST/api/v1/credit-balanceSignature Required

Authentication

This endpoint requires Signature-based Authentication. You must include the following headers:

HeaderDescription
x-signatureHMAC-SHA256 signature of the request
x-timestampUnix timestamp (seconds) when the request was generated

Note: See Overview for detailed information on how signature authentication works and how to generate signatures.

Request Body

FieldTypeRequiredDefaultValidation
clientIdstringYes-Min 1 character
amountnumberYes-Min: 0.01
descriptionstringNo-Max 500 characters
referencestringNo-Max 255 characters, external reference ID

Request Example

{
  "clientId": "CLIENT_001",
  "amount": 100.50,
  "description": "Deposit via bank transfer",
  "reference": "BANK_TXN_123456"
}

Response

Success Response (200 OK)

{
  "status": "success",
  "message": "Balance credited successfully",
  "data": {
    "userId": 123,
    "clientId": "CLIENT_001",
    "amount": 100.50,
    "type": "credit",
    "transactionId": 456,
    "balance": 1600.50
  }
}

Response Fields

FieldTypeDescription
statusstringAlways "success" for successful requests
messagestringHuman-readable success message
data.userIdintegerInternal user ID
data.clientIdstringClient identifier
data.amountnumberAmount that was credited
data.typestringTransaction type: "credit"
data.transactionIdintegerUnique transaction ID for this credit operation
data.balancenumber | nullNew wallet balance after credit, or null if unavailable

Error Responses

Validation Error (400 Bad Request)

{
  "status": "failed",
  "message": "Validation failed",
  "data": {
    "errors": {
      "clientId": ["The clientId field is required."],
      "amount": ["The amount field is required.", "The amount must be at least 0.01."]
    }
  }
}

User Not Found (404 Not Found)

{
  "status": "failed",
  "message": "User not found",
  "data": null
}

Authentication Error (401 Unauthorized)

{
  "status": "error",
  "message": "Invalid signature",
  "data": null
}

Server Error (500 Internal Server Error)

{
  "status": "failed",
  "message": "Failed to credit balance",
  "data": {
    "error": "Database connection failed"
  }
}

Usage Example

cURL

curl -X POST https://wdcf.xerve.online/api/v1/credit-balance \
  -H "Content-Type: application/json" \
  -H "x-signature: YOUR_SIGNATURE" \
  -H "x-timestamp: 1706802000" \
  -d '{
    "clientId": "CLIENT_001",
    "amount": 100.50,
    "description": "Deposit via bank transfer",
    "reference": "BANK_TXN_123456"
  }'

Note: To generate the signature, refer to the Overview documentation.

JavaScript/TypeScript (with Axios)

import axios from 'axios';
// Import your signature generation function (see Overview)
import { generateSignature } from './signature-utils';

const API_BASE_URL = 'https://wdcf.xerve.online';
const CLIENT_SECRET = 'your-secret-key';

interface CreditBalanceData {
  clientId: string;
  amount: number;
  description?: string;
  reference?: string;
}

async function creditBalance(data: CreditBalanceData) {
  const timestamp = Math.floor(Date.now() / 1000);

  // Generate signature (see Overview for implementation)
  const signature = generateSignature({
    method: 'POST',
    path: '/api/v1/credit-balance',
    payload: data,
    secret: CLIENT_SECRET,
    timestamp
  });

  try {
    const response = await axios.post(
      `${API_BASE_URL}/api/v1/credit-balance`,
      data,
      {
        headers: {
          'Content-Type': 'application/json',
          'x-signature': signature,
          'x-timestamp': timestamp.toString()
        }
      }
    );

    console.log('Credited amount:', response.data.data.amount);
    console.log('New balance:', response.data.data.balance);
    console.log('Transaction ID:', response.data.data.transactionId);
    return response.data;
  } catch (error: any) {
    console.error('Error:', error.response?.data || error.message);
    throw error;
  }
}

// Usage
creditBalance({
  clientId: 'CLIENT_001',
  amount: 100.50,
  description: 'Deposit via bank transfer',
  reference: 'BANK_TXN_123456'
});

Python

import requests
# Import your signature generation function (see Overview)
from signature_utils import generate_signature
import time

API_BASE_URL = 'https://wdcf.xerve.online'
CLIENT_SECRET = 'your-secret-key'

def credit_balance(client_id: str, amount: float, description: str = None, reference: str = None):
    timestamp = int(time.time())
    payload = {
        "clientId": client_id,
        "amount": amount
    }
    
    if description:
        payload["description"] = description
    if reference:
        payload["reference"] = reference

    # Generate signature (see Overview for implementation)
    signature = generate_signature(
        method="POST",
        path="/api/v1/credit-balance",
        payload=payload,
        secret=CLIENT_SECRET,
        timestamp=timestamp
    )

    headers = {
        "Content-Type": "application/json",
        "x-signature": signature,
        "x-timestamp": str(timestamp)
    }

    response = requests.post(
        f"{API_BASE_URL}/api/v1/credit-balance",
        json=payload,
        headers=headers
    )

    response.raise_for_status()
    data = response.json()
    print(f"Credited amount: {data['data']['amount']}")
    print(f"New balance: {data['data']['balance']}")
    print(f"Transaction ID: {data['data']['transactionId']}")
    return data

# Usage
if __name__ == "__main__":
    credit_balance(
        client_id="CLIENT_001",
        amount=100.50,
        description="Deposit via bank transfer",
        reference="BANK_TXN_123456"
    )

Important Notes

  1. Atomic Operation: The credit operation is atomic - either both the transaction record and balance update succeed, or both fail. This ensures data consistency.
  2. Idempotency: The reference field can be used to track external transaction IDs. If you need strict idempotency, implement checks on your side before calling this endpoint.
  3. Minimum Amount: The minimum credit amount is 0.01. Requests with smaller amounts will be rejected.
  4. Currency: All amounts are in the default currency (USD). Currency conversion is not handled by this endpoint.
  5. Transaction Record: Each credit operation creates a transaction record that can be retrieved using the Get Transactions API.
  6. Negative Amounts: Do not send negative amounts to this endpoint. Use the Debit Balance API for deductions.

Common Use Cases

  • User Deposits: Credit user wallet when they make a deposit
  • Promotional Bonuses: Award bonus credits to users
  • Refund Processing: Return funds to user wallets
  • Correction Adjustments: Fix balance discrepancies

Error Handling

Error CodePossible CausesResolution
400Missing/invalid fields, amount < 0.01Check validation errors and ensure amount meets minimum
401Invalid signature or expired timestampVerify signature generation and ensure timestamp is current
404User not foundVerify clientId exists; may need to create user first
500Database or transaction service failureCheck server logs and retry; transaction may have failed