def transfer(intent_request): account = intent_request['currentIntent']['slots']['account'] cpname = intent_request['currentIntent']['slots']['name'] amount = intent_request['currentIntent']['slots']['amount'] account_check=validate_account(account) if account_check=='valid': our_bank =obp.getBanks() for i in our_bank: for j in obp.getPrivateAccounts(i['id']): if (j['id']==account): bank = i['id'] our_account = obp.getAccount(bank,account) balance = our_account['balance']['amount'] if float(amount)>float(balance): message = "insufficient balance" return close(intent_request, message) cp_check = validate_counterparty(account,cpname) if cp_check == 'valid': obp.setPaymentDetails('USD',str(amount)) cp=obp.getCounterparties('cb.44.us.cb',account) cpid = "" for j in cp: if (j['name']==cpname): cpid = j['counterparty_id'] obp.createTransactionRequestV210('cb.44.us.cb',str(account),'COUNTERPARTY','cb.44.us.cb','19630908',cpid,'cb.44.us.cb') message = "Your transaction is successful" content = message + "\n Would you like to know anything?" #return close(intent_request, message) return elicit_intent(content) else: message = "Invalid Counterparty name" return close(intent_request, message) else: message = "Invalid Account number" return close(intent_request, message)
def cplist(intent_request): cpnames=[] account = intent_request['currentIntent']['slots']['account'] our_bank =obp.getBanks() m=validate_account(account) if m == 'valid': for i in our_bank: for j in obp.getPrivateAccounts(i['id']): if (j['id']==account): cp=obp.getCounterparties(i['id'],j['id']) for k in cp: cpnames.append(k['name']) print (cpnames) if (len(cpnames)==0): message = "you dont have any counter parties" return close(intent_request, message) else: data = "\n".join(cpnames) message = "your counterparties are:"+ data content = message + "\n Would you like to know anything?" #return close(intent_request, message) return elicit_intent(content) else: message = "Invalid Account Number" return close(intent_request,message)
def check_balance(intent_request): account = intent_request['currentIntent']['slots']['account'] print (account) source = intent_request['invocationSource'] if source == 'DialogCodeHook': slots = intent_request['currentIntent']['slots'] intent_name = intent_request['currentIntent']['name'] if (account == None): return elicit_slot(intent_name,slots,'account') print (account) validation_result = validate_account(account) if validation_result == 'valid': our_bank =obp.getBanks() for i in our_bank: for j in obp.getPrivateAccounts(i['id']): if (j['id']==account): bank = i['id'] our_account = obp.getAccount(bank,account) balance = our_account['balance']['amount'] print (balance) message = "Your account balance is $"+ balance mess = message + 10*" "+ "\n Would you like to know anything?" #return close(intent_request,message) return elicit_intent(mess) else: message = "Invalid Account Number" return close(intent_request,message)
def validate_counterparty(account,name): cpnames=[] our_bank =obp.getBanks() for i in our_bank: for j in obp.getPrivateAccounts(i['id']): if (j['id']==account): cp=obp.getCounterparties(i['id'],j['id']) for k in cp: cpnames.append(k['name']) if name is not None and name.lower() not in cpnames: return "invalid" else: return "valid"
def validate_account(slot_value): accounts=[] value = slot_value count = 0 our_bank =obp.getBanks() for i in our_bank: #print(i['id']) priv_acc=obp.getPrivateAccounts(i['id']) #print(len(our_bank),len(priv_acc)) for j in obp.getPrivateAccounts(i['id']): accounts.append(j['id']) if value is not None and value.lower() not in accounts: return "invalid" else: return "valid"
def listAccounts(intent_request): accounts=[] new_slot = intent_request['currentIntent']['slots'] our_bank =obp.getBanks() for i in our_bank: #print(i['id']) priv_acc=obp.getPrivateAccounts(i['id']) #print(len(our_bank),len(priv_acc)) for j in obp.getPrivateAccounts(i['id']): accounts.append(j['id']) data = '\n'.join(accounts) print (data) message = "your account numbers are : \n" + data content = message + "\n\nWould you like to know anything?" #mess = {'mystring': 'Line 1\nLine 2'} print (content) #return close(intent_request, message) #return confirm_intent( 'Balance', new_slot, content) return elicit_intent(content)
def transactions(intent_request): transactions_list=[] account = intent_request['currentIntent']['slots']['account'] our_bank =obp.getBanks() check_account=validate_account(account) if check_account == 'valid': for i in our_bank: for j in obp.getPrivateAccounts(i['id']): if (j['id']==account): details=obp.getTransactions(i['id'],j['id']) for n in details: transactions_list.append(('Time:', n['details']['completed'],'name:',n['other_account']['holder']['name'],'amount:',n['details']['value']['amount'])) if (len(transactions_list)>0): data = " \n".join(transactions_list[0]) message = "your last transaction details are:"+data content = message + "\n Would you like to know anything?" #return close(intent_request, message) return elicit_intent(content) else: message = "you dont have any transactions" return close(intent_request, message) else: message = "Invalid Account number" return close(intent_request, message)
from props.danskebank import * #from props.socgen import * # You probably don't need to change those import lib.obp obp = lib.obp obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION) # login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) obp.setCounterParty(COUNTERPARTY_BANK, OUR_COUNTERPARTY, OUR_COUNTERPARTY_ID, OUR_COUNTERPARTY_IBAN) obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) banks = obp.getBanks() our_bank = banks[0]['id'] cp_bank = obp.getCounterBankId() cp_account = obp.getCounterpartyAccountId() print("our bank: {0}".format(our_bank)) #get accounts for a specific bank print(" --- Private accounts") accounts = obp.getPrivateAccounts(our_bank) for a in accounts: print(a['id'])