Skip to main content

This package simplifies ercasng payment processing in python

Project description

ErcasPay

A python package that simplifies https://docs.ercaspay.com/ payment api integration into your python projects.

Installation

This package requires the request library to be installed

pip install requests==2.32.3
pip install python-ercas-ng

Usage

from Ercasng.ercaspay import ErcasPay

## Do not hardcode your secret key inside your code

## Instanstiate ErcasPay Object with your ercasPay secret key

ercas_object = ErcasPay(ercas_pay_secret_key: str)

Initiate Transaction Demo

#This function/method could be a view for django, flask, fastapi or something else.

def initialize_transaction(request):
    amount = 100.00 # Amount for the transaction. Mandatory
    payment_refrence = "R5md7gd9b4s3h2j5d67g" # Payment refrence for the transaction. Mandatory
    customer_name = "FirstName LastName" # Customer name. Mandatory
    customer_email = "customer@example.com" # Customer email. Mandatory
    customer_phone = "08012345678" # Customer phone number. Optional
    redirect_url = "http://redirect.example.com" #Redirect URL. Optional
    description = "Description" # Description. Optional

    ## if the target customer will pay in naira:
        # use the ngn_init method
    # else 
        # use the usd_init method.

    ## Initiate Naira Transaction
    ngn_init = ercas_object.naira_initiate_transaction(self, amount:float, payment_reference:str,
                                   customer_name:str, customer_email:str,
                                   customer_phone:str = None, redirect_url:str=None,
                                   descrption:str = None)

    ## Initiate USD Transaction
    usd_init = ercas_object.usd_initiate_transaction(self, amount:float, payment_reference:str,
                                   customer_name:str, customer_email:str,
                                   customer_phone:str = None, redirect_url:str=None,
                                   descrption:str = None)


     ## handle Successful response for any of the above methods
     if ngn_init["tx_status"]:
        return {
            "tx_status": True,
            "tx_code": "success",
            "tx_body": {
                "payment_reference": "R5md7gd9b4s3h2j5d67g",
                "tx_reference": "ERCS|20231113082706|1699860426792",
                "checkoutUrl": "https://sandbox-checkout.ercaspay.com/ERCS|20231113082706|1699860426792"
            }
        }

        ## The Checkout URL is required and should be returned to and loaded from the frontend to complete the payment checkout

    ## Handle Unsuccessful Response
    return {
                "tx_status": False,
                "tx_code": "failed",
                "error_message": "Actual error that occurred",
                "tx_body": []
            }

Verify Transaction Demo

#This function/method could be a view for django, flask, fastapi or something else.

def verify_transaction(request):
    transaction_reference = "transaction_reference"
    verify_tx = ercas_object.verify_transaction(transaction_reference)

    ## Handle Successful Response
    if verify_tx["tx_status"]:
        return {
            "tx_status": True,
            "tx_code": "success",
            "tx_message": "Transaction fetched successfully",
            "tx_body": {
                "domain": "test",
                "status": "SUCCESSFUL",
                "ercs_reference": "ERCS|20231112152333|1699799013942",
                "tx_reference": "CSHM|WLTP|48606GWR",
                "amount": 100,
                "description": null,
                "paid_at": "2023-11-12T14:24:58.000000Z",
                "created_at": "2023-11-12T14:23:33.000000Z",
                "channel": "BANK_TRANSFER",
                "currency": "NGN",
                "metadata": "{\"firstname\":\"\",\"lastname\":\"Benson\",\"email\":\"iie@mail.com\"}",
                "fee": 1.4,
                "fee_bearer": "customer",
                "settled_amount": 100,
                "customer": {
                "name": "FirstName LastName",
                "phone_number": "09061628409",
                "email": "customer@email.com",
                "reference": "ZEKvFI-N8lMHY"
                }
            }

        ## Handle Unccessful Response
        if not verify_tx["tx_status"]:
            return {
                "tx_status": False,
                "error_message": "Actual error message",
                "tx_code": "failed",
                "tx_body": []
                }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_ercas_ng-1.0.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_ercas_ng-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file python_ercas_ng-1.0.0.tar.gz.

File metadata

  • Download URL: python_ercas_ng-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for python_ercas_ng-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ed8214c52b0364280522211cb913bd4441dc15cfa76adf637b4c205245dfe91c
MD5 499ac4a076c193e8a062b67471f049d1
BLAKE2b-256 caeeeee5c409d60cf6b25fbbfea91754058dfba76904106bc4b5ccc3f57affd7

See more details on using hashes here.

File details

Details for the file python_ercas_ng-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_ercas_ng-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ca52c25f4bdeb02cc6ab744c4fc74040364ee8897e0899163a1c67f850ffe5a
MD5 d97c2f33177de5e4f23ff58f2fc0ed4b
BLAKE2b-256 4e756c88bb4202662371f9b5f34ab8464edf69041f66fb993932e1d0fd8d9b3c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page