本文整理汇总了Python中cart.Cart.check_out方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.check_out方法的具体用法?Python Cart.check_out怎么用?Python Cart.check_out使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.Cart
的用法示例。
在下文中一共展示了Cart.check_out方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cart_checkout
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import check_out [as 别名]
def cart_checkout(request, template='events/cart_checkout.html'):
context = {}
cart = CartManager(request)
if request.method == 'POST':
try:
stripe.api_key = settings.STRIPE_PRIVATE_KEY
# get the credit card details submitted by the form
token = request.POST['stripeToken']
# create the charge on Stripe's servers - this will charge the user's card
charge = stripe.Charge.create(
amount=int(cart.summary()*100), # amount in cents
currency="usd",
card=token,
description=request.user.email
)
if charge.get('paid'):
subject = _(u'[Django Events] Your purchase has been accepted.')
message = 'You bought:\n'
for ticket_order in cart:
message += '%s * %s for %s\n' % (ticket_order.quantity,
ticket_order.ticket.name,
ticket_order.ticket.event.name)
send_mail(subject, message, '[email protected]',
[request.user.email], fail_silently=True)
cart.check_out()
return HttpResponse('TRUE')
return HttpResponse('FALSE')
except:
import traceback
traceback.print_exc()
示例2: done
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import check_out [as 别名]
def done(self, form_list, **kwargs):
cart = Cart(self.request)
cart.create_cart()
order = Order(cart=cart.cart)
client = form_list[0].save(commit=False)
address = form_list[1].save()
client.shipping_address = address
billing_address = address
if condition_step_3(self):
billing_address = form_list[2].save()
client.billing_address = billing_address
client.save()
order.client = client
payment_option = self.get_cleaned_data_for_step("4").get("payment_options", None)
print ("PAYMENT {0}".format(self.get_cleaned_data_for_step("4")))
language = translation.get_language().upper()
if payment_option == "PayPal":
result = self.create_paypalpayment(cart)
order.payment = result.paypal_payment_db
order.save()
# we need to do the checkout after saving the order,
# if something went wrong
cart.check_out()
mail_result = EMailTemplate.objects.send("{0}_ORDER_SUCCESS_PAYPAL".format(language), client.email,
{"order": order, "billing_address": billing_address,
"shipping_address": address,
"paypal_url": order.payment.approval_url})
if result.payment.error:
logger.error("PayPal payment went wrong! Errors: {0}".format(result.payment.error))
return render(self.request, "cuescience_shop/failure_paypal.html", {"order": order})
elif not result.payment.errors and order.payment.approval_url:
return render(self.request, "cuescience_shop/success_paypal.html", {"order": order})
elif payment_option == "Prepayment":
payment = PrePayment()
payment.save()
order.payment = payment
order.save()
cart.check_out()
mail_result = EMailTemplate.objects.send("{0}_ORDER_SUCCESS_PREPAYMENT".format(language), client.email,
{"order": order, "billing_address": billing_address,
"shipping_address": address})
return render(self.request, "cuescience_shop/success.html", {"order": order})
return render_to_response("cuescience_shop/cart/index.html", RequestContext(self.request))