Skip to main content

CamPay Python SDK

Python SDK for CamPay Payment Gateway

CamPay is a Fintech service of the company TAKWID GROUP which launched its financial services in Cameroon from January 2021.

We provide businesses and institutions with solutions for collecting and transferring money online, via primarily Mobile Money(MTN and Orange).

With CamPay, simplify the purchasing experience for your customers thanks to our mobile money payment solutions, accessible via your website and/or mobile application.

Summary

Getting Started

These instructions will get you started with the CamPay SDK for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

  • Create an account on CamPay platform
  • Register an application under your account.
  • Expand your registered application to get access to your API keys

Installing

     pip install campay

Running the samples

  • Initialize the library with credentials.

        from campay.sdk import Client as CamPayClient
    
        campay = CamPayClient({
            "app_username" : "PASTE YOUR APP_USERNAME HERE",
            "app_password" : "PASTE YOUR APP_PASSWORD HERE",
            "environment" : "DEV" #use "DEV" for demo mode or "PROD" for live mode
        })
    
  • Optional settings (defaults shown):

        campay = CamPayClient({
            ...,
            "verify_ssl": True,       # verify HTTPS certificates
            "request_timeout": 30,    # seconds per HTTP request
            "poll_timeout": 300,      # max seconds collect()/disburse() wait for confirmation
        })
    

To collect payments from your client - DIRECTLY

OPTION 1: This option initiates a transaction and waits( or block the running code) for the transaction to complete before returning a response.

      collect = campay.collect({
         "amount": "5", #The amount you want to collect
         "currency": "XAF",
         "from": "2376xxxxxxxx", #Phone number to request amount from. Must include country code
         "description": "some description",
         "external_reference": "", #Reference from the system initiating the transaction.
      })

      print(collect)
      #{"reference": "bcedde9b-62a7-4421-96ac-2e6179552a1a", "external_reference":"12345678", "status": "SUCCESSFUL", "amount": 5, "currency": "XAF", "operator": "MTN", "code": "CP201027T00005", "operator_reference":  "1880106956" }
      

status can be SUCCESSFUL or FAILED. If the customer has not confirmed within poll_timeout seconds, status is PENDING and the response includes the reference to check later with get_transaction_status.

OPTION 2: This option initiates a transaction and immediately returns the initiated transaction reference for you to use to check the status of the transaction.

      collect = campay.initCollect({ # or campay.init_collect(...)
         "amount": "5", #The amount you want to collect
         "currency": "XAF",
         "from": "2376xxxxxxxx", #Phone number to request amount from. Must include country code
         "description": "some description",
         "external_reference": "", #Reference from the system initiating the transaction.
      })

      print(collect)
      #{"reference": "bcedde9b-62a7-4421-96ac-2e6179552a1a", "ussd_code": "*126# for MTN or #150*50# for ORANGE", "operator": "mtn or orange" }
      

The default status for initiated transactions is PENDING

To check a transaction status.

You need the initiated transaction reference to use this function.

      campay_status = campay.get_transaction_status({
         "reference": "bcedde9b-62a7-1234-96ac-2e6179552a1a", #The reference returned from campay.initCollect
      })

      print(campay_status)
      #{"reference": "bcedde9b-62a7-4421-96ac-2e6179552a1a", "external_reference":"12345678", "status": "SUCCESSFUL", "amount": 5, "currency": "XAF", "operator": "MTN", "code": "CP201027T00005", "operator_reference":  "1880106956" }
      

status can be PENDING, SUCCESSFUL or FAILED

      payment_link = campay.get_payment_link({
         "amount": "5",
         "currency": "XAF",
         "description": "some description",
         "external_reference": "12345678",
         "from":"2376xxxxxxxx",
         "first_name":"John",
         "last_name":"Doe",
         "email":"",
         "redirect_url": "https://mysite.com/",
         "failure_redirect_url":"https://failed.com/",
         "payment_options":"MOMO,CARD"
      })

      print(payment_link)
      #{"status": "SUCCESSFUL", "link": "https://www.campay.com/pay/with/link/", "reference": "bcedde9b-62a7-4421-96ac-2e6179552a1a"}
      '''
      Redirect your customer to the returned payment link. 
      You can use the "reference" to verify the status of the transaction. If check the transaction status and client has not initiated a transaction on the payment link, you will get a response telling you the transaction is not found.
      '''
      

status can be SUCCESSFUL or FAILED

To disburse

Please enable API withdrawal under app settings before trying this request

     disburse = campay.disburse({
         "amount": "5", #The amount you want to disburse
         "currency": "XAF",
         "to": "2376xxxxxxxx", #Phone number to disburse amount to. Must include country code
         "description": "some description",
         "external_reference": "", #Reference from the system initiating the transaction.
     })

     print(disburse)
     #{"reference": "bcedde9b-62a7-4421-96ac-2e6179552a1a", "external_reference":"12345678", "status": "SUCCESSFUL", "amount": 5, "currency": "XAF", "operator": "MTN", "code": "CP201027T00005", "operator_reference":  "1880106956" }

status can be SUCCESSFUL or FAILED, or PENDING if poll_timeout is reached

To Get application balance.

     balance = campay.get_balance()

     print(balance)
     #{"total_balance": 0, "mtn_balance": 0, "orange_balance": 0, "currency": "XAF"}

Deployment

Change the environment of the library introduction to PROD

      from campay.sdk import Client
      campay = Client({
          "app_username" : "PASTE YOUR APP_USERNAME HERE",
          "app_password" : "PASTE YOUR APP_PASSWORD HERE",
          "environment" : "PROD" #use "DEV" for demo mode or "PROD" for live mode
      })

Metadata

Release files for campay 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for campay 1.2.0
File Size Uploaded Provenance Actions
campay-1.2.0.tar.gz 19.3 kB Without provenance Details for campay-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for campay 1.2.0
File Interpreter ABI Platform Actions
campay-1.2.0-py3-none-any.whl Python 3 none any Details for campay-1.2.0-py3-none-any.whl

Total release size: 37.4 kB

Release files / campay-1.2.0.tar.gz

Download URL campay-1.2.0.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
236d6ccd021137130834e8298d3d9aeb41aefd1eb060e9cbc34a7dcfdc1bcb6e
BLAKE2b-256 checksum
How to use checksums
4a0f0cdf815cada80fe7a2f5dada60b18d131dc64f0bee6337e1aa04ebcaebca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release files / campay-1.2.0-py3-none-any.whl

Download URL campay-1.2.0-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a40930ee204196191cd4a4f816a54a8a4243dc3760d4c4fc2ea1100817712ef
BLAKE2b-256 checksum
How to use checksums
8b6dd0ebf8eda6d30ad9def7a9ff32b15a1d46627d8bc93e427fb742850626e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Security for campay 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page