當前位置: 首頁>>代碼示例>>Python>>正文


Python Order.card_type方法代碼示例

本文整理匯總了Python中orders.models.Order.card_type方法的典型用法代碼示例。如果您正苦於以下問題:Python Order.card_type方法的具體用法?Python Order.card_type怎麽用?Python Order.card_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在orders.models.Order的用法示例。


在下文中一共展示了Order.card_type方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: checkout_auto_renewal

# 需要導入模塊: from orders.models import Order [as 別名]
# 或者: from orders.models.Order import card_type [as 別名]
def checkout_auto_renewal(request):
    """for admin charging of auto renews"""
    customer = request.POST.get('ccStripeId', "")
    record_id = request.POST.get('recordId', "")
    user_id = request.POST.get('userId', "")
    issue = request.POST.get('issueNo', "")
    cc = CreditCard.objects.get(stripe_id=customer)
    user = User.objects.get(id=user_id)
    record = Record.objects.get(id=record_id)
    sub = Subscription.objects.get(sku="pbrenewal")

    cart = Cart(user=user)
    cart.save()
    cart_item = CartItem(cart=cart,
                         subscription=sub,
                         flug=sub.slug,
                         line_total=sub.price,
                         recipient=record.recipient,
                         )
    cart_item.save()
    cart.product_total = cart_item.line_total
    cart.total = cart_item.line_total
    cart.save()
    order=Order(cart=cart,
                user=user,
                total=cart.total,
                payer_name=user.get_full_name(),
                payer_email=user.email,
                )
    order.order_id = id_generator()
    order.save()
    amount = int(order.total * 100)  # convert to cents
    fee = int(order.total * 100 * settings.TRINITY_FEE * .01)  # % of inputed ($) amount, in cents
    try:
        charge = stripe.Charge.create(
            amount=amount,  # amount in cents, again
            currency="usd",
            application_fee=fee,
            customer=customer,
            api_key=settings.TRINITY_API_KEY,
        )

        order.status = "Finished"
        order.last4 = cc.last4
        order.card_type = cc.card_type
        order.save()

        recipient = record.recipient
        last_record = Record.objects.filter(recipient=recipient).order_by('issue').last()
        ish = last_record.issue + 1
        # try:
        #    all_record = Record.objects.get(recipient=sub.recipient, originating_order=order, issue=ish)

        for x in range(0, cart_item.subscription.term):
            try:
                record = Record.objects.get(recipient=recipient, originating_order=order, issue=ish)
                pass
            except Record.DoesNotExist:
                new_record = Record(recipient=recipient, originating_order=order, issue=ish)
                new_record.save()
            ish += 1

        order.status = "Recorded"
        order.save()

        # now we notify.
        subbies = CartItem.subbie_type.filter(cart=cart)
        current_site = Site.objects.get_current()
        local = settings.LOCAL
        email_context = {
            "cart": cart,
            "subbies": subbies,
            "order": order,
            "current_site": current_site,
            "local": local,
        }

        if settings.EMAIL_NOTIFICATIONS is True:
            recipient = order.payer_email
            print "email notifications are true and we're about to send to %s" % recipient

            purchase_notify(email_context, recipient)

        else:
            print "email settings not true"
            pass

    except stripe.CardError, e:

        # Since it's a decline, stripe.error.CardError will be caught
        body = e.json_body
        err = body['error']

        print "Status is: %s" % e.http_status
        print "Type is: %s" % err['type']
        print "Code is: %s" % err['code']

        print "Message is: %s" % err['message']
        messages.error(request, "%s The payment could not be completed." % err['message'])
開發者ID:davogler,項目名稱:POSTv3,代碼行數:101,代碼來源:views.py


注:本文中的orders.models.Order.card_type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。