Giter VIP home page Giter VIP logo

upi-deeplinks-python-sdk's Introduction

Setu UPI DeepLinks: Python SDK

setu is a Python SDK for accessing Setu’s UPI Deeplinks APIs. The SDK is designed with ease of access in mind, with native Python class objects for inputs & ouputs and custom exceptions.

Version Downloads License

SDK in action

Getting started

SDK documentation →
Full documentation →
Product overview →

Installation

pip install setu

Features

  • Full support for latest UPI Deeplinks APIs
  • Native Python class objects for all inputs & responses
  • Allows both JWT & OAuth authentication mechanisms
  • SANDBOX mode to test integration & PRODUCTION for live data
  • Internal mechanism for OAuth authentication to automatically re-fetch token when current one expires, and retry all failed requests.

Examples

Setup

from setu import Deeplink
from setu.contract import RefundRequestItem, SetuAPIException

dl = Deeplink(
    scheme_id="c4f57443-dc1e-428f-8c4e-e5fd531057d2",
    secret="5b288618-473f-4193-ae1b-8c42f223798e",
    product_instance_id="861023031961584801",
    auth_type="OAUTH",
    mode="SANDBOX",
)

Generate UPI payment link

bill_amount = 100
try:
    link = dl.create_payment_link(
        amount_value=bill_amount,
        biller_bill_id="test_transaction_1234",
        amount_exactness="EXACT",
        payee_name="Python SDK unittest",
        transaction_note="unittest transaction",
    )
    assert link.payment_link.upi_id == "refundtest@kaypay"
except SetuException as e:
    assert False

Get Payment Link Status

try:
    link_status = dl.check_payment_status(link.platform_bill_id)
    assert link_status.status == "BILL_CREATED"
except SetuAPIException as e:
    assert False

Trigger mock payment for UPI payment link (Sandbox only)

try:
    credit_response = dl.trigger_mock_payment(
        float(bill_amount) / 100, link.payment_link.upi_id, link.platform_bill_id
    )
except SetuAPIException as e:
    assert False

Mock Settlement

try:
    dl.trigger_mock_settlement([credit_response.utr])
except SetuAPIException as e:
    assert False

Expire bill payment

try:
    dl.expire_payment_link(link.platform_bill_id)
except SetuAPIException as e:
    assert False

Initiate Refund

try:
    batch_initiate_refund_response = dl.initiate_batch_refund(
        refunds=[
            RefundRequestItem(
                identifier=link.platform_bill_id,
                identifierType="BILL_ID",
                refundType="FULL",
            ),
        ],
    )
    assert batch_initiate_refund_response.refunds[0].status == "Pending"
except SetuAPIException as e:
    assert False

Get refund batch status

try:
    refund_batch_status_response = dl.get_batch_refund_status(batch_initiate_refund_response.batch_id)
    assert refund_batch_status_response.refunds[0].bill_id == link.platform_bill_id
except SetuAPIException as e:
    assert False

Get individual refund status

try:
    refund_status_response = dl.get_refund_status(batch_initiate_refund_response.refunds[0].id)
    assert refund_status_response.bill_id == link.platform_bill_id
except SetuAPIException as e:
    assert False

Contributing

Have a look through existing Issues and Pull Requests that you could help with. If you'd like to request a feature or report a bug, please create a GitHub Issue using the template provided.

See contribution guide →

Credits

This package was created with Cookiecutter and the waynerv/cookiecutter-pypackage project template.

License

MIT. Have at it.

upi-deeplinks-python-sdk's People

Contributors

aditya-67 avatar akshaybhalotia avatar gandharva-setu avatar ghostwriternr avatar nithinkashyapn avatar ritwickdey avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

rameshoswal

upi-deeplinks-python-sdk's Issues

illegal base64 data at input byte 1

When I use the scheme_id/jwt_secret copied from the dashboard as Python strings, I get this error. What is the right way to pass these parameters as String ?
Exception: ('Bad credentials', {'code': 'jwt-verification-failed', 'detail': 'illegal base64 data at input byte 1', 'docURL': '', 'title': 'AUTHENTICATION_ERROR', 'errors': [], 'traceID':

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.