HQD-159: rename InstallmentWasStarted → InstallmentWasCharged, fire e…#118
HQD-159: rename InstallmentWasStarted → InstallmentWasCharged, fire e…#118bladeroot wants to merge 1 commit into
Conversation
…very month Previously the event fired only on the first billing month (exact match with formula since). If billing missed that month, the Sale was never created. Now the event fires for every month within the installment period. HandleInstallmentWasCharged (in hiapi-legacy) is already idempotent: it checks whether a Sale with the correct till-date already exists and skips creation if so. Renamed to InstallmentWasCharged to reflect the actual semantics — one charge processed, not necessarily the start of the installment.
📝 WalkthroughWalkthroughThis PR renames the domain event ChangesInstallment Event Rename and Modifier Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/charge/modifiers/event/InstallmentWasCharged.php (1)
41-46:⚠️ Potential issue | 🟠 Major | ⚡ Quick winSerialize the billing month as part of the event payload.
InstallmentWasChargedcan now be emitted multiple times for the sameprice_id/part_id, butjsonSerialize()still makes every month look identical. Any consumer that persists, deduplicates, or replays the JSON form loses which installment month was actually charged. Include the charge month/time, or another stable period identifier, in the serialized payload.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/charge/modifiers/event/InstallmentWasCharged.php` around lines 41 - 46, The jsonSerialize() output for InstallmentWasCharged omits any stable period identifier so multiple events with the same price_id/part_id are indistinguishable; update InstallmentWasCharged::jsonSerialize() to include a billing-period field (e.g. "charged_at" as an ISO‑8601 timestamp or "billing_month" as YYYY‑MM) derived from the Charge object (use the appropriate accessor on $this->charge such as getChargedAt()/getChargeDate()/getBillingPeriod()/getPeriodStart() and format to a stable string) so consumers can tell which installment month was charged. Ensure the new key is present alongside 'price_id' and 'part_id' and uses a consistent, parseable format.src/charge/modifiers/Installment.php (1)
105-119:⚠️ Potential issue | 🟠 Major | ⚡ Quick winNormalize the end-date check to billing-month granularity.
$timeis always normalized tofirst day of this month midnight, but this helper compares it to rawtill/term->addTo($since)timestamps and only treats an exact same-day diff as a match. For installments that start or end mid-month, the first post-installment billing month will never satisfy this check, soInstallmentWasFinishedis skipped. Compare against the same normalized month boundary used inmodifyCharge().🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/charge/modifiers/Installment.php` around lines 105 - 119, In isFirstMonthAfterInstallmentPassed, normalize the compared boundaries to the same "first day of month midnight" granularity as $time instead of relying on day-exact diff checks: when using $this->getTill()->getValue() or $this->getTerm()->addTo($since->getValue()), convert those DateTimeImmutable values to the month boundary (e.g. first day of that month at 00:00) before doing the <= or equality comparison, and replace the diff('%a') === '0' checks with direct comparisons against the normalized boundary; use the same normalization helper used in modifyCharge() or implement a small local normalization call and reference getSince, getTill, getTerm and term->addTo(...) to locate the places to change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/charge/modifiers/event/InstallmentWasCharged.php`:
- Around line 41-46: The jsonSerialize() output for InstallmentWasCharged omits
any stable period identifier so multiple events with the same price_id/part_id
are indistinguishable; update InstallmentWasCharged::jsonSerialize() to include
a billing-period field (e.g. "charged_at" as an ISO‑8601 timestamp or
"billing_month" as YYYY‑MM) derived from the Charge object (use the appropriate
accessor on $this->charge such as
getChargedAt()/getChargeDate()/getBillingPeriod()/getPeriodStart() and format to
a stable string) so consumers can tell which installment month was charged.
Ensure the new key is present alongside 'price_id' and 'part_id' and uses a
consistent, parseable format.
In `@src/charge/modifiers/Installment.php`:
- Around line 105-119: In isFirstMonthAfterInstallmentPassed, normalize the
compared boundaries to the same "first day of month midnight" granularity as
$time instead of relying on day-exact diff checks: when using
$this->getTill()->getValue() or $this->getTerm()->addTo($since->getValue()),
convert those DateTimeImmutable values to the month boundary (e.g. first day of
that month at 00:00) before doing the <= or equality comparison, and replace the
diff('%a') === '0' checks with direct comparisons against the normalized
boundary; use the same normalization helper used in modifyCharge() or implement
a small local normalization call and reference getSince, getTill, getTerm and
term->addTo(...) to locate the places to change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 985cc3a9-a6dd-4988-a026-7733041e3f7d
📒 Files selected for processing (7)
docs/formula-and-modifiers.mddocs/overview.mdsrc/charge/modifiers/Installment.phpsrc/charge/modifiers/event/InstallmentWasCharged.phptests/behat/Combination.featuretests/behat/Installment.featuretests/unit/charge/modifiers/InstallmentTest.php
…very month
Previously the event fired only on the first billing month (exact match with formula since). If billing missed that month, the Sale was never created.
Now the event fires for every month within the installment period. HandleInstallmentWasCharged (in hiapi-legacy) is already idempotent: it checks whether a Sale with the correct till-date already exists and skips creation if so.
Renamed to InstallmentWasCharged to reflect the actual semantics — one charge processed, not necessarily the start of the installment.
Summary by CodeRabbit
Bug Fixes
Documentation