From 0739c6183ed68f326c316d6cc01b9c2d4e536a48 Mon Sep 17 00:00:00 2001 From: Erawat Chamanont Date: Fri, 13 Nov 2026 20:04:18 +0000 Subject: [PATCH] MAE-1373: Add a test that pay-later instalments are selected for charging Membership payment plan instalments are pay later (invoices). Cover that the instalment charge selection picks up a due pay-later contribution and dispatches it, alongside the existing Pending and Partially paid cases. --- .../Service/InstalmentChargeServiceTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/phpunit/Civi/Paymentprocessingcore/Service/InstalmentChargeServiceTest.php b/tests/phpunit/Civi/Paymentprocessingcore/Service/InstalmentChargeServiceTest.php index c011e62..0c4cdef 100644 --- a/tests/phpunit/Civi/Paymentprocessingcore/Service/InstalmentChargeServiceTest.php +++ b/tests/phpunit/Civi/Paymentprocessingcore/Service/InstalmentChargeServiceTest.php @@ -85,6 +85,26 @@ public function testSelectsPendingContributions(): void { $this->assertCount(1, $this->capturedEvents); } + /** + * Tests that pay-later contributions are selected. + * + * Membership payment plan instalments are pay later (invoices), and must be + * charged like any other due instalment. + */ + public function testSelectsPayLaterContributions(): void { + $fixtures = $this->createTestFixtures([ + 'contribution_status' => 'Pending', + 'receive_date' => date('Y-m-d', strtotime('-1 day')), + 'is_pay_later' => TRUE, + ]); + + $result = $this->service->chargeInstalments([self::PROCESSOR_TYPE], 500, 3); + + $this->assertEquals(1, $result['charged']); + $this->assertCount(1, $this->capturedEvents); + $this->assertArrayHasKey((int) $fixtures['contribution_id'], $this->capturedEvents[0]->getItems()); + } + /** * Tests that Partially paid contributions are selected. */ @@ -641,6 +661,7 @@ private function createTestFixtures(array $options = []): array { 'receive_date' => $options['receive_date'] ?? date('Y-m-d'), 'total_amount' => $totalAmount, 'currency' => $options['currency'] ?? 'GBP', + 'is_pay_later' => $options['is_pay_later'] ?? FALSE, ]); // Note: paid_amount is a computed field, not a real column.