Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ source of truth for the flag.

The custom `src/Model/*` classes are gone — responses are the SDK's readonly DTOs (`Response\Payment\
{Payment,Operation,Link}`) plus the `PaymentState`/`OperationType` enums. The behavior that used to live
on those models now lives in the stateless `Operations` helper over a `list<Operation>`: `latest()`,
`isApproved()` (status code `20000`), `isApprovedOfType()`, `isLatestApproved()`, `latestApproved()`,
`hasApproved()`, `hasPending()`, `authorizedAmount()`. `StatusAction` (last *approved* operation, so a
trailing rejected/pending attempt does not mask what happened) and the `Authorize`/`Capture` entry-point
decisions are driven by these helpers plus the SDK enums.
on those models now lives in the stateless `Operations` helper over a `list<Operation>`:
`isApproved()` (status code `20000`), `isApprovedOfType()`, `latestApproved()`, `latestOfType()`,
`hasApproved()`, `hasPending()`. `StatusAction` (last *approved* operation, so a trailing
rejected/pending attempt does not mask what happened), the `Authorize`/`Capture` entry-point decisions
and the declined-operation check are driven by these helpers plus the SDK enums. Every helper has a
caller in `src/`; the ones that lost theirs along the way (`latest()`, `isLatestApproved()`,
`authorizedAmount()`) were dropped before 2.0 rather than kept as accidental public API.

## End-to-end harness (`examples/e2e/`)

Expand Down
36 changes: 0 additions & 36 deletions src/Operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ private function __construct()
{
}

/**
* @param list<Operation> $operations
*/
public static function latest(array $operations): ?Operation
{
if ([] === $operations) {
return null;
}

return $operations[array_key_last($operations)];
}

/**
* The most recent approved operation, or null if nothing has been approved (yet).
*
Expand Down Expand Up @@ -122,28 +110,4 @@ public static function isApprovedOfType(?Operation $operation, OperationType $ty
{
return null !== $operation && $type === $operation->type() && self::isApproved($operation);
}

/**
* @param list<Operation> $operations
*/
public static function isLatestApproved(array $operations, OperationType $type): bool
{
return self::isApprovedOfType(self::latest($operations), $type);
}

/**
* The amount of the most recent approved authorize operation, or 0 if there is none.
*
* @param list<Operation> $operations
*/
public static function authorizedAmount(array $operations): int
{
foreach (array_reverse($operations) as $operation) {
if (OperationType::Authorize === $operation->type() && self::isApproved($operation)) {
return (int) $operation->amount;
}
}

return 0;
}
}
50 changes: 0 additions & 50 deletions tests/OperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@

class OperationsTest extends TestCase
{
#[Test]
public function latestReturnsNullForNoOperations(): void
{
self::assertNull(Operations::latest([]));
}

#[Test]
public function latestReturnsTheLastOperation(): void
{
$first = $this->operation(1, OperationType::Authorize);
$last = $this->operation(2, OperationType::Capture);

self::assertSame($last, Operations::latest([$first, $last]));
}

#[Test]
public function latestApprovedSkipsTrailingRejectedAndPendingOperations(): void
{
Expand Down Expand Up @@ -128,41 +113,6 @@ public function isApprovedOfTypeChecksBothTypeAndApproval(): void
self::assertFalse(Operations::isApprovedOfType(null, OperationType::Capture));
}

#[Test]
public function isLatestApprovedLooksAtTheLastOperation(): void
{
$operations = [
$this->operation(1, OperationType::Authorize, '20000'),
$this->operation(2, OperationType::Capture, '20000'),
];

self::assertTrue(Operations::isLatestApproved($operations, OperationType::Capture));
self::assertFalse(Operations::isLatestApproved($operations, OperationType::Authorize));
self::assertFalse(Operations::isLatestApproved([], OperationType::Capture));
}

#[Test]
public function authorizedAmountReturnsTheMostRecentApprovedAuthorizeAmount(): void
{
$operations = [
$this->operation(1, OperationType::Authorize, '20000', 50),
$this->operation(2, OperationType::Authorize, '20000', 100),
$this->operation(3, OperationType::Capture, '20000', 100),
];

self::assertSame(100, Operations::authorizedAmount($operations));
}

#[Test]
public function authorizedAmountIsZeroWithoutAnApprovedAuthorize(): void
{
self::assertSame(0, Operations::authorizedAmount([]));
self::assertSame(0, Operations::authorizedAmount([
$this->operation(1, OperationType::Authorize, '40000', 100),
$this->operation(2, OperationType::Capture, '20000', 100),
]));
}

private function operation(int $id, OperationType $type, ?string $qpStatusCode = '20000', int $amount = 100): Operation
{
return new Operation(
Expand Down
Loading