Skip to content

Commit

Permalink
Merge pull request #463 from renderbox/develop
Browse files Browse the repository at this point in the history
Release v0.4.19
  • Loading branch information
mgcamisa authored Oct 25, 2024
2 parents e6dfbdb + 044cc33 commit 269d7be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ universal = true

[project]
name = "django-vendor"
version = "0.4.18"
version = "0.4.19"

authors = [
{ name="Grant Viklund", email="[email protected]" },
Expand Down
22 changes: 17 additions & 5 deletions src/vendor/models/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,30 +253,40 @@ 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())

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)

Expand All @@ -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:
Expand Down
11 changes: 5 additions & 6 deletions src/vendor/processors/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand Down

0 comments on commit 269d7be

Please sign in to comment.