Skip to content

Commit

Permalink
Merge pull request #576 from sptgps/573-zhuangmiao-trial_end-days
Browse files Browse the repository at this point in the history
Bugfix: in subscriptions.create, trial_days using timezone naive utcnow() and add test
  • Loading branch information
paltman authored Nov 26, 2021
2 parents a263211 + 9ee3c7f commit 4bc2904
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pinax/stripe/actions/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def create(customer, plan, quantity=None, trial_days=None, token=None, coupon=No

subscription_params = {}
if trial_days:
subscription_params["trial_end"] = datetime.datetime.utcnow() + datetime.timedelta(days=trial_days)
subscription_params["trial_end"] = timezone.now() + datetime.timedelta(days=trial_days)
if token:
subscription_params["source"] = token

Expand Down
5 changes: 4 additions & 1 deletion pinax/stripe/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,10 @@ def test_subscription_create_with_trial(self, SubscriptionCreateMock, SyncMock):
subscriptions.create(self.customer, "the-plan", trial_days=3)
self.assertTrue(SubscriptionCreateMock.called)
_, kwargs = SubscriptionCreateMock.call_args
self.assertEqual(kwargs["trial_end"].date(), (datetime.datetime.utcnow() + datetime.timedelta(days=3)).date())
self.assertEquals(kwargs["trial_end"].date(),
(timezone.now() + datetime.timedelta(days=3)).date())
self.assertEquals(kwargs["trial_end"].tzname(),
(timezone.now() + datetime.timedelta(days=3)).tzname())

@patch("pinax.stripe.actions.subscriptions.sync_subscription_from_stripe_data")
@patch("stripe.Subscription.create")
Expand Down

0 comments on commit 4bc2904

Please sign in to comment.