Repository navigation
Fix cancel payment showing after the NACHA cutoff has passed - #97556
Conversation
…n is not loaded yet
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0413680a64
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (payActions.length === 0) { | ||
| return false; |
There was a problem hiding this comment.
Keep elsewhere cancellations available when actions are paged out
When a reimbursed report was paid elsewhere but its PAY action is not in the currently loaded report-actions page (for example, cold-opening a long report with many newer comments/system actions), getAllReportActions(report.reportID) can return no pay actions even though the payment is cancellable; the More menu subscribes via usePaginatedReportActions in src/components/MoneyReportHeaderActions/MoneyReportHeaderSecondaryActions.tsx:155-156 and does not force-load the older PAY action. This early return therefore hides Cancel payment until the user happens to load that old action, regressing the previous paid-elsewhere fallback where no NACHA cutoff check was needed.
Useful? React with 👍 / 👎.
|
@iwiznia while verifying the fix for this issue I hit the same error in a case the frontend can't detect. Repro on staging: verified test business bank account (routing Can you confirm the backend behavior: does CancelReimbursement cancel a queued ACH withdrawal before the daily batch on production, or is an ACH payment uncancellable as soon as it's made? If it's uncancellable, the right fix is to stop offering Cancel payment for bank payments entirely and I'll update my PR that way. The current PR (#97556) fixes the cases where the option was shown after the cutoff had passed and while report actions were still loading, which cover the repro in the OP. I kinda feel this is BE issue. cc @dmkt9 |
|
Or else I found better RCA and solution (I guess): Root cause
Two more holes show the option when it can't work:
Solution Gate the bank branch on an active queued reimbursement (helpers already exist in + const queuedReimbursementCount = allActionsArray.filter((action) => !!action && isReimbursementQueuedAction(action)).length;
+ const dequeuedReimbursementCount = allActionsArray.filter((action) => !!action && isReimbursementDeQueuedOrCanceledAction(action)).length;
+ const hasActiveQueuedReimbursement = queuedReimbursementCount > dequeuedReimbursementCount;
- const isBankProcessing = isPaidViaBankAccount && (isInBillingState || isApprovedAndReimbursed || isAutoReimbursed);
+ const isBankProcessing = isPaidViaBankAccount && hasActiveQueuedReimbursement && (isInBillingState || isApprovedAndReimbursed || isAutoReimbursed);- const paymentDatetime = new Date(action.created);
+ const paymentDatetime = fromZonedTime(action.created, 'UTC');+ if (payActions.length === 0) {
+ return false;
+ }@dmkt9 what do you think? @iwiznia could you pls confirm this ?
|
|
The frontend gap is real, but the cause isn't the payee's wallet. canCancel gates on creditPosted IS NULL, not STATE_QUEUED, regular ACH stays cancellable until the debit posts, payee bank account or not. cancelBatchReimbursements1 asserts canCancel == true for a row already past queued. What can't be cancelled is payment type: fast ACH (credit posts immediately, L585), Stripe Connect (L486), booked Corpay. Your repro looks like fast ACH, what was the exact error string? What is the requestID? Separately, canCancel requires state BILLING + status REIMBURSED exactly, so accepting APPROVED/AUTOREIMBURSED is a second mismatch (AUTOREIMBURSED is post-batch, cancel already gone). Fix either way: call GetReportCancelReimbursementStatus instead of inferring from state. |
|
@iwiznia thanks for clarification.
How much "fast" means at maximum? 1 minute? 1 hour? I tried after 30minues as well
"Auth CancelReimbursement returned an error" Payload
curl 'https://dev.new.expensify.com:8082/staging/api/CancelPayment?' Response: {
"code": 666,
"jsonCode": 666,
"type": "Expensify\\Libs\\Error\\ExpError",
"UUID": "A4B9B751-6E44-4AC8-9F80-0CB4C4A6B659",
"message": "Auth CancelReimbursement returned an error",
"title": "",
"data": {
"onyxData": [
{
"onyxMethod": "merge",
"key": "reportActions_1534790247507182",
"value": {
"9012988934894641253": {
"errors": {
"1785586189587213": "Auth CancelReimbursement returned an error"
}
}
}
}
]
},
"htmlMessage": "",
"onyxData": [
{
"onyxMethod": "merge",
"key": "reportActions_1534790247507182",
"value": {
"9012988934894641253": {
"errors": {
"1785586189587213": "Auth CancelReimbursement returned an error"
}
}
}
}
],
"requestID": "a244bc743c23b905-SJC"
}P.s: I tried to cancel right after paying, i.e, in 10 seconds |
…rring from report state
|
@iwiznia PR updated per your suggestion: the app now calls And is there a way to get a regular (cancellable) ACH on staging for QA, or should QA steps cover the elsewhere flow only? |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 641f682535
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const isBankPaymentCancellable = !!reimbursementCancellableStatus?.canCancel; | ||
|
|
||
| return isPaymentProcessing && !hasDailyNachaCutoffPassed; | ||
| return (!!report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS_NUM.APPROVED) || (isPaidViaBankAccount && isBankPaymentCancellable); |
There was a problem hiding this comment.
Gate bank cancellation on a reimbursed report state
When a bank reimbursement is reported as cancellable and then the user cancels it, cancelPayment() moves the report back to APPROVED but does not clear reportCancelReimbursementStatus_<reportID>, and this hook also stops refreshing once the report is no longer REIMBURSED. Because this branch only checks the historical PAY action plus the stale canCancel, the More menu can continue to show Cancel payment on the already-canceled/approved report, leading to another CancelPayment attempt for a payment that no longer exists; keep the backend flag scoped to the reimbursed/billing states or clear it when cancellation succeeds.
Useful? React with 👍 / 👎.
| statementKey?: string; | ||
|
|
||
| /** Whether a report's bank reimbursement can still be canceled, from GetReportCancelReimbursementStatus */ | ||
| reimbursementCancellableStatus?: { |
There was a problem hiding this comment.
❌ CONSISTENCY-3 (docs)
The inline reimbursementCancellableStatus object type added here duplicates the exact shape (canCancel?: boolean and isWaitingForCreditToPost?: boolean, including the doc comments) of the new ReportCancelReimbursementStatus type added in src/types/onyx/ReportCancelReimbursementStatus.ts. Two identical definitions can drift apart over time. Response.ts already references named types elsewhere (e.g. transactionsPending3DSReview?: TransactionsPending3DSReview), so reuse the named type here instead of redefining its shape inline:
import type ReportCancelReimbursementStatus from './ReportCancelReimbursementStatus';
// ...
/** Whether a report's bank reimbursement can still be canceled, from GetReportCancelReimbursementStatus */
reimbursementCancellableStatus?: ReportCancelReimbursementStatus;Reviewed at: 641f682 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
between 24 hours and 2-3 business days
Thanks! Logs are not that useful as they are not printing the exact reason of the failure... I see this in the DB: So no reimbursement entry, I think due to it being the test bank account? Asking here |
|
Alright yeah, we skip the reimbursement table entry https://github.com/Expensify/Auth/blob/1435decebd88d7f53b55540ae0869d561f5b9e47/auth/lib/ACHReimbursement.cpp#L2390 and I think that means we never can cancel the reimbursement https://github.com/Expensify/Auth/blob/1435decebd88d7f53b55540ae0869d561f5b9e47/auth/lib/ACHReimbursement.cpp#L847 |
|
@mukhrr We have conflicts |
| errors?: OnyxCommon.Errors; | ||
|
|
||
| isWaitingOnBankAccount?: boolean; | ||
| canCancelReimbursement?: boolean; |
There was a problem hiding this comment.
Please add a comment for this
| const isReimbursementSubmitted = report.stateNum === CONST.REPORT.STATE_NUM.BILLING && report.statusNum === CONST.REPORT.STATUS_NUM.REIMBURSED; | ||
|
|
||
| return isPaymentProcessing && !hasDailyNachaCutoffPassed; | ||
| return isPaidViaBankAccount && isReimbursementSubmitted && !hasCutoffPassed && !!report.canCancelReimbursement; |
There was a problem hiding this comment.
I think we need to clear report.canCancelReimbursement optimistically once the cancellation is requested. Otherwise, report.canCancelReimbursement could become stale.
|
@iwiznia The |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1a462df28
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const isReimbursementSubmitted = report.stateNum === CONST.REPORT.STATE_NUM.BILLING && report.statusNum === CONST.REPORT.STATUS_NUM.REIMBURSED; | ||
|
|
||
| return isPaymentProcessing && !hasDailyNachaCutoffPassed; | ||
| return isPaidViaBankAccount && isReimbursementSubmitted && !hasCutoffPassed && !!report.canCancelReimbursement; |
There was a problem hiding this comment.
Refresh cancellability before offering cancellation
When OpenReport returns canCancelReimbursement: true and the report remains mounted while the credit posts or the cutoff passes, this condition continues trusting the persisted snapshot; reading new Date() here does not itself trigger a React render, and no remaining hook or timer refreshes the backend flag. The More menu can therefore retain Cancel payment and send a request Auth now rejects. Fresh evidence in this revision is that the prior refresh hook has been replaced by this report field, whose only client-side mutation is during a cancellation attempt; refresh or invalidate it when opening the menu or on an appropriate lifecycle event.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
hmm cutoff part is not new, main has the same new Date() here. the flag doesnt need a refresh (I hope). @iwiznia when credit posts Auth moves the report out of BILLING, that comes through Pusher?? or am I wrong? here refresh on menu open means extra API call, the 1:1:1 thing we dropped intentionally
There was a problem hiding this comment.
I don't think it comes through pusher but I also don't think it's a problem. Yes in the very unlikely case you had the report open, the reimbursement cancelation changes and you try to cancel the reimbursement, you'll get an error. That's so unlikely that I don't think we care.
| value: { | ||
| statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED, | ||
| isWaitingOnBankAccount: expenseReport.isWaitingOnBankAccount, | ||
| canCancelReimbursement: expenseReport.canCancelReimbursement, |
There was a problem hiding this comment.
I just realized there's one case where, if cancelPayment fails because the NACHA cutoff has already passed, canCancelReimbursement gets restored to true, causing the Cancel Payment option to appear again. However, as @iwiznia mentioned, this case is pretty rare, so I think we can ignore it for now.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safarichrome.mp4 |
|
@iwiznia kindly bump |
| const isAutoReimbursed = report.stateNum === CONST.REPORT.STATE_NUM.AUTOREIMBURSED && report.statusNum === CONST.REPORT.STATUS_NUM.REIMBURSED; | ||
| const isBankProcessing = isPaidViaBankAccount && (isInBillingState || isApprovedAndReimbursed || isAutoReimbursed); | ||
| const isPaymentProcessing = (!!report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS_NUM.APPROVED) || isBankProcessing; | ||
| const hasCutoffPassed = hasPayActionPassedNachaCutoff(latestPayAction); |
There was a problem hiding this comment.
Hmmm not sure I get this, why are we not just relying on the value of canCancelReimbursement (same below)?
There was a problem hiding this comment.
oh nice catch. yeah, it makes sense 👍 we can rely on BE
There was a problem hiding this comment.
@iwiznia I think we still need hasCutoffPassed here in case canCancelReimbursement becomes stale while offline. Otherwise, we should disable Cancel Payment entirely when we're offline.
|
🚧 iwiznia has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/iwiznia in version: 9.4.91-0 🚀
|
|
Yes, help site changes were required. Draft PR: Docs updates for E/A#97556 Clarify when Cancel payment is available Why: this PR replaced the client-side cancellability guess (report state + NACHA cutoff) with the backend's answer, so Cancel payment now only appears when the reimbursement can actually still be stopped — and never for payment types that post the credit immediately. Two articles described the old model, and one of them contradicted itself. What changed in the docs
No Expensify Classic change needed — Cancel ACH Reimbursement already describes cancellation as available only before the funds are withdrawn, which is the model New Expensify now matches. Verification and conventions
@mukhrr, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR |
|
🚀 Deployed to production by https://github.com/lakchote in version: 9.4.91-3 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Canceling a bank payment showed "Auth CancelReimbursement returned an error" because the app inferred cancellability from report state (
APPROVED/BILLING/AUTOREIMBURSED+REIMBURSED) plus a NACHA cutoff heuristic. The backend'scanCancelactually gates on the credit not having posted yet (state BILLING + status REIMBURSED exactly), and some payment types (fast ACH, Stripe Connect, booked Corpay) post the credit immediately, so they are never cancellable and no client-side inference can know that. Details in #97556 (comment).Per that suggestion, the app now asks the backend directly: a new side effect command
GetReportCancelReimbursementStatusis called when a reimbursed expense report is opened, the result is stored in Onyx (reportCancelReimbursementStatus_<reportID>), and Cancel payment is only offered whencanCancelis true. The state inference and the NACHA cutoff check are removed.Unchanged: paid elsewhere cancellation, and the guard that hides the option while the report's pay actions haven't loaded (we can't tell a bank payment from an elsewhere payment yet).
Fixed Issues
$ #96345
PROPOSAL: #96345 (comment)
Tests
reimbursementsrow for those, socanCancelis always false and the option stays hidden for every bank payment, see Fix cancel payment showing after the NACHA cutoff has passed #97556 (comment).Offline tests
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android_app.mp4
Android: mWeb Chrome
android_web.mp4
iOS: Native
ios_app.mp4
iOS: mWeb Safari
ios_web.mp4
MacOS: Chrome / Safari
MacOS: Desktop
96345-web.mp4