diff --git a/datacenterlight/tests.py b/datacenterlight/tests.py index ca1bb930..68f4e15d 100644 --- a/datacenterlight/tests.py +++ b/datacenterlight/tests.py @@ -1,6 +1,7 @@ # from django.test import TestCase - +import datetime from time import sleep +from unittest import skipIf import stripe from celery.result import AsyncResult @@ -8,7 +9,6 @@ from django.conf import settings from django.core.management import call_command from django.test import TestCase, override_settings from model_mommy import mommy -from unittest import skipIf from datacenterlight.models import VMTemplate from datacenterlight.tasks import create_vm_task @@ -119,7 +119,8 @@ class CeleryTaskTestCase(TestCase): subscription_result = self.stripe_utils.subscribe_customer_to_plan( stripe_customer.stripe_id, [{"plan": stripe_plan.get( - 'response_object').stripe_plan_id}]) + 'response_object').stripe_plan_id}], + int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None) stripe_subscription_obj = subscription_result.get('response_object') # Check if the subscription was approved and is active if stripe_subscription_obj is None \ diff --git a/datacenterlight/views.py b/datacenterlight/views.py index ae649623..4dd328ad 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -1,3 +1,4 @@ +import datetime import logging from django import forms @@ -785,7 +786,9 @@ class OrderConfirmationView(DetailView, FormView): subscription_result = stripe_utils.subscribe_customer_to_plan( stripe_api_cus_id, [{"plan": stripe_plan.get( - 'response_object').stripe_plan_id}]) + 'response_object').stripe_plan_id}], + int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None + ) stripe_subscription_obj = subscription_result.get('response_object') # Check if the subscription was approved and is active if (stripe_subscription_obj is None diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index a1779d5f..8af6ddf6 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -724,6 +724,7 @@ X_FRAME_OPTIONS = ('SAMEORIGIN' if X_FRAME_OPTIONS_ALLOW_FROM_URI is None else INVOICE_WEBHOOK_SECRET = env('INVOICE_WEBHOOK_SECRET') DEBUG = bool_env('DEBUG') +ADD_TRIAL_PERIOD_TO_SUBSCRIPTION = bool_env('ADD_TRIAL_PERIOD_TO_SUBSCRIPTION') READ_VM_REALM = env('READ_VM_REALM') AUTH_NAME = env('AUTH_NAME') diff --git a/hosting/views.py b/hosting/views.py index e0f5ebd3..ce17376b 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1034,7 +1034,8 @@ class OrdersHostingDetailView(LoginRequiredMixin, DetailView, FormView): subscription_result = stripe_utils.subscribe_customer_to_plan( stripe_api_cus_id, [{"plan": stripe_plan.get( - 'response_object').stripe_plan_id}]) + 'response_object').stripe_plan_id}], + int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None) stripe_subscription_obj = subscription_result.get('response_object') # Check if the subscription was approved and is active if (stripe_subscription_obj is None or diff --git a/utils/tests.py b/utils/tests.py index 8abbbb1d..c67041d1 100644 --- a/utils/tests.py +++ b/utils/tests.py @@ -1,5 +1,7 @@ +import datetime import uuid from time import sleep +from unittest import skipIf from unittest.mock import patch import stripe @@ -8,7 +10,6 @@ from django.conf import settings from django.http.request import HttpRequest from django.test import Client from django.test import TestCase, override_settings -from unittest import skipIf from model_mommy import mommy from datacenterlight.models import StripePlan @@ -231,7 +232,8 @@ class StripePlanTestCase(TestStripeCustomerDescription): result = self.stripe_utils.subscribe_customer_to_plan( stripe_customer.stripe_id, [{"plan": stripe_plan.get( - 'response_object').stripe_plan_id}]) + 'response_object').stripe_plan_id}], + int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None) self.assertIsInstance(result.get('response_object'), stripe.Subscription) self.assertIsNone(result.get('error')) @@ -247,7 +249,8 @@ class StripePlanTestCase(TestStripeCustomerDescription): result = self.stripe_utils.subscribe_customer_to_plan( stripe_customer.stripe_id, [{"plan": stripe_plan.get( - 'response_object').stripe_plan_id}]) + 'response_object').stripe_plan_id}], + int(datetime.datetime.now().timestamp()) + 300 if settings.ADD_5MIN_TRIAL_TO_SUBSCRIPTION else None) self.assertIsNone(result.get('response_object'), None) self.assertIsNotNone(result.get('error'))