PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.12.2
GiveWP – Donation Plugin and Fundraising Platform v3.12.2
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 4 years ago Exceptions 3 years ago Migrations 2 years ago Models 2 years ago PayPalCheckoutSdk 2 years ago Repositories 2 years ago Webhooks 2 years ago AccountAdminNotices.php 4 years ago AdminSettingFields.php 2 years ago AdvancedCardFields.php 4 years ago AjaxRequestHandler.php 2 years ago DonationDetailsPage.php 4 years ago DonationFormPaymentMethod.php 2 years ago PayPalClient.php 2 years ago PayPalCommerce.php 2 years ago RefreshToken.php 2 years ago RefundPaymentHandler.php 4 years ago ScriptLoader.php 2 years ago Utils.php 2 years ago onBoardingRedirectHandler.php 2 years ago
AdminSettingFields.php
515 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 2.9.0
17 */
18 class AdminSettingFields
19 {
20 /**
21 * @var MerchantDetail
22 */
23 private $merchantModel;
24
25 /**
26 * @var Settings
27 */
28 private $settingRepository;
29
30 /**
31 * @var MerchantDetails
32 */
33 private $merchantRepository;
34
35 /**
36 * AdminSettingFields constructor.
37 *
38 * @param MerchantDetail $merchantDetail
39 * @param MerchantDetails $merchantDetailRepository
40 * @param Settings $settings
41 */
42 public function __construct(
43 MerchantDetail $merchantDetail,
44 MerchantDetails $merchantDetailRepository,
45 Settings $settings
46 ) {
47 $this->merchantModel = $merchantDetail;
48 $this->merchantRepository = $merchantDetailRepository;
49 $this->settingRepository = $settings;
50 }
51
52 /**
53 * Bootstrap fields.
54 *
55 * @since 2.9.0
56 */
57 public function boot()
58 {
59 add_action('give_admin_field_paypal_commerce_account_manger', [$this, 'payPalCommerceAccountManagerField']);
60 add_action('give_admin_field_paypal_commerce_account_country', [$this, 'accountCountryField']);
61 add_action('give_admin_field_paypal_commerce_introduction', [$this, 'introductionSection']);
62 }
63
64 /**
65 * Render account country field.
66 *
67 * @since 2.9.0
68 */
69 public function accountCountryField()
70 {
71 /* @var Give_HTML_Elements $htmlElements */
72 $htmlElements = give('html');
73
74 $settingHtml = $htmlElements->select(
75 [
76 'id' => 'paypal_commerce_account_country',
77 'options' => give_get_country_list(),
78 'chosen' => true,
79 'placeholder' => esc_html__('Choose a country', 'give'),
80 'show_option_all' => false,
81 'show_option_none' => false,
82 'data' => [
83 'search-type' => 'no_ajax',
84 ],
85 'selected' => $this->merchantModel->accountCountry ?: $this->settingRepository->getAccountCountry(),
86 ]
87 );
88 ?>
89 <tr valign="top" class="js-fields-has-custom-saving-logic">
90 <th scope="row" class="titledesc">
91 <label for="give_paypal_commerce_country"><?php
92 esc_html_e('Account Country', 'give'); ?></label>
93 </th>
94 <td class="give-forminp">
95 <?php
96 printf(
97 '%1$s<div class="give-field-description">%2$s</div>',
98 $settingHtml,
99 esc_html__('The country the PayPal account is based from. Make sure to select before connecting.', 'give')
100 )
101 ?>
102 </td>
103 </tr>
104 <?php
105 }
106
107 /**
108 * PayPal Checkout account manager custom field
109 *
110 * @since 3.0.0 Update PayPal sandbox connection button description.
111 * @since 2.9.0
112 */
113 public function payPalCommerceAccountManagerField()
114 {
115 $recurringAddonInfo = Give_License::get_plugin_by_slug('give-recurring');
116 $isRecurringAddonActive = isset($recurringAddonInfo['Status']) && 'active' === $recurringAddonInfo['Status'];
117
118 // Show live PayPal connect button.
119 $paypalLiveSetting = new \stdClass();
120 $paypalLiveSetting->label = esc_html__('PayPal Connection', 'give');
121 $paypalLiveSetting->mode = 'live';
122 $paypalLiveSetting->connectButtonLabel = esc_html__('Connect with PayPal Live', 'give');
123 $paypalLiveSetting->description = esc_html__('PayPal is currently NOT connected.', 'give');
124 $paypalLiveSetting->isRecurringAddonActive = $isRecurringAddonActive;
125 echo $this->getPayPalConnectionSettingView($paypalLiveSetting);
126
127 // Show sandbox PayPal connect button.
128 $paypalSandboxSetting = new \stdClass();
129 $paypalSandboxSetting->label = esc_html__('PayPal Sandbox Connection', 'give');
130 $paypalSandboxSetting->mode = 'sandbox';
131 $paypalSandboxSetting->connectButtonLabel = esc_html__('Connect with PayPal Sandbox', 'give');
132 $paypalSandboxSetting->description = sprintf(
133 '%1$s <a href="%2$s" target="_blank">%3$s</a> <strong>%4$s</strong>',
134 esc_html__('PayPal sandbox is currently NOT connected.', 'give'),
135 esc_url('https://docs.givewp.com/paypal-sandbox-setup'),
136 esc_html__('Set up a separate PayPal Sandbox account for testing.', 'give'),
137 esc_html__('Live PayPal accounts will not work.', 'give')
138 );
139 $paypalSandboxSetting->isRecurringAddonActive = $isRecurringAddonActive;
140
141 echo $this->getPayPalConnectionSettingView($paypalSandboxSetting);
142
143 echo $this->getBanner();
144 }
145
146 /**
147 * PayPal Commerce introduction section.
148 *
149 * @since 2.9.0
150 */
151 public function introductionSection()
152 {
153 ?>
154 <div id="give-paypal-commerce-introduction-wrap">
155 <div class="hero-section">
156 <div>
157 <h2><?php
158 esc_html_e('Accept Donations with PayPal Donations', 'give'); ?></h2>
159 <p class="give-field-description">
160 <?php
161 esc_html_e(
162 'Allow your donors to give using Debit or Credit Cards directly on your website with no additional fees.',
163 'give'
164 );
165 ?>
166 </p>
167 </div>
168 <div class="paypal-logo">
169 <img src="<?php echo GIVE_PLUGIN_URL . '/assets/dist/images/admin/paypal-logo.svg'; ?>"
170 width="316"
171 height="84"
172 alt="<?php esc_attr_e('PayPal Logo Image', 'give'); ?>">
173 </div>
174 </div>
175 <div class="feature-list">
176 <div><i class="fa fa-angle-right"></i><?php
177 esc_html_e('Credit and Debit Card Donations', 'give'); ?>
178 </div>
179 <div>
180 <i class="fa fa-angle-right"></i><?php
181 esc_html_e('Improve donation conversion rates', 'give'); ?>
182 </div>
183 <div><i class="fa fa-angle-right"></i><?php
184 esc_html_e('Easy no-API key connection', 'give'); ?></div>
185 <div>
186 <i class="fa fa-angle-right"></i><?php
187 esc_html_e('Accept payments from around the world', 'give'); ?>
188 </div>
189 <div><i class="fa fa-angle-right"></i><?php
190 esc_html_e('Donate via PayPal accounts', 'give'); ?>
191 </div>
192 <div><i class="fa fa-angle-right"></i><?php
193 esc_html_e('Supports 3D Secure payments', 'give'); ?>
194 </div>
195 </div>
196 </div>
197 <?php
198 }
199
200 /**
201 * Return whether or not country is in North America
202 */
203 private function isCountryInNorthAmerica(): bool
204 {
205 // Countries list: https://en.wikipedia.org/wiki/List_of_North_American_countries_by_area#Countries
206 $northAmericaCountryList = [
207 'CA', // Canada
208 'US', // United States
209 'MX', // Mexico
210 'NI', // Nicaragua
211 'HN', // Honduras
212 'CU', // Cuba
213 'GT', // Guatemala
214 'PA', // Panama
215 'CR', // Costa Rica
216 'DO', // Dominican Republic
217 'HT', // Haiti
218 'BZ', // Belize
219 'SV', // EL Salvador
220 'BS', // The Bahamas
221 'JM', // Jamaica
222 'TT', // Trinidad and Tobago
223 'DM', // Dominica
224 'LC', // Saint Lucia
225 'AG', // Antigua and Barbuda
226 'BB', // Barbados
227 'VC', // Saint Vincent and the Grenadines
228 'GD', // Grenada
229 'KN', // Saint Kitts and Nevis
230 ];
231
232 $accountCountry = $this->settingRepository->getAccountCountry();
233
234 return in_array($accountCountry, $northAmericaCountryList, true);
235 }
236
237 /**
238 * Return admin guidance notice to fix PayPal on boarding error.
239 *
240 * @since 3.10.0 Updated phone number for contact
241 * @since 2.9.6
242 *
243 * @param bool $completeMessage
244 *
245 * @return string
246 */
247 public function getAdminGuidanceNotice($completeMessage = true)
248 {
249 if ($this->isCountryInNorthAmerica()) {
250 $telephone = sprintf(
251 '<a href="tel:%1$s">%1$s</a>',
252 '1-888-350-2387'
253 );
254
255 $message = sprintf(
256 esc_html__('Please call a PayPal support representative at %1$s', 'give'),
257 $telephone
258 );
259 } else {
260 $message = esc_html__(
261 'Please reach out to PayPal support from your PayPal account Resolution Center',
262 'give'
263 );
264 }
265
266 $message .= $completeMessage ? esc_html__(' and relay the following message:', 'give') : '.';
267
268 return $message;
269 }
270
271 /**
272 * Print on boarding errors.
273 *
274 * @since 2.9.6
275 */
276 private function printErrors(MerchantDetails $merchantDetailsRepository)
277 {
278 $accountErrors = $merchantDetailsRepository->getAccountErrors();
279
280 if (! empty($accountErrors)) :
281 ?>
282 <div>
283 <p class="error-message"><?php esc_html_e('Warning, your account is not ready to accept donations.', 'give'); ?></p>
284 <p>
285 <?php
286 printf(
287 '%1$s %2$s',
288 esc_html__(
289 'There is an issue with your PayPal account that is preventing you from being able to accept donations.',
290 'give'
291 ),
292 $this->getAdminGuidanceNotice()
293 )
294 ?>
295 </p>
296 <div class="paypal-message-template">
297 <?php esc_html_e('Greetings!', 'give'); ?><br><br>
298 <?php esc_html_e(
299 '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:',
300 'give'
301 );
302 ?><br>
303 <?php echo $this->formatErrors($accountErrors); ?>
304 <br>
305 <?php
306 esc_html_e(
307 'Please help me resolve these account errors so I can begin accepting payments via PayPal on GiveWP.',
308 'give'
309 );
310 ?>
311 </div>
312
313 <?php if ($this->merchantRepository->accountIsConnected()) :?>
314 <?php
315 $reCheckAccountStatusUrl = add_query_arg(
316 [
317 'post_type' => 'give_forms',
318 'page' => 'give-settings',
319 'tab' => 'gateways',
320 'section' => 'paypal',
321 'group' => 'paypal-commerce',
322 'paypalStatusCheck' => '1',
323 'mode' => $merchantDetailsRepository->getMode()
324 ],
325 admin_url('edit.php')
326 );
327 ?>
328 <p>
329 <a href="<?php echo $reCheckAccountStatusUrl; ?>">
330 <?php esc_html_e('Re-Check Account Status', 'give'); ?>
331 </a>
332 </p>
333 <?php endif; ?>
334
335 </div>
336 <?php endif;
337 }
338
339 /**
340 * Return format errors string.
341 *
342 * @since 2.9.6
343 *
344 * @param array $errors
345 *
346 * @return string
347 */
348 private function formatErrors($errors)
349 {
350 $isSingleError = ! (count($errors) > 1);
351 $formattedArray = array_map(
352 static function ($arr) use ($isSingleError) {
353 if (is_array($arr)) {
354 switch ($arr['type']) {
355 case 'url':
356 return sprintf(
357 '<%1$s>%2$s<br><code>%3$s</code></%1$s>',
358 $isSingleError ? 'p' : 'li',
359 $arr['message'],
360 urldecode_deep($arr['value'])
361 );
362
363 case 'json':
364 return sprintf(
365 '<%1$s>%2$s<br><code>%3$s</code></%1$s>',
366 $isSingleError ? 'p' : 'li',
367 $arr['message'],
368 $arr['value']
369 );
370 }
371 }
372
373 return sprintf(
374 '<%1$s>%2$s</%1$s>',
375 $isSingleError ? 'p' : 'li',
376 $arr
377 );
378 },
379 $errors
380 );
381
382 $output = implode('', $formattedArray);
383
384 if (! $isSingleError) {
385 $output = sprintf(
386 '<ul class="ul-disc">%1$s</ul>',
387 $output
388 );
389 }
390
391 return $output;
392 }
393
394 /**
395 * This function return html for "PayPal Connection" and "PayPal Sandbox Connection".
396 *
397 * @param \stdClass $paypalSetting PayPal setting data.
398 */
399 private function getPayPalConnectionSettingView(\stdClass $paypalSetting): string
400 {
401 ob_start();
402
403 /** @var MerchantDetails $mechantDetailsRepository */
404 $mechantDetailsRepository = give(MerchantDetails::class);
405 $mechantDetailsRepository->setMode($paypalSetting->mode);
406
407 $merchantDetail = $mechantDetailsRepository->getDetails();
408
409 $canShowAccountInformation = $mechantDetailsRepository->accountIsConnected();
410 ?>
411 <tr>
412 <th scope="row" class="titledesc">
413 <label for="give_paypal_commerce_country">
414 <?php echo $paypalSetting->label ?>
415 </label>
416 </th>
417 <td class="give-forminp">
418 <div class="give-paypal-commerce-account-manager-field-wrap">
419 <div class="connect-button-wrap">
420 <div
421 class="button-wrap connection-setting<?php echo $canShowAccountInformation ? ' give-hidden' : ''; ?>">
422 <div>
423 <button class="button button-primary button-large js-give-paypal-on-boarding-handler"
424 data-mode="<?php echo $paypalSetting->mode; ?>">
425 <i class="fab fa-paypal"></i>&nbsp;&nbsp;
426 <?php echo $paypalSetting->connectButtonLabel; ?>
427 </button>
428 <?php if ('live' === $paypalSetting->mode) : ?>
429 <span class="tooltip">
430 <span class="left-arrow"></span>
431 <?php esc_html_e('Click to get started!', 'give'); ?>
432 </span>
433 <?php // We are using one PayPal button to handle both sandbox and live mode connection.?>
434 <a class="give-hidden" target="PPFrame"
435 data-paypal-onboard-complete="givePayPalOnBoardedCallback" href="#"
436 data-paypal-button="true">
437 <?php esc_html_e('Sign up for PayPal', 'give'); ?>
438 </a>
439 <?php endif; ?>
440 </div>
441 <span class="give-field-description">
442 <i class="fa fa-exclamation"></i><?php echo $paypalSetting->description ?>
443 </span>
444 </div>
445 <div
446 class="button-wrap disconnection-setting<?php echo ! $canShowAccountInformation ? ' give-hidden' : ''; ?>">
447 <div>
448 <button class="button button-large disabled" disabled="disabled">
449 <i class="fab fa-paypal"></i>&nbsp;&nbsp;<?php
450 esc_html_e('Connected', 'give'); ?>
451 </button>
452 </div>
453 <div>
454 <span class="give-field-description">
455 <i class="fa fa-check"></i>
456 <?php
457 if ($merchantDetail->accountIsReady) {
458 $connectedAccountTypeMessage = $merchantDetail->supportsCustomPayments
459 ? esc_html__('Connected as Advanced for payments as', 'give')
460 : esc_html__('Connected as Standard for payments as', 'give');
461 } else {
462 $connectedAccountTypeMessage = esc_html__('Connected for payments as', 'give');
463 }
464
465 printf(
466 '%1$s <span class="paypal-account-email">%2$s</span>',
467 $connectedAccountTypeMessage,
468 $merchantDetail->merchantId
469 );
470 ?>
471 </span>
472 <span class="actions">
473 <button
474 class="js-give-paypal-disconnect-paypal-account"
475 data-mode="<?php echo $paypalSetting->mode; ?>">
476 <?php esc_html_e('Disconnect', 'give'); ?>
477 </button>
478 </span>
479 </div>
480 </div>
481 <?php $this->printErrors($mechantDetailsRepository); ?>
482 </div>
483 </div>
484 </td>
485 </tr>
486 <?php
487 return ob_get_clean();
488 }
489
490 /**
491 * @since 2.33.0
492 */
493 private function getBanner(): string
494 {
495 ob_start();
496
497 if (
498 give(MerchantDetail::class)->accountIsReady
499 && give_is_gateway_active(PayPalCommerce::id())
500 ) {
501 return '';
502 }
503 ?>
504 <tr>
505 <th scope="row" class="titledesc">
506 </th>
507 <td class="give-forminp">
508 <?php echo give(PayPalDonationsSettingPageBanner::class)->render(); ?>
509 </td>
510 </tr>
511 <?php
512 return ob_get_clean();
513 }
514 }
515