-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevolutAPI_live.py
More file actions
202 lines (130 loc) · 5.25 KB
/
revolutAPI_live.py
File metadata and controls
202 lines (130 loc) · 5.25 KB
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
import requests
import json
import revolut_fe_live as rev_at
with open('access_token_list_real.txt') as json_file:
data = json.load(json_file)
for at in data['access_token']:
access_token = at
access_token_list = rev_at.access_tokens
client_id = "YOUR CLIENT ID HERE"
base_url_live = "https://b2b.revolut.com/api/1.0"
print(access_token)
base_url_sandbox = "https://sandbox-b2b.revolut.com/api/1.0"
headers = {
"Authorization" : f"Bearer {access_token}",
#"Content-Type" : "application/json"
}
account_ids = []
counterparty_ids = []
class Revolut:
def accounts(self):
'''
Get request to receive my accounts // Needed for my id
'''
accounts_endpoint = "/accounts"
get_accounts = f"{base_url_live}{accounts_endpoint}"
#when get requests.get
r = requests.get(get_accounts, headers=headers)
print(r.status_code)
print(r.text)
def receive_counterparties(self):
'''
Use this to get all of my counterparties added previously. This will be used to check if i need to add the new customer to my counterparty list.
If they are on this list i can just pass over the next step.
'''
receive_counterparties_endpoint = "/counterparties"
receive_counterparties = f"{base_url_live}{receive_counterparties_endpoint}"
r = requests.get(receive_counterparties, headers=headers)
print(r.status_code)
print(r.text)
def create_counterparty_rev(self, data):
'''
Making a counterparty to make the payment
'''
counterparty_endpoint = "/counterparty"
create_counterparty = f"{base_url_live}{counterparty_endpoint}"
r = requests.post(create_counterparty, json=data, headers=headers)
print(r.status_code)
print(r.text)
text = r.text
json_txt = json.loads(text)
counterparty_id = json_txt["id"]
counterparty_ids.append(counterparty_id)
def create_counterparty_uk(self, data):
counterparty_endpoint = "/counterparty"
create_counterparty = f"{base_url_live}{counterparty_endpoint}"
r = requests.post(create_counterparty, json=data, headers=headers)
print(r.status_code)
print(r.text)
text = r.text
json_txt = json.loads(text)
counterparty_id = json_txt["id"]
counterparty_ids.append(counterparty_id)
accounts = json_txt["accounts"]
accounts_json = accounts[0]
account_id = accounts_json["id"]
account_ids.append(account_id)
def create_counterparty_international(self, data):
counterparty_endpoint = "/counterparty"
create_counterparty = f"{base_url_live}{counterparty_endpoint}"
r = requests.post(create_counterparty, json=data, headers=headers)
print(r.status_code)
print(r.text)
def instant_payment(self, data):
'''
This is to create an instant payment. This is used if the rental is less than 3 days
'''
instant_payment_endpoint = "/pay"
create_instant_payment = f"{base_url_live}{instant_payment_endpoint}"
r = requests.post(create_instant_payment, json=data, headers=headers)
print(r.status_code)
print(r.text)
def schedule_payment(self, data):
'''
This is used to create a schedule payment. This is if the rental is longer than 3 days
'''
schedule_payment_endpoint = "/pay"
create_schedule_payment = f"{base_url_live}{schedule_payment_endpoint}"
r = requests.post(create_schedule_payment, json=data, headers=headers)
print(r.status_code)
print(r.text)
def draft_payment(self, data):
'''
Used for draft payments. Draft payments have to be manually accepted by the revolut owner.
'''
draft_payment_endpoint = "/payment-drafts"
create_draft_payment = "https://b2b.revolut.com/api/1.0/payment-drafts"
r = requests.post(create_draft_payment, json=data, headers=headers)
print(r.status_code)
print(r.text)
def receive_all_transactions(self):
'''
receive all transactions from the past 90 days
'''
receive_all_transactions_endpoint = "/transactions"
receive_all_transactions = f"{base_url_live}{receive_all_transactions_endpoint}"
r = requests.get(receive_all_transactions, headers=headers)
print(r.status_code)
print(r.text)
def receive_a_transaction(self, data):
'''
receive a transaction
'''
receive_a_transaction_endpoint = f"/transactions/{data}"
receive_a_transaction = f"{base_url_live}{receive_a_transaction_endpoint}"
r = requests.get(receive_a_transaction, headers=headers)
print(r.status_code)
print(r.text)
def webhook(self):
'''
This is to receive webhooks.
'''
webhook_data = {
"url": "https://example.com/example/path" #my url
}
webhook_endpoint = "/webhook"
create_webhook = f"{base_url_live}{webhook_endpoint}"
r = requests.post(create_webhook, json=webhook_data, headers=headers)
print(r.status_code)
print(r.text)
rev = Revolut()