Code Monkey home page Code Monkey logo

moncash_python's Introduction

moncash

Digicel Moncash API SDK for Python

Simple python wrapper to perform and retrieve payment to moncash api with python

Features

  • Receive money from a mobile account to business account
  • Query transaction status
  • Transfert money

Quickstart

Installation

Using pip

    pip install moncash

Receive money from a mobile account

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

Query transactions status

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"
}

Error handling

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

Authors

Madsen Servius ([email protected])

Useful links

moncash_python's People

Contributors

chamane avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.