A Python SDK for interacting with the Ercaspay payment gateway.
Project description
Ercaspay SDK Documentation
Ercaspay SDK provides an easy and efficient way to interact with the Ercaspay payment gateway. This SDK simplifies the process of making payments, verifying transactions, and handling various payment methods.
Installation
To install the SDK, run:
pip install ercaspysdk
Checkout Payment
Checkout payments allow your customers to make payments using the standard Ercaspay checkout page.
Usage
from ercaspy.client import Ercaspy
from ercaspy.exceptions import APIError
client = Ercaspy(api_key="Your_Api_Key")
payment_data = {
"amount": "1500",
"paymentReference": "unique_transaction_code",
"customerName": "Sheden",
"customerEmail": "shedenbright@gmail.com",
"currency": "NGN",
"redirectUrl": "https://frontendurl.com",
"paymentMethods": "card, ussd, bank-transfer"
}
def initiate_payment():
try:
response = client.initiate_payment(payment_data=payment_data)
print(response)
except APIError as e:
print(f"An error occurred while initiating payment: {e}")
Sample Response:
{
"requestSuccessful": True,
"responseCode": "success",
"responseMessage": "success",
"responseBody": {
"paymentReference": "olamide123456",
"transactionReference": "ERCS|20241216193301|1734373981563",
"checkoutUrl": "https://sandbox-checkout.ercaspay.com/ERCS|20241216193301|1734373981563"
}
}
Redirect the user to the checkoutUrl. After a successful payment, the user will be redirected back to the specified redirectUrl.
Verify Checkout Transaction
Call the verify_transaction method to verify a transaction.
Usage
transaction_ref = "transaction_reference_from_checkout"
def verify_transaction(transaction_ref):
try:
response = client.verify_transaction(transaction_ref)
print(response)
except APIError as e:
print(f"An error occurred while verifying the transaction: {e}")
Direct Integration
Bank Transfer
The bank transfer method generates dynamic bank details for your customers to make payments. The account number can only be used once by the customer.
Usage
payment_data = {
"amount": "1500",
"paymentReference": "unique_transaction_ref",
"customerName": "Sheden",
"customerEmail": "shedenbright@gmail.com",
"currency": "NGN",
"redirectUrl": "https://frontendurl.com",
"paymentMethods": "bank-transfer"
}
def bank_transfer(payment_data):
try:
response = client.initiate_bank_transfer(data=payment_data)
print(response)
except APIError as e:
print(f"An error occurred while initiating bank transfer: {e}")
Verify Direct Integration Payment
Call the check_direct_payment_status method to verify the payment status.
Usage
transaction_ref = "unique_transaction_ref"
payment_method = "bank-transfer"
def verify_direct_payment(transaction_ref, payment_method):
try:
response = client.check_direct_payment_status(transaction_ref, payment_method)
print(response)
except APIError as e:
print(f"An error occurred while verifying payment status: {e}")
USSD Payment
USSD payment allows customers to pay using their phone without internet access. The endpoint generates a USSD code for the payment.
Usage
payment_data = {
"amount": "1500",
"paymentReference": "unique_transaction_ref",
"customerName": "Sheden",
"customerEmail": "shedenbright@gmail.com",
"currency": "NGN",
"paymentMethods": "ussd"
}
def ussd_transaction(payment_data):
try:
response = client.initiate_ussd_transaction(data=payment_data, bank_name="fcmb")
print(response)
except APIError as e:
print(f"An error occurred while initiating USSD transaction: {e}")
Verify the payment using check_direct_payment_status as shown in the Verify Direct Integration Payment section.
Card Payment
Card payment allows customers to pay with their debit or credit card.
Encrypt Card Details
Use the following function to encrypt card details before initiating the transaction:
def encrypt_card(card_number, cvv, pin, expiry_date):
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
import base64
import json
# Load public key
with open('key/rsa_public_key.pub', 'rb') as key_file:
public_key_data = key_file.read()
public_key = RSA.import_key(public_key_data)
# Card details
card_params = {
'cvv': cvv,
'pin': pin,
'expiryDate': expiry_date,
'pan': card_number
}
# Encrypt details
cipher = PKCS1_v1_5.new(public_key)
encrypted = cipher.encrypt(json.dumps(card_params).encode('utf-8'))
return base64.b64encode(encrypted).decode('utf-8')
Initiate Card Transaction
data = {
"card_number": "5123450000000008",
"cvv": "100",
"pin": "1234",
"expiry_date": "0139",
"transaction_reference": "ERCS|20241216191025|1734372625377"
}
encrypted_payload = encrypt_card(
card_number=data["card_number"],
cvv=data["cvv"],
pin=data["pin"],
expiry_date=data["expiry_date"]
)
def initiate_card_transaction(encrypted_payload, transaction_ref):
try:
response = client.initiate_card_transaction(payload=encrypted_payload, transaction_ref=transaction_ref)
print(response)
except APIError as e:
print(f"An error occurred while initiating card transaction: {e}")
OTP Management
Submit OTP
def submit_otp(otp, transaction_ref, gateway_ref):
try:
response = client.submit_otp(otp, transaction_ref, gateway_ref)
print(response)
except APIError as e:
print(f"An error occurred while submitting OTP: {e}")
Resend OTP
def resend_otp(transaction_ref, gateway_ref):
try:
response = client.resend_otp(transaction_ref, gateway_ref)
print(response)
except APIError as e:
print(f"An error occurred while resending OTP: {e}")
Utilities
Get Supported Banks
Fetch the list of supported banks:
banks = client.get_bank_list()
print(banks)
Cancel Transaction
To cancel a transaction that has not been completed:
client.cancel_transaction(transaction_ref="transaction_reference")
Developed by: Shedenbright
Contact: shedenbright@gmail.com
Resume: sheden-resume.netlify.app
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ercaspysdk-0.2.2.tar.gz.
File metadata
- Download URL: ercaspysdk-0.2.2.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5180a1ba076292470db08630ad4181eed6eacdbb32bf8411657dbce33640833b
|
|
| MD5 |
58809c2d6a1d9d88a4acfdb47078f3ec
|
|
| BLAKE2b-256 |
23955988ef33775452977dddb0c613b2547fce31196dde74fc054dc5f45accbd
|
File details
Details for the file ercaspysdk-0.2.2-py3-none-any.whl.
File metadata
- Download URL: ercaspysdk-0.2.2-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7af49670a5cd4b001f053a2cb6a1942d4d7a544b0ff75bef42f6738d7b59411
|
|
| MD5 |
a8e82d467c4b6fe3230e7736077f150e
|
|
| BLAKE2b-256 |
8a0d2fa5d2135e1d04d70b698cb411975e313bd239fe0047ceed9e2269e1fb9a
|