feat(payments): explicit PayPal capture state handling (#377) - #1104
Merged
Calebux merged 1 commit intoJul 24, 2026
Merged
Conversation
The PayPal capture path collapsed every non-COMPLETED status into a single generic error, so callers could not tell a declined card from a transient failure or a payment held for review. Handle each documented PayPal capture status explicitly: - COMPLETED -> success (guards against a missing capture id) - DECLINED / FAILED -> explicit permanent-failure error, including PayPal's status_details.reason when present - PENDING -> surfaced as requiresAction so it is persisted as pending and finalized by the webhook rather than reported as a hard success - unknown -> generic fallback error Adds status_details.reason to PayPalCaptureResponse and unit tests for the DECLINED, FAILED, and PENDING branches. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Relates to #377.
The real PayPal order/capture flow already exists in
PaymentService(created in prior work —d718702,a1045c7), so this PR focuses on the one acceptance-criteria gap that was still weak: "Handle declined/failed states explicitly."Previously the capture path treated every non-
COMPLETEDstatus as one generic error:So a genuinely declined card, a transient failure, and a payment held for review (PENDING) were indistinguishable to UI/API callers.
Changes
client/lib/payment-service.ts— branch on the PayPal capture status explicitly:COMPLETEDDECLINED/FAILEDstatus_details.reasonwhen presentPENDINGrequiresActionso it's persisted as pending and finalized by the webhook, instead of being reported as a hard successclient/lib/paypal-service.ts— addstatus_details.reasontoPayPalCaptureResponseso the decline reason can be surfaced.Testing
vitest run lib/__tests__/payment-service.test.ts:11 passed / 5 failed→14 passed / 5 failedafter adding the 3 new passing tests. Those pre-existing failures are unrelated to PayPal and out of scope here.🤖 Generated with Claude Code