本文整理匯總了Python中models.Ticket.payment_response方法的典型用法代碼示例。如果您正苦於以下問題:Python Ticket.payment_response方法的具體用法?Python Ticket.payment_response怎麽用?Python Ticket.payment_response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Ticket
的用法示例。
在下文中一共展示了Ticket.payment_response方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ticket_buy
# 需要導入模塊: from models import Ticket [as 別名]
# 或者: from models.Ticket import payment_response [as 別名]
def ticket_buy(tariff_id):
if request.method == 'POST' and int(tariff_id) in [20, 29]:
# HOTFIX - umoznuje to volat i GETem
# if int(tariff_id) in [20, 29]:
phone = request.form['phone']
ticket = Ticket(tariff=tariff_id, phone=phone)
d = {}
d["settled_currency"] = "CZK"
d["return_url"] = "http://%s/notification" % request.host
d["notify_url"] = "http://%s/notification" % request.host
d["notify_email"] = "%s" % settings.bitcoinPayOwnerEmail
d["price"] = tariff_id
d["currency"] = "CZK"
ref = {}
ref["phone_number"] = phone
ref["tariff"] = tariff_id
d["reference"] = ref
headers = {
'Content-Type': 'application/json',
'Authorization': 'Token %s' % settings.bitcoinPayAuthToken
}
request_payment = Request('https://www.bitcoinpay.com/api/v1/payment/btc', data=json.dumps(d), headers=headers)
response_body = urlopen(request_payment).read()
data = json.loads(response_body)["data"]
ticket.payment_id = data["payment_id"]
ticket.status = data["status"]
ticket.settled_amount = data["settled_amount"]
ticket.settled_currency = data["settled_currency"]
ticket.payment_response = json.dumps(data)
db_session.add(ticket)
db_session.commit()
# ulozime payment id v session
session["last_payment_id"] = ticket.payment_id
# saving user's phone to be able to retrieve tickets overview
session[PHONE_SESSION_KEY] = int(phone)
return redirect(data["payment_url"], code=302)
phone = session.get(PHONE_SESSION_KEY)
tariff = get_tariffs(tariff_id)
# return redirect(url_for('index'))
return render_template('ticket_buy.html', tariff=tariff, phone=phone)