Package: cashfree-pg-sdk-python
cashfree-pg-sdk-pythonAPI version: 2022-09-01Package version: 2.0.1Requirements.Python 2.7 and 3.4+Discord Server SupportOfficial 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/HrCz9tW2shInstallation & Usagepip installYyou can install directly using:pip3installgit+https://github.com/cashfree/cashfree-pg-sdk-python.git(you may need to runpip3with root permission:sudo pip3 install git+https://github.com/cashfree/cashfree-pg-sdk-python.git)Then import the package:importcashfree_pg_sdk_pythonSetuptoolsInstall viaSetuptools.python3setup.pyinstall--user(orsudo python3 setup.py installto install the package for all users)Then import the package:importcashfree_pg_sdk_pythonGetting StartedPlease follow theinstallation procedureand 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__importprint_functionimporttimeimportcashfree_pg_sdk_pythonfromcashfree_pg_sdk_python.restimportApiExceptionfrompprintimportpprint# 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 clientwithCFPython_sdk.ApiClient(configuration)asapi_client:# Create an instance of the API classapi_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. requestsThe 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 OrderThe following snippet provides an example on how to create an order with Cashfree# Making the create order request. For more extensivecf_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 Snippettry:createOrderResult=CreateOrder(cf_config_test,cf_headers_test,cf_order_request_test)print("Creat order successful with the following details")print(createOrderResult)exceptApiExceptionase: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 DetailsYou 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 Snippettry:GetOrderResult=GetOrder(cfconfigtest,cfheaderstest,result[0].order_id)print("Get Order successful wiith the following details")print(createOrderResult)exceptApiExceptionase:print("Exception when calling create order:%s\n"%e)Other funtionsPay 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 ModelsCFAppCFAppPaymentCFAuthorizationInPaymentsEntityCFAuthorizationRequestCFCardCFCardEMICFCardPaymentCFCardlessEMICFCardlessEMIPaymentCFCryptogramCFCustomerDetailsCFEMIPaymentCFErrorCFFetchAllSavedInstrumentsCFLinkCFLinkCancelledResponseCFLinkCustomerDetailsEntityCFLinkMetaEntityCFLinkNotifyEntityCFLinkOrdersCFLinkRequestCFNetbankingCFNetbankingPaymentCFOrderCFOrderMetaCFOrderPayDataCFOrderPayRequestCFOrderPayResponseCFOrderRequestCFPaylaterCFPaylaterPaymentCFPaymentMethodCFPaymentURLObjectCFPaymentsEntityCFPaymentsEntityAppCFPaymentsEntityAppPaymentCFPaymentsEntityCardCFPaymentsEntityCardPaymentCFPaymentsEntityCardlessEMICFPaymentsEntityCardlessEMIPaymentCFPaymentsEntityMethodCFPaymentsEntityNetbankingPaymentCFPaymentsEntityPaylaterCFPaymentsEntityPaylaterPaymentCFPaymentsEntityUPICFPaymentsEntityUPIPaymentCFRefundCFRefundRequestCFRefundURLObjectCFSavedInstrumentMetaCFSettlementURLObjectCFSettlementsEntityCFUPICFUPIAuthorizeDetailsCFUPIPaymentCFVendorSplitLinkCancelledErrorRefundSpeedDocumentation For AuthorizationAll endpoints do not require authorization.Authordevelopers@cashfree.com