def post(self): # build it and redirect to something. # NOTE: setting in app.yaml protects this for admin-only access. # NOTE: A real program would have validation here amount = Decimal(self.request.get('amount', 0)) amount_cct = self.request.get('amount_cct', 'BTC')[0:3].upper() payable_cct = self.request.get('payable_cct', 'BTC')[0:3].upper() label = self.request.get('label', None) show_fiat = self.request.get('show_fiat', False) n = MyInvoice() n.amount_cct = amount_cct n.payable_cct = payable_cct if amount_cct == payable_cct: n.payable = amount n.amount = amount else: # get a spot quote. q = CK_API.get('/v1/spot_quote/%s/%s/%s' % (payable_cct, amount_cct, amount)) n.payable = q.result.decimal.quantize(Decimal('0.0001')) n.amount = amount n.label = label[0:190] if label else None n.show_fiat = bool(show_fiat) n.token = b32encode(os.urandom(10)) # TODO get a pubkey for the request acct = ACCOUNT_MAP[payable_cct] r = CK_API.put('/v1/new/receive', account=acct, memo='See %s' % n.get_url(), amount=n.payable) req = r.result n.pubkey = req.coin.address n.ck_refnum = req.ref_number # save it. key = n.put() # bugfix: not seeing the new entry in the list after redirect # TODO: this doesn't help! need a fix for this issue from google.appengine.ext import ndb ndb.get_context().clear_cache() # redirect to making page. self.redirect('/make')
def post(self): # build it and redirect to something. # NOTE: setting in app.yaml protects this for admin-only access. # NOTE: A real program would have validation here amount = Decimal(self.request.get('amount', 0)) amount_cct = self.request.get('amount_cct', 'BTC')[0:3].upper() payable_cct = self.request.get('payable_cct', 'BTC')[0:3].upper() label = self.request.get('label', None) show_fiat = self.request.get('show_fiat', False) n = MyInvoice() n.amount_cct = amount_cct n.payable_cct = payable_cct if amount_cct == payable_cct: n.payable = amount n.amount = amount else: # get a spot quote. q = CK_API.get('/v1/spot_quote/%s/%s/%s' % (payable_cct, amount_cct, amount)) n.payable = q.result.decimal.quantize(Decimal('0.0001')) n.amount = amount n.label = label[0:190] if label else None n.show_fiat = bool(show_fiat) n.token = b32encode(os.urandom(10)) # TODO get a pubkey for the request acct = ACCOUNT_MAP[payable_cct] r = CK_API.put('/v1/new/receive', account = acct, memo = 'See %s' % n.get_url(), amount = n.payable) req = r.result n.pubkey = req.coin.address n.ck_refnum = req.ref_number # save it. key = n.put() # bugfix: not seeing the new entry in the list after redirect # TODO: this doesn't help! need a fix for this issue from google.appengine.ext import ndb ndb.get_context().clear_cache() # redirect to making page. self.redirect('/make')