Example #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)
Example #2
0
class Magazine(models.Model):

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

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

    def __unicode__(self):
        return self.name
Example #3
0
            self.queue_new_feeds(new_feeds=stale_feeds)


def create_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)
    else:
        Profile.objects.get_or_create(user=instance)


post_save.connect(create_profile, sender=User)


def paypal_signup(sender, **kwargs):
    ipn_obj = sender
    user = User.objects.get(username=ipn_obj.custom)
    user.profile.activate_premium()


subscription_signup.connect(paypal_signup)


def change_password(user, old_password, new_password):
    user_db = authenticate(username=user.username, password=old_password)
    if user_db is None:
        return -1
    else:
        user_db.set_password(new_password)
        user_db.save()
        return 1
Example #4
0
    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)
Example #5
0
        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=s, ipn=sender,
                    event='unexpected subscription', amount=sender.mc_gross
                    ).save()
        signals.event.send(s, ipn=sender, subscription=s, user=u,
                           event='unexpected_subscription')
subscription_signup.connect(handle_subscription_signup)

def handle_subscription_cancel(sender, **kwargs):
    us = _ipn_usersubscription(sender)
    u, s = us.user, us.subscription
    if us.pk is not None:
        if not us.active:
            us.unsubscribe()
            us.delete()
            Transaction(user=u, subscription=s, ipn=sender,
                        event='remove subscription (cancelled)', amount=sender.mc_gross
                        ).save()
        else:
            us.cancelled = True
            us.save()
            Transaction(user=u, subscription=s, ipn=sender,
from paypal.standard.ipn.signals import subscription_signup
import logging

def sub_signup_receiver(sender, **kwargs):
  log = logging.getLogger("dev.ttagit.logger")
  log.debug("SIGNAL!!!!----Signup Subscr")

subscription_signup.connect(sub_signup_receiver)
Example #7
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)
Example #8
0
        tier_info.payment_due_date = expected_due_date
    else:
        tier_info.payment_due_date = datetime.timedelta(days=30) + ipn_obj.subscr_date
    tier_info.save()

    # If we get the IPN, and we have not yet adjusted the tier name
    # to be at that level, now is a *good* time to do so.
    amount = float(ipn_obj.amount3)
    if current_tier_obj.dollar_cost() == amount:
        pass
    else:
        # Find the right tier to move to
        target_tier_name = localtv.tiers.Tier.get_by_cost(amount)
        _actually_switch_tier(target_tier_name)

subscription_signup.connect(handle_recurring_profile_start)

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

    # 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.
    import localtv.models
Example #9
0
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ('-expires', )

    def __unicode__(self):
        return self.user.username

    def payment_type(self):
        if self.stripe_id:
            return 'Stripe'

        return 'PayPal'


def paypal_subs_created(sender, **kwargs):
    user = User.objects.get(id=sender.custom)

    subs = Subscription(
        user=user,
        name=user.username,
        stype=sender.item_number,
        expires=timezone.now() + datetime.timedelta(days=365),
        paypal_id=sender.payer_email,
        paypal_subs=sender.subscr_id,
    )
    subs.save()


subscription_signup.connect(paypal_subs_created)
Example #10
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')
  expires = models.DateTimeField()
  cancelled = models.BooleanField(default=False)
  created = models.DateTimeField(auto_now_add=True)
  
  class Meta:
    ordering = ('-expires',)
    
  def __unicode__ (self):
    return self.user.username
    
  def payment_type (self):
    if self.stripe_id:
      return 'Stripe'
      
    return 'PayPal'
    
def paypal_subs_created (sender, **kwargs):
  user = User.objects.get(id=sender.custom)
  
  subs = Subscription(
    user = user,
    name = user.username,
    stype = sender.item_number,
    expires = timezone.now() + datetime.timedelta(days=365),
    paypal_id = sender.payer_email,
    paypal_subs = sender.subscr_id,
  )
  subs.save()
  
subscription_signup.connect(paypal_subs_created)
Example #12
0
        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)
Example #13
0
from paypal.standard.ipn.signals import subscription_signup
import logging


def sub_signup_receiver(sender, **kwargs):
    log = logging.getLogger("dev.ttagit.logger")
    log.debug("SIGNAL!!!!----Signup Subscr")


subscription_signup.connect(sub_signup_receiver)
Example #14
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)
Example #15
0
        for sub in stale_feeds:
            sub.feed.fetched_once = False
            sub.feed.save()
        
        if stale_feeds:
            stale_feeds = list(set([f.feed.pk for f in stale_feeds]))
            self.queue_new_feeds(new_feeds=stale_feeds)
        
        
def create_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance)
    else:
        Profile.objects.get_or_create(user=instance)
post_save.connect(create_profile, sender=User)


def paypal_signup(sender, **kwargs):
    ipn_obj = sender
    user = User.objects.get(username=ipn_obj.custom)
    user.profile.activate_premium()
subscription_signup.connect(paypal_signup)

def change_password(user, old_password, new_password):
    user_db = authenticate(username=user.username, password=old_password)
    if user_db is None:
        return -1
    else:
        user_db.set_password(new_password)
        user_db.save()
        return 1
Example #16
0
    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)
Example #17
0
        self.update_approver_status()
        
    def update_approver_status(self):
        #TODO: do this only when approver changes or on create
        count = ApprovalRule.objects.filter(approver=self.approver).count()
        self.approver.is_approver = bool(count)
        self.approver.save()
        
        
class NationalHoliday(models.Model):
    country_code = models.CharField(max_length=10)
    name = models.CharField(max_length=150)
    date = models.DateField()
    
        
#class Settings(models.Model):
#    
#    default_days_off = models.SmallIntegerField(default=20)
#    day_count_reset_date = models.CharField(max_length=20, default='01-01') # day-month


from paypal.standard.ipn.signals import subscription_signup

def on_subscription_start(sender, **kwargs):
    ipn_obj = sender
    # Undertake some action depending upon `ipn_obj`.
    print ipn_obj
    #if ipn_obj.custom == "Upgrade all users!":
        #Users.objects.update(paid=True)        
subscription_signup.connect(on_subscription_start)
Example #18
0
    if expected_due_date:
        tier_info.payment_due_date = expected_due_date
    else:
        tier_info.payment_due_date = datetime.timedelta(days=30) + ipn_obj.subscr_date
    tier_info.save()

    # If we get the IPN, and we have not yet adjusted the tier name
    # to be at that level, now is a *good* time to do so.
    amount = float(ipn_obj.amount3)
    if current_tier_obj.dollar_cost() == amount:
        pass
    else:
        # Find the right tier to move to
        target_tier_name = tiers.Tier.get_by_cost(amount)
        _actually_switch_tier(target_tier_name)
subscription_signup.connect(handle_recurring_profile_start)


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

    # 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.
Example #19
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)
Example #20
0
                                user=u,
                                usersubscription=us)
    else:
        Transaction(user=u,
                    subscription=s,
                    ipn=sender,
                    event='unexpected subscription',
                    amount=sender.mc_gross).save()
        signals.event.send(s,
                           ipn=sender,
                           subscription=s,
                           user=u,
                           event='unexpected_subscription')


subscription_signup.connect(handle_subscription_signup)


def handle_subscription_cancel(sender, **kwargs):
    us = _ipn_usersubscription(sender)
    u, s = us.user, us.subscription
    if us.pk is not None:
        if not us.active:
            us.unsubscribe()
            us.delete()
            Transaction(user=u,
                        subscription=s,
                        ipn=sender,
                        event='remove subscription (cancelled)',
                        amount=sender.mc_gross).save()
        else: