示例#1
0
文件: views.py 项目: pdiazv/makaw
def stripe_charge_view(request):

    article = Article.objects.get(pk=request.POST.get('article_id'))

    if article.quantity != 0 and article.sales_count == article.quantity:
        success_obj = { 'tag': 'error', 'message': 'Thank you for your interest in buying {}. Unfortunately, the item is sold out :('.format(article.name) }
        return HttpResponse(json.dumps(success_obj))

    raw_data = json.loads(request.POST.get('info'))
    dispatcher = StripeDispatcher(stripe.Customer, stripe.Charge)
    charge = dispatcher.finalize_charge(raw_data, article)

    info = PaymentInfo(
       source = 'stripe',
       article = article,
       txid = charge['txid'],
       chid = charge['chid'],
       status = charge['status'],
       amount = charge['amount'],
    )
    info.save()

    article.sales_count = article.sales_count + 1
    article.save()

    success_obj = { 'tag': 'success', 'message': 'Thank you for buying a {}. Your payment will be processed shortly.'.format(article.name) }
    return HttpResponse(json.dumps(success_obj))
示例#2
0
文件: views.py 项目: pdiazv/makaw
def paypal_success_view(request):

    charge = request.GET;
    article = get_object_or_404(Article, pk=request.GET.get('item_number'))

    info = PaymentInfo(
       source = 'paypal',
       article = article,
       txid = charge['tx'],
       chid = charge['tx'],
       status = charge['st'],
       amount = charge['amt'],
    )
    info.save()

    messages.success(request, 'Thank you for buying a <b>{}</b>. Your payment will be processed shortly.'.format(article.name))
    return redirect('ui:featured_article', article_id=article.id)