diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 185b3e29..3a720cdc 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -933,11 +933,11 @@ 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}], - coupon='ipv6-discount-8chf' if ( - 'name' in discount and - discount['name'] is not None and - 'ipv6' in discount['name'].lower() - ) else "", + coupon=(discount['stripe_coupon_id'] + if 'name' in discount and + 'ipv6' in discount['name'].lower() and + discount['stripe_coupon_id'] + else ""), tax_rates=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [], ) stripe_subscription_obj = subscription_result.get('response_object') diff --git a/hosting/views.py b/hosting/views.py index 729d115b..17af51fd 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1185,7 +1185,11 @@ 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}], - coupon='ipv6-discount-8chf' if 'name' in discount and 'ipv6' in discount['name'].lower() else "", + coupon=(discount['stripe_coupon_id'] + if 'name' in discount and + 'ipv6' in discount['name'].lower() and + discount['stripe_coupon_id'] + else ""), tax_rates=[stripe_tax_rate.tax_rate_id] if stripe_tax_rate else [], ) stripe_subscription_obj = subscription_result.get('response_object') diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 2ad3d335..aebbf717 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -122,7 +122,8 @@ def get_vm_price_for_given_vat(cpu, memory, ssd_size, hdd_size=0, discount = { 'name': discount_name, 'amount': discount_amount, - 'amount_with_vat': round(float(discount_amount_with_vat), 2) + 'amount_with_vat': round(float(discount_amount_with_vat), 2), + 'stripe_coupon_id': pricing.stripe_coupon_id } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent), 2), discount) @@ -173,7 +174,8 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0, vat = vat.quantize(cents, decimal.ROUND_HALF_UP) discount = { 'name': pricing.discount_name, - 'amount': round(float(pricing.discount_amount), 2) + 'amount': round(float(pricing.discount_amount), 2), + 'stripe_coupon_id': pricing.stripe_coupon_id } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent), 2), discount)