本文整理汇总了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'])