-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
61 lines (50 loc) · 1.5 KB
/
main.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
import web
import paypalv2 as paypal
urls = [
'/create', 'PaymentCreate',
'/pay', 'PaymentExecute',
'/payout', 'PayoutCreate',
'/payout/(.*)', 'PayoutInfo'
]
app = web.application(urls, globals())
class PaymentCreate:
def GET(self):
i = web.input()
if not i.get('amt') or not i.get('des'):
return web.badrequest()
amt = i.amt
des = i.des
res = paypal.createPayment(amt, des)
if type(res) == str:
return web.seeother(res)
else:
return web.notfound()
class PaymentExecute:
def GET(self):
i = web.input()
if not i.get('paymentId') or not i.get('PayerID'):
return web.badrequest()
id_payment = i.get('paymentId')
id_payer = i.get('PayerID')
res = paypal.executePayment(id_payment, id_payer)
if type(res) is str:
return { 'success': True }
else:
return { 'error': res }
class PayoutCreate:
def GET(self):
i = web.input()
if not i.get('amts') or not i.get('usrs'):
return web.badrequest()
amts = i.get('amts').split(';')
usrs = i.get('usrs').split(';')
payout = paypal.createPayout(amts, usrs)
if payout:
web.seeother('/payout/%s'%payout.batch_header.payout_batch_id)
class PayoutInfo:
def GET(self, pid):
payout = paypal.getPayout(pid)
payout.api = None
return payout.__dict__
if __name__ == '__main__':
app.run()