From 01513c508a121e95e702dfb75e806ba924c6752f Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:11:51 -0600 Subject: [PATCH 1/3] Add tests for payment passed to trigger_payment_status_change --- .../test_FrmTransLiteActionsController.php | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tests/phpunit/stripe/test_FrmTransLiteActionsController.php b/tests/phpunit/stripe/test_FrmTransLiteActionsController.php index 3ab0047edf..b61846791b 100644 --- a/tests/phpunit/stripe/test_FrmTransLiteActionsController.php +++ b/tests/phpunit/stripe/test_FrmTransLiteActionsController.php @@ -70,6 +70,94 @@ public function test_maybe_use_decimal() { $this->assertSame( '111.500', $amount ); } + /** + * @covers FrmTransLiteActionsController::trigger_payment_status_change + */ + public function test_trigger_payment_status_change_keeps_passed_payment() { + $entry = $this->create_entry_with_payments( array( 'complete', 'pending' ) ); + $older_id = $entry['payment_ids'][0]; + $older = ( new FrmTransLitePayment() )->get_one( $older_id ); + + $atts = $this->trigger_payment_status_change( + array( + 'status' => 'refunded', + 'payment' => $older, + ) + ); + + $this->assertNotNull( $atts ); + $this->assertEquals( $older_id, $atts['payment']->id ); + $this->assertEquals( $entry['id'], $atts['entry_id'] ); + } + + /** + * @covers FrmTransLiteActionsController::trigger_payment_status_change + */ + public function test_trigger_payment_status_change_loads_payment_for_entry() { + $entry = $this->create_entry_with_payments( array( 'complete' ) ); + + $atts = $this->trigger_payment_status_change( + array( + 'status' => 'refunded', + 'entry' => (object) array( 'id' => $entry['id'] ), + ) + ); + + $this->assertNotNull( $atts ); + $this->assertEquals( $entry['payment_ids'][0], $atts['payment']->id ); + } + + /** + * @param array $atts + * + * @return array|null The atts passed to the frm_payment_status_refunded hook. + */ + private function trigger_payment_status_change( $atts ) { + $received = null; + $callback = function ( $hook_atts ) use ( &$received ) { + $received = $hook_atts; + }; + + add_action( 'frm_payment_status_refunded', $callback ); + FrmTransLiteActionsController::trigger_payment_status_change( $atts ); + remove_action( 'frm_payment_status_refunded', $callback ); + + return $received; + } + + /** + * @param string[] $statuses One payment is created per status, oldest first. + * + * @return array{id: int, payment_ids: int[]} + */ + private function create_entry_with_payments( $statuses ) { + ( new FrmTransLiteDb() )->upgrade(); + + $form = $this->factory->form->create_and_get(); + $entry = $this->factory->entry->create_and_get( $this->factory->field->generate_entry_array( $form ) ); + $frm_payment = new FrmTransLitePayment(); + $payment_ids = array(); + + foreach ( $statuses as $index => $status ) { + $payment_ids[] = $frm_payment->create( + array( + 'item_id' => $entry->id, + 'action_id' => 1, + 'amount' => '10.00', + 'paysys' => 'stripe', + 'receipt_id' => 'pi_test_' . $index, + 'status' => $status, + 'created_at' => gmdate( 'Y-m-d H:i:s', strtotime( '+' . $index . ' day' ) ), + ) + ); + } + + return array( + 'id' => $entry->id, + 'payment_ids' => $payment_ids, + ); + } + /** * @param string $amount * @param array $currency From d0fd2db57ba5141486bd542de0fffb887a4ad1f3 Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:12:42 -0600 Subject: [PATCH 2/3] Keep the passed payment in trigger_payment_status_change --- stripe/controllers/FrmTransLiteActionsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/stripe/controllers/FrmTransLiteActionsController.php b/stripe/controllers/FrmTransLiteActionsController.php index ad2d4355ee..123be0f6ad 100755 --- a/stripe/controllers/FrmTransLiteActionsController.php +++ b/stripe/controllers/FrmTransLiteActionsController.php @@ -220,6 +220,7 @@ public static function trigger_payment_status_change( $atts ) { $atts = array( 'trigger' => $atts['status'], 'entry_id' => $entry_id, + 'payment' => isset( $atts['payment'] ) ? $atts['payment'] : null, ); if ( ! isset( $atts['payment'] ) ) { From a934dc415193c4cc23ff107787d38626de275b68 Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:14:46 -0600 Subject: [PATCH 3/3] Use null coalescing for the passed payment --- stripe/controllers/FrmTransLiteActionsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stripe/controllers/FrmTransLiteActionsController.php b/stripe/controllers/FrmTransLiteActionsController.php index 123be0f6ad..7d55d73e8b 100755 --- a/stripe/controllers/FrmTransLiteActionsController.php +++ b/stripe/controllers/FrmTransLiteActionsController.php @@ -220,7 +220,7 @@ public static function trigger_payment_status_change( $atts ) { $atts = array( 'trigger' => $atts['status'], 'entry_id' => $entry_id, - 'payment' => isset( $atts['payment'] ) ? $atts['payment'] : null, + 'payment' => $atts['payment'] ?? null, ); if ( ! isset( $atts['payment'] ) ) {