Add result helpers to Payment and Operation - #13
Merged
Conversation
"Was the capture approved?" meant hand-rolling the same inspection in every integration: find the operation with type=capture, pending=false and qp_status_code=20000. That's where consumers make bugs (forgetting `pending`, comparing the code as an int, summing rejected operations). Operation: - QP_STATUS_APPROVED = '20000' - isApproved(): !pending && qpStatusCode === '20000' - isOfType(OperationType|string) Payment: - operation(int $id): ?Operation - latestOperation(): ?Operation (highest id, regardless of array order) - operationsOfType(OperationType|string): list<Operation> - hasPendingOperation(): bool - authorizedAmount() / capturedAmount() / refundedAmount(): sums of APPROVED operations only (authorizedAmount includes `recurring`, which authorizes a recurring payment) - isCancelled(): an approved cancel exists Plus a README section "Reading what happened to a payment" and tests (unit tests on hand-built payments + assertions on the mapped fixture). Refs #10 (finding 4).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.x #13 +/- ##
============================================
+ Coverage 98.50% 98.64% +0.14%
- Complexity 147 171 +24
============================================
Files 24 24
Lines 401 443 +42
============================================
+ Hits 395 437 +42
Misses 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Aug 17, 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.
Part of #10 (finding 4).
Why
"Was the capture approved?" meant hand-rolling the same inspection in every integration: find the operation with
type=capture,pending=falseandqp_status_code='20000'. That's exactly where consumers make bugs — forgettingpending, comparing the code as an int, summing rejected operations, picking "the last operation" from an array whose order they don't control.What
OperationQP_STATUS_APPROVED = '20000'isApproved()—!pending && qpStatusCode === '20000'(so a pending op with a stale code, a rejection, or 3-D Secure required are allfalse)isOfType(OperationType|string)Paymentoperation(int $id): ?OperationlatestOperation(): ?Operation— highest id, regardless of array orderoperationsOfType(OperationType|string): list<Operation>hasPendingOperation(): bool— the "don't read the outcome yet" signal for async operationsauthorizedAmount()/capturedAmount()/refundedAmount()— sums of approved operations only (authorizedAmount()also countsrecurring, which is the authorization of a recurring payment)isCancelled()— an approvedcancelexistsAll additive; no existing signature changes. README gains a "Reading what happened to a payment" section (also explaining
accepted,balance, and that operation ids are per-payment sequence numbers → a good callback idempotency key).Tests: unit tests on hand-built payments (approved/pending/rejected mixes, unordered operations, missing amounts, no operations) plus assertions on the mapped
payment.jsonfixture.