当前位置: 首页>>代码示例>>Python>>正文


Python Cart.check_out方法代码示例

本文整理汇总了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()
开发者ID:digideskio,项目名称:django_events,代码行数:32,代码来源:views.py

示例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))
开发者ID:cuescience,项目名称:cuescience-shop,代码行数:52,代码来源:cart_views.py


注:本文中的cart.Cart.check_out方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。