CouponsPage
1 year ago
CustomersPage
5 months ago
DashboardPage
1 year ago
DownloadLogsPage
1 year ago
ExportPage
5 months ago
GroupsPage
1 year ago
OrdersPage
1 year ago
PlansPage
2 months ago
SubscriptionsPage
3 months ago
TaxSettings
3 years ago
views
1 month ago
CheckListHeader.php
3 years ago
CheckoutFieldsManager.php
1 year ago
ContextualStateChangeHelper.php
3 years ago
FileDownloads.php
3 years ago
PaymentMethods.php
1 year ago
PaymentSettings.php
1 month ago
PlanIntegrationsMetabox.php
10 months ago
SettingsFieldsParser.php
1 year ago
index.php
3 years ago
PaymentMethods.php
147 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\Membership; |
| 4 | |
| 5 | use ProfilePress\Core\Admin\SettingsPages\AbstractSettingsPage; |
| 6 | use ProfilePress\Core\Membership\PaymentMethods\PaymentMethods as PaymentGateways; |
| 7 | use ProfilePress\Custom_Settings_Page_Api; |
| 8 | |
| 9 | class PaymentMethods |
| 10 | { |
| 11 | public function __construct() |
| 12 | { |
| 13 | add_filter('ppress_settings_page_submenus_tabs', [$this, 'header_sub_menu_tab']); |
| 14 | |
| 15 | add_action('ppress_admin_settings_submenu_page_payments_payment-methods', [$this, 'payment_methods_page']); |
| 16 | |
| 17 | add_action('ppress_register_menu_page_payments_payment-methods', function () { |
| 18 | |
| 19 | add_filter('ppress_general_settings_admin_page_title', function () { |
| 20 | return esc_html__('Payment Methods ‹ Payments', 'wp-user-avatar'); |
| 21 | }); |
| 22 | |
| 23 | add_action('admin_footer', [$this, 'js_script']); |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | public function header_sub_menu_tab($tabs) |
| 28 | { |
| 29 | $tabs[173] = ['parent' => 'payments', 'id' => 'payment-methods', 'label' => esc_html__('Payment Methods', 'wp-user-avatar')]; |
| 30 | |
| 31 | return $tabs; |
| 32 | } |
| 33 | |
| 34 | public function payment_method_list() |
| 35 | { |
| 36 | ob_start(); |
| 37 | require dirname(__FILE__) . '/views/payment-method-list.php'; |
| 38 | |
| 39 | return ob_get_clean(); |
| 40 | } |
| 41 | |
| 42 | protected function get_enabled_payment_methods() |
| 43 | { |
| 44 | $methods = PaymentGateways::get_instance()->get_enabled_methods(); |
| 45 | |
| 46 | $bucket = ['' => __('— No gateway —', 'wp-user-avatar')]; |
| 47 | |
| 48 | foreach ($methods as $id => $method) { |
| 49 | $bucket[$id] = $method->get_method_title(); |
| 50 | } |
| 51 | |
| 52 | return $bucket; |
| 53 | } |
| 54 | |
| 55 | public function payment_methods_page() |
| 56 | { |
| 57 | $instance = Custom_Settings_Page_Api::instance(); |
| 58 | $instance->option_name(PPRESS_PAYMENT_METHODS_OPTION_NAME); |
| 59 | $instance->page_header(esc_html__('Payment Methods', 'wp-user-avatar')); |
| 60 | |
| 61 | if ( ! empty($_GET['method'])) { |
| 62 | |
| 63 | $method = PaymentGateways::get_instance()->get_by_id( |
| 64 | sanitize_text_field($_GET['method']) |
| 65 | ); |
| 66 | |
| 67 | if ( ! $method) { |
| 68 | ppress_do_admin_redirect(add_query_arg(['view' => 'payments', 'section' => 'payment-methods'], PPRESS_SETTINGS_SETTING_PAGE)); |
| 69 | } |
| 70 | |
| 71 | $instance->page_header($method->get_method_title()); |
| 72 | |
| 73 | add_action('wp_cspa_after_header', function () use ($method) { |
| 74 | echo '<p>' . $method->get_method_description() . '</p>'; |
| 75 | }); |
| 76 | |
| 77 | $settings = []; |
| 78 | foreach ($method->admin_settings() as $key => $setting) { |
| 79 | $settings[0][$method->id . '_' . $key] = $setting; |
| 80 | } |
| 81 | |
| 82 | } else { |
| 83 | |
| 84 | $instance->add_view_classes('ppress-payment-methods-list'); |
| 85 | |
| 86 | $settings = [ |
| 87 | [ |
| 88 | 'payment_method_list' => [ |
| 89 | 'type' => 'arbitrary', |
| 90 | 'data' => $this->payment_method_list(), |
| 91 | ], |
| 92 | 'test_mode' => [ |
| 93 | 'label' => esc_html__('Test Mode', 'wp-user-avatar'), |
| 94 | 'description' => esc_html__('When test mode is enabled, no live transactions are processed. Use test mode in conjunction with the sandbox/test account for the payment method to test.', 'wp-user-avatar'), |
| 95 | 'type' => 'checkbox' |
| 96 | ], |
| 97 | 'test_mode_reconnection_notice' => [ |
| 98 | 'label' => '', |
| 99 | 'data' => '<style>#test_mode_reconnection_notice_row {display:none}</style><div class="pp-alert-notice pp-alert-notice-info"><p>' . __('Switching test/live modes would require payment methods reconnection or setup.', 'wp-user-avatar') . '</p></div>', |
| 100 | 'type' => 'custom_field_block' |
| 101 | ], |
| 102 | 'default_payment_method' => [ |
| 103 | 'label' => esc_html__('Default Payment Method', 'wp-user-avatar'), |
| 104 | 'description' => esc_html__('Select payment method to automatically load on the checkout page. If empty, the first active method is selected instead.', 'wp-user-avatar'), |
| 105 | 'type' => 'select', |
| 106 | 'options' => $this->get_enabled_payment_methods() |
| 107 | ] |
| 108 | ] |
| 109 | ]; |
| 110 | |
| 111 | add_action('wp_cspa_after_header', function () { |
| 112 | echo '<p>' . esc_html__('Installed payment methods are listed below. Drag and drop to control their display order on the frontend.', 'wp-user-avatar') . '</p>'; |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | $instance->main_content($settings); |
| 117 | $instance->remove_white_design(); |
| 118 | AbstractSettingsPage::register_core_settings($instance, true); |
| 119 | $instance->build(true); |
| 120 | } |
| 121 | |
| 122 | public function js_script() |
| 123 | { |
| 124 | ?> |
| 125 | <script type="text/javascript"> |
| 126 | (function ($) { |
| 127 | $(function () { |
| 128 | $('#test_mode').on('change', function () { |
| 129 | $('#test_mode_reconnection_notice_row').show(); |
| 130 | }); |
| 131 | }); |
| 132 | })(jQuery) |
| 133 | </script> |
| 134 | <?php |
| 135 | } |
| 136 | |
| 137 | public static function get_instance() |
| 138 | { |
| 139 | static $instance = null; |
| 140 | |
| 141 | if (is_null($instance)) { |
| 142 | $instance = new self(); |
| 143 | } |
| 144 | |
| 145 | return $instance; |
| 146 | } |
| 147 | } |