| @@ -44,14 +44,25 @@ | ||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * Remove the cron when the plugin is deactivated. | |
| 48 | + * Remove the payment cron when all gateways are disconnected. | |
| 49 | 49 | * |
| 50 | + * @since 6.32.1 | |
| 51 | + * | |
| 52 | + * @param string $gateway 'stripe', 'square', or 'paypal'. | |
| 53 | + * @param string $mode 'test' or 'live'. | |
| 54 | + * | |
| 50 | 55 | * @return void |
| 51 | 56 | */ |
| 52 | - public static function remove_cron() { | |
| 53 | - wp_clear_scheduled_hook( 'frm_payment_cron' ); | |
| 57 | + public static function maybe_remove_payment_cron( $gateway, $mode ) { | |
| 58 | + $stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup(); | |
| 59 | + $square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup(); | |
| 60 | + $paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup(); | |
| 61 | + | |
| 62 | + if ( ! $stripe_connected && ! $square_connected && ! $paypal_connected ) { | |
| 63 | + wp_clear_scheduled_hook( 'frm_payment_cron' ); | |
| 64 | + } | |
| 54 | 65 | } |
| 55 | 66 | |
| 56 | 67 | /** |
| 57 | 68 | * Process overdue subscriptions. |
| @@ -58,14 +69,18 @@ | ||
| 58 | 69 | * |
| 59 | 70 | * @return void |
| 60 | 71 | */ |
| 61 | 72 | public static function run_payment_cron() { |
| 62 | - $frm_sub = new FrmTransLiteSubscription(); | |
| 63 | - $frm_payment = new FrmTransLitePayment(); | |
| 73 | + $frm_sub = new FrmTransLiteSubscription(); | |
| 74 | + $frm_payment = new FrmTransLitePayment(); | |
| 75 | + $overdue_subscriptions = $frm_sub->get_overdue_subscriptions(); | |
| 64 | 76 | |
| 65 | - $overdue_subscriptions = $frm_sub->get_overdue_subscriptions(); | |
| 66 | - FrmTransLiteLog::log_message( 'Stripe Cron Message', count( $overdue_subscriptions ) . ' subscriptions found to be processed.', false ); | |
| 77 | + if ( ! $overdue_subscriptions && ! $frm_sub->get_active_subscriptions() ) { | |
| 78 | + return; | |
| 79 | + } | |
| 67 | 80 | |
| 81 | + FrmTransLiteLog::log_message( 'Overdue Subscription Cron Message', count( $overdue_subscriptions ) . ' subscriptions found to be processed.', false ); | |
| 82 | + | |
| 68 | 83 | foreach ( $overdue_subscriptions as $sub ) { |
| 69 | 84 | $last_payment = $frm_payment->get_one_by( $sub->id, 'sub_id' ); |
| 70 | 85 | |
| 71 | 86 | if ( ! $last_payment ) { |
| @@ -86,9 +101,9 @@ | ||
| 86 | 101 | $log_message .= 'Failed triggers run on canceled subscription. '; |
| 87 | 102 | } else { |
| 88 | 103 | // Get the most recent payment after the gateway has a chance to create one. |
| 89 | 104 | $check_payment = $frm_payment->get_one_by( $sub->id, 'sub_id' ); |
| 90 | - $new_payment = $check_payment->id != $last_payment->id; | |
| 105 | + $new_payment = (int) $check_payment->id !== (int) $last_payment->id; | |
| 91 | 106 | $last_payment = $check_payment; |
| 92 | 107 | $status = 'no'; |
| 93 | 108 | |
| 94 | 109 | if ( ! $last_payment ) { |
| @@ -112,9 +127,9 @@ | ||
| 112 | 127 | $log_message .= 'on payment #' . $last_payment->id; |
| 113 | 128 | } |
| 114 | 129 | }//end if |
| 115 | 130 | |
| 116 | - FrmTransLiteLog::log_message( 'Stripe Cron Message', $log_message ); | |
| 131 | + FrmTransLiteLog::log_message( 'Overdue Subscription Cron Message', $log_message ); | |
| 117 | 132 | |
| 118 | 133 | self::maybe_trigger_changes( |
| 119 | 134 | array( |
| 120 | 135 | 'status' => $status, |
| @@ -195,16 +210,48 @@ | ||
| 195 | 210 | */ |
| 196 | 211 | public static function add_repeat_cadence_value( $args ) { |
| 197 | 212 | $action = $args['form_action']; |
| 198 | 213 | |
| 199 | - if ( ! empty( $action->post_content['repeat_cadence'] ) ) { | |
| 200 | - $params = array( | |
| 201 | - 'type' => 'hidden', | |
| 202 | - 'class' => 'frm-repeat-cadence-value', | |
| 203 | - 'value' => $action->post_content['repeat_cadence'], | |
| 204 | - ); | |
| 205 | - echo '<input '; | |
| 206 | - FrmAppHelper::array_to_html_params( $params, true ); | |
| 207 | - echo ' />'; | |
| 214 | + if ( empty( $action->post_content['repeat_cadence'] ) ) { | |
| 215 | + return; | |
| 208 | 216 | } |
| 217 | + | |
| 218 | + $params = array( | |
| 219 | + 'type' => 'hidden', | |
| 220 | + 'class' => 'frm-repeat-cadence-value', | |
| 221 | + 'value' => $action->post_content['repeat_cadence'], | |
| 222 | + ); | |
| 223 | + echo '<input '; | |
| 224 | + FrmAppHelper::array_to_html_params( $params, true ); | |
| 225 | + echo ' />'; | |
| 226 | + } | |
| 227 | + | |
| 228 | + /** | |
| 229 | + * Gateway fields are included for add-on compatibility but we do not want it to be visible. | |
| 230 | + * They do however need to be visible when the payments submodule is active. | |
| 231 | + * | |
| 232 | + * @since 6.30 | |
| 233 | + * | |
| 234 | + * @return void | |
| 235 | + */ | |
| 236 | + public static function hide_gateway_fields_in_builder() { | |
| 237 | + wp_add_inline_style( | |
| 238 | + 'formidable-admin', | |
| 239 | + ' | |
| 240 | + #frm_builder_page li[data-ftype="gateway"] { display: none; } | |
| 241 | + .frm_field_box:has(li[data-ftype="gateway"]:only-child) { display: none; } | |
| 242 | + ' | |
| 243 | + ); | |
| 244 | + } | |
| 245 | + | |
| 246 | + /** | |
| 247 | + * Remove the cron when the plugin is deactivated. | |
| 248 | + * | |
| 249 | + * @deprecated 6.32.1 | |
| 250 | + * | |
| 251 | + * @return void | |
| 252 | + */ | |
| 253 | + public static function remove_cron() { | |
| 254 | + _deprecated_function( __METHOD__, '6.32.1' ); | |
| 255 | + wp_clear_scheduled_hook( 'frm_payment_cron' ); | |
| 209 | 256 | } |
| 210 | 257 | } |