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:
Uses users and not billing profiles.
Didn't add the migrations file to the commit because there's another open PR #282 that has a migration that might get merged before this. Will update commit with migration file.
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:
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:
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.
Doesn't work with abandoned carts, it would still count the coupon as used even if it weren't checked out
Summary:
Notes:
Other approaches tried:
Change get_cart_options
Changing CouponRedeemAPIView