Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions classes/controllers/FrmAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1330,14 +1330,18 @@ public static function handle_activation() {

/**
* The payment cron is unscheduled when Formidable is deactivated.
* We need to add it back again on activation if Stripe is configured.
* We need to add it back again on activation if any payment gateway is configured.
*
* @since 6.5
*
* @return void
*/
private static function maybe_activate_payment_cron() {
if ( ! FrmStrpLiteConnectHelper::stripe_connect_is_setup() ) {
$stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup();
$square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup();
$paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup();

if ( ! $stripe_connected && ! $square_connected && ! $paypal_connected ) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions paypal/helpers/FrmPayPalLiteConnectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ public static function process_event( $event_id ) {
public static function handle_disconnect() {
self::disconnect();
self::reset_paypal_api_integration();
FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'paypal', self::get_mode_value_from_post() );
wp_send_json_success();
}

Expand Down
1 change: 1 addition & 0 deletions square/helpers/FrmSquareLiteConnectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ public static function cancel_subscription( $subscription_id ) {
public static function handle_disconnect() {
self::disconnect();
self::reset_square_api_integration();
FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'square', self::get_mode_value_from_post() );
wp_send_json_success();
}

Expand Down
29 changes: 26 additions & 3 deletions stripe/controllers/FrmTransLiteAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,23 @@ public static function maybe_schedule_cron() {
}

/**
* Remove the cron when the plugin is deactivated.
* Remove the payment cron when all gateways are disconnected.
*
* @since x.x
*
* @param string $gateway 'stripe', 'square', or 'paypal'.
* @param string $mode 'test' or 'live'.
*
* @return void
*/
public static function remove_cron() {
wp_clear_scheduled_hook( 'frm_payment_cron' );
public static function maybe_remove_payment_cron( $gateway, $mode ) {
$stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup();
$square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup();
$paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup();

if ( ! $stripe_connected && ! $square_connected && ! $paypal_connected ) {
wp_clear_scheduled_hook( 'frm_payment_cron' );
}
}

/**
Expand Down Expand Up @@ -231,4 +242,16 @@ public static function hide_gateway_fields_in_builder() {
'
);
}

/**
* Remove the cron when the plugin is deactivated.
*
* @deprecated x.x
*
* @return void
*/
public static function remove_cron() {
_deprecated_function( __METHOD__, 'x.x' );
wp_clear_scheduled_hook( 'frm_payment_cron' );
}
}
2 changes: 2 additions & 0 deletions stripe/controllers/FrmTransLiteHooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static function load_hooks() {
* @return void
*/
public static function load_admin_hooks() {
add_action( 'frm_disconnected_gateway', 'FrmTransLiteAppController::maybe_remove_payment_cron' );

if ( class_exists( 'FrmTransHooksController', false ) ) {
add_action( 'frm_pay_show_square_options', 'FrmTransLiteAppController::add_repeat_cadence_value' );

Expand Down
23 changes: 1 addition & 22 deletions stripe/helpers/FrmStrpLiteConnectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static function get_url_to_connect_server() {
private static function handle_disconnect() {
self::disconnect();
self::reset_stripe_connect_integration();
self::maybe_unschedule_crons();
FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'stripe', self::get_mode_value_from_post() );
wp_send_json_success();
}

Expand All @@ -290,27 +290,6 @@ private static function disconnect() {
return self::post_with_authenticated_body( 'disconnect', $additional_body );
}

/**
* Stop the payment cron once all Stripe connections have been disconnected.
*
* @since 6.5
*
* @return void
*/
private static function maybe_unschedule_crons() {
if ( self::at_least_one_mode_is_setup() ) {
// Don't unschedule if a mode is still on.
return;
}

$event = 'frm_payment_cron';
$timestamp = wp_next_scheduled( $event );

if ( false !== $timestamp ) {
wp_unschedule_event( $timestamp, $event );
}
}

/**
* @since 6.5
*
Expand Down
18 changes: 18 additions & 0 deletions stripe/helpers/FrmTransLiteAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,22 @@ private static function sort_gateways( $gateways, $order ) {

return $sorted + $gateways;
}

/**
* @since x.x
*
* @param string $gateway 'stripe', 'square', or 'paypal'.
* @param string $mode 'test' or 'live'.
*
* @return void
*/
public static function trigger_gateway_disconnected_hook( $gateway, $mode ) {
/**
* @since x.x
*
* @param string $gateway 'stripe', 'square', or 'paypal'.
* @param string $mode 'test' or 'live'.
*/
do_action( 'frm_disconnected_gateway', $gateway, $mode );
}
}
Loading