From e122e9071a571e252f4e42224ae742158bf0be98 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Mon, 16 Jan 2017 00:24:53 +0100 Subject: [PATCH 01/26] Removing sandbox instructions --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index 24e46b3..f1389c1 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,3 @@ $ python hello_obp.py ```bash $ python2 hello_payments.py ``` - - -## Import Sandbox - -Edit the data to import in the script, then run: - -```bash -$ python2 import_sandbox.py -``` From 71f6de33eea322a7aa9687a64d64eeb8c615d475 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Mon, 16 Jan 2017 00:26:26 +0100 Subject: [PATCH 02/26] Update README python3 for payments --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1389c1..1585950 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,5 @@ $ python hello_obp.py ## Hello Payments ```bash -$ python2 hello_payments.py +$ python3 hello_payments.py ``` From bda78831d368f7cb0b214eae4da8e913d1e01994 Mon Sep 17 00:00:00 2001 From: Tran Tu Date: Wed, 18 Jan 2017 15:56:22 +0100 Subject: [PATCH 03/26] merged modular successfully --- .gitignore | 7 ++++++- hello_payments.py | 14 +++++++++----- import/import_sandbox.py | 6 +++--- lib/obp.py | 29 ++++++++++++++++++++++------- props/danskebank.py | 12 ++++++++++-- 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 4327856..74f0732 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,12 @@ __pycache__/ *.py[cod] *$py.class - +.gitignore~ +.project +.pydevproject +.settings/ +env2/ +env3/ # C extensions *.so diff --git a/hello_payments.py b/hello_payments.py index 6f901e9..2f93ef1 100644 --- a/hello_payments.py +++ b/hello_payments.py @@ -19,11 +19,15 @@ # login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) - +obp.setCounterPart(COUNTERPART_BANK, OUR_COUNTERPART) +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) banks = obp.getBanks() our_bank = banks[0]['id'] -cp_bank = our_bank + +cp_bank = obp.getCounterBank() +cp_account = obp.getCounterId() + print ("our bank: {0}".format(our_bank)) #get accounts for a specific bank @@ -36,7 +40,7 @@ #just picking first account our_account = accounts[0]['id'] -cp_account = accounts[1]['id'] + print ("our account: {0}".format(our_account)) print ("") @@ -58,9 +62,9 @@ if (initiate_response['challenge'] != None): #we need to answer the challenge challenge_query = initiate_response['challenge']['id'] - transation_req_id = initiate_response['id']['value'] + transaction_req_id = initiate_response['id']['value'] - challenge_response = obp.answerChallenge(bank, account, transaction_req_id, challenge_query) + challenge_response = obp.answerChallenge(our_bank, our_account, transaction_req_id, challenge_query) if "error" in challenge_response: sys.exit("Got an error: " + str(challenge_response)) diff --git a/import/import_sandbox.py b/import/import_sandbox.py index 11a506c..015c20e 100644 --- a/import/import_sandbox.py +++ b/import/import_sandbox.py @@ -38,7 +38,7 @@ }], } -print 'Posting to {0}'.format(URL_IMPORT) +print ('Posting to {0}'.format(URL_IMPORT)) response = requests.post(URL_IMPORT, json=data) -print response.status_code -print response.text +print (response.status_code) +print (response.text) diff --git a/lib/obp.py b/lib/obp.py index 76778f8..8b5595b 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -10,6 +10,17 @@ CONTENT_JSON = { 'content-type' : 'application/json' } +def setCounterPart(bank,iD): + global COUNTERPART_BANK, OUR_COUNTERPART + COUNTERPART_BANK = bank + OUR_COUNTERPART = iD + +def setPaymentDetails(currency,value): + global OUR_CURRENCY, OUR_VALUE + + OUR_CURRENCY = currency + OUR_VALUE =value + def setBaseUrl(u): global BASE_URL BASE_URL = u @@ -60,7 +71,11 @@ def requestMeeting(purpose_id, provider_id): # Print result log("code=" + response.status_code + " text=" + response.text) return response.json() +def getCounterBank(): + return COUNTERPART_BANK +def getCounterId(): + return OUR_COUNTERPART # Get banks def getBanks(): # Prepare headers @@ -106,18 +121,18 @@ def getChallengeTypes(bank, account): # Answer the challenge def answerChallenge(bank, account, transation_req_id, challenge_query): - body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode - response = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( - BASE_URL, bank, account, transation_req_id), data=body, headers=merge(DL_TOKEN, CONTENT_JSON) - ) - return response.json + body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode + response = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( + BASE_URL, bank, account, transation_req_id), data=body, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON) + ) + return response.json def getTransactionRequest(bank, account, transation_req_id): response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transactions".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json -def initiateTransactionRequest(bank, account, challenge_type): - send_to = {"bank": COUNTERPART_BANK, "account": OUR_COUNTERPART} +def initiateTransactionRequest(bank, account, challenge_type, cp_bank, cp_account): + send_to = {"bank": cp_bank, "account": cp_account} payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ challenge_type + '"}' diff --git a/props/danskebank.py b/props/danskebank.py index b894d39..20428c1 100644 --- a/props/danskebank.py +++ b/props/danskebank.py @@ -1,4 +1,10 @@ +# -*- coding: utf-8 -*- +""" +Settings for the hello scripts. +You most likely need to edit a few of them, e.g. API_HOST and the OAuth +credentials. +""" OUR_BANK = 'dan.01.uk.uk' @@ -16,8 +22,8 @@ CALLBACK_URI = 'http://127.0.0.1/cb' # Our counterpart account id (of the same currency) -OUR_COUNTERPART = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' -COUNTERPART_BANK = 'gh.29.uk' +OUR_COUNTERPART = 'be4c3b50-fa7a-4e38-989b-e6d3c874a368' +COUNTERPART_BANK = 'dan.01.uk.uk' # Our currency to use OUR_CURRENCY = 'GBP' @@ -26,3 +32,5 @@ # values below 1000 do not requre challenge request OUR_VALUE = '0.01' OUR_VALUE_LARGE = '1000.00' +PAYMENT_DESCRIPTION = 'Hello Payments v2.1!' + From 4210471b7ac533116528904a504aa8f4b3b70986 Mon Sep 17 00:00:00 2001 From: Petar Bozin Date: Wed, 15 Feb 2017 17:43:41 +0100 Subject: [PATCH 04/26] Code update and cleanup, added props for socgen2-k --- .gitignore | 1 - hello_obp.py | 34 +++++++++++++++++++++++++++------- hello_payments.py | 10 +++++++--- lib/obp.py | 12 +++++++++++- props/socgen.py | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 props/socgen.py diff --git a/.gitignore b/.gitignore index 74f0732..897062d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ dist/ downloads/ eggs/ .eggs/ -lib64/ parts/ sdist/ var/ diff --git a/hello_obp.py b/hello_obp.py index ea47e0f..804a9f2 100644 --- a/hello_obp.py +++ b/hello_obp.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import print_function # (at top of module) -import sys, requests +import sys, time, requests # Note: in order to use this example, you need to have at least one account @@ -9,6 +9,7 @@ # All properties are now kept in one central place from props.danskebank import * +#from props.socgen import * @@ -38,18 +39,21 @@ #just picking first account our_account = accounts[0]['id'] print ("our account: {0}".format(our_account)) - print ("") -print (" --- Get owner transactions") -transactions = obp.getTransactions(our_bank, our_account) -print ("Got {0} transactions".format(len(transactions))) - +#reload account +account_data = obp.getAccount(our_bank, our_account) +print (" --- Load our account data") +print ("our account data:\n{0}".format(account_data)) +print ("") +print (" --- Modify account label") +new_label = "New label %s" % time.strftime("%d/%m/%Y %I:%M:%S") +print(new_label) # Prepare post data and set new label value post_data = { 'id' : '%s' % our_account, - 'label' : 'New label', + 'label' : '%s' % new_label, 'bank_id': '%s' % OUR_BANK } @@ -57,5 +61,21 @@ response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}".format(BASE_URL, API_VERSION, our_bank, our_account), json=post_data, headers=obp.mergeHeaders(obp.DL_TOKEN, obp.CONTENT_JSON)) # Print result +print ("") print(response.status_code) print(response.text) + +#reload account again for comparison +account = obp.getAccount(our_bank, our_account) +print ("") +print (" --- Reload account data") +print ("our account data after label update:\n{0}".format(account)) + + +print ("") +print (" --- Get owner transactions") +transactions = obp.getTransactions(our_bank, our_account) +print ("Got {0} transactions".format(len(transactions))) +for t in transactions: + print ('{0} ({1} {2})'.format(t['id'], t['details']['value']['currency'], t['details']['value']['amount'])) + diff --git a/hello_payments.py b/hello_payments.py index 2f93ef1..fb38cf1 100644 --- a/hello_payments.py +++ b/hello_payments.py @@ -9,6 +9,7 @@ # All properties are now kept in one central place from props.danskebank import * +#from props.socgen import * # You probably don't need to change those import lib.obp @@ -49,11 +50,13 @@ print ("Got {0} transactions".format(len(transactions))) print (" --- Get challenge request types") -challenge_type = obp.getChallengeTypes(our_bank, our_account) +challenge_types = obp.getChallengeTypes(our_bank, our_account) +print (challenge_types) +challenge_type = challenge_types[0] print (challenge_type) print ("") -print ("Initiate transaction requesti (small value)") +print ("Initiate transaction request (small value)") initiate_response = obp.initiateTransactionRequest(our_bank, our_account, challenge_type, cp_bank, cp_account) if "error" in initiate_response: @@ -72,5 +75,6 @@ print ("Transaction created: {0}".format(challenge_response["transaction_ids"])) else: #There was no challenge, transaction was created immediately - print ("Transaction was successfully created: {0}".format(initiate_response["transaction_ids"])) + print ("Transaction was successfully created:") + print ("{0}".format(initiate_response)) diff --git a/lib/obp.py b/lib/obp.py index 8b5595b..7e29fa5 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -109,6 +109,12 @@ def getPrivateAccounts(bank): response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/private".format(BASE_URL, API_VERSION, bank), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json()['accounts'] +# Get a single account +def getAccount(bank, account): + # Prepare headers + response = requests.get(u"{0}/obp/{1}/my/banks/{2}/accounts/{3}/account".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + return response.json() + # Get owner's transactions def getTransactions(bank, account): response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transactions".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) @@ -117,7 +123,11 @@ def getTransactions(bank, account): # Get challenge types def getChallengeTypes(bank, account): response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) - return response.json()[0]['value'] + types = response.json()['transaction_request_types'] + res = [] + for type in types: + res.append(type['value']) + return res # Answer the challenge def answerChallenge(bank, account, transation_req_id, challenge_query): diff --git a/props/socgen.py b/props/socgen.py new file mode 100644 index 0000000..11c569a --- /dev/null +++ b/props/socgen.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +""" +Settings for the hello scripts. + +You most likely need to edit a few of them, e.g. API_HOST and the OAuth +credentials. +""" + +OUR_BANK = '00100' + +USERNAME = '1000203893' +PASSWORD = '1000203893' +CONSUMER_KEY = 'bvldezvlnqj4mtva4jfktke4xliep0bt1xm44yxi' +CONSUMER_SECRET = 'fgwo35uhkroebasxlqgzjjcc0cf1yaujuynkwodz' + +# API server URL +BASE_URL = 'https://socgen2-k-api.openbankproject.com' +API_VERSION = "v2.1.0" + +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'http://127.0.0.1/cb' + +# Our counterpart account id (of the same currency) +OUR_COUNTERPART = '3806441b-bbdf-3c60-b2b3-14e2f645635f' +COUNTERPART_BANK = '00100' + +# Our currency to use +OUR_CURRENCY = 'XAF' + +# Our value to transfer +# values below 1000 do not requre challenge request +OUR_VALUE = '0.01' +OUR_VALUE_LARGE = '1000.00' +PAYMENT_DESCRIPTION = 'Hello Payments v2.1!' From 4f87a32e0e93541efe73e3e385cbbe23c1c6e6c3 Mon Sep 17 00:00:00 2001 From: Petar Bozin Date: Wed, 15 Feb 2017 20:18:44 +0100 Subject: [PATCH 05/26] Added hello_set_entitlements.py --- hello_obp.py | 21 ++++++++---- hello_set_entitlements.py | 69 +++++++++++++++++++++++++++++++++++++++ lib/obp.py | 53 ++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 hello_set_entitlements.py diff --git a/hello_obp.py b/hello_obp.py index 804a9f2..2f87cbf 100644 --- a/hello_obp.py +++ b/hello_obp.py @@ -20,15 +20,21 @@ obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION) -# login and set authorized token +# Login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) -#banks = obp.getBanks() +# 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 +# Get accounts for a specific bank print (" --- Private accounts") accounts = obp.getPrivateAccounts(our_bank) @@ -36,13 +42,14 @@ for a in accounts: print (a['id']) -#just picking first account +# Just picking first account our_account = accounts[0]['id'] print ("our account: {0}".format(our_account)) + +# Reload account print ("") -#reload account -account_data = obp.getAccount(our_bank, our_account) print (" --- Load our account data") +account_data = obp.getAccount(our_bank, our_account) print ("our account data:\n{0}".format(account_data)) print ("") @@ -65,7 +72,7 @@ print(response.status_code) print(response.text) -#reload account again for comparison +# Reload account again for comparison account = obp.getAccount(our_bank, our_account) print ("") print (" --- Reload account data") diff --git a/hello_set_entitlements.py b/hello_set_entitlements.py new file mode 100644 index 0000000..07c7800 --- /dev/null +++ b/hello_set_entitlements.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +from __future__ import print_function # (at top of module) +import sys, time, requests + + +# Note: in order to use this example, you need to have at least one account +# that you can send money from (i.e. be the owner). +# All properties are now kept in one central place + +from props.danskebank import * +#from props.socgen import * + +ROLES=['CanQueryOtherUser'] +ENTITLEMENTS=['CanQueryOtherUser'] + +# 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) + +# Get all entitlements +print ("") +print (" --- Get user's entitlements") +all_entitlements = obp.getAllEntitlements() +print ("all entitlements:\n{0}".format(all_entitlements)) + +# Get current user +print ("") +print (" --- Get current user") +user = obp.getCurrentUser() +user_id = user['user_id'] +print ("current user id: {0}".format(user)) + +# Get user entitlements +print ("") +print (" --- Get user's entitlements") +entitlements = obp.getAllEntitlements() +if 'error' not in entitlements: + print ("user {0} entitlements:\n{1}".format(user_id, entitlements)) +else: + + # Add CanGetEntitlementsForAnyUserAtOneBank entitlement + print ("") + print (" --- Add CanGetEntitlementsForAnyUserAtAnyBank entitlement") + response = obp.addEntitlement('CanGetEntitlementsForAnyUserAtAnyBank', user_id, OUR_BANK) + print ("response:\n{0}".format(response)) + + +# Add system roles from list +for role in ROLES: + print ("") + print (" --- Add {0} role".format(role)) + response = obp.addRole(role, user_id) + print ("response:\n{0}".format(response)) + +# Add entitlements from list +for entitlement in ENTITLEMENTS: + print ("") + print (" --- Add {0} entitlement".format(entitlement)) + response = obp.addEntitlement(entitlement, user_id, OUR_BANK) + print ("response:\n{0}".format(response)) + +print ("") diff --git a/lib/obp.py b/lib/obp.py index 7e29fa5..ceb3a0e 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -71,11 +71,13 @@ def requestMeeting(purpose_id, provider_id): # Print result log("code=" + response.status_code + " text=" + response.text) return response.json() + def getCounterBank(): return COUNTERPART_BANK def getCounterId(): return OUR_COUNTERPART + # Get banks def getBanks(): # Prepare headers @@ -149,3 +151,54 @@ def initiateTransactionRequest(bank, account, challenge_type, cp_bank, cp_accoun response = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format(BASE_URL, bank, account, challenge_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json() +# Create counterparty +def createCounterparty(bank, account, name): + post_data = { + 'name' : '%s' % name, + 'other_bank_id' : '%s' % bank, + 'other_account_id' : '%s' % account, + 'other_account_provider' : '%s' % 'OBP', + 'other_account_routing_scheme' : '%s' '', + 'other_account_routing_address': '%s' '', + 'other_bank_routing_scheme' : '%s' '', + 'other_bank_routing_address' : '%s' '', + 'is_beneficiary' : true + } + # Send post request with attached json + response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/counterparties".format(BASE_URL, API_VERSION), json=post_data, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + # Log result + log("code=" + response.status_code + " text=" + response.text) + return response.json() + +# Get all entitlements +def getAllEntitlements(): + response = requests.get(u"{0}/obp/{1}/entitlements".format(BASE_URL, API_VERSION), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + return response.json() + +# Get user's entitlements +def getEntitlements(user, bank): + response = requests.get(u"{0}/obp/{1}/banks/{2}/users/{3}/entitlements".format(BASE_URL, API_VERSION, bank, user), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + return response.json() + +# Add system role to user +def addRole(role, user): + post_data = { + 'bank_id' : '', + 'role_name' : '%s' % role + } + # Send post request with attached json + response = requests.post(u"{0}/obp/{1}/users/{2}/entitlements".format(BASE_URL, API_VERSION, user), json=post_data, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + # Log result + return response.text + +# Add entitlement to user +def addEntitlement(entitlement, user, bank=''): + post_data = { + 'bank_id' : '%s' % bank, + 'role_name' : '%s' % entitlement + } + # Send post request with attached json + response = requests.post(u"{0}/obp/{1}/users/{2}/entitlements".format(BASE_URL, API_VERSION, user), json=post_data, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + # Log result + return response.text + From 0bee73e431758c2fc1b81869c2dd3377011c4e14 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Sun, 19 Feb 2017 00:34:26 +0100 Subject: [PATCH 06/26] Added TODO --- hello_payments.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hello_payments.py b/hello_payments.py index fb38cf1..951865d 100644 --- a/hello_payments.py +++ b/hello_payments.py @@ -18,6 +18,10 @@ obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION) + +# TODO Refactor to use the word Counterparty instead of Counterpart etc. + + # login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) obp.setCounterPart(COUNTERPART_BANK, OUR_COUNTERPART) From 34af72e80187ff3dd7f846af19c6dabe985ff2df Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Wed, 1 Mar 2017 09:54:54 +0100 Subject: [PATCH 07/26] #6 Make sure the word "counterparty" is used, replaced all the counterpart --- hello_payments.py | 5 +---- lib/obp.py | 12 ++++++------ old/hello_payments.py | 6 +++--- old/hello_payments_v1.py | 4 ++-- old/hello_payments_v210.py | 18 ++++++++++++------ props/danskebank.py | 6 +++--- props/default.py | 6 +++--- props/socgen.py | 6 +++--- 8 files changed, 33 insertions(+), 30 deletions(-) diff --git a/hello_payments.py b/hello_payments.py index 951865d..784330d 100644 --- a/hello_payments.py +++ b/hello_payments.py @@ -19,12 +19,9 @@ obp.setApiVersion(API_VERSION) -# TODO Refactor to use the word Counterparty instead of Counterpart etc. - - # login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) -obp.setCounterPart(COUNTERPART_BANK, OUR_COUNTERPART) +obp.setCounterParty(COUNTERPARTY_BANK, OUR_COUNTERPARTY) obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) banks = obp.getBanks() diff --git a/lib/obp.py b/lib/obp.py index ceb3a0e..ac329b6 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -10,10 +10,10 @@ CONTENT_JSON = { 'content-type' : 'application/json' } -def setCounterPart(bank,iD): - global COUNTERPART_BANK, OUR_COUNTERPART - COUNTERPART_BANK = bank - OUR_COUNTERPART = iD +def setCounterParty(bank, iD): + global COUNTERPARTY_BANK, OUR_COUNTERPARTY + COUNTERPARTY_BANK = bank + OUR_COUNTERPARTY = iD def setPaymentDetails(currency,value): global OUR_CURRENCY, OUR_VALUE @@ -73,10 +73,10 @@ def requestMeeting(purpose_id, provider_id): return response.json() def getCounterBank(): - return COUNTERPART_BANK + return COUNTERPARTY_BANK def getCounterId(): - return OUR_COUNTERPART + return OUR_COUNTERPARTY # Get banks def getBanks(): diff --git a/old/hello_payments.py b/old/hello_payments.py index 2bc76a5..0f6ebfa 100644 --- a/old/hello_payments.py +++ b/old/hello_payments.py @@ -6,7 +6,7 @@ # that you can send money from (i.e. be the owner). # All properties are now kept in one central place -from lib.danskebank import * +from props.danskebank import * # You probably don't need to change those LOGIN_URL = '{0}/my/logins/direct'.format(BASE_URL) @@ -73,7 +73,7 @@ def merge(x, y): print ("") print ("Initiate transaction requesti (small value)") -send_to = {"bank": COUNTERPART_BANK, "account": OUR_COUNTERPART} +send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ challenge_type + '"}' @@ -108,7 +108,7 @@ def merge(x, y): #print #print "Initiate transaction request (large value)" -#send_to = {"bank": COUNTERPART_BANK, "account": OUR_COUNTERPART} +#send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} #payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ # '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE_LARGE + '"}, "description": "Description abc", "challenge_type" : "' + \ # challenge_type + '"}' diff --git a/old/hello_payments_v1.py b/old/hello_payments_v1.py index 2942ca8..0f6ebfa 100644 --- a/old/hello_payments_v1.py +++ b/old/hello_payments_v1.py @@ -73,7 +73,7 @@ def merge(x, y): print ("") print ("Initiate transaction requesti (small value)") -send_to = {"bank": COUNTERPART_BANK, "account": OUR_COUNTERPART} +send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ challenge_type + '"}' @@ -108,7 +108,7 @@ def merge(x, y): #print #print "Initiate transaction request (large value)" -#send_to = {"bank": COUNTERPART_BANK, "account": OUR_COUNTERPART} +#send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} #payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ # '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE_LARGE + '"}, "description": "Description abc", "challenge_type" : "' + \ # challenge_type + '"}' diff --git a/old/hello_payments_v210.py b/old/hello_payments_v210.py index f319cc1..9e56cde 100644 --- a/old/hello_payments_v210.py +++ b/old/hello_payments_v210.py @@ -1,7 +1,13 @@ # -*- coding: utf-8 -*- from __future__ import print_function # (at top of module) -import obp +import lib.obp,requests +obp = lib.obp +# Helper function to merge headers +def merge(x, y): + z = x.copy() + z.update(y) + return z # Note: in order to use this example, you need to have at least one account # that you can send money from (i.e. be the owner). @@ -16,9 +22,9 @@ BASE_URL = "https://apisandbox.openbankproject.com" API_VERSION = "v1.4.0" -# Our counterpart account id (of the same currency) -OUR_COUNTERPART = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' -COUNTERPART_BANK = 'gh.29.uk' +# Our COUNTERPARTY account id (of the same currency) +OUR_COUNTERPARTY = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' +COUNTERPARTY_BANK = 'gh.29.uk' # Our currency to use OUR_CURRENCY = 'GBP' @@ -75,7 +81,7 @@ print ("") print ("Initiate transaction requesti (small value)") -send_to = {"bank": COUNTERPART_BANK, "account": OUR_COUNTERPART} +send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ challenge_type + '"}' @@ -110,7 +116,7 @@ #print #print "Initiate transaction request (large value)" -#send_to = {"bank": COUNTERPART_BANK, "account": OUR_COUNTERPART} +#send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} #payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ # '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE_LARGE + '"}, "description": "Description abc", "challenge_type" : "' + \ # challenge_type + '"}' diff --git a/props/danskebank.py b/props/danskebank.py index 20428c1..4c12e51 100644 --- a/props/danskebank.py +++ b/props/danskebank.py @@ -21,9 +21,9 @@ # You will paste the redirect location here when running the script CALLBACK_URI = 'http://127.0.0.1/cb' -# Our counterpart account id (of the same currency) -OUR_COUNTERPART = 'be4c3b50-fa7a-4e38-989b-e6d3c874a368' -COUNTERPART_BANK = 'dan.01.uk.uk' +# Our COUNTERPARTY account id (of the same currency) +OUR_COUNTERPARTY = 'be4c3b50-fa7a-4e38-989b-e6d3c874a368' +COUNTERPARTY_BANK = 'dan.01.uk.uk' # Our currency to use OUR_CURRENCY = 'GBP' diff --git a/props/default.py b/props/default.py index e787d4e..f034954 100644 --- a/props/default.py +++ b/props/default.py @@ -14,9 +14,9 @@ # You will paste the redirect location here when running the script CALLBACK_URI = 'http://127.0.0.1/cb' -# Our counterpart account id (of the same currency) -OUR_COUNTERPART = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' -COUNTERPART_BANK = 'gh.29.uk' +# Our COUNTERPARTY account id (of the same currency) +OUR_COUNTERPARTY = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' +COUNTERPARTY_BANK = 'gh.29.uk' # Our currency to use OUR_CURRENCY = 'GBP' diff --git a/props/socgen.py b/props/socgen.py index 11c569a..84a0aec 100644 --- a/props/socgen.py +++ b/props/socgen.py @@ -21,9 +21,9 @@ # You will paste the redirect location here when running the script CALLBACK_URI = 'http://127.0.0.1/cb' -# Our counterpart account id (of the same currency) -OUR_COUNTERPART = '3806441b-bbdf-3c60-b2b3-14e2f645635f' -COUNTERPART_BANK = '00100' +# Our COUNTERPARTY account id (of the same currency) +OUR_COUNTERPARTY = '3806441b-bbdf-3c60-b2b3-14e2f645635f' +COUNTERPARTY_BANK = '00100' # Our currency to use OUR_CURRENCY = 'XAF' From ab69b82f102c30fc2259723e2d1d6b194dd0d700 Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Wed, 1 Mar 2017 14:29:42 +0100 Subject: [PATCH 08/26] #8 add V210 - Create Transaction Requests --- hello_payments-V210.py | 171 +++++++++++++++++++++++++++++++++++++++++ hello_payments.py | 8 +- lib/obp.py | 58 ++++++++++++-- props/danskebank.py | 3 + props/default.py | 4 + props/localtest.py | 31 ++++++++ props/socgen.py | 4 + 7 files changed, 267 insertions(+), 12 deletions(-) create mode 100644 hello_payments-V210.py create mode 100644 props/localtest.py diff --git a/hello_payments-V210.py b/hello_payments-V210.py new file mode 100644 index 0000000..729e67a --- /dev/null +++ b/hello_payments-V210.py @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests + +# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN, SEPA, COUNTERPARTY + +# Note: in order to use this example, you need to have at least one account that you can send money from (i.e. be the owner). +# And another account to receiver money(the Counterparty fields should be correct) +# All properties are now kept in 'localtest.py', you need set up your own props. + +#########################Step 1 : Login in(OAuth process) and prepare the bankaccounts to make the payment.################ +# You probably don't need to change those +from props.localtest import * +import lib.obp + +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) +obp.setCounterParty(COUNTERPARTY_BANK, OUR_COUNTERPARTY, OUR_COUNTERPARTY_ID, OUR_COUNTERPARTY_IBAN) + +# login and set authorized token +obp.login(USERNAME, PASSWORD, CONSUMER_KEY) +banks = obp.getBanks() +# get a bank id +our_bank = banks[1]['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[0]['id'] +print("our account: {0}".format(our_account)) + +#get reciver bankaccount info (the counterparty fields) +cp_bank = obp.getCounterBankId() +cp_account = obp.getCounterpartyAccountId() +cp_cunterparty_id = obp.getCunterpartyId() +cp_cunterparty_iban = obp.getCunterpartyIban() + +# check all request types,now support: SANDBOX_TAN, SEPA, COUNTERPARTY and FREE_FORM +print(" --- Get challenge request types") +challenge_types = obp.getChallengeTypes(our_bank, our_account) +print(challenge_types) + +######################### Step2 - make a payment - SANDBOX_TAN ################ +print("") +print("") +challenge_type_sandbox_tan = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) +#####Case1: without challenge +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sandbox_tan, cp_bank, cp_account, + cp_cunterparty_id, cp_cunterparty_iban) +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sandbox_tan, cp_bank, cp_account, + cp_cunterparty_id, cp_cunterparty_iban) +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(our_bank, our_account, transaction_req_id, challenge_type_sandbox_tan, challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) + +######################### Step3 - make a payment - SEPA ################ +print("") +print("") +challenge_type_sepa = "SEPA" + +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) +#####Case1: without challenge +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sepa, cp_bank, cp_account, cp_cunterparty_id, + cp_cunterparty_iban) +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sepa, cp_bank, cp_account, cp_cunterparty_id, + cp_cunterparty_iban) +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(our_bank, our_account, transaction_req_id, challenge_type_sepa, challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) + +######################### Step4 - make a payment - COUNTERPARTY ################ +print("") +print("") +challenge_type_counterparty = "COUNTERPARTY" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) +#####Case1: without challenge +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_counterparty, cp_bank, cp_account, + cp_cunterparty_id, cp_cunterparty_iban) +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_counterparty, cp_bank, cp_account, + cp_cunterparty_id, cp_cunterparty_iban) +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(our_bank, our_account, transaction_req_id, challenge_type_counterparty, challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) diff --git a/hello_payments.py b/hello_payments.py index 784330d..e11d4ef 100644 --- a/hello_payments.py +++ b/hello_payments.py @@ -21,14 +21,14 @@ # login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) -obp.setCounterParty(COUNTERPARTY_BANK, OUR_COUNTERPARTY) -obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +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.getCounterBank() -cp_account = obp.getCounterId() +cp_bank = obp.getCounterBankId() +cp_account = obp.getCounterpartyAccountId() print ("our bank: {0}".format(our_bank)) diff --git a/lib/obp.py b/lib/obp.py index ac329b6..01351e3 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -10,10 +10,12 @@ CONTENT_JSON = { 'content-type' : 'application/json' } -def setCounterParty(bank, iD): - global COUNTERPARTY_BANK, OUR_COUNTERPARTY - COUNTERPARTY_BANK = bank - OUR_COUNTERPARTY = iD +def setCounterParty(bank_id, account_id,counterparty_id, counterparty_iban): + global COUNTERPARTY_BANK, OUR_COUNTERPARTY, OUR_COUNTERPARTY_ID, OUR_COUNTERPARTY_IBAN + COUNTERPARTY_BANK = bank_id + OUR_COUNTERPARTY = account_id + OUR_COUNTERPARTY_ID = counterparty_id + OUR_COUNTERPARTY_IBAN = counterparty_iban def setPaymentDetails(currency,value): global OUR_CURRENCY, OUR_VALUE @@ -72,12 +74,18 @@ def requestMeeting(purpose_id, provider_id): log("code=" + response.status_code + " text=" + response.text) return response.json() -def getCounterBank(): +def getCounterBankId(): return COUNTERPARTY_BANK -def getCounterId(): +def getCounterpartyAccountId(): return OUR_COUNTERPARTY +def getCunterpartyId(): + return OUR_COUNTERPARTY_ID + +def getCunterpartyIban(): + return OUR_COUNTERPARTY_IBAN + # Get banks def getBanks(): # Prepare headers @@ -129,7 +137,7 @@ def getChallengeTypes(bank, account): res = [] for type in types: res.append(type['value']) - return res + return res # Answer the challenge def answerChallenge(bank, account, transation_req_id, challenge_query): @@ -137,7 +145,7 @@ def answerChallenge(bank, account, transation_req_id, challenge_query): response = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( BASE_URL, bank, account, transation_req_id), data=body, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON) ) - return response.json + return response.json() def getTransactionRequest(bank, account, transation_req_id): response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transactions".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) @@ -202,3 +210,37 @@ def addEntitlement(entitlement, user, bank=''): # Log result return response.text + + +# Answer Transaction Request Challenge. - V210 +def answerChallengeV210(bank, account, transation_req_id, challenge_type, challenge_query): + body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode + response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests/{5}/challenge".format( + BASE_URL, API_VERSION, bank, account, challenge_type, transation_req_id), data=body, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON) + ) + return response.json() + +# Create Transaction Request. - V210 +# Note : previous called 'initiateTransactionRequest', now keep it the same and OBP-API endpoint name +def createTransactionRequestV210(bank, account, challenge_type, cp_bank, cp_account,cp_cunterparty_id, cp_cunterparty_iban): + if(challenge_type=="SANDBOX_TAN"): + send_to = {"bank": cp_bank, "account": cp_account} + payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ + '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc"}' + elif(challenge_type=="SEPA"): + send_to = {"iban": cp_cunterparty_iban} + payload = '{"to": {"iban": "' + send_to['iban'] +\ + '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "charge_policy" : "' + \ + "SHARED" + '"}' + elif (challenge_type=="COUNTERPARTY"): + send_to = {"counterparty_id": cp_cunterparty_id} + payload = '{"to": {"counterparty_id": "' + send_to['counterparty_id'] + \ + '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "charge_policy" : "' + \ + "SHARED" + '"}' + else: # FREE_FORM + send_to = {"bank": cp_bank, "account": cp_account} + payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ + '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ + challenge_type + '"}' + response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests".format(BASE_URL, API_VERSION, bank, account, challenge_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + return response.json() \ No newline at end of file diff --git a/props/danskebank.py b/props/danskebank.py index 4c12e51..ec7bc25 100644 --- a/props/danskebank.py +++ b/props/danskebank.py @@ -24,6 +24,9 @@ # Our COUNTERPARTY account id (of the same currency) OUR_COUNTERPARTY = 'be4c3b50-fa7a-4e38-989b-e6d3c874a368' COUNTERPARTY_BANK = 'dan.01.uk.uk' +# this following two fields are just used in V210 +OUR_COUNTERPARTY_ID = '' +OUR_COUNTERPARTY_IBAN = '' # Our currency to use OUR_CURRENCY = 'GBP' diff --git a/props/default.py b/props/default.py index f034954..256ec0c 100644 --- a/props/default.py +++ b/props/default.py @@ -17,6 +17,10 @@ # Our COUNTERPARTY account id (of the same currency) OUR_COUNTERPARTY = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' COUNTERPARTY_BANK = 'gh.29.uk' +# this following two fields are just used in V210 +OUR_COUNTERPARTY_ID = '' +OUR_COUNTERPARTY_IBAN = '' + # Our currency to use OUR_CURRENCY = 'GBP' diff --git a/props/localtest.py b/props/localtest.py new file mode 100644 index 0000000..f7f34a7 --- /dev/null +++ b/props/localtest.py @@ -0,0 +1,31 @@ +# This is just for local test, you need first run the OBP-API locally, +# and maybe prepare the CONSUMER_KEY, OUR_COUNTERPARTY_ACCOUNT_ID, OUR_COUNTERPARTY_ID, OUR_COUNTERPARTY_IBAN locall + +OUR_BANK = 'gh.29.uk' + +USERNAME = 'susan.uk.29@example.com' +PASSWORD = '2b78e8' +CONSUMER_KEY = '3ru5q4x4bfdeicdqpxwrylujtmwfj5r1m2gluaef' + +# API server URL +BASE_URL = "http://127.0.0.1:8080" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" + +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'http://127.0.0.1/cb' + +# Our COUNTERPARTY account (the same currency) +COUNTERPARTY_BANK = 'gh.29.uk' +OUR_COUNTERPARTY = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' +OUR_COUNTERPARTY_ID = '7825c891-df3d-466e-aaae-38fed8c0c68e' +OUR_COUNTERPARTY_IBAN = 'DE12 1234 5123 4510 2207 8077 877' + +# Our currency to use +OUR_CURRENCY = 'GBP' + +# Our value to transfer +# values below 1000 do not require challenge request +OUR_VALUE = '0.01' +OUR_VALUE_LARGE = '1001.00' diff --git a/props/socgen.py b/props/socgen.py index 84a0aec..c70d221 100644 --- a/props/socgen.py +++ b/props/socgen.py @@ -24,6 +24,10 @@ # Our COUNTERPARTY account id (of the same currency) OUR_COUNTERPARTY = '3806441b-bbdf-3c60-b2b3-14e2f645635f' COUNTERPARTY_BANK = '00100' +# this following two fields are just used in V210 +OUR_COUNTERPARTY_ID = '' +OUR_COUNTERPARTY_IBAN = '' + # Our currency to use OUR_CURRENCY = 'XAF' From d6226aec398d393d22da85d3a0f6cc39d1d896dd Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Tue, 7 Mar 2017 12:37:46 +0100 Subject: [PATCH 09/26] #8 add V210 - Create Transaction Requests --added kafka --- hello_payments-V210.py | 171 --------------- hello_payments_V210_kafka.py | 197 +++++++++++++++++ hello_payments_V210_mapper.py | 222 ++++++++++++++++++++ lib/obp.py | 65 +++--- props/localtest_kafka.py | 33 +++ props/{localtest.py => localtest_mapper.py} | 25 ++- 6 files changed, 506 insertions(+), 207 deletions(-) delete mode 100644 hello_payments-V210.py create mode 100644 hello_payments_V210_kafka.py create mode 100644 hello_payments_V210_mapper.py create mode 100644 props/localtest_kafka.py rename props/{localtest.py => localtest_mapper.py} (68%) diff --git a/hello_payments-V210.py b/hello_payments-V210.py deleted file mode 100644 index 729e67a..0000000 --- a/hello_payments-V210.py +++ /dev/null @@ -1,171 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function # (at top of module) -import sys, requests - -# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN, SEPA, COUNTERPARTY - -# Note: in order to use this example, you need to have at least one account that you can send money from (i.e. be the owner). -# And another account to receiver money(the Counterparty fields should be correct) -# All properties are now kept in 'localtest.py', you need set up your own props. - -#########################Step 1 : Login in(OAuth process) and prepare the bankaccounts to make the payment.################ -# You probably don't need to change those -from props.localtest import * -import lib.obp - -obp = lib.obp -obp.setBaseUrl(BASE_URL) -obp.setApiVersion(API_VERSION_V210) -obp.setCounterParty(COUNTERPARTY_BANK, OUR_COUNTERPARTY, OUR_COUNTERPARTY_ID, OUR_COUNTERPARTY_IBAN) - -# login and set authorized token -obp.login(USERNAME, PASSWORD, CONSUMER_KEY) -banks = obp.getBanks() -# get a bank id -our_bank = banks[1]['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[0]['id'] -print("our account: {0}".format(our_account)) - -#get reciver bankaccount info (the counterparty fields) -cp_bank = obp.getCounterBankId() -cp_account = obp.getCounterpartyAccountId() -cp_cunterparty_id = obp.getCunterpartyId() -cp_cunterparty_iban = obp.getCunterpartyIban() - -# check all request types,now support: SANDBOX_TAN, SEPA, COUNTERPARTY and FREE_FORM -print(" --- Get challenge request types") -challenge_types = obp.getChallengeTypes(our_bank, our_account) -print(challenge_types) - -######################### Step2 - make a payment - SANDBOX_TAN ################ -print("") -print("") -challenge_type_sandbox_tan = "SANDBOX_TAN" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) -#####Case1: without challenge -print("create transaction request small value (without challenge)") -# set up a small value in payment detail -obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint -initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sandbox_tan, cp_bank, cp_account, - cp_cunterparty_id, cp_cunterparty_iban) -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) - -#####Case2: with challenge -print("") -print("create transaction request large value (with challenge)") -# set up a large value in payment detail -obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint -initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sandbox_tan, cp_bank, cp_account, - cp_cunterparty_id, cp_cunterparty_iban) -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# we need to answer the challenge -challenge_query = initiate_response['challenge']['id'] -transaction_req_id = initiate_response['id'] - -challenge_response = obp.answerChallengeV210(our_bank, our_account, transaction_req_id, challenge_type_sandbox_tan, challenge_query) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) - -######################### Step3 - make a payment - SEPA ################ -print("") -print("") -challenge_type_sepa = "SEPA" - -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) -#####Case1: without challenge -print("create transaction request small value (without challenge)") -# set up a small value in payment detail -obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint -initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sepa, cp_bank, cp_account, cp_cunterparty_id, - cp_cunterparty_iban) -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) - -#####Case2: with challenge -print("") -print("create transaction request large value (with challenge)") -# set up a large value in payment detail -obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint -initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_sepa, cp_bank, cp_account, cp_cunterparty_id, - cp_cunterparty_iban) -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# we need to answer the challenge -challenge_query = initiate_response['challenge']['id'] -transaction_req_id = initiate_response['id'] - -challenge_response = obp.answerChallengeV210(our_bank, our_account, transaction_req_id, challenge_type_sepa, challenge_query) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) - -######################### Step4 - make a payment - COUNTERPARTY ################ -print("") -print("") -challenge_type_counterparty = "COUNTERPARTY" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) -#####Case1: without challenge -print("create transaction request small value (without challenge)") -# set up a small value in payment detail -obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint -initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_counterparty, cp_bank, cp_account, - cp_cunterparty_id, cp_cunterparty_iban) -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) - -#####Case2: with challenge -print("") -print("create transaction request large value (with challenge)") -# set up a large value in payment detail -obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint -initiate_response = obp.createTransactionRequestV210(our_bank, our_account, challenge_type_counterparty, cp_bank, cp_account, - cp_cunterparty_id, cp_cunterparty_iban) -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# we need to answer the challenge -challenge_query = initiate_response['challenge']['id'] -transaction_req_id = initiate_response['id'] - -challenge_response = obp.answerChallengeV210(our_bank, our_account, transaction_req_id, challenge_type_counterparty, challenge_query) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) diff --git a/hello_payments_V210_kafka.py b/hello_payments_V210_kafka.py new file mode 100644 index 0000000..54b997a --- /dev/null +++ b/hello_payments_V210_kafka.py @@ -0,0 +1,197 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests + +# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN, SEPA, COUNTERPARTY (kafka) + +# Note: in order to use this example, you need to have at least one account that you can send money from (i.e. be the owner). +# And another account to receiver money(toBankAccount and toCounterparty fields should be correct) +# All properties are now kept in 'localtest_kafka.py',you need set up your own props. + +#########################Step 1 : Login in(OAuth process) and prepare the bankaccounts to make the payment.################ +# You probably don't need to change those +# connector=mapped +from props.localtest_kafka import * +import lib.obp + +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +# login and set authorized token +obp.login(USERNAME, PASSWORD, CONSUMER_KEY) + +# set fromAccount info: +from_bank_id = FROM_BANK_ID +from_account_id = FROM_ACCOUNT_ID + +# check all request types,now support: SANDBOX_TAN, SEPA, COUNTERPARTY and FREE_FORM +print("Get support Transaction Request Types :") +transaction_request_type = obp.getChallengeTypes(from_bank_id, from_account_id) +print(transaction_request_type) + +######################### Step2 - make a payment - SANDBOX_TAN ################ +print("") +print("") +# set receiver bank account: +to_bank_id = TO_BANK_ID +to_account_id = TO_ACCOUNT_ID + +challenge_type_sandbox_tan = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) +#####Case1: without challenge +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sandbox_tan, + to_bank_id=to_bank_id, # for SANDBOX_TAN + to_account_id=to_account_id, # for SANDBOX_TAN + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY + +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sandbox_tan, + to_bank_id=to_bank_id, # for SANDBOX_TAN + to_account_id=to_account_id, # for SANDBOX_TAN + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sandbox_tan, challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) + +######################### Step3 - make a payment - SEPA ################ +print("") +print("") +# set receiver COUNTERPARTY_IBAN: +to_counterparty_iban = TO_COUNTERPARTY_IBAN + +challenge_type_sepa = "SEPA" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) +#####Case1: without challenge +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sepa, + to_bank_id="", # for SANDBOX_TAN + to_account_id="", # for SANDBOX_TAN + to_counterparty_id="", # used for SEPA + to_counterparty_iban=to_counterparty_iban) # used for COUNTERPARTY +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sepa, + to_bank_id="", # for SANDBOX_TAN + to_account_id="", # for SANDBOX_TAN + to_counterparty_id="", # used for SEPA + to_counterparty_iban=to_counterparty_iban) # used for COUNTERPARTY +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) + +######################### Step4 - make a payment - COUNTERPARTY ################ +print("") +print("") + +# set receiver COUNTERPARTY_ID: +to_counterparty_id = TO_COUNTERPARTY_ID + +challenge_type_counterparty = "COUNTERPARTY" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) +#####Case1: without challenge +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_counterparty, + to_bank_id="", # for SANDBOX_TAN + to_account_id="", # for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_counterparty, + to_bank_id="", # for SANDBOX_TAN + to_account_id="", # for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, + challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) \ No newline at end of file diff --git a/hello_payments_V210_mapper.py b/hello_payments_V210_mapper.py new file mode 100644 index 0000000..24dda69 --- /dev/null +++ b/hello_payments_V210_mapper.py @@ -0,0 +1,222 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests + +# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN, SEPA, COUNTERPARTY (mapped) + +# Note: in order to use this example, you need to have at least one account that you can send money from (i.e. be the owner). +# And another account to receiver money(for SEPA or COUNTERPARTY, create a new COUNTERPARTY do need to prepare for them) +# All properties are now kept in 'localtest_mapper.py',you need set up your own props. + +#########################Step 1 : Login in(OAuth process) and prepare the bankaccounts to make the payment.################ +# You probably don't need to change those +# connector=mapped +import uuid + +from props.localtest_mapper import * +import lib.obp + +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +# login and set authorized token +obp.login(USERNAME, PASSWORD, CONSUMER_KEY) + +# set the fromAccount info: +from_bank_id = FROM_BANK_ID +from_account_id = FROM_ACCOUNT_ID + +######################### Step2 - make a payment - SANDBOX_TAN ################ +print("") +print("") +# set the toAccount for SANDBOX_TAN +to_bank_id = TO_BANK_ID +to_account_id = TO_ACCOUNT_ID + +challenge_type_sandbox_tan = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) +#####Case1: without challenge +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sandbox_tan, + to_bank_id=to_bank_id, + to_account_id=to_account_id, + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sandbox_tan, + to_bank_id=to_bank_id, + to_account_id=to_account_id, + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sandbox_tan, challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) + +######################### Step3 - make a payment - SEPA ################ +print("") +print("") +challenge_type_sepa = "SEPA" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) + +# Create the new COUNTERPARTY for SEPA, other_account_routing_scheme must equal "IBAN" +to_counterparty_iban = str(uuid.uuid4()) +create_counterparty_response = obp.createCounterparty(bank_id=from_bank_id, + account_id=from_account_id, + name=str(uuid.uuid4()), + other_account_routing_scheme="IBAN", + other_account_routing_address=to_counterparty_iban, + other_bank_routing_scheme="test", + other_bank_routing_address="test") +if "error" in create_counterparty_response: + sys.exit("Got an error: " + str(create_counterparty_response)) + +print("create Counterparty was successfully created:") +print("{0}".format(create_counterparty_response)) + +#####Case1: without challenge +print("") +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sepa, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id="", # used for COUNTERPARTY + to_counterparty_iban=to_counterparty_iban) + +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sepa, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id="", # used for COUNTERPARTY + to_counterparty_iban=to_counterparty_iban) +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) + +######################### Step4 - make a payment - COUNTERPARTY ################ +print("") +print("") +challenge_type_counterparty = "COUNTERPARTY" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) + +# Create the new COUNTERPARTY, toCounterparty.other_account_routing_scheme =="OBP" && toCounterparty.other_bank_routing_scheme=="OBP") +create_counterparty_response = obp.createCounterparty(bank_id=from_bank_id, + account_id=from_account_id, + name=str(uuid.uuid4()), + other_account_routing_scheme="OBP", + other_account_routing_address="test", + other_bank_routing_scheme="OBP", + other_bank_routing_address="test") +if "error" in create_counterparty_response: + sys.exit("Got an error: " + str(create_counterparty_response)) + +print("create Counterparty was successfully created:") +print("{0}".format(create_counterparty_response)) +to_counterparty_id = create_counterparty_response['counterparty_id'] + +#####Case1: without challenge +print("") +print("create transaction request small value (without challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_counterparty, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, + to_counterparty_iban="") # used for SEPA + +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# There was no challenge, transaction was created immediately +print("Transaction was successfully created:") +print("{0}".format(initiate_response)) + +#####Case2: with challenge +print("") +print("create transaction request large value (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_counterparty, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, + to_counterparty_iban="") # used for SEPA +if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + +# we need to answer the challenge +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] + +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, + challenge_query) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +print("Transaction status: {0}".format(challenge_response['status'])) +print("Transaction created: {0}".format(challenge_response["transaction_ids"])) diff --git a/lib/obp.py b/lib/obp.py index 01351e3..df474d3 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -80,10 +80,10 @@ def getCounterBankId(): def getCounterpartyAccountId(): return OUR_COUNTERPARTY -def getCunterpartyId(): +def getCounterpartyId(): return OUR_COUNTERPARTY_ID -def getCunterpartyIban(): +def getCounterpartyIban(): return OUR_COUNTERPARTY_IBAN # Get banks @@ -159,23 +159,32 @@ def initiateTransactionRequest(bank, account, challenge_type, cp_bank, cp_accoun response = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format(BASE_URL, bank, account, challenge_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json() -# Create counterparty -def createCounterparty(bank, account, name): +# Create counterparty, input data format: +# { +# "name":"Friend", +# "other_account_routing_scheme":"IBAN", +# "other_account_routing_address":"GR1301720530005053000582373", +# "other_bank_routing_scheme":"BIC", +# "other_bank_routing_address":"PIRBGRAAXXX", +# "is_beneficiary":true +# } +def createCounterparty(bank_id, + account_id, + name, + other_account_routing_scheme, + other_account_routing_address, + other_bank_routing_scheme, + other_bank_routing_address): post_data = { 'name' : '%s' % name, - 'other_bank_id' : '%s' % bank, - 'other_account_id' : '%s' % account, - 'other_account_provider' : '%s' % 'OBP', - 'other_account_routing_scheme' : '%s' '', - 'other_account_routing_address': '%s' '', - 'other_bank_routing_scheme' : '%s' '', - 'other_bank_routing_address' : '%s' '', - 'is_beneficiary' : true + 'other_account_routing_scheme' : '%s' % other_account_routing_scheme , + 'other_account_routing_address': '%s' % other_account_routing_address, + 'other_bank_routing_scheme' : '%s' % other_bank_routing_scheme, + 'other_bank_routing_address' : '%s' % other_bank_routing_address, + 'is_beneficiary' : True } # Send post request with attached json - response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/counterparties".format(BASE_URL, API_VERSION), json=post_data, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) - # Log result - log("code=" + response.status_code + " text=" + response.text) + response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/counterparties".format(BASE_URL, API_VERSION, bank_id, account_id), json=post_data, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json() # Get all entitlements @@ -222,25 +231,31 @@ def answerChallengeV210(bank, account, transation_req_id, challenge_type, challe # Create Transaction Request. - V210 # Note : previous called 'initiateTransactionRequest', now keep it the same and OBP-API endpoint name -def createTransactionRequestV210(bank, account, challenge_type, cp_bank, cp_account,cp_cunterparty_id, cp_cunterparty_iban): - if(challenge_type=="SANDBOX_TAN"): - send_to = {"bank": cp_bank, "account": cp_account} +def createTransactionRequestV210(from_bank_id, + from_account_id, + transaction_request_type, + to_bank_id, + to_account_id, + to_counterparty_id, + to_counterparty_iban): + if(transaction_request_type== "SANDBOX_TAN"): + send_to = {"bank": to_bank_id, "account": to_account_id} payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc"}' - elif(challenge_type=="SEPA"): - send_to = {"iban": cp_cunterparty_iban} + elif(transaction_request_type== "SEPA"): + send_to = {"iban": to_counterparty_iban} payload = '{"to": {"iban": "' + send_to['iban'] +\ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "charge_policy" : "' + \ "SHARED" + '"}' - elif (challenge_type=="COUNTERPARTY"): - send_to = {"counterparty_id": cp_cunterparty_id} + elif (transaction_request_type== "COUNTERPARTY"): + send_to = {"counterparty_id": to_counterparty_id} payload = '{"to": {"counterparty_id": "' + send_to['counterparty_id'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "charge_policy" : "' + \ "SHARED" + '"}' else: # FREE_FORM - send_to = {"bank": cp_bank, "account": cp_account} + send_to = {"bank": to_bank_id, "account": to_account_id} payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ - challenge_type + '"}' - response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests".format(BASE_URL, API_VERSION, bank, account, challenge_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + transaction_request_type + '"}' + response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests".format(BASE_URL, API_VERSION, from_bank_id, from_account_id, transaction_request_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json() \ No newline at end of file diff --git a/props/localtest_kafka.py b/props/localtest_kafka.py new file mode 100644 index 0000000..b81eccf --- /dev/null +++ b/props/localtest_kafka.py @@ -0,0 +1,33 @@ +# This is just for local test, you need first run the OBP-API locally, +# and you need prepare the USERNAME, PASSWORD and CONSUMER_KEY. +# if you want to transfer to other account or counterparty, you need prepare your own data. + +# API server URL +BASE_URL = "http://127.0.0.1:8080" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'http://127.0.0.1/cb' + +#login user: +USERNAME = 'robert.x.0.gh@example.com' +PASSWORD = '3e3a3102' +CONSUMER_KEY = 'e0xcuubmfzkdbaef30zmrgnwa51dekgnf3vxhavp' + +#fromAccount info: +FROM_BANK_ID = 'obp-bank-x-gh' +FROM_ACCOUNT_ID = 'e0ec24be-5ab1-4760-9189-ad280228c134' + +#toBankAccount and toCounterparty info: +TO_BANK_ID = 'obp-bank-x-gh' +TO_ACCOUNT_ID = 'e4f001fe-0f0d-4f93-a8b2-d865077315ec' +TO_COUNTERPARTY_ID = 'a635f6ff-c26b-46ad-8194-2406bacceae4' +TO_COUNTERPARTY_IBAN = 'DE12 1234 5123 4510 2207 8077 877' + +# Our currency to use +OUR_CURRENCY = 'GBP' +# Our value to transfer +# values below 1000 do not require challenge request +OUR_VALUE = '0.01' +OUR_VALUE_LARGE = '1001.00' diff --git a/props/localtest.py b/props/localtest_mapper.py similarity index 68% rename from props/localtest.py rename to props/localtest_mapper.py index f7f34a7..440ed50 100644 --- a/props/localtest.py +++ b/props/localtest_mapper.py @@ -1,11 +1,6 @@ # This is just for local test, you need first run the OBP-API locally, -# and maybe prepare the CONSUMER_KEY, OUR_COUNTERPARTY_ACCOUNT_ID, OUR_COUNTERPARTY_ID, OUR_COUNTERPARTY_IBAN locall +# and maybe prepare the CONSUMER_KEY, OUR_COUNTERPARTY_ACCOUNT_ID, OUR_COUNTERPARTY_ID, OUR_COUNTERPARTY_IBAN locally -OUR_BANK = 'gh.29.uk' - -USERNAME = 'susan.uk.29@example.com' -PASSWORD = '2b78e8' -CONSUMER_KEY = '3ru5q4x4bfdeicdqpxwrylujtmwfj5r1m2gluaef' # API server URL BASE_URL = "http://127.0.0.1:8080" @@ -16,11 +11,19 @@ # You will paste the redirect location here when running the script CALLBACK_URI = 'http://127.0.0.1/cb' -# Our COUNTERPARTY account (the same currency) -COUNTERPARTY_BANK = 'gh.29.uk' -OUR_COUNTERPARTY = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' -OUR_COUNTERPARTY_ID = '7825c891-df3d-466e-aaae-38fed8c0c68e' -OUR_COUNTERPARTY_IBAN = 'DE12 1234 5123 4510 2207 8077 877' + +#login user: +USERNAME = 'susan.uk.29@example.com' +PASSWORD = '2b78e8' +CONSUMER_KEY = '3ru5q4x4bfdeicdqpxwrylujtmwfj5r1m2gluaef' + +#fromAccount info: +FROM_BANK_ID = 'gh.29.uk' +FROM_ACCOUNT_ID = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' + +#toBankAccount and toCounterparty info: +TO_BANK_ID = 'gh.29.uk' +TO_ACCOUNT_ID = '26fa77a2-028f-4022-b47d-26caa8db359a' # Our currency to use OUR_CURRENCY = 'GBP' From 6756e510dd87d25cfd796b116f943ca2cbbc98a4 Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Wed, 8 Mar 2017 14:29:38 +0100 Subject: [PATCH 10/26] #8 add V210 - Create Transaction Requests --tweaking --- hello_payments_V210_kafka.py | 79 +++++++++++++++------------------ hello_payments_V210_mapper.py | 82 +++++++++++++++++------------------ lib/obp.py | 29 ++++++++++++- 3 files changed, 102 insertions(+), 88 deletions(-) diff --git a/hello_payments_V210_kafka.py b/hello_payments_V210_kafka.py index 54b997a..2336115 100644 --- a/hello_payments_V210_kafka.py +++ b/hello_payments_V210_kafka.py @@ -19,16 +19,13 @@ obp.setApiVersion(API_VERSION_V210) # login and set authorized token +print("Call API - 0 'DirectLogin'") obp.login(USERNAME, PASSWORD, CONSUMER_KEY) # set fromAccount info: from_bank_id = FROM_BANK_ID from_account_id = FROM_ACCOUNT_ID -# check all request types,now support: SANDBOX_TAN, SEPA, COUNTERPARTY and FREE_FORM -print("Get support Transaction Request Types :") -transaction_request_type = obp.getChallengeTypes(from_bank_id, from_account_id) -print(transaction_request_type) ######################### Step2 - make a payment - SANDBOX_TAN ################ print("") @@ -40,7 +37,7 @@ challenge_type_sandbox_tan = "SANDBOX_TAN" print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) #####Case1: without challenge -print("create transaction request small value (without challenge)") +print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) # call 'Create Transaction Requests - V210' endpoint @@ -52,16 +49,12 @@ to_counterparty_id="", # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - # There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) +obp.printMessageNoChallenge(initiate_response) #####Case2: with challenge print("") -print("create transaction request large value (with challenge)") +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) # call 'Create Transaction Requests - V210' endpoint @@ -72,21 +65,23 @@ to_account_id=to_account_id, # for SANDBOX_TAN to_counterparty_id="", # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) -# we need to answer the challenge + +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) + +# Then we need to answer the challenge challenge_query = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] - +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sandbox_tan, challenge_query) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) -######################### Step3 - make a payment - SEPA ################ +obp.printMessageAfterAnswerChallenge(challenge_response) + +# ######################### Step3 - make a payment - SEPA ################ print("") print("") # set receiver COUNTERPARTY_IBAN: @@ -95,7 +90,7 @@ challenge_type_sepa = "SEPA" print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) #####Case1: without challenge -print("create transaction request small value (without challenge)") +print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) # call 'Create Transaction Requests - V210' endpoint @@ -110,12 +105,11 @@ sys.exit("Got an error: " + str(initiate_response)) # There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) +obp.printMessageNoChallenge(initiate_response) #####Case2: with challenge print("") -print("create transaction request large value (with challenge)") +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) # call 'Create Transaction Requests - V210' endpoint @@ -126,19 +120,20 @@ to_account_id="", # for SANDBOX_TAN to_counterparty_id="", # used for SEPA to_counterparty_iban=to_counterparty_iban) # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) + +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) # we need to answer the challenge challenge_query = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_query) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) +obp.printMessageAfterAnswerChallenge(challenge_response) ######################### Step4 - make a payment - COUNTERPARTY ################ print("") @@ -150,7 +145,7 @@ challenge_type_counterparty = "COUNTERPARTY" print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) #####Case1: without challenge -print("create transaction request small value (without challenge)") +print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) # call 'Create Transaction Requests - V210' endpoint @@ -161,16 +156,13 @@ to_account_id="", # for SANDBOX_TAN to_counterparty_id=to_counterparty_id, # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) # There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) +obp.printMessageNoChallenge(initiate_response) #####Case2: with challenge print("") -print("create transaction request large value (with challenge)") +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) # call 'Create Transaction Requests - V210' endpoint @@ -181,17 +173,16 @@ to_account_id="", # for SANDBOX_TAN to_counterparty_id=to_counterparty_id, # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) # we need to answer the challenge challenge_query = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, - challenge_query) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, challenge_query) -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) \ No newline at end of file +obp.printMessageAfterAnswerChallenge(challenge_response) \ No newline at end of file diff --git a/hello_payments_V210_mapper.py b/hello_payments_V210_mapper.py index 24dda69..91033cd 100644 --- a/hello_payments_V210_mapper.py +++ b/hello_payments_V210_mapper.py @@ -37,7 +37,7 @@ challenge_type_sandbox_tan = "SANDBOX_TAN" print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) #####Case1: without challenge -print("create transaction request small value (without challenge)") +print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) # call 'Create Transaction Requests - V210' endpoint @@ -48,16 +48,13 @@ to_account_id=to_account_id, to_counterparty_id="", # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) # There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) +obp.printMessageNoChallenge(initiate_response) #####Case2: with challenge print("") -print("create transaction request large value (with challenge)") +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) # call 'Create Transaction Requests - V210' endpoint @@ -68,19 +65,23 @@ to_account_id=to_account_id, to_counterparty_id="", # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) + +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) # we need to answer the challenge -challenge_query = initiate_response['challenge']['id'] +print("") +print("Then we need to answer the challenge") +challenge_id = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sandbox_tan, challenge_query) +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sandbox_tan, challenge_id) if "error" in challenge_response: sys.exit("Got an error: " + str(challenge_response)) -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) +obp.printMessageAfterAnswerChallenge(challenge_response) ######################### Step3 - make a payment - SEPA ################ print("") @@ -97,15 +98,13 @@ other_account_routing_address=to_counterparty_iban, other_bank_routing_scheme="test", other_bank_routing_address="test") -if "error" in create_counterparty_response: - sys.exit("Got an error: " + str(create_counterparty_response)) print("create Counterparty was successfully created:") print("{0}".format(create_counterparty_response)) #####Case1: without challenge print("") -print("create transaction request small value (without challenge)") +print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) # call 'Create Transaction Requests - V210' endpoint @@ -116,17 +115,15 @@ to_account_id="", # used for SANDBOX_TAN to_counterparty_id="", # used for COUNTERPARTY to_counterparty_iban=to_counterparty_iban) - -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - +if "error" in create_counterparty_response: + sys.exit("Got an error: " + str(create_counterparty_response)) + # There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) +obp.printMessageNoChallenge(initiate_response) #####Case2: with challenge print("") -print("create transaction request large value (with challenge)") +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) # call 'Create Transaction Requests - V210' endpoint @@ -139,17 +136,19 @@ to_counterparty_iban=to_counterparty_iban) if "error" in initiate_response: sys.exit("Got an error: " + str(initiate_response)) + +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) # we need to answer the challenge -challenge_query = initiate_response['challenge']['id'] +challenge_id = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_id) -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_query) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) +obp.printMessageAfterAnswerChallenge(challenge_response) ######################### Step4 - make a payment - COUNTERPARTY ################ print("") @@ -174,7 +173,7 @@ #####Case1: without challenge print("") -print("create transaction request small value (without challenge)") +print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) # call 'Create Transaction Requests - V210' endpoint @@ -186,16 +185,12 @@ to_counterparty_id=to_counterparty_id, to_counterparty_iban="") # used for SEPA -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - # There was no challenge, transaction was created immediately -print("Transaction was successfully created:") -print("{0}".format(initiate_response)) +obp.printMessageNoChallenge(initiate_response) #####Case2: with challenge print("") -print("create transaction request large value (with challenge)") +print("Call API - 3 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) # call 'Create Transaction Requests - V210' endpoint @@ -206,17 +201,18 @@ to_account_id="", # used for SANDBOX_TAN to_counterparty_id=to_counterparty_id, to_counterparty_iban="") # used for SEPA -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) # we need to answer the challenge -challenge_query = initiate_response['challenge']['id'] +challenge_id = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] - +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, - challenge_query) + challenge_id) if "error" in challenge_response: sys.exit("Got an error: " + str(challenge_response)) -print("Transaction status: {0}".format(challenge_response['status'])) -print("Transaction created: {0}".format(challenge_response["transaction_ids"])) +obp.printMessageAfterAnswerChallenge(challenge_response) diff --git a/lib/obp.py b/lib/obp.py index df474d3..119ccbd 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -258,4 +258,31 @@ def createTransactionRequestV210(from_bank_id, '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ transaction_request_type + '"}' response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests".format(BASE_URL, API_VERSION, from_bank_id, from_account_id, transaction_request_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) - return response.json() \ No newline at end of file + return response.json() + + +# define some help print transaction methods status +def printMessageNoChallenge(initiate_response): + if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + print("There was no challenge, transaction was created immediately:") + print("The response is : {0}".format(initiate_response)) + print("Transaction status: {0}".format(initiate_response['status'])) + print("Transaction id is created: {0}".format(initiate_response["transaction_ids"])) + + +def printMessageWithChallenge(initiate_response): + if "error" in initiate_response: + sys.exit("Got an error: " + str(initiate_response)) + print("There was a challenge, transaction was interrupted, the transaction_request is 'INITIATED' and new Transaction id is null:") + print("The response is: {0}".format(initiate_response)) + print("Transaction status: {0}".format(initiate_response['status'])) + print("New Transaction ID created: {0}".format(initiate_response["transaction_ids"])) + + +def printMessageAfterAnswerChallenge(challenge_response): + if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + print("The result is: {0}".format(challenge_response)) + print("Transaction status: {0}".format(challenge_response['status'])) + print("New Transaction ID created: {0}".format(challenge_response["transaction_ids"])) From 51a3398567419076aa3c40aca7e4799ec103ad1a Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Mon, 13 Mar 2017 09:06:48 +0100 Subject: [PATCH 11/26] #8 add V210 - Create Transaction Requests --for Socgen --- hello_payments_V210_Socgenk.py | 78 ++++++++++++++++++++++++++++++ lib/obp.py | 25 +++++++++- props/localtest_Socgen1_k.py | 29 +++++++++++ props/localtest_Socgen2_k.py | 30 ++++++++++++ props/localtest_Socgen2_k_local.py | 29 +++++++++++ 5 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 hello_payments_V210_Socgenk.py create mode 100644 props/localtest_Socgen1_k.py create mode 100644 props/localtest_Socgen2_k.py create mode 100644 props/localtest_Socgen2_k_local.py diff --git a/hello_payments_V210_Socgenk.py b/hello_payments_V210_Socgenk.py new file mode 100644 index 0000000..ebb8efe --- /dev/null +++ b/hello_payments_V210_Socgenk.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests + +# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN +# over Socgen1-k https://socgen-k-api.openbankproject.com/ +# or over Socgen2-k https://socgen2-k-api.openbankproject.com/ +# or local : http://127.0.0.1:8080 (You need set up local test environment) + +# Note: +# All needed users and accounts are now kept in 'localtest_Socgen1-k.py' or 'localtest_Socgen2-k.py'' or 'localtest_Socgen2-k'', +# You can pick up one to test the sandbox you want, just modify the following lines to switch props +# from props.localtest_Socgen1_k import * +from props.localtest_Socgen2_k import * +# from props.localtest_Socgen2_k_local import * + + +#########################Step 1 : Login in(OAuth process).################ + +import lib.obp +import logging + +logging.basicConfig(level=logging.DEBUG) + +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +print("Call API - 0 'DirectLogin' -- login and set authorized token") +obp.login(USERNAME, PASSWORD, CONSUMER_KEY) + +######################### Step2 - Make a Payment - SANDBOX_TAN ################ +print("") +print("Set fromAccount info: from_bank_id = {0} and from_account_id= {1}.".format(FROM_BANK_ID, FROM_ACCOUNT_ID)) +from_bank_id = FROM_BANK_ID +from_account_id = FROM_ACCOUNT_ID + +print("") +print("Set toAccount info: to_bank_id = {0} and to_account_id= {1}.".format(TO_BANK_ID, TO_ACCOUNT_ID)) +to_bank_id = TO_BANK_ID +to_account_id = TO_ACCOUNT_ID + +print("") +challenge_type_sandbox_tan = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) +print("") +print("Set up the OUR_CURRENCY = {0} and OUR_VALUE_LARGE = {1} ".format(OUR_CURRENCY, OUR_VALUE_LARGE)) +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) + +print("Call API - 1 'Create Transaction Request. -- V210' (with challenge)") +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=challenge_type_sandbox_tan, + to_bank_id=to_bank_id, # for SANDBOX_TAN + to_account_id=to_account_id, # for SANDBOX_TAN + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +obp.printMessageWithChallenge(initiate_response) + +print("") +print("Call API - 2 'Answer Transaction Request Challenge. -- V210'") +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] +challenge_response = obp.answerChallengeV210(bank_id=from_bank_id, + account_id=from_account_id, + transation_req_id=transaction_req_id, + challenge_type=challenge_type_sandbox_tan, + challenge_query=challenge_query) + +obp.printMessageAfterAnswerChallenge(challenge_response) + +# Then we need to check the get Transactions +print("") +print("Call API - 3 'Get Transactions for Account (Full)-- V210'") +new_transaction_id = challenge_response["transaction_ids"] +getTransactions_response = obp.getTransactions(from_bank_id, from_account_id) + +obp.printGetTransactionsResponse(getTransactions_response, new_transaction_id) diff --git a/lib/obp.py b/lib/obp.py index 119ccbd..8c6d8db 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -222,10 +222,10 @@ def addEntitlement(entitlement, user, bank=''): # Answer Transaction Request Challenge. - V210 -def answerChallengeV210(bank, account, transation_req_id, challenge_type, challenge_query): +def answerChallengeV210(bank_id, account_id, transation_req_id, challenge_type, challenge_query): body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests/{5}/challenge".format( - BASE_URL, API_VERSION, bank, account, challenge_type, transation_req_id), data=body, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON) + BASE_URL, API_VERSION, bank_id, account_id, challenge_type, transation_req_id), data=body, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON) ) return response.json() @@ -283,6 +283,27 @@ def printMessageWithChallenge(initiate_response): def printMessageAfterAnswerChallenge(challenge_response): if "error" in challenge_response: sys.exit("Got an error: " + str(challenge_response)) + print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") print("The result is: {0}".format(challenge_response)) print("Transaction status: {0}".format(challenge_response['status'])) print("New Transaction ID created: {0}".format(challenge_response["transaction_ids"])) + + +def printGetTransactionsResponse(response,new_transaction_id): + if "error" in response: + sys.exit("Got an error: " + str(response)) + + print("Check the whether new_transaction_id ({0}) is in response: ".format(new_transaction_id)) + if new_transaction_id in str(response) : + for transaction in response: + if new_transaction_id in str(response) : + print (transaction) + else: + print ("Note: the new_transaction_id ({0}) is not in response !!!".format(new_transaction_id)) + + print("") + print("Print all the transactions : ") + count=0 + for transaction in response: + count=count + 1 + print (str(count) +":"+str(transaction)) \ No newline at end of file diff --git a/props/localtest_Socgen1_k.py b/props/localtest_Socgen1_k.py new file mode 100644 index 0000000..63e206c --- /dev/null +++ b/props/localtest_Socgen1_k.py @@ -0,0 +1,29 @@ +# This is just for socgen-k test, you make sure Socgen-k server is working well. +# https://socgen-k-api.openbankproject.com/ + +# API server URL +BASE_URL = "https://socgen-k-api.openbankproject.com" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'http://127.0.0.1/cb' + +#login user: +USERNAME = '1000203892' +PASSWORD = '123456' +CONSUMER_KEY = 'ojgl4l4ypbmxggi0ktbyo0olea2aunvrrkk3ipgz' + +#fromAccount info: +FROM_BANK_ID = '00100' +FROM_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' + +TO_BANK_ID = '00100' +TO_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' + +# Our currency to use +OUR_CURRENCY = 'XAF' + +# Our value to transfer +OUR_VALUE = '10' +OUR_VALUE_LARGE = '1001.00' \ No newline at end of file diff --git a/props/localtest_Socgen2_k.py b/props/localtest_Socgen2_k.py new file mode 100644 index 0000000..f7b11b1 --- /dev/null +++ b/props/localtest_Socgen2_k.py @@ -0,0 +1,30 @@ +# This is just for socgen-k test, you make sure Socgen-k server is working well. +# https://socgen-k-api.openbankproject.com/ + +# API server URL +BASE_URL = "https://socgen2-k-api.openbankproject.com" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'http://127.0.0.1/cb' + +#login user: +USERNAME = '1000203892' +PASSWORD = '123456' +CONSUMER_KEY = 'gexnvhs1hx1zumjjldqyihfftzzhdbuhxrp3mcmw' + + +#fromAccount info: +FROM_BANK_ID = '00100' +FROM_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' + +TO_BANK_ID = '00100' +TO_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' + +# Our currency to use +OUR_CURRENCY = 'XAF' + +# Our value to transfer +OUR_VALUE = '10' +OUR_VALUE_LARGE = '1001.00' \ No newline at end of file diff --git a/props/localtest_Socgen2_k_local.py b/props/localtest_Socgen2_k_local.py new file mode 100644 index 0000000..41cbbe9 --- /dev/null +++ b/props/localtest_Socgen2_k_local.py @@ -0,0 +1,29 @@ +# This is just for socgen-k test, you make sure Socgen-k server is working well. +# https://socgen-k-api.openbankproject.com/ + +# API server URL +BASE_URL = "http://127.0.0.1:8080" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'http://127.0.0.1/cb' + +# login user: +USERNAME = '1000203892' +PASSWORD = 'fffffffffffffffff' +CONSUMER_KEY = 'gmtcx4letf2isej1slxhpphtnt2jkt30ldazvkmd' + +# fromAccount info: +FROM_BANK_ID = '00100' +FROM_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' + +TO_BANK_ID = '00100' +TO_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' + +# Our currency to use +OUR_CURRENCY = 'XAF' + +# Our value to transfer +OUR_VALUE = '10' +OUR_VALUE_LARGE = '1001.00' From 0108194ea57c0c90e7209bf87a5163f0d44337c4 Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Fri, 17 Mar 2017 18:45:51 +0100 Subject: [PATCH 12/26] add tests for counterprty ,sepa teset --- hello_payments_V210_socgenk_two_owners.py | 165 ++++++++++++++++++++++ lib/obp.py | 48 ++++--- props/localtest_Socgen1_k_two_owners.py | 60 ++++++++ 3 files changed, 254 insertions(+), 19 deletions(-) create mode 100644 hello_payments_V210_socgenk_two_owners.py create mode 100644 props/localtest_Socgen1_k_two_owners.py diff --git a/hello_payments_V210_socgenk_two_owners.py b/hello_payments_V210_socgenk_two_owners.py new file mode 100644 index 0000000..08c0cd7 --- /dev/null +++ b/hello_payments_V210_socgenk_two_owners.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests +import lib.obp +import uuid +#import logging +#logging.basicConfig(level=logging.DEBUG) + +# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN +# over Socgen1-k https://socgen-k-api.openbankproject.com/ + +#########################Step 1 : Login in(OAuth process).################ +from props.localtest_Socgen1_k_two_owners import * #17 + +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +print("Call API - 0 'DirectLogin' -- login and set authorized token") +obp.login(USERNAME, PASSWORD, CONSUMER_KEY) + + +########################### Step2 - Make a Payment - SANDBOX_TAN ################ +print("") +print("Set fromAccount info: from_bank_id = {0} and from_account_id= {1}.".format(FROM_BANK_ID, FROM_ACCOUNT_ID)) +from_bank_id = FROM_BANK_ID +from_account_id = FROM_ACCOUNT_ID + +print("") +print("Set toAccount info: to_bank_id = {0} and to_account_id= {1}.".format(TO_BANK_ID, TO_ACCOUNT_ID)) +to_bank_id = TO_BANK_ID +to_account_id = TO_ACCOUNT_ID + +print("") +challenge_type_sandbox_tan = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) +print("") +print("Set up the OUR_CURRENCY = {0} and OUR_VALUE_LARGE = {1} ".format(OUR_CURRENCY, OUR_VALUE_LARGE)) +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) + +print("Call API - 1 'Create Transaction Request. -- V210' (with challenge)") +initiate_response = obp.createTransactionRequestV210(from_bank_id=FROM_BANK_ID, + from_account_id=FROM_ACCOUNT_ID, + transaction_request_type=challenge_type_sandbox_tan, + to_bank_id=to_bank_id, # for SANDBOX_TAN + to_account_id=to_account_id, # for SANDBOX_TAN + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +obp.printMessageWithChallenge(initiate_response) + +print("") +print("Call API - 2 'Answer Transaction Request Challenge. -- V210'") +challenge_query = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] +challenge_response = obp.answerChallengeV210(bank_id=from_bank_id, + account_id=from_account_id, + transation_req_id=transaction_req_id, + challenge_type=challenge_type_sandbox_tan, + challenge_query=challenge_query) + +obp.printMessageAfterAnswerChallenge(challenge_response) + +print("") +print("Then we need to check the get Transactions") +print("Call API - 3 'Get Transactions for Account (Full)-- V210'") +new_transaction_id = challenge_response["transaction_ids"] +getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) +obp.printGetTransactionsResponse(getTransactions_response, new_transaction_id) + +######################### Step3 - make a payment - SEPA ################ +print("") +print("") +challenge_type_sepa = "SEPA" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) +print("Call API -1 'Create counterparty for an account --Socgen1-k' ") +# Create the new COUNTERPARTY for SEPA, other_account_routing_scheme must equal "IBAN" +to_counterparty_iban = str(uuid.uuid4()) +create_counterparty_response = obp.createCounterparty(bank_id=FROM_BANK_ID, + account_id=FROM_ACCOUNT_ID, + name=str(uuid.uuid4()), + other_account_routing_scheme="IBAN", + other_account_routing_address=to_counterparty_iban, + other_bank_routing_scheme="BankId", + other_bank_routing_address="00100") +obp.printCreateCounterparty(create_counterparty_response) + +print("") +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=FROM_BANK_ID, + from_account_id=FROM_ACCOUNT_ID, + transaction_request_type=challenge_type_sepa, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id="", # used for COUNTERPARTY + to_counterparty_iban=to_counterparty_iban) + +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) + +# we need to answer the challenge +challenge_id = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_id) + +# obp.printMessageAfterAnswerChallenge(challenge_response) +print("The response is: {0}".format(challenge_response)) + + +######################### Step3 - make a payment - COUNTERPARTY ################ +print("") +print("") +challenge_type_counterparty = "COUNTERPARTY" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) + +# Create the new COUNTERPARTY, toCounterparty.other_account_routing_scheme =="OBP" && toCounterparty.other_bank_routing_scheme=="OBP") +print("Call API -1 'Create counterparty for an account --Socgen1-k' ") +create_counterparty_response = obp.createCounterparty(bank_id=FROM_BANK_ID, + account_id=FROM_ACCOUNT_ID, + name=str(uuid.uuid4()), + other_account_routing_scheme="BankAccountID", + other_account_routing_address="1000203892", + other_bank_routing_scheme="BankId", + other_bank_routing_address="00100") + +obp.printCreateCounterparty(create_counterparty_response) + +print("{0}".format(create_counterparty_response)) +to_counterparty_id = create_counterparty_response['counterparty_id'] + +#####Case1: without challenge +print("") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=FROM_BANK_ID, + from_account_id=FROM_ACCOUNT_ID, + transaction_request_type=challenge_type_counterparty, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, # used for COUNTERPARTY + to_counterparty_iban="") # used for SEPA +# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' +obp.printMessageWithChallenge(initiate_response) + +# we need to answer the challenge +challenge_id = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, + challenge_id) +if "error" in challenge_response: + sys.exit("Got an error: " + str(challenge_response)) + +# obp.printMessageAfterAnswerChallenge(challenge_response) diff --git a/lib/obp.py b/lib/obp.py index 8c6d8db..d080e03 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -262,31 +262,34 @@ def createTransactionRequestV210(from_bank_id, # define some help print transaction methods status -def printMessageNoChallenge(initiate_response): - if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) +def printMessageNoChallenge(response): + if "error" in response: + print("The result is: {0}".format(response)) + # sys.exit("Got an error: " + str(response)) print("There was no challenge, transaction was created immediately:") - print("The response is : {0}".format(initiate_response)) - print("Transaction status: {0}".format(initiate_response['status'])) - print("Transaction id is created: {0}".format(initiate_response["transaction_ids"])) + print("The response is : {0}".format(response)) + print("Transaction status: {0}".format(response['status'])) + print("Transaction id is created: {0}".format(response["transaction_ids"])) -def printMessageWithChallenge(initiate_response): - if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) +def printMessageWithChallenge(response): + if "error" in response: + print("The result is: {0}".format(response)) + # sys.exit("Got an error: " + str(response)) print("There was a challenge, transaction was interrupted, the transaction_request is 'INITIATED' and new Transaction id is null:") - print("The response is: {0}".format(initiate_response)) - print("Transaction status: {0}".format(initiate_response['status'])) - print("New Transaction ID created: {0}".format(initiate_response["transaction_ids"])) + print("The response is: {0}".format(response)) + print("Transaction status: {0}".format(response['status'])) + print("New Transaction ID created: {0}".format(response["transaction_ids"])) -def printMessageAfterAnswerChallenge(challenge_response): - if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) +def printMessageAfterAnswerChallenge(response): + if "error" in response: + print("The result is: {0}".format(response)) + # sys.exit("Got an error: " + str(response)) print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") - print("The result is: {0}".format(challenge_response)) - print("Transaction status: {0}".format(challenge_response['status'])) - print("New Transaction ID created: {0}".format(challenge_response["transaction_ids"])) + print("The result is: {0}".format(response)) + print("Transaction status: {0}".format(response['status'])) + print("New Transaction ID created: {0}".format(response["transaction_ids"])) def printGetTransactionsResponse(response,new_transaction_id): @@ -306,4 +309,11 @@ def printGetTransactionsResponse(response,new_transaction_id): count=0 for transaction in response: count=count + 1 - print (str(count) +":"+str(transaction)) \ No newline at end of file + print (str(count) +":"+str(transaction)) + +def printCreateCounterparty(response): + if "error" in response: + print("The result is: {0}".format(response)) + # sys.exit("Got an error: " + str(response)) + print("Counterparty is created:") + print("The result is: {0}".format(response)) diff --git a/props/localtest_Socgen1_k_two_owners.py b/props/localtest_Socgen1_k_two_owners.py new file mode 100644 index 0000000..0585f5b --- /dev/null +++ b/props/localtest_Socgen1_k_two_owners.py @@ -0,0 +1,60 @@ +# This is just for socgen-k test, you make sure Socgen-k server is working well. +# https://socgen-k-api.openbankproject.com/ + +# API server URL +BASE_URL = "https://socgen-k-api.openbankproject.com" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'http://127.0.0.1/cb' + +# login user: +USERNAME = '1000203893' +PASSWORD = '123456' +CONSUMER_KEY = '45wpocdzh2uwnorvrk2sfy1rnwyc0h2ff3kdkr2s' + +# fromAccount info: 1000203893 +FROM_BANK_ID = '00100' +# FROM_ACCOUNT_ID = '3806441b-bbdf-3c60-b2b3-14e2f645635f' # 0 transaction +FROM_ACCOUNT_ID = '83b96bb4-ae2c-3e90-ad2c-8ce0b4b0023b' # 3 transactions +# FROM_ACCOUNT_ID = 'df88925b-4a7f-31f6-a077-3dcbd60b669f' # 12 transaction + +TO_BANK_ID = '00100' + +# the following there acounds are all belong to login user : 1000203893 +# TO_ACCOUNT_ID = '3806441b-bbdf-3c60-b2b3-14e2f645635f' +# TO_ACCOUNT_ID = '83b96bb4-ae2c-3e90-ad2c-8ce0b4b0023b' +TO_ACCOUNT_ID = 'df88925b-4a7f-31f6-a077-3dcbd60b669f' + +# this account is belong to user: 1000203892 +# TO_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' + +# these accounts are belong to user: 1000203891 +# TO_ACCOUNT_ID = '1f5587fa-8ad8-3c6b-8fac-ac3db5bdc3db' + +# these accounts are belong to user: 1000203899 --Ulrich Standalone account +# TO_ACCOUNT_ID = 'bb912420-484d-38c2-8c5b-d9772dd5bfbc' +# TO_ACCOUNT_ID = '0796d146-e39c-36a1-85cd-ef74f5d8227d' + +# toCountery +# { +# "name": "test2", +# "created_by_user_id": "b9ed3a54-1e98-4ca1-9f95-76815373d9f4", +# "this_bank_id": "00100", +# "this_account_id": "83b96bb4-ae2c-3e90-ad2c-8ce0b4b0023b", +# "this_view_id": "owner", +# "counterparty_id": "a78dab15-1c51-4e1e-bfc2-aa270a60eb6d", +# "other_bank_routing_scheme": "Agence", +# "other_account_routing_scheme": "BKCOM_ACCOUNT", +# "other_bank_routing_address": "00100", +# "other_account_routing_address": "1000203892", +# "is_beneficiary": true +# } + +# Our currency to use +OUR_CURRENCY = 'XAF' + +# Our value to transfer +OUR_VALUE = '10' +OUR_VALUE_LARGE = '1001.00' From 19adab0c9157a1dff18361648abc162d0d400a9a Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Mon, 20 Mar 2017 17:07:38 +0100 Subject: [PATCH 13/26] fixed the tests for SocGen1k-SANDBOX, SEPA and COUNTERPARTY --- hello_payments_V210_Socgenk.py | 2 +- hello_payments_V210_socgenk_two_owners.py | 20 ++++++++++--------- lib/obp.py | 17 ++++++++++------ .../{localtest_Socgen1_k.py => socgen1_k.py} | 0 ..._two_owners.py => socgen1_k_two_owners.py} | 4 ++-- .../{localtest_Socgen2_k.py => socgen2_k.py} | 0 ..._Socgen2_k_local.py => socgen2_k_local.py} | 0 7 files changed, 25 insertions(+), 18 deletions(-) rename props/{localtest_Socgen1_k.py => socgen1_k.py} (100%) rename props/{localtest_Socgen1_k_two_owners.py => socgen1_k_two_owners.py} (94%) rename props/{localtest_Socgen2_k.py => socgen2_k.py} (100%) rename props/{localtest_Socgen2_k_local.py => socgen2_k_local.py} (100%) diff --git a/hello_payments_V210_Socgenk.py b/hello_payments_V210_Socgenk.py index ebb8efe..f188017 100644 --- a/hello_payments_V210_Socgenk.py +++ b/hello_payments_V210_Socgenk.py @@ -11,7 +11,7 @@ # All needed users and accounts are now kept in 'localtest_Socgen1-k.py' or 'localtest_Socgen2-k.py'' or 'localtest_Socgen2-k'', # You can pick up one to test the sandbox you want, just modify the following lines to switch props # from props.localtest_Socgen1_k import * -from props.localtest_Socgen2_k import * +from props.socgen2_k import * # from props.localtest_Socgen2_k_local import * diff --git a/hello_payments_V210_socgenk_two_owners.py b/hello_payments_V210_socgenk_two_owners.py index 08c0cd7..5cef0db 100644 --- a/hello_payments_V210_socgenk_two_owners.py +++ b/hello_payments_V210_socgenk_two_owners.py @@ -10,7 +10,7 @@ # over Socgen1-k https://socgen-k-api.openbankproject.com/ #########################Step 1 : Login in(OAuth process).################ -from props.localtest_Socgen1_k_two_owners import * #17 +from props.socgen1_k_two_owners import * #17 obp = lib.obp obp.setBaseUrl(BASE_URL) @@ -60,13 +60,6 @@ obp.printMessageAfterAnswerChallenge(challenge_response) -print("") -print("Then we need to check the get Transactions") -print("Call API - 3 'Get Transactions for Account (Full)-- V210'") -new_transaction_id = challenge_response["transaction_ids"] -getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) -obp.printGetTransactionsResponse(getTransactions_response, new_transaction_id) - ######################### Step3 - make a payment - SEPA ################ print("") print("") @@ -162,4 +155,13 @@ if "error" in challenge_response: sys.exit("Got an error: " + str(challenge_response)) -# obp.printMessageAfterAnswerChallenge(challenge_response) +obp.printMessageAfterAnswerChallenge(challenge_response) + + +######################### Step4 - Print all transactions ################ +print("") +print("Then we need to check the get Transactions") +print("Call API - 1 'Get Transactions for Account (Full)-- V210'") +new_transaction_id = challenge_response["transaction_ids"] +getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) +obp.printGetTransactionsResponse(getTransactions_response, new_transaction_id) \ No newline at end of file diff --git a/lib/obp.py b/lib/obp.py index d080e03..5cdfefb 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -161,13 +161,16 @@ def initiateTransactionRequest(bank, account, challenge_type, cp_bank, cp_accoun # Create counterparty, input data format: # { -# "name":"Friend", -# "other_account_routing_scheme":"IBAN", -# "other_account_routing_address":"GR1301720530005053000582373", -# "other_bank_routing_scheme":"BIC", -# "other_bank_routing_address":"PIRBGRAAXXX", -# "is_beneficiary":true +# "name": "test3", +# "other_account_routing_scheme": "BankAccountID", +# "other_account_routing_address": "1000203892", +# "other_bank_routing_scheme": "BankId", +# "other_bank_routing_address": "00100", +# "other_branch_routing_scheme": "OBP", +# "other_branch_routing_address": "Berlin", +# "is_beneficiary": true # } + def createCounterparty(bank_id, account_id, name, @@ -181,6 +184,8 @@ def createCounterparty(bank_id, 'other_account_routing_address': '%s' % other_account_routing_address, 'other_bank_routing_scheme' : '%s' % other_bank_routing_scheme, 'other_bank_routing_address' : '%s' % other_bank_routing_address, + 'other_branch_routing_scheme' : 'OBP', # not useful now, set default value + 'other_branch_routing_address' : 'Berlin', # not useful now, set default value 'is_beneficiary' : True } # Send post request with attached json diff --git a/props/localtest_Socgen1_k.py b/props/socgen1_k.py similarity index 100% rename from props/localtest_Socgen1_k.py rename to props/socgen1_k.py diff --git a/props/localtest_Socgen1_k_two_owners.py b/props/socgen1_k_two_owners.py similarity index 94% rename from props/localtest_Socgen1_k_two_owners.py rename to props/socgen1_k_two_owners.py index 0585f5b..b7014c8 100644 --- a/props/localtest_Socgen1_k_two_owners.py +++ b/props/socgen1_k_two_owners.py @@ -25,10 +25,10 @@ # the following there acounds are all belong to login user : 1000203893 # TO_ACCOUNT_ID = '3806441b-bbdf-3c60-b2b3-14e2f645635f' # TO_ACCOUNT_ID = '83b96bb4-ae2c-3e90-ad2c-8ce0b4b0023b' -TO_ACCOUNT_ID = 'df88925b-4a7f-31f6-a077-3dcbd60b669f' +# TO_ACCOUNT_ID = 'df88925b-4a7f-31f6-a077-3dcbd60b669f' # this account is belong to user: 1000203892 -# TO_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' +TO_ACCOUNT_ID = '410ad4eb-9f63-300f-8cb9-12f0ab677521' # these accounts are belong to user: 1000203891 # TO_ACCOUNT_ID = '1f5587fa-8ad8-3c6b-8fac-ac3db5bdc3db' diff --git a/props/localtest_Socgen2_k.py b/props/socgen2_k.py similarity index 100% rename from props/localtest_Socgen2_k.py rename to props/socgen2_k.py diff --git a/props/localtest_Socgen2_k_local.py b/props/socgen2_k_local.py similarity index 100% rename from props/localtest_Socgen2_k_local.py rename to props/socgen2_k_local.py From b3849c8abd1f6709fec2946f8baf886e9276de2b Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Tue, 28 Mar 2017 14:19:53 +0200 Subject: [PATCH 14/26] added test for make-payments, over kafka, counterparty locally. --- ...o_payments_V210_Socgenk-getTransactions.py | 36 +++ hello_payments_V210_Socgenk.py | 11 +- hello_payments_V210_kafka.py | 121 +++++----- ..._payments_V210_kafka_Counterparty_local.py | 220 ++++++++++++++++++ hello_payments_V210_mapper.py | 153 ++++++------ hello_payments_V210_socgenk_two_owners.py | 4 +- lib/obp.py | 43 ++-- props/localtest_kafka.py | 20 +- 8 files changed, 438 insertions(+), 170 deletions(-) create mode 100644 hello_payments_V210_Socgenk-getTransactions.py create mode 100644 hello_payments_V210_kafka_Counterparty_local.py diff --git a/hello_payments_V210_Socgenk-getTransactions.py b/hello_payments_V210_Socgenk-getTransactions.py new file mode 100644 index 0000000..27b0681 --- /dev/null +++ b/hello_payments_V210_Socgenk-getTransactions.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests + +# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN +# over Socgen1-k https://socgen-k-api.openbankproject.com/ +# or over Socgen2-k https://socgen2-k-api.openbankproject.com/ +# or local : http://127.0.0.1:8080 (You need set up local test environment) + +# Note: +# All needed users and accounts are now kept in 'localtest_Socgen1-k.py' or 'localtest_Socgen2-k.py'' or 'localtest_Socgen2-k'', +# You can pick up one to test the sandbox you want, just modify the following lines to switch props +from props.socgen1_k import * +#from props.socgen2_k import * +# from props.localtest_Socgen2_k_local import * + + +#########################Step 1 : Direct Login process .################ + +import lib.obp +import logging +#logging.basicConfig(level=logging.DEBUG) + +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +print("Call API - 0 'DirectLogin' -- login and set authorized token") +obp.login(USERNAME, PASSWORD, CONSUMER_KEY) + +# Then we need to check the get Transactions +print("") +print("Call API - 3 'Get Transactions for Account (Full)-- V210'") +getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) + +obp.printGetTransactions(getTransactions_response) diff --git a/hello_payments_V210_Socgenk.py b/hello_payments_V210_Socgenk.py index f188017..1ff48e6 100644 --- a/hello_payments_V210_Socgenk.py +++ b/hello_payments_V210_Socgenk.py @@ -10,17 +10,16 @@ # Note: # All needed users and accounts are now kept in 'localtest_Socgen1-k.py' or 'localtest_Socgen2-k.py'' or 'localtest_Socgen2-k'', # You can pick up one to test the sandbox you want, just modify the following lines to switch props -# from props.localtest_Socgen1_k import * -from props.socgen2_k import * +from props.socgen1_k import * +#from props.socgen2_k import * # from props.localtest_Socgen2_k_local import * -#########################Step 1 : Login in(OAuth process).################ +#########################Step 1 : Direct Login process .################ import lib.obp import logging - -logging.basicConfig(level=logging.DEBUG) +#logging.basicConfig(level=logging.DEBUG) obp = lib.obp obp.setBaseUrl(BASE_URL) @@ -75,4 +74,4 @@ new_transaction_id = challenge_response["transaction_ids"] getTransactions_response = obp.getTransactions(from_bank_id, from_account_id) -obp.printGetTransactionsResponse(getTransactions_response, new_transaction_id) +obp.printGetTransactions(getTransactions_response) diff --git a/hello_payments_V210_kafka.py b/hello_payments_V210_kafka.py index 2336115..190e55b 100644 --- a/hello_payments_V210_kafka.py +++ b/hello_payments_V210_kafka.py @@ -1,24 +1,35 @@ # -*- coding: utf-8 -*- from __future__ import print_function # (at top of module) import sys, requests +import lib.obp -# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN, SEPA, COUNTERPARTY (kafka) - -# Note: in order to use this example, you need to have at least one account that you can send money from (i.e. be the owner). -# And another account to receiver money(toBankAccount and toCounterparty fields should be correct) -# All properties are now kept in 'localtest_kafka.py',you need set up your own props. -#########################Step 1 : Login in(OAuth process) and prepare the bankaccounts to make the payment.################ -# You probably don't need to change those -# connector=mapped +# test payment workflow +# prerequisites: +# 1 run OBP-API and run OBP-Kafka_Python +# 2 in props +# get_counterparties_from_OBP_DB = false +# connector=kafka_vMar2017 +# 3 prepare your own accounts info +# Reference : localtest_kafka.py +# +# test endpoint list: +# 1 Create Transaction Request. (SANDBOX_TAN)- V210 +# 2 Create Transaction Request. (SEPA)- V210 +# 3 Create Transaction Request. (COUNTERPARTY)- V210 +# 4 Answer Transaction Request Challenge. (SANDBOX_TAN)-V210 +# 5 Answer Transaction Request Challenge. (SEPA)-V210 +# 6 Answer Transaction Request Challenge. (COUNTERPARTY)-V210 +# 7 Get Transaction by Id. -V121 +# 8 Get Transactions for Account (Full)-- V210 + +#########################Step1 : Direct Login process ################ from props.localtest_kafka import * -import lib.obp obp = lib.obp obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION_V210) -# login and set authorized token print("Call API - 0 'DirectLogin'") obp.login(USERNAME, PASSWORD, CONSUMER_KEY) @@ -26,58 +37,51 @@ from_bank_id = FROM_BANK_ID from_account_id = FROM_ACCOUNT_ID - -######################### Step2 - make a payment - SANDBOX_TAN ################ +######################### Step2 : make a payment - SANDBOX_TAN ################ print("") print("") # set receiver bank account: to_bank_id = TO_BANK_ID to_account_id = TO_ACCOUNT_ID -challenge_type_sandbox_tan = "SANDBOX_TAN" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) -#####Case1: without challenge +TRANSACTION_REQUEST_TYPE_SANDBOX_TAN = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_SANDBOX_TAN)) print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sandbox_tan, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, to_bank_id=to_bank_id, # for SANDBOX_TAN to_account_id=to_account_id, # for SANDBOX_TAN to_counterparty_id="", # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY - -# There was no challenge, transaction was created immediately obp.printMessageNoChallenge(initiate_response) -#####Case2: with challenge print("") print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sandbox_tan, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, to_bank_id=to_bank_id, # for SANDBOX_TAN to_account_id=to_account_id, # for SANDBOX_TAN to_counterparty_id="", # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' obp.printMessageWithChallenge(initiate_response) -# Then we need to answer the challenge -challenge_query = initiate_response['challenge']['id'] -transaction_req_id = initiate_response['id'] print("") print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") -print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sandbox_tan, challenge_query) - +transaction_req_id = initiate_response['id'] +challenge_query = initiate_response['challenge']['id'] +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, + challenge_query) obp.printMessageAfterAnswerChallenge(challenge_response) @@ -87,8 +91,8 @@ # set receiver COUNTERPARTY_IBAN: to_counterparty_iban = TO_COUNTERPARTY_IBAN -challenge_type_sepa = "SEPA" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) +TRANSACTION_REQUEST_TYPE_SEPA = "SEPA" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_SEPA)) #####Case1: without challenge print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail @@ -96,15 +100,11 @@ # call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sepa, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SEPA, to_bank_id="", # for SANDBOX_TAN to_account_id="", # for SANDBOX_TAN to_counterparty_id="", # used for SEPA to_counterparty_iban=to_counterparty_iban) # used for COUNTERPARTY -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# There was no challenge, transaction was created immediately obp.printMessageNoChallenge(initiate_response) #####Case2: with challenge @@ -112,16 +112,14 @@ print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sepa, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SEPA, to_bank_id="", # for SANDBOX_TAN to_account_id="", # for SANDBOX_TAN to_counterparty_id="", # used for SEPA to_counterparty_iban=to_counterparty_iban) # used for COUNTERPARTY -# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' obp.printMessageWithChallenge(initiate_response) # we need to answer the challenge @@ -130,8 +128,7 @@ print("") print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") -print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_query) +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, TRANSACTION_REQUEST_TYPE_SEPA, challenge_query) obp.printMessageAfterAnswerChallenge(challenge_response) @@ -142,47 +139,57 @@ # set receiver COUNTERPARTY_ID: to_counterparty_id = TO_COUNTERPARTY_ID -challenge_type_counterparty = "COUNTERPARTY" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) -#####Case1: without challenge +TRANSACTION_REQUEST_TYPE_COUNTERPARTY = "COUNTERPARTY" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_COUNTERPARTY)) print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_counterparty, + transaction_request_type=TRANSACTION_REQUEST_TYPE_COUNTERPARTY, to_bank_id="", # for SANDBOX_TAN to_account_id="", # for SANDBOX_TAN to_counterparty_id=to_counterparty_id, # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY - -# There was no challenge, transaction was created immediately obp.printMessageNoChallenge(initiate_response) -#####Case2: with challenge + print("") print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_counterparty, + transaction_request_type=TRANSACTION_REQUEST_TYPE_COUNTERPARTY, to_bank_id="", # for SANDBOX_TAN to_account_id="", # for SANDBOX_TAN to_counterparty_id=to_counterparty_id, # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' obp.printMessageWithChallenge(initiate_response) -# we need to answer the challenge +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") challenge_query = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_COUNTERPARTY, + challenge_query) + +obp.printMessageAfterAnswerChallenge(challenge_response) +######################## Step5 - Get Transactions ################ print("") -print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") -print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, challenge_query) +print("") +print("--------- Check the new transaction records") +print("Call API - 1 'Get Transaction by Id.-- V121'") + +newTransactionId = challenge_response["transaction_ids"] +getTransaction_response = obp.getTransaction(FROM_BANK_ID, FROM_ACCOUNT_ID, newTransactionId) +obp.printGetTransaction(getTransaction_response, newTransactionId) -obp.printMessageAfterAnswerChallenge(challenge_response) \ No newline at end of file +print("Call API - 2 'Get Transactions for Account (Full)-- V121'") +getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) +obp.printGetTransactions(getTransactions_response) diff --git a/hello_payments_V210_kafka_Counterparty_local.py b/hello_payments_V210_kafka_Counterparty_local.py new file mode 100644 index 0000000..be7c795 --- /dev/null +++ b/hello_payments_V210_kafka_Counterparty_local.py @@ -0,0 +1,220 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests +import uuid +import lib.obp + +# test payment workflow +# prerequisites: +# 1 run OBP-API and run OBP-Kafka_Python +# 2 in props +# get_counterparties_from_OBP_DB =true +# connector=kafka_vMar2017 +# 3 prepare your own accounts info +# Reference : localtest_kafka.py +# +# test endpoint list: +# 1 Create counterparty for an account - V210 +# 2 Create Transaction Request. (SANDBOX_TAN)- V210 +# 3 Create Transaction Request. (SEPA)- V210 +# 4 Create Transaction Request. (COUNTERPARTY)- V210 +# 5 Answer Transaction Request Challenge. (SANDBOX_TAN)-V210 +# 6 Answer Transaction Request Challenge. (SEPA)-V210 +# 7 Answer Transaction Request Challenge. (COUNTERPARTY)-V210 +# 8 Get Transaction by Id. -V121 +# 9 Get Transactions for Account (Full)-- V210 + +#########################Step 1 : Direct Login process.################ +from props.localtest_kafka import * +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +# login and set authorized token +print("Call API - 0 'DirectLogin'") +obp.login(USERNAME, PASSWORD, CONSUMER_KEY) + +# set fromAccount info: +from_bank_id = FROM_BANK_ID +from_account_id = FROM_ACCOUNT_ID + +# set fromAccount info: +from_bank_id = FROM_BANK_ID +from_account_id = FROM_ACCOUNT_ID + + +######################### Step2 - make a payment - SANDBOX_TAN ################ +print("") +print("") +# set the toAccount for SANDBOX_TAN +to_bank_id = TO_BANK_ID +to_account_id = TO_ACCOUNT_ID + +TRANSACTION_REQUEST_TYPE_SANDBOX_TAN = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_SANDBOX_TAN)) +#####Case1: without challenge +print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +# call 'Create Transaction Requests - V210' endpoint +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, + to_bank_id=to_bank_id, + to_account_id=to_account_id, + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY + +# There was no challenge, transaction was created immediately +obp.printMessageNoChallenge(initiate_response) + +#####Case2: with challenge +print("") +print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, + to_bank_id=to_bank_id, + to_account_id=to_account_id, + to_counterparty_id="", # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +obp.printMessageWithChallenge(initiate_response) + +print("") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") +transaction_req_id = initiate_response['id'] +challenge_id = initiate_response['challenge']['id'] +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, + challenge_id) + +obp.printMessageAfterAnswerChallenge(challenge_response) + +######################### Step3 - make a payment - SEPA ################ +print("") +print("") +TRANSACTION_REQUEST_TYPE_SEPA = "SEPA" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_SEPA)) + +to_counterparty_iban = str(uuid.uuid4()) +print("Call API - 1 'Create counterparty for an account. -- V210'") +create_counterparty_response = obp.createCounterparty(bank_id=from_bank_id, + account_id=from_account_id, + name=str(uuid.uuid4()), + other_account_routing_scheme="IBAN",# for SEPA, here must be IBAN + other_account_routing_address=to_counterparty_iban, + other_bank_routing_scheme="test", + other_bank_routing_address="test") +obp.printCreateCounterparty(create_counterparty_response) + +print("") +print("Call API - 2 'Create Transaction Request. -- V210' (no challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SEPA, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id="", # used for COUNTERPARTY + to_counterparty_iban=to_counterparty_iban)# used for SEPA +obp.printMessageNoChallenge(initiate_response) + +print("") +print("Call API - 3 'Create Transaction Request. -- V210' (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SEPA, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id="", # used for COUNTERPARTY + to_counterparty_iban=to_counterparty_iban) # used for SEPA +obp.printMessageWithChallenge(initiate_response) + +print("") +print("Call API - 4 'Answer Transaction Request Challenge. -- V210'") +transaction_req_id = initiate_response['id'] +challenge_id = initiate_response['challenge']['id'] +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_SEPA, + challenge_id) + +obp.printMessageAfterAnswerChallenge(challenge_response) + +######################### Step4 - make a payment - COUNTERPARTY ################ +print("") +print("") +TRANSACTION_REQUEST_TYPE_COUNTERPARTY = "COUNTERPARTY" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_COUNTERPARTY)) +print("Call API - 1 'Create counterparty for an account. -- V210'") +create_counterparty_response = obp.createCounterparty(bank_id=from_bank_id, + account_id=from_account_id, + name=str(uuid.uuid4()), + other_account_routing_scheme="OBP", + other_account_routing_address="test", + other_bank_routing_scheme="OBP", + other_bank_routing_address="test") +obp.printCreateCounterparty(create_counterparty_response) + +print("") +print("Call API - 2 'Create Transaction Request. -- V210' (no challenge)") +# set up a small value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) +to_counterparty_id = create_counterparty_response['counterparty_id'] +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=TRANSACTION_REQUEST_TYPE_COUNTERPARTY, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, + to_counterparty_iban="") # used for SEPA +obp.printMessageNoChallenge(initiate_response) + + +print("") +print("Call API - 3 'Create Transaction Request. -- V210' (with challenge)") +# set up a large value in payment detail +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) +initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, + from_account_id=from_account_id, + transaction_request_type=TRANSACTION_REQUEST_TYPE_COUNTERPARTY, + to_bank_id="", # used for SANDBOX_TAN + to_account_id="", # used for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, + to_counterparty_iban="") # used for SEPA +obp.printMessageWithChallenge(initiate_response) + +print("") +print("Call API - 4 'Answer Transaction Request Challenge. -- V210'") +transaction_req_id = initiate_response['id'] +challenge_id = initiate_response['challenge']['id'] +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_COUNTERPARTY, + challenge_id) +obp.printMessageAfterAnswerChallenge(challenge_response) + +######################## Step5 - Get Transactions ################ +print("") +print("") +print("--------- Check the new transaction records") +print("Call API - 1 'Get Transaction by Id.-- V121'") + +newTransactionId = challenge_response["transaction_ids"] +getTransaction_response = obp.getTransaction(FROM_BANK_ID, FROM_ACCOUNT_ID, newTransactionId) +obp.printGetTransaction(getTransaction_response, newTransactionId) + +print("Call API - 2 'Get Transactions for Account (Full)-- V121'") +getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) +obp.printGetTransactions(getTransactions_response) + + diff --git a/hello_payments_V210_mapper.py b/hello_payments_V210_mapper.py index 91033cd..a0f14c0 100644 --- a/hello_payments_V210_mapper.py +++ b/hello_payments_V210_mapper.py @@ -1,26 +1,37 @@ # -*- coding: utf-8 -*- from __future__ import print_function # (at top of module) import sys, requests - -# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN, SEPA, COUNTERPARTY (mapped) - -# Note: in order to use this example, you need to have at least one account that you can send money from (i.e. be the owner). -# And another account to receiver money(for SEPA or COUNTERPARTY, create a new COUNTERPARTY do need to prepare for them) -# All properties are now kept in 'localtest_mapper.py',you need set up your own props. - -#########################Step 1 : Login in(OAuth process) and prepare the bankaccounts to make the payment.################ -# You probably don't need to change those -# connector=mapped import uuid -from props.localtest_mapper import * import lib.obp +# test payment workflow +# prerequisites: +# 1 run OBP-API and run OBP-Kafka_Python +# 2 in props +# connector=mapped +# 3 prepare your own accounts info +# Reference : localtest_mapper.py +# +# test endpoint list: +# 1 Create counterparty for an account - V210 +# 2 Create Transaction Request. (SANDBOX_TAN)- V210 +# 3 Create Transaction Request. (SEPA)- V210 +# 4 Create Transaction Request. (COUNTERPARTY)- V210 +# 5 Answer Transaction Request Challenge. (SANDBOX_TAN)-V210 +# 6 Answer Transaction Request Challenge. (SEPA)-V210 +# 7 Answer Transaction Request Challenge. (COUNTERPARTY)-V210 +# 8 Get Transaction by Id. -V121 +# 9 Get Transactions for Account (Full)-- V210 + +#########################Step1 : Direct Login process ################import uuid +from props.localtest_mapper import * + obp = lib.obp obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION_V210) -# login and set authorized token +print("Call API - 0 'DirectLogin'") obp.login(USERNAME, PASSWORD, CONSUMER_KEY) # set the fromAccount info: @@ -34,16 +45,14 @@ to_bank_id = TO_BANK_ID to_account_id = TO_ACCOUNT_ID -challenge_type_sandbox_tan = "SANDBOX_TAN" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sandbox_tan)) -#####Case1: without challenge +TRANSACTION_REQUEST_TYPE_SANDBOX_TAN = "SANDBOX_TAN" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_SANDBOX_TAN)) print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sandbox_tan, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, to_bank_id=to_bank_id, to_account_id=to_account_id, to_counterparty_id="", # used for SEPA @@ -57,39 +66,34 @@ print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sandbox_tan, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, to_bank_id=to_bank_id, to_account_id=to_account_id, to_counterparty_id="", # used for SEPA to_counterparty_iban="") # used for COUNTERPARTY -# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' obp.printMessageWithChallenge(initiate_response) -# we need to answer the challenge print("") -print("Then we need to answer the challenge") +print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") challenge_id = initiate_response['challenge']['id'] transaction_req_id = initiate_response['id'] - -print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") -print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sandbox_tan, challenge_id) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_SANDBOX_TAN, + challenge_id) obp.printMessageAfterAnswerChallenge(challenge_response) ######################### Step3 - make a payment - SEPA ################ print("") print("") -challenge_type_sepa = "SEPA" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_sepa)) +TRANSACTION_REQUEST_TYPE_SEPA = "SEPA" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_SEPA)) -# Create the new COUNTERPARTY for SEPA, other_account_routing_scheme must equal "IBAN" +print("Call API - 1 'Create counterparty for an account. -- V210'") to_counterparty_iban = str(uuid.uuid4()) create_counterparty_response = obp.createCounterparty(bank_id=from_bank_id, account_id=from_account_id, @@ -98,65 +102,54 @@ other_account_routing_address=to_counterparty_iban, other_bank_routing_scheme="test", other_bank_routing_address="test") +obp.printCreateCounterparty(create_counterparty_response) -print("create Counterparty was successfully created:") -print("{0}".format(create_counterparty_response)) - -#####Case1: without challenge print("") -print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") +print("Call API - 2 'Create Transaction Request. -- V210' (no challenge)") # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sepa, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SEPA, to_bank_id="", # used for SANDBOX_TAN to_account_id="", # used for SANDBOX_TAN to_counterparty_id="", # used for COUNTERPARTY to_counterparty_iban=to_counterparty_iban) -if "error" in create_counterparty_response: - sys.exit("Got an error: " + str(create_counterparty_response)) - -# There was no challenge, transaction was created immediately obp.printMessageNoChallenge(initiate_response) -#####Case2: with challenge print("") print("Call API - 2 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_sepa, + transaction_request_type=TRANSACTION_REQUEST_TYPE_SEPA, to_bank_id="", # used for SANDBOX_TAN to_account_id="", # used for SANDBOX_TAN to_counterparty_id="", # used for COUNTERPARTY to_counterparty_iban=to_counterparty_iban) -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' obp.printMessageWithChallenge(initiate_response) -# we need to answer the challenge -challenge_id = initiate_response['challenge']['id'] -transaction_req_id = initiate_response['id'] print("") print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_sepa, challenge_id) +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_SEPA, + challenge_id) +challenge_id = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] obp.printMessageAfterAnswerChallenge(challenge_response) ######################### Step4 - make a payment - COUNTERPARTY ################ print("") print("") -challenge_type_counterparty = "COUNTERPARTY" -print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(challenge_type_counterparty)) +TRANSACTION_REQUEST_TYPE_COUNTERPARTY = "COUNTERPARTY" +print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_COUNTERPARTY)) -# Create the new COUNTERPARTY, toCounterparty.other_account_routing_scheme =="OBP" && toCounterparty.other_bank_routing_scheme=="OBP") +print("Call API - 1 'Create counterparty for an account. -- V210'") create_counterparty_response = obp.createCounterparty(bank_id=from_bank_id, account_id=from_account_id, name=str(uuid.uuid4()), @@ -164,22 +157,16 @@ other_account_routing_address="test", other_bank_routing_scheme="OBP", other_bank_routing_address="test") -if "error" in create_counterparty_response: - sys.exit("Got an error: " + str(create_counterparty_response)) - -print("create Counterparty was successfully created:") -print("{0}".format(create_counterparty_response)) -to_counterparty_id = create_counterparty_response['counterparty_id'] +obp.printCreateCounterparty(create_counterparty_response) -#####Case1: without challenge print("") print("Call API - 1 'Create Transaction Request. -- V210' (no challenge)") +to_counterparty_id = create_counterparty_response['counterparty_id'] # set up a small value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_counterparty, + transaction_request_type=TRANSACTION_REQUEST_TYPE_COUNTERPARTY, to_bank_id="", # used for SANDBOX_TAN to_account_id="", # used for SANDBOX_TAN to_counterparty_id=to_counterparty_id, @@ -188,31 +175,43 @@ # There was no challenge, transaction was created immediately obp.printMessageNoChallenge(initiate_response) -#####Case2: with challenge print("") print("Call API - 3 'Create Transaction Request. -- V210' (with challenge)") # set up a large value in payment detail obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) -# call 'Create Transaction Requests - V210' endpoint initiate_response = obp.createTransactionRequestV210(from_bank_id=from_bank_id, from_account_id=from_account_id, - transaction_request_type=challenge_type_counterparty, + transaction_request_type=TRANSACTION_REQUEST_TYPE_COUNTERPARTY, to_bank_id="", # used for SANDBOX_TAN to_account_id="", # used for SANDBOX_TAN to_counterparty_id=to_counterparty_id, to_counterparty_iban="") # used for SEPA -# There was a challenge, transaction was interrupted, and the transaction_request is 'INITIATED' obp.printMessageWithChallenge(initiate_response) -# we need to answer the challenge -challenge_id = initiate_response['challenge']['id'] -transaction_req_id = initiate_response['id'] print("") print("Call API - 3 'Answer Transaction Request Challenge. -- V210'") print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") -challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, challenge_type_counterparty, +# we need to answer the challenge +challenge_id = initiate_response['challenge']['id'] +transaction_req_id = initiate_response['id'] +challenge_response = obp.answerChallengeV210(from_bank_id, + from_account_id, + transaction_req_id, + TRANSACTION_REQUEST_TYPE_COUNTERPARTY, challenge_id) -if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - obp.printMessageAfterAnswerChallenge(challenge_response) + + +######################## Step5 - Get Transactions ################ +print("") +print("") +print("--------- Check the new transaction records") +print("Call API - 1 'Get Transaction by Id.-- V121'") + +newTransactionId = challenge_response["transaction_ids"] +getTransaction_response = obp.getTransaction(from_bank_id, from_account_id, newTransactionId) +obp.printGetTransaction(getTransaction_response, newTransactionId) + +print("Call API - 2 'Get Transactions for Account (Full)-- V121'") +getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) +obp.printGetTransactions(getTransactions_response) \ No newline at end of file diff --git a/hello_payments_V210_socgenk_two_owners.py b/hello_payments_V210_socgenk_two_owners.py index 5cef0db..0a00bdc 100644 --- a/hello_payments_V210_socgenk_two_owners.py +++ b/hello_payments_V210_socgenk_two_owners.py @@ -9,7 +9,7 @@ # This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN # over Socgen1-k https://socgen-k-api.openbankproject.com/ -#########################Step 1 : Login in(OAuth process).################ +#########################Step 1 : Direct Login process .################ from props.socgen1_k_two_owners import * #17 obp = lib.obp @@ -164,4 +164,4 @@ print("Call API - 1 'Get Transactions for Account (Full)-- V210'") new_transaction_id = challenge_response["transaction_ids"] getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) -obp.printGetTransactionsResponse(getTransactions_response, new_transaction_id) \ No newline at end of file +obp.printGetTransactions(getTransactions_response) \ No newline at end of file diff --git a/lib/obp.py b/lib/obp.py index 5cdfefb..faf56f1 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -130,6 +130,11 @@ def getTransactions(bank, account): response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transactions".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json()['transactions'] +# Get Transaction by Id. +def getTransaction(bank_id, account_id, transaction_id): + response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transactions/{4}/transaction".format(BASE_URL, API_VERSION, bank_id, account_id, transaction_id), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + return response.json() + # Get challenge types def getChallengeTypes(bank, account): response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) @@ -227,10 +232,16 @@ def addEntitlement(entitlement, user, bank=''): # Answer Transaction Request Challenge. - V210 -def answerChallengeV210(bank_id, account_id, transation_req_id, challenge_type, challenge_query): - body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode - response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests/{5}/challenge".format( - BASE_URL, API_VERSION, bank_id, account_id, challenge_type, transation_req_id), data=body, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON) +def answerChallengeV210(bank_id, + account_id, + transation_req_id, + challenge_type, + challenge_query): + body = '{"id": "' + challenge_query + '","answer": "123456"}' # any number works in sandbox mode + response = requests.post( u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/transaction-request-types/{4}/transaction-requests/{5}/challenge".format( + BASE_URL, API_VERSION, bank_id, account_id, challenge_type, + transation_req_id), data=body, + headers=mergeHeaders(DL_TOKEN, CONTENT_JSON) ) return response.json() @@ -297,28 +308,24 @@ def printMessageAfterAnswerChallenge(response): print("New Transaction ID created: {0}".format(response["transaction_ids"])) -def printGetTransactionsResponse(response,new_transaction_id): +def printGetTransactions(response): if "error" in response: sys.exit("Got an error: " + str(response)) - - print("Check the whether new_transaction_id ({0}) is in response: ".format(new_transaction_id)) - if new_transaction_id in str(response) : - for transaction in response: - if new_transaction_id in str(response) : - print (transaction) - else: - print ("Note: the new_transaction_id ({0}) is not in response !!!".format(new_transaction_id)) - - print("") print("Print all the transactions : ") count=0 for transaction in response: count=count + 1 print (str(count) +":"+str(transaction)) - + +def printGetTransaction(response, newTransactionId): + if "error" in response: + sys.exit("Got an error: " + str(response)) + print("Check wther the new transactionId{0} is exsting".format(newTransactionId)) + print("The result is: {0}".format(response)) + def printCreateCounterparty(response): if "error" in response: - print("The result is: {0}".format(response)) - # sys.exit("Got an error: " + str(response)) + sys.exit("Got an error: " + str(response)) print("Counterparty is created:") print("The result is: {0}".format(response)) + diff --git a/props/localtest_kafka.py b/props/localtest_kafka.py index b81eccf..476c0d0 100644 --- a/props/localtest_kafka.py +++ b/props/localtest_kafka.py @@ -3,23 +3,23 @@ # if you want to transfer to other account or counterparty, you need prepare your own data. # API server URL -BASE_URL = "http://127.0.0.1:8080" -API_VERSION = "v2.0.0" -API_VERSION_V210 = "v2.1.0" +BASE_URL = "http://127.0.0.1:8080" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" # API server will redirect your browser to this URL, should be non-functional # You will paste the redirect location here when running the script CALLBACK_URI = 'http://127.0.0.1/cb' -#login user: -USERNAME = 'robert.x.0.gh@example.com' -PASSWORD = '3e3a3102' +# login user: +USERNAME = 'robert.x.0.gh@example.com' +PASSWORD = '3e3a3102' CONSUMER_KEY = 'e0xcuubmfzkdbaef30zmrgnwa51dekgnf3vxhavp' -#fromAccount info: -FROM_BANK_ID = 'obp-bank-x-gh' -FROM_ACCOUNT_ID = 'e0ec24be-5ab1-4760-9189-ad280228c134' +# fromAccount info: +FROM_BANK_ID = 'obp-bank-x-gh' +FROM_ACCOUNT_ID = 'e0ec24be-5ab1-4760-9189-ad280228c134' -#toBankAccount and toCounterparty info: +# toBankAccount and toCounterparty info(These data is from kafka side): TO_BANK_ID = 'obp-bank-x-gh' TO_ACCOUNT_ID = 'e4f001fe-0f0d-4f93-a8b2-d865077315ec' TO_COUNTERPARTY_ID = 'a635f6ff-c26b-46ad-8194-2406bacceae4' From b77a91e6ecdefa24598ee2c9200d649793f46fd6 Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Tue, 28 Mar 2017 18:05:39 +0200 Subject: [PATCH 15/26] rename some file name and move the payment-test over k1 server --- ...o_payments_V210_Socgenk-getTransactions.py | 36 ------------------- hello_payments_V210_kafka.py | 4 +-- ..._payments_V210_kafka_Counterparty_local.py | 17 ++++----- ...mapper.py => hello_payments_V210_mapped.py | 3 +- ...enk.py => hello_payments_V210_one_owner.py | 0 ...rs.py => hello_payments_V210_two_owners.py | 0 props/k1_kafka.py | 31 ++++++++++++++++ 7 files changed, 40 insertions(+), 51 deletions(-) delete mode 100644 hello_payments_V210_Socgenk-getTransactions.py rename hello_payments_V210_mapper.py => hello_payments_V210_mapped.py (99%) rename hello_payments_V210_Socgenk.py => hello_payments_V210_one_owner.py (100%) rename hello_payments_V210_socgenk_two_owners.py => hello_payments_V210_two_owners.py (100%) create mode 100644 props/k1_kafka.py diff --git a/hello_payments_V210_Socgenk-getTransactions.py b/hello_payments_V210_Socgenk-getTransactions.py deleted file mode 100644 index 27b0681..0000000 --- a/hello_payments_V210_Socgenk-getTransactions.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function # (at top of module) -import sys, requests - -# This test is calling in V210 of OBP-API, Create Transaction Request for SANDBOX_TAN -# over Socgen1-k https://socgen-k-api.openbankproject.com/ -# or over Socgen2-k https://socgen2-k-api.openbankproject.com/ -# or local : http://127.0.0.1:8080 (You need set up local test environment) - -# Note: -# All needed users and accounts are now kept in 'localtest_Socgen1-k.py' or 'localtest_Socgen2-k.py'' or 'localtest_Socgen2-k'', -# You can pick up one to test the sandbox you want, just modify the following lines to switch props -from props.socgen1_k import * -#from props.socgen2_k import * -# from props.localtest_Socgen2_k_local import * - - -#########################Step 1 : Direct Login process .################ - -import lib.obp -import logging -#logging.basicConfig(level=logging.DEBUG) - -obp = lib.obp -obp.setBaseUrl(BASE_URL) -obp.setApiVersion(API_VERSION_V210) - -print("Call API - 0 'DirectLogin' -- login and set authorized token") -obp.login(USERNAME, PASSWORD, CONSUMER_KEY) - -# Then we need to check the get Transactions -print("") -print("Call API - 3 'Get Transactions for Account (Full)-- V210'") -getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) - -obp.printGetTransactions(getTransactions_response) diff --git a/hello_payments_V210_kafka.py b/hello_payments_V210_kafka.py index 190e55b..26e250f 100644 --- a/hello_payments_V210_kafka.py +++ b/hello_payments_V210_kafka.py @@ -2,7 +2,7 @@ from __future__ import print_function # (at top of module) import sys, requests import lib.obp - +from props.localtest_kafka import * # test payment workflow # prerequisites: @@ -24,8 +24,6 @@ # 8 Get Transactions for Account (Full)-- V210 #########################Step1 : Direct Login process ################ -from props.localtest_kafka import * - obp = lib.obp obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION_V210) diff --git a/hello_payments_V210_kafka_Counterparty_local.py b/hello_payments_V210_kafka_Counterparty_local.py index be7c795..487738a 100644 --- a/hello_payments_V210_kafka_Counterparty_local.py +++ b/hello_payments_V210_kafka_Counterparty_local.py @@ -3,15 +3,15 @@ import sys, requests import uuid import lib.obp +from props.k1_kafka import * +import logging +logging.basicConfig(level=logging.DEBUG) # test payment workflow # prerequisites: -# 1 run OBP-API and run OBP-Kafka_Python -# 2 in props -# get_counterparties_from_OBP_DB =true -# connector=kafka_vMar2017 -# 3 prepare your own accounts info -# Reference : localtest_kafka.py +# 1 https://k1.openbankproject.com is working well +# 2 prepare your own accounts info +# Reference : k1_kafka.py # # test endpoint list: # 1 Create counterparty for an account - V210 @@ -22,10 +22,9 @@ # 6 Answer Transaction Request Challenge. (SEPA)-V210 # 7 Answer Transaction Request Challenge. (COUNTERPARTY)-V210 # 8 Get Transaction by Id. -V121 -# 9 Get Transactions for Account (Full)-- V210 +# 9 Get Transactions for Account (Full)-- V121 #########################Step 1 : Direct Login process.################ -from props.localtest_kafka import * obp = lib.obp obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION_V210) @@ -216,5 +215,3 @@ print("Call API - 2 'Get Transactions for Account (Full)-- V121'") getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) obp.printGetTransactions(getTransactions_response) - - diff --git a/hello_payments_V210_mapper.py b/hello_payments_V210_mapped.py similarity index 99% rename from hello_payments_V210_mapper.py rename to hello_payments_V210_mapped.py index a0f14c0..dd03a58 100644 --- a/hello_payments_V210_mapper.py +++ b/hello_payments_V210_mapped.py @@ -2,7 +2,7 @@ from __future__ import print_function # (at top of module) import sys, requests import uuid - +from props.localtest_mapper import * import lib.obp # test payment workflow @@ -25,7 +25,6 @@ # 9 Get Transactions for Account (Full)-- V210 #########################Step1 : Direct Login process ################import uuid -from props.localtest_mapper import * obp = lib.obp obp.setBaseUrl(BASE_URL) diff --git a/hello_payments_V210_Socgenk.py b/hello_payments_V210_one_owner.py similarity index 100% rename from hello_payments_V210_Socgenk.py rename to hello_payments_V210_one_owner.py diff --git a/hello_payments_V210_socgenk_two_owners.py b/hello_payments_V210_two_owners.py similarity index 100% rename from hello_payments_V210_socgenk_two_owners.py rename to hello_payments_V210_two_owners.py diff --git a/props/k1_kafka.py b/props/k1_kafka.py new file mode 100644 index 0000000..eafdf32 --- /dev/null +++ b/props/k1_kafka.py @@ -0,0 +1,31 @@ +# API server URL +BASE_URL = "https://k1.openbankproject.com" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'https://k1-explorer.openbankproject.com/cb' + +# login user: +USERNAME = 'robert.y.9.gh@example.com' +PASSWORD = 'c9a641df' +CONSUMER_KEY = 'ofljcaggqvcff0ziqcsni4i1bl43fgwelqjasv4m' +#Consumer Secret wtw43dsxvvebssjnp13iafniqh3h0ficonijtxc5 +#Consumer ID 8 + +# fromAccount info: +FROM_BANK_ID = 'obp-bank-y-gh' +FROM_ACCOUNT_ID = 'e4f001fe-0f0d-4f93-a8b2-d865077315ec' + +# toBankAccount and toCounterparty info(These data is from kafka side): +TO_BANK_ID = 'obp-bank-x-gh' +TO_ACCOUNT_ID = 'e0ec24be-5ab1-4760-9189-ad280228c134' +TO_COUNTERPARTY_ID = 'a635f6ff-c26b-46ad-8194-2406bacceae4' +TO_COUNTERPARTY_IBAN = 'DE12 1234 5123 4510 2207 8077 877' + +# Our currency to use +OUR_CURRENCY = 'GBP' +# Our value to transfer +# values below 1000 do not require challenge request +OUR_VALUE = '0.01' +OUR_VALUE_LARGE = '1001.00' From ec09d8d5d3e86120473932b90390c307c7c6040e Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Fri, 31 Mar 2017 09:54:49 +0200 Subject: [PATCH 16/26] added getCounterparties for hello_payments_V210_kafka_Counterparty_local --- hello_payments_V210_kafka_Counterparty_local.py | 12 ++++++++++++ lib/obp.py | 14 ++++++++++++++ props/k1_kafka.py | 1 + props/localtest_kafka.py | 10 +++++----- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/hello_payments_V210_kafka_Counterparty_local.py b/hello_payments_V210_kafka_Counterparty_local.py index 487738a..a5e480b 100644 --- a/hello_payments_V210_kafka_Counterparty_local.py +++ b/hello_payments_V210_kafka_Counterparty_local.py @@ -23,6 +23,7 @@ # 7 Answer Transaction Request Challenge. (COUNTERPARTY)-V210 # 8 Get Transaction by Id. -V121 # 9 Get Transactions for Account (Full)-- V121 +# 10 Get Counterparties of one Account.-- V220 #########################Step 1 : Direct Login process.################ obp = lib.obp @@ -215,3 +216,14 @@ print("Call API - 2 'Get Transactions for Account (Full)-- V121'") getTransactions_response = obp.getTransactions(FROM_BANK_ID, FROM_ACCOUNT_ID) obp.printGetTransactions(getTransactions_response) + + +######################## Step6 - Get Counterparties ################ +print("") +print("") +print("--------- Get the Counterparties") +print("Call API - 1 'Get Counterparties of one Account..-- V220'") +obp.setApiVersion(API_VERSION_V220) + +getCounterparties_response = obp.getCounterparties(FROM_BANK_ID, FROM_ACCOUNT_ID) +obp.printGetCounterparties(getCounterparties_response) diff --git a/lib/obp.py b/lib/obp.py index faf56f1..87a1673 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -277,6 +277,12 @@ def createTransactionRequestV210(from_bank_id, return response.json() +# Get Counterparties of one Account.-V220 +def getCounterparties(bank, account): + response = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/{3}/owner/counterparties".format(BASE_URL, API_VERSION, bank, account), headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + return response.json()['counterparties'] + + # define some help print transaction methods status def printMessageNoChallenge(response): if "error" in response: @@ -329,3 +335,11 @@ def printCreateCounterparty(response): print("Counterparty is created:") print("The result is: {0}".format(response)) +def printGetCounterparties(response): + if "error" in response: + sys.exit("Got an error: " + str(response)) + print("Print all the counterparties : ") + count=0 + for transaction in response: + count=count + 1 + print (str(count) +":"+str(transaction)) \ No newline at end of file diff --git a/props/k1_kafka.py b/props/k1_kafka.py index eafdf32..c84e18d 100644 --- a/props/k1_kafka.py +++ b/props/k1_kafka.py @@ -2,6 +2,7 @@ BASE_URL = "https://k1.openbankproject.com" API_VERSION = "v2.0.0" API_VERSION_V210 = "v2.1.0" +API_VERSION_V220 = "v2.2.0" # API server will redirect your browser to this URL, should be non-functional # You will paste the redirect location here when running the script CALLBACK_URI = 'https://k1-explorer.openbankproject.com/cb' diff --git a/props/localtest_kafka.py b/props/localtest_kafka.py index 476c0d0..5d7f47e 100644 --- a/props/localtest_kafka.py +++ b/props/localtest_kafka.py @@ -11,13 +11,13 @@ CALLBACK_URI = 'http://127.0.0.1/cb' # login user: -USERNAME = 'robert.x.0.gh@example.com' -PASSWORD = '3e3a3102' -CONSUMER_KEY = 'e0xcuubmfzkdbaef30zmrgnwa51dekgnf3vxhavp' +USERNAME = 'robert.y.9.gh@example.com' +PASSWORD = 'c9a641df' +CONSUMER_KEY = '5du40pymqlgufkncfxn3cny5zhlxv3kts5d2a3lj' # fromAccount info: -FROM_BANK_ID = 'obp-bank-x-gh' -FROM_ACCOUNT_ID = 'e0ec24be-5ab1-4760-9189-ad280228c134' +FROM_BANK_ID = 'obp-bank-y-gh' +FROM_ACCOUNT_ID = 'e4f001fe-0f0d-4f93-a8b2-d865077315ec' # toBankAccount and toCounterparty info(These data is from kafka side): TO_BANK_ID = 'obp-bank-x-gh' From 462d1cefeefc41acf265f20a9a775bf5bcfe1276 Mon Sep 17 00:00:00 2001 From: hongwei1 Date: Fri, 7 Apr 2017 11:56:44 +0200 Subject: [PATCH 17/26] added the balance check for kafka and mapped --- ...erparty_local.py => hello_payments_V210.py | 43 ++++++++++++++----- lib/obp.py | 7 ++- props/apisandbox.py | 32 ++++++++++++++ props/{localtest_kafka.py => local_kafka.py} | 1 + .../{localtest_mapper.py => local_mapper.py} | 0 5 files changed, 72 insertions(+), 11 deletions(-) rename hello_payments_V210_kafka_Counterparty_local.py => hello_payments_V210.py (86%) create mode 100644 props/apisandbox.py rename props/{localtest_kafka.py => local_kafka.py} (97%) rename props/{localtest_mapper.py => local_mapper.py} (100%) diff --git a/hello_payments_V210_kafka_Counterparty_local.py b/hello_payments_V210.py similarity index 86% rename from hello_payments_V210_kafka_Counterparty_local.py rename to hello_payments_V210.py index a5e480b..66ae9ed 100644 --- a/hello_payments_V210_kafka_Counterparty_local.py +++ b/hello_payments_V210.py @@ -4,15 +4,15 @@ import uuid import lib.obp from props.k1_kafka import * +#from props.apisandbox import * import logging logging.basicConfig(level=logging.DEBUG) # test payment workflow # prerequisites: -# 1 https://k1.openbankproject.com is working well -# 2 prepare your own accounts info -# Reference : k1_kafka.py -# +# 1 prepare your own accounts info (please try following props first) +# Reference : k1_kafka.py/apisandbox.py +# # test endpoint list: # 1 Create counterparty for an account - V210 # 2 Create Transaction Request. (SANDBOX_TAN)- V210 @@ -24,8 +24,9 @@ # 8 Get Transaction by Id. -V121 # 9 Get Transactions for Account (Full)-- V121 # 10 Get Counterparties of one Account.-- V220 +# 11 Get Counterparties of one Account.-- V220 -#########################Step 1 : Direct Login process.################ +print("#########################Step 1 : Direct Login process.################") obp = lib.obp obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION_V210) @@ -37,15 +38,16 @@ # set fromAccount info: from_bank_id = FROM_BANK_ID from_account_id = FROM_ACCOUNT_ID +getAccount_response_before = obp.getAccount(FROM_BANK_ID, FROM_ACCOUNT_ID) # set fromAccount info: from_bank_id = FROM_BANK_ID from_account_id = FROM_ACCOUNT_ID -######################### Step2 - make a payment - SANDBOX_TAN ################ print("") print("") +print("######################### Step2 - make a payment - SANDBOX_TAN ########") # set the toAccount for SANDBOX_TAN to_bank_id = TO_BANK_ID to_account_id = TO_ACCOUNT_ID @@ -94,9 +96,9 @@ obp.printMessageAfterAnswerChallenge(challenge_response) -######################### Step3 - make a payment - SEPA ################ print("") print("") +print("######################### Step3 - make a payment - SEPA ################") TRANSACTION_REQUEST_TYPE_SEPA = "SEPA" print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_SEPA)) @@ -149,9 +151,9 @@ obp.printMessageAfterAnswerChallenge(challenge_response) -######################### Step4 - make a payment - COUNTERPARTY ################ print("") print("") +print("######################### Step4 - make a payment - COUNTERPARTY #######") TRANSACTION_REQUEST_TYPE_COUNTERPARTY = "COUNTERPARTY" print("--------- TRANSACTION_REQUEST_TYPE : {0}".format(TRANSACTION_REQUEST_TYPE_COUNTERPARTY)) print("Call API - 1 'Create counterparty for an account. -- V210'") @@ -203,9 +205,9 @@ challenge_id) obp.printMessageAfterAnswerChallenge(challenge_response) -######################## Step5 - Get Transactions ################ print("") print("") +print("######################## Step5 - Get Transactions #####################") print("--------- Check the new transaction records") print("Call API - 1 'Get Transaction by Id.-- V121'") @@ -218,12 +220,33 @@ obp.printGetTransactions(getTransactions_response) -######################## Step6 - Get Counterparties ################ print("") print("") +print("######################## Step6 - Get Counterparties ################") print("--------- Get the Counterparties") print("Call API - 1 'Get Counterparties of one Account..-- V220'") obp.setApiVersion(API_VERSION_V220) getCounterparties_response = obp.getCounterparties(FROM_BANK_ID, FROM_ACCOUNT_ID) obp.printGetCounterparties(getCounterparties_response) + +print("") +print("") +print("######################## Step7 - Get Bank Account, check balance ##") +print("--------- Get the Bank and check the balance") +print("Call API - 1 'Get Account by Id (Core) -- V220'") +obp.setApiVersion(API_VERSION_V220) + +print("The Bank Detail before make transactions:") +obp.printGetAccount(getAccount_response_before) +balance_before = getAccount_response_before['balance']['amount'] +getAccount_response = obp.getAccount(FROM_BANK_ID, FROM_ACCOUNT_ID) +print("The Bank Detail after make transactions:") +obp.printGetAccount(getAccount_response) +balance_after = getAccount_response['balance']['amount'] + +print("Check the balance changed, we make 6 times transfer in this script, total transfer should be 3003 (1000+1+1000+1+1000+1):") +print("The Balance changed between before and after: {0}".format(round((float(balance_before) - float(balance_after)),2))) +print("Note: for connector = kafka/obpjvm, the balance will not change for now! double checked your BASE_URL") + + diff --git a/lib/obp.py b/lib/obp.py index 87a1673..951738e 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -342,4 +342,9 @@ def printGetCounterparties(response): count=0 for transaction in response: count=count + 1 - print (str(count) +":"+str(transaction)) \ No newline at end of file + print (str(count) +":"+str(transaction)) + +def printGetAccount(response): + if "error" in response: + sys.exit("Got an error: " + str(response)) + print("The account detail is: {0}".format(response)) \ No newline at end of file diff --git a/props/apisandbox.py b/props/apisandbox.py new file mode 100644 index 0000000..ed2b809 --- /dev/null +++ b/props/apisandbox.py @@ -0,0 +1,32 @@ +# API server URL +BASE_URL = "https://apisandbox.openbankproject.com" +API_VERSION = "v2.0.0" +API_VERSION_V210 = "v2.1.0" +API_VERSION_V220 = "v2.2.0" +# API server will redirect your browser to this URL, should be non-functional +# You will paste the redirect location here when running the script +CALLBACK_URI = 'https://apisandbox.openbankproject.com/cb' + +# login user: +USERNAME = 'susan.uk.29@example.com' +PASSWORD = '2b78e8' +CONSUMER_KEY = 'mmsjy5gv3ha1achrnqfrea4u42gxi5wsowownpfb' +#Consumer Secret lez2xf3jiz1quhxxhrmdr200hpxdwjwybjmeidjd +#Consumer ID 2193 + +# fromAccount info: +FROM_BANK_ID = 'gh.29.uk' +FROM_ACCOUNT_ID = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' + +# toBankAccount and toCounterparty info(These data is from kafka side): +TO_BANK_ID = 'gh.29.uk' +TO_ACCOUNT_ID = '851273ba-90d5-43d7-bb31-ea8eba5903c7' +# TO_COUNTERPARTY_ID = 'a635f6ff-c26b-46ad-8194-2406bacceae4' +# TO_COUNTERPARTY_IBAN = 'DE12 1234 5123 4510 2207 8077 877' + +# Our currency to use +OUR_CURRENCY = 'GBP' +# Our value to transfer +# values below 1000 do not require challenge request +OUR_VALUE = '1.00' +OUR_VALUE_LARGE = '1001.00' diff --git a/props/localtest_kafka.py b/props/local_kafka.py similarity index 97% rename from props/localtest_kafka.py rename to props/local_kafka.py index 5d7f47e..5598b55 100644 --- a/props/localtest_kafka.py +++ b/props/local_kafka.py @@ -6,6 +6,7 @@ BASE_URL = "http://127.0.0.1:8080" API_VERSION = "v2.0.0" API_VERSION_V210 = "v2.1.0" +API_VERSION_V220 = "v2.2.0" # API server will redirect your browser to this URL, should be non-functional # You will paste the redirect location here when running the script CALLBACK_URI = 'http://127.0.0.1/cb' diff --git a/props/localtest_mapper.py b/props/local_mapper.py similarity index 100% rename from props/localtest_mapper.py rename to props/local_mapper.py From 1467b5d86013053054613289d77293163fe070b2 Mon Sep 17 00:00:00 2001 From: Philipp Omenitsch Date: Thu, 17 Aug 2017 17:10:37 +0200 Subject: [PATCH 18/26] change default api endpoint to default Current endpoint doesn't work so changed to something that works --- hello_obp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello_obp.py b/hello_obp.py index 2f87cbf..1a94364 100644 --- a/hello_obp.py +++ b/hello_obp.py @@ -8,7 +8,7 @@ # that you can send money from (i.e. be the owner). # All properties are now kept in one central place -from props.danskebank import * +from props.default import * #from props.socgen import * From 5516ce7f3d8a589e8f92c7e5dff02d5d3cd93daf Mon Sep 17 00:00:00 2001 From: Sebastian Henschel Date: Mon, 21 Aug 2017 13:07:23 +0200 Subject: [PATCH 19/26] Applied pep8 fixes to hello_obp.py --- hello_obp.py | 72 +++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/hello_obp.py b/hello_obp.py index 1a94364..89e7d6a 100644 --- a/hello_obp.py +++ b/hello_obp.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import print_function # (at top of module) -import sys, time, requests +import sys +import time +import requests # Note: in order to use this example, you need to have at least one account @@ -9,8 +11,6 @@ # All properties are now kept in one central place from props.default import * -#from props.socgen import * - # You probably don't need to change those @@ -23,66 +23,74 @@ # Login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) -# Get current user -print ("") -print (" --- Get current user") +# Get current user +print("") +print(" --- Get current user") user = obp.getCurrentUser() -print ("current user data:\n{0}".format(user)) +print("current user data:\n{0}".format(user)) user_id = user['user_id'] -print ("current user id: {0}".format(user)) +print("current user id: {0}".format(user)) -our_bank = OUR_BANK #banks[0]['id'] -print ("our bank: {0}".format(our_bank)) +our_bank = OUR_BANK # banks[0]['id'] +print("our bank: {0}".format(our_bank)) # Get accounts for a specific bank -print (" --- Private accounts") +print(" --- Private accounts") accounts = obp.getPrivateAccounts(our_bank) for a in accounts: - print (a['id']) + print(a['id']) # Just picking first account our_account = accounts[0]['id'] -print ("our account: {0}".format(our_account)) +print("our account: {0}".format(our_account)) # Reload account -print ("") -print (" --- Load our account data") +print("") +print(" --- Load our account data") account_data = obp.getAccount(our_bank, our_account) -print ("our account data:\n{0}".format(account_data)) +print("our account data:\n{0}".format(account_data)) -print ("") -print (" --- Modify account label") +print("") +print(" --- Modify account label") new_label = "New label %s" % time.strftime("%d/%m/%Y %I:%M:%S") print(new_label) # Prepare post data and set new label value post_data = { - 'id' : '%s' % our_account, - 'label' : '%s' % new_label, - 'bank_id': '%s' % OUR_BANK + 'id': '%s' % our_account, + 'label': '%s' % new_label, + 'bank_id': '%s' % OUR_BANK } # Send post request with attached json with new label value -response = requests.post(u"{0}/obp/{1}/banks/{2}/accounts/{3}".format(BASE_URL, API_VERSION, our_bank, our_account), json=post_data, headers=obp.mergeHeaders(obp.DL_TOKEN, obp.CONTENT_JSON)) +response = requests.post( + u"{0}/obp/{1}/banks/{2}/accounts/{3}".format( + BASE_URL, API_VERSION, our_bank, our_account), + json=post_data, + headers=obp.mergeHeaders(obp.DL_TOKEN, obp.CONTENT_JSON) +) # Print result -print ("") +print("") print(response.status_code) print(response.text) # Reload account again for comparison account = obp.getAccount(our_bank, our_account) -print ("") -print (" --- Reload account data") -print ("our account data after label update:\n{0}".format(account)) +print("") +print(" --- Reload account data") +print("our account data after label update:\n{0}".format(account)) -print ("") -print (" --- Get owner transactions") +print("") +print(" --- Get owner transactions") transactions = obp.getTransactions(our_bank, our_account) -print ("Got {0} transactions".format(len(transactions))) -for t in transactions: - print ('{0} ({1} {2})'.format(t['id'], t['details']['value']['currency'], t['details']['value']['amount'])) - +print("Got {0} transactions".format(len(transactions))) +for t in transactions: + print('{0} ({1} {2})'.format( + t['id'], + t['details']['value']['currency'], + t['details']['value']['amount']) + ) From 36f4b0fc1589e75ae05ef00690535696f0da465e Mon Sep 17 00:00:00 2001 From: Sebastian Henschel Date: Mon, 21 Aug 2017 13:09:24 +0200 Subject: [PATCH 20/26] Removed old/ --- old/hello_obp.py | 72 ------------------ old/hello_payments.py | 141 ----------------------------------- old/hello_payments_v1.py | 141 ----------------------------------- old/hello_payments_v210.py | 149 ------------------------------------- old/hello_search.py | 56 -------------- 5 files changed, 559 deletions(-) delete mode 100644 old/hello_obp.py delete mode 100644 old/hello_payments.py delete mode 100644 old/hello_payments_v1.py delete mode 100644 old/hello_payments_v210.py delete mode 100644 old/hello_search.py diff --git a/old/hello_obp.py b/old/hello_obp.py deleted file mode 100644 index d52e6f5..0000000 --- a/old/hello_obp.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- - -# Note: in order to use this example, you need to have at least one account - -# Our account's bank -OUR_BANK = 'obp-bankx-n' - -# username, password and consumer key -USERNAME = 'robert.x.d.n@example.com' -PASSWORD = '8596d7de' -CONSUMER_KEY = 'fj43ona2cxxo3xrqyojdwzfpktwhj5avzwnee0jm' - -# API server URL -BASE_URL = "https://apisandbox.openbankproject.com" -#BASE_URL = "http://localhost:8080" - - - -LOGIN_URL = '{0}/my/logins/direct'.format(BASE_URL) -LOGIN_HEADER = { 'Authorization' : 'DirectLogin username="%s",password="%s",consumer_key="%s"' % (USERNAME, PASSWORD, CONSUMER_KEY)} - -import sys, requests -# Helper function to merge headers -def merge(x, y): - z = x.copy() - z.update(y) - return z - -# Login and receive authorized token -print('Login as {0} to {1}'.format(LOGIN_HEADER, LOGIN_URL)) -r = requests.get(LOGIN_URL, headers=LOGIN_HEADER) - -if (r.status_code != 200): - print("error: could not login") - sys.exit(0) - -# Login OK - create authorization headers -token = r.json()['token'] -print("Received token: {0}".format(token)) - -# Prepare headers -directlogin = { 'Authorization' : 'DirectLogin token=%s' % token} -content_json = { 'content-type' : 'application/json' } -limit = { 'obp_limit' : '25' } - -# Get all private accounts for this user -response = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/private".format(BASE_URL, OUR_BANK), headers=directlogin) -print(response.status_code) - -print (response.text) -# Print accounts -accounts = response.json()['accounts'] -for a in accounts: - print(a['id']) - -# Just picking first account -our_account = accounts[0]['id'] -print("our account: {0}".format(our_account)) - -# Prepare post data and set new label value -post_data = { - 'id' : '%s' % our_account, - 'label' : 'New label', - 'bank_id': '%s' % OUR_BANK -} - -# Send post request with attached json with new label value -response = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}".format(BASE_URL, OUR_BANK, our_account), json=post_data, headers=merge(directlogin, content_json)) - -# Print result -print(response.status_code) -print(response.text) diff --git a/old/hello_payments.py b/old/hello_payments.py deleted file mode 100644 index 0f6ebfa..0000000 --- a/old/hello_payments.py +++ /dev/null @@ -1,141 +0,0 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function # (at top of module) - -# Note: in order to use this example, you need to have at least one account -# that you can send money from (i.e. be the owner). -# All properties are now kept in one central place - -from props.danskebank import * - -# You probably don't need to change those -LOGIN_URL = '{0}/my/logins/direct'.format(BASE_URL) -loginHeader = { 'Authorization' : 'DirectLogin username="%s",password="%s",consumer_key="%s"' % (USERNAME, PASSWORD, CONSUMER_KEY)} - -import sys, requests - -def merge(x, y): - z = x.copy() - z.update(y) - return z - -# login and receive authorized token -print (loginHeader) - -print (LOGIN_URL) - -print ('Login as {0} to {1}'.format(loginHeader, LOGIN_URL)) - -r = requests.get(LOGIN_URL, headers=loginHeader) - -if (r.status_code != 200): - print ("error: could not login") - sys.exit(0) - -# login ok - create authorization headers -token = r.json()['token'] - -print ("Received token: {0}".format(token)) - -directlogin = { 'Authorization' : 'DirectLogin token=%s' % token} -content_json = { 'content-type' : 'application/json' } -limit = { 'obp_limit' : '25' } - -#get accounts for a specific bank -print ("Private accounts") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/private".format(BASE_URL, OUR_BANK), headers=directlogin) -#print r.json() - -accounts = r.json()['accounts'] -for a in accounts: - print (a['id']) - -#just picking first account -our_account = accounts[0]['id'] -print ("our account: {0}".format(our_account)) - -print ("") -print ("Get owner transactions") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transactions".format(BASE_URL, - OUR_BANK, - our_account), headers=merge(directlogin, limit) -) -transactions = r.json()['transactions'] -print ("Got {0} transactions".format(len(transactions))) - -print ("Get challenge request types") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types".format(BASE_URL, - OUR_BANK, - our_account), headers=directlogin -) -challenge_type = r.json()[0]['value'] -print (challenge_type) - -print ("") -print ("Initiate transaction requesti (small value)") -send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} -payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ - '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ - challenge_type + '"}' -r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format( - BASE_URL, OUR_BANK, our_account, challenge_type), data=payload, headers=merge(directlogin, content_json)) -initiate_response = r.json() - -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -if (initiate_response['challenge'] != None): - #we need to answer the challenge - challenge_query = initiate_response['challenge']['id'] - transation_req_id = initiate_response['id']['value'] - - print ("Challenge query is {0}".format(challenge_query)) - body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode - r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( - BASE_URL, OUR_BANK, our_account, transation_req_id), data=body, headers=merge(directlogin, content_json) - ) - - challenge_response = r.json() - if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - - print ("Transaction status: {0}".format(challenge_response['status'])) - print ("Transaction created: {0}".format(challenge_response["transaction_ids"])) -else: - #There was no challenge, transaction was created immediately - print ("Transaction was successfully created: {0}".format(initiate_response["transaction_ids"])) - - -#print -#print "Initiate transaction request (large value)" -#send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} -#payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ -# '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE_LARGE + '"}, "description": "Description abc", "challenge_type" : "' + \ -# challenge_type + '"}' -#r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format( -# BASE_URL, OUR_BANK, our_account, challenge_type), data=payload, headers=merge(directlogin, content_json)) -#initiate_response = r.json() -# -#if "error" in initiate_response: -# sys.exit("Got an error: " + str(initiate_response)) -# -#if (initiate_response['challenge'] != None): -# #we need to answer the challenge -# challenge_query = initiate_response['challenge']['id'] -# transation_req_id = initiate_response['id']['value'] -# -# print "Challenge query is {0}".format(challenge_query) -# body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode -# r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( -# BASE_URL, OUR_BANK, our_account, transation_req_id), data=body, headers=merge(directlogin, content_json) -# ) -# -# challenge_response = r.json() -# if "error" in challenge_response: -# sys.exit("Got an error: " + str(challenge_response)) -# -# print "Transaction status: {0}".format(challenge_response['status']) -# print "Transaction created: {0}".format(challenge_response["transaction_ids"]) -#else: -# #There was no challenge, transaction was created immediately -# print "Transaction was successfully created: {0}".format(initiate_response["transaction_ids"]) diff --git a/old/hello_payments_v1.py b/old/hello_payments_v1.py deleted file mode 100644 index 0f6ebfa..0000000 --- a/old/hello_payments_v1.py +++ /dev/null @@ -1,141 +0,0 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function # (at top of module) - -# Note: in order to use this example, you need to have at least one account -# that you can send money from (i.e. be the owner). -# All properties are now kept in one central place - -from props.danskebank import * - -# You probably don't need to change those -LOGIN_URL = '{0}/my/logins/direct'.format(BASE_URL) -loginHeader = { 'Authorization' : 'DirectLogin username="%s",password="%s",consumer_key="%s"' % (USERNAME, PASSWORD, CONSUMER_KEY)} - -import sys, requests - -def merge(x, y): - z = x.copy() - z.update(y) - return z - -# login and receive authorized token -print (loginHeader) - -print (LOGIN_URL) - -print ('Login as {0} to {1}'.format(loginHeader, LOGIN_URL)) - -r = requests.get(LOGIN_URL, headers=loginHeader) - -if (r.status_code != 200): - print ("error: could not login") - sys.exit(0) - -# login ok - create authorization headers -token = r.json()['token'] - -print ("Received token: {0}".format(token)) - -directlogin = { 'Authorization' : 'DirectLogin token=%s' % token} -content_json = { 'content-type' : 'application/json' } -limit = { 'obp_limit' : '25' } - -#get accounts for a specific bank -print ("Private accounts") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/private".format(BASE_URL, OUR_BANK), headers=directlogin) -#print r.json() - -accounts = r.json()['accounts'] -for a in accounts: - print (a['id']) - -#just picking first account -our_account = accounts[0]['id'] -print ("our account: {0}".format(our_account)) - -print ("") -print ("Get owner transactions") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transactions".format(BASE_URL, - OUR_BANK, - our_account), headers=merge(directlogin, limit) -) -transactions = r.json()['transactions'] -print ("Got {0} transactions".format(len(transactions))) - -print ("Get challenge request types") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types".format(BASE_URL, - OUR_BANK, - our_account), headers=directlogin -) -challenge_type = r.json()[0]['value'] -print (challenge_type) - -print ("") -print ("Initiate transaction requesti (small value)") -send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} -payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ - '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ - challenge_type + '"}' -r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format( - BASE_URL, OUR_BANK, our_account, challenge_type), data=payload, headers=merge(directlogin, content_json)) -initiate_response = r.json() - -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -if (initiate_response['challenge'] != None): - #we need to answer the challenge - challenge_query = initiate_response['challenge']['id'] - transation_req_id = initiate_response['id']['value'] - - print ("Challenge query is {0}".format(challenge_query)) - body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode - r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( - BASE_URL, OUR_BANK, our_account, transation_req_id), data=body, headers=merge(directlogin, content_json) - ) - - challenge_response = r.json() - if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - - print ("Transaction status: {0}".format(challenge_response['status'])) - print ("Transaction created: {0}".format(challenge_response["transaction_ids"])) -else: - #There was no challenge, transaction was created immediately - print ("Transaction was successfully created: {0}".format(initiate_response["transaction_ids"])) - - -#print -#print "Initiate transaction request (large value)" -#send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} -#payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ -# '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE_LARGE + '"}, "description": "Description abc", "challenge_type" : "' + \ -# challenge_type + '"}' -#r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format( -# BASE_URL, OUR_BANK, our_account, challenge_type), data=payload, headers=merge(directlogin, content_json)) -#initiate_response = r.json() -# -#if "error" in initiate_response: -# sys.exit("Got an error: " + str(initiate_response)) -# -#if (initiate_response['challenge'] != None): -# #we need to answer the challenge -# challenge_query = initiate_response['challenge']['id'] -# transation_req_id = initiate_response['id']['value'] -# -# print "Challenge query is {0}".format(challenge_query) -# body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode -# r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( -# BASE_URL, OUR_BANK, our_account, transation_req_id), data=body, headers=merge(directlogin, content_json) -# ) -# -# challenge_response = r.json() -# if "error" in challenge_response: -# sys.exit("Got an error: " + str(challenge_response)) -# -# print "Transaction status: {0}".format(challenge_response['status']) -# print "Transaction created: {0}".format(challenge_response["transaction_ids"]) -#else: -# #There was no challenge, transaction was created immediately -# print "Transaction was successfully created: {0}".format(initiate_response["transaction_ids"]) diff --git a/old/hello_payments_v210.py b/old/hello_payments_v210.py deleted file mode 100644 index 9e56cde..0000000 --- a/old/hello_payments_v210.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function # (at top of module) -import lib.obp,requests -obp = lib.obp - -# Helper function to merge headers -def merge(x, y): - z = x.copy() - z.update(y) - return z - -# Note: in order to use this example, you need to have at least one account -# that you can send money from (i.e. be the owner). - -OUR_BANK = 'gh.29.uk' - -USERNAME = 'robert.uk.29@example.com' -PASSWORD = 'd9c663' -CONSUMER_KEY = '5bno1qctzfsbm1hzfpclmtqx0p5rolf0mdorhoef' - -# API server URL -BASE_URL = "https://apisandbox.openbankproject.com" -API_VERSION = "v1.4.0" - -# Our COUNTERPARTY account id (of the same currency) -OUR_COUNTERPARTY = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' -COUNTERPARTY_BANK = 'gh.29.uk' - -# Our currency to use -OUR_CURRENCY = 'GBP' - -# Our value to transfer -# values below 1000 do not requre challenge request -OUR_VALUE = '0.01' -OUR_VALUE_LARGE = '1000.00' - - - -## Code starts below this line - -obp.setBaseUrl(BASE_URL) -token = obp.login(USERNAME, PASSWORD, CONSUMER_KEY) - -print ("Received token: {0}".format(token)) - -exit - -directlogin = { 'Authorization' : 'DirectLogin token=%s' % token} -content_json = { 'content-type' : 'application/json' } -limit = { 'obp_limit' : '25' } - -#get accounts for a specific bank -print ("Private accounts") -r = requests.get(u"{0}/obp/{1}/banks/{2}/accounts/private".format(BASE_URL, API_VERSION, OUR_BANK), headers=directlogin) -#print r.json() - -accounts = r.json()['accounts'] -for a in accounts: - print (a['id']) - -#just picking first account -our_account = accounts[0]['id'] -print ("our account: {0}".format(our_account)) - -print ("") -print ("Get owner transactions") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transactions".format(BASE_URL, - OUR_BANK, - our_account), headers=merge(directlogin, limit) -) -transactions = r.json()['transactions'] -print ("Got {0} transactions".format(len(transactions))) - -print ("Get challenge request types") -r = requests.get(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types".format(BASE_URL, - OUR_BANK, - our_account), headers=directlogin -) -challenge_type = r.json()[0]['value'] -print (challenge_type) - -print ("") -print ("Initiate transaction requesti (small value)") -send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} -payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ - '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ - challenge_type + '"}' -r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format( - BASE_URL, OUR_BANK, our_account, challenge_type), data=payload, headers=merge(directlogin, content_json)) -initiate_response = r.json() - -if "error" in initiate_response: - sys.exit("Got an error: " + str(initiate_response)) - -if (initiate_response['challenge'] != None): - #we need to answer the challenge - challenge_query = initiate_response['challenge']['id'] - transation_req_id = initiate_response['id']['value'] - - print ("Challenge query is {0}".format(challenge_query)) - body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode - r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( - BASE_URL, OUR_BANK, our_account, transation_req_id), data=body, headers=merge(directlogin, content_json) - ) - - challenge_response = r.json() - if "error" in challenge_response: - sys.exit("Got an error: " + str(challenge_response)) - - print ("Transaction status: {0}".format(challenge_response['status'])) - print ("Transaction created: {0}".format(challenge_response["transaction_ids"])) -else: - #There was no challenge, transaction was created immediately - print ("Transaction was successfully created: {0}".format(initiate_response["transaction_ids"])) - - -#print -#print "Initiate transaction request (large value)" -#send_to = {"bank": COUNTERPARTY_BANK, "account": OUR_COUNTERPARTY} -#payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ -# '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE_LARGE + '"}, "description": "Description abc", "challenge_type" : "' + \ -# challenge_type + '"}' -#r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format( -# BASE_URL, OUR_BANK, our_account, challenge_type), data=payload, headers=merge(directlogin, content_json)) -#initiate_response = r.json() -# -#if "error" in initiate_response: -# sys.exit("Got an error: " + str(initiate_response)) -# -#if (initiate_response['challenge'] != None): -# #we need to answer the challenge -# challenge_query = initiate_response['challenge']['id'] -# transation_req_id = initiate_response['id']['value'] -# -# print "Challenge query is {0}".format(challenge_query) -# body = '{"id": "' + challenge_query + '","answer": "123456"}' #any number works in sandbox mode -# r = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/sandbox/transaction-requests/{3}/challenge".format( -# BASE_URL, OUR_BANK, our_account, transation_req_id), data=body, headers=merge(directlogin, content_json) -# ) -# -# challenge_response = r.json() -# if "error" in challenge_response: -# sys.exit("Got an error: " + str(challenge_response)) -# -# print "Transaction status: {0}".format(challenge_response['status']) -# print "Transaction created: {0}".format(challenge_response["transaction_ids"]) -#else: -# #There was no challenge, transaction was created immediately -# print "Transaction was successfully created: {0}".format(initiate_response["transaction_ids"]) diff --git a/old/hello_search.py b/old/hello_search.py deleted file mode 100644 index d538f96..0000000 --- a/old/hello_search.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- coding: utf-8 -*- - -# Set search query and elasticsearch index -SEARCH_QUERY="q=obp" -ES_INDEX = "metrics" - -# Note: in order to use this example, you need to have an user -# that has entitlement CanSearchWarehouse or CanSearchMetrics -USERNAME = 'robert.x.d.n@example.com' -PASSWORD = '8596d7de' -CONSUMER_KEY = 'fj43ona2cxxo3xrqyojdwzfpktwhj5avzwnee0jm' - -# API server URL -BASE_URL = "https://apisandbox.openbankproject.com" - -LOGIN_URL = '{0}/my/logins/direct'.format(BASE_URL) - -# API server will redirect your browser to this URL, should be non-functional -# You will paste the redirect location here when running the script -CALLBACK_URI = 'http://127.0.0.1/cb' - -# You probably don't need to change those -loginHeader = { 'Authorization' : 'DirectLogin username="%s",password="%s",consumer_key="%s"' % (USERNAME, PASSWORD, CONSUMER_KEY)} - - -import sys, requests -# Helper function to merge headers -def merge(x, y): - z = x.copy() - z.update(y) - return z - -# Login and receive authorized token -print 'Login as {0} to {1}'.format(loginHeader, LOGIN_URL) -r = requests.get(LOGIN_URL, headers=loginHeader) - -if (r.status_code != 200): - print "error: could not login" - sys.exit(0) - -# Login OK - create authorization headers -token = r.json()['token'] -print "Received token: {0}".format(token) - -# Prepare headers -directlogin = { 'Authorization' : 'DirectLogin token=%s' % token} -content_json = { 'content-type' : 'application/json' } -limit = { 'obp_limit' : '25' } - -# Perform search -response = requests.get(u"{0}/obp/v2.0.0/search/{1}/{2}".format(BASE_URL, ES_INDEX, SEARCH_QUERY), headers=merge(directlogin, content_json)) - -# Print result -print response.status_code -print response.text - From 8f2f9ccfb6375773bb4fe09d748eb1772ee94987 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Tue, 6 Feb 2018 18:44:35 -0500 Subject: [PATCH 21/26] Direct Login now needs to be POST and returns status code 201 --- lib/obp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/obp.py b/lib/obp.py index 951738e..3b6afcc 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -52,8 +52,8 @@ def login(username, password, consumer_key): login_header = { 'Authorization' : 'DirectLogin username="%s",password="%s",consumer_key="%s"' % (username, password, consumer_key)} # Login and receive authorized token log('Login as {0} to {1}'.format(login_header, login_url)) - r = requests.get(login_url, headers=login_header) - if (r.status_code != 200): + r = requests.post(login_url, headers=login_header) + if (r.status_code != 201): log("error: could not login") log("text: " + r.text) return r.text From 91b105acf2f9547fd760a9f6e5b1da475de367c3 Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Tue, 4 Dec 2018 01:52:53 +0000 Subject: [PATCH 22/26] hello_payments.py now imports props.default by default just like hello_obp.py (so that getting started README works as expected) --- hello_payments.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hello_payments.py b/hello_payments.py index e11d4ef..bf1cc85 100644 --- a/hello_payments.py +++ b/hello_payments.py @@ -8,8 +8,7 @@ # that you can send money from (i.e. be the owner). # All properties are now kept in one central place -from props.danskebank import * -#from props.socgen import * +from props.default import * # You probably don't need to change those import lib.obp From 40972a483a3b715bdc696908b98bfb198cad48ac Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Fri, 14 Jun 2019 16:49:33 +0100 Subject: [PATCH 23/26] Updated create transaction request to use v2.2.0 v2.2.0 honours the canCreateAnyTransactionRequest role. --- lib/obp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/obp.py b/lib/obp.py index 3b6afcc..f7c7243 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -161,7 +161,7 @@ def initiateTransactionRequest(bank, account, challenge_type, cp_bank, cp_accoun payload = '{"to": {"account_id": "' + send_to['account'] +'", "bank_id": "' + send_to['bank'] + \ '"}, "value": {"currency": "' + OUR_CURRENCY + '", "amount": "' + OUR_VALUE + '"}, "description": "Description abc", "challenge_type" : "' + \ challenge_type + '"}' - response = requests.post(u"{0}/obp/v1.4.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format(BASE_URL, bank, account, challenge_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) + response = requests.post(u"{0}/obp/v2.2.0/banks/{1}/accounts/{2}/owner/transaction-request-types/{3}/transaction-requests".format(BASE_URL, bank, account, challenge_type), data=payload, headers=mergeHeaders(DL_TOKEN, CONTENT_JSON)) return response.json() # Create counterparty, input data format: @@ -347,4 +347,4 @@ def printGetCounterparties(response): def printGetAccount(response): if "error" in response: sys.exit("Got an error: " + str(response)) - print("The account detail is: {0}".format(response)) \ No newline at end of file + print("The account detail is: {0}".format(response)) From 4491a994ba4e13b4226bdd267896705efef91441 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Sat, 5 Oct 2019 19:10:02 -0400 Subject: [PATCH 24/26] Tweaking README on venv --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1585950..721687f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,17 @@ Python Example for OBP API ========================== + + +## Virtual Environment for Python (optional) + +pip install --upgrade virtualenv + +virtualenv -p /usr/local/bin/python3 py3env + +source py3env/bin/activate + + ## Setup ```bash @@ -10,8 +21,10 @@ $ pip install -r requirements.txt ## Hello OBP -```bash #compatible with python2 and 3 + + +```bash $ python hello_obp.py ``` From d9a397490b05c725aead64da5f7b72ebbc2287b8 Mon Sep 17 00:00:00 2001 From: tawoe Date: Tue, 30 Nov 2021 09:39:50 +0100 Subject: [PATCH 25/26] update request to undefined version (latest) --- .gitignore | 2 ++ requirements.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 897062d..dfff155 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ env3/ # Distribution / packaging .Python env/ +venv/ +venv2/ build/ develop-eggs/ dist/ diff --git a/requirements.txt b/requirements.txt index be04c9a..f229360 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests==2.5.1 +requests From ae17be6ed68e436aa1dcdf1f1ab9f1c690e30dfe Mon Sep 17 00:00:00 2001 From: tawoe Date: Tue, 30 Nov 2021 10:58:04 +0100 Subject: [PATCH 26/26] update requests to >= 2.20.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f229360..111f18b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests +requests>=2.20.0