New CinetPay Python Library 😎
Python SDK for CinetPay Payment API.
Currently Supported Services
- Payment API
Next
We will add progressively support for following CinetPay Services:
- Transfert API
- SMS API
- Airtime API
Prerequisites
You need to have at least 3.9 version of python to be able to continue. To do this:
Next you can go ahead with CinetPay.
Install
pip install CinetPay
API
This Python library's API is designed around the CinetPay REST API
Settings
There are two ways to setup CinetPay Client:
- Using a Config object
from cinetpay import (
Client, Config, Credential
Channels, Currencies, Languages,
)
# Setting up a client configuration
config = Config(
currencies = Currencies.XOF,
languages = Languages.FR,
channels = Channels.ALL,
lock_phone_number = True,
raise_on_error = True,
credentials = Credential(
apikey = 'XXXXXXXXXXXXXXXXXX',
site_id = 'XXXXXX'
)
)
# Initializing the client
client = Client(
configs = config
)
- Using a dictionary object
from cinetpay import (
Client, Config,
Channels, Currencies, Languages,
)
# Setting up a client configuration
config = {
'currencies': Currencies.XOF,
'languages': Languages.FR,
'channels': Channels.ALL,
'lock_phone_number': True,
'raise_on_error': False, # If True, client will raise on request errors
'credentials':{
'apikey':'XXXXXXXXXXXXXXXXXX',
'site_id':'XXXXXX',
}
}
# Initializing the client
client = Client(
configs = config
)
Transactions
Create Order
from cinetpay import (
Order, Customer, Currencies,
)
# CREATING A TRANSACTION
order = Order(
id = 'ORDER1234',
amount = 1000,
currency = Currencies.XOF,
description = 'Description of the transaction',
notify_url = 'https://www.exemple.com/notify',
return_url = 'https://www.exemple.com/return',
customer = Customer(
customer_id = 'mycustomer123',
customer_email = 'mycustomer@mydomain.com',
customer_phone_number = '+22890000000',
customer_name = 'John',
customer_surname = 'Doe',
)
)
# GET ORDER JSON REPRESENTATION
print(order.to_representation())
{
"transaction_id":"ORDER1234",
"amount":1000,
"notify_url":"https://www.exemple.com/notify",
"return_url":"https://www.exemple.com/return",
"description":"Description of the transaction",
"customer_id":"mycustomer123",
"customer_name":"John",
"customer_surname":"Doe",
"customer_phone_number":"+22890000000",
"apikey":"XXXXXXXXXXXXXXXXXXXXX",
"site_id":"XXXXXX",
"channels":"ALL",
"lang":"fr",
"currency":"XOF",
"lock_phone_number":false
}
Create Transaction
from cinetpay import (
Client, Config, Order, Customer,
Channels, Currencies, Languages,
Credential
)
# Setting up a client configuration
config = Config(
currencies = Currencies.XOF,
languages = Languages.FR,
channels = Channels.ALL,
lock_phone_number = True,
raise_on_error = True,
credentials = Credential(
apikey = 'XXXXXXXXXXXXXXXXXX',
site_id = 'XXXXXX'
)
)
# Initializing the client
client = Client(
configs = config
)
# CREATING A TRANSACTION
order = Order(
id = 'ORDER1234',
amount = 1000,
currency = Currencies.XOF,
description = 'Description of the transaction',
notify_url = 'https://www.exemple.com/notify',
return_url = 'https://www.exemple.com/return',
customer = Customer(
customer_id = 'mycustomer123',
customer_email = 'mycustomer@mydomain.com',
customer_phone_number = '+22890000000',
customer_name = 'John',
customer_surname = 'Doe',
)
)
# INITIALIZE PAYMENT
res = client.initialize_transaction(order)
print(res)
Retrieve Transaction
To get a specific transaction you can use the get_transaction function with the transaction_id or token.
response = client.get_transaction(transaction_id)
Get a Specific Transaction payment url
You can also get a payment URL for a specific Transaction using get_bill_url function.
response = client.get_bill_url(transaction_id)
Responses
The default Request response class, is returned when detail is set to True in the request.
response = client.create_transaction(my_transaction)
print(response) # <Class Response status: 201, error: False>
# Use json attribute to access response data.
print(response.json) # {"id":transaction_id,...}
PagginatedResponse is used to manage Pagginated response data. It provides properties such as :
has_next: bool ,Trueif the PagginatedResponse has a next page elseFalse.has_prev: bool,Trueif the PagginatedResponse has a next page elseFalsenext_page: PagginatedResponse, the next page ifhas_nextisTrueprevious_page: PagginatedResponse, the next page ifhas_previsTrueresult: sequence[ Mapping[ str,any ] ], the page data.
Errors
Errors are raised if requests return an error status.
This Error is returned if raise_on_error is set to True in Client configs.
from cinetpay import (
Client, Config, Credential,
Channels, Currencies, Languages,
)
# Setting up a client configuration
config = Config(
currencies = Currencies.XOF,
languages = Languages.FR,
channels = Channels.ALL,
lock_phone_number = True,
raise_on_error = True,
credentials = Credential(
apikey = 'WRONG-API-KEY',
site_id = 'SIDE-ID'
)
)
# Initializing the client
client = Client(
configs = config
)
response = client.get_transaction('TRANSACTION-ID')
# With raise_on_error set to False
print(type(response)) # <class 'cinetpay._types.ErrorResponse'>
print(response.get_message()) # Client - Client error '400 Bad Request' for url 'https://api-checkout.cinetpay.com/v2/payment'.
# Access ErorResponse infos
print(response.json)
# {'code': '624', 'message': 'UNKNOWN_ERROR', 'description': 'An error occurred while processing the request', 'api_response_id': '1716800180.4474'}
print(response.description)
# An error occurred while processing the request.
print(response.cause)
# 1- l'apikey saisi est incorrect
# 2- La valeur de lock_phone_number est à true mais la valeur du customer_phone_number est incorrect.
print(response.hint)
# 1- Récupérer l'apikey correcte dans votre back-office(menu integration)
# 2- La variable doit être false.
# For more information check: https://docs.cinetpay.com/api/1.0-fr/checkout/initialisation#problemes-frequents
This Error is raised if raise_on_error is set to True in Client configs.
from cinetpay import (
Client, Config, Credential,
Channels, Currencies, Languages,
)
# Setting up a client configuration
config = Config(
currencies = Currencies.XOF,
languages = Languages.FR,
channels = Channels.ALL,
lock_phone_number = True,
raise_on_error = True,
credentials = Credential(
apikey = 'WRONG-API-KEY',
site_id = 'SIDE-ID'
)
)
# Initializing the client
client = Client(
configs = config
)
response = client.get_transaction('TRANSACTION-ID')
# Will raise a ResponseError with response message.
Made with ❤️ By #Einswilli
Metadata
Release files for CinetPay 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cinetpay-0.0.1.tar.gz | 14.1 kB | Without provenance | Details for cinetpay-0.0.1.tar.gz |
Release files / cinetpay-0.0.1.tar.gz
| Download URL | cinetpay-0.0.1.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
093db0c77e5ece01f22fc88a24593a5174e112d535044fe2ed7d9b7304539c8e
|
|
BLAKE2b-256 checksum How to use checksums |
45651df37cc73f37746672129f28edb2e4742ab6bce6a365cc2e285e55b5f6eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.1
|
Security for CinetPay 0.0.1
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.