PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.12.2
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.12.2
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / admin / settings / class-charitable-gateway-settings.php

class-charitable-gateway-settings.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.12.2, at includes/admin/settings/class-charitable-gateway-settings.php

160 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Gateway Settings UI.
4 *
5 * @package Charitable/Classes/Charitable_Gateway_Settings
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.0.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Gateway_Settings' ) ) :
19
20 /**
21 * Charitable_Gateway_Settings
22 *
23 * @final
24 * @since 1.0.0
25 */
26 final class Charitable_Gateway_Settings {
27
28 /**
29 * The single instance of this class.
30 *
31 * @var Charitable_Gateway_Settings|null
32 */
33 private static $instance = null;
34
35 /**
36 * Create object instance.
37 *
38 * @since 1.0.0
39 */
40 private function __construct() {
41 }
42
43 /**
44 * Returns and/or create the single instance of this class.
45 *
46 * @since 1.2.0
47 *
48 * @return Charitable_Gateway_Settings
49 */
50 public static function get_instance() {
51 if ( is_null( self::$instance ) ) {
52 self::$instance = new self();
53 }
54
55 return self::$instance;
56 }
57
58 /**
59 * Returns all the payment gateway settings fields.
60 *
61 * @since 1.0.0
62 *
63 * @return array
64 */
65 public function add_gateway_fields() {
66 if ( ! charitable_is_settings_view( 'gateways' ) ) {
67 return array();
68 }
69
70 return array(
71 'section' => array(
72 'title' => '',
73 'type' => 'hidden',
74 'priority' => 10000,
75 'value' => 'gateways',
76 'save' => false,
77 ),
78 'section_gateways' => array(
79 'title' => __( 'Payment Gateways', 'charitable' ),
80 'type' => 'heading',
81 'priority' => 5,
82 ),
83 'gateways' => array(
84 'title' => false,
85 'callback' => array( $this, 'render_gateways_table' ),
86 'priority' => 10,
87 ),
88 'test_mode' => array(
89 'title' => __( 'Turn on Test Mode', 'charitable' ),
90 'type' => 'checkbox',
91 'help' => __( 'When test mode is on, donations are routed to each gateway\'s sandbox/test credentials instead of live, no real charges are made, and the donation form displays a "Test Mode" banner. Use this to verify your setup end-to-end before accepting real donations. Turn off when you\'re ready to go live.', 'charitable' ),
92 'priority' => 15,
93 'class' => 'charitable-test-mode-checkbox',
94 ),
95 'additional_gateways' => array(
96 'type' => 'content',
97 'content' => '<p class="charitable-gateways-additional-link"><a href="https://www.wpcharitable.com/multiple-payment-gateways/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'View Additional Payment Gateways', 'charitable' ) . '</a></p>',
98 'priority' => 20,
99 ),
100 );
101 }
102
103 /**
104 * Add settings for each individual payment gateway.
105 *
106 * @since 1.0.0
107 *
108 * @param array $fields The existing fields.
109 * @return array
110 */
111 public function add_individual_gateway_fields( $fields ) {
112
113 foreach ( charitable_get_helper( 'gateways' )->get_active_gateways() as $gateway ) {
114 if ( ! class_exists( $gateway ) ) {
115 continue;
116 }
117 $gateway = new $gateway();
118
119 $fields[ 'gateways_' . $gateway->get_gateway_id() ] = apply_filters( 'charitable_settings_fields_gateways_gateway', array(), $gateway );
120
121 }
122
123 return $fields;
124 }
125
126 /**
127 * Add gateway keys to the settings groups.
128 *
129 * @since 1.0.0
130 *
131 * @param string[] $groups The existing groups.
132 * @return string[]
133 */
134 public function add_gateway_settings_dynamic_groups( $groups ) {
135 foreach ( charitable_get_helper( 'gateways' )->get_active_gateways() as $gateway_key => $gateway ) {
136 if ( ! class_exists( $gateway ) ) {
137 continue;
138 }
139
140 $groups[ 'gateways_' . $gateway_key ] = apply_filters( 'charitable_gateway_settings_fields_gateways_gateway', array(), new $gateway() );
141 }
142
143 return $groups;
144 }
145
146 /**
147 * Display table with available payment gateways.
148 *
149 * @since 1.0.0
150 *
151 * @param array $args The arguments.
152 * @return void
153 */
154 public function render_gateways_table( $args ) {
155 charitable_admin_view( 'settings/gateways', $args );
156 }
157 }
158
159 endif;
160