-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix/installment offer code persistence #2249
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?
Fix/installment offer code persistence #2249
Conversation
|
|
||
| def has_original_offer_code? | ||
| original_offer_code_id.present? && (original_offer_code_amount_cents.present? || original_offer_code_amount_percentage.present?) | ||
| end | ||
|
|
||
| def original_offer_code_amount_off(price_cents) | ||
| return 0 if !has_original_offer_code? | ||
| return original_offer_code_amount_cents if !original_offer_code_is_percent? | ||
|
|
||
| (price_cents * (original_offer_code_amount_percentage / 100.0)).round | ||
| end | ||
|
|
||
| def original_offer_code_display_code | ||
| original_offer_code_code | ||
| end | ||
|
|
||
| def displayed_amount_off(currency_type, with_symbol: false) | ||
| return nil unless has_original_offer_code? | ||
|
|
||
| if with_symbol | ||
| if original_offer_code_is_percent? | ||
| "#{original_offer_code_amount_percentage}%" | ||
| else | ||
| Money.new(original_offer_code_amount_cents, currency_type).format(no_cents_if_whole: true, symbol: true) | ||
| end | ||
| else | ||
| if original_offer_code_is_percent? | ||
| original_offer_code_amount_percentage | ||
| else | ||
| Money.new(original_offer_code_amount_cents, currency_type).format(no_cents_if_whole: true, symbol: false) | ||
| end | ||
| end | ||
| end |
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.
removed association, added display methods
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.
updated set_price_and_rate and original_offer_code
| } | ||
|
|
||
| if purchase.offer_code.present? | ||
| snapshot_attrs.merge!( | ||
| original_offer_code_id: purchase.offer_code.id, | ||
| original_offer_code_amount_cents: purchase.offer_code.amount_cents, | ||
| original_offer_code_amount_percentage: purchase.offer_code.amount_percentage, | ||
| original_offer_code_is_percent: purchase.offer_code.is_percent?, | ||
| original_offer_code_duration_in_months: purchase.offer_code.duration_in_months, | ||
| original_offer_code_code: purchase.offer_code.code, | ||
| original_offer_code_currency: purchase.offer_code.currency_type | ||
| ) | ||
| end | ||
|
|
||
| payment_option.build_installment_plan_snapshot(snapshot_attrs) |
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.
snapshot now includes offer code fields
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.
new service
|
@EmCousin _a added updates as per #2237 (comment) |
fixes #1410
Previous PR #2075 & #2237
What
Stores offer code discount terms directly in InstallmentPlanSnapshot so installment payments retain their original discount even if the offer code is deleted, expired, or modified.
Changes
belongs_to :original_offer_codeassociation - no longer relies on live offer codeset_price_and_rateprioritizes snapshot data for installment paymentsOnetime::BackfillPaymentOptionInstallmentSnapshotsto include offer code data when creating snapshotsOnetime::BackfillOfferCodeFieldsToInstallmentSnapshotsto update existing snapshots missing offer code dataTests
AI disclosure
Used Claude Opus 4.5 via Cursor for implementation.
All code was manually reviewed and verified.
Notes
I’ve watched all the Antiwork livestreams