Exemple #1
0
 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)
Exemple #2
0
class Purchase(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='purchases')
    magazine = models.ForeignKey(Magazine)
    subscription_end = models.DateTimeField(default=timezone.now())


def subscription_created(sender, **kwargs):
    ipn_obj = sender

    magazine_id = ipn_obj.custom.split('-')[0]
    user_id = ipn_obj.custom.split('-')[1]

    purchase = Purchase.objects.create(magazine_id=magazine_id, user_id=user_id,
                                       subscription_end=arrow.now().replace(weeks=+4).datetime)


subscription_signup.connect(subscription_created)


def subscription_was_cancelled(sender, **kwargs):
    ipn_obj = sender

    magazine_id = ipn_obj.custom.split('-')[0]
    user_id = ipn_obj.custom.split('-')[1]
    purchase = Purchase.objects.get(user_id=user_id, magazine_id=magazine_id)
    purchase.subscription_end = arrow.now()
    purchase.save()


subscription_cancel.connect(subscription_was_cancelled)
Exemple #3
0
from django.db import models
from paypal.standard.ipn.signals import subscription_cancel
import logging

def show_me_cancel(sender, **kwargs):
	logger = logging.getLogger("dev.ttagit.logger")
	logger.info("subscription_cancel")

subscription_cancel.connect(show_me_cancel)
Exemple #4
0
    # If the thing is invalid, do not process any further.
    if ipn_obj.flag:
        return

    # If the IPN object refers to a subscription ID other than the one that is ours,
    # stop immediately. This could happen if, say, they create a new subscription ID
    # (due to upgrading tier) and then cancelling the old one.
    #
    # That's exactly how we ask people to upgrade between tiers. Luckily, this
    # transition case is covered by the test suite.
    tier_info = TierInfo.objects.get_current()
    if tier_info.current_paypal_profile_id != ipn_obj.subscr_id:
        return

    _actually_switch_tier('basic')
subscription_cancel.connect(on_subscription_cancel_switch_to_basic)
subscription_eot.connect(on_subscription_cancel_switch_to_basic)


def handle_recurring_profile_modify(sender, **kwargs):
    ipn_obj = sender

    # If the thing is invalid, do not process any further.
    if ipn_obj.flag:
        return

    sitelocation = SiteLocation.objects.get_current()
    tier_info = TierInfo.objects.get_current()

    if (tier_info.current_paypal_profile_id != sender.subscr_id) and (tier_info.use_zendesk()):
        # then we had better notify staff indicating that the old one
        else:
            us.cancelled = True
            us.save()
            Transaction(user=u, subscription=s, ipn=sender,
                        event='cancel subscription', amount=sender.mc_gross
                        ).save()
        signals.unsubscribed.send(s, ipn=sender, subscription=s, user=u,
                                  usersubscription=us,
#                                  refund=refund, reason='cancel')
                                  reason='cancel')
    else:
        Transaction(user=u, subscription=s, ipn=sender,
                    event='unexpected cancel', amount=sender.mc_gross
                    ).save()
        signals.event.send(s, ipn=sender, subscription=s, user=u, event='unexpected_cancel')
subscription_cancel.connect(handle_subscription_cancel)
subscription_eot.connect(handle_subscription_cancel)

def handle_subscription_modify(sender, **kwargs):
    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()
        valid = False
    elif ipn_obj.mc_amount3 != trans.gross_amount:
        valid = False

    if not valid:
        subject, from_email = 'DA admin - Paypal subscription error', 'Directo al Artista <*****@*****.**>'
        message = render_to_string('email/paypal_subs_error.html', {
            'trans': trans, 'object': ipn_obj.item_name,
        })

        html_content = render_to_string('email/global/template.html', {
            'email_title': 'DA admin - Paypal subscription error',
            'email_content': message,
        })

        html_content = transform(html_content)
        text_content = strip_tags(html_content)

        msg = EmailMultiAlternatives(subject, text_content, from_email, ['*****@*****.**'])
        msg.attach_alternative(html_content, "text/html")
        msg.send(fail_silently=True)

    return valid

payment_was_successful.connect(payment_success)
payment_was_flagged.connect(payment_success_flagged)
payment_was_refunded.connect(paypal_refund_payment)

subscription_cancel.connect(paypal_subscription_canceled)
subscription_signup.connect(paypal_validate_plan_signup)
subscription_eot.connect(paypal_subscription_eot)
Exemple #7
0
from django.contrib.auth.models import User
from paypal.standard.ipn.signals import subscription_signup, subscription_cancel

def activate_subscription(sender, **kwargs):
    ipn_obj = sender
    user_profile = User.objects.get(username=ipn_obj.custom).get_profile()
    user_profile.is_subscriber = True
    user_profile.save()
subscription_signup.connect(activate_subscription, dispatch_uid='subscription.models.activate_subscription')

def cancel_subscription(sender, **kwargs):
    ipn_obj = sender
    user_profile = User.objects.get(username=ipn_obj.custom).get_profile()
    user_profile.is_subscriber = False
    user_profile.save()
subscription_cancel.connect(cancel_subscription, dispatch_uid='subscription.models.cancel_subscription')
Exemple #8
0
from django.db import models
from django.conf import settings
from django.utils import timezone
from signals import subscription_was_cancelled, subscription_created
from paypal.standard.ipn.signals import subscription_signup, subscription_cancel

subscription_signup.connect(subscription_created)
subscription_cancel.connect(subscription_was_cancelled)


class Magazine(models.Model):

    name = models.CharField(max_length=254, default='')
    description = models.TextField()
    price = models.DecimalField(max_digits=6, decimal_places=2)

    def __unicode__(self):
        return self.name


class Purchase(models.Model):

    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             related_name='purchases')
    magazine = models.ForeignKey(Magazine)
    subscription_end = models.DateTimeField(default=timezone.now)
from paypal.standard.ipn.signals import subscription_cancel
import logging

def sub_cancel_receiver(sender, **kwargs):
  log = logging.getLogger("dev.ttagit.logger")
	log.debug("SIGNAL!!!!----Cancel Subscription")

subscription_cancel.connect(show_me_the_money)
Exemple #10
0
        userprofile.trial_expiry_date = None
    if userprofile:
        userprofile.account_level = paid_account
        userprofile.save()


def arb_subscription_cancel_handler(sender, **kwargs):
    free_account = AccountLevel.objects.get(pk=1)
    try:
        userprofile = UserProfile.objects.get(pk=sender.user_profile.pk)
    except UserProfile.DoesNotExist:
        userprofile = None
    if userprofile:
        userprofile.subscription_active = 0
        userprofile.account_level = free_account
        userprofile.save()


#Paypal Signals
payment_was_successful.connect(my_payment_was_successful_handler)
subscription_signup.connect(my_payment_was_successful_handler)
subscription_cancel.connect(my_payment_cancel_handler)
subscription_cancel.connect(my_end_of_subscription_handler)

#Authorize.net ARB Signals
arb_subscription_signup.connect(arb_subscription_signup_handler)
arb_subscription_cancel.connect(arb_subscription_cancel_handler)

post_delete.connect(user_post_delete, sender=User)
post_save.connect(create_user_profile, sender=User)
Exemple #11
0
        userprofile.trial_ended = True
        userprofile.trial_expiry_date = None
    if userprofile:
        userprofile.account_level = paid_account
        userprofile.save()

def arb_subscription_cancel_handler(sender, **kwargs):
    free_account = AccountLevel.objects.get(pk=1)
    try:
        userprofile = UserProfile.objects.get(pk=sender.user_profile.pk)
    except UserProfile.DoesNotExist:
        userprofile = None
    if userprofile:  
        userprofile.subscription_active = 0
        userprofile.account_level = free_account
        userprofile.save()


#Paypal Signals
payment_was_successful.connect(my_payment_was_successful_handler)
subscription_signup.connect(my_payment_was_successful_handler)
subscription_cancel.connect(my_payment_cancel_handler)
subscription_cancel.connect(my_end_of_subscription_handler)

#Authorize.net ARB Signals
arb_subscription_signup.connect(arb_subscription_signup_handler)
arb_subscription_cancel.connect(arb_subscription_cancel_handler)

post_delete.connect(user_post_delete, sender=User)
post_save.connect(create_user_profile, sender=User)
Exemple #12
0
		# TODO: Only setup for monthly based, need to cater for other cycles
		invalid_date = True
		day_start = self.created.day
		while invalid_date:
			try:
				if datetime.now().month == 12:
					next_cycle_reset = date(datetime.now().year+1, 1, day_start)
				else:
					next_cycle_reset = date(datetime.now().year, datetime.now().month+1, day_start)
				invalid_date = False
			except:
				day_start = day_start - 1
		return next_cycle_reset
	
	def save(self, *args, **kwargs):
		super(UserSubscription, self).save(*args, **kwargs)
		
		# Delete all other entries for this user, so we only have one active one
		if self.is_active:
			all_other_subs = UserSubscription.objects.filter(user=self.user).exclude(subscription=self.subscription)
			all_other_subs.delete()
	
	def __unicode__(self):
		return "%s (%s)" % (self.user, self.subscription)
		

# SIGNALS
subscription_signup.connect(signal_subscription_created)
subscription_cancel.connect(signal_subscription_cancel)
subscription_eot.connect(signal_subscription_expires)
payment_was_successful.connect(signal_payment_was_successful)
Exemple #13
0
        return

    # If the IPN object refers to a subscription ID other than the one that is ours,
    # stop immediately. This could happen if, say, they create a new subscription ID
    # (due to upgrading tier) and then cancelling the old one.
    #
    # That's exactly how we ask people to upgrade between tiers. Luckily, this
    # transition case is covered by the test suite.
    tier_info = TierInfo.objects.get_current()
    if tier_info.current_paypal_profile_id != ipn_obj.subscr_id:
        return

    _actually_switch_tier('basic')


subscription_cancel.connect(on_subscription_cancel_switch_to_basic)
subscription_eot.connect(on_subscription_cancel_switch_to_basic)


def handle_recurring_profile_modify(sender, **kwargs):
    ipn_obj = sender

    # If the thing is invalid, do not process any further.
    if ipn_obj.flag:
        return

    sitelocation = SiteLocation.objects.get_current()
    tier_info = TierInfo.objects.get_current()

    if (tier_info.current_paypal_profile_id !=
            sender.subscr_id) and (tier_info.use_zendesk()):
            #                                  refund=refund, reason='cancel')
            reason='cancel')
    else:
        Transaction(user=u,
                    subscription=s,
                    ipn=sender,
                    event='unexpected cancel',
                    amount=sender.mc_gross).save()
        signals.event.send(s,
                           ipn=sender,
                           subscription=s,
                           user=u,
                           event='unexpected_cancel')


subscription_cancel.connect(handle_subscription_cancel)
subscription_eot.connect(handle_subscription_cancel)


def handle_subscription_modify(sender, **kwargs):
    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,