Guard every action against a missing quickpayPaymentId - #60
Merged
Conversation
StatusAction, SyncAction and ConfirmPaymentAction already guarded the missing-id case; AuthorizeAction, CaptureAction, RefundAction and CancelAction did not — (int) $model['quickpayPaymentId'] on a missing key is (int) null = 0, so the call went out as an operation on /payments/0 and came back as a NotFoundException after a network round trip, blaming a payment id nobody ever set. The new Details::paymentId() helper reads the id in one place: missing, non-numeric or non-positive values throw a clear LogicException before any HTTP happens (also catching a garbage id where the loose (int) cast used to send 0), and a numeric string — the shape a serialization round trip in the consumer's storage may produce — is accepted.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 2.x #60 +/- ##
============================================
- Coverage 97.43% 97.23% -0.20%
- Complexity 126 132 +6
============================================
Files 14 15 +1
Lines 351 362 +11
============================================
+ Hits 342 352 +10
- Misses 9 10 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Aug 10, 2026
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.
Fixes robustness finding R3 of #57.
Problem
The guards were inconsistent:
StatusAction,SyncActionandConfirmPaymentActionhandled a missingquickpayPaymentIdexplicitly, butAuthorizeAction,CaptureAction,RefundActionandCancelActiondid not —(int) $model['quickpayPaymentId']on a missing key is(int) null = 0, so the call went out as an operation on/payments/0and came back as aNotFoundExceptionafter a network round trip, blaming a payment id nobody ever set.AuthorizeActioneven ranvalidateNotEmpty()on four other keys but not this one.Fix
New
Details::paymentId()helper (mirroring the existingAmountspattern) reads the id in one place and is used by all seven read sites:LogicException("The payment has not been created at Quickpay …") before any HTTP happens — this also hardens the three previously guarded actions, where a garbage id ('abc') still slipped through the loose cast as0;AuthorizeActionresolves the id before minting a notify token, so no token is created for a payment that does not exist.StatusAction'smarkNew()andSyncAction's no-op for an absent key are unchanged — absence is meaningful there by design.Tests
Per-action guard tests (throw + zero HTTP requests) for Authorize/Capture/Refund/Cancel, plus a dedicated
DetailsTestcovering the accepted and rejected shapes.