-
Notifications
You must be signed in to change notification settings - Fork 18
/
iban_rest.py
49 lines (41 loc) · 1.38 KB
/
iban_rest.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
#!/usr/bin/env python
# coding: utf-8
import webapp2
import iban
import json
class IBAN(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'application/json'
data = {
'ispb': '',
'agency': '',
'account': '',
'country': 'BR',
'account_type': 'C',
'account_owner': '1',
}
args = self.request.params
if args.get('iban'):
return self._check_iban(args['iban'])
data.update((k, args[k].replace('-', '').strip())
for k in set(data).intersection(args))
if not all(data.viewvalues()):
data['ispb'] = iban.ISPB
self.response.write(json.dumps(data))
else:
return self._make_iban(data)
def _check_iban(self, value):
check = iban.check_iban(value.upper())
self.response.write(json.dumps({'valid': check}))
def _make_iban(self, data):
try:
value = iban.make_iban(
data['ispb'], data['agency'], data['account'], data['country'],
data['account_type'], data['account_owner'])
except Exception:
self.response.status = 403
value = 'Invalid parameters'
self.response.write(json.dumps({'iban': value}))
application = webapp2.WSGIApplication([
('/rest/', IBAN),
], debug=True)