# Electricity API Documentation

The Electricity API lets you sell prepaid electricity through your app. You can check a South African meter before purchase and look up the same order to retrieve the token once the municipality provides it. The SIMcloud minimum order is R11.

## Base URL

```text
https://simcloud.co.za/api/electricity.php
```

## Authentication

All API requests require authentication using a Bearer token in the Authorization header:

```http
Authorization: Bearer YOUR_API_TOKEN
```

See the [API conventions](https://simcloud.co.za/api/index.html#conventions) for IPv4, request timeouts, and retries.

## How It Works

1.  Optionally check a meter number with `GET` before placing an order.
2.  Submit a purchase request with `POST`.
3.  SIMcloud submits the request to the municipality and stores the order locally.
4.  Poll the same endpoint with `GET` until the order status changes from `pending` to a final status.
5.  When the order completes successfully, the response includes the voucher PIN details.

## Endpoints

### 1. Check Meter Support

Validate a prepaid electricity meter number before placing an order.

GET

#### Query Parameters

| Parameter | Type | Required | Description |
|----|----|----|----|
| meter_number | string | Yes | Meter number to validate. Spaces and hyphens are removed before checking. |

Meter check query parameters

#### Example Request

```bash
curl -4 -sS -i 'https://simcloud.co.za/api/electricity.php?meter_number=01234567890' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN"
```

#### Supported Meter Response

```json
{
    "status": "success",
    "message": "We support this meter.",
    "meter_number": "01234567890",
    "supported": true,
    "provider": "City of Ekurhuleni IMMS"
}
```

#### Unsupported Meter Response

```json
{
    "status": "unsupported",
    "message": "This meter is not supported.",
    "meter_number": "01234567890",
    "supported": false,
    "provider": null
}
```

#### Meter Validation Unavailable

A temporary validation problem does not mean that the meter is unsupported.

```json
{
    "status": "unknown",
    "message": "The municipality could not confirm this meter right now. Please try again later.",
    "meter_number": "01234567890",
    "supported": null,
    "provider": null
}
```

### 2. Place Electricity Order

Create a new prepaid electricity purchase request.

POST **Content-Type:** application/json

#### Request Parameters

| Parameter | Type | Required | Description |
|----|----|----|----|
| meter_number | string | Yes | Meter number to recharge. |
| amount | integer | Yes | Total customer amount in whole rand (no cents). Must be between R11 and R1000. Fractional amounts are rejected, not rounded. |
| client_reference | string | Yes | Your unique reference for one intended purchase. SIMcloud appends a timestamp and unique suffix for the electricity purchase. Repeat the same reference and purchase details to retrieve the original result without buying again. Reusing it with different details returns 409; use a new reference for a new purchase. |
| recipient | string | Yes | South African mobile number that should receive the PIN SMS. |
| send_sms | boolean | No | Set to `false` to prevent the SIMcloud completion SMS from being sent for this order. Defaults to `true`. |
| sms_company_name | string | No | Optional custom company name to use in the SIMcloud completion SMS. |

Place electricity order request fields

The API also accepts the existing field names `deviceId`, `electricity_order_reference` and `smsRecipientMsisdn` for compatibility.

These SMS options apply only to the SIMcloud Electricity API and only affect the SIMcloud completion SMS sent after a successful order.

#### Example Request

```bash
curl -4 -sS -i -X POST 'https://simcloud.co.za/api/electricity.php' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{
    "meter_number": "01234567890",
    "amount": 150,
    "client_reference": "INV-10045",
    "recipient": "0821234567",
    "send_sms": true,
    "sms_company_name": "acme power"
}'
```

Orders from R11 through R55 have a fixed R1 service fee. Above R55, the fee is amount × 3 / 103, capped at R10 and rounded down to whole rand. The amount sent for electricity is the customer amount minus the fee. A R11 order sends R10 for electricity. Individual meters may have higher limits.

#### Example Request With SMS Disabled

```bash
curl -4 -sS -i -X POST 'https://simcloud.co.za/api/electricity.php' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{
    "meter_number": "01234567890",
    "amount": 150,
    "client_reference": "INV-10046",
    "recipient": "0821234567",
    "send_sms": false
}'
```

#### Success Response

```json
{
    "status": "success",
    "message": "Electricity order accepted",
    "order_id": 415,
    "client_reference": "INV-10045_1763270400_0123456789ab",
    "submitted_reference": "INV-10045",
    "order_reference_id": 987654321,
    "meter_number": "01234567890",
    "recipient": "27821234567",
    "send_sms": true,
    "sms_company_name": "acme power",
    "amount": 150,
    "electricity_amount": 146,
    "fee": 4,
    "process_status": "Pending",
    "billing_status": "pending",
    "timestamp": "2026-04-16 14:30:00"
}
```

#### Insufficient Balance Response

```json
{
    "status": "error",
    "message": "Insufficient balance. Please top up your account.",
    "required_balance": 150,
    "available_balance": 120
}
```

### 3. Query Electricity Order

Poll an existing electricity order by internal order ID, SIMcloud client reference, or municipality order reference.

GET

#### Query Parameters

| Parameter | Type | Required | Description |
|----|----|----|----|
| order_id | integer | No | SIMcloud electricity order ID returned by the POST request. |
| client_reference | string | No | The client reference returned by POST or the original submitted reference. |
| order_reference_id | integer | No | Municipality order reference returned by the POST request. |

Check electricity order query parameters

At least one of the three query parameters is required.

Only orders that belong to the authenticated account can be queried.

#### Example Request

```bash
curl -4 -sS -i 'https://simcloud.co.za/api/electricity.php?order_id=415' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN"
```

#### Pending Response

```json
{
    "status": "pending",
    "message": "Voucher details are not available yet. Please allow a few moments for the Municipality to provide the voucher details"
}
```

#### Successful Response

```json
{
    "status": "success",
    "order_id": 415,
    "message": "This electricity order has been processed successfully.",
    "transaction_details": {
        "reference": "987654321",
        "amount": "R146.00",
        "recipient": "27821234567",
        "meter_number": "01234567890",
        "network": "Electricity",
        "date": "2026-04-16 14:31:00",
        "utility": "Example Municipality"
    },
    "entry_instructions": "Enter the PINs in the order shown.",
    "recharge_pin_information": [
        {
            "entry_order": 1,
            "description": "PURCHASE",
            "pin": "0000 0000 0000 0000 0000",
            "units": "13.70"
        }
    ]
}
```

## Electricity amount rejections

When the electricity amount is rejected, POST returns HTTP 400 with `code: supplier_amount_rejected`. If the rejection arrives after the order was accepted, GET returns HTTP 200 with `status: failed` and the same code. SIMcloud only includes `minimum_electricity_amount` or `maximum_electricity_amount` when reported in the rejection. These values are rand amounts for electricity, before adding the SIMcloud fee.

Use the original client reference to retrieve the recorded result. An order that fails for this reason is not billed. SIMcloud does not change the amount or submit a new purchase automatically.

## Uncertain purchase outcomes

If a purchase cannot be confirmed with the municipality, SIMcloud immediately checks its status using the original reference. If the outcome is still unknown, POST returns HTTP 202 with `status: pending`, `code: reconciliation_pending` and `client_reference`. This is not a confirmed failure. Do not submit another purchase with a new reference. Poll GET using the returned client reference or your original reference; the existing electricity worker continues enquiries.

A repeated POST with the same reference and details returns the original acceptance/rejection or pending state. No new purchase is sent. HTTP 409/code `request_in_progress` means another request is currently handling that reference.

## PIN entry order

Successful GET responses include `entry_order` on each item in `recharge_pin_information`, sorted by required entry order, and `entry_instructions`. When key-change PINs are present, customers must enter KEY-CHANGE-1, then KEY-CHANGE-2, then purchase/free-unit PINs. SMS and voucher pages show all supplied PINs in this order.

## Statuses

- `pending`: SIMcloud is still confirming the purchase or waiting for usable voucher PINs. Continue polling the existing order, even if the municipality has marked it complete.
- `success`: Order completed successfully and voucher details are available.
- `failed`: The municipality returned a failed status.
- `cancelled`: The municipality returned a cancelled status.

## Error Responses

Most errors return `status: error` and `message`. Balance prechecks also return `required_balance` and `available_balance`. Reconciliation and conflict responses can also include a machine-readable `code`.

| HTTP Status | Description |
|----|----|
| 202 | Purchase outcome is being reconciled (`reconciliation_pending`). Poll by the original or returned client reference. |
| 400 | Missing or invalid parameters, insufficient balance, or a confirmed purchase rejection. |
| 401 | Unauthorized (invalid or missing token) |
| 404 | Order not found |
| 409 | Duplicate/pending meter transaction (`code: duplicate_transaction`), conflicting reference (`reference_conflict`) or concurrent request (`request_in_progress`). Check the existing order. `retry_after_seconds: 300` is included only when the five-minute duplicate rule applies; it does not confirm the earlier order's outcome. |
| 502 | Municipality request failed |
| 503 | Electricity service temporarily unavailable |
| 405 | Method not allowed. |
| 500 | Unexpected error. For a purchase, query the original reference before attempting another. |

Electricity error responses
