Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ListPaymentMethodsAction | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\Investor; |
| 6 | |
| 7 | use App\Domain\Stripe\Data\PaymentMethodData; |
| 8 | use App\Domain\Stripe\Service\InvestorStripeService; |
| 9 | use App\Renderer\JsonRenderer; |
| 10 | use App\Support\Row; |
| 11 | use Psr\Http\Message\ResponseInterface; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | /** |
| 15 | * GET /api/investor/payment-methods |
| 16 | * |
| 17 | * Returns the card-type PaymentMethods attached to the requesting |
| 18 | * investor's Stripe Customer. Returns an empty list when the investor has |
| 19 | * no Customer yet (lazy creation defers to first SetupIntent). |
| 20 | */ |
| 21 | final readonly class ListPaymentMethodsAction |
| 22 | { |
| 23 | public function __construct( |
| 24 | private InvestorStripeService $service, |
| 25 | private JsonRenderer $renderer, |
| 26 | ) {} |
| 27 | |
| 28 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 29 | { |
| 30 | $investorId = Row::int($request->getAttributes(), 'investorId'); |
| 31 | |
| 32 | $methods = $this->service->listPaymentMethods($investorId); |
| 33 | |
| 34 | $data = array_map( |
| 35 | static fn(PaymentMethodData $pm): array => [ |
| 36 | 'id' => $pm->id, |
| 37 | 'brand' => $pm->brand, |
| 38 | 'last4' => $pm->last4, |
| 39 | 'expMonth' => $pm->expMonth, |
| 40 | 'expYear' => $pm->expYear, |
| 41 | 'isDefault' => $pm->isDefault, |
| 42 | ], |
| 43 | $methods, |
| 44 | ); |
| 45 | |
| 46 | return $this->renderer->json($response, [ |
| 47 | 'success' => true, |
| 48 | 'data' => ['paymentMethods' => $data], |
| 49 | ]); |
| 50 | } |
| 51 | } |