Example #1
0
def create_recurring_profile_handler(request):
    """We will return a tuple where the first element is the dict that
    should be passed to PayPal CreateRecurringPaymentsProfile method and the
    second one is a PayPalUserSubscription object already set up that matches
    the data on the dict."""
    token = request.session['paypal_token']
    subscription = request.session['paypal_subscription']
    user = request.user
    profile = user.get_profile()
    upgrading = request.session['paypal_upgrading']
    us = request.session['paypal_current']
    time_obj = datetime.datetime.now()
    trial = False
    new_us = PayPalUserSubscription(user=user, subscription=subscription)
    if upgrading and us is not None:
        # We set the Trial time as the time left on the current user
        # subscription
        delta_days = (us.expires - datetime.datetime.now().date()).days
        print delta_days
        if delta_days > 0:
            print 'Adding trial time from our current subscription'
            trial = True
            trial_dict = dict(TRIALBILLINGPERIOD='Day',
                              TRIALBILLINGFREQUENCY=delta_days,
                              TRIALTOTALBILLINGCYCLES=1,
                              TRIALAMT=0)
            new_us.expires = subscription_utils.extend_date_by(
                new_us.expires, delta_days, 'D')
            print trial_dict
    elif not profile.had_trial:
        # The user is not upgrading and hasn't had his trial period.'
        trial = True
        trial_dict = dict(
            TRIALBILLINGPERIOD=subscription.get_trial_unit_display(),
            TRIALBILLINGFREQUENCY=1,
            TRIALTOTALBILLINGCYCLES=1,
            TRIALAMT=0)
        new_us.expires = subscription_utils.extend_date_by(
            new_us.expires, subscription.trial_period, subscription.trial_unit)
    else:
        # No trial.
        pass

    the_dict = dict(
        TOKEN=token,
        PROFILESTARTDATE=time_obj.strftime('%Y-%m-%dT%H:%M:%SZ'),
        DESC='Jim Venetos Golf Academy Membership: %s' %
        subscription.description,
        BILLINGPERIOD=subscription.get_recurrence_unit_display(),
        BILLINGFREQUENCY=1,
        AMT=subscription.price,
        MAXFAILEDPAYMENTS=3,
    )
    if trial:
        the_dict.update(trial_dict)

    return (the_dict, new_us)
Example #2
0
 def __init__(self, *args, **kwargs):
     super(UserSubscription, self).__init__(*args, **kwargs)
     
     if self.expires is None: 
         period, unit = (self.subscription.trial_period, 
                         self.subscription.trial_unit) if self.subscription.trial_period \
                         else (self.subscription.recurrence_period,
                             self.subscription.recurrence_unit)
         
         self.expires = utils.extend_date_by(datetime.datetime.now(), period, unit)
Example #3
0
 def extend(self, timedelta=None):
     """Extend subscription by `timedelta' or by subscription's
     recurrence period."""
     if timedelta is not None:
         self.expires += timedelta
     else:
         self.expires = utils.extend_date_by(
             self.expires, self.subscription.recurrence_period,
             self.subscription.recurrence_unit)
     self.save()
     signals.recured.send(self)
Example #4
0
    def __init__(self, *args, **kwargs):
        super(UserSubscription, self).__init__(*args, **kwargs)

        if self.expires is None:
            period, unit = (self.subscription.trial_period,
                            self.subscription.trial_unit) if self.subscription.trial_period \
                            else (self.subscription.recurrence_period,
                                self.subscription.recurrence_unit)

            self.expires = utils.extend_date_by(datetime.datetime.now(),
                                                period, unit)
Example #5
0
 def extend(self, timedelta=None):
     """Extend subscription by `timedelta' or by subscription's
     recurrence period."""
     if timedelta is not None:
         self.expires += timedelta
     else:
         self.expires = utils.extend_date_by(
                         self.expires,
                         self.subscription.recurrence_period,
                         self.subscription.recurrence_unit)
     self.save()
     signals.recured.send(self)
Example #6
0
def create_recurring_profile_handler(request):
    """We will return a tuple where the first element is the dict that
    should be passed to PayPal CreateRecurringPaymentsProfile method and the
    second one is a PayPalUserSubscription object already set up that matches
    the data on the dict."""
    token = request.session['paypal_token']
    subscription = request.session['paypal_subscription']
    user = request.user
    profile = user.get_profile()
    upgrading = request.session['paypal_upgrading']
    us = request.session['paypal_current']
    time_obj = datetime.datetime.now()
    trial = False
    new_us = PayPalUserSubscription(
        user=user, subscription=subscription
    )
    if upgrading and us is not None:
        # We set the Trial time as the time left on the current user
        # subscription
        delta_days = (us.expires-datetime.datetime.now().date()).days
        print delta_days
        if delta_days > 0:
            print 'Adding trial time from our current subscription'
            trial = True
            trial_dict = dict(
                TRIALBILLINGPERIOD='Day',
                TRIALBILLINGFREQUENCY=delta_days,
                TRIALTOTALBILLINGCYCLES=1,
                TRIALAMT=0
            )
            new_us.expires = subscription_utils.extend_date_by(
                new_us.expires,
                delta_days,
                'D'
            )
            print trial_dict
    elif not profile.had_trial:
        # The user is not upgrading and hasn't had his trial period.'
        trial = True
        trial_dict = dict(
            TRIALBILLINGPERIOD=subscription.get_trial_unit_display(),
            TRIALBILLINGFREQUENCY=1,
            TRIALTOTALBILLINGCYCLES=1,
            TRIALAMT=0
        )
        new_us.expires = subscription_utils.extend_date_by(
            new_us.expires,
            subscription.trial_period,
            subscription.trial_unit
        )
    else:
        # No trial.
        pass

    the_dict = dict(
        TOKEN=token,
        PROFILESTARTDATE=time_obj.strftime('%Y-%m-%dT%H:%M:%SZ'),
        DESC='Jim Venetos Golf Academy Membership: %s' % subscription.description,
        BILLINGPERIOD=subscription.get_recurrence_unit_display(),
        BILLINGFREQUENCY=1,
        AMT=subscription.price,
        MAXFAILEDPAYMENTS=3,
    )
    if trial:
        the_dict.update(trial_dict)

    return (the_dict, new_us)