API Docs
Python Examples
Here are some examples of how to use the MotapaPay API with Python.
Initiating a Transaction
Python
import requests
url = "https://api.motapa.africa/v1/transactions"
headers = {
"Authorization": "Bearer mp_test_26PHem9AhJZvU623DfE1x4sd",
"Content-Type": "application/json"
}
data = {
"currency": "USD",
"amount": 1000,
"email": "customer@example.com",
"mobile_money_number": "254712345678",
"payment_method_code": "mpesa",
"transaction_reference": "MOTAPAPAY1234567890"
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
print("Transaction initiated:", response.json())
else:
print("Error:", response.status_code, response.text)Listing Wallets
Python
import requests
url = "https://api.motapa.africa/v1/wallets/list"
params = {
"limit": 100
}
headers = {
"Authorization": "Bearer mp_test_26PHem9AhJZvU623DfE1x4sd",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
print("Wallet details:", response.json())
else:
print("Error:", response.status_code, response.text)Authenticating API Requests
Python
import requests
url = "https://api.motapa.africa/v1/authenticate"
headers = {
"Authorization": "Bearer undefined_test_26PHem9AhJZvU623DfE1x4sd",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
print("Authentication successful:", response.json())
else:
print("Error:", response.status_code, response.text)Creating a Wallet
Python
import requests
url = "https://api.motapa.africa/v1/wallets/create"
headers = {
"Authorization": "Bearer mp_test_26PHem9AhJZvU623DfE1x4sd",
"Content-Type": "application/json"
}
data = {
"currency": "USD",
"balance": 1000
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
print("Wallet created:", response.json())
else:
print("Error:", response.status_code, response.text)Fetching Wallet Balance
Python
import requests
url = "https://api.motapa.africa/v1/wallets/balance"
headers = {
"Authorization": "Bearer mp_test_26PHem9AhJZvU623DfE1x4sd",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
print("Wallet balance:", response.json())
else:
print("Error:", response.status_code, response.text)