Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SetDefaultPaymentMethodAction
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Action\Investor;
6
7use App\Domain\Stripe\Service\InvestorStripeService;
8use App\Renderer\JsonRenderer;
9use App\Support\Row;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12
13/**
14 * PATCH /api/investor/payment-methods/{paymentMethodId}/default
15 *
16 * Mark the given PaymentMethod as the default for off-session charges
17 * (loan payments). Ownership of the PM is verified before mutating
18 * Stripe — see InvestorStripeService.
19 */
20final readonly class SetDefaultPaymentMethodAction
21{
22    public function __construct(
23        private InvestorStripeService $service,
24        private JsonRenderer $renderer,
25    ) {}
26
27    /**
28     * @param array<string, string> $args
29     * @param ServerRequestInterface $request
30     * @param ResponseInterface $response
31     */
32    public function __invoke(
33        ServerRequestInterface $request,
34        ResponseInterface $response,
35        array $args,
36    ): ResponseInterface {
37        $investorId = Row::int($request->getAttributes(), 'investorId');
38        $paymentMethodId = Row::string($args, 'paymentMethodId');
39
40        $this->service->setDefaultPaymentMethod($investorId, $paymentMethodId);
41
42        return $this->renderer->json($response, [
43            'success' => true,
44            'message' => 'Default payment method updated',
45        ]);
46    }
47}