-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
49 lines (44 loc) · 1.9 KB
/
cli.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
from ABN_TIKKIE import *
import argparse
import json
import sys
if __name__== "__main__":
parser = argparse.ArgumentParser(description="ABN AMRO TIKKIE API cli")
parser.add_argument('--mode', nargs='?', const=1, type=str, default='fetch', help='fetch/request: fetch existing requests or create new one')
parser.add_argument('--amount', nargs='?', const=1, type=int, default=0, help='ammount in cents for payment request')
parser.add_argument('--description', nargs='?', type=str, help="description for the payment request")
parser.add_argument('--externalid', nargs='?', type=str, help="id for the payment request for for example invoice numbers")
mode, amount, description, externalid = parser.parse_args().mode, parser.parse_args().amount, parser.parse_args().description, parser.parse_args().externalid
access_token = load_access_token()
if access_token is None:
sys.exit(-1)
if mode == 'fetch':
requests = []
offset = 0
while True:
res = get_payment_requests(access_token, offset=offset)
if type(res) == dict:
requests += res['paymentRequests']
if res['totalElements'] == 100:
offset += 100
continue
else:
results = {
"totalElements" : len(requests),
"paymentRequests" : requests
}
print(json.dumps(results))
sys.exit(0)
else:
print(json.dumps(res.json()))
sys.exit(1)
elif mode == 'request':
res = create_payment_request(access_token, amount, description, externalid)
if type(res) == dict:
print(json.dumps(res))
sys.exit(0)
else:
print(json.dumps(res.json()))
sys.exit(1)
else:
sys.exit(2)