diff --git a/pyproject.toml b/pyproject.toml index 54af2028..03d7c321 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ universal = true [project] name = "django-vendor" -version = "0.4.18" +version = "0.4.19" authors = [ { name="Grant Viklund", email="renderbox@gmail.com" }, diff --git a/src/vendor/models/offer.py b/src/vendor/models/offer.py index 07e4c3af..1cd21391 100644 --- a/src/vendor/models/offer.py +++ b/src/vendor/models/offer.py @@ -253,22 +253,29 @@ def has_trial(self): return True return False - def has_valid_billing_start_date(self, today=timezone.now()): + def has_valid_billing_start_date(self, today=None): + if today is None: + today = timezone.now() + if self.billing_start_date and self.billing_start_date > today: return True return False - def get_offer_start_date(self, start_date=timezone.now()): + def get_offer_start_date(self, start_date=None): + if start_date is None: + start_date = timezone.now() if self.term_start_date and self.term_start_date > start_date: return self.term_start_date return start_date - def get_offer_end_date(self, start_date=timezone.now()): + def get_offer_end_date(self, start_date=None): """ Determines the start date offset so the payment gateway starts charging the monthly offer """ units = self.term_details.get('term_units', TermDetailUnits.MONTH) + if start_date is None: + start_date = timezone.now() if units == TermDetailUnits.MONTH: return get_future_date_months(start_date, self.get_period_length()) @@ -276,7 +283,10 @@ def get_offer_end_date(self, start_date=timezone.now()): elif units == TermDetailUnits.DAY: return get_future_date_days(start_date, self.get_period_length()) - def get_trial_end_date(self, start_date=timezone.now()): + def get_trial_end_date(self, start_date=None): + if start_date is None: + start_date = timezone.now() + if self.billing_start_date and self.billing_start_date > start_date: return self.billing_start_date - timedelta(days=1) @@ -292,7 +302,9 @@ def get_trial_end_date(self, start_date=timezone.now()): return start_date + timedelta(days=self.get_trial_days()) - def get_payment_start_date_trial_offset(self, start_date=timezone.now()): + def get_payment_start_date_trial_offset(self, start_date=None): + if start_date is None: + start_date = timezone.now() trial_end_date = self.get_trial_end_date(start_date) if trial_end_date == start_date: diff --git a/src/vendor/processors/stripe.py b/src/vendor/processors/stripe.py index 3c030d03..6a305665 100644 --- a/src/vendor/processors/stripe.py +++ b/src/vendor/processors/stripe.py @@ -350,16 +350,15 @@ def stripe_call(self, *args): def convert_decimal_to_integer(self, decimal): if decimal == 0: return 0 - + fraction_part, whole_part = modf(decimal) - + rounded_fraction = round(fraction_part, 2) + whole_str = str(whole_part).split('.')[0] - # need to use Decimal since floats will not always round as expected - rounded_fraction = Decimal(fraction_part).quantize(Decimal('.00'), rounding=ROUND_UP) - fraction_str = str(rounded_fraction).split('.')[1] + fraction_str = str(rounded_fraction).split('.')[1][:2] if len(fraction_str) < 2: - fraction_str = "0" + fraction_str + fraction_str = fraction_str + "0" stripe_amount = int("".join([whole_str, fraction_str]))