Ejemplo n.º 1
0
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"
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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"
Ejemplo n.º 7
0
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) 
Ejemplo n.º 8
0
# Get current user
print("")
print(" --- Get current user")
user = obp.getCurrentUser()
print("current user data:\n{0}".format(user))
user_id = user['user_id']
print("current user id: {0}".format(user))

our_bank = OUR_BANK  # banks[0]['id']
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'])

# Just picking first account
our_account = accounts[1]['id']
print("our account: {0}".format(our_account))

# Reload account
print("")
print(" --- Load our account data")
account_data = obp.getAccount(our_bank, our_account)
print("our account data:\n{0}".format(account_data))

print("")