| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmStrpLiteSettingsController { |
| 7 |
|
| 8 |
/** |
| 9 |
* Add Stripe section to Global Settings. |
| 10 |
* |
| 11 |
* @param array $sections |
| 12 |
* |
| 13 |
* @return array |
| 14 |
*/ |
| 15 |
public static function add_settings_section( $sections ) { |
| 16 |
$sections['stripe'] = array( |
| 17 |
'class' => self::class, |
| 18 |
'function' => 'route', |
| 19 |
'icon' => 'frmfont frm_stripe_icon', |
| 20 |
); |
| 21 |
|
| 22 |
add_action( |
| 23 |
'frm_messages_settings_form', |
| 24 |
/** |
| 25 |
* @param object $frm_settings |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
function ( $frm_settings ) { |
| 30 |
$stripe_settings = FrmStrpLiteAppHelper::get_settings()->settings; |
| 31 |
require FrmStrpLiteAppHelper::plugin_path() . '/views/settings/messages.php'; |
| 32 |
} |
| 33 |
); |
| 34 |
|
| 35 |
return $sections; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Handle global settings routing. |
| 40 |
* |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
public static function route() { |
| 44 |
self::global_settings_form(); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Print the Stripe section for Global settings. |
| 49 |
* |
| 50 |
* @param array $atts |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
public static function global_settings_form( $atts = array() ) { |
| 55 |
$atts = array_merge( $atts, self::get_default_settings_atts() ); |
| 56 |
$errors = $atts['errors']; |
| 57 |
$message = $atts['message']; |
| 58 |
$settings = FrmStrpLiteAppHelper::get_settings(); |
| 59 |
$stripe_connect_is_live = FrmStrpLiteConnectHelper::stripe_connect_is_setup( 'live' ); |
| 60 |
$stripe_connect_is_on_for_test = FrmStrpLiteConnectHelper::stripe_connect_is_setup( 'test' ); |
| 61 |
|
| 62 |
include FrmStrpLiteAppHelper::plugin_path() . '/views/settings/form.php'; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @return array |
| 67 |
*/ |
| 68 |
private static function get_default_settings_atts() { |
| 69 |
return array( |
| 70 |
'errors' => array(), |
| 71 |
'message' => '', |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Handle processing changes to global Stripe Settings. |
| 77 |
* |
| 78 |
* @return void |
| 79 |
*/ |
| 80 |
public static function process_form() { |
| 81 |
$settings = FrmStrpLiteAppHelper::get_settings(); |
| 82 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 83 |
$settings->update( wp_unslash( $_POST ) ); |
| 84 |
$settings->store(); |
| 85 |
} |
| 86 |
} |
| 87 |
|