我正在写一个基于Django 3 By Example第三版的在线商店。我在付款部分遇到了一个关于这本书的代码的问题,我搜索了互联网并更新了一些代码,但我仍然有一个问题!在填写借记卡表格后,当我点击“立即付款!”按钮时,我没有被重定向到Don页面!
process.html
{% extends "shop/base.html" %}
{% block title %} Pay by credit card {% endblock %}
{% block sidenavigation %}
{% endblock %}
{% block content %}
## Pay by credit card
{% endblock %}
进程视图:
def payment_process(request):
"""The view that processes the payment"""
order_id = request.session.get('order_id')
order = get_object_or_404(Order, id=order_id)
total_cost = order.get_total_cost()
print(f'ORDER=== {order.first_name}')
if request.method == 'POST':
print('---------Post------------')
# retrieve nonce
# retrieve nonce
nonce = request.POST.get('paymentMethodNonce', None)
# # create User
customer_kwargs = {
# "customer_id": order.braintree_id
"first_name": order.first_name,
"last_name": order.last_name,
"email": order.email
}
customer_create = gateway.customer.create(customer_kwargs)
customer_id = customer_create.customer.id
# create and submit transaction
result = gateway.transaction.sale({
'amount': f'{total_cost:.2f}',
'payment_method_nonce': nonce,
'options': {
'submit_for_settlement': True
}
})
print(f'Result----{result}')
if result.is_success:
# mark the order as paid
print(f'------Success----')
order.paid = True
# store the unique transaction id
order.braintree_id = result.transaction.id
order.save()
return redirect('payment:done')
else:
return redirect('payment:canceled')
else:
print('---------Get----------')
# generate token
client_token = gateway.client_token.generate()
return render(
request,
'payment/process.html',
{
'order': order,
'client_token': client_token
}
)
1条答案
按热度按时间u3r8eeie1#
缩进payment_process函数中的代码