-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathadmin.py
71 lines (55 loc) · 2.01 KB
/
admin.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
62
63
64
65
66
67
68
69
70
71
import webapp2
import datetime
from model import Document
from blockchain import callback_secret_valid
from base import JsonAPIHandler
from secrets import SECRET_ADMIN_PATH
from config import MIN_SATOSHIS_PAYMENT
class BootstrapHandler(JsonAPIHandler):
def handle(self):
return {"success" : True}
class PendingHandler(webapp2.RequestHandler):
def get(self):
actionable = Document.get_actionable()
url = SECRET_ADMIN_PATH + '/autopay'
for d in actionable:
self.response.write('<a href="%s?d=%s">%s</a><br /><br />' % (url, d.digest, d.digest))
class AutopayHandler(JsonAPIHandler):
def handle(self):
digest = self.request.get("d")
doc = Document.get_doc(digest)
if not doc:
return {"success" : False, "error": "format"}
return doc.blockchain_certify()
class BasePaymentCallback(JsonAPIHandler):
def handle(self):
test = self.request.get("test") == "true"
try:
tx_hash = self.request.get("transaction_hash")
address = self.request.get("address")
satoshis = int(self.request.get("value"))
payment_address = self.request.get("input_address")
except ValueError, e:
return "error: value error"
if not tx_hash:
return "error: no transaction_hash"
if not address:
return "error: no address"
if satoshis <= 0: # outgoing payment
return "*ok*"
if satoshis < MIN_SATOSHIS_PAYMENT: # not enough
return "*ok*"
if not test:
doc = Document.get_by_address(payment_address)
if not doc:
return "error: couldn't find document"
return self.process_payment(satoshis, doc)
return "*ok*"
def process_payment(self, satoshis, doc):
secret = self.request.get("secret")
if not callback_secret_valid(secret):
return "error: secret invalid"
doc.received_payment()
return "*ok*"
class PaymentCallback(BasePaymentCallback):
pass