Stripe in Blender Studio #93018

Merged
Anna Sirota merged 9 commits from studio-to-stripe into main 2024-06-17 17:39:10 +02:00
2 changed files with 9 additions and 3 deletions
Showing only changes of commit f6c53505e5 - Show all commits

View File

@ -147,6 +147,9 @@ class CheckoutExistingOrderView(LoginRequiredMixin, ExpectReadableIPAddressMixin
# should be passed from the app, this url name is defined in example_app # should be passed from the app, this url name is defined in example_app
cancel_url = 'settings_home' cancel_url = 'settings_home'
def get_cancel_url(self):
return reverse(self.cancel_url)
def get_object(self, queryset=None) -> models.Order: def get_object(self, queryset=None) -> models.Order:
order_id: int = self.kwargs['order_id'] order_id: int = self.kwargs['order_id']
order_q = models.Order.objects.filter(customer=self.request.user.customer) order_q = models.Order.objects.filter(customer=self.request.user.customer)
@ -171,7 +174,7 @@ class CheckoutExistingOrderView(LoginRequiredMixin, ExpectReadableIPAddressMixin
# we have to do it to avoid uri-encoding of curly braces, # we have to do it to avoid uri-encoding of curly braces,
# otherwise stripe doesn't do the template substitution # otherwise stripe doesn't do the template substitution
success_url = success_url.replace('CHECKOUT_SESSION_ID', '{CHECKOUT_SESSION_ID}', 1) success_url = success_url.replace('CHECKOUT_SESSION_ID', '{CHECKOUT_SESSION_ID}', 1)
cancel_url = self.request.build_absolute_uri(reverse(self.cancel_url)) cancel_url = self.request.build_absolute_uri(self.get_cancel_url())
session = stripe_utils.create_stripe_checkout_session_for_order( session = stripe_utils.create_stripe_checkout_session_for_order(
order, order,
success_url, success_url,

View File

@ -102,7 +102,10 @@ class PaymentMethodChangeView(LoginRequiredMixin, View):
log = log.getChild('PaymentMethodChangeView') log = log.getChild('PaymentMethodChangeView')
subscription: models.Subscription subscription: models.Subscription
success_url = '/' success_url = '/'
cancel_url = '/' cancel_url = 'settings_home'
def get_cancel_url(self):
return reverse(self.cancel_url)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
self.subscription = get_object_or_404( self.subscription = get_object_or_404(
@ -120,7 +123,7 @@ class PaymentMethodChangeView(LoginRequiredMixin, View):
# we have to do it to avoid uri-encoding of curly braces, # we have to do it to avoid uri-encoding of curly braces,
# otherwise stripe doesn't do the template substitution # otherwise stripe doesn't do the template substitution
success_url = success_url.replace('CHECKOUT_SESSION_ID', '{CHECKOUT_SESSION_ID}', 1) success_url = success_url.replace('CHECKOUT_SESSION_ID', '{CHECKOUT_SESSION_ID}', 1)
cancel_url = self.request.build_absolute_uri(reverse(self.cancel_url)) cancel_url = self.request.build_absolute_uri(self.get_cancel_url())
session = stripe_utils.setup_stripe_payment_method( session = stripe_utils.setup_stripe_payment_method(
self.subscription.currency.lower(), self.subscription.currency.lower(),
request.user.customer, request.user.customer,