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