def capture_payment(request, order_pk, payment_pk):
order = get_object_or_404(Order, pk=order_pk)
payment = get_object_or_404(order.payments, pk=payment_pk)
amount = order.get_total().quantize('0.01').gross
form = CapturePaymentForm(request.POST or None, payment=payment,
initial={'amount': amount})
if form.is_valid() and form.capture():
amount = form.cleaned_data['amount']
msg = pgettext_lazy(
'Dashboard message related to a payment',
'Captured %(amount)s') % {'amount': gross(amount)}
payment.order.create_history_entry(comment=msg, user=request.user)
messages.success(request, msg)
return redirect('dashboard:order-details', order_pk=order.pk)
status = 400 if form.errors else 200
ctx = {'captured': payment.captured_amount, 'currency': payment.currency,
'form': form, 'order': order, 'payment': payment}
return TemplateResponse(request, 'dashboard/order/modal/capture.html', ctx,
status=status)
评论列表
文章目录