AWS Builder Center

What SIMcloud does when a prepaid electricity purchase times out

A prepaid electricity request times out. Did it fail, or is the token already on its way? Here’s how SIMcloud handles uncertain purchases, and how to design the same recovery workflow with AWS Step Functions.

PHP Developer & Technical Consultant
Imagine someone buying prepaid electricity. Your app sends the purchase request. Then the connection times out. The customer is still waiting for a token, and you have a decision to make. Do you send the request again?
The municipality may already have processed it. If you submit a second purchase under a new reference, the customer could end up paying twice. If you show “failed,” they may try again themselves. If you show “success,” they’ll expect a token you don’t have.
I build SIMcloud, a South African platform businesses use to manage airtime, data, SMS, and prepaid electricity. Of those services, electricity is a good example of what makes an integration hard. The API call can be over while the work it started is still going. Your application needs a way to find out what happened and explain it to the customer.  SIMcloud API documentation 

Give the purchase a reference before you send it

Start by saving the purchase intent in your own system. Give it a stable reference and store the details that define it, such as the meter, amount, and intended recipient. If the API returns its own identifiers, save those against the same local order.
In SIMcloud’s electricity API, we save a recovery record before submitting the purchase. If we can’t confirm the outcome, we query the municipality using the original reference. A reference also belongs to one set of purchase details. Reusing it with a different amount or meter is a conflict, because the two requests represent different purchases.  SIMcloud electricity API 
That distinction makes it easier to design for double clicks, worker restarts, and people coming back to a checkout after a timeout. Two attempts to complete the same purchase should lead back to one order. A customer deliberately making a second purchase needs a new reference. The caller is in the best position to tell those two intentions apart.  Amazon Builders’ Library on idempotent APIs 

Tell the customer what you actually know

An electricity order raises several separate questions. Has the purchase been accepted? Is a usable token available? What does the billing record show? Support needs all three answers. The customer usually wants to know when they can enter the token.
Here’s how I’d translate those states into a customer screen and an operational action:
What you know
What the customer sees
What the application does
The purchase request timed out and the outcome is unknown
“We’re checking your purchase.”
Look up the original reference.
The order is known, but the token is still unavailable
“Your token is still being processed.”
Keep checking the existing order.
A usable token is available
Show the token and any entry instructions.
Record fulfilment and reconcile billing separately.
The purchase is confirmed to have failed
Explain the failure and the next step.
Resolve the original order before offering a new purchase.
SIMcloud can return HTTP  202  with  reconciliation_pending  when it still has to establish the outcome. The next action is a status query, using the returned reference if you have it or your original reference if you never got a response. The electricity API can also return  pending  while voucher details are unavailable. Both cases need a path back to the existing order.  SIMcloud electricity order queries 
Give automatic polling a deadline. Once it expires, move the order to a review queue with the reference, last known status, and last check time. That gives support enough information to investigate without asking the customer to reconstruct the transaction.

How I’d build the same recovery loop with AWS Step Functions

If I were implementing this on AWS, I’d use a Step Functions Standard workflow to make the recovery path explicit:
  1. Record the purchase intent in the order store before the first submission. Pass the internal order ID through the workflow.
  1. Submit the purchase and save any identifiers returned. If submission times out, route to a status enquiry for the original reference.
  1. Check the existing order. Use a  Choice  state to route on the outcome. While the order is pending, use a  Wait  state before checking again. Back off between attempts and stop automatic polling at a defined deadline.
  1. Record the outcome. Deliver the token when it’s available, handle a confirmed failure, or send an unresolved order to review.
The part I’d test most carefully is restarting the workflow after the purchase was accepted but before the submission task recorded its response. Step Functions can rerun a failed task when you redrive an execution. The task therefore needs to read the durable order record and know when to check the existing purchase. The workflow engine can tell you a task timed out. Querying the municipality can tell you whether the token was issued.  Step Functions Standard workflows  ·  Redriving executions 

Give AI assistants permission to check before they can buy

The same distinction matters when an AI assistant is the caller. “Did this customer’s recharge go through?” is a reporting request. “Buy another recharge” spends money. An assistant investigating the first question can do its job with access to the original order’s status.
In SIMcloud’s Model Context Protocol integration, reporting and transactions use separate OAuth permissions. A reporting connection can check the wallet balance, transaction history, and existing order status. It can’t place purchases, send SMS, or retrieve electricity PINs. For workflows that do need to spend money, I’d make the recipient, product, and amount visible for confirmation before submission. If the outcome is uncertain, the assistant should bring back the status of the existing order.  SIMcloud MCP integration 

The first test I’d run

Simulate a purchase being accepted and then drop the response. Restart your worker, redrive the workflow, or click the button again. Check that there’s still one purchase, that the customer sees an honest pending status, and that support can find the order by its original reference. Then make the token available and check that the original order is fulfilled.
That test will tell you more about how your integration behaves on a bad day than a checkout that succeeds on the first try.
If you build payment, prepaid, or other systems that depend on external APIs, follow me for more field notes from SIMcloud. I’ll cover what goes into a useful reconciliation log, how to handle partial failures in bulk recharges, and how to design permissions for AI tools that can spend money.  Follow Erik Thiart on AWS Builder Center 
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article