forked from OpenBankProject/Hello-OBP-DirectLogin-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_payments_V210_mapped.py
216 lines (189 loc) · 11.2 KB
/
hello_payments_V210_mapped.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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)