Skip to main content

Casfree Payments Payment Gateway Python SDK

Project description

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

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

cashfree_pg_sdk_python-2.0.1.tar.gz (55.1 kB view hashes)

Uploaded Source

Built Distribution

cashfree_pg_sdk_python-2.0.1-py3-none-any.whl (137.1 kB view hashes)

Uploaded Python 3

Supported by

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