Buy SMS
This end points allows users to Buy SMS for their Accounts.
Overview
This API allows users to purchase SMS bundles to top up their SMS wallet. The value of the SMS bundle purchased will be stored, and the system will calculate the number of SMS messages based on the cost per SMS. The SMS purchase can be done either from the App Level or directly through Tuku Pay.
1. Buy SMS (Top Up SMS Wallet)
Method:
POST
URL:
/api/sms-wallet/topup
Request Body:
Request Body Fields:
Field
Type
Required
Description
userId
string
Yes
The user who is purchasing SMS bundles.
purchaseAmount
number
Yes
The amount in KES spent on purchasing the SMS bundle.
paymentMethod
string
Yes
The payment method used (e.g., mpesa
, visa
, paypal
, etc.).
paymentReference
string
Yes
The reference or transaction ID from the payment provider.
appId
string
Optional
The app ID if the purchase is done through an app.
paymentStatus
string
Yes
The status of the payment (e.g., success
, failure
).
transactionId
string
Yes
The unique transaction ID for the top-up.
topupDate
datetime
Yes
The date and time the top-up was completed.
Response:
Response Fields:
Field
Type
Description
status
string
The status of the top-up transaction (success
, failure
).
smsAdded
number
The number of SMS added to the wallet after purchase.
newSmsBalance
number
The new SMS balance after the top-up.
userId
string
The user who made the purchase.
purchaseAmount
number
The amount spent on SMS purchase (KES).
unitCost
number
The cost per SMS at the time of purchase (KES).
message
string
A success or failure message describing the top-up process.
2. Check SMS Balance
Method:
GET
URL:
/api/sms-wallet/balance
Query Parameters:
Field
Type
Required
Description
userId
string
Yes
The user whose SMS balance is being checked.
Response Example:
Response Fields:
Field
Type
Description
userId
string
The user whose SMS balance is being checked.
smsBalance
number
The current SMS balance in the user's SMS wallet.
unitCost
number
The cost per SMS at the time of the balance check.
lastUpdated
datetime
The last time the SMS balance was updated.
3. Set SMS Alert Threshold
Method:
POST
URL:
/api/sms-wallet/set-threshold
Request Body:
Request Body Fields:
Field
Type
Required
Description
userId
string
Yes
The user setting the SMS threshold alert.
thresholdAmount
number
Yes
The SMS balance threshold that triggers the alert (e.g., 5000 SMS remaining).
alertType
string
Yes
Type of alert: sms
, email
, or both.
notificationMethod
string
Yes
The method used to notify the user (sms
, email
).
alertMessage
string
Yes
The custom message to send when the threshold is reached.
createdBy
string
Yes
The user who set the threshold (typically an admin).
Response Example:
Implementation Notes
SMS Wallet Balancing: Each time a user purchases SMS, the system will calculate the number of SMS messages based on the
pricePerSms
from thesms-costs
table.Top-Up and Deductions: The
smsAdded
field indicates how many SMS credits were added to the user's SMS wallet. These credits will be deducted when an SMS is sent.Payment Methods: When buying SMS, the payment can be made via MPESA, Visa/MasterCard, PayPal, or App Checkout. These methods will update the SMS wallet once the payment is processed successfully.
Low SMS Balance Alerts: When the SMS balance falls below the specified threshold, an alert will be triggered and sent via the configured
notificationMethod
(SMS or Email).Default Costs: If no specific cost is defined for a user, the default SMS cost (
0.8 KES
) will apply