Coupon Redemption

A user can use a coupon to avail discounts on purchases of products. If the company is offering subscription, then the user can use the coupon to avail discount on subscriptions too.

Coupons are tied to a product or subscription. Multiple coupons can be attached to a product or subscription. Same coupon can be attached to multiple products.( A company can have multiple products but a single subscription).

Coupon details are stored in coupons table and subscription details are stored in subscription table.

When a user tries to redeem a coupon, the following operations are performed - Validates whether the coupon code is valid (By checking the coupons table) Matches the coupon code against the products in cart. If no products are found, then coupon will be rejected If the product matches, the a discount is calculated and deducted from the product price. Once the order is confirmed, then the coupon redeem count is increased by 1.

Following are the DB change required Table Name: coupon_usages

Column_name type Description
id integer primary key
purchase_id integer cart item id
coupon_id integer references the coupon.
created_at date_time date on which this coupon was redeemed
updated_at date_time

Please note that coupon_usages keeps track of all successful redemption tries. An entry in coupon usages does not mean that the coupon has been redeemed. Only when the order is confirmed, the coupon is termed as successfully redeemed.