From d51590b6eeecffec69607392722fb12ce8b30aef Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 1 Oct 2026 10:13:58 -0300 Subject: [PATCH 1/2] Simplify payment cron --- .../controllers/FrmTransLiteAppController.php | 99 ++----------------- 1 file changed, 7 insertions(+), 92 deletions(-) diff --git a/stripe/controllers/FrmTransLiteAppController.php b/stripe/controllers/FrmTransLiteAppController.php index 87c04bc590..4368ee46cb 100755 --- a/stripe/controllers/FrmTransLiteAppController.php +++ b/stripe/controllers/FrmTransLiteAppController.php @@ -81,110 +81,25 @@ public static function run_payment_cron() { FrmTransLiteLog::log_message( 'Overdue Subscription Cron Message', count( $overdue_subscriptions ) . ' subscriptions found to be processed.', false ); foreach ( $overdue_subscriptions as $sub ) { + if ( $sub->status !== 'future_cancel' ) { + continue; + } + $last_payment = $frm_payment->get_one_by( $sub->id, 'sub_id' ); if ( ! $last_payment ) { continue; } - $log_message = 'Subscription #' . $sub->id . ': '; - - if ( $sub->status === 'future_cancel' ) { - FrmTransLiteSubscriptionsController::change_subscription_status( - array( - 'status' => 'canceled', - 'sub' => $sub, - ) - ); - - $status = 'failed'; - $log_message .= 'Failed triggers run on canceled subscription. '; - } else { - // Get the most recent payment after the gateway has a chance to create one. - $check_payment = $frm_payment->get_one_by( $sub->id, 'sub_id' ); - $new_payment = (int) $check_payment->id !== (int) $last_payment->id; - $last_payment = $check_payment; - $status = 'no'; - - if ( ! $last_payment ) { - $log_message .= 'No payments found for subscription #' . $sub->id . '. '; - self::add_one_fail( $sub ); - } elseif ( $new_payment ) { - $status = $last_payment->status; - self::update_sub_for_new_payment( $sub, $last_payment ); - } elseif ( $last_payment->expire_date < gmdate( 'Y-m-d' ) ) { - // The payment has expired, and no new payment was made. - $status = 'failed'; - self::add_one_fail( $sub ); - } else { - // Don't run any triggers. - $last_payment = false; - } - - $log_message .= $status . ' triggers run '; - - if ( $last_payment ) { - $log_message .= 'on payment #' . $last_payment->id; - } - }//end if - - FrmTransLiteLog::log_message( 'Overdue Subscription Cron Message', $log_message ); - - self::maybe_trigger_changes( - array( - 'status' => $status, - 'payment' => $last_payment, - ) - ); - - unset( $sub ); - }//end foreach - } - - /** - * @param object $sub - * @param object $last_payment - * - * @return void - */ - private static function update_sub_for_new_payment( $sub, $last_payment ) { - $frm_sub = new FrmTransLiteSubscription(); - - if ( $last_payment->status === 'complete' ) { - $frm_sub->update( - $sub->id, - array( - 'fail_count' => 0, - 'next_bill_date' => $last_payment->expire_date, - ) - ); - } elseif ( $last_payment->status === 'failed' ) { - self::add_one_fail( $sub ); - } - } - - /** - * Add to the fail count. - * If the subscription has failed > 3 times, set it to canceled. - * - * @param object $sub - * - * @return void - */ - private static function add_one_fail( $sub ) { - $frm_sub = new FrmTransLiteSubscription(); - $fail_count = $sub->fail_count + 1; - $new_values = compact( 'fail_count' ); - $frm_sub->update( $sub->id, $new_values ); - - if ( $fail_count > 3 ) { FrmTransLiteSubscriptionsController::change_subscription_status( array( 'status' => 'canceled', 'sub' => $sub, ) ); - } + + unset( $sub ); + }//end foreach } /** From 9bb36a21967a3da3f57eadd9ab675ccefd412a02 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 1 Oct 2026 10:25:23 -0300 Subject: [PATCH 2/2] Remove another unused function --- stripe/controllers/FrmTransLiteAppController.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/stripe/controllers/FrmTransLiteAppController.php b/stripe/controllers/FrmTransLiteAppController.php index 4368ee46cb..172c5d1ec0 100755 --- a/stripe/controllers/FrmTransLiteAppController.php +++ b/stripe/controllers/FrmTransLiteAppController.php @@ -102,17 +102,6 @@ public static function run_payment_cron() { }//end foreach } - /** - * @param array $atts - * - * @return void - */ - private static function maybe_trigger_changes( $atts ) { - if ( $atts['payment'] ) { - FrmTransLiteActionsController::trigger_payment_status_change( $atts ); - } - } - /** * This is called when the Payments submodule is active. * It ensures that the hidden repeater cadence input exists even when another add-on is handling the settings.