From 0a5514855502466639ad67dd742f3295baf3160e Mon Sep 17 00:00:00 2001 From: Moggach Date: Wed, 17 Jul 2024 15:28:38 +0000 Subject: [PATCH 1/6] change styling on bootstrap alert on gift purchase checkout screen --- app/templates/app/frames/shipping_cost.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/app/frames/shipping_cost.html b/app/templates/app/frames/shipping_cost.html index e1e3948f..2ff4a357 100644 --- a/app/templates/app/frames/shipping_cost.html +++ b/app/templates/app/frames/shipping_cost.html @@ -42,7 +42,7 @@ {% bootstrap_alert "This subscription will automatically renew, and you can cancel at any time." dismissible=False alert_type="success" extra_classes='mb-2' %} {% if request.GET.gift_mode %} - {% bootstrap_alert "At checkout, please add your own shipping address, in case we need to send you any gift card materials. Your gift recipient will be able to enter their own address when they redeem." dismissible=False alert_type="warning" extra_classes='mb-2' %} + {% bootstrap_alert "At checkout, please add your own shipping address, in case we need to send you any gift card materials. Your gift recipient will be able to enter their own address when they redeem." dismissible=False alert_type="warning" extra_classes='mb-2 text-light bg-danger' %} {% endif %} {% if user.is_member and not request.GET.gift_mode %}
From c41303049f4bfc4655dfcab3927cc3ee0f2536f0 Mon Sep 17 00:00:00 2001 From: Moggach Date: Wed, 17 Jul 2024 16:15:14 +0000 Subject: [PATCH 2/6] dont show shipping address options in stripe checkout when we are in gift mode --- app/views.py | 61 +++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/app/views.py b/app/views.py index 570a14db..3abf8f66 100644 --- a/app/views.py +++ b/app/views.py @@ -611,30 +611,29 @@ def create_checkout_context( if zone is None: raise ValueError("zone required to create checkout") - checkout_args = dict( - mode="subscription", - allow_promotion_codes=True, - line_items=price.to_checkout_line_items(product=product, zone=zone), + checkout_args = { + "mode": "subscription", + "allow_promotion_codes": True, + "line_items": price.to_checkout_line_items(product=product, zone=zone), # By default, customer details aren't updated, but we want them to be. - customer_update={ - "shipping": "auto", + "customer_update": { "address": "auto", "name": "auto", }, - shipping_address_collection={"allowed_countries": zone.country_codes}, - metadata={"primary_product": product.id}, - ) + "metadata": {"primary_product": product.id}, + } - next = "/" - if gift_mode: - checkout_args["metadata"]["gift_mode"] = True - next = reverse_lazy("completed_gift_purchase") + if not gift_mode: + checkout_args["customer_update"]["shipping"] = "auto" + checkout_args["shipping_address_collection"] = {"allowed_countries": zone.country_codes} else: - next = reverse_lazy("completed_membership_purchase") + checkout_args["metadata"]["gift_mode"] = True + + next_url = reverse_lazy("completed_gift_purchase" if gift_mode else "completed_membership_purchase") return { "checkout_args": checkout_args, - "next": next, + "next": next_url, "cancel_url": price.plan.url, "breadcrumbs": { "price": price, @@ -665,7 +664,6 @@ def get( return StripeCheckoutView.as_view(context=checkout_context)(request) - from django.shortcuts import get_object_or_404 @@ -1263,19 +1261,17 @@ def create_checkout_context( if zone is None: raise ValueError("zone required to create checkout") - checkout_args = dict( - mode="subscription", - allow_promotion_codes=True, - line_items=price.to_checkout_line_items(product=product, zone=zone), + checkout_args = { + "mode": "subscription", + "allow_promotion_codes": True, + "line_items": price.to_checkout_line_items(product=product, zone=zone), # By default, customer details aren't updated, but we want them to be. - customer_update={ - "shipping": "auto", + "customer_update": { "address": "auto", "name": "auto", }, - shipping_address_collection={"allowed_countries": zone.country_codes}, - metadata={"primary_product": product.id}, - ) + "metadata": {"primary_product": product.id}, + } if donation_amount > 0: checkout_args["line_items"].append( @@ -1287,16 +1283,17 @@ def create_checkout_context( ) ) - next = "/" - if gift_mode: - checkout_args["metadata"]["gift_mode"] = True - next = reverse_lazy("completed_gift_purchase") + if not gift_mode: + checkout_args["customer_update"]["shipping"] = "auto" + checkout_args["shipping_address_collection"] = {"allowed_countries": zone.country_codes} else: - next = reverse_lazy("completed_membership_purchase") + checkout_args["metadata"]["gift_mode"] = True + + next_url = reverse_lazy("completed_gift_purchase" if gift_mode else "completed_membership_purchase") return { "checkout_args": checkout_args, - "next": next, + "next": next_url, "cancel_url": price.plan.url, "breadcrumbs": { "price": price, @@ -1336,4 +1333,4 @@ def get( donation_amount=donation_amount, ) - return StripeCheckoutView.as_view(context=checkout_context)(request) + return StripeCheckoutView.as_view(context=checkout_context)(request) \ No newline at end of file From eecf64fea412a7bf99495046bf0ffc7c1878038e Mon Sep 17 00:00:00 2001 From: Moggach Date: Wed, 17 Jul 2024 16:17:31 +0000 Subject: [PATCH 3/6] remove unnecessary alert from gift card checkout --- app/templates/app/frames/shipping_cost.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/templates/app/frames/shipping_cost.html b/app/templates/app/frames/shipping_cost.html index 2ff4a357..21efb563 100644 --- a/app/templates/app/frames/shipping_cost.html +++ b/app/templates/app/frames/shipping_cost.html @@ -41,9 +41,6 @@
{% bootstrap_alert "This subscription will automatically renew, and you can cancel at any time." dismissible=False alert_type="success" extra_classes='mb-2' %} - {% if request.GET.gift_mode %} - {% bootstrap_alert "At checkout, please add your own shipping address, in case we need to send you any gift card materials. Your gift recipient will be able to enter their own address when they redeem." dismissible=False alert_type="warning" extra_classes='mb-2 text-light bg-danger' %} - {% endif %} {% if user.is_member and not request.GET.gift_mode %}
From b4a6646304b39c80170d6c0ff7bd35d77a082715 Mon Sep 17 00:00:00 2001 From: Moggach Date: Wed, 17 Jul 2024 19:06:57 +0000 Subject: [PATCH 4/6] add back in shipping address for gift purchases but allow all countries --- app/views.py | 66 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/app/views.py b/app/views.py index 3abf8f66..ab2721d9 100644 --- a/app/views.py +++ b/app/views.py @@ -35,6 +35,7 @@ from sentry_sdk import capture_exception, capture_message from wagtail.models import Page + from app import analytics from app.forms import ( CountrySelectorForm, @@ -587,6 +588,7 @@ def get_context_data(self, price_id, product_id, country_id="GB", **kwargs): } return context + class SubscriptionCheckoutView(TemplateView): @@ -611,29 +613,35 @@ def create_checkout_context( if zone is None: raise ValueError("zone required to create checkout") - checkout_args = { - "mode": "subscription", - "allow_promotion_codes": True, - "line_items": price.to_checkout_line_items(product=product, zone=zone), + checkout_args = dict( + mode="subscription", + allow_promotion_codes=True, + line_items=price.to_checkout_line_items(product=product, zone=zone), # By default, customer details aren't updated, but we want them to be. - "customer_update": { + customer_update={ + "shipping": "auto", "address": "auto", "name": "auto", }, - "metadata": {"primary_product": product.id}, - } + shipping_address_collection={"allowed_countries": zone.country_codes}, + metadata={"primary_product": product.id}, + ) - if not gift_mode: - checkout_args["customer_update"]["shipping"] = "auto" - checkout_args["shipping_address_collection"] = {"allowed_countries": zone.country_codes} - else: + next = "/" + if gift_mode: checkout_args["metadata"]["gift_mode"] = True - next_url = reverse_lazy("completed_gift_purchase" if gift_mode else "completed_membership_purchase") + checkout_args["shipping_address_collection"] = { + "allowed_countries": ShippingZone.all_country_codes + + } + next = reverse_lazy("completed_gift_purchase") + else: + next = reverse_lazy("completed_membership_purchase") return { "checkout_args": checkout_args, - "next": next_url, + "next": next, "cancel_url": price.plan.url, "breadcrumbs": { "price": price, @@ -664,6 +672,7 @@ def get( return StripeCheckoutView.as_view(context=checkout_context)(request) + from django.shortcuts import get_object_or_404 @@ -1261,17 +1270,19 @@ def create_checkout_context( if zone is None: raise ValueError("zone required to create checkout") - checkout_args = { - "mode": "subscription", - "allow_promotion_codes": True, - "line_items": price.to_checkout_line_items(product=product, zone=zone), + checkout_args = dict( + mode="subscription", + allow_promotion_codes=True, + line_items=price.to_checkout_line_items(product=product, zone=zone), # By default, customer details aren't updated, but we want them to be. - "customer_update": { + customer_update={ + "shipping": "auto", "address": "auto", "name": "auto", }, - "metadata": {"primary_product": product.id}, - } + shipping_address_collection={"allowed_countries": zone.country_codes}, + metadata={"primary_product": product.id}, + ) if donation_amount > 0: checkout_args["line_items"].append( @@ -1283,17 +1294,16 @@ def create_checkout_context( ) ) - if not gift_mode: - checkout_args["customer_update"]["shipping"] = "auto" - checkout_args["shipping_address_collection"] = {"allowed_countries": zone.country_codes} - else: + next = "/" + if gift_mode: checkout_args["metadata"]["gift_mode"] = True - - next_url = reverse_lazy("completed_gift_purchase" if gift_mode else "completed_membership_purchase") + next = reverse_lazy("completed_gift_purchase") + else: + next = reverse_lazy("completed_membership_purchase") return { "checkout_args": checkout_args, - "next": next_url, + "next": next, "cancel_url": price.plan.url, "breadcrumbs": { "price": price, @@ -1333,4 +1343,4 @@ def get( donation_amount=donation_amount, ) - return StripeCheckoutView.as_view(context=checkout_context)(request) \ No newline at end of file + return StripeCheckoutView.as_view(context=checkout_context)(request) From 776e9e1dbebfb1cb4360260e687a389cbfc840fc Mon Sep 17 00:00:00 2001 From: Moggach Date: Wed, 17 Jul 2024 19:10:01 +0000 Subject: [PATCH 5/6] add back in warning message --- app/templates/app/frames/shipping_cost.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/templates/app/frames/shipping_cost.html b/app/templates/app/frames/shipping_cost.html index 21efb563..01224de7 100644 --- a/app/templates/app/frames/shipping_cost.html +++ b/app/templates/app/frames/shipping_cost.html @@ -41,6 +41,9 @@
{% bootstrap_alert "This subscription will automatically renew, and you can cancel at any time." dismissible=False alert_type="success" extra_classes='mb-2' %} + {% if request.GET.gift_mode %} + {% bootstrap_alert "At checkout, please add your own shipping address, in case we need to send you any gift card materials. Your gift recipient will be able to enter their own address when they redeem." dismissible=False alert_type="warning" extra_classes='mb-2 text-light bg-danger' %} + {% endif %} {% if user.is_member and not request.GET.gift_mode %}
@@ -49,7 +52,7 @@ type="checkbox" value="" id='confirm_cancel_current_subscriptions' - name='confirm_cancel_current_subscriptions'/> + name='confirm_cancel_current_subscriptions' />