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