-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetDonationFundsTransferInstructions.php
79 lines (72 loc) · 2.58 KB
/
GetDonationFundsTransferInstructions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
namespace BigGive\Identity\Application\Actions;
use BigGive\Identity\Client\Stripe;
use BigGive\Identity\Domain\Person;
use BigGive\Identity\Repository\PersonRepository;
use Laminas\Diactoros\Response\JsonResponse;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpNotFoundException;
/**
* @OA\Get(
* path="/v1/people/{personId}/funding_instructions",
* @OA\PathParameter(
* name="personId",
* description="UUID of the person",
* @OA\Schema(
* type="string",
* format="uuid",
* example="f7095caf-7180-4ddf-a212-44bacde69066",
* pattern="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
* ),
* ),
* summary="Get a Person's funding instructions for donation funds top-up by bank transfer",
* operationId="funding_instructions_get",
* security={
* {"personJWT": {}}
* },
* @OA\Response(
* response=200,
* description="Funding instructions object as documented at
* https://stripe.com/docs/payments/customer-balance/funding-instructions?bt-region-tabs=uk",
* @OA\JsonContent(),
* ),
* @OA\Response(
* response=401,
* description="JWT token verification failed",
* ),
* ),
* @link https://stripe.com/docs/payments/customer-balance/funding-instructions?bt-region-tabs=uk
*/
class GetDonationFundsTransferInstructions extends Action
{
public function __construct(
LoggerInterface $logger,
private readonly PersonRepository $personRepository,
private readonly Stripe $stripeClient,
) {
parent::__construct($logger);
}
public function action(Request $request, array $args): ResponseInterface
{
$person = $this->personRepository->find($this->resolveArg($args, $request, 'personId'));
if (!$person) {
throw new HttpNotFoundException($request, 'Person not found');
}
$instructions = $this->stripeClient->customers->createFundingInstructions(
$person->stripe_customer_id,
[
'funding_type' => 'bank_transfer',
'bank_transfer' => [
// Only UK bank support for now.
'type' => 'gb_bank_transfer',
],
'currency' => $request->getQueryParams()['currency'] ?? 'gbp',
],
);
return new JsonResponse($instructions);
}
}