def __init__(self, shop): self.shop = shop # Hook the payment was successful listener on the appropriate signal sent # by django-paypal (success_signal) assert settings.PAYPAL_RECEIVER_EMAIL, "You need to define a PAYPAL_RECEIVER_EMAIL in settings with the money recipient's email addresss" assert settings.PAYPAL_CURRENCY_CODE, "You need to define a PAYPAL_CURRENCY_CODE in settings with the currency code" success_signal.connect(self.payment_was_successful, weak=False) flagged_signal.connect(self.payment_was_flagged, weak=False) subscription_cancel_signal.connect(self.subscription_cancelled, weak=False) subscription_eot_signal.connect(self.subscription_expired, weak=False) subscription_modify_signal.connect(self.subscription_modified, weak=False) subscription_signup_signal.connect(self.subscription_signup_success, weak=False) recurring_create_signal.connect(self.recurring_created, weak=False) recurring_payment_signal.connect(self.recurring_payment, weak=False) recurring_cancel_signal.connect(self.recurring_cancelled, weak=False)
us = _ipn_usersubscription(sender) u, s = us.user, us.subscription print 'modify', u, s if us: # delete all user's other subscriptions for old_us in u.usersubscription_set.all(): if old_us==us: continue # don't touch current subscription old_us.delete() Transaction(user=u, subscription=s, ipn=sender, event='remove subscription (deactivated)', amount=sender.mc_gross ).save() # activate new subscription us.subscribe() us.active = True us.cancelled = False us.save() Transaction(user=u, subscription=s, ipn=sender, event='activated', amount=sender.mc_gross ).save() signals.subscribed.send(s, ipn=sender, subscription=s, user=u, usersubscription=us) else: Transaction(user=u, subscription=u, ipn=sender, event='unexpected subscription modify', amount=sender.mc_gross ).save() signals.event.send(s, ipn=sender, subscription=s, user=u, event='unexpected_subscription_modify') subscription_modify.connect(handle_subscription_modify)
message_body, use_configured_assignee=False) return # Okay, well at this point, we need to adjust the site tier to match. amount = float(ipn_obj.amount3) sitelocation = localtv.models.SiteLocation.objects.get_current() if sitelocation.get_tier().dollar_cost() == amount: pass else: # Find the right tier to move to try: target_tier_name = localtv.tiers.Tier.get_by_cost(amount) except ValueError: # then we had better notify staff indicating that the # amount is bizarre. if tier_info.use_zendesk(): import localtv.zendesk message_body = render_to_string('localtv/admin/tiers_emails/confused_modify_wrong_amount.txt', {'paypal_email_address': settings.PAYPAL_RECEIVER_EMAIL, 'profile_on_file': tier_info.current_paypal_profile_id, 'site_domain': localtv.models.SiteLocation.objects.get_current().site.domain, 'surprising_profile': ipn_obj.subscr_id}) localtv.zendesk.create_ticket("Eek, you should check on this MC site", message_body, use_configured_assignee=False) return _actually_switch_tier(target_tier_name) subscription_modify.connect(handle_recurring_profile_modify)
target_tier_name = tiers.Tier.get_by_cost(amount) except ValueError: # then we had better notify staff indicating that the # amount is bizarre. if tier_info.use_zendesk(): message_body = render_to_string('localtv/admin/tiers_emails/confused_modify_wrong_amount.txt', {'paypal_email_address': tiers.get_paypal_email_address(), 'profile_on_file': tier_info.current_paypal_profile_id, 'site_domain': sitelocation.site.domain, 'surprising_profile': ipn_obj.subscr_id}) zendesk.create_ticket("Eek, you should check on this MC site", message_body, use_configured_assignee=False) return _actually_switch_tier(target_tier_name) subscription_modify.connect(handle_recurring_profile_modify) def handle_successful_payment(sender, **kwargs): ipn_obj = sender # If the thing is invalid, do not process any further. if ipn_obj.flag: return test_ipn = getattr(settings, 'PAYPAL_TEST', False) if ipn_obj.test_ipn != test_ipn: # per Asheesh, make sure that the test_ipn setting matches the PAYPAL_TEST setting return
# activate new subscription us.subscribe() us.active = True us.cancelled = False us.save() Transaction(user=u, subscription=s, ipn=sender, event='activated', amount=sender.mc_gross).save() signals.subscribed.send(s, ipn=sender, subscription=s, user=u, usersubscription=us) else: Transaction(user=u, subscription=u, ipn=sender, event='unexpected subscription modify', amount=sender.mc_gross).save() signals.event.send(s, ipn=sender, subscription=s, user=u, event='unexpected_subscription_modify') subscription_modify.connect(handle_subscription_modify)