PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.7.0
GiveWP – Donation Plugin and Fundraising Platform v4.7.0
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / PaymentGateways / PayPalCommerce / AdminSettingFields.php
give / src / PaymentGateways / PayPalCommerce Last commit date
Banners 2 years ago DataTransferObjects 1 year ago Exceptions 3 years ago Migrations 2 years ago Models 2 years ago PayPalCheckoutSdk 1 year ago Repositories 1 year ago Webhooks 2 years ago AccountAdminNotices.php 4 years ago AdminSettingFields.php 1 year ago AdvancedCardFields.php 4 years ago AjaxRequestHandler.php 1 year ago DonationDetailsPage.php 4 years ago DonationFormPaymentMethod.php 2 years ago PayPalClient.php 2 years ago PayPalCommerce.php 10 months ago RefreshToken.php 2 years ago RefundPaymentHandler.php 4 years ago ScriptLoader.php 1 year ago Utils.php 2 years ago onBoardingRedirectHandler.php 1 year ago
AdminSettingFields.php
516 lines
1 <?php
2
3 namespace Give\PaymentGateways\PayPalCommerce;
4
5 use Give\PaymentGateways\PayPalCommerce\Banners\PayPalDonationsSettingPageBanner;
6 use Give\PaymentGateways\PayPalCommerce\Models\MerchantDetail;
7 use Give\PaymentGateways\PayPalCommerce\Repositories\MerchantDetails;
8 use Give\PaymentGateways\PayPalCommerce\Repositories\Settings;
9 use Give_HTML_Elements;
10 use Give_License;
11
12 /**
13 * Class AdminSettingFields
14 * @package Give\PaymentGateways\PayPalCommerce
15 *
16 * @since 3.16.0 added nonce to disconnect button
17 * @since 2.9.0
18 */
19 class AdminSettingFields
20 {
21 /**
22 * @var MerchantDetail
23 */
24 private $merchantModel;
25
26 /**
27 * @var Settings
28 */
29 private $settingRepository;
30
31 /**
32 * @var MerchantDetails
33 */
34 private $merchantRepository;
35
36 /**
37 * AdminSettingFields constructor.
38 *
39 * @param MerchantDetail $merchantDetail
40 * @param MerchantDetails $merchantDetailRepository
41 * @param Settings $settings
42 */
43 public function __construct(
44 MerchantDetail $merchantDetail,
45 MerchantDetails $merchantDetailRepository,
46 Settings $settings
47 ) {
48 $this->merchantModel = $merchantDetail;
49 $this->merchantRepository = $merchantDetailRepository;
50 $this->settingRepository = $settings;
51 }
52
53 /**
54 * Bootstrap fields.
55 *
56 * @since 2.9.0
57 */
58 public function boot()
59 {
60 add_action('give_admin_field_paypal_commerce_account_manger', [$this, 'payPalCommerceAccountManagerField']);
61 add_action('give_admin_field_paypal_commerce_account_country', [$this, 'accountCountryField']);
62 add_action('give_admin_field_paypal_commerce_introduction', [$this, 'introductionSection']);
63 }
64
65 /**
66 * Render account country field.
67 *
68 * @since 2.9.0
69 */
70 public function accountCountryField()
71 {
72 /* @var Give_HTML_Elements $htmlElements */
73 $htmlElements = give('html');
74
75 $settingHtml = $htmlElements->select(
76 [
77 'id' => 'paypal_commerce_account_country',
78 'options' => give_get_country_list(),
79 'chosen' => true,
80 'placeholder' => esc_html__('Choose a country', 'give'),
81 'show_option_all' => false,
82 'show_option_none' => false,
83 'data' => [
84 'search-type' => 'no_ajax',
85 ],
86 'selected' => $this->merchantModel->accountCountry ?: $this->settingRepository->getAccountCountry(),
87 ]
88 );
89 ?>
90 <tr valign="top" class="js-fields-has-custom-saving-logic">
91 <th scope="row" class="titledesc">
92 <label for="give_paypal_commerce_country"><?php
93 esc_html_e('Account Country', 'give'); ?></label>
94 </th>
95 <td class="give-forminp">
96 <?php
97 printf(
98 '%1$s<div class="give-field-description">%2$s</div>',
99 $settingHtml,
100 esc_html__('The country the PayPal account is based from. Make sure to select before connecting.', 'give')
101 )
102 ?>
103 </td>
104 </tr>
105 <?php
106 }
107
108 /**
109 * PayPal Checkout account manager custom field
110 *
111 * @since 3.0.0 Update PayPal sandbox connection button description.
112 * @since 2.9.0
113 */
114 public function payPalCommerceAccountManagerField()
115 {
116 $recurringAddonInfo = Give_License::get_plugin_by_slug('give-recurring');
117 $isRecurringAddonActive = isset($recurringAddonInfo['Status']) && 'active' === $recurringAddonInfo['Status'];
118
119 // Show live PayPal connect button.
120 $paypalLiveSetting = new \stdClass();
121 $paypalLiveSetting->label = esc_html__('PayPal Connection', 'give');
122 $paypalLiveSetting->mode = 'live';
123 $paypalLiveSetting->connectButtonLabel = esc_html__('Connect with PayPal Live', 'give');
124 $paypalLiveSetting->description = esc_html__('PayPal is currently NOT connected.', 'give');
125 $paypalLiveSetting->isRecurringAddonActive = $isRecurringAddonActive;
126 echo $this->getPayPalConnectionSettingView($paypalLiveSetting);
127
128 // Show sandbox PayPal connect button.
129 $paypalSandboxSetting = new \stdClass();
130 $paypalSandboxSetting->label = esc_html__('PayPal Sandbox Connection', 'give');
131 $paypalSandboxSetting->mode = 'sandbox';
132 $paypalSandboxSetting->connectButtonLabel = esc_html__('Connect with PayPal Sandbox', 'give');
133 $paypalSandboxSetting->description = sprintf(
134 '%1$s <a href="%2$s" target="_blank">%3$s</a> <strong>%4$s</strong>',
135 esc_html__('PayPal sandbox is currently NOT connected.', 'give'),
136 esc_url('https://docs.givewp.com/paypal-sandbox-setup'),
137 esc_html__('Set up a separate PayPal Sandbox account for testing.', 'give'),
138 esc_html__('Live PayPal accounts will not work.', 'give')
139 );
140 $paypalSandboxSetting->isRecurringAddonActive = $isRecurringAddonActive;
141
142 echo $this->getPayPalConnectionSettingView($paypalSandboxSetting);
143
144 echo $this->getBanner();
145 }
146
147 /**
148 * PayPal Commerce introduction section.
149 *
150 * @since 2.9.0
151 */
152 public function introductionSection()
153 {
154 ?>
155 <div id="give-paypal-commerce-introduction-wrap">
156 <div class="hero-section">
157 <div>
158 <h2><?php
159 esc_html_e('Accept Donations with PayPal Donations', 'give'); ?></h2>
160 <p class="give-field-description">
161 <?php
162 esc_html_e(
163 'Allow your donors to give using Debit or Credit Cards directly on your website with no additional fees.',
164 'give'
165 );
166 ?>
167 </p>
168 </div>
169 <div class="paypal-logo">
170 <img src="<?php echo GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/paypal-logo.png'; ?>"
171 width="316"
172 height="84"
173 alt="<?php esc_attr_e('PayPal Logo Image', 'give'); ?>">
174 </div>
175 </div>
176 <div class="feature-list">
177 <div><i class="fa fa-angle-right"></i><?php
178 esc_html_e('Credit and Debit Card Donations', 'give'); ?>
179 </div>
180 <div>
181 <i class="fa fa-angle-right"></i><?php
182 esc_html_e('Improve donation conversion rates', 'give'); ?>
183 </div>
184 <div><i class="fa fa-angle-right"></i><?php
185 esc_html_e('Easy no-API key connection', 'give'); ?></div>
186 <div>
187 <i class="fa fa-angle-right"></i><?php
188 esc_html_e('Accept payments from around the world', 'give'); ?>
189 </div>
190 <div><i class="fa fa-angle-right"></i><?php
191 esc_html_e('Donate via PayPal accounts', 'give'); ?>
192 </div>
193 <div><i class="fa fa-angle-right"></i><?php
194 esc_html_e('Supports 3D Secure payments', 'give'); ?>
195 </div>
196 </div>
197 </div>
198 <?php
199 }
200
201 /**
202 * Return whether or not country is in North America
203 */
204 private function isCountryInNorthAmerica(): bool
205 {
206 // Countries list: https://en.wikipedia.org/wiki/List_of_North_American_countries_by_area#Countries
207 $northAmericaCountryList = [
208 'CA', // Canada
209 'US', // United States
210 'MX', // Mexico
211 'NI', // Nicaragua
212 'HN', // Honduras
213 'CU', // Cuba
214 'GT', // Guatemala
215 'PA', // Panama
216 'CR', // Costa Rica
217 'DO', // Dominican Republic
218 'HT', // Haiti
219 'BZ', // Belize
220 'SV', // EL Salvador
221 'BS', // The Bahamas
222 'JM', // Jamaica
223 'TT', // Trinidad and Tobago
224 'DM', // Dominica
225 'LC', // Saint Lucia
226 'AG', // Antigua and Barbuda
227 'BB', // Barbados
228 'VC', // Saint Vincent and the Grenadines
229 'GD', // Grenada
230 'KN', // Saint Kitts and Nevis
231 ];
232
233 $accountCountry = $this->settingRepository->getAccountCountry();
234
235 return in_array($accountCountry, $northAmericaCountryList, true);
236 }
237
238 /**
239 * Return admin guidance notice to fix PayPal on boarding error.
240 *
241 * @since 3.10.0 Updated phone number for contact
242 * @since 2.9.6
243 *
244 * @param bool $completeMessage
245 *
246 * @return string
247 */
248 public function getAdminGuidanceNotice($completeMessage = true)
249 {
250 if ($this->isCountryInNorthAmerica()) {
251 $telephone = sprintf(
252 '<a href="tel:%1$s">%1$s</a>',
253 '1-888-350-2387'
254 );
255
256 $message = sprintf(
257 esc_html__('Please call a PayPal support representative at %1$s', 'give'),
258 $telephone
259 );
260 } else {
261 $message = esc_html__(
262 'Please reach out to PayPal support from your PayPal account Resolution Center',
263 'give'
264 );
265 }
266
267 $message .= $completeMessage ? esc_html__(' and relay the following message:', 'give') : '.';
268
269 return $message;
270 }
271
272 /**
273 * Print on boarding errors.
274 *
275 * @since 2.9.6
276 */
277 private function printErrors(MerchantDetails $merchantDetailsRepository)
278 {
279 $accountErrors = $merchantDetailsRepository->getAccountErrors();
280
281 if (! empty($accountErrors)) :
282 ?>
283 <div>
284 <p class="error-message"><?php esc_html_e('Warning, your account is not ready to accept donations.', 'give'); ?></p>
285 <p>
286 <?php
287 printf(
288 '%1$s %2$s',
289 esc_html__(
290 'There is an issue with your PayPal account that is preventing you from being able to accept donations.',
291 'give'
292 ),
293 $this->getAdminGuidanceNotice()
294 )
295 ?>
296 </p>
297 <div class="paypal-message-template">
298 <?php esc_html_e('Greetings!', 'give'); ?><br><br>
299 <?php esc_html_e(
300 'I am trying to connect my PayPal account to the GiveWP plugin for WordPress. I have gone through the onboarding process to connect my account, but when I finish I\'m given the following message from GiveWP:',
301 'give'
302 );
303 ?><br>
304 <?php echo $this->formatErrors($accountErrors); ?>
305 <br>
306 <?php
307 esc_html_e(
308 'Please help me resolve these account errors so I can begin accepting payments via PayPal on GiveWP.',
309 'give'
310 );
311 ?>
312 </div>
313
314 <?php if ($this->merchantRepository->accountIsConnected()) :?>
315 <?php
316 $reCheckAccountStatusUrl = add_query_arg(
317 [
318 'post_type' => 'give_forms',
319 'page' => 'give-settings',
320 'tab' => 'gateways',
321 'section' => 'paypal',
322 'group' => 'paypal-commerce',
323 'paypalStatusCheck' => '1',
324 'mode' => $merchantDetailsRepository->getMode()
325 ],
326 admin_url('edit.php')
327 );
328 ?>
329 <p>
330 <a href="<?php echo $reCheckAccountStatusUrl; ?>">
331 <?php esc_html_e('Re-Check Account Status', 'give'); ?>
332 </a>
333 </p>
334 <?php endif; ?>
335
336 </div>
337 <?php endif;
338 }
339
340 /**
341 * Return format errors string.
342 *
343 * @since 2.9.6
344 *
345 * @param array $errors
346 *
347 * @return string
348 */
349 private function formatErrors($errors)
350 {
351 $isSingleError = ! (count($errors) > 1);
352 $formattedArray = array_map(
353 static function ($arr) use ($isSingleError) {
354 if (is_array($arr)) {
355 switch ($arr['type']) {
356 case 'url':
357 return sprintf(
358 '<%1$s>%2$s<br><code>%3$s</code></%1$s>',
359 $isSingleError ? 'p' : 'li',
360 $arr['message'],
361 urldecode_deep($arr['value'])
362 );
363
364 case 'json':
365 return sprintf(
366 '<%1$s>%2$s<br><code>%3$s</code></%1$s>',
367 $isSingleError ? 'p' : 'li',
368 $arr['message'],
369 $arr['value']
370 );
371 }
372 }
373
374 return sprintf(
375 '<%1$s>%2$s</%1$s>',
376 $isSingleError ? 'p' : 'li',
377 $arr
378 );
379 },
380 $errors
381 );
382
383 $output = implode('', $formattedArray);
384
385 if (! $isSingleError) {
386 $output = sprintf(
387 '<ul class="ul-disc">%1$s</ul>',
388 $output
389 );
390 }
391
392 return $output;
393 }
394
395 /**
396 * This function return html for "PayPal Connection" and "PayPal Sandbox Connection".
397 *
398 * @param \stdClass $paypalSetting PayPal setting data.
399 */
400 private function getPayPalConnectionSettingView(\stdClass $paypalSetting): string
401 {
402 ob_start();
403
404 /** @var MerchantDetails $mechantDetailsRepository */
405 $mechantDetailsRepository = give(MerchantDetails::class);
406 $mechantDetailsRepository->setMode($paypalSetting->mode);
407
408 $merchantDetail = $mechantDetailsRepository->getDetails();
409
410 $canShowAccountInformation = $mechantDetailsRepository->accountIsConnected();
411 ?>
412 <tr>
413 <th scope="row" class="titledesc">
414 <label for="give_paypal_commerce_country">
415 <?php echo $paypalSetting->label ?>
416 </label>
417 </th>
418 <td class="give-forminp">
419 <div class="give-paypal-commerce-account-manager-field-wrap">
420 <div class="connect-button-wrap">
421 <div
422 class="button-wrap connection-setting<?php echo $canShowAccountInformation ? ' give-hidden' : ''; ?>">
423 <div>
424 <button class="button button-primary button-large js-give-paypal-on-boarding-handler"
425 data-mode="<?php echo $paypalSetting->mode; ?>">
426 <i class="fab fa-paypal"></i>&nbsp;&nbsp;
427 <?php echo $paypalSetting->connectButtonLabel; ?>
428 </button>
429 <?php if ('live' === $paypalSetting->mode) : ?>
430 <span class="tooltip">
431 <span class="left-arrow"></span>
432 <?php esc_html_e('Click to get started!', 'give'); ?>
433 </span>
434 <?php // We are using one PayPal button to handle both sandbox and live mode connection.?>
435 <a class="give-hidden" target="PPFrame" data-paypal-button="true">
436 <?php esc_html_e('Sign up for PayPal', 'give'); ?>
437 </a>
438 <?php endif; ?>
439 </div>
440 <span class="give-field-description">
441 <i class="fa fa-exclamation"></i><?php echo $paypalSetting->description ?>
442 </span>
443 </div>
444 <div
445 class="button-wrap disconnection-setting<?php echo ! $canShowAccountInformation ? ' give-hidden' : ''; ?>">
446 <div>
447 <button class="button button-large disabled" disabled="disabled">
448 <i class="fab fa-paypal"></i>&nbsp;&nbsp;<?php
449 esc_html_e('Connected', 'give'); ?>
450 </button>
451 </div>
452 <div>
453 <span class="give-field-description">
454 <i class="fa fa-check"></i>
455 <?php
456 if ($merchantDetail->accountIsReady) {
457 $connectedAccountTypeMessage = $merchantDetail->supportsCustomPayments
458 ? esc_html__('Connected as Advanced for payments as', 'give')
459 : esc_html__('Connected as Standard for payments as', 'give');
460 } else {
461 $connectedAccountTypeMessage = esc_html__('Connected for payments as', 'give');
462 }
463
464 printf(
465 '%1$s <span class="paypal-account-email">%2$s</span>',
466 $connectedAccountTypeMessage,
467 $merchantDetail->merchantId
468 );
469 ?>
470 </span>
471 <span class="actions">
472 <button
473 class="js-give-paypal-disconnect-paypal-account"
474 data-mode="<?php echo $paypalSetting->mode; ?>"
475 data-nonce="<?php echo esc_attr(wp_create_nonce('give_paypal_commerce_disconnect_account')); ?>"
476 >
477 <?php esc_html_e('Disconnect', 'give'); ?>
478 </button>
479 </span>
480 </div>
481 </div>
482 <?php $this->printErrors($mechantDetailsRepository); ?>
483 </div>
484 </div>
485 </td>
486 </tr>
487 <?php
488 return ob_get_clean();
489 }
490
491 /**
492 * @since 2.33.0
493 */
494 private function getBanner(): string
495 {
496 ob_start();
497
498 if (
499 give(MerchantDetail::class)->accountIsReady
500 && give_is_gateway_active(PayPalCommerce::id())
501 ) {
502 return '';
503 }
504 ?>
505 <tr>
506 <th scope="row" class="titledesc">
507 </th>
508 <td class="give-forminp">
509 <?php echo give(PayPalDonationsSettingPageBanner::class)->render(); ?>
510 </td>
511 </tr>
512 <?php
513 return ob_get_clean();
514 }
515 }
516