-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathwepay-example.py
43 lines (33 loc) · 1.34 KB
/
wepay-example.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
import web
from wepay import WePay
from wepay.exceptions import WePayError
CLIENT_ID = ''
CLIENT_SECRET = ''
IN_PRODUCTION = False
urls = (
'/', 'index',
'/callback(.*)', 'callback'
)
app = web.application(urls, globals())
class index:
def GET(self):
wepay = WePay(IN_PRODUCTION)
# redirect to wepay for authorization
web.redirect(wepay.get_authorization_url(web.ctx.homedomain + '/callback', CLIENT_ID))
class callback:
def GET(self, query):
wepay = WePay(IN_PRODUCTION)
code = web.input(code='')['code']
try:
# try to get a token with our code
wepay.get_token(web.ctx.homedomain + '/callback', CLIENT_ID, CLIENT_SECRET, code)
# make a new account
create_response = wepay.call('/account/create', { 'name': 'kitty expenses fund', 'description': 'all the money for my kitty' })
# give the account a new picture
wepay.call('/account/modify', { 'account_id': create_response['account_id'], 'image_uri': 'http://www.placekitten.com/500/500' })
# redirect to the new account
web.redirect(create_response['account_uri'])
except WePayError as e:
return "Received a WePay Error: " + repr(e)
if __name__ == "__main__":
app.run()