PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.11.0
GiveWP – Donation Plugin and Fundraising Platform v2.11.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
DataTransferObjects 5 years ago Models 5 years ago Repositories 5 years ago Webhooks 5 years ago AccountAdminNotices.php 5 years ago AdminSettingFields.php 5 years ago AdvancedCardFields.php 5 years ago AjaxRequestHandler.php 5 years ago DonationDetailsPage.php 5 years ago DonationFormPaymentMethod.php 5 years ago DonationProcessor.php 5 years ago PayPalClient.php 5 years ago PayPalCommerce.php 5 years ago RefreshToken.php 5 years ago RefundPaymentHandler.php 5 years ago ScriptLoader.php 5 years ago Utils.php 5 years ago onBoardingRedirectHandler.php 5 years ago
AdminSettingFields.php
392 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 * @since 2.9.0
14 * @package Give\PaymentGateways\PayPalCommerce
15 *
16 */
17 class AdminSettingFields {
18 /**
19 * @var MerchantDetail
20 */
21 private $merchantModel;
22
23 /**
24 * @var Settings
25 */
26 private $settingRepository;
27
28 /**
29 * @var MerchantDetails
30 */
31 private $merchantRepository;
32
33 /**
34 * AdminSettingFields constructor.
35 *
36 * @param MerchantDetail $merchantDetail
37 * @param MerchantDetails $merchantDetailRepository
38 * @param Settings $settings
39 */
40 public function __construct( MerchantDetail $merchantDetail, MerchantDetails $merchantDetailRepository, Settings $settings ) {
41 $this->merchantModel = $merchantDetail;
42 $this->merchantRepository = $merchantDetailRepository;
43 $this->settingRepository = $settings;
44 }
45
46 /**
47 * Bootstrap fields.
48 *
49 * @since 2.9.0
50 */
51 public function boot() {
52 add_action( 'give_admin_field_paypal_commerce_account_manger', [ $this, 'payPalCommerceAccountManagerField' ] );
53 add_action( 'give_admin_field_paypal_commerce_account_country', [ $this, 'accountCountryField' ] );
54 add_action( 'give_admin_field_paypal_commerce_introduction', [ $this, 'introductionSection' ] );
55 }
56
57 /**
58 * Render account country field.
59 *
60 * @since 2.9.0
61 */
62 public function accountCountryField() {
63 /* @var Give_HTML_Elements $htmlElements */
64 $htmlElements = give( 'html' );
65
66 $settingHtml = $htmlElements->select(
67 [
68 'id' => 'paypal_commerce_account_country',
69 'options' => give_get_country_list(),
70 'chosen' => true,
71 'placeholder' => esc_html__( 'Choose a country', 'give' ),
72 'show_option_all' => false,
73 'show_option_none' => false,
74 'data' => [
75 'search-type' => 'no_ajax',
76 ],
77 'selected' => $this->merchantModel->accountCountry ?: $this->settingRepository->getAccountCountry(),
78 ]
79 );
80
81 $trClass = $this->merchantRepository->accountIsConnected() ?
82 'js-fields-has-custom-saving-logic hide-with-position' :
83 'js-fields-has-custom-saving-logic';
84 ?>
85 <tr valign="top" class="<?php echo $trClass; ?>">
86 <th scope="row" class="titledesc">
87 <label for="give_paypal_commerce_country"><?php esc_html_e( 'Account Country', 'give' ); ?></label>
88 </th>
89 <td class="give-forminp">
90 <?php
91 printf(
92 '%1$s<div class="give-field-description">%2$s</div>',
93 $settingHtml,
94 esc_html__( 'The country your site operates from.', 'give' )
95 )
96 ?>
97 </td>
98 </tr>
99 <?php
100 }
101
102 /**
103 * Paypal Checkout account manager custom field
104 *
105 * @since 2.9.0
106 */
107 public function payPalCommerceAccountManagerField() {
108 $recurringAddonInfo = Give_License::get_plugin_by_slug( 'give-recurring' );
109 $isRecurringAddonActive = isset( $recurringAddonInfo['Status'] ) && 'active' === $recurringAddonInfo['Status'];
110 ?>
111 <tr valign="top">
112 <th scope="row" class="titledesc">
113 <label for="give_paypal_commerce_country"><?php esc_html_e( 'PayPal Connection', 'give' ); ?></label>
114 </th>
115 <td class="give-forminp">
116 <div id="give-paypal-commerce-account-manager-field-wrap">
117 <div class="connect-button-wrap">
118 <?php
119 /** @var MerchantDetails $accountRepository */
120 $accountRepository = give( MerchantDetails::class );
121 ?>
122 <div class="button-wrap connection-setting <?php echo $accountRepository->accountIsConnected() ? 'give-hidden' : ''; ?>">
123 <div>
124 <button class="button button-primary button-large" id="js-give-paypal-on-boarding-handler">
125 <i class="fab fa-paypal"></i>&nbsp;&nbsp;
126 <?php
127 esc_html_e(
128 'Connect with PayPal',
129 'give'
130 );
131 ?>
132 </button>
133 <a class="give-hidden" target="_blank"
134 data-paypal-onboard-complete="givePayPalOnBoardedCallback" href="#"
135 data-paypal-button="true">
136 <?php esc_html_e( 'Sign up for PayPal', 'give' ); ?>
137 </a>
138 <span class="tooltip">
139 <span class="left-arrow"></span>
140 <?php esc_html_e( 'Click to get started!', 'give' ); ?>
141 </span>
142 </div>
143 <span class="give-field-description">
144 <i class="fa fa-exclamation"></i>
145 <?php esc_html_e( 'PayPal is currently NOT connected.', 'give' ); ?>
146 </span>
147 </div>
148 <div class="button-wrap disconnection-setting <?php echo ! $accountRepository->accountIsConnected() ? 'give-hidden' : ''; ?>">
149 <div>
150 <button class="button button-large disabled" disabled="disabled">
151 <i class="fab fa-paypal"></i>&nbsp;&nbsp;<?php esc_html_e( 'Connected', 'give' ); ?>
152 </button>
153 </div>
154 <div>
155 <span class="give-field-description">
156 <i class="fa fa-check"></i>
157 <?php
158 printf(
159 '%1$s <span class="paypal-account-email">%2$s</span>',
160 esc_html__( 'Connected for payments as', 'give' ),
161 give( MerchantDetail::class )->merchantId
162 );
163 ?>
164 </span>
165 <span class="actions">
166 <a href="#"
167 id="js-give-paypal-disconnect-paypal-account"><?php esc_html_e( 'Disconnect', 'give' ); ?></a>
168 </span>
169 </div>
170 <div class="api-access-feature-list-wrap">
171 <p><?php esc_html_e( 'APIs Connected:', 'give' ); ?></p>
172 <ul>
173 <li><?php esc_html_e( 'Payments', 'give' ); ?></li>
174 <?php if ( $isRecurringAddonActive ) : ?>
175 <li><?php esc_html_e( 'Subscriptions', 'give' ); ?></li>
176 <?php endif; ?>
177 <li><?php esc_html_e( 'Refunds', 'give' ); ?></li>
178 </ul>
179 </div>
180 </div>
181 <?php $this->printErrors(); ?>
182 </div>
183 </div>
184 </td>
185 </tr>
186 <?php
187 }
188
189
190 /**
191 * PayPal Commerce introduction section.
192 *
193 * @since 2.9.0
194 */
195 public function introductionSection() {
196 ?>
197 <div id="give-paypal-commerce-introduction-wrap">
198 <div class="hero-section">
199 <div>
200 <h2><?php esc_html_e( 'Accept Donations with PayPal Donations', 'give' ); ?></h2>
201 <p class="give-field-description"><?php esc_html_e( 'Allow your donors to give using Debit or Credit Cards directly on your website with no additional fees.', 'give' ); ?></p>
202 </div>
203 <div class="paypal-logo">
204 <img src="<?php echo GIVE_PLUGIN_URL . '/assets/dist/images/admin/paypal-logo.svg'; ?>" width="316" height="84" alt="<?php esc_attr_e( 'PayPal Logo Image', 'give' ); ?>">
205 </div>
206 </div>
207 <div class="feature-list">
208 <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Credit and Debit Card Donations', 'give' ); ?>
209 </div>
210 <div>
211 <i class="fa fa-angle-right"></i><?php esc_html_e( 'Improve donation conversion rates', 'give' ); ?>
212 </div>
213 <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Easy no-API key connection', 'give' ); ?></div>
214 <div>
215 <i class="fa fa-angle-right"></i><?php esc_html_e( 'Accept payments from around the world', 'give' ); ?>
216 </div>
217 <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Donate via PayPal accounts', 'give' ); ?>
218 </div>
219 <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Supports 3D Secure payments', 'give' ); ?>
220 </div>
221 </div>
222 </div>
223 <?php
224 }
225
226 /**
227 * Return whether or not country is in North America
228 *
229 * @return boolean
230 */
231 private function isCountryInNorthAmerica() {
232 // Countries list: https://en.wikipedia.org/wiki/List_of_North_American_countries_by_area#Countries
233 $northAmericaCountryList = [
234 'CA', // Canada
235 'US', // United States
236 'MX', // Mexico
237 'NI', // Nicaragua
238 'HN', // Honduras
239 'CU', // Cuba
240 'GT', // Guatemala
241 'PA', // Panama
242 'CR', // Costa Rica
243 'DO', // Dominican Republic
244 'HT', // Haiti
245 'BZ', // Belize
246 'SV', // EL Salvador
247 'BS', // The Bahamas
248 'JM', // Jamaica
249 'TT', // Trinidad and Tobago
250 'DM', // Dominica
251 'LC', // Saint Lucia
252 'AG', // Antigua and Barbuda
253 'BB', // Barbados
254 'VC', // Saint Vincent and the Grenadines
255 'GD', // Grenada
256 'KN', // Saint Kitts and Nevis
257 ];
258
259 $accountCountry = $this->settingRepository->getAccountCountry();
260
261 return in_array( $accountCountry, $northAmericaCountryList, true );
262 }
263
264 /**
265 * Return admin guidance notice to fix PayPal on boarding error.
266 *
267 * @since 2.9.6
268 *
269 * @param bool $completeMessage
270 *
271 * @return string
272 */
273 public function getAdminGuidanceNotice( $completeMessage = true ) {
274 if ( $this->isCountryInNorthAmerica() ) {
275 $telephone = sprintf(
276 '<a href="tel:%1$s">%1$s</a>',
277 '1-855-456-1330'
278 );
279
280 $message = sprintf(
281 esc_html__( 'Please call a PayPal support representative at %1$s', 'give' ),
282 $telephone
283 );
284 } else {
285 $message = esc_html__( 'Please reach out to PayPal support from your PayPal account Resolution Center', 'give' );
286 }
287
288 $message .= $completeMessage ? esc_html__( ' and relay the following message:', 'give' ) : '.';
289
290 return $message;
291 }
292
293 /**
294 * Print on boarding errors.
295 *
296 * @since 2.9.6
297 */
298 private function printErrors() {
299 $accountErrors = give( MerchantDetails::class )->getAccountErrors();
300 $hasUnknownPayPalError = isset( $_GET['paypal-error'] );
301
302 if ( ! empty( $accountErrors ) ) :
303 ?>
304 <div>
305 <p class="error-message"><?php esc_html_e( 'Warning, your account is not ready to accept donations.', 'give' ); ?></p>
306 <p>
307 <?php
308 printf(
309 '%1$s %2$s',
310 esc_html__(
311 'There is an issue with your PayPal account that is preventing you from being able to accept donations.',
312 'give'
313 ),
314 $this->getAdminGuidanceNotice()
315 )
316 ?>
317 </p>
318 <div class="paypal-message-template">
319 <?php esc_html_e( 'Greetings!', 'give' ); ?><br><br>
320 <?php esc_html_e( '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:', 'give' ); ?><br>
321 <?php echo $this->formatErrors( $accountErrors ); ?>
322 <br><?php esc_html_e( 'Please help me resolve these account errors so I can begin accepting payments via PayPal on GiveWP.', 'give' ); ?>
323 </div>
324
325 <?php if ( $this->merchantRepository->accountIsConnected() ) : ?>
326 <p>
327 <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways&section=paypal&paypalStatusCheck' ); ?>">
328 <?php esc_html_e( 'Re-Check Account Status', 'give' ); ?>
329 </a>
330 </p>
331 <?php endif; ?>
332
333 </div>
334 <?php
335 endif;
336 }
337
338 /**
339 * Return format errors string.
340 *
341 * @since 2.9.6
342 * @param array $errors
343 *
344 * @return string
345 */
346 private function formatErrors( $errors ) {
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 },
377 $errors
378 );
379
380 $output = implode( '', $formattedArray );
381
382 if ( ! $isSingleError ) {
383 $output = sprintf(
384 '<ul class="ul-disc">%1$s</ul>',
385 $output
386 );
387 }
388
389 return $output;
390 }
391 }
392