| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmStrpLiteAppController { |
| 7 |
|
| 8 |
/** |
| 9 |
* Install required tables. |
| 10 |
* |
| 11 |
* @param mixed $old_db_version |
| 12 |
* @return void |
| 13 |
*/ |
| 14 |
public static function install( $old_db_version = false ) { |
| 15 |
FrmTransLiteAppController::install( $old_db_version ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Remove Stripe database items after uninstall. |
| 20 |
* |
| 21 |
* @since 6.5, introduced in v2.07 of the Stripe add on. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public static function uninstall() { |
| 26 |
if ( ! current_user_can( 'administrator' ) ) { |
| 27 |
$frm_settings = FrmAppHelper::get_settings(); |
| 28 |
wp_die( esc_html( $frm_settings->admin_permission ) ); |
| 29 |
} |
| 30 |
|
| 31 |
$options_to_delete = array( |
| 32 |
FrmStrpLiteEventsController::$events_to_skip_option_name, |
| 33 |
'frm_strp_options', |
| 34 |
); |
| 35 |
|
| 36 |
$modes = array( 'test', 'live' ); |
| 37 |
$option_name_keys = array( 'account_id', 'client_password', 'server_password', 'details_submitted' ); |
| 38 |
foreach ( $modes as $mode ) { |
| 39 |
foreach ( $option_name_keys as $key ) { |
| 40 |
$options_to_delete[] = 'frm_strp_connect_' . $key . '_' . $mode; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
foreach ( $options_to_delete as $option_name ) { |
| 45 |
delete_option( $option_name ); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Redirect to Stripe settings when payments are not yet installed |
| 51 |
* and the payments page is accessed by its URL. |
| 52 |
* |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public static function maybe_redirect_to_stripe_settings() { |
| 56 |
if ( ! FrmAppHelper::is_admin_page( 'formidable-payments' ) || self::payments_are_installed() ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
wp_safe_redirect( admin_url( 'admin.php?page=formidable-settings&t=stripe_settings' ) ); |
| 61 |
die(); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @return bool |
| 66 |
*/ |
| 67 |
private static function payments_are_installed() { |
| 68 |
$db = new FrmTransLiteDb(); |
| 69 |
$option = get_option( $db->db_opt_name ); |
| 70 |
return false !== $option; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Add the gateway for compatibility with the Payments submodule. |
| 75 |
* This adds the Stripe checkbox option to the list of gateways. |
| 76 |
* |
| 77 |
* @param array $gateways |
| 78 |
* @return array |
| 79 |
*/ |
| 80 |
public static function add_gateway( $gateways ) { |
| 81 |
$gateways['stripe'] = array( |
| 82 |
'label' => 'Stripe', |
| 83 |
'user_label' => __( 'Payment', 'formidable' ), |
| 84 |
'class' => 'StrpLite', |
| 85 |
'recurring' => true, |
| 86 |
'include' => array( |
| 87 |
'billing_first_name', |
| 88 |
'billing_last_name', |
| 89 |
'credit_card', |
| 90 |
'billing_address', |
| 91 |
), |
| 92 |
); |
| 93 |
return $gateways; |
| 94 |
} |
| 95 |
} |
| 96 |
|