forked from OpenBankProject/Hello-OBP-DirectLogin-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_payments_V210_kafka.py
193 lines (165 loc) · 9.62 KB
/
hello_payments_V210_kafka.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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)