diff --git a/.gitignore b/.gitignore index 4327856..dfff155 100644 --- a/.gitignore +++ b/.gitignore @@ -2,20 +2,26 @@ __pycache__/ *.py[cod] *$py.class - +.gitignore~ +.project +.pydevproject +.settings/ +env2/ +env3/ # C extensions *.so # Distribution / packaging .Python env/ +venv/ +venv2/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ -lib64/ parts/ sdist/ var/ diff --git a/README.md b/README.md index 24e46b3..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,23 +21,16 @@ $ pip install -r requirements.txt ## Hello OBP -```bash #compatible with python2 and 3 -$ python hello_obp.py -``` -## Hello Payments - ```bash -$ python2 hello_payments.py +$ python hello_obp.py ``` -## Import Sandbox - -Edit the data to import in the script, then run: +## Hello Payments ```bash -$ python2 import_sandbox.py +$ python3 hello_payments.py ``` diff --git a/hello_obp.py b/hello_obp.py index ea47e0f..89e7d6a 100644 --- a/hello_obp.py +++ b/hello_obp.py @@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- from __future__ import print_function # (at top of module) -import sys, requests +import sys +import time +import 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.default import * # You probably don't need to change those @@ -19,43 +20,77 @@ 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)) +our_bank = OUR_BANK # banks[0]['id'] +print("our bank: {0}".format(our_bank)) -#get accounts for a specific bank -print (" --- Private accounts") +# Get accounts for a specific bank +print(" --- Private accounts") accounts = obp.getPrivateAccounts(our_bank) for a in accounts: - print (a['id']) + print(a['id']) -#just picking first account +# 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))) +print("our account: {0}".format(our_account)) +# Reload account +print("") +print(" --- Load our account data") +account_data = obp.getAccount(our_bank, our_account) +print("our account data:\n{0}".format(account_data)) +print("") +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', - '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(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 6f901e9..bf1cc85 100644 --- a/hello_payments.py +++ b/hello_payments.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 * # You probably don't need to change those import lib.obp @@ -17,13 +17,18 @@ obp.setBaseUrl(BASE_URL) obp.setApiVersion(API_VERSION) + # login and set authorized token obp.login(USERNAME, PASSWORD, CONSUMER_KEY) - +obp.setCounterParty(COUNTERPARTY_BANK, OUR_COUNTERPARTY,OUR_COUNTERPARTY_ID,OUR_COUNTERPARTY_IBAN) +obp.setPaymentDetails(OUR_CURRENCY, OUR_VALUE_LARGE) banks = obp.getBanks() our_bank = banks[0]['id'] -cp_bank = our_bank + +cp_bank = obp.getCounterBankId() +cp_account = obp.getCounterpartyAccountId() + print ("our bank: {0}".format(our_bank)) #get accounts for a specific bank @@ -36,7 +41,7 @@ #just picking first account our_account = accounts[0]['id'] -cp_account = accounts[1]['id'] + print ("our account: {0}".format(our_account)) print ("") @@ -45,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: @@ -58,9 +65,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)) @@ -68,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/hello_payments_V210.py b/hello_payments_V210.py new file mode 100644 index 0000000..66ae9ed --- /dev/null +++ b/hello_payments_V210.py @@ -0,0 +1,252 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests +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 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 +# 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)-- V121 +# 10 Get Counterparties of one Account.-- V220 +# 11 Get Counterparties of one Account.-- V220 + +print("#########################Step 1 : Direct Login process.################") +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 +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 + + +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 + +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) + +print("") +print("") +print("######################### Step3 - make a payment - SEPA ################") +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) + +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'") +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) + +print("") +print("") +print("######################## Step5 - Get Transactions #####################") +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) + + +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/hello_payments_V210_kafka.py b/hello_payments_V210_kafka.py new file mode 100644 index 0000000..26e250f --- /dev/null +++ b/hello_payments_V210_kafka.py @@ -0,0 +1,193 @@ +# -*- coding: utf-8 -*- +from __future__ import print_function # (at top of module) +import sys, requests +import lib.obp +from props.localtest_kafka import * + +# 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 ################ +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +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 + +######################### Step2 : make a payment - SANDBOX_TAN ################ +print("") +print("") +# set receiver bank account: +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)) +print("Call API - 1 '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_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.printMessageNoChallenge(initiate_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) +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, # 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 - 3 'Answer Transaction Request Challenge. -- V210'") +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) + +# ######################### Step3 - make a payment - SEPA ################ +print("") +print("") +# set receiver COUNTERPARTY_IBAN: +to_counterparty_iban = TO_COUNTERPARTY_IBAN + +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 +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_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 +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_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 + +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'") +challenge_response = obp.answerChallengeV210(from_bank_id, from_account_id, transaction_req_id, TRANSACTION_REQUEST_TYPE_SEPA, challenge_query) + +obp.printMessageAfterAnswerChallenge(challenge_response) + +######################### Step4 - make a payment - COUNTERPARTY ################ +print("") +print("") + +# set receiver COUNTERPARTY_ID: +to_counterparty_id = TO_COUNTERPARTY_ID + +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) +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="", # for SANDBOX_TAN + to_account_id="", # for SANDBOX_TAN + to_counterparty_id=to_counterparty_id, # used for SEPA + to_counterparty_iban="") # used for COUNTERPARTY +obp.printMessageNoChallenge(initiate_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) +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="", # for SANDBOX_TAN + to_account_id="", # for SANDBOX_TAN + to_counterparty_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'") +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("") +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_mapped.py b/hello_payments_V210_mapped.py new file mode 100644 index 0000000..dd03a58 --- /dev/null +++ b/hello_payments_V210_mapped.py @@ -0,0 +1,216 @@ +# -*- coding: utf-8 -*- +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 +# 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 + +obp = lib.obp +obp.setBaseUrl(BASE_URL) +obp.setApiVersion(API_VERSION_V210) + +print("Call API - 0 'DirectLogin'") +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 + +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) +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'") +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_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)) + +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, + 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") +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) +obp.printMessageNoChallenge(initiate_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) +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) +obp.printMessageWithChallenge(initiate_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, + 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("") +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 - 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) +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 + +# There was no challenge, transaction was created immediately +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 - 3 'Answer Transaction Request Challenge. -- V210'") +print("Transaction is done , and the transaction_request is 'COMPLETED' and new Transaction id is created: :") +# 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) +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_one_owner.py b/hello_payments_V210_one_owner.py new file mode 100644 index 0000000..1ff48e6 --- /dev/null +++ b/hello_payments_V210_one_owner.py @@ -0,0 +1,77 @@ +# -*- 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) + +######################### 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.printGetTransactions(getTransactions_response) diff --git a/hello_payments_V210_two_owners.py b/hello_payments_V210_two_owners.py new file mode 100644 index 0000000..0a00bdc --- /dev/null +++ b/hello_payments_V210_two_owners.py @@ -0,0 +1,167 @@ +# -*- 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 : Direct Login process .################ +from props.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) + +######################### 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) + + +######################### 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.printGetTransactions(getTransactions_response) \ No newline at end of file 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/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..f7c7243 100755 --- a/lib/obp.py +++ b/lib/obp.py @@ -10,6 +10,19 @@ CONTENT_JSON = { 'content-type' : 'application/json' } +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 + + OUR_CURRENCY = currency + OUR_VALUE =value + def setBaseUrl(u): global BASE_URL BASE_URL = u @@ -39,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 @@ -61,6 +74,18 @@ def requestMeeting(purpose_id, provider_id): log("code=" + response.status_code + " text=" + response.text) return response.json() +def getCounterBankId(): + return COUNTERPARTY_BANK + +def getCounterpartyAccountId(): + return OUR_COUNTERPARTY + +def getCounterpartyId(): + return OUR_COUNTERPARTY_ID + +def getCounterpartyIban(): + return OUR_COUNTERPARTY_IBAN + # Get banks def getBanks(): # Prepare headers @@ -94,33 +119,232 @@ 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)) 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)) - 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): - 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 + '"}' - 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: +# { +# "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, + other_account_routing_scheme, + other_account_routing_address, + other_bank_routing_scheme, + other_bank_routing_address): + post_data = { + 'name' : '%s' % name, + '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, + '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 + 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 +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 + + + +# 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) + ) + return response.json() + +# Create Transaction Request. - V210 +# Note : previous called 'initiateTransactionRequest', now keep it the same and OBP-API endpoint name +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(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 (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": 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" : "' + \ + 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() + + +# 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: + 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(response)) + print("Transaction status: {0}".format(response['status'])) + print("Transaction id is created: {0}".format(response["transaction_ids"])) + + +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(response)) + print("Transaction status: {0}".format(response['status'])) + print("New Transaction ID created: {0}".format(response["transaction_ids"])) + + +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(response)) + print("Transaction status: {0}".format(response['status'])) + print("New Transaction ID created: {0}".format(response["transaction_ids"])) + + +def printGetTransactions(response): + if "error" in response: + sys.exit("Got an error: " + str(response)) + 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: + sys.exit("Got an error: " + str(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)) + +def printGetAccount(response): + if "error" in response: + sys.exit("Got an error: " + str(response)) + print("The account detail is: {0}".format(response)) 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 2bc76a5..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 lib.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": COUNTERPART_BANK, "account": OUR_COUNTERPART} -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": COUNTERPART_BANK, "account": OUR_COUNTERPART} -#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 2942ca8..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": COUNTERPART_BANK, "account": OUR_COUNTERPART} -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": COUNTERPART_BANK, "account": OUR_COUNTERPART} -#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 f319cc1..0000000 --- a/old/hello_payments_v210.py +++ /dev/null @@ -1,143 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function # (at top of module) -import obp - - -# 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 counterpart account id (of the same currency) -OUR_COUNTERPART = '8ca8a7e4-6d02-48e3-a029-0b2bf89de9f0' -COUNTERPART_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": COUNTERPART_BANK, "account": OUR_COUNTERPART} -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": COUNTERPART_BANK, "account": OUR_COUNTERPART} -#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 - 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/danskebank.py b/props/danskebank.py index b894d39..ec7bc25 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' @@ -15,9 +21,12 @@ # 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 = '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' @@ -26,3 +35,5 @@ # values below 1000 do not requre challenge request OUR_VALUE = '0.01' OUR_VALUE_LARGE = '1000.00' +PAYMENT_DESCRIPTION = 'Hello Payments v2.1!' + diff --git a/props/default.py b/props/default.py index e787d4e..256ec0c 100644 --- a/props/default.py +++ b/props/default.py @@ -14,9 +14,13 @@ # 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' +# 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/k1_kafka.py b/props/k1_kafka.py new file mode 100644 index 0000000..c84e18d --- /dev/null +++ b/props/k1_kafka.py @@ -0,0 +1,32 @@ +# API server URL +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' + +# 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' diff --git a/props/local_kafka.py b/props/local_kafka.py new file mode 100644 index 0000000..5598b55 --- /dev/null +++ b/props/local_kafka.py @@ -0,0 +1,34 @@ +# 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_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' + +# login user: +USERNAME = 'robert.y.9.gh@example.com' +PASSWORD = 'c9a641df' +CONSUMER_KEY = '5du40pymqlgufkncfxn3cny5zhlxv3kts5d2a3lj' + +# 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 = '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/local_mapper.py b/props/local_mapper.py new file mode 100644 index 0000000..440ed50 --- /dev/null +++ b/props/local_mapper.py @@ -0,0 +1,34 @@ +# 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 locally + + +# 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 = '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' + +# 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 new file mode 100644 index 0000000..c70d221 --- /dev/null +++ b/props/socgen.py @@ -0,0 +1,39 @@ +# -*- 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 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' + +# 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!' diff --git a/props/socgen1_k.py b/props/socgen1_k.py new file mode 100644 index 0000000..63e206c --- /dev/null +++ b/props/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/socgen1_k_two_owners.py b/props/socgen1_k_two_owners.py new file mode 100644 index 0000000..b7014c8 --- /dev/null +++ b/props/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' diff --git a/props/socgen2_k.py b/props/socgen2_k.py new file mode 100644 index 0000000..f7b11b1 --- /dev/null +++ b/props/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/socgen2_k_local.py b/props/socgen2_k_local.py new file mode 100644 index 0000000..41cbbe9 --- /dev/null +++ b/props/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' diff --git a/requirements.txt b/requirements.txt index be04c9a..111f18b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests==2.5.1 +requests>=2.20.0