def initialize(): try: Payouts.init('CF8596D2125MM8G66AQAY', '8eba07528682962556c6dd4f9c84b278664d4283', 'TEST') # Payouts.init("CF27870FMPD32Z3L7IQQ22", # "7c27c6ebf9d31091bd9034a0f0887442792a9ad7", "PROD") except ConnectionError: return None
Below is an integration flow on how to use Cashfree's payouts SDK. The SDK can be found at: https://github.com/cashfree/cashfree-sdk-python Please go through the payout docs here: https://dev.cashfree.com/payouts The following script contains the following functionalities : 1. Cashgram.create_cashgram -> create a cashgram 2. Cashgram.get_cashgram_status -> get status of the created cashgram ''' from cashfree_sdk.payouts import Payouts from cashfree_sdk.payouts.cashgram import Cashgram clientId = "clientId" clientSecret = "clientSecret" env = "TEST" try: Payouts.init(clientId, clientSecret, env) create_cashgram_response = Cashgram.create_cashgram( cashgramId="cf111", amount= "1.00", name= "sameera", email= "*****@*****.**", phone= "9000000001", linkExpiry= "2020/01/19", remarks= "sample cashgram", notifyCustomer= 1 ) print("create cashgram response") print(create_cashgram_response.content) get_cashgram_status_response = Cashgram.get_cashgram_status("cf111")
def posttoredemmoney(request): data = {} if request.method == 'POST': hname = request.POST['holdername'] accno = request.POST['accoutno'] ifscode = request.POST['ifscode'] wallets = wallet.objects.filter(user=request.user).first() responses = Payouts.init(settings.clientId, settings.clientSecret, "TEST") if wallets.accoutno != accno or wallets.holdername != hname or wallets.IFSC != ifscode: replace_bene = Beneficiary.replace_bene(wallets.walletid) wallets.holdername = hname wallets.accoutno = accno wallets.IFSC = ifscode wallets.save() amount = wallets.Balanceamt bene_details_response = '' try: bene_details_response = Beneficiary.get_bene_details( wallets.walletid) # bene_details_response_content = json.loads(bene_details_response.content) # print("get beneficary details") bene_details_response = bene_details_response.json() print(bene_details_response) except IncorrectCredsError as exception: data['servererror'] = 1 messages.success( request, 'Sorry, your money transfering process has been failed , due to some server error.Please try again later.' ) return HttpResponse(json.dumps(data), content_type="application/json") except EntityDoesntExistError as err: try: bene_details_response = create_Beneficiary( wallets.walletid, request.user.first_name, request.user.email, wallets.userdetail.phnumber1, accno, ifscode, wallets.userdetail.address1, wallets.userdetail.city, wallets.userdetail.state, wallets.userdetail.pincode) print(bene_details_response) except InputWrongFormatError: errormessage = 'Invalid Account Mumber or IFSC code!' data['errormessage'] = errormessage return HttpResponse(json.dumps(data), content_type="application/json") if bene_details_response != '': if bene_details_response['subCode'] == "200": try: transferid = unique_transferid_generator() trequest = Request_Transfer(wallets.walletid, transferid, "1.00") print(trequest) if trequest[ 'subCode'] == "201": #pending and pendeint and later success redems = redem(redemid=transferid, redemamt=amount, user=request.user, wallets=wallets, redemstatus=2) redems.save() data['valid'] = 1 messages.success( request, 'Your Money has redemed Successfully , but your money Transfer request is pending at the bank. Incase , if Money is not transfered in your bank account, dont worry we will refund your money back into the Your wallet.' ) return HttpResponse(json.dumps(data), content_type="application/json") else: data['valid'] = 1 redems = redem(redemid=transferid, redemamt=amount, user=request.user, wallets=wallets, redemstatus=1) redems.save() messages.success( request, 'Your Money has redemed , and transfered into your bank account successfully.' ) return HttpResponse(json.dumps(data), content_type="application/json") except: data['servererror'] = 1 messages.success( request, 'Sorry, your money transfering process has been failed , due to some server error.Please try again later.' ) return HttpResponse(json.dumps(data), content_type="application/json") return HttpResponse(json.dumps(data), content_type="application/json")
NOT_FOUND = {'message': 'Resource not found.'} ALREADY_EXISTS = {'message': 'User with that phone number exists already.'} BOTH_USERS_MUST_EXIST = {'message': 'Both participatingusers must exist.'} SOMETHING_IS_WRONG = {'message': "Something's wrong."} SIGNATURE_VALIDATION_FAILED = {'message': 'Signature validation failed.'} SMS_BODY = '%s has sent you Rs. %s.00 via EasyCredit. Click on this link to receive the amount. %s' mongo = MongoClient(MONGO_CONN_STR) # Server db = mongo.easycredit # Database users, sessions = db.users, db.sessions # Collections with open('cf_public_key.pem') as pemfile: CF_PUBLIC_KEY = pemfile.read() Payouts.init(CF_CLIENT_ID, CF_CLIENT_SECRET, CF_ACCOUNT, public_key=CF_PUBLIC_KEY) Twilio = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) def response(body=SUCCESS, status_code=200): return func.HttpResponse(json.dumps(body), status_code=status_code) def logged_in(user): active_session = sessions.find_one({'userId': user['id']}) if active_session: logging.info(f"Already logged in: {user['id']}") return str(active_session['_id']) else: logging.info(f"Not logged in: {user['id']}")
clientId = "client_id" clientSecret = "client_secret" entries = [{ "transferId": "PTM_00121241112", "amount": "12", "phone": "9999999999", "bankAccount": "9999999999", "ifsc": "PYTM0_000001", "email": "*****@*****.**", "name": "bharat" }] try: Payouts.init(clientId, clientSecret, "TEST") print(payouts_config_var.url) batch_tnx_create = Transfers.create_batch_transfer( batchTransferId="Test_Bank_Account_Format_46", batchFormat="BANK_ACCOUNT", batch=entries, deleteBene=1) status = Transfers.get_batch_transfer_status( batchTransferId="Test_Bank_Account_Format_45") except Exception as err: print("err occured") print(err) import traceback print(traceback.print_exc())