コード例 #1
0
 def pending():
     # Process pending ones
     payments = Payment.objects.filter(
         customer__origin=PAYMENTS_ORIGIN,
         state=Payment.ACCEPTED).select_for_update()
     for payment in payments:
         if 'subscription' in payment.extra:
             process_subscription(payment)
         else:
             process_donation(payment)
コード例 #2
0
def process_payment(request):
    try:
        payment = Payment.objects.get(
            pk=request.GET["payment"],
            customer__origin=PAYMENTS_ORIGIN,
            customer__user_id=request.user.id,
        )
    except (KeyError, Payment.DoesNotExist):
        return redirect(reverse("user"))

    # Create donation
    if payment.state in (Payment.NEW, Payment.PENDING):
        messages.error(request, gettext("Payment not yet processed, please retry."))
    elif payment.state == Payment.REJECTED:
        messages.error(
            request,
            gettext("The payment was rejected: {}").format(
                payment.details.get("reject_reason", gettext("Unknown reason"))
            ),
        )
    elif payment.state == Payment.ACCEPTED:
        if "subscription" in payment.extra:
            messages.success(request, gettext("Thank you for your subscription."))
            process_subscription(payment)
        else:
            messages.success(request, gettext("Thank you for your donation."))
            donation = process_donation(payment)
            if donation.reward:
                return redirect(donation)

    return redirect(reverse("user"))