PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.12.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.12.1
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 1.7.0.9 1.8.0 All 210 releases
charitable / includes / admin / views / settings / gateways.php

gateways.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.12.1, at includes/admin/views/settings/gateways.php

324 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * Display the table of payment gateways.
10 *
11 * @author David Bisset
12 * @package Charitable/Admin View/Settings
13 * @copyright Copyright (c) 2023, WP Charitable LLC
14 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
15 * @since 1.0.0
16 * @version 1.6.38 - Add Stripe Warning
17 * @version 1.8.2 - Add Stripe Warning
18 * @version 1.8.7 - Add Square Legacy gateway and sanitize gateway logos.
19 * @version 1.8.8.6
20 */
21
22 $charitable_helper = charitable_get_helper( 'gateways' );
23 $charitable_gateways = $charitable_helper->get_available_gateways();
24 $charitable_default = $charitable_helper->get_default_gateway();
25 $charitable_upgrades = $charitable_helper->get_recommended_gateways();
26
27 /**
28 * Map of gateway IDs to documentation URLs. When set, a small help icon
29 * (dashicons-editor-help) appears next to the gateway name and links to
30 * the docs in a new tab. Legacy `paypal` is intentionally omitted — only
31 * PayPal Commerce gets a doc link.
32 */
33 $charitable_gateway_doc_urls = array(
34 'stripe' => 'https://www.wpcharitable.com/documentation/charitable-stripe/',
35 'square_core' => 'https://www.wpcharitable.com/documentation/how-to-connect-to-square/',
36 'paypal_commerce' => 'https://www.wpcharitable.com/documentation/how-to-connect-to-paypal-ecommerce',
37 'offline' => 'https://www.wpcharitable.com/documentation/setting-up-offline-donations/',
38 );
39
40 // Add a warning message here if Stripe is an enabled gateway, but no keys are found.
41
42 if ( class_exists( 'Charitable_Gateway_Stripe_AM' ) ) {
43
44 if ( ( ! defined( 'CHARITABLE_DISABLE_STRIPE_KEY_CHECK' ) || ! CHARITABLE_DISABLE_STRIPE_KEY_CHECK ) && is_array( $charitable_gateways ) && ! empty( $charitable_gateways ) && in_array( 'Charitable_Gateway_Stripe_AM', $charitable_gateways, true ) && $charitable_helper->is_active_gateway( 'Charitable_Gateway_Stripe_AM' ) ) { // phpcs:ignore
45 $charitable_stripe_gateway = new Charitable_Gateway_Stripe_AM();
46 $charitable_stripe_keys = $charitable_stripe_gateway->get_keys();
47
48 if ( ! isset( $charitable_stripe_keys['public_key'] ) || empty( $charitable_stripe_keys['public_key'] ) ) {
49 // Display the warning message HTML.
50 /* translators: %s: URL to the Stripe settings page */
51 echo wp_kses(
52 sprintf(
53 '<div class="charitable-settings-notice charitable-stripe-key-notice"> %s</div>',
54 sprintf(
55 /* translators: %s: URL to the Stripe settings page */
56 esc_html__( '<strong>Note:</strong> Stripe is enabled but it does not appear to be connected or API keys are missing. <a href="%s">Confirm Stripe settings to keep using this gateway</a>.', 'charitable' ),
57 esc_url( admin_url( 'admin.php?page=charitable-settings&tab=gateways&group=gateways_stripe' ) )
58 )
59 ),
60 array(
61 'div' => array( 'class' => array() ),
62 'strong' => array(),
63 'a' => array( 'href' => array() ),
64 )
65 );
66 }
67 }
68 }
69
70 // Enforce display order: Stripe → PayPal Commerce → Square → everything else.
71 $charitable_reordered_gateways = array();
72 $charitable_anchored_keys = array( 'stripe', 'paypal_commerce', 'square_core' );
73
74 foreach ( $charitable_anchored_keys as $charitable_key ) {
75 if ( isset( $charitable_gateways[ $charitable_key ] ) ) {
76 $charitable_reordered_gateways[ $charitable_key ] = $charitable_gateways[ $charitable_key ];
77 }
78 }
79
80 // Append remaining gateways in their original order.
81 foreach ( $charitable_gateways as $charitable_key => $charitable_class ) {
82 if ( ! isset( $charitable_reordered_gateways[ $charitable_key ] ) ) {
83 $charitable_reordered_gateways[ $charitable_key ] = $charitable_class;
84 }
85 }
86
87 $charitable_gateways = $charitable_reordered_gateways;
88
89 foreach ( $charitable_gateways as $charitable_gateway ) :
90
91 $charitable_gateway = class_exists( $charitable_gateway ) ? new $charitable_gateway() : null;
92 if ( ! $charitable_gateway ) {
93 continue;
94 }
95
96 $charitable_is_active = $charitable_helper->is_active_gateway( $charitable_gateway->get_gateway_id() );
97
98 if ( $charitable_is_active ) {
99 $charitable_action_url = esc_url(
100 add_query_arg(
101 array(
102 'charitable_action' => 'disable_gateway',
103 'gateway_id' => $charitable_gateway->get_gateway_id(),
104 '_nonce' => wp_create_nonce( 'gateway' ),
105 ),
106 admin_url( 'admin.php?page=charitable-settings&tab=gateways' )
107 )
108 );
109 $charitable_action_text = __( 'Disable Gateway', 'charitable' );
110 } else {
111 $charitable_action_url = esc_url(
112 add_query_arg(
113 array(
114 'charitable_action' => 'enable_gateway',
115 'gateway_id' => $charitable_gateway->get_gateway_id(),
116 '_nonce' => wp_create_nonce( 'gateway' ),
117 ),
118 admin_url( 'admin.php?page=charitable-settings&tab=gateways' )
119 )
120 );
121 $charitable_action_text = __( 'Enable Gateway', 'charitable' );
122 }
123
124 $charitable_action_url = esc_url(
125 add_query_arg(
126 array(
127 'charitable_action' => $charitable_is_active ? 'disable_gateway' : 'enable_gateway',
128 'gateway_id' => $charitable_gateway->get_gateway_id(),
129 '_nonce' => wp_create_nonce( 'gateway' ),
130 ),
131 admin_url( 'admin.php?page=charitable-settings&tab=gateways' )
132 )
133 );
134
135 $charitable_make_default_url = esc_url(
136 add_query_arg(
137 array(
138 'charitable_action' => 'make_default_gateway',
139 'gateway_id' => $charitable_gateway->get_gateway_id(),
140 '_nonce' => wp_create_nonce( 'gateway' ),
141 ),
142 admin_url( 'admin.php?page=charitable-settings&tab=gateways' )
143 )
144 );
145
146 $charitable_gateway_name = null !== $charitable_gateway->get_name() ? $charitable_gateway->get_name() : '';
147
148 ?>
149 <?php $charitable_gateway_id = $charitable_gateway->get_gateway_id(); ?>
150 <div class="charitable-settings-object charitable-gateway <?php echo esc_attr( strtolower( $charitable_gateway_name ) ); ?>">
151 <span class="gateway-logo-name">
152 <?php if ( isset( $charitable_gateway_doc_urls[ $charitable_gateway_id ] ) ) : ?>
153 <a
154 href="<?php echo esc_url( $charitable_gateway_doc_urls[ $charitable_gateway_id ] ); ?>"
155 target="_blank"
156 rel="noopener noreferrer"
157 class="charitable-gateway-help"
158 title="<?php
159 /* translators: %s: gateway name (e.g. Stripe). */
160 printf( esc_attr__( 'View %s documentation', 'charitable' ), esc_attr( $charitable_gateway_name ) );
161 ?>"
162 aria-label="<?php
163 /* translators: %s: gateway name (e.g. Stripe). */
164 printf( esc_attr__( 'View %s documentation', 'charitable' ), esc_attr( $charitable_gateway_name ) );
165 ?>">
166 <span class="dashicons dashicons-editor-help" aria-hidden="true"></span>
167 </a>
168 <?php endif; ?>
169 <?php
170 // if method get_logo() exists, use it.
171 if ( method_exists( $charitable_gateway, 'get_logo' ) ) {
172 $charitable_logo = $charitable_gateway->get_logo();
173 if ( is_string( $charitable_logo ) && ( strpos( $charitable_logo, '<img' ) !== false || strpos( $charitable_logo, '<svg' ) !== false ) ) {
174 echo '<span class="gateway-logo">' . wp_kses(
175 $charitable_logo,
176 array(
177 'img' => array(
178 'src' => array(),
179 'alt' => array(),
180 'class' => array(),
181 'width' => array(),
182 'height' => array(),
183 'style' => array(),
184 ),
185 'svg' => array(
186 'xmlns' => array(),
187 'viewBox' => array(),
188 'width' => array(),
189 'height' => array(),
190 'class' => array(),
191 ),
192 'path' => array(
193 'd' => array(),
194 'fill' => array(),
195 ),
196 )
197 ) . '</span>';
198 } else {
199 echo '<span class="gateway-logo">' . esc_html( $charitable_logo ) . '</span>';
200 }
201 } else {
202 $charitable_name = esc_html( $charitable_gateway->get_name() );
203 if ( 'square' === strtolower( $charitable_name ) ) {
204 $charitable_name .= ' ' . __( '(Legacy)', 'charitable' );
205 }
206 echo '<h4>' . esc_html( $charitable_name ) . '</h4>';
207 }
208 ?>
209
210 <?php if ( $charitable_gateway->get_recommended() ) : ?>
211 <span class="charitable-badge charitable-badge-sm charitable-badge-inline charitable-badge-green charitable-badge-rounded"><i class="fa fa-star" aria-hidden="true"></i><?php esc_html_e( 'Recommended', 'charitable' ); ?></span>
212 <?php endif ?>
213
214 <?php if ( (string) $charitable_gateway->get_gateway_id() === (string) $charitable_default ) : ?>
215
216 <span class="charitable-badge charitable-badge-sm charitable-badge-inline charitable-badge-orange charitable-badge-rounded"><i class="fa fa-check" aria-hidden="true"></i><?php esc_html_e( 'Default Gateway', 'charitable' ); ?></span>
217
218 <?php elseif ( $charitable_is_active ) : ?>
219
220 <a href="<?php echo esc_url( $charitable_make_default_url ); ?>" class="make-default-gateway"><i class="fa fa-check" aria-hidden="true"></i><?php esc_html_e( 'Make default', 'charitable' ); ?></a>
221
222 <?php endif ?>
223 </span>
224 <span class="actions">
225 <?php
226 if ( $charitable_is_active ) :
227 $charitable_settings_url = esc_url(
228 add_query_arg(
229 array(
230 'group' => 'gateways_' . $charitable_gateway->get_gateway_id(),
231 ),
232 admin_url( 'admin.php?page=charitable-settings&tab=gateways' )
233 )
234 );
235 ?>
236
237 <a href="<?php echo esc_url( $charitable_settings_url ); ?>" class="button button-primary"><?php esc_html_e( 'Gateway Settings', 'charitable' ); ?></a>
238 <?php endif ?>
239 <a href="<?php echo esc_url( $charitable_action_url ); ?>" class="button"><?php echo esc_html( $charitable_action_text ); ?></a>
240 </span>
241 </div>
242
243 <?php
244 // Display Square fallback row after PayPal Commerce if the Square class
245 // isn't loaded. Rendering after PayPal Commerce (rather than Stripe) keeps
246 // the display order Stripe → PayPal → Square → others when the Square SDK
247 // is missing and `Charitable_Gateway_Square` is therefore skipped in the
248 // main loop above.
249 if ( 'paypal_commerce' === $charitable_gateway->get_gateway_id() && ! class_exists( 'Charitable_Gateway_Square' ) ) :
250 $charitable_php_version_check = version_compare( PHP_VERSION, '8.1.0', '>=' );
251
252 if ( ! $charitable_php_version_check ) {
253 $charitable_error_message = sprintf(
254 /* translators: %s: URL to documentation */
255 __( 'Requires PHP 8.1.0 or higher. <a href="%s" target="_blank">See our documentation</a>.', 'charitable' ),
256 'https://www.wpcharitable.com/documentation/php-version-compatibility-square/'
257 );
258 } else {
259 $charitable_error_message = __( 'Square gateway could not be loaded.', 'charitable' );
260 }
261 ?>
262 <div class="charitable-settings-object charitable-gateway square">
263 <span class="gateway-logo-name">
264 <?php if ( isset( $charitable_gateway_doc_urls['square_core'] ) ) : ?>
265 <a
266 href="<?php echo esc_url( $charitable_gateway_doc_urls['square_core'] ); ?>"
267 target="_blank"
268 rel="noopener noreferrer"
269 class="charitable-gateway-help"
270 title="<?php esc_attr_e( 'View Square documentation', 'charitable' ); ?>"
271 aria-label="<?php esc_attr_e( 'View Square documentation', 'charitable' ); ?>">
272 <span class="dashicons dashicons-editor-help" aria-hidden="true"></span>
273 </a>
274 <?php endif; ?>
275 <span class="gateway-logo"><?php echo '<svg width="88" height="22" viewBox="0 0 88 22" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.6761 1.54849e-07H18.3239C19.299 -0.000282679 20.2344 0.386894 20.924 1.07633C21.6136 1.76576 22.0011 2.70095 22.0011 3.6761V18.3228C22.0011 20.3537 20.3547 22 18.3239 22H3.6761C1.64567 21.9994 0 20.3533 0 18.3228V3.6761C0 1.64584 1.64584 1.54849e-07 3.6761 1.54849e-07ZM16.8434 18.0005C17.4842 18.0005 18.0037 17.481 18.0037 16.8402L18.0005 5.16083C18.0005 4.52004 17.481 4.00058 16.8402 4.00058H5.1619C4.854 4.00058 4.55872 4.12297 4.3411 4.34079C4.12348 4.55861 4.00137 4.854 4.00165 5.1619V16.8402C4.00165 17.481 4.52111 18.0005 5.1619 18.0005H16.8434Z" fill="#3E4348"/><path d="M8.66615 13.9828C8.30039 13.9799 8.00543 13.6826 8.00544 13.3168V8.65442C8.00459 8.47722 8.07438 8.30698 8.19939 8.18138C8.32439 8.05578 8.49429 7.98517 8.67149 7.98517H13.3403C13.5174 7.98545 13.6871 8.05615 13.8121 8.18169C13.937 8.30724 14.0069 8.47731 14.0063 8.65442V13.3157C14.0069 13.4928 13.937 13.6629 13.8121 13.7884C13.6871 13.914 13.5174 13.9847 13.3403 13.985L8.66615 13.9828Z" fill="#3E4348"/><path d="M33.1959 10.0196C32.5149 9.83388 31.8702 9.65883 31.3696 9.43575C30.4431 9.0216 30.0119 8.44734 30.0119 7.62972C30.0119 6.08414 31.5062 5.3882 32.9942 5.3882C34.4084 5.3882 35.6434 5.97313 36.4728 7.03412L36.5293 7.1067L37.7248 6.17167L37.6672 6.09908C36.5646 4.69653 34.9315 3.92801 33.0667 3.92801C31.8254 3.92801 30.6875 4.26317 29.8646 4.87265C28.9381 5.55044 28.4492 6.53351 28.4492 7.70657C28.4492 10.4338 31.0173 11.0987 33.0817 11.6335C35.1706 12.1843 36.4504 12.6027 36.4504 14.1952C36.4504 15.7632 35.1823 16.7762 33.2204 16.7762C32.2502 16.7762 30.4538 16.519 29.3245 14.7941L29.2722 14.7129L28.0148 15.6234L28.0639 15.6971C29.1313 17.3131 30.9736 18.2407 33.1244 18.2407C36.0458 18.2407 38.0098 16.5915 38.0098 14.1387C38.0098 11.3314 35.3392 10.6045 33.1959 10.0196Z" fill="#3E4348"/><path fill-rule="evenodd" clip-rule="evenodd" d="M47.5395 9.45282V7.97662H48.9452V21.9979H47.5395V16.52C46.7368 17.6205 45.5328 18.2225 44.1174 18.2225C41.4447 18.2225 39.5767 16.0824 39.5767 12.9923C39.5767 9.90219 41.4489 7.745 44.1174 7.745C45.5232 7.745 46.7272 8.35021 47.5395 9.45282ZM41.0583 12.9752C41.0583 15.8358 42.6967 16.8552 44.2305 16.8552L44.2337 16.8562C46.2415 16.8562 47.5395 15.3192 47.5395 12.9752C47.5395 10.6312 46.2394 9.11552 44.2305 9.11552C41.8919 9.11552 41.0583 11.1094 41.0583 12.9752Z" fill="#3E4348"/><path d="M58.239 7.97662V13.511C58.239 15.4484 56.9122 16.8552 55.0848 16.8552C53.567 16.8552 52.8284 15.9543 52.8284 14.1024V7.97662H51.4226V14.3895C51.4226 16.7911 52.728 18.2246 54.914 18.2246C56.276 18.2246 57.4459 17.6472 58.24 16.5915V17.9962H59.6458V7.97662H58.239Z" fill="#3E4348"/><path fill-rule="evenodd" clip-rule="evenodd" d="M62.293 9.02907C63.3294 8.21465 64.7362 7.7482 66.1505 7.7482C68.3846 7.7482 69.7177 8.85935 69.7135 10.723V17.9984H68.3067V16.8872C67.5968 17.7763 66.57 18.2268 65.2486 18.2268C63.0956 18.2268 61.7571 17.0494 61.7571 15.1559C61.7571 12.6934 64.0776 12.307 65.0661 12.1426C65.2272 12.116 65.3937 12.0904 65.5601 12.0647L65.5603 12.0647L65.5663 12.0638C66.9168 11.8559 68.3109 11.6414 68.3109 10.4957C68.3109 9.19878 66.6276 9.09845 66.1121 9.09845C65.2016 9.09845 63.9154 9.3685 63.0412 10.1263L62.9612 10.1957L62.2268 9.08137L62.293 9.02907ZM63.2248 15.0769C63.2248 16.6823 64.7362 16.8562 65.3863 16.8562H65.3873C66.8006 16.8562 68.3131 16.1027 68.3099 13.985V12.5354C67.6242 12.9685 66.6483 13.1377 65.7778 13.2886L65.7631 13.2912L65.3265 13.3691C63.9325 13.6274 63.2248 13.9604 63.2248 15.0769Z" fill="#3E4348"/><path d="M77.8577 8.16554C77.5236 7.92752 76.9974 7.78555 76.4487 7.78555C75.3213 7.80037 74.2664 8.34386 73.5998 9.25322V7.97235H72.1941V17.9909H73.5998V12.6326C73.5998 10.2566 74.9352 9.19237 76.2576 9.19237C76.6447 9.1872 77.0279 9.26852 77.3795 9.4304L77.4745 9.48057L77.9196 8.20611L77.8577 8.16554Z" fill="#3E4348"/><path fill-rule="evenodd" clip-rule="evenodd" d="M78.2697 13.0136C78.2697 9.91394 80.2027 7.7482 82.9662 7.7482C85.6282 7.7482 87.4887 9.67057 87.4834 12.4276C87.4826 12.6673 87.4694 12.9067 87.4439 13.1449L87.4353 13.2271H79.7501C79.7853 15.4334 81.1132 16.8562 83.1508 16.8562C84.3186 16.8562 85.3304 16.3813 85.9997 15.5177L86.0605 15.4388L87.0788 16.346L87.0223 16.4143C86.3455 17.2394 85.1116 18.2236 83.0729 18.2236C80.2016 18.2236 78.2697 16.1304 78.2697 13.0136ZM82.9277 9.09738C81.2103 9.09738 79.9924 10.2277 79.8024 11.9879H85.9976C85.8759 10.5725 85.0113 9.09738 82.9277 9.09738Z" fill="#3E4348"/></svg>'; ?></span>
276
277 <span class="charitable-badge charitable-badge-sm charitable-badge-inline charitable-badge-green charitable-badge-rounded"><i class="fa fa-star" aria-hidden="true"></i><?php esc_html_e( 'Recommended', 'charitable' ); ?></span>
278 </span>
279 <span class="actions">
280 <span class="gateway-error">
281 <?php
282 echo wp_kses(
283 $charitable_error_message,
284 array(
285 'a' => array(
286 'href' => array(),
287 'target' => array(),
288 ),
289 )
290 );
291 ?>
292 </span>
293 </span>
294 </div>
295 <?php
296 endif;
297 endforeach
298 ?>
299
300 <?php
301 if ( ! empty( $charitable_upgrades ) ) :
302 if ( 1 === count( $charitable_upgrades ) ) {
303 $charitable_currencies = charitable_get_currency_helper()->get_all_currencies();
304 $charitable_gateway = key( $charitable_upgrades );
305 $charitable_message = sprintf(
306 /* translators: %1$s: currency; %2$s: hyperlink %3$s: payment gateway name */
307 __( '<strong>Tip</strong>: Accept donations in %1$s with <a href="%2$s" target="_blank">%3$s</a>.', 'charitable' ),
308 $charitable_currencies[ charitable_get_currency() ],
309 'https://www.wpcharitable.com/extensions/charitable-' . $charitable_gateway . '/?utm_source=WordPress&utm_campaign=WP+Charitable&utm_medium=Upgrade+Notice&utm_content=Accept+Donations',
310 current( $charitable_upgrades )
311 );
312 } else {
313 $charitable_message = sprintf(
314 /* translators: %1$s: hyperlink; %2$s: single extension name; %3$s: comma-separated list of extension names */
315 __( '<strong>Need more options?</strong> <a href="%1$s" target="_blank">Click here to browse our payment gateway extensions</a>, including %3$s and %2$s.', 'charitable' ),
316 'https://www.wpcharitable.com/extensions/category/payment-gateways/?utm_source=WordPress&utm_campaign=WP+Charitable&utm_medium=Admin+Notice&utm_content=Need+More+Options+Browse+Gateway+Extensions',
317 array_pop( $charitable_upgrades ),
318 implode( ', ', $charitable_upgrades )
319 );
320 }
321 ?>
322 <p class="charitable-gateway-prompt charitable-settings-notice"><?php echo esc_html( $charitable_message ); ?></p>
323 <?php endif ?>
324