def test_first_payment_description(self): def format_date(date_): from django.template.defaultfilters import date return date(date_, 'M j, Y') rental_plan = RentalPlan.objects.all_active()[0] _inum, desc = rental_plan.get_first_payment_description("123") next_payment_date = format_date(inc_date(datetime.date.today(), "1m")) self.assertTrue(next_payment_date in desc)
def get_expiration_date(self, plan_start_date=None, downgrade=False): _plan = self._payment_matrix[self.pk] exp = _plan[3] if not exp: return None if downgrade: exp -= 1 if plan_start_date is None: plan_start_date = datetime.date.today() return inc_date(plan_start_date, exp)
def test_signup_plan_free_trial(self): plan = RentalPlan.objects.get(slug="free_trial") # Monthly 1 Game Plan self.signup_plan(plan) self.assertEqual(len(mail.outbox), 1) self.assertEqual(MemberRentalPlan.objects.count(), 1) mrp = MemberRentalPlan.objects.all()[0] self.assertEqual(mrp.plan, plan.pk) self.assertEqual(mrp.start_date, datetime.date.today()) self.assertEqual(mrp.expiration_date, None) self.assertEqual(mrp.next_payment_date, inc_date(datetime.date.today(), "10d")) self.assertEqual(mrp.next_payment_amount, None) self.assertTrue(mrp.first_payment)
def test_get_next_payment(self): # # Limited 1 # rental_plan = RentalPlan.objects.all_active()[0] # First Payment date, amount, type_ = rental_plan.get_next_payment() self.assertEqual(date, datetime.date.today()) self.assertEqual(amount, rental_plan.first_payment_amount) self.assertEqual(type_, "AUTH_CAPTURE") # Thereafter Payment date, amount, type_ = rental_plan.get_next_payment(datetime.date.today()) self.assertEqual(date, inc_date(datetime.date.today(), "1m")) self.assertEqual(amount, rental_plan.thereafter_payments_amount) self.assertEqual(type_, "AUTH_CAPTURE") # --- # # Free Trial # rental_plan = RentalPlan.objects.get(slug="free_trial") # First Payment date, amount, type_ = rental_plan.get_next_payment() self.assertEqual(date, datetime.date.today()) self.assertEqual(amount, rental_plan.first_payment_amount) self.assertEqual(type_, "AUTH_ONLY") # Thereafter Payment # Actually this doesn't matter because there will be no # thereafter payments for Free Trial (we have set # scheduled_plan to PlanB) date, amount, type_ = rental_plan.get_next_payment(datetime.date.today()) self.assertEqual(date, inc_date(datetime.date.today(), "10d")) self.assertEqual(amount, None) self.assertEqual(type_, "AUTH_CAPTURE")
def test_signup_plan_limited(self): plan = RentalPlan.objects.get(slug="unlimited1") self.signup_plan(plan) self.assertEqual(len(mail.outbox), 1) self.assertEqual(MemberRentalPlan.objects.count(), 1) self.assertEqual(User.objects.count(), 1) self.assertEqual(Profile.objects.count(), 1) self.assertTrue(Profile.objects.all()[0].shipping_state) mrp = MemberRentalPlan.objects.all()[0] self.assertEqual(mrp.plan, plan.pk) self.assertEqual(mrp.start_date, datetime.date.today()) self.assertEqual(mrp.expiration_date, None) self.assertEqual(mrp.next_payment_date, inc_date(datetime.date.today(), "1m")) self.assertEqual(mrp.next_payment_amount, mrp.rental_plan.thereafter_payments_amount) self.assertTrue(mrp.first_payment) card = BillingCard.objects.all()[0] self.assertTrue(card.data.get("exp_year")) self.assertTrue(card.type)
def get_next_payment(self, plan_start_date=None, force_future_date=False): if force_future_date: raise NotImplementedError payment_amount = self.thereafter_payments_amount payment_type = "AUTH_CAPTURE" pay_every = self.pay_every # If first payment if plan_start_date is None: plan_start_date = datetime.date.today() pay_every = 0 payment_amount = self.first_payment_amount payment_type = self.first_payment_type if pay_every is None and payment_amount is None: return None, None, None while True: date, amount, type_ = inc_date(plan_start_date, pay_every), payment_amount, payment_type if not force_future_date or date > datetime.date.today(): break plan_start_date = date return date, amount and Decimal(amount), type_