Skip to main content

cashfree-pg-sdk-python

  • API version: 2022-09-01
  • Package version: 2.0.1

Requirements.

Python 2.7 and 3.4+

Discord Server Support

Official Discord server is helpful to get support regarding any cashfree SDK , share any issues , raise tickets , give suggestions and request features for the SDK. Join the community of like-minded developers using the link provided below. Link :- https://discord.gg/HrCz9tW2sh

Installation & Usage

pip install

Yyou can install directly using:

pip3 install git+https://github.com/cashfree/cashfree-pg-sdk-python.git

(you may need to run pip3 with root permission: sudo pip3 install git+https://github.com/cashfree/cashfree-pg-sdk-python.git)

Then import the package:

import cashfree_pg_sdk_python

Setuptools

Install via Setuptools.

python3 setup.py install --user

(or sudo python3 setup.py install to install the package for all users)

Then import the package:

import cashfree_pg_sdk_python

Getting Started

Please follow the installation procedure and then run the following: The following part is the basic and common setup required to make any request to Casfhfree using the sdk.

# Note : Please visit https://docs.cashfree.com/ for the complete documentation of the various terminologies used below, 
# if not familiar with.


from __future__ import print_function

import time
import cashfree_pg_sdk_python
from cashfree_pg_sdk_python.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to https://sandbox.cashfree.com/pg
# See configuration.py for a list of all supported configuration parameters.
configuration = CFPython_sdk.Configuration(
    host = "https://sandbox.cashfree.com/pg"
)
# Enter a context with an instance of the API client
with CFPython_sdk.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = CFPython_sdk.OrdersApi(api_client)
x_client_id = 'x_client_id_example' # str |
x_client_secret = 'x_client_secret_example' # str |
x_api_version = '2022-09-01' # str |  (optional) (default to '2022-09-01')
x_idempotency_replayed = False # bool |  (optional) (default to False)
x_idempotency_key = 'x_idempotency_key_example' # str |  (optional)
x_request_id = 'x_request_id_example' # str |  (optional)
cf_order_request = CFPython_sdk.CFOrderRequest() # CFOrderRequest |  (optional)

Making the config and headers for the subsequent CreateOrder / pay_order etc. requests

The variables declared and assigned in the previous (GETTING STARTED) step will be used here.

    cf_config_test = CFConfig(x_client_id,
                            x_client_secret, x_api_version, CFenv.SANDBOX)
    # cfHeaders consists of two things mainly, 1) x-idempotecy-key and 2) x-request-id ; x-request-id can help the consumer of the # sdk to maintain meaningful logs on their side. This can be a unique/non-unique identifier that the consumer can use. It is
    # advisable that x-request-id be unique for each request so that the logging of the events of one request do not clash 
    # with the other. Here, request is a CreateOrder/OrderPay etc. requests that the consumer makes to cashfree.
    cf_headers_test = CFHeaders(
        x_idempotency_key, x_request_id)

Creating an Order

The following snippet provides an example on how to create an order with Cashfree

    # Making the create order request. For more extensive 
    cf_order_request_test = cf_order_request.CFOrderRequest(
        order_amount=10.16,
        order_currency="INR",
        customer_details=cf_customer_details.CFCustomerDetails(
            customer_id="testpythonSDKUSER",
            customer_email="email@cf.com",
            customer_phone="9999999999"
        ), order_note="YOUR_NOTE",
        order_tags={
            "key": "key_example",
        },
        order_meta=CFOrderMeta(
            payment_methods="nb,upi",
            notify_url="https://webhook.merchantsite.com/691ffcf3-80db-4c10-b0d6-fbdc0be7b146" # This is the webhook url.
        ),
    )
     # Create Order Snippet
    try:
        createOrderResult = CreateOrder(cf_config_test, cf_headers_test,
                             cf_order_request_test)
        print("Creat order successful with the following details")
        print(createOrderResult)
    except ApiException as e:
        print("Exception when calling create order: %s\n" % e)

Note: createOrderResult[0].order_id can be used to get the order id from the response.

Getting Order Details

You may wonder why is this function important -> Although you get the order details of the created order in the response of the CreateOrder as a part of the result above , but if you have to get the order details again after some time against the orderid then this function can be utilised. The following snippet is an example on how to use the function.

# Get Order Snippet
try:
    GetOrderResult = GetOrder(cfconfigtest, cfheaderstest,
                      result[0].order_id)
    print("Get Order successful wiith the following details")
    print(createOrderResult)
except ApiException as e:
    print("Exception when calling create order: %s\n" % e)

Other funtions

Pay Order call , getting transaction details and creating refund are all supported by this SDK, the same payload as in the normal API can be created and passed to the funtions and the SDK takes care of the network call thereafter. gatewayiinterface.py contains all the methods that can be used.

For any queries/help join the Official discord group mentioned in the beginning of this README doc.

Documentation For Models

Documentation For Authorization

All endpoints do not require authorization.

Author

developers@cashfree.com

Metadata

Release files for cashfree-pg-sdk-python 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cashfree-pg-sdk-python 2.0.1
File Size Uploaded
cashfree_pg_sdk_python-2.0.1.tar.gz 55.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cashfree-pg-sdk-python 2.0.1
File Interpreter ABI Platform
cashfree_pg_sdk_python-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 192.1 kB

Release files / cashfree_pg_sdk_python-2.0.1.tar.gz

Download URL cashfree_pg_sdk_python-2.0.1.tar.gz
Size 55.1 kB
Tags Source
SHA-256 checksum
How to use checksums
88c5a988d9faaf441aacf002c4c5bb538a04208f2c27320617cae6d23a6d926f
BLAKE2b-256 checksum
How to use checksums
583b25a12e97bc3ea43bba7b791ddd7df4612473045787021915aca67a2ee558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / cashfree_pg_sdk_python-2.0.1-py3-none-any.whl

Download URL cashfree_pg_sdk_python-2.0.1-py3-none-any.whl
Size 137.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2964310824f446b2af70222a078f958484020ed503474570bd2e8f5985442bd7
BLAKE2b-256 checksum
How to use checksums
4244768d64c9cb3843b476e9e2fcb3d813241c3937245579f71e9d4b7e5c67fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page