-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutes.php
More file actions
183 lines (153 loc) · 8.74 KB
/
routes.php
File metadata and controls
183 lines (153 loc) · 8.74 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
declare(strict_types=1);
use Los\RateLimit\RateLimitMiddleware;
use MatchBot\Application\Actions\DeletePaymentMethod;
use MatchBot\Application\Actions\DonorAccount\ReturnAllDonationFunds;
use MatchBot\Application\Actions\Sitemap;
use MatchBot\Application\Actions\UpdatePaymentMethod;
use MatchBot\Application\Actions\Donations;
use MatchBot\Application\Actions\DonorAccount;
use MatchBot\Application\Actions\GetPaymentMethods;
use MatchBot\Application\Actions\Hooks;
use MatchBot\Application\Actions\Status;
use MatchBot\Application\Auth\DonationPublicAuthMiddleware;
use MatchBot\Application\Auth\PersonManagementAuthMiddleware;
use MatchBot\Application\Auth\PersonWithPasswordAuthMiddleware;
use MatchBot\Application\Auth\SalesforceAuthMiddleware;
use MatchBot\Application\CacheableResponseMiddleware;
use Middlewares\ClientIp;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\App;
use Slim\Exception\HttpNotFoundException;
use Slim\Routing\RouteCollectorProxy;
use MatchBot\Application\Actions\RegularGivingMandate;
return function (App $app) {
$app->get('/ping', Status::class);
$app->get('/sitemap', Sitemap::class)->add(CacheableResponseMiddleware::class);
$app->group('/v1', function (RouteCollectorProxy $versionGroup) {
// Provides real IP for e.g. rate limiter
$ipMiddleware = getenv('APP_ENV') === 'local'
? new ClientIp()
: (new ClientIp())->proxy([], ['X-Forwarded-For']);
$versionGroup->post('/people/{personId:[a-z0-9-]{36}}/donations', Donations\Create::class)
->add(PersonManagementAuthMiddleware::class)
->add($ipMiddleware)
->add(RateLimitMiddleware::class);
$versionGroup->group('/donations/{donationId:[a-z0-9-]{36}}', function (RouteCollectorProxy $group) {
$group->get('', Donations\Get::class);
$group->put('', Donations\Update::class); // Includes cancelling.
$group->post('/confirm', Donations\Confirm::class);
$group->post('/remove-matching-expectation', Donations\RemoveMatchingExpecation::class);
})
->add(DonationPublicAuthMiddleware::class);
$versionGroup->get('/donations/{donationId:[a-z0-9-]{36}}/explain', Donations\Explain::class)
->add(SalesforceAuthMiddleware::class);
$versionGroup->post(
'/donations/{donationId:[a-z0-9-]{36}}/send-donor-thanks-email',
Donations\ResendDonorThanksNotification::class
)->add(SalesforceAuthMiddleware::class);
$versionGroup->post(
'/donations/{donationId:[a-z0-9-]{36}}/remove-gift-aid-declaration',
Donations\RemoveGiftAidDeclaration::class
)->add(SalesforceAuthMiddleware::class);
$versionGroup->get(
'/campaigns/{salesforceId:[a-zA-Z0-9]{18}}',
\MatchBot\Application\Actions\Campaigns\Get::class
)->add(CacheableResponseMiddleware::class);
// preview of a campaign intended for use only by the person at the charity who is in the process of
// editing the campaign and wants to check their work - not intended for public use although not
// currently restricted.
$versionGroup->get(
'/campaigns/early-preview/{salesforceId:[a-zA-Z0-9]{18}}',
\MatchBot\Application\Actions\Campaigns\GetEarlyPreview::class
);
$versionGroup->get(
'/meta-campaigns/{slug:[a-zA-Z0-9-]{2,100}}',
\MatchBot\Application\Actions\MetaCampaigns\Get::class,
)->add(CacheableResponseMiddleware::class);
$versionGroup->put(
'/charities/{salesforceId:[a-zA-Z0-9]{18}}',
\MatchBot\Application\Actions\Charities\Put::class
)->add(SalesforceAuthMiddleware::class);
$versionGroup->post(
'/campaigns/upsert-many',
\MatchBot\Application\Actions\Campaigns\UpsertMany::class
)->add(SalesforceAuthMiddleware::class);
$versionGroup->post(
'/charities/upsert-many',
\MatchBot\Application\Actions\Charities\UpsertMany::class
)->add(SalesforceAuthMiddleware::class);
$versionGroup->get(
'/charities/{charitySalesforceId:[a-zA-Z0-9]{18}}/campaigns',
\MatchBot\Application\Actions\Campaigns\GetSummariesForCharity::class
)->add(CacheableResponseMiddleware::class);
$versionGroup->get('/campaigns', \MatchBot\Application\Actions\Campaigns\Search::class)
->add(CacheableResponseMiddleware::class);
$versionGroup->post('/mailing-list-signup', \MatchBot\Application\Actions\MailingListSignup::class)
->add(\MatchBot\Application\Auth\CaptchaMiddleware::class);
/**
* Cancel *all* pending donations for the current Donor with the specified query param criteria,
* currently taking one campaign ID and most useful for Donation Funds tips.
*/
$versionGroup->delete('/donations', Donations\CancelAll::class)
->add(PersonManagementAuthMiddleware::class)
->add($ipMiddleware)
->add(RateLimitMiddleware::class);
$versionGroup->group('/people/{personId:[a-z0-9-]{36}}', function (RouteCollectorProxy $pwdDonorGroup) {
/** @psalm-suppress DeprecatedClass Until we delete Donate use & the endpoint */
$pwdDonorGroup->post('/donor-account', DonorAccount\Create::class);
$pwdDonorGroup->get('/donor-account', DonorAccount\Get::class);
$pwdDonorGroup->post('/donor-account/withdraw-funds', ReturnAllDonationFunds::class);
$pwdDonorGroup->post('/create-customer-session', RegularGivingMandate\CreateCustomerSession::class);
$pwdDonorGroup->post('/regular-giving', RegularGivingMandate\Create::class);
$pwdDonorGroup->put('/regular-giving/payment-method', RegularGivingMandate\UpdatePaymentMethod::class);
$pwdDonorGroup->delete('/regular-giving/payment-method', RegularGivingMandate\RemovePaymentMethod::class);
$pwdDonorGroup->get('/donations', Donations\GetAllForUser::class);
$pwdDonorGroup->delete('/donations', Donations\CancelAll::class);
$pwdDonorGroup->post('/create-setup-intent', RegularGivingMandate\CreateSetupIntent::class);
$pwdDonorGroup->group('/payment_methods', function (RouteCollectorProxy $paymentMethodsGroup) {
$paymentMethodUriSuffixPattern = '/{payment_method_id:[a-zA-Z0-9_]{10,50}}';
$paymentMethodsGroup->get('', GetPaymentMethods::class);
$paymentMethodsGroup->delete($paymentMethodUriSuffixPattern, DeletePaymentMethod::class);
$paymentMethodsGroup->put("$paymentMethodUriSuffixPattern/billing_details", UpdatePaymentMethod::class);
});
})
->add(PersonWithPasswordAuthMiddleware::class) // Runs last
->add($ipMiddleware)
->add(RateLimitMiddleware::class);
// TODO Discuss moving this to e.g. /people/{personId}/mandates for consistency & easier understanding
// of the available endpoints.
$versionGroup->get('/regular-giving/my-donation-mandates', RegularGivingMandate\GetAllForUser::class)
->add(PersonWithPasswordAuthMiddleware::class)
->add($ipMiddleware)
->add(RateLimitMiddleware::class);
$versionGroup->get('/regular-giving/my-donation-mandates/{mandateId:[a-z0-9-]{36}}', RegularGivingMandate\Get::class)
->add(PersonWithPasswordAuthMiddleware::class)
->add($ipMiddleware)
->add(RateLimitMiddleware::class);
$versionGroup->post('/regular-giving/my-donation-mandates/{mandateId:[a-z0-9-]{36}}/cancel', RegularGivingMandate\Cancel::class)
->add(PersonWithPasswordAuthMiddleware::class)
->add($ipMiddleware)
->add(RateLimitMiddleware::class);
$versionGroup->get(
'/test-donation-collection-for-date/{date}',
\MatchBot\Application\Actions\CollectRegularGivingForTest::class
);
$versionGroup->post('/regular-giving/mandate/{mandateId:[a-z0-9-]{36}}/cancel', RegularGivingMandate\CancelAsAdmin::class)
->add(SalesforceAuthMiddleware::class);
});
// Authenticated through Stripe's SDK signature verification
$app->post('/hooks/stripe', Hooks\StripePaymentsUpdate::class);
$app->post('/hooks/stripe-connect', Hooks\StripePayoutUpdate::class);
$app->options(
'/{routes:.+}',
fn (RequestInterface $_req, ResponseInterface $resp, array $_args): ResponseInterface => $resp
);
$app->map(
['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
'/{routes:.+}',
fn (ServerRequestInterface $req, ResponseInterface $_resp) => throw new HttpNotFoundException($req)
);
};