Callbacks
Callbacks are a crucial part of TheBridge API’s asynchronous communication system. They allow our system to notify your application about the status of transactions in real-time, ensuring you’re always up-to-date with the latest information.Overview
When you initiate a transaction using our API, we process it asynchronously. This means that instead of waiting for the transaction to complete before responding, we immediately return a response acknowledging that we’ve received your request. The actual processing happens in the background. To keep you informed about the transaction’s progress, we send callbacks to a URL you specify. These callbacks are HTTP POST requests containing JSON data about the transaction status.Callback URL
When making a payment request, you should include acallback_url
parameter. This is the endpoint where we’ll send status updates about the transaction. For example:
Callback Data Structure
Here’s an example of the callback data you’ll receive:trans_ref
This is the transaction_id you provided when initiating the transaction on make_payment endpoint. It helps you match the callback to the original transaction in your system.trans_id
This is a unique identifier for the transaction in our system. You can use this ID when querying our API for more details about the transaction.trans_status
This field provides a detailed status code. It consists of a numeric code followed by a short description. The first three characters of this field indicate the transaction status:- “000”: The transaction was successful.
- “001”: The transaction is still being processed.
- “002”: The transaction failed.
- Extract the first three characters of the
trans_status
field. - Use this numeric code to determine the transaction status.
- The text after the slash provides additional human-readable information.
message
This field provides a human-readable description of the transaction status. Common values include:- “SUCCESSFUL”: The transaction was completed successfully.
- “FAILED”: The transaction failed to process.
- “PENDING”: The transaction is still being processed.
customer_number
The phone number of the customer who made the payment. This is in the international format without the ’+’ sign (e.g., “233XXXXXXXXX” for a Ghanaian number).nw
The network provider used for the transaction. For example:- “MTN” for MTN Mobile Money
- “TEL” for Telecel Cash
- “AIR” for AirtelTigo Money
payment_mode
The mode of payment used. For example:- “MOM” for Mobile Money
- “CRD” for Card payments
payment_option
This field typically mirrors the payment_mode, providing additional clarity on the payment method used.Handling Callbacks
When you receive a callback, you should:- Verify the callback’s authenticity (see Security Considerations below).
- Update your local records with the new transaction status.
- Trigger any necessary actions in your system (e.g., fulfilling an order if the payment was successful).
- Respond to the callback with a 200 OK status to acknowledge receipt.
Security Considerations
To ensure the security of your system, always verify the authenticity of callbacks before processing them. Here are some measures you can implement:- IP Whitelisting: Only accept callbacks from TheBridge API’s known IP addresses.
- HTTPS: Ensure your callback URL uses HTTPS to encrypt the data in transit.
- Signature Verification: We include a digital signature with each callback. Verify this signature to ensure the callback hasn’t been tampered with.