Simple python wrapper to perform and retrieve payment to moncash api with python
- Receive money from a mobile account to business account
- Query transaction status
- Transfert money
pip install moncash
import moncash
gateway = moncash.Moncash(
client_id="xxxxxxxx",
client_secret="xxxxxxxx",
environment=moncash.environment.Sandbox
)
try:
get_paid_url = gateway.payment.create(amount=250, reference=10)
except moncash.exceptions.MoncashError:
get_paid_url = None
print("Unexpected error...")
print(get_paid_url)
# TODO: redirect the user to get_paid_url
Grab transaction with the reference
try:
transaction = gateway.payment.get_by_ref(reference=10)
except moncash.exceptions.NotFoundError:
transaction = None
print("We didnt found this transaction... It is not valid")
except moncash.exceptions.MoncashError:
transaction = None
print("Unexpected error...")
Grab transaction with the transactionId
# you should handle error
try:
transaction = gateway.payment.get_by_id(transactionId=10)
except moncash.exceptions.NotFoundError:
transaction = None
print("We didnt found this transaction... It is not valid")
except moncash.exceptions.MoncashError:
transaction = None
print("Unexpected error...")
The response should be something like for the transactions querying status (whether with reference or the id):
{
"reference": "13",
"transaction_id": "2160048483",
"cost": "250",
"message": "successful",
"payer": "50936050083"
}
A good application is an application where you care about errors (Madsen Servius)
Exhaustive list of the Exceptions:
- MoncashError
- ConfigurationError
- PaymentError
- AuthenticationError
- AuthorizationError
- GatewayTimeoutError
- RequestTimeoutError
- ServerError
- ServiceUnavailableError
- TooManyRequestsError
- UnexpectedError
- UpgradeRequiredError
- NotFoundError
- ConnectionError
- InvalidResponseError
- TimeoutError
- ConnectTimeoutError
- ReadTimeoutError
To import them in you code you have to write:
from moncash.exceptions import NameOfTheExceptionCatched
Madsen Servius ([email protected])