Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DON-998: set PI just before processing the payment instead of at the #1151

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
06ace14
DON-998: set PI just before processing the payment instead of at the
Dec 24, 2024
1255811
Merge branch 'develop' into DON-998-2nd-3rd-donation-PI-rework
dorota-joanna Dec 27, 2024
e4140fd
DON-998 - separate function to find donations PI ready
Dec 27, 2024
9850962
DON-998 - fix psalm errors
Dec 27, 2024
7adff46
DON-998 - WIP: record unsuccessful payment attempts to limit number o…
Dec 27, 2024
4bbd055
DON-998 - extract limit as class variable
Dec 27, 2024
a78a574
DON-998 - unify datetime format
Dec 30, 2024
c191a9e
DON-998 - WIP, when running, the EM closes at ln 55
Dec 31, 2024
7c8f775
DON-998 - fix for the EM closing at 55
Jan 2, 2025
9c2a5fe
DON-998 - lint fix
Jan 2, 2025
6fdb9ca
MAT-379 – first pass handling Person upsert messages from Identity
NoelLH Dec 27, 2024
ffeb5e2
MAT-379 – check in missed psalm suppress
NoelLH Dec 27, 2024
15829b6
MAT-379 – fix weird DI loop similar to the CharityUpdated one we alre…
NoelLH Dec 28, 2024
a8fc155
MAT-379: Run matchbot consumer automatically in dev environment
bdsl Jan 2, 2025
b9671ab
DON-998 - create test campaign and attach to donation
Jan 2, 2025
78aa7be
DON-998 - fix EM query by assigning to value rather than dayOfMonth
Jan 2, 2025
093da3b
DON-998 - fix psalm and new integration test passing
Jan 2, 2025
805e582
DON-998 - fix psalm:
Jan 2, 2025
913327a
DON-998 - fix psalm:
Jan 2, 2025
06be75c
DON-998 - make batch limit a constant
Jan 3, 2025
f8f1ad7
DON-998 - rename limit
Jan 3, 2025
ea92c8a
DON-998 - additional query constraints
Jan 3, 2025
b15db8b
DON-998 - rename test file
Jan 3, 2025
e0d9009
DON-998 - remove unused code
Jan 3, 2025
6fd57be
DON-998 - use fixed date time in test
Jan 3, 2025
90df036
DON-998 - fix date format and remove unused variable
Jan 3, 2025
f986891
DON-998 - fix null error in test query
Jan 3, 2025
c02ea38
DON-998 - fix test: allow finding donations with preAuth date exactly…
Jan 3, 2025
7cfaa89
Merge branch 'develop' into DON-998-2nd-3rd-donation-PI-rework
dorota-joanna Jan 3, 2025
da7ac4f
DON-998 - split test - wip
Jan 3, 2025
76c0afe
DON-998 - conditionally activate mandate in test setup
Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Application/Commands/TakeRegularGivingDonations.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
$now = $this->container->get(\DateTimeImmutable::class);

$this->createNewDonationsAccordingToRegularGivingMandates($now, $io);
$this->setPaymentIntentWhenReachedPaymentDate($now, $io);

Check warning on line 85 in src/Application/Commands/TakeRegularGivingDonations.php

View check run for this annotation

Codecov / codecov/patch

src/Application/Commands/TakeRegularGivingDonations.php#L85

Added line #L85 was not covered by tests
$this->confirmPreCreatedDonationsThatHaveReachedPaymentDate($now, $io);

return 0;
Expand All @@ -101,6 +102,19 @@
}
}

private function setPaymentIntentWhenReachedPaymentDate(

Check warning on line 105 in src/Application/Commands/TakeRegularGivingDonations.php

View check run for this annotation

Codecov / codecov/patch

src/Application/Commands/TakeRegularGivingDonations.php#L105

Added line #L105 was not covered by tests
\DateTimeImmutable $now,
SymfonyStyle $io
): void {
$donations = $this->donationRepository->findDonationsToSetPaymentIntent($now, limit:20);
dorota-joanna marked this conversation as resolved.
Show resolved Hide resolved
$io->block(count($donations) . " donations are due to have Payment Intent set at this time");

Check warning on line 110 in src/Application/Commands/TakeRegularGivingDonations.php

View check run for this annotation

Codecov / codecov/patch

src/Application/Commands/TakeRegularGivingDonations.php#L109-L110

Added lines #L109 - L110 were not covered by tests

foreach ($donations as $donation) {
$this->donationService->createPaymentIntent($donation);
$io->writeln("setting payment intent on donation #{$donation->getId()}");

Check warning on line 114 in src/Application/Commands/TakeRegularGivingDonations.php

View check run for this annotation

Codecov / codecov/patch

src/Application/Commands/TakeRegularGivingDonations.php#L112-L114

Added lines #L112 - L114 were not covered by tests
}
}

private function confirmPreCreatedDonationsThatHaveReachedPaymentDate(
\DateTimeImmutable $now,
SymfonyStyle $io
Expand Down
27 changes: 27 additions & 0 deletions src/Domain/DoctrineDonationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,33 @@
return $result;
}

/**
* We only set Payment Intent on the day of the payment due to stripe limitations, see
*/
public function findDonationsToSetPaymentIntent(\DateTimeImmutable $atDateTime, int $limit): array

Check warning on line 747 in src/Domain/DoctrineDonationRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Domain/DoctrineDonationRepository.php#L747

Added line #L747 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have no test coverage – would be a good fit for an integration test?

{
$preAuthorized = DonationStatus::PreAuthorized->value;
$active = MandateStatus::Active->value;
$currentDateTime = new \DateTimeImmutable('now');
dorota-joanna marked this conversation as resolved.
Show resolved Hide resolved
$dayOfMonthToday = $currentDateTime->format('d');

Check warning on line 752 in src/Domain/DoctrineDonationRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Domain/DoctrineDonationRepository.php#L749-L752

Added lines #L749 - L752 were not covered by tests

$query = $this->getEntityManager()->createQuery(<<<DQL
SELECT donation from Matchbot\Domain\Donation donation JOIN donation.mandate mandate
WHERE donation.donationStatus = '$preAuthorized'
AND mandate.status = '$active'
AND mandate.dayOfMonth = '$dayOfMonthToday'

Check warning on line 758 in src/Domain/DoctrineDonationRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Domain/DoctrineDonationRepository.php#L754-L758

Added lines #L754 - L758 were not covered by tests
AND donation.preAuthorizationDate <= :now
DQL
dorota-joanna marked this conversation as resolved.
Show resolved Hide resolved
);

Check warning on line 761 in src/Domain/DoctrineDonationRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Domain/DoctrineDonationRepository.php#L760-L761

Added lines #L760 - L761 were not covered by tests

$query->setParameter('now', $atDateTime);
$query->setMaxResults($limit);

Check warning on line 764 in src/Domain/DoctrineDonationRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Domain/DoctrineDonationRepository.php#L763-L764

Added lines #L763 - L764 were not covered by tests

/** @var list<Donation> $result */
$result = $query->getResult();
return $result;

Check warning on line 768 in src/Domain/DoctrineDonationRepository.php

View check run for this annotation

Codecov / codecov/patch

src/Domain/DoctrineDonationRepository.php#L767-L768

Added lines #L767 - L768 were not covered by tests
}

public function findPreAuthorizedDonationsReadyToConfirm(\DateTimeImmutable $atDateTime, int $limit): array
{
$preAuthorized = DonationStatus::PreAuthorized->value;
Expand Down
5 changes: 5 additions & 0 deletions src/Domain/DonationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public function pushSalesforcePending(\DateTimeImmutable $now, MessageBusInterfa
*/
public function findAllCompleteForCustomer(StripeCustomerId $stripeCustomerId): array;

/**
* @return list<Donation>
*/
public function findDonationsToSetPaymentIntent(\DateTimeImmutable $atDateTime, int $limit): array;

/**
* @return list<Donation>
*/
Expand Down
1 change: 0 additions & 1 deletion src/Domain/RegularGivingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public function makeNextDonationForMandate(RegularGivingMandate $mandate): ?Dona
return null;
}

$this->donationService->createPaymentIntent($donation);
$mandate->setDonationsCreatedUpTo($preAuthorizationDate);

return $donation;
Expand Down
5 changes: 5 additions & 0 deletions tests/Domain/InMemoryDonationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ public function totalMatchFundsReleased(): string
throw new \Exception("Method not implemented in test double");
}

#[\Override] public function findDonationsToSetPaymentIntent(\DateTimeImmutable $atDateTime, int $limit): array
{
throw new \Exception("Method not implemented in test double");
}

#[\Override] public function maxSequenceNumberForMandate(int $mandateId): ?DonationSequenceNumber
{
throw new \Exception("Method not implemented in test double");
Expand Down