A Django-based SDK for integrating with the Mobiska Payment Gateway
Project description
Mobiska Payment Gateway SDK
A Django-based SDK for integrating with the Mobiska Payment Gateway.
Features
- Make payment requests to the Mobiska API
- Send SMS messages through the Mobiska API
- Check SMS account balance
- Track and manage payment transactions and SMS messages
- RESTful API endpoints for client applications
- Admin interface for monitoring transactions and SMS messages
Installation
- Clone the repository:
git clone https://github.com/kofnet002/mobiska-sdk.git
cd mobiska-sdk
- Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- Configure your Mobiska API credentials in
core/settings.py:
# Mobiska API Settings
MOBISKA_API_URL = 'https://mobiska-api.stimuluzdev.com'
MOBISKA_API_USERNAME = 'client_key' # Replace with actual client key
MOBISKA_API_PASSWORD = 'secret_key' # Replace with actual secret key
- Run migrations:
python manage.py migrate
- Create a superuser to access the admin interface:
python manage.py createsuperuser
- Run the development server:
python manage.py runserver
Usage
Direct SDK Usage
Payment Processing
from apps.mobiska.client import MobiskaClient
# Initialize the client
client = MobiskaClient(
username="YOUR_USERNAME", # Optional, defaults to settings.MOBISKA_API_USERNAME
password="YOUR_PASSWORD", # Optional, defaults to settings.MOBISKA_API_PASSWORD
)
# Make a payment request
response = client.make_payment(
service_id=2,
reference="Payment for Product XYZ",
nickname="MyStore",
transaction_id="unique-transaction-id-123",
customer_number="0541840988",
network="MTN", # MTN, VOD, AIR, VIS, MAS
amount=100.00,
payment_option="MOM", # MOM, CRD, CRM
callback_url="https://mywebsite.com/payment-callback",
currency_code="GHS"
)
# Handle the response
if response["response_code"] == "202":
print("Payment request successful:", response["response_message"])
else:
print("Payment request failed:", response["response_message"])
SMS Messaging
from apps.mobiska.client import MobiskaClient
# Initialize the client
client = MobiskaClient()
# Send an SMS message
response = client.send_sms(
service_id=2,
unique_id="unique-sms-id-123",
sender_id="MYCOMPANY",
msg_body="Your verification code is 123456",
recipient_number=["233541234567", "233241234567"]
)
# Handle the response
if response["response_code"] == "000":
print("SMS sent successfully:", response["response_message"])
print("Message ID:", response["response_data"]["message_id"])
else:
print("SMS sending failed:", response["response_message"])
# Check SMS account balance
balance_response = client.check_sms_account_balance(service_id=2)
if balance_response["response_code"] == "000":
print(f"Account balance: {balance_response['response_data']['balance']} {balance_response['response_data']['currency']}")
else:
print("Failed to retrieve balance:", balance_response["response_message"])
API Usage
Payment API
Make a POST request to /api/payment/make/ with the following payload:
{
"service_id": 2,
"reference": "Payment for Product XYZ",
"nickname": "MyStore",
"transaction_id": "unique-transaction-id-123",
"trans_type": "CTM",
"customer_number": "0541840988",
"nw": "MTN",
"amount": 100.00,
"payment_option": "MOM",
"callback_url": "https://mywebsite.com/payment-callback",
"currency_code": "GHS",
"currency_val": 1,
"request_time": "2025-07-25T02:30:00Z"
}
Authentication
The API uses token authentication. To obtain a token:
curl -X POST http://localhost:8000/api-token-auth/ -d "client_key=yourclientkey&secret_key=yoursecretkey"
Then include the token in your API requests:
curl -X POST http://localhost:8000/api/payment/make/ \
-H "Authorization: Token YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"service_id": 2, ...}'
SMS API
Sending SMS
Make a POST request to /api/v1/sms/send/ with the following payload:
{
"service_id": 2,
"unique_id": "unique-sms-id-123",
"sender_id": "MYCOMPANY",
"msg_body": "Your verification code is 123456",
"recipient_number": ["233541234567", "233241234567"]
}
Example using curl:
curl -X POST http://localhost:8000/api/v1/sms/send/ \
-H "Authorization: Token YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"service_id": 2, "unique_id": "unique-sms-id-123", "sender_id": "MYCOMPANY", "msg_body": "Your verification code is 123456", "recipient_number": ["233541234567", "233241234567"]}'
Checking SMS Account Balance
Make a GET request to /api/v1/sms/balance/ to check your SMS account balance.
curl -X GET http://localhost:8000/api/v1/sms/balance/ \
-H "Authorization: Token YOUR_TOKEN"
Admin Interface
Access the admin interface at http://localhost:8000/admin/ to view and manage payment transactions and SMS messages.
Payment Transactions
The admin interface allows you to monitor all payment transactions, including their status, response codes, and other details.
SMS Messages
The SMS Messages section in the admin interface provides tracking and monitoring of all SMS messages sent through the Mobiska API. You can view:
- Message content and recipients
- Delivery status and response codes
- Timestamps for message creation and sending
- Full API response data
Network Providers
- MTN: MTN Mobile Money
- VOD: Vodafone Cash
- AIR: AirtelTigo Money
- VIS: Visa Card
- MAS: Mastercard
Payment Options
- MOM: Mobile Money
- CRD: Bank Cards
- CRM: Hosted Checkout (Mobile Money and Cards)
API Credentials
To generate your API credentials, follow these steps:
- Combine your client key and secret key:
{client_key}:{secret_key} - Base64 encode the combined string
- Create the Authorization header:
Authorization: Basic {base64_encoded_string}
Example:
echo -n "mob_client_123:sk_live_abcdef123456" | base64
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mobiska-sdk-0.1.0.tar.gz.
File metadata
- Download URL: mobiska-sdk-0.1.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a21f3069fd4f58a1e0a582686958bb7e89964f55dff9508f30bd066efc3d796
|
|
| MD5 |
6e3f7df4f07366358efd8ed25a015212
|
|
| BLAKE2b-256 |
9f453cde9448fd03d79a07fce313cf9bddb96a442afe3d6482c64bd8eb398fd5
|
File details
Details for the file mobiska_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mobiska_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0deee57df26fa90f49a9419f28de5bfaad392599a0062cda09c59368ae98503e
|
|
| MD5 |
a090486ca8d3b3aa02952a4302f66343
|
|
| BLAKE2b-256 |
b76be1b5ee6c211f5a696be251598223c01c0ebd56a3ad68ef3fd07b8f59b04d
|