e Ecovoy Developers
ecovoy.com Log in

Code examples

A complete sandbox integration: get a token, look up a number, optionally select another operator, create the order, confirm it and follow the result.

These examples use sandbox credentials. Run them on your server — never in a browser or mobile app, where the client_secret would be exposed.

  1. /mobile-recharge/lookup — automatic identification of the operator.
  2. /mobile-recharge/operator-switch — only if the customer chooses another operator.
  3. /mobile-recharge/orders — creates the order with your external_ref_id (one per transaction) and a new Idempotency-Key. Does not execute the recharge.
  4. Store the transaction_id returned by Ecovoy next to your external_ref_id.
  5. /mobile-recharge/confirm — executes the recharge. (Or /cancel-transaction to give up, only before confirming.)
  6. GET /transactions/{transaction_id} — until the status is final.
#!/usr/bin/env bash
# Complete sandbox flow: token -> lookup -> (operator-switch) -> order -> confirm -> status.
# Requires jq and uuidgen. A number ending in 1111 creates a PENDING order in the sandbox.
set -euo pipefail
BASE=https://api.ecovoy.com/api/v2
MOBILE="+50944101111"

TOKEN=$(curl -s -X POST "$BASE/oauth/token" \
  -d grant_type=client_credentials \
  -d client_id="$ECOVOY_CLIENT_ID" \
  -d client_secret="$ECOVOY_CLIENT_SECRET" | jq -r .access_token)

# 1. Automatic identification
curl -s -X POST "$BASE/mobile-recharge/lookup" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d "{\"mobile_number\": \"$MOBILE\"}" | jq '.data.operators, .data.products'

# 2. (Optional) the customer chose another operator: use the products of THAT operator
PRODUCT=$(curl -s -X POST "$BASE/mobile-recharge/operator-switch" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d "{\"mobile_number\": \"$MOBILE\", \"operator_id\": \"sbx-ht-002\", \"country_iso_code\": \"HTI\"}" \
  | jq -r '.data.products[0].id')

# 3. Create the order with the reference of this sale in YOUR system (one per transaction).
#    Keep the key: on a network error, retry with the SAME key and body.
REF="ORDER-2026-000123"
KEY=$(uuidgen)
ORDER=$(curl -s -X POST "$BASE/mobile-recharge/orders" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $KEY" \
  -d "{\"mobile_number\": \"$MOBILE\", \"product_id\": \"$PRODUCT\", \"external_ref_id\": \"$REF\", \"external_customer_id\": \"CUSTOMER-001\"}")

# 4. Store the transaction_id generated by Ecovoy next to your external_ref_id
TX=$(echo "$ORDER" | jq -r .data.transaction_id)
echo "$ORDER" | jq '.data | {transaction_id, external_ref_id, status}'   # status: PENDING

# 5. Execute the recharge
curl -s -X POST "$BASE/mobile-recharge/confirm" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d "{\"transaction_id\": \"$TX\"}" | jq '.data.status'

# 6. Follow the result
curl -s "$BASE/transactions/$TX" -H "Authorization: Bearer $TOKEN" | jq .data.status

Testing different results

In the sandbox, the end of the mobile number decides the order result:

In Production every order starts as PENDING and must be confirmed within 15 minutes. See POST /mobile-recharge/orders.

Retries

Next steps