fix(payments): back-fill orphaned payment records via Horizon in reconciliation job#34
Open
Jaydbrown wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #18
Summary
The
recoverPaidWithoutPaymentspath in the reconciliation job found sessions markedpaidwith no correspondingpaymentsrow but only logged them as "requires manual investigation" — it never actually recovered them. This PR makes that path active: it queries Horizon to find the confirming transaction, verifies it, and inserts the missing payment record so the DB is consistent without manual intervention.Root cause
When the phase-2 transaction in
processPayment(payment insert +paidstatus update) commits the session status update but the process dies before thepaymentsinsert completes — or the insert is rolled back while the outer status update already committed — you get apaidsession with no payment row. The reconciliation job found these but stopped at a log message.Changes
src/payments/payment-recovery.service.tsPaidWithoutPaymentRowinterface — addedmemoandreceiving_accountcolumns to the SELECT so we have the data needed to query Horizon:findConfirmingPayment— widened the parameter type to accept bothStuckProcessingRowandPaidWithoutPaymentRow, avoiding code duplication:recoverPaidWithoutPayments— now actively recovers instead of just logging:onConflictDoNothingensures the insert is idempotent — if the cron fires twice before the session is resolved, the second run is a no-op.Recovery flow after this fix
Test plan
paidsession that has nopaymentsrow and a matching Horizon transaction → payment record is insertedverifyTransactionreturns false → logged for manual review