-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDonationRepository.php
More file actions
198 lines (166 loc) · 7.35 KB
/
DonationRepository.php
File metadata and controls
198 lines (166 loc) · 7.35 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
namespace MatchBot\Domain;
use DateTime;
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
use MatchBot\Application\Commands\ExpirePendingMandates;
use MatchBot\Application\Matching;
use MatchBot\Application\Messenger\DonationUpserted;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Messenger\MessageBusInterface;
/**
* Includes a subset of methods from \Doctrine\Persistence\ObjectRepository<Donation>. Not adding all methods
* to allow for easier in-memory implementation.
*/
interface DonationRepository
{
/**
* Finds incomplete donations created long enough ago to be eligible to have their match-funding removed.
*
* Excludes any donations created in relation to a regular giving mandate as those have a slightly different way
* of being matched and unmatched - {@see ExpirePendingMandates::doExecute()}
*
* @return UuidInterface[]
*/
public function findWithExpiredMatching(\DateTimeImmutable $now): array;
/**
* @return Donation[] Donations which, when considered in isolation, could have some or all of their match
* funds swapped with higher priority matching (e.g. swapping out champion funds and
* swapping in pledges). The caller shouldn't assume that *all* donations may be fully
* swapped; typically we will choose to swap earlier-collected donations first, and it may
* be that priority funds are used up before we get to the end of the list.
*/
public function findWithMatchingWhichCouldBeReplacedWithHigherPriorityAllocation(\DateTimeImmutable $campaignsClosedBefore, \DateTimeImmutable $donationsCollectedAfter,): array;
/**
* @return Donation[]
*/
public function findReadyToClaimGiftAid(bool $withResends): array;
/**
* @return Donation[]
*/
public function findNotFullyMatchedToCampaignsWhichClosedSince(DateTime $closedSinceDate): array;
/**
* @return Donation[]
*/
public function findRecentNotFullyMatchedToMatchCampaigns(DateTime $sinceDate): array;
/**
* @param string[] $transferIds
* @return Donation[]
*/
public function findWithTransferIdInArray(array $transferIds): array;
/**
* Takes a now-ish input that's typically the floor of the current minute and
* looks for donations *created* between $nowish-16 minutes and $nowish-1 minutes, with >£0 matching assigned.
* Returns:
* * if there are fewer than 20 such donations, null; or
* * if there are 20+ such donations, the ratio of those which are complete.
*/
public function getRecentHighVolumeCompletionRatio(\DateTimeImmutable $nowish): ?float;
public function countDonationsCreatedInMinuteTo(\DateTimeImmutable $end): int;
public function countDonationsCollectedInMinuteTo(\DateTimeImmutable $end): int;
/**
* Give up on pushing Cancelled donations to Salesforce after a few minutes. For example,
* this was needed after CC21 for a last minute donation that could not be persisted in
* Salesforce because the campaign close date had passed before it reached SF.
*
* @return int Number of donations updated to 'complete'.
*/
public function abandonOldCancelled(): int;
/**
* Locks row in DB to prevent concurrent updates. See jira MAT-260
* Requires an open transaction to be managed by the caller.
* @throws LockWaitTimeoutException
* @param array<string, string|null> $criteria
* @param array<string, string>|null $orderBy
*/
public function findAndLockOneBy(array $criteria, ?array $orderBy = null): ?Donation;
/**
* Re-queues proxy objects to Salesforce en masse.
*
* By using FIFO queues and deduplicating on UUID if there are multiple consumers, we should make it unlikely
* that Salesforce hits Donation record lock contention issues.
*
* @return int Number of objects pushed
*
*
*/
public function pushSalesforcePending(\DateTimeImmutable $now, MessageBusInterface $bus): int;
/**
* Finds all successful donations from the donor with the given stripe customer ID.
*
* In principle, we would probably prefer to the user ID's we've assigned to donors here
* instead of the Stripe Customer ID, so we're less tied into stripe, but we don't have those currently in
* the Donation table. Considering adding that column and writing a script to fill in on all old donations.
* @return list<Donation>
*/
public function findAllCompleteForCustomer(StripeCustomerId $stripeCustomerId): array;
/**
* @return list<Donation>
*/
public function findDonationsToSetPaymentIntent(\DateTimeImmutable $atDateTime, int $maxBatchSize): array;
/**
* @return list<Donation>
*/
public function findPreAuthorizedDonationsReadyToConfirm(\DateTimeImmutable $atDateTime, int $limit): array;
public function maxSequenceNumberForMandate(int $mandateId): ?DonationSequenceNumber;
/**
* @return list<Donation>
*/
public function findPendingAndPreAuthedForMandate(UuidInterface $mandateId): array;
/**
* @return list<Donation>
*/
public function findAllForMandate(UuidInterface $mandateId): array;
/**
* Returns a limited size list of donation fund tip donations that have been left unpaid for some time and
* we will want to auto-cancel
* @return list<UuidInterface>
*/
public function findStaleDonationFundsTips(\DateTimeImmutable $atDateTime, \DateInterval $cancelationDelay): array;
/**
* @param Salesforce18Id<Campaign> $campaignId
* @return list<UuidInterface>
*/
public function findPendingByDonorCampaignAndMethod(string $donorStripeId, Salesforce18Id $campaignId, PaymentMethodType $paymentMethodType,): array;
public function findAndLockOneByUUID(UuidInterface $donationId): ?Donation;
public function push(DonationUpserted $changeMessage): void;
/**
* @return ?Donation
* @param ?int $id
*/
public function find($id);
/**
* @param array{uuid: UuidInterface[]} $criteria
* @return list<Donation>
*/
public function findBy(array $criteria);
/**
* @phpstan-param array<string, mixed> $criteria
* @return ?Donation
*/
public function findOneBy(array $criteria);
public function findOneByUUID(UuidInterface $donationUUID): ?Donation;
/**
* @return list<Donation>
*/
public function findAllByPayoutId(string $payoutId): array;
/**
* @param Campaign $campaign
* @return non-negative-int
*/
public function countCompleteDonationsToCampaign(Campaign $campaign): int;
/**
* Finds donations with total funding withdrawals greater than amount - this would be an error as we only offer up
* to 100% matching but may be possible in some race conditions in which case we will need to patch data so we don't
* end up paying out moree than charities are entitled to.
*
* @return list<Donation>
*/
public function findOverMatchedDonations(): array;
/**
* Returns a list of donations that may have been temporarily holding funds and therefore blocking the given
* donation from being fully matched at the time it was initiated.
*
* @return list<Donation>
*/
public function potentiallyCompetingDonations(Donation $donation): array;
}