Skip to content

Commit

Permalink
Don't ask for off-session setup on anonymous donors (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuboschek committed Jun 30, 2024
1 parent 751a429 commit 9623a7e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions donations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ class DonateView(CreateView):
model = Donation
fields = ["amount", "target"]

def get_success_url(self):
def get_success_url(self) -> str:
# Create a Stripe Checkout Session
stripe_customer = user_to_stripe_customer_id(self.request.user)

if stripe_customer:
payment_method_options = {"card": {"setup_future_usage": "off_session"}}
else:
payment_method_options = None

session: stripe.checkout.Session = stripe.checkout.Session.create(
customer=user_to_stripe_customer_id(self.request.user),
mode="payment",
Expand All @@ -47,7 +54,7 @@ def get_success_url(self):
success_url=self.request.build_absolute_uri(
reverse("donation-detail", args=(str(self.object.external_id),))
),
payment_method_options={"card": {"setup_future_usage": "off_session"}},
payment_method_options=payment_method_options,
submit_type="donate",
)

Expand Down

0 comments on commit 9623a7e

Please sign in to comment.