from django.dispatch import receiver
from django.shortcuts import get_object_or_404
from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received, payment_was_successful, payment_was_flagged
from billing.models import UserBalanceChange
@receiver(payment_was_successful)
def payment_notification(sender, **kwargs):
ipn_obj = sender
if ipn_obj.payment_status == ST_PP_COMPLETED:
# payment was successful
order = get_object_or_404(UserBalanceChange, id=int(ipn_obj.invoice))
# mark the order as paid
order.active = True
order.save()
# valid_ipn_received.connect(payment_notification)
payment_was_flagged.connect(payment_notification)