-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix: Preserve offer code discount for installments when code is deleted/expired/maxed (#1410) #3066
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
base: main
Are you sure you want to change the base?
Changes from all commits
52a8bbd
6ee718f
77675c8
ffb4525
bcc4d1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,7 +248,21 @@ def build_purchase(override_params: {}, from_failed_charge_email: false) | |
| purchase = Purchase.new(purchase_params) | ||
| purchase.variant_attributes = original_purchase.variant_attributes | ||
|
|
||
| purchase.offer_code = original_purchase.offer_code if discount_applies_to_next_charge? | ||
| if discount_applies_to_next_charge? | ||
| if original_purchase.purchase_offer_code_discount.present? | ||
| original_discount = original_purchase.purchase_offer_code_discount | ||
| purchase.offer_code = original_purchase.offer_code | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting |
||
| purchase.build_purchase_offer_code_discount( | ||
| offer_code: original_discount.offer_code, | ||
| offer_code_amount: original_discount.offer_code_amount, | ||
| offer_code_is_percent: original_discount.offer_code_is_percent, | ||
| pre_discount_minimum_price_cents: original_discount.pre_discount_minimum_price_cents, | ||
| duration_in_months: original_discount.duration_in_months | ||
| ) | ||
| elsif original_purchase.offer_code.present? | ||
| purchase.offer_code = original_purchase.offer_code | ||
| end | ||
| end | ||
|
Comment on lines
+251
to
+265
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the Core fix - we check if |
||
|
|
||
| purchase.purchaser = user | ||
| purchase.link = link | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test directly covers the reported issue #1410 - offer code with max_purchase_count=1, verify quantity_left <= 0 after first purchase, then confirm discount still applies to next installment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reordered the logic - check cached data first, then check if offer code is deleted. Previously we'd return nil for deleted codes before even checking if we had cached data.