Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Work-in-Progress] limit coupon use as one per profile (#280) #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Deep-Chill
Copy link
Contributor

@Deep-Chill Deep-Chill commented Oct 28, 2023

Summary:

  • Add a "uses" ManyToManyField to keep track of a coupon's usage by users
  • Validate the "redeem method" using this field
  • Add users to this field in the "execute_order" method
  • Works with abandoned carts, works with "redeem" function/APIview/"cart-periods/" page, works with coupon codes in the session.

Notes:

Other approaches tried:

  • Change get_cart_options

    • Uses billing profiles(ie. subscription.organization in the get_cart_options function) and filters for relevant Transactions where the coupon code is applied to keep track of usage. Could also use a ManyToManyField here and add to it in the execute_order function like done in this commit.
    • Issue:
      1. Visual mismatch on the /cart-periods/ page. Users can attempt to "redeem" coupons, and the page shows coupons as applied, although they aren't in effect. This occurs because CouponRedeemAPIView applies coupons to all eligible cart items for the requesting user, then afterwards get_cart_options sets the coupon to None.
  • Changing CouponRedeemAPIView

    • Uses request.user, and filters for Transactions where the coupon is used OR uses a ManyToManyField in the coupon model to store users that have used a coupon
    • Issues:
      1. If we're using request.user but we want to track billing profiles, we can't properly filter for organizations since there's no "organization" passed into the view, and if we try to get attached_organizations that causes a mismatch when a user has multiple organizations.
      2. Doesn't work with abandoned carts, it would still count the coupon as used even if it weren't checked out

@smirolo smirolo changed the title [Work-in-Progress] limit coupon use as one per profile [Work-in-Progress] limit coupon use as one per profile (#280) Oct 30, 2023
Copy link
Contributor

@smirolo smirolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the rationale. It is not limiting one coupon per profile but instead one coupon per user.
That means:

  • 2 users that are profile managers for the same organization can use the coupon for that organization.
  • a user that is a profile manager for multiple organizations can only use the coupon once, having to choose which organization to apply it to.
    It might be OK as a business decision to limit coupon per user instead of per profile. I need to think about it. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants