Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DetachPaymentMethodAction | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
7 / 7 |
|
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\Service\InvestorStripeService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use App\Support\Row; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | |
| 13 | /** |
| 14 | * DELETE /api/investor/payment-methods/{paymentMethodId} |
| 15 | * |
| 16 | * Detach a PaymentMethod from the requesting investor's Stripe Customer. |
| 17 | * Ownership of the PM is verified first — see InvestorStripeService. |
| 18 | */ |
| 19 | final readonly class DetachPaymentMethodAction |
| 20 | { |
| 21 | public function __construct( |
| 22 | private InvestorStripeService $service, |
| 23 | private JsonRenderer $renderer, |
| 24 | ) {} |
| 25 | |
| 26 | /** |
| 27 | * @param array<string, string> $args |
| 28 | * @param ServerRequestInterface $request |
| 29 | * @param ResponseInterface $response |
| 30 | */ |
| 31 | public function __invoke( |
| 32 | ServerRequestInterface $request, |
| 33 | ResponseInterface $response, |
| 34 | array $args, |
| 35 | ): ResponseInterface { |
| 36 | $investorId = Row::int($request->getAttributes(), 'investorId'); |
| 37 | $paymentMethodId = Row::string($args, 'paymentMethodId'); |
| 38 | |
| 39 | $this->service->detachPaymentMethod($investorId, $paymentMethodId); |
| 40 | |
| 41 | return $this->renderer->json($response, [ |
| 42 | 'success' => true, |
| 43 | 'message' => 'Payment method removed', |
| 44 | ]); |
| 45 | } |
| 46 | } |