id = 'gateways';
$this->label = esc_html__('Payment Gateways', 'give');
$this->default_tab = 'gateways-settings';
parent::__construct();
// Do not use main form for this tab.
if (give_get_current_setting_tab() === $this->id) {
add_action('give_admin_field_gateway_notice', [$this, 'render_gateway_notice'], 10, 2);
add_action('give_admin_field_enabled_gateways', [$this, 'render_enabled_gateways'], 10, 2);
}
}
/**
* Get settings array.
*
* @since 1.8
* @return array
*/
public function get_settings()
{
$settings = [];
$current_section = give_get_current_setting_section();
switch ($current_section) {
case 'offline-donations':
$settings = [
// Section 3: Offline gateway.
[
'type' => 'title',
'id' => 'give_title_gateway_settings_3',
],
[
'name' => __('Collect Billing Details', 'give'),
'desc' => __('If enabled, required billing address fields are added to Offline Donation forms. These fields are not required to process the transaction, but you may have a need to collect the data. Billing address details are added to both the donation and donor record in GiveWP. ', 'give'),
'id' => 'give_offline_donation_enable_billing_fields',
'type' => 'radio_inline',
'default' => 'disabled',
'options' => [
'enabled' => __('Enabled', 'give'),
'disabled' => __('Disabled', 'give'),
],
],
[
'name' => __('Offline Donation Instructions', 'give'),
'desc' => __('The Offline Donation Instructions are a chance for you to educate the donor on how to best submit offline donations. These instructions appear directly on the form, and after submission of the form. Note: You may also customize the instructions on individual forms as needed.', 'give'),
'id' => 'global_offline_donation_content',
'default' => give_get_default_offline_donation_content(),
'type' => 'wysiwyg',
'options' => [
'textarea_rows' => 6,
],
],
[
'name' => esc_html__('Offline Donations Settings Docs Link', 'give'),
'id' => 'offline_gateway_settings_docs_link',
'url' => esc_url('http://docs.givewp.com/offlinegateway'),
'title' => __('Offline Gateway Settings', 'give'),
'type' => 'give_docs_link',
],
[
'type' => 'sectionend',
'id' => 'give_title_gateway_settings_3',
],
];
break;
case 'gateways-settings':
$settings = [
// Section 1: Gateways.
[
'id' => 'give_title_gateway_settings_1',
'type' => 'title',
],
[
'id' => 'gateway_notice',
'type' => 'gateway_notice',
],
[
'name' => __('Test Mode', 'give'),
'desc' => __(
'If enabled, donations are processed through the sandbox/test accounts configured in each gateway\'s settings. This prevents having to use real money for tests. See the payment gateway documentation for instructions on configuring sandbox accounts.',
'give'
),
'id' => 'test_mode',
'type' => 'radio_inline',
'default' => 'disabled',
'options' => [
'enabled' => __('Enabled', 'give'),
'disabled' => __('Disabled', 'give'),
],
],
[
'name' => __('Enabled Gateways', 'give') . ' - v2',
'desc' => __('Enable your payment gateway. Can be ordered by dragging.', 'give'),
'id' => 'gateways',
'type' => 'enabled_gateways',
],
[
'name' => __('Enabled Gateways', 'give') . ' - v3',
'desc' => __('Enable your payment gateway. Can be ordered by dragging.', 'give'),
'id' => 'gateways_v3',
'type' => 'enabled_gateways_hidden',
],
/**
* "Enabled Gateways" setting field contains gateways label setting but when you save gateway settings then label will not save
* because this is not registered setting API and code will not recognize them.
*
* This setting will not render on admin setting screen but help internal code to recognize "gateways_label" setting and add them to give setting when save.
*/
[
'name' => __('Gateways Label', 'give') . ' - v2',
'desc' => '',
'id' => 'gateways_label',
'type' => 'gateways_label_hidden',
],
[
'name' => __('Gateways Label', 'give') . ' - v3',
'desc' => '',
'id' => 'gateways_label_v3',
'type' => 'gateways_label_hidden',
],
/**
* "Enabled Gateways" setting field contains default gateway setting but when you save gateway settings then this setting will not save
* because this is not registered setting API and code will not recognize them.
*
* This setting will not render on admin setting screen but help internal code to recognize "default_gateway" setting and add them to give setting when save.
*/
[
'name' => __('Default Gateway', 'give') . ' - v2',
'desc' => __('The gateway that will be selected by default.', 'give'),
'id' => 'default_gateway',
'type' => 'default_gateway_hidden',
],
[
'name' => __('Default Gateway', 'give') . ' - v3',
'desc' => __('The gateway that will be selected by default.', 'give'),
'id' => 'default_gateway_v3',
'type' => 'default_gateway_hidden',
],
[
'name' => __('Gateways Docs Link', 'give'),
'id' => 'gateway_settings_docs_link',
'url' => esc_url('http://docs.givewp.com/settings-gateways'),
'title' => __('Gateway Settings', 'give'),
'type' => 'give_docs_link',
],
[
'id' => 'give_title_gateway_settings_1',
'type' => 'sectionend',
],
];
break;
}
/**
* Filter the payment gateways settings.
* Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
*/
$settings = apply_filters('give_settings_gateways', $settings);
/**
* Filter the settings.
*
* @since 1.8
*
* @param array $settings
*/
$settings = apply_filters('give_get_settings_' . $this->id, $settings);
// Output.
return $settings;
}
/**
* Get sections.
*
* @since 2.9.0 move offline-donations to end of gateway list
* @since 1.8
*
* @return array
*/
public function get_sections()
{
$sections = apply_filters(
'give_get_sections_' . $this->id,
[
'gateways-settings' => __('Gateways', 'give'),
]
);
$sections['offline-donations'] = __('Offline Donations', 'give');
return $sections;
}
/**
* @since 2.13.0
* @return bool
*/
private function hasPremiumPaymentGateway()
{
$gateways = give_get_payment_gateways();
return (bool)apply_filters('give_gateway_upsell_notice_conditions', count($gateways) > 8);
}
/**
* @since 2.13.0
*
* @return bool
*/
private function canAcceptCreditCard()
{
return Give\Helpers\Gateways\Stripe::isAccountConfigured() ||
give(MerchantDetails::class)->accountIsConnected();
}
/**
* Render Gateway Notice
*
* @since 4.2.0 Updated messages removing mentions to Stripe fees
* @since 2.3.0
* @access public
*
* @param $field
* @param $settings
*/
public function render_gateway_notice($field, $settings)
{
if (! $this->hasPremiumPaymentGateway() && ! $this->canAcceptCreditCard()) {
?>
PayPal Donations, or a premium gateway like 2checkout, or Authorize.Net.',
'give'
),
Give()->tooltips->render_help(
__(
'The Stripe payment gateway includes a 2% processing fee in addition to Stripe’s transaction fee. This ensures our ability to provide future support and updates for the plugin.',
'give'
)
),
admin_url('edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=paypal'),
'https://givewp.com/addons/2checkout/?utm_source=WP%20Admin%20%3E%20Donations%20%3E%20Settings%20%3E%20Gateways&utm_medium=banner',
'https://givewp.com/addons/authorize-net-gateway/?utm_source=WP%20Admin%20%3E%20Donations%20%3E%20Settings%20%3E%20Gateways&utm_medium=banner'
);
?>
getStripeConnectButtonMarkup(); ?>
gateways->hasPaymentGateway($key);
},
ARRAY_FILTER_USE_BOTH
);
// v2 gateways are gateways that are registered with updated gateway registration API.
// These payment gateways support donation processing with v2 donation forms.
// Legacy payment gateways will display with v2 gateways.
$v2Gateways = give_get_ordered_payment_gateways(
array_merge(
$legacyGateways,
array_intersect_key(
$gateways,
give()->gateways->getPaymentGateways(2)
)
),
2
);
// v3 gateways are gateways that are registered with updated gateway registration API.
// These payment gateways support donation processing with v3 donation forms.
$v3Gateways = give_get_ordered_payment_gateways(
array_intersect_key($gateways, give()->gateways->getPaymentGateways(3)),
3
);
$groups = [
'v3' => [
'label' => __('Visual Form Builder', 'give'),
'gateways' => $v3Gateways,
'settings' => give_get_option('gateways_v3', []),
'gatewaysLabel' => give_get_option('gateways_label_v3', []),
'defaultGateway' => give_get_option('default_gateway_v3', current(array_keys($v3Gateways))),
'helper' => [
'text' => __(
'Uses the blocks-based visual form builder for creating and customizing a donation form.',
'give'
),
'image' => GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/give-settings-gateways-v3.jpg',
]
],
'v2' => [
'label' => __('Option-Based Form Editor', 'give'),
'gateways' => $v2Gateways,
'settings' => $settings,
'gatewaysLabel' => give_get_option('gateways_label', []),
'defaultGateway' => give_get_option('default_gateway', current(array_keys($v2Gateways))),
'helper' => [
'text' => __(
'Uses the traditional settings options for creating and customizing a donation form.',
'give'
),
'image' => GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/give-settings-gateways-v2.jpg',
],
],
];
/**
* @since 3.18.0
*/
$groups = apply_filters('give_settings_payment_gateways_menu_groups', $groups);
$defaultGroup = current(array_keys($groups));
ob_start();
echo '