Coder Social home page Coder Social logo

python-webpay's Introduction

Python package for Webpay gateway API

Installation

Install from PyPI:

pip install webpay-bahamta

For async support:

pip install webpay-bahamta[async]

Usage

Simple example:

from webpay import WebpayAPI, exceptions

API_KEY = "webpay:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"
webpay = WebpayAPI(API_KEY)

# Make a payment
payment_url = webpay.payment(
    reference='payment1',
    amount_irr=100000,
    callback_url='https://example.com',
    payer_mobile='+989111111111',  # Optional
    trusted_pan=None  # Optional
)

# Verify payment
try:
    payment_data = webpay.verify(
        reference='payment1',
        amount_irr=100000
    )
    if payment_data.get("state") == "paid":
            print("Payment confirmed")
    else:
        print("Payment not confirmed")
except exceptions.APIError as exc:
    if exc.error_key == 'NOT_CONFIRMED':
        print("Payment not confirmed")
    else:
        raise exc

Async example:

import asyncio
from webpay import AsyncWebpayAPI, exceptions

API_KEY = "webpay:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"
webpay = AsyncWebpayAPI(API_KEY)


async def main():
    # Make a payment
    payment_url = await webpay.payment(
        reference='payment1',
        amount_irr=100000,
        callback_url='https://example.com',
        payer_mobile='+989111111111',  # Optional
        trusted_pan=None  # Optional
    )

    # Verify payment
    try:
        payment_data = await webpay.verify(
            reference='payment1',
            amount_irr=100000
        )
        if payment_data.get("state") == "paid":
            print("Payment confirmed")
        else:
            print("Payment not confirmed")
    except exceptions.APIError as exc:
        if exc.error_key == 'NOT_CONFIRMED':
            print("Payment not confirmed")
        else:
            raise exc

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

payment_url will be like:

https://webpay.bahamta.com/api/…

payment_data will be like:

{
    "state": "paid",
    "total": 1000000,
    "wage": 5000,
    "gateway": "sep",
    "terminal": "11223344",
    "pay_ref": "GmshtyjwKSu5lKOLquYrzO9BqjUMb/TPUK0qak/iVs",
    "pay_trace": "935041",
    "pay_pan": "123456******1234",
    "pay_cid": "77CB1B455FB5F60415A7A02E4502134CFD72DBF6D1EC8FA2B48467DFB124AA75A",
    "pay_time": "2019-11-12T16:39:57.686436+03:30"
}

Examples

flask-donation-page - An example of usage in flask app views

API Documentation

https://webpay.bahamta.com/doc/api

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.