@@ -38,553 +38,553 @@ |
||
38 | 38 | */ |
39 | 39 | class BillingForm extends EE_Billing_Attendee_Info_Form |
40 | 40 | { |
41 | - /** |
|
42 | - * Filepath to template files |
|
43 | - * |
|
44 | - * @var @template_path |
|
45 | - */ |
|
46 | - protected $template_path; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var EE_Transaction |
|
50 | - */ |
|
51 | - protected $transaction; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var EE_PMT_PayPalCheckout |
|
55 | - */ |
|
56 | - protected $paypal_pmt; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - protected $checkout_type; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Class constructor. |
|
66 | - * |
|
67 | - * @param EE_Payment_Method $payment_method |
|
68 | - * @param array $options |
|
69 | - * @throws EE_Error |
|
70 | - * @throws ReflectionException |
|
71 | - */ |
|
72 | - public function __construct(EE_Payment_Method $payment_method, array $options = []) |
|
73 | - { |
|
74 | - $this->paypal_pmt = $payment_method; |
|
75 | - // Can't be too careful. |
|
76 | - $this->transaction = $options['transaction'] ?? null; |
|
77 | - $this->template_path = $options['template_path'] ?? ''; |
|
78 | - $this->checkout_type = $payment_method->get_extra_meta(Domain::META_KEY_CHECKOUT_TYPE, true, ''); |
|
79 | - $pm_slug = $payment_method->slug(); |
|
80 | - $parameters = array_replace_recursive( |
|
81 | - $options, |
|
82 | - [ |
|
83 | - 'name' => 'PayPalCommerceBillingForm', |
|
84 | - 'html_id' => 'pp-' . $pm_slug . '-billing-form', |
|
85 | - 'html_class' => 'pp_commerce_billing_form', |
|
86 | - 'subsections' => [ |
|
87 | - 'eea_paypal_commerce_token' => new EE_Hidden_Input( |
|
88 | - [ |
|
89 | - 'html_id' => 'eea-paypal-commerce-token', |
|
90 | - 'html_name' => 'EEA_paymentToken', |
|
91 | - 'default' => '', |
|
92 | - ] |
|
93 | - ), |
|
94 | - 'pp_order_nonce' => new EE_Hidden_Input( |
|
95 | - [ |
|
96 | - 'html_id' => 'eea-' . $pm_slug . '-order-nonce', |
|
97 | - 'html_name' => 'pp_order_nonce', |
|
98 | - 'default' => '', |
|
99 | - ] |
|
100 | - ), |
|
101 | - 'pp_order_id' => new EE_Hidden_Input( |
|
102 | - [ |
|
103 | - 'html_id' => 'eea-' . $pm_slug . '-order-id', |
|
104 | - 'html_name' => 'pp_order_id', |
|
105 | - 'default' => '', |
|
106 | - ] |
|
107 | - ), |
|
108 | - 'pp_order_status' => new EE_Hidden_Input( |
|
109 | - [ |
|
110 | - 'html_id' => 'eea-' . $pm_slug . '-order-status', |
|
111 | - 'html_name' => 'pp_order_status', |
|
112 | - 'default' => '', |
|
113 | - ] |
|
114 | - ), |
|
115 | - 'pp_order_amount' => new EE_Hidden_Input( |
|
116 | - [ |
|
117 | - 'html_id' => 'eea-' . $pm_slug . '-order-amount', |
|
118 | - 'html_name' => 'pp_order_amount', |
|
119 | - 'default' => '', |
|
120 | - ] |
|
121 | - ), |
|
122 | - ], |
|
123 | - ] |
|
124 | - ); |
|
125 | - // Add data tags to the PP script. |
|
126 | - add_filter('script_loader_tag', [$this, 'addDataTagsToScript'], 10, 2); |
|
127 | - parent::__construct($payment_method, $parameters); |
|
128 | - // Add and exclude other sections. |
|
129 | - $this->addPaymentSections(); |
|
130 | - // Additional actions and/or filters. |
|
131 | - $this->loadActionsAndFilters(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Add PayPal payment sections. |
|
137 | - * |
|
138 | - * @return void |
|
139 | - * @throws EE_Error |
|
140 | - * @throws ReflectionException |
|
141 | - */ |
|
142 | - public function addPaymentSections(): void |
|
143 | - { |
|
144 | - // Exclude the default billing form fields. |
|
145 | - $this->exclude([ |
|
146 | - 'first_name', |
|
147 | - 'last_name', |
|
148 | - 'email', |
|
149 | - ]); |
|
150 | - // Add PayPal Hosted Fields. |
|
151 | - if ($this->checkout_type !== 'express_checkout') { |
|
152 | - $this->addAdvancedCardFields(); |
|
153 | - } |
|
154 | - // Add payment types separator, if both are enabled. |
|
155 | - if ($this->checkout_type === 'all') { |
|
156 | - $this->addTypesSeparator(); |
|
157 | - } |
|
158 | - // Add PayPal Buttons section. |
|
159 | - if ($this->checkout_type !== 'ppcp') { |
|
160 | - $this->add_subsections( |
|
161 | - [ |
|
162 | - 'paypal_commerce_pm_form' => $this->addPayPalCheckout(), |
|
163 | - ] |
|
164 | - ); |
|
165 | - } |
|
166 | - // Exclude the rest billing form fields if the payment type is express checkout. |
|
167 | - if ($this->checkout_type === 'express_checkout') { |
|
168 | - $this->exclude([ |
|
169 | - 'address', |
|
170 | - 'address2', |
|
171 | - 'state', |
|
172 | - 'phone', |
|
173 | - 'city', |
|
174 | - 'country', |
|
175 | - 'zip', |
|
176 | - ]); |
|
177 | - // Remove the Info subsection. |
|
178 | - add_filter('FHEE__EE_Form_Section_Proper___construct__options_array', [$this, 'excludeInfoSubsection']); |
|
179 | - } |
|
180 | - $this->add_subsections( |
|
181 | - [ |
|
182 | - 'debug_content' => $this->addDebugContent($this->paypal_pmt), |
|
183 | - ] |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Additional actions and/or filters. |
|
190 | - * |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function loadActionsAndFilters(): void |
|
194 | - { |
|
195 | - add_filter( |
|
196 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
197 | - [__CLASS__, 'excludeBillingFormFields'], |
|
198 | - 10, |
|
199 | - 2 |
|
200 | - ); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Filter out billing form fields if pay button was used. |
|
206 | - * |
|
207 | - * @param EE_Billing_Info_Form $billing_form |
|
208 | - * @param EE_Payment_Method $payment_method |
|
209 | - * @return EE_Billing_Info_Form |
|
210 | - */ |
|
211 | - public static function excludeBillingFormFields( |
|
212 | - EE_Billing_Info_Form $billing_form, |
|
213 | - EE_Payment_Method $payment_method |
|
214 | - ): EE_Billing_Info_Form { |
|
215 | - $request = LoaderFactory::getShared(Request::class); |
|
216 | - $request_params = $request->requestParams(); |
|
217 | - if ( |
|
218 | - // Only the PPC billing form. |
|
219 | - $billing_form instanceof BillingForm |
|
220 | - && ! empty($request_params['process_form_submission']) |
|
221 | - && $request_params['process_form_submission'] === '1' |
|
222 | - && ! empty($request_params['eep_ppc_skip_form_validation']) |
|
223 | - ) { |
|
224 | - // Hide card info fields. |
|
225 | - $billing_form->exclude([ |
|
226 | - 'pp_name_on_card', |
|
227 | - 'address', |
|
228 | - 'address2', |
|
229 | - 'state', |
|
230 | - 'phone', |
|
231 | - 'city', |
|
232 | - 'country', |
|
233 | - 'zip', |
|
234 | - ]); |
|
235 | - } |
|
236 | - return $billing_form; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Add advanced card & debit card fields. |
|
242 | - * |
|
243 | - * @return void |
|
244 | - * @throws EE_Error|ReflectionException |
|
245 | - */ |
|
246 | - public function addAdvancedCardFields(): void |
|
247 | - { |
|
248 | - $pm_slug = $this->paypal_pmt->slug(); |
|
249 | - $this->add_subsections( |
|
250 | - [ |
|
251 | - 'pp_card_number' => new EE_Form_Section_HTML( |
|
252 | - EEH_HTML::label( |
|
253 | - esc_html__('Card Number', 'event_espresso'), |
|
254 | - "$pm_slug-card-number-lbl", |
|
255 | - "$pm_slug-card-fields", |
|
256 | - "", |
|
257 | - 'for="' . $pm_slug . '-card-number"' |
|
258 | - ) . |
|
259 | - EEH_HTML::p( |
|
260 | - "", |
|
261 | - "$pm_slug-card-number", |
|
262 | - "card_field $pm_slug-card-fields" |
|
263 | - ) |
|
264 | - ), |
|
265 | - 'pp_expiration_date' => new EE_Form_Section_HTML( |
|
266 | - EEH_HTML::label( |
|
267 | - esc_html__('Expiration Date', 'event_espresso'), |
|
268 | - "$pm_slug-expiration-date-lbl", |
|
269 | - "$pm_slug-card-fields", |
|
270 | - "", |
|
271 | - 'for="' . $pm_slug . '-expiration-date"' |
|
272 | - ) . |
|
273 | - EEH_HTML::p( |
|
274 | - "", |
|
275 | - "$pm_slug-expiration-date", |
|
276 | - "card_field $pm_slug-card-fields" |
|
277 | - ) |
|
278 | - ), |
|
279 | - 'pp_card_cvv' => new EE_Form_Section_HTML( |
|
280 | - EEH_HTML::label( |
|
281 | - esc_html__('CVV', 'event_espresso'), |
|
282 | - "$pm_slug-cvv-lbl", |
|
283 | - "$pm_slug-card-fields", |
|
284 | - "", |
|
285 | - 'for="' . $pm_slug . '-cvv"' |
|
286 | - ) . |
|
287 | - EEH_HTML::p( |
|
288 | - "", |
|
289 | - "$pm_slug-cvv", |
|
290 | - "card_field $pm_slug-card-fields" |
|
291 | - ) |
|
292 | - ), |
|
293 | - 'pp_name_on_card' => new EE_Text_Input( |
|
294 | - [ |
|
295 | - 'html_label_text' => esc_html__('Name On Card', 'event_espresso'), |
|
296 | - 'html_id' => $pm_slug . '-card-holder-name', |
|
297 | - 'html_name' => 'card-holder-name', |
|
298 | - 'html_class' => '', |
|
299 | - 'required' => true, |
|
300 | - ] |
|
301 | - ), |
|
302 | - ] |
|
303 | - ); |
|
304 | - // Add the submit button at the end. |
|
305 | - $this->add_subsections( |
|
306 | - [ |
|
307 | - 'pp_cc_submit' => new EE_Submit_Input( |
|
308 | - [ |
|
309 | - 'html_label_text' => esc_html__('Submit', 'event_espresso'), |
|
310 | - 'html_id' => $pm_slug, |
|
311 | - 'html_class' => 'eep-ppc-btn', |
|
312 | - ] |
|
313 | - ), |
|
314 | - ], |
|
315 | - 'phone', |
|
316 | - false |
|
317 | - ); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Add advanced card & debit card fields. |
|
323 | - * |
|
324 | - * @return void |
|
325 | - * @throws EE_Error|ReflectionException |
|
326 | - */ |
|
327 | - public function addTypesSeparator(): void |
|
328 | - { |
|
329 | - $this->add_subsections( |
|
330 | - [ |
|
331 | - 'pp_payment_types_separator' => new EE_Form_Section_HTML( |
|
332 | - EEH_HTML::div( |
|
333 | - EEH_HTML::div( |
|
334 | - ' ', |
|
335 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
336 | - 'eep-ppc-separator-line eep-left-floating' |
|
337 | - ) . |
|
338 | - EEH_HTML::div( |
|
339 | - esc_html__(' or ', 'event_espresso'), |
|
340 | - 'eep-' . $this->paypal_pmt->slug() . '-separator-text', |
|
341 | - 'eep-ppc-separator-text1 eep-mid-floating' |
|
342 | - ) . EEH_HTML::div( |
|
343 | - ' ', |
|
344 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
345 | - 'eep-ppc-separator-line eep-right-floating' |
|
346 | - ), |
|
347 | - 'eep-ppc-separator-holder', |
|
348 | - 'eep-ppc-separator-holder' |
|
349 | - ) |
|
350 | - ), |
|
351 | - ] |
|
352 | - ); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Exclude the info subsection from the PPC checkout form. |
|
358 | - * |
|
359 | - * @param array $options_array |
|
360 | - * @return array |
|
361 | - * @throws EE_Error |
|
362 | - * @throws ReflectionException |
|
363 | - */ |
|
364 | - public function excludeInfoSubsection(array $options_array): array |
|
365 | - { |
|
366 | - if (! empty($options_array['html_id']) |
|
367 | - && $options_array['html_id'] === 'spco-payment-method-info-' . $this->paypal_pmt->slug() |
|
368 | - ) { |
|
369 | - if (! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
370 | - unset($options_array['subsections']['info']); |
|
371 | - } |
|
372 | - } |
|
373 | - return $options_array; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Possibly adds debug content to PayPal commerce billing form. |
|
379 | - * |
|
380 | - * @param EE_Payment_Method $paypal_pm |
|
381 | - * @return EE_Form_Section_Base |
|
382 | - * @throws EE_Error|ReflectionException |
|
383 | - */ |
|
384 | - public function addDebugContent(EE_Payment_Method $paypal_pm): EE_Form_Section_Base |
|
385 | - { |
|
386 | - if ($paypal_pm->debug_mode()) { |
|
387 | - return new EE_Form_Section_Proper( |
|
388 | - [ |
|
389 | - 'layout_strategy' => new EE_Template_Layout( |
|
390 | - [ |
|
391 | - 'layout_template_file' => $this->template_path . 'debugInfo.template.php', |
|
392 | - 'template_args' => [], |
|
393 | - ] |
|
394 | - ), |
|
395 | - ] |
|
396 | - ); |
|
397 | - } |
|
398 | - return new EE_Form_Section_HTML(); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Add PayPal checkout buttons. |
|
404 | - * |
|
405 | - * @return EE_Form_Section_Proper |
|
406 | - * @throws EE_Error |
|
407 | - */ |
|
408 | - public function addPayPalCheckout(): EE_Form_Section_Proper |
|
409 | - { |
|
410 | - $template_args['pm_slug'] = $this->paypal_pmt->slug(); |
|
411 | - return new EE_Form_Section_Proper( |
|
412 | - [ |
|
413 | - 'layout_strategy' => new EE_Template_Layout( |
|
414 | - [ |
|
415 | - 'layout_template_file' => $this->template_path . 'paymentButtons.template.php', |
|
416 | - 'template_args' => $template_args, |
|
417 | - ] |
|
418 | - ), |
|
419 | - ] |
|
420 | - ); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Load scripts and localize data needed for this form. |
|
426 | - * |
|
427 | - * @param $tag |
|
428 | - * @param $handle |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public function addDataTagsToScript($tag, $handle): string |
|
432 | - { |
|
433 | - if ($handle === 'eea_paypal_commerce_js_lib') { |
|
434 | - $bn_code = PayPalExtraMetaManager::getPmOption($this->_pm_instance, Domain::META_KEY_BN_CODE); |
|
435 | - $response = EED_PayPalCommerce::requestClientToken($this->paypal_pmt); |
|
436 | - if (empty($response['client_token'])) { |
|
437 | - return $tag; |
|
438 | - } |
|
439 | - $client_token = $response['client_token']; |
|
440 | - $attributes = " data-partner-attribution-id=\"$bn_code\" data-client-token=\"$client_token\""; |
|
441 | - $tag = str_replace('></script>', $attributes . '></script>', $tag); |
|
442 | - } |
|
443 | - return $tag; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Load scripts and localize data needed for this form. |
|
449 | - * |
|
450 | - * @return void |
|
451 | - * @throws EE_Error |
|
452 | - * @throws ReflectionException |
|
453 | - * @throws Exception |
|
454 | - */ |
|
455 | - public function enqueue_js(): void |
|
456 | - { |
|
457 | - $third_party = EED_PayPalCommerce::isThirdParty($this->_pm_instance); |
|
458 | - $currency = CurrencyManager::currencyCode(); |
|
459 | - $client_id_key = Domain::META_KEY_CLIENT_ID; |
|
460 | - // Scripts. |
|
461 | - $scripts_src = 'https://www.paypal.com/sdk/js?components=buttons,hosted-fields&intent=capture'; |
|
462 | - if ($third_party) { |
|
463 | - $client_id_key = Domain::META_KEY_PARTNER_CLIENT_ID; |
|
464 | - $merchant_id = PayPalExtraMetaManager::getPmOption( |
|
465 | - $this->_pm_instance, |
|
466 | - Domain::META_KEY_SELLER_MERCHANT_ID |
|
467 | - ); |
|
468 | - $scripts_src .= "&merchant-id=$merchant_id"; |
|
469 | - } |
|
470 | - $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
471 | - $scripts_src .= "&client-id=$client_id¤cy=$currency"; |
|
472 | - wp_enqueue_script('eea_paypal_commerce_js_lib', $scripts_src, [], null); |
|
473 | - wp_enqueue_script( |
|
474 | - 'eea_paypal_commerce_js', |
|
475 | - EEP_PAYPAL_COMMERCE_URL . 'assets/js/paypal-commerce-payments.js', |
|
476 | - ['eea_paypal_commerce_js_lib'], |
|
477 | - EVENT_ESPRESSO_VERSION, |
|
478 | - true |
|
479 | - ); |
|
480 | - // Styles. |
|
481 | - wp_enqueue_style( |
|
482 | - 'eea_paypal_checkout_form_styles', |
|
483 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-checkout.css', |
|
484 | - [], |
|
485 | - EVENT_ESPRESSO_VERSION |
|
486 | - ); |
|
487 | - // Localize the script with our transaction data. |
|
488 | - $parameters = $this->localizeParameters(); |
|
489 | - wp_localize_script('eea_paypal_commerce_js', 'eeaPPCommerceParameters', $parameters); |
|
490 | - parent::enqueue_js(); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * Get PayPal order ID if already created for this transaction. |
|
496 | - * |
|
497 | - * @param string $transaction_id |
|
498 | - * @return string |
|
499 | - */ |
|
500 | - public function getPpOrderId(string $transaction_id): string |
|
501 | - { |
|
502 | - try { |
|
503 | - $pp_order = PayPalExtraMetaManager::getPmOption($this->paypal_pmt, Domain::META_KEY_LAST_ORDER); |
|
504 | - $pp_order_txn_id = $pp_order['ee_txn_id'] ?? false; |
|
505 | - if ($pp_order_txn_id != $transaction_id) { |
|
506 | - // Old order data, delete it. |
|
507 | - PayPalExtraMetaManager::deletePmOption($this->paypal_pmt, Domain::META_KEY_LAST_ORDER); |
|
508 | - return ''; |
|
509 | - } |
|
510 | - } catch (Exception $exception) { |
|
511 | - return ''; |
|
512 | - } |
|
513 | - return $pp_order['id'] ?? ''; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Form and return PayPal commerce parameters for script localization. |
|
519 | - * |
|
520 | - * @return array |
|
521 | - * @throws EE_Error |
|
522 | - * @throws ReflectionException |
|
523 | - * @throws Exception |
|
524 | - */ |
|
525 | - public function localizeParameters(): array |
|
526 | - { |
|
527 | - // Also tell the script about each instance of this PM. |
|
528 | - $pm_versions = []; |
|
529 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active( |
|
530 | - EEM_Payment_Method::scope_cart, |
|
531 | - [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
|
532 | - ); |
|
533 | - foreach ($active_payment_methods as $payment_method) { |
|
534 | - $pm_versions[ $payment_method->slug() ] = [ |
|
535 | - 'pm_slug' => $payment_method->slug(), |
|
536 | - ]; |
|
537 | - } |
|
538 | - |
|
539 | - // Convert money for a display format. |
|
540 | - $decimal_places = CurrencyManager::getDecimalPlaces(); |
|
541 | - $org_country = isset(EE_Registry::instance()->CFG->organization) |
|
542 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
543 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
544 | - : 'US'; |
|
545 | - $transaction_id = $this->transaction instanceof EE_Transaction ? $this->transaction->ID() : 0; |
|
546 | - $currency_code = CurrencyManager::currencyCode(); |
|
547 | - return [ |
|
548 | - 'pm_versions' => $pm_versions, |
|
549 | - 'payment_currency' => $currency_code, |
|
550 | - 'checkout_type' => $this->checkout_type, |
|
551 | - 'currency_sign' => EE_Registry::instance()->CFG->currency->sign, |
|
552 | - 'pp_order_id' => $this->getPpOrderId($transaction_id), |
|
553 | - 'pp_order_nonce' => wp_create_nonce(Domain::CAPTURE_ORDER_NONCE_NAME), |
|
554 | - // The transaction ID is only used for logging errors. |
|
555 | - 'txn_id' => $transaction_id, |
|
556 | - 'org_country' => $org_country, |
|
557 | - 'decimal_places' => $decimal_places, |
|
558 | - 'site_name' => get_bloginfo('name'), |
|
559 | - 'active_states' => EED_PayPalCommerce::getActiveStates(), |
|
560 | - 'no_spco_error' => esc_html__( |
|
561 | - 'It appears the SDK script was not loaded properly! Please refresh the page and try again or contact support.', |
|
562 | - 'event_espresso' |
|
563 | - ), |
|
564 | - 'no_pm_error' => esc_html__( |
|
565 | - 'It appears that PayPal Commerce checkout JavaScript was not loaded properly! Please refresh the page and try again or contact support. PayPal Commerce payments can\'t be processed.', |
|
566 | - 'event_espresso' |
|
567 | - ), |
|
568 | - 'browser_not_supported' => esc_html__( |
|
569 | - 'It appears that this browser is not supported by PayPal scripts. We apologize, but PayPal payments won\'t work in this browser version.', |
|
570 | - 'event_espresso' |
|
571 | - ), |
|
572 | - 'get_token_error' => esc_html__( |
|
573 | - 'There was an error while trying to get the payment token. Please refresh the page and try again or contact support.', |
|
574 | - 'event_espresso' |
|
575 | - ), |
|
576 | - 'form_validation_notice' => esc_html__('Billing form information not valid.', 'event_espresso'), |
|
577 | - 'no_verification_token' => esc_html__('Missing the Verification token.', 'event_espresso'), |
|
578 | - 'error_response' => esc_html__('Got an error response (AJAX)', 'event_espresso'), |
|
579 | - 'payment_error' => esc_html__( |
|
580 | - 'There was an error with this payment. See the logs for details.', |
|
581 | - 'event_espresso' |
|
582 | - ), |
|
583 | - 'no_order_id' => esc_html__('No Order ID found.', 'event_espresso'), |
|
584 | - 'general_pp_error' => esc_html__('PayPal form threw an error.', 'event_espresso'), |
|
585 | - 'hf_render_error' => esc_html__('Hosted fields could not be rendered!', 'event_espresso'), |
|
586 | - 'pm_capture_error' => esc_html__('Payment could not be captured!', 'event_espresso'), |
|
587 | - 'not_acdc_eligible' => esc_html__('This merchant is not eligible for Advanced Card Fields checkout type.', 'event_espresso'), |
|
588 | - ]; |
|
589 | - } |
|
41 | + /** |
|
42 | + * Filepath to template files |
|
43 | + * |
|
44 | + * @var @template_path |
|
45 | + */ |
|
46 | + protected $template_path; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var EE_Transaction |
|
50 | + */ |
|
51 | + protected $transaction; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var EE_PMT_PayPalCheckout |
|
55 | + */ |
|
56 | + protected $paypal_pmt; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + protected $checkout_type; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Class constructor. |
|
66 | + * |
|
67 | + * @param EE_Payment_Method $payment_method |
|
68 | + * @param array $options |
|
69 | + * @throws EE_Error |
|
70 | + * @throws ReflectionException |
|
71 | + */ |
|
72 | + public function __construct(EE_Payment_Method $payment_method, array $options = []) |
|
73 | + { |
|
74 | + $this->paypal_pmt = $payment_method; |
|
75 | + // Can't be too careful. |
|
76 | + $this->transaction = $options['transaction'] ?? null; |
|
77 | + $this->template_path = $options['template_path'] ?? ''; |
|
78 | + $this->checkout_type = $payment_method->get_extra_meta(Domain::META_KEY_CHECKOUT_TYPE, true, ''); |
|
79 | + $pm_slug = $payment_method->slug(); |
|
80 | + $parameters = array_replace_recursive( |
|
81 | + $options, |
|
82 | + [ |
|
83 | + 'name' => 'PayPalCommerceBillingForm', |
|
84 | + 'html_id' => 'pp-' . $pm_slug . '-billing-form', |
|
85 | + 'html_class' => 'pp_commerce_billing_form', |
|
86 | + 'subsections' => [ |
|
87 | + 'eea_paypal_commerce_token' => new EE_Hidden_Input( |
|
88 | + [ |
|
89 | + 'html_id' => 'eea-paypal-commerce-token', |
|
90 | + 'html_name' => 'EEA_paymentToken', |
|
91 | + 'default' => '', |
|
92 | + ] |
|
93 | + ), |
|
94 | + 'pp_order_nonce' => new EE_Hidden_Input( |
|
95 | + [ |
|
96 | + 'html_id' => 'eea-' . $pm_slug . '-order-nonce', |
|
97 | + 'html_name' => 'pp_order_nonce', |
|
98 | + 'default' => '', |
|
99 | + ] |
|
100 | + ), |
|
101 | + 'pp_order_id' => new EE_Hidden_Input( |
|
102 | + [ |
|
103 | + 'html_id' => 'eea-' . $pm_slug . '-order-id', |
|
104 | + 'html_name' => 'pp_order_id', |
|
105 | + 'default' => '', |
|
106 | + ] |
|
107 | + ), |
|
108 | + 'pp_order_status' => new EE_Hidden_Input( |
|
109 | + [ |
|
110 | + 'html_id' => 'eea-' . $pm_slug . '-order-status', |
|
111 | + 'html_name' => 'pp_order_status', |
|
112 | + 'default' => '', |
|
113 | + ] |
|
114 | + ), |
|
115 | + 'pp_order_amount' => new EE_Hidden_Input( |
|
116 | + [ |
|
117 | + 'html_id' => 'eea-' . $pm_slug . '-order-amount', |
|
118 | + 'html_name' => 'pp_order_amount', |
|
119 | + 'default' => '', |
|
120 | + ] |
|
121 | + ), |
|
122 | + ], |
|
123 | + ] |
|
124 | + ); |
|
125 | + // Add data tags to the PP script. |
|
126 | + add_filter('script_loader_tag', [$this, 'addDataTagsToScript'], 10, 2); |
|
127 | + parent::__construct($payment_method, $parameters); |
|
128 | + // Add and exclude other sections. |
|
129 | + $this->addPaymentSections(); |
|
130 | + // Additional actions and/or filters. |
|
131 | + $this->loadActionsAndFilters(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Add PayPal payment sections. |
|
137 | + * |
|
138 | + * @return void |
|
139 | + * @throws EE_Error |
|
140 | + * @throws ReflectionException |
|
141 | + */ |
|
142 | + public function addPaymentSections(): void |
|
143 | + { |
|
144 | + // Exclude the default billing form fields. |
|
145 | + $this->exclude([ |
|
146 | + 'first_name', |
|
147 | + 'last_name', |
|
148 | + 'email', |
|
149 | + ]); |
|
150 | + // Add PayPal Hosted Fields. |
|
151 | + if ($this->checkout_type !== 'express_checkout') { |
|
152 | + $this->addAdvancedCardFields(); |
|
153 | + } |
|
154 | + // Add payment types separator, if both are enabled. |
|
155 | + if ($this->checkout_type === 'all') { |
|
156 | + $this->addTypesSeparator(); |
|
157 | + } |
|
158 | + // Add PayPal Buttons section. |
|
159 | + if ($this->checkout_type !== 'ppcp') { |
|
160 | + $this->add_subsections( |
|
161 | + [ |
|
162 | + 'paypal_commerce_pm_form' => $this->addPayPalCheckout(), |
|
163 | + ] |
|
164 | + ); |
|
165 | + } |
|
166 | + // Exclude the rest billing form fields if the payment type is express checkout. |
|
167 | + if ($this->checkout_type === 'express_checkout') { |
|
168 | + $this->exclude([ |
|
169 | + 'address', |
|
170 | + 'address2', |
|
171 | + 'state', |
|
172 | + 'phone', |
|
173 | + 'city', |
|
174 | + 'country', |
|
175 | + 'zip', |
|
176 | + ]); |
|
177 | + // Remove the Info subsection. |
|
178 | + add_filter('FHEE__EE_Form_Section_Proper___construct__options_array', [$this, 'excludeInfoSubsection']); |
|
179 | + } |
|
180 | + $this->add_subsections( |
|
181 | + [ |
|
182 | + 'debug_content' => $this->addDebugContent($this->paypal_pmt), |
|
183 | + ] |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Additional actions and/or filters. |
|
190 | + * |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function loadActionsAndFilters(): void |
|
194 | + { |
|
195 | + add_filter( |
|
196 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
197 | + [__CLASS__, 'excludeBillingFormFields'], |
|
198 | + 10, |
|
199 | + 2 |
|
200 | + ); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Filter out billing form fields if pay button was used. |
|
206 | + * |
|
207 | + * @param EE_Billing_Info_Form $billing_form |
|
208 | + * @param EE_Payment_Method $payment_method |
|
209 | + * @return EE_Billing_Info_Form |
|
210 | + */ |
|
211 | + public static function excludeBillingFormFields( |
|
212 | + EE_Billing_Info_Form $billing_form, |
|
213 | + EE_Payment_Method $payment_method |
|
214 | + ): EE_Billing_Info_Form { |
|
215 | + $request = LoaderFactory::getShared(Request::class); |
|
216 | + $request_params = $request->requestParams(); |
|
217 | + if ( |
|
218 | + // Only the PPC billing form. |
|
219 | + $billing_form instanceof BillingForm |
|
220 | + && ! empty($request_params['process_form_submission']) |
|
221 | + && $request_params['process_form_submission'] === '1' |
|
222 | + && ! empty($request_params['eep_ppc_skip_form_validation']) |
|
223 | + ) { |
|
224 | + // Hide card info fields. |
|
225 | + $billing_form->exclude([ |
|
226 | + 'pp_name_on_card', |
|
227 | + 'address', |
|
228 | + 'address2', |
|
229 | + 'state', |
|
230 | + 'phone', |
|
231 | + 'city', |
|
232 | + 'country', |
|
233 | + 'zip', |
|
234 | + ]); |
|
235 | + } |
|
236 | + return $billing_form; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Add advanced card & debit card fields. |
|
242 | + * |
|
243 | + * @return void |
|
244 | + * @throws EE_Error|ReflectionException |
|
245 | + */ |
|
246 | + public function addAdvancedCardFields(): void |
|
247 | + { |
|
248 | + $pm_slug = $this->paypal_pmt->slug(); |
|
249 | + $this->add_subsections( |
|
250 | + [ |
|
251 | + 'pp_card_number' => new EE_Form_Section_HTML( |
|
252 | + EEH_HTML::label( |
|
253 | + esc_html__('Card Number', 'event_espresso'), |
|
254 | + "$pm_slug-card-number-lbl", |
|
255 | + "$pm_slug-card-fields", |
|
256 | + "", |
|
257 | + 'for="' . $pm_slug . '-card-number"' |
|
258 | + ) . |
|
259 | + EEH_HTML::p( |
|
260 | + "", |
|
261 | + "$pm_slug-card-number", |
|
262 | + "card_field $pm_slug-card-fields" |
|
263 | + ) |
|
264 | + ), |
|
265 | + 'pp_expiration_date' => new EE_Form_Section_HTML( |
|
266 | + EEH_HTML::label( |
|
267 | + esc_html__('Expiration Date', 'event_espresso'), |
|
268 | + "$pm_slug-expiration-date-lbl", |
|
269 | + "$pm_slug-card-fields", |
|
270 | + "", |
|
271 | + 'for="' . $pm_slug . '-expiration-date"' |
|
272 | + ) . |
|
273 | + EEH_HTML::p( |
|
274 | + "", |
|
275 | + "$pm_slug-expiration-date", |
|
276 | + "card_field $pm_slug-card-fields" |
|
277 | + ) |
|
278 | + ), |
|
279 | + 'pp_card_cvv' => new EE_Form_Section_HTML( |
|
280 | + EEH_HTML::label( |
|
281 | + esc_html__('CVV', 'event_espresso'), |
|
282 | + "$pm_slug-cvv-lbl", |
|
283 | + "$pm_slug-card-fields", |
|
284 | + "", |
|
285 | + 'for="' . $pm_slug . '-cvv"' |
|
286 | + ) . |
|
287 | + EEH_HTML::p( |
|
288 | + "", |
|
289 | + "$pm_slug-cvv", |
|
290 | + "card_field $pm_slug-card-fields" |
|
291 | + ) |
|
292 | + ), |
|
293 | + 'pp_name_on_card' => new EE_Text_Input( |
|
294 | + [ |
|
295 | + 'html_label_text' => esc_html__('Name On Card', 'event_espresso'), |
|
296 | + 'html_id' => $pm_slug . '-card-holder-name', |
|
297 | + 'html_name' => 'card-holder-name', |
|
298 | + 'html_class' => '', |
|
299 | + 'required' => true, |
|
300 | + ] |
|
301 | + ), |
|
302 | + ] |
|
303 | + ); |
|
304 | + // Add the submit button at the end. |
|
305 | + $this->add_subsections( |
|
306 | + [ |
|
307 | + 'pp_cc_submit' => new EE_Submit_Input( |
|
308 | + [ |
|
309 | + 'html_label_text' => esc_html__('Submit', 'event_espresso'), |
|
310 | + 'html_id' => $pm_slug, |
|
311 | + 'html_class' => 'eep-ppc-btn', |
|
312 | + ] |
|
313 | + ), |
|
314 | + ], |
|
315 | + 'phone', |
|
316 | + false |
|
317 | + ); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Add advanced card & debit card fields. |
|
323 | + * |
|
324 | + * @return void |
|
325 | + * @throws EE_Error|ReflectionException |
|
326 | + */ |
|
327 | + public function addTypesSeparator(): void |
|
328 | + { |
|
329 | + $this->add_subsections( |
|
330 | + [ |
|
331 | + 'pp_payment_types_separator' => new EE_Form_Section_HTML( |
|
332 | + EEH_HTML::div( |
|
333 | + EEH_HTML::div( |
|
334 | + ' ', |
|
335 | + 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
336 | + 'eep-ppc-separator-line eep-left-floating' |
|
337 | + ) . |
|
338 | + EEH_HTML::div( |
|
339 | + esc_html__(' or ', 'event_espresso'), |
|
340 | + 'eep-' . $this->paypal_pmt->slug() . '-separator-text', |
|
341 | + 'eep-ppc-separator-text1 eep-mid-floating' |
|
342 | + ) . EEH_HTML::div( |
|
343 | + ' ', |
|
344 | + 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
345 | + 'eep-ppc-separator-line eep-right-floating' |
|
346 | + ), |
|
347 | + 'eep-ppc-separator-holder', |
|
348 | + 'eep-ppc-separator-holder' |
|
349 | + ) |
|
350 | + ), |
|
351 | + ] |
|
352 | + ); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Exclude the info subsection from the PPC checkout form. |
|
358 | + * |
|
359 | + * @param array $options_array |
|
360 | + * @return array |
|
361 | + * @throws EE_Error |
|
362 | + * @throws ReflectionException |
|
363 | + */ |
|
364 | + public function excludeInfoSubsection(array $options_array): array |
|
365 | + { |
|
366 | + if (! empty($options_array['html_id']) |
|
367 | + && $options_array['html_id'] === 'spco-payment-method-info-' . $this->paypal_pmt->slug() |
|
368 | + ) { |
|
369 | + if (! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
370 | + unset($options_array['subsections']['info']); |
|
371 | + } |
|
372 | + } |
|
373 | + return $options_array; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Possibly adds debug content to PayPal commerce billing form. |
|
379 | + * |
|
380 | + * @param EE_Payment_Method $paypal_pm |
|
381 | + * @return EE_Form_Section_Base |
|
382 | + * @throws EE_Error|ReflectionException |
|
383 | + */ |
|
384 | + public function addDebugContent(EE_Payment_Method $paypal_pm): EE_Form_Section_Base |
|
385 | + { |
|
386 | + if ($paypal_pm->debug_mode()) { |
|
387 | + return new EE_Form_Section_Proper( |
|
388 | + [ |
|
389 | + 'layout_strategy' => new EE_Template_Layout( |
|
390 | + [ |
|
391 | + 'layout_template_file' => $this->template_path . 'debugInfo.template.php', |
|
392 | + 'template_args' => [], |
|
393 | + ] |
|
394 | + ), |
|
395 | + ] |
|
396 | + ); |
|
397 | + } |
|
398 | + return new EE_Form_Section_HTML(); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Add PayPal checkout buttons. |
|
404 | + * |
|
405 | + * @return EE_Form_Section_Proper |
|
406 | + * @throws EE_Error |
|
407 | + */ |
|
408 | + public function addPayPalCheckout(): EE_Form_Section_Proper |
|
409 | + { |
|
410 | + $template_args['pm_slug'] = $this->paypal_pmt->slug(); |
|
411 | + return new EE_Form_Section_Proper( |
|
412 | + [ |
|
413 | + 'layout_strategy' => new EE_Template_Layout( |
|
414 | + [ |
|
415 | + 'layout_template_file' => $this->template_path . 'paymentButtons.template.php', |
|
416 | + 'template_args' => $template_args, |
|
417 | + ] |
|
418 | + ), |
|
419 | + ] |
|
420 | + ); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Load scripts and localize data needed for this form. |
|
426 | + * |
|
427 | + * @param $tag |
|
428 | + * @param $handle |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public function addDataTagsToScript($tag, $handle): string |
|
432 | + { |
|
433 | + if ($handle === 'eea_paypal_commerce_js_lib') { |
|
434 | + $bn_code = PayPalExtraMetaManager::getPmOption($this->_pm_instance, Domain::META_KEY_BN_CODE); |
|
435 | + $response = EED_PayPalCommerce::requestClientToken($this->paypal_pmt); |
|
436 | + if (empty($response['client_token'])) { |
|
437 | + return $tag; |
|
438 | + } |
|
439 | + $client_token = $response['client_token']; |
|
440 | + $attributes = " data-partner-attribution-id=\"$bn_code\" data-client-token=\"$client_token\""; |
|
441 | + $tag = str_replace('></script>', $attributes . '></script>', $tag); |
|
442 | + } |
|
443 | + return $tag; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Load scripts and localize data needed for this form. |
|
449 | + * |
|
450 | + * @return void |
|
451 | + * @throws EE_Error |
|
452 | + * @throws ReflectionException |
|
453 | + * @throws Exception |
|
454 | + */ |
|
455 | + public function enqueue_js(): void |
|
456 | + { |
|
457 | + $third_party = EED_PayPalCommerce::isThirdParty($this->_pm_instance); |
|
458 | + $currency = CurrencyManager::currencyCode(); |
|
459 | + $client_id_key = Domain::META_KEY_CLIENT_ID; |
|
460 | + // Scripts. |
|
461 | + $scripts_src = 'https://www.paypal.com/sdk/js?components=buttons,hosted-fields&intent=capture'; |
|
462 | + if ($third_party) { |
|
463 | + $client_id_key = Domain::META_KEY_PARTNER_CLIENT_ID; |
|
464 | + $merchant_id = PayPalExtraMetaManager::getPmOption( |
|
465 | + $this->_pm_instance, |
|
466 | + Domain::META_KEY_SELLER_MERCHANT_ID |
|
467 | + ); |
|
468 | + $scripts_src .= "&merchant-id=$merchant_id"; |
|
469 | + } |
|
470 | + $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
471 | + $scripts_src .= "&client-id=$client_id¤cy=$currency"; |
|
472 | + wp_enqueue_script('eea_paypal_commerce_js_lib', $scripts_src, [], null); |
|
473 | + wp_enqueue_script( |
|
474 | + 'eea_paypal_commerce_js', |
|
475 | + EEP_PAYPAL_COMMERCE_URL . 'assets/js/paypal-commerce-payments.js', |
|
476 | + ['eea_paypal_commerce_js_lib'], |
|
477 | + EVENT_ESPRESSO_VERSION, |
|
478 | + true |
|
479 | + ); |
|
480 | + // Styles. |
|
481 | + wp_enqueue_style( |
|
482 | + 'eea_paypal_checkout_form_styles', |
|
483 | + EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-checkout.css', |
|
484 | + [], |
|
485 | + EVENT_ESPRESSO_VERSION |
|
486 | + ); |
|
487 | + // Localize the script with our transaction data. |
|
488 | + $parameters = $this->localizeParameters(); |
|
489 | + wp_localize_script('eea_paypal_commerce_js', 'eeaPPCommerceParameters', $parameters); |
|
490 | + parent::enqueue_js(); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * Get PayPal order ID if already created for this transaction. |
|
496 | + * |
|
497 | + * @param string $transaction_id |
|
498 | + * @return string |
|
499 | + */ |
|
500 | + public function getPpOrderId(string $transaction_id): string |
|
501 | + { |
|
502 | + try { |
|
503 | + $pp_order = PayPalExtraMetaManager::getPmOption($this->paypal_pmt, Domain::META_KEY_LAST_ORDER); |
|
504 | + $pp_order_txn_id = $pp_order['ee_txn_id'] ?? false; |
|
505 | + if ($pp_order_txn_id != $transaction_id) { |
|
506 | + // Old order data, delete it. |
|
507 | + PayPalExtraMetaManager::deletePmOption($this->paypal_pmt, Domain::META_KEY_LAST_ORDER); |
|
508 | + return ''; |
|
509 | + } |
|
510 | + } catch (Exception $exception) { |
|
511 | + return ''; |
|
512 | + } |
|
513 | + return $pp_order['id'] ?? ''; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Form and return PayPal commerce parameters for script localization. |
|
519 | + * |
|
520 | + * @return array |
|
521 | + * @throws EE_Error |
|
522 | + * @throws ReflectionException |
|
523 | + * @throws Exception |
|
524 | + */ |
|
525 | + public function localizeParameters(): array |
|
526 | + { |
|
527 | + // Also tell the script about each instance of this PM. |
|
528 | + $pm_versions = []; |
|
529 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active( |
|
530 | + EEM_Payment_Method::scope_cart, |
|
531 | + [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
|
532 | + ); |
|
533 | + foreach ($active_payment_methods as $payment_method) { |
|
534 | + $pm_versions[ $payment_method->slug() ] = [ |
|
535 | + 'pm_slug' => $payment_method->slug(), |
|
536 | + ]; |
|
537 | + } |
|
538 | + |
|
539 | + // Convert money for a display format. |
|
540 | + $decimal_places = CurrencyManager::getDecimalPlaces(); |
|
541 | + $org_country = isset(EE_Registry::instance()->CFG->organization) |
|
542 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
543 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
544 | + : 'US'; |
|
545 | + $transaction_id = $this->transaction instanceof EE_Transaction ? $this->transaction->ID() : 0; |
|
546 | + $currency_code = CurrencyManager::currencyCode(); |
|
547 | + return [ |
|
548 | + 'pm_versions' => $pm_versions, |
|
549 | + 'payment_currency' => $currency_code, |
|
550 | + 'checkout_type' => $this->checkout_type, |
|
551 | + 'currency_sign' => EE_Registry::instance()->CFG->currency->sign, |
|
552 | + 'pp_order_id' => $this->getPpOrderId($transaction_id), |
|
553 | + 'pp_order_nonce' => wp_create_nonce(Domain::CAPTURE_ORDER_NONCE_NAME), |
|
554 | + // The transaction ID is only used for logging errors. |
|
555 | + 'txn_id' => $transaction_id, |
|
556 | + 'org_country' => $org_country, |
|
557 | + 'decimal_places' => $decimal_places, |
|
558 | + 'site_name' => get_bloginfo('name'), |
|
559 | + 'active_states' => EED_PayPalCommerce::getActiveStates(), |
|
560 | + 'no_spco_error' => esc_html__( |
|
561 | + 'It appears the SDK script was not loaded properly! Please refresh the page and try again or contact support.', |
|
562 | + 'event_espresso' |
|
563 | + ), |
|
564 | + 'no_pm_error' => esc_html__( |
|
565 | + 'It appears that PayPal Commerce checkout JavaScript was not loaded properly! Please refresh the page and try again or contact support. PayPal Commerce payments can\'t be processed.', |
|
566 | + 'event_espresso' |
|
567 | + ), |
|
568 | + 'browser_not_supported' => esc_html__( |
|
569 | + 'It appears that this browser is not supported by PayPal scripts. We apologize, but PayPal payments won\'t work in this browser version.', |
|
570 | + 'event_espresso' |
|
571 | + ), |
|
572 | + 'get_token_error' => esc_html__( |
|
573 | + 'There was an error while trying to get the payment token. Please refresh the page and try again or contact support.', |
|
574 | + 'event_espresso' |
|
575 | + ), |
|
576 | + 'form_validation_notice' => esc_html__('Billing form information not valid.', 'event_espresso'), |
|
577 | + 'no_verification_token' => esc_html__('Missing the Verification token.', 'event_espresso'), |
|
578 | + 'error_response' => esc_html__('Got an error response (AJAX)', 'event_espresso'), |
|
579 | + 'payment_error' => esc_html__( |
|
580 | + 'There was an error with this payment. See the logs for details.', |
|
581 | + 'event_espresso' |
|
582 | + ), |
|
583 | + 'no_order_id' => esc_html__('No Order ID found.', 'event_espresso'), |
|
584 | + 'general_pp_error' => esc_html__('PayPal form threw an error.', 'event_espresso'), |
|
585 | + 'hf_render_error' => esc_html__('Hosted fields could not be rendered!', 'event_espresso'), |
|
586 | + 'pm_capture_error' => esc_html__('Payment could not be captured!', 'event_espresso'), |
|
587 | + 'not_acdc_eligible' => esc_html__('This merchant is not eligible for Advanced Card Fields checkout type.', 'event_espresso'), |
|
588 | + ]; |
|
589 | + } |
|
590 | 590 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $options, |
82 | 82 | [ |
83 | 83 | 'name' => 'PayPalCommerceBillingForm', |
84 | - 'html_id' => 'pp-' . $pm_slug . '-billing-form', |
|
84 | + 'html_id' => 'pp-'.$pm_slug.'-billing-form', |
|
85 | 85 | 'html_class' => 'pp_commerce_billing_form', |
86 | 86 | 'subsections' => [ |
87 | 87 | 'eea_paypal_commerce_token' => new EE_Hidden_Input( |
@@ -93,28 +93,28 @@ discard block |
||
93 | 93 | ), |
94 | 94 | 'pp_order_nonce' => new EE_Hidden_Input( |
95 | 95 | [ |
96 | - 'html_id' => 'eea-' . $pm_slug . '-order-nonce', |
|
96 | + 'html_id' => 'eea-'.$pm_slug.'-order-nonce', |
|
97 | 97 | 'html_name' => 'pp_order_nonce', |
98 | 98 | 'default' => '', |
99 | 99 | ] |
100 | 100 | ), |
101 | 101 | 'pp_order_id' => new EE_Hidden_Input( |
102 | 102 | [ |
103 | - 'html_id' => 'eea-' . $pm_slug . '-order-id', |
|
103 | + 'html_id' => 'eea-'.$pm_slug.'-order-id', |
|
104 | 104 | 'html_name' => 'pp_order_id', |
105 | 105 | 'default' => '', |
106 | 106 | ] |
107 | 107 | ), |
108 | 108 | 'pp_order_status' => new EE_Hidden_Input( |
109 | 109 | [ |
110 | - 'html_id' => 'eea-' . $pm_slug . '-order-status', |
|
110 | + 'html_id' => 'eea-'.$pm_slug.'-order-status', |
|
111 | 111 | 'html_name' => 'pp_order_status', |
112 | 112 | 'default' => '', |
113 | 113 | ] |
114 | 114 | ), |
115 | 115 | 'pp_order_amount' => new EE_Hidden_Input( |
116 | 116 | [ |
117 | - 'html_id' => 'eea-' . $pm_slug . '-order-amount', |
|
117 | + 'html_id' => 'eea-'.$pm_slug.'-order-amount', |
|
118 | 118 | 'html_name' => 'pp_order_amount', |
119 | 119 | 'default' => '', |
120 | 120 | ] |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | "$pm_slug-card-number-lbl", |
255 | 255 | "$pm_slug-card-fields", |
256 | 256 | "", |
257 | - 'for="' . $pm_slug . '-card-number"' |
|
258 | - ) . |
|
257 | + 'for="'.$pm_slug.'-card-number"' |
|
258 | + ). |
|
259 | 259 | EEH_HTML::p( |
260 | 260 | "", |
261 | 261 | "$pm_slug-card-number", |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | "$pm_slug-expiration-date-lbl", |
269 | 269 | "$pm_slug-card-fields", |
270 | 270 | "", |
271 | - 'for="' . $pm_slug . '-expiration-date"' |
|
272 | - ) . |
|
271 | + 'for="'.$pm_slug.'-expiration-date"' |
|
272 | + ). |
|
273 | 273 | EEH_HTML::p( |
274 | 274 | "", |
275 | 275 | "$pm_slug-expiration-date", |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | "$pm_slug-cvv-lbl", |
283 | 283 | "$pm_slug-card-fields", |
284 | 284 | "", |
285 | - 'for="' . $pm_slug . '-cvv"' |
|
286 | - ) . |
|
285 | + 'for="'.$pm_slug.'-cvv"' |
|
286 | + ). |
|
287 | 287 | EEH_HTML::p( |
288 | 288 | "", |
289 | 289 | "$pm_slug-cvv", |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | 'pp_name_on_card' => new EE_Text_Input( |
294 | 294 | [ |
295 | 295 | 'html_label_text' => esc_html__('Name On Card', 'event_espresso'), |
296 | - 'html_id' => $pm_slug . '-card-holder-name', |
|
296 | + 'html_id' => $pm_slug.'-card-holder-name', |
|
297 | 297 | 'html_name' => 'card-holder-name', |
298 | 298 | 'html_class' => '', |
299 | 299 | 'required' => true, |
@@ -332,16 +332,16 @@ discard block |
||
332 | 332 | EEH_HTML::div( |
333 | 333 | EEH_HTML::div( |
334 | 334 | ' ', |
335 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
335 | + 'eep-'.$this->paypal_pmt->slug().'-payments-separator', |
|
336 | 336 | 'eep-ppc-separator-line eep-left-floating' |
337 | - ) . |
|
337 | + ). |
|
338 | 338 | EEH_HTML::div( |
339 | 339 | esc_html__(' or ', 'event_espresso'), |
340 | - 'eep-' . $this->paypal_pmt->slug() . '-separator-text', |
|
340 | + 'eep-'.$this->paypal_pmt->slug().'-separator-text', |
|
341 | 341 | 'eep-ppc-separator-text1 eep-mid-floating' |
342 | - ) . EEH_HTML::div( |
|
342 | + ).EEH_HTML::div( |
|
343 | 343 | ' ', |
344 | - 'eep-' . $this->paypal_pmt->slug() . '-payments-separator', |
|
344 | + 'eep-'.$this->paypal_pmt->slug().'-payments-separator', |
|
345 | 345 | 'eep-ppc-separator-line eep-right-floating' |
346 | 346 | ), |
347 | 347 | 'eep-ppc-separator-holder', |
@@ -363,10 +363,10 @@ discard block |
||
363 | 363 | */ |
364 | 364 | public function excludeInfoSubsection(array $options_array): array |
365 | 365 | { |
366 | - if (! empty($options_array['html_id']) |
|
367 | - && $options_array['html_id'] === 'spco-payment-method-info-' . $this->paypal_pmt->slug() |
|
366 | + if ( ! empty($options_array['html_id']) |
|
367 | + && $options_array['html_id'] === 'spco-payment-method-info-'.$this->paypal_pmt->slug() |
|
368 | 368 | ) { |
369 | - if (! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
369 | + if ( ! empty($options_array['subsections']) && isset($options_array['subsections']['info'])) { |
|
370 | 370 | unset($options_array['subsections']['info']); |
371 | 371 | } |
372 | 372 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | [ |
389 | 389 | 'layout_strategy' => new EE_Template_Layout( |
390 | 390 | [ |
391 | - 'layout_template_file' => $this->template_path . 'debugInfo.template.php', |
|
391 | + 'layout_template_file' => $this->template_path.'debugInfo.template.php', |
|
392 | 392 | 'template_args' => [], |
393 | 393 | ] |
394 | 394 | ), |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | [ |
413 | 413 | 'layout_strategy' => new EE_Template_Layout( |
414 | 414 | [ |
415 | - 'layout_template_file' => $this->template_path . 'paymentButtons.template.php', |
|
415 | + 'layout_template_file' => $this->template_path.'paymentButtons.template.php', |
|
416 | 416 | 'template_args' => $template_args, |
417 | 417 | ] |
418 | 418 | ), |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } |
439 | 439 | $client_token = $response['client_token']; |
440 | 440 | $attributes = " data-partner-attribution-id=\"$bn_code\" data-client-token=\"$client_token\""; |
441 | - $tag = str_replace('></script>', $attributes . '></script>', $tag); |
|
441 | + $tag = str_replace('></script>', $attributes.'></script>', $tag); |
|
442 | 442 | } |
443 | 443 | return $tag; |
444 | 444 | } |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | ); |
468 | 468 | $scripts_src .= "&merchant-id=$merchant_id"; |
469 | 469 | } |
470 | - $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
470 | + $client_id = PayPalExtraMetaManager::getPmOption($this->_pm_instance, $client_id_key); |
|
471 | 471 | $scripts_src .= "&client-id=$client_id¤cy=$currency"; |
472 | 472 | wp_enqueue_script('eea_paypal_commerce_js_lib', $scripts_src, [], null); |
473 | 473 | wp_enqueue_script( |
474 | 474 | 'eea_paypal_commerce_js', |
475 | - EEP_PAYPAL_COMMERCE_URL . 'assets/js/paypal-commerce-payments.js', |
|
475 | + EEP_PAYPAL_COMMERCE_URL.'assets/js/paypal-commerce-payments.js', |
|
476 | 476 | ['eea_paypal_commerce_js_lib'], |
477 | 477 | EVENT_ESPRESSO_VERSION, |
478 | 478 | true |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | // Styles. |
481 | 481 | wp_enqueue_style( |
482 | 482 | 'eea_paypal_checkout_form_styles', |
483 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-checkout.css', |
|
483 | + EEP_PAYPAL_COMMERCE_URL.'assets'.DS.'css'.DS.'eea-paypal-checkout.css', |
|
484 | 484 | [], |
485 | 485 | EVENT_ESPRESSO_VERSION |
486 | 486 | ); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
532 | 532 | ); |
533 | 533 | foreach ($active_payment_methods as $payment_method) { |
534 | - $pm_versions[ $payment_method->slug() ] = [ |
|
534 | + $pm_versions[$payment_method->slug()] = [ |
|
535 | 535 | 'pm_slug' => $payment_method->slug(), |
536 | 536 | ]; |
537 | 537 | } |
@@ -27,450 +27,450 @@ |
||
27 | 27 | */ |
28 | 28 | class OnboardingFormHtml |
29 | 29 | { |
30 | - /** |
|
31 | - * Payment method. |
|
32 | - * |
|
33 | - * @var EE_PMT_Base |
|
34 | - */ |
|
35 | - protected $payment_method = null; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method instance. |
|
39 | - * |
|
40 | - * @var EE_PMT_Base |
|
41 | - */ |
|
42 | - protected $pm_instance = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method slug. |
|
46 | - * |
|
47 | - * @var EE_PMT_Base |
|
48 | - */ |
|
49 | - protected $pm_slug = null; |
|
50 | - |
|
51 | - /** |
|
52 | - * PayPal Onboarding button text. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $onboard_btn_text = ''; |
|
57 | - |
|
58 | - /** |
|
59 | - * PayPal Onboarding button in sandbox mode text. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $sandbox_btn_text = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * PayPal Onboarding section sandbox mode text. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $authed_sandbox_text = ''; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Class constructor. |
|
75 | - * |
|
76 | - * @param EE_PMT_Base $pmt |
|
77 | - * @param EE_Payment_Method $payment_method |
|
78 | - */ |
|
79 | - public function __construct(EE_PMT_Base $pmt, EE_Payment_Method $payment_method) |
|
80 | - { |
|
81 | - $this->payment_method = $pmt; |
|
82 | - $this->pm_instance = $payment_method; |
|
83 | - $this->pm_slug = $this->pm_instance->slug(); |
|
84 | - $this->onboard_btn_text = esc_html__('Connect with PayPal', 'event_espresso'); |
|
85 | - $this->sandbox_btn_text = esc_html__('Connect with PayPal (sandbox)', 'event_espresso'); |
|
86 | - $this->authed_sandbox_text = esc_html__('(using sandbox credentials)', 'event_espresso'); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Form a heading. |
|
92 | - * |
|
93 | - * @param string $text |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function getHeader(string $text = ''): string |
|
97 | - { |
|
98 | - $text = $text ?: esc_html__('PayPal Onboarding: %1$s', 'event_espresso'); |
|
99 | - return EEH_HTML::th( |
|
100 | - sprintf( |
|
101 | - $text, |
|
102 | - $this->payment_method->get_help_tab_link() |
|
103 | - ), |
|
104 | - 'eea_paypal_onboard_heading_' . $this->pm_slug, |
|
105 | - 'eea-paypal-onboard-heading' |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Add the onboarding button. |
|
112 | - * |
|
113 | - * @param array $subsections |
|
114 | - * @param bool $is_onboard |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public function addOnboardButton(array $subsections, bool $is_onboard): array |
|
118 | - { |
|
119 | - // Section to be displayed if not onboard. |
|
120 | - $subsections['paypal_onboard_btn'] = new EE_Form_Section_HTML( |
|
121 | - EEH_HTML::tr( |
|
122 | - $this->getHeader() . |
|
123 | - EEH_HTML::td( |
|
124 | - EEH_HTML::button( |
|
125 | - $this->onboard_btn_text, |
|
126 | - 'eea-paypal-onboard-btn button button--primary', |
|
127 | - '', |
|
128 | - 'eea_paypal_onboard_btn_' . $this->pm_slug, |
|
129 | - ) |
|
130 | - . EEH_HTML::link( |
|
131 | - '#', |
|
132 | - '', |
|
133 | - '', |
|
134 | - 'eea_paypal_onboard_trigger_btn_' . $this->pm_slug, |
|
135 | - 'eea-paypal-onboard-trigger-btn', |
|
136 | - '', |
|
137 | - 'data-ee-pm-slug="' . $this->pm_slug . '" data-paypal-button="true"' |
|
138 | - ) |
|
139 | - ), |
|
140 | - 'eea_paypal_onboard_section_' . $this->pm_slug, |
|
141 | - 'eea-onboard-section eea-onboard-section-' . $this->pm_slug, |
|
142 | - // Are we onboard ? |
|
143 | - $is_onboard ? 'display:none;' : '' |
|
144 | - ), |
|
145 | - ['required' => true] |
|
146 | - ); |
|
147 | - return $subsections; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Add the offboarding (deauthorize) button. |
|
153 | - * |
|
154 | - * @param array $subsections |
|
155 | - * @param bool $is_onboard |
|
156 | - * @return array |
|
157 | - */ |
|
158 | - public function addOffboardButton(array $subsections, bool $is_onboard): array |
|
159 | - { |
|
160 | - $onboard_sandbox_section = $this->getOnboardSandboxSection(); |
|
161 | - // If we are connected, display the seller merchant ID. |
|
162 | - $seller_id_section = $this->getSellerIdSection(); |
|
163 | - // Section to be displayed when onboard. |
|
164 | - $subsections['paypal_offboard_btn'] = new EE_Form_Section_HTML( |
|
165 | - EEH_HTML::tr( |
|
166 | - $this->getHeader() |
|
167 | - . EEH_HTML::td( |
|
168 | - EEH_HTML::img( |
|
169 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'lib' . DS . 'paypal-onboard.png', |
|
170 | - '', |
|
171 | - 'eea_paypal_offboard_ico', |
|
172 | - 'eea-paypal-offboard-ico' |
|
173 | - ) |
|
174 | - . EEH_HTML::strong( |
|
175 | - esc_html__('Connected.', 'event_espresso'), |
|
176 | - 'eea_paypal_offboard_txt_' . $this->pm_slug, |
|
177 | - 'eea-paypal-offboard-txt' |
|
178 | - ) |
|
179 | - . $onboard_sandbox_section |
|
180 | - . $seller_id_section |
|
181 | - . EEH_HTML::link( |
|
182 | - '#', |
|
183 | - EEH_HTML::span(esc_html__('Disconnect', 'event_espresso')), |
|
184 | - '', |
|
185 | - 'eea_paypal_offboard_btn_' . $this->pm_slug, |
|
186 | - 'eea-paypal-onboard-btn button button--primary' |
|
187 | - ) |
|
188 | - ), |
|
189 | - 'eea_paypal_offboard_section_' . $this->pm_slug, |
|
190 | - 'eea-offboard-section-' . $this->pm_slug, |
|
191 | - // Are we onboard ? |
|
192 | - ! $is_onboard ? 'display:none;' : '' |
|
193 | - ), |
|
194 | - ['required' => true] |
|
195 | - ); |
|
196 | - return $subsections; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Get the sandbox onboarding section contents. |
|
202 | - * |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function getOnboardSandboxSection(): string |
|
206 | - { |
|
207 | - // Is this a test onboarding ? |
|
208 | - $sandbox_mode_text = $this->pm_instance->debug_mode() ? $this->authed_sandbox_text : ''; |
|
209 | - return ' ' . EEH_HTML::strong( |
|
210 | - $sandbox_mode_text, |
|
211 | - 'eea_paypal_onboard_test_txt_' . $this->pm_slug, |
|
212 | - 'eea-paypal-onboard-test-txt' |
|
213 | - ); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Get the seller merchant ID section contents. |
|
219 | - * |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function getSellerIdSection(): string |
|
223 | - { |
|
224 | - try { |
|
225 | - $is_third_party = EED_PayPalCommerce::isThirdParty($this->pm_instance); |
|
226 | - $meta_key = $is_third_party ? Domain::META_KEY_SELLER_MERCHANT_ID : Domain::META_KEY_PAYER_ID; |
|
227 | - $payer_id = PayPalExtraMetaManager::getPmOption($this->pm_instance, $meta_key) ?: '--'; |
|
228 | - } catch (Exception $e) { |
|
229 | - $payer_id = '--'; |
|
230 | - } |
|
231 | - return ' ' . EEH_HTML::strong( |
|
232 | - sprintf(esc_html__('Linked account ID: %1$s', 'event_espresso'), $payer_id), |
|
233 | - 'eea_paypal_seller_id_' . $this->pm_slug, |
|
234 | - 'eea-paypal-seller-id' |
|
235 | - ); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Add the PM slug holder. |
|
241 | - * |
|
242 | - * @param array $subsections |
|
243 | - * @return array |
|
244 | - */ |
|
245 | - public function addPmSlugHolder(array $subsections): array |
|
246 | - { |
|
247 | - $subsections['paypal_pm_slug_holder'] = new EE_Form_Section_HTML( |
|
248 | - EEH_HTML::span( |
|
249 | - '', |
|
250 | - 'eea_paypal_pm_slug', |
|
251 | - 'eea-paypal-pm-slug', |
|
252 | - 'display:none;' |
|
253 | - ) |
|
254 | - ); |
|
255 | - return $subsections; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * HTML for onboarding settings dialog. |
|
261 | - * |
|
262 | - * @return EE_Form_Section_Base |
|
263 | - */ |
|
264 | - public function connectDialog(): EE_Form_Section_Base |
|
265 | - { |
|
266 | - return new EE_Form_Section_HTML( |
|
267 | - EEH_HTML::div( |
|
268 | - $this->countriesSelectHtml() . |
|
269 | - $this->paymentOptionsHtml() . |
|
270 | - EEH_HTML::div( |
|
271 | - EEH_HTML::link( |
|
272 | - '', |
|
273 | - 'Cancel', |
|
274 | - 'cancel, go back', |
|
275 | - 'eea_ppc_connect_cancel_' . $this->pm_slug, |
|
276 | - 'eea-ppc-connect-cancel button button--secondary' |
|
277 | - ) . |
|
278 | - EEH_HTML::link( |
|
279 | - '', |
|
280 | - 'Continue', |
|
281 | - 'ok, continue', |
|
282 | - 'eea_ppc_connect_ok_' . $this->pm_slug, |
|
283 | - 'eea-ppc-connect-ok button button--primary-alt' |
|
284 | - ), |
|
285 | - '', |
|
286 | - 'eep-ppc-dialog-yes-no' |
|
287 | - ), |
|
288 | - 'eea_paypal_connect_dialog_' . $this->pm_slug |
|
289 | - ) |
|
290 | - ); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Form a countries select and return as html. |
|
296 | - * |
|
297 | - * @return string |
|
298 | - */ |
|
299 | - public function countriesSelectHtml(): string |
|
300 | - { |
|
301 | - $countries = []; |
|
302 | - $countries_select = EEH_HTML::strong( |
|
303 | - esc_html__('Please select a country where your PayPal account is registered:', 'event_espresso'), |
|
304 | - 'eep_ppc_country_txt_' . $this->pm_slug, |
|
305 | - 'eep-ppc-country-txt' |
|
306 | - ); |
|
307 | - try { |
|
308 | - // Get all countries list. |
|
309 | - $countries_iso = EEM_Country::instance()->get_all_countries(); |
|
310 | - foreach ($countries_iso as $iso => $country) { |
|
311 | - if ($country instanceof EE_Country) { |
|
312 | - $countries [ $iso ] = $country->get('CNT_name'); |
|
313 | - } |
|
314 | - } |
|
315 | - // Now build the select input. |
|
316 | - $select_input = new EE_Select_Input( |
|
317 | - $countries, |
|
318 | - [ |
|
319 | - 'html_name' => 'eep_ppc_country_' . $this->pm_slug, |
|
320 | - 'html_id' => 'eep_ppc_country_' . $this->pm_slug, |
|
321 | - 'html_class' => 'eep-ppc-country-' . $this->pm_slug, |
|
322 | - 'html_label_text' => esc_html__('Select country', 'event_espresso'), |
|
323 | - 'required' => true, |
|
324 | - 'default' => EE_Config::instance()->organization->CNT_ISO ?? 'US' |
|
325 | - ] |
|
326 | - ); |
|
327 | - $countries_select .= $select_input->get_html_for_input(); |
|
328 | - } catch (Exception $e) { |
|
329 | - // Countries list set at this point, so just continue. |
|
330 | - } |
|
331 | - return $countries_select; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Form the payment options checkboxes and return as html. |
|
337 | - * |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - public function paymentOptionsHtml(): string |
|
341 | - { |
|
342 | - $options_lbl = EEH_HTML::strong( |
|
343 | - esc_html__('Select a product you\'d like to allow at checkout:', 'event_espresso'), |
|
344 | - 'eea_ppc_product_txt_' . $this->pm_slug, |
|
345 | - 'eea-ppc-product-txt' |
|
346 | - ); |
|
347 | - $express_checkout_lbl = EEH_HTML::label( |
|
348 | - esc_html__('Accept PayPal ', 'event_espresso') |
|
349 | - . EEH_HTML::img( |
|
350 | - 'https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png', |
|
351 | - '', |
|
352 | - 'eea_ppc_express_checkout_img_' . $this->pm_slug, |
|
353 | - 'eea-ppc-express-checkout-img' |
|
354 | - ), |
|
355 | - '', |
|
356 | - '', |
|
357 | - '', |
|
358 | - 'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-express_checkout"' |
|
359 | - ); |
|
360 | - $ppcp_lbl = EEH_HTML::label( |
|
361 | - esc_html__('Accept credit and debit card payments with PayPal ', 'event_espresso') |
|
362 | - . EEH_HTML::img( |
|
363 | - 'https://www.paypalobjects.com/digitalassets/c/website/marketing/apac/C2/logos-buttons/optimize/Full_Online_Tray_RGB.png', |
|
364 | - '', |
|
365 | - 'eea_ppc_ppcp_img_' . $this->pm_slug, |
|
366 | - 'eea-ppc-ppcp-img' |
|
367 | - ), |
|
368 | - '', |
|
369 | - '', |
|
370 | - '', |
|
371 | - 'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-ppcp"' |
|
372 | - ); |
|
373 | - $checkbox = new EE_Checkbox_Multi_Input( |
|
374 | - [ |
|
375 | - 'express_checkout' => $express_checkout_lbl, |
|
376 | - 'ppcp' => $ppcp_lbl, |
|
377 | - ], |
|
378 | - [ |
|
379 | - 'html_id' => 'eep_ppc_checkout_type_' . $this->pm_slug, |
|
380 | - 'html_label_text' => esc_html__( |
|
381 | - 'Select a product you\'d like to allow at checkout.', |
|
382 | - 'event_espresso' |
|
383 | - ), |
|
384 | - 'html_help_text' => esc_html__( |
|
385 | - 'Select a product you\'d like to allow at checkout.', |
|
386 | - 'event_espresso' |
|
387 | - ), |
|
388 | - 'default' => ['express_checkout', 'ppcp'] |
|
389 | - ] |
|
390 | - ); |
|
391 | - try { |
|
392 | - return EEH_HTML::div( |
|
393 | - $options_lbl |
|
394 | - . $checkbox->get_html_for_input(), |
|
395 | - 'eep_ppc_checkout_types_' . $this->pm_slug, |
|
396 | - 'eep-ppc-checkout-types' |
|
397 | - ); |
|
398 | - } catch (Exception $e) { |
|
399 | - return ''; |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * HTML for onboarding settings dialog. |
|
406 | - * |
|
407 | - * @return EE_Form_Section_Base |
|
408 | - */ |
|
409 | - public function processingMask(): EE_Form_Section_Base |
|
410 | - { |
|
411 | - return new EE_Form_Section_HTML( |
|
412 | - EEH_HTML::div( |
|
413 | - EEH_HTML::div(' ', 'eep_ppc_processing_mask', 'eep-ppc-processing-mask') . |
|
414 | - EEH_HTML::div(' ', 'eep_ppc_processing_spinner', 'ee-spinner ee-spin') . |
|
415 | - EEH_HTML::div( |
|
416 | - esc_html__('The login window should be open. If you don\'t see a new PayPal login window you might need to enable pop-ups in your browser in order to continue.') . |
|
417 | - EEH_HTML::div( |
|
418 | - EEH_HTML::link( |
|
419 | - '#', |
|
420 | - esc_html__('Focus window'), |
|
421 | - esc_html__('Focus window'), |
|
422 | - 'eep_ppc_window_focus_' . $this->pm_slug, |
|
423 | - 'eep-ppc-window-focus' |
|
424 | - ) |
|
425 | - ), |
|
426 | - 'eep_ppc_processing_message', |
|
427 | - 'eep-ppc-processing-message' |
|
428 | - ), |
|
429 | - 'eep_ppc_processing_' . $this->pm_slug, |
|
430 | - 'eep-ppc-processing' |
|
431 | - ) |
|
432 | - ); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * HTML for the disconnect warning dialog. |
|
438 | - * |
|
439 | - * @return EE_Form_Section_Base |
|
440 | - */ |
|
441 | - public function disconnectDialog(): EE_Form_Section_Base |
|
442 | - { |
|
443 | - $message = esc_html__( |
|
444 | - 'Disconnecting your PayPal account will prevent you from offering PayPal services and products on your website.', |
|
445 | - 'event_espresso' |
|
446 | - ); |
|
447 | - return new EE_Form_Section_HTML( |
|
448 | - EEH_HTML::div( |
|
449 | - EEH_HTML::strong( |
|
450 | - $message, |
|
451 | - 'eep_ppc_disconnect_dialog_txt_' . $this->pm_slug, |
|
452 | - 'eep-ppc-disconnect-dialog-txt' |
|
453 | - ) . |
|
454 | - EEH_HTML::div( |
|
455 | - EEH_HTML::link( |
|
456 | - '', |
|
457 | - 'Cancel', |
|
458 | - 'cancel, go back', |
|
459 | - 'eep_ppc_disconnect_cancel_' . $this->pm_slug, |
|
460 | - 'eep-ppc-disconnect-cancel button button--secondary' |
|
461 | - ) . |
|
462 | - EEH_HTML::link( |
|
463 | - '', |
|
464 | - 'Disconnect', |
|
465 | - 'ok, continue', |
|
466 | - 'eep_ppc_disconnect_ok_' . $this->pm_slug, |
|
467 | - 'eep-ppc-disconnect-ok button button--primary-alt' |
|
468 | - ), |
|
469 | - '', |
|
470 | - 'eep-ppc-dialog-yes-no' |
|
471 | - ), |
|
472 | - 'eep_paypal_disconnect_dialog_' . $this->pm_slug |
|
473 | - ) |
|
474 | - ); |
|
475 | - } |
|
30 | + /** |
|
31 | + * Payment method. |
|
32 | + * |
|
33 | + * @var EE_PMT_Base |
|
34 | + */ |
|
35 | + protected $payment_method = null; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method instance. |
|
39 | + * |
|
40 | + * @var EE_PMT_Base |
|
41 | + */ |
|
42 | + protected $pm_instance = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method slug. |
|
46 | + * |
|
47 | + * @var EE_PMT_Base |
|
48 | + */ |
|
49 | + protected $pm_slug = null; |
|
50 | + |
|
51 | + /** |
|
52 | + * PayPal Onboarding button text. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $onboard_btn_text = ''; |
|
57 | + |
|
58 | + /** |
|
59 | + * PayPal Onboarding button in sandbox mode text. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $sandbox_btn_text = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * PayPal Onboarding section sandbox mode text. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $authed_sandbox_text = ''; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Class constructor. |
|
75 | + * |
|
76 | + * @param EE_PMT_Base $pmt |
|
77 | + * @param EE_Payment_Method $payment_method |
|
78 | + */ |
|
79 | + public function __construct(EE_PMT_Base $pmt, EE_Payment_Method $payment_method) |
|
80 | + { |
|
81 | + $this->payment_method = $pmt; |
|
82 | + $this->pm_instance = $payment_method; |
|
83 | + $this->pm_slug = $this->pm_instance->slug(); |
|
84 | + $this->onboard_btn_text = esc_html__('Connect with PayPal', 'event_espresso'); |
|
85 | + $this->sandbox_btn_text = esc_html__('Connect with PayPal (sandbox)', 'event_espresso'); |
|
86 | + $this->authed_sandbox_text = esc_html__('(using sandbox credentials)', 'event_espresso'); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Form a heading. |
|
92 | + * |
|
93 | + * @param string $text |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function getHeader(string $text = ''): string |
|
97 | + { |
|
98 | + $text = $text ?: esc_html__('PayPal Onboarding: %1$s', 'event_espresso'); |
|
99 | + return EEH_HTML::th( |
|
100 | + sprintf( |
|
101 | + $text, |
|
102 | + $this->payment_method->get_help_tab_link() |
|
103 | + ), |
|
104 | + 'eea_paypal_onboard_heading_' . $this->pm_slug, |
|
105 | + 'eea-paypal-onboard-heading' |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Add the onboarding button. |
|
112 | + * |
|
113 | + * @param array $subsections |
|
114 | + * @param bool $is_onboard |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public function addOnboardButton(array $subsections, bool $is_onboard): array |
|
118 | + { |
|
119 | + // Section to be displayed if not onboard. |
|
120 | + $subsections['paypal_onboard_btn'] = new EE_Form_Section_HTML( |
|
121 | + EEH_HTML::tr( |
|
122 | + $this->getHeader() . |
|
123 | + EEH_HTML::td( |
|
124 | + EEH_HTML::button( |
|
125 | + $this->onboard_btn_text, |
|
126 | + 'eea-paypal-onboard-btn button button--primary', |
|
127 | + '', |
|
128 | + 'eea_paypal_onboard_btn_' . $this->pm_slug, |
|
129 | + ) |
|
130 | + . EEH_HTML::link( |
|
131 | + '#', |
|
132 | + '', |
|
133 | + '', |
|
134 | + 'eea_paypal_onboard_trigger_btn_' . $this->pm_slug, |
|
135 | + 'eea-paypal-onboard-trigger-btn', |
|
136 | + '', |
|
137 | + 'data-ee-pm-slug="' . $this->pm_slug . '" data-paypal-button="true"' |
|
138 | + ) |
|
139 | + ), |
|
140 | + 'eea_paypal_onboard_section_' . $this->pm_slug, |
|
141 | + 'eea-onboard-section eea-onboard-section-' . $this->pm_slug, |
|
142 | + // Are we onboard ? |
|
143 | + $is_onboard ? 'display:none;' : '' |
|
144 | + ), |
|
145 | + ['required' => true] |
|
146 | + ); |
|
147 | + return $subsections; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Add the offboarding (deauthorize) button. |
|
153 | + * |
|
154 | + * @param array $subsections |
|
155 | + * @param bool $is_onboard |
|
156 | + * @return array |
|
157 | + */ |
|
158 | + public function addOffboardButton(array $subsections, bool $is_onboard): array |
|
159 | + { |
|
160 | + $onboard_sandbox_section = $this->getOnboardSandboxSection(); |
|
161 | + // If we are connected, display the seller merchant ID. |
|
162 | + $seller_id_section = $this->getSellerIdSection(); |
|
163 | + // Section to be displayed when onboard. |
|
164 | + $subsections['paypal_offboard_btn'] = new EE_Form_Section_HTML( |
|
165 | + EEH_HTML::tr( |
|
166 | + $this->getHeader() |
|
167 | + . EEH_HTML::td( |
|
168 | + EEH_HTML::img( |
|
169 | + EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'lib' . DS . 'paypal-onboard.png', |
|
170 | + '', |
|
171 | + 'eea_paypal_offboard_ico', |
|
172 | + 'eea-paypal-offboard-ico' |
|
173 | + ) |
|
174 | + . EEH_HTML::strong( |
|
175 | + esc_html__('Connected.', 'event_espresso'), |
|
176 | + 'eea_paypal_offboard_txt_' . $this->pm_slug, |
|
177 | + 'eea-paypal-offboard-txt' |
|
178 | + ) |
|
179 | + . $onboard_sandbox_section |
|
180 | + . $seller_id_section |
|
181 | + . EEH_HTML::link( |
|
182 | + '#', |
|
183 | + EEH_HTML::span(esc_html__('Disconnect', 'event_espresso')), |
|
184 | + '', |
|
185 | + 'eea_paypal_offboard_btn_' . $this->pm_slug, |
|
186 | + 'eea-paypal-onboard-btn button button--primary' |
|
187 | + ) |
|
188 | + ), |
|
189 | + 'eea_paypal_offboard_section_' . $this->pm_slug, |
|
190 | + 'eea-offboard-section-' . $this->pm_slug, |
|
191 | + // Are we onboard ? |
|
192 | + ! $is_onboard ? 'display:none;' : '' |
|
193 | + ), |
|
194 | + ['required' => true] |
|
195 | + ); |
|
196 | + return $subsections; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Get the sandbox onboarding section contents. |
|
202 | + * |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function getOnboardSandboxSection(): string |
|
206 | + { |
|
207 | + // Is this a test onboarding ? |
|
208 | + $sandbox_mode_text = $this->pm_instance->debug_mode() ? $this->authed_sandbox_text : ''; |
|
209 | + return ' ' . EEH_HTML::strong( |
|
210 | + $sandbox_mode_text, |
|
211 | + 'eea_paypal_onboard_test_txt_' . $this->pm_slug, |
|
212 | + 'eea-paypal-onboard-test-txt' |
|
213 | + ); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Get the seller merchant ID section contents. |
|
219 | + * |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function getSellerIdSection(): string |
|
223 | + { |
|
224 | + try { |
|
225 | + $is_third_party = EED_PayPalCommerce::isThirdParty($this->pm_instance); |
|
226 | + $meta_key = $is_third_party ? Domain::META_KEY_SELLER_MERCHANT_ID : Domain::META_KEY_PAYER_ID; |
|
227 | + $payer_id = PayPalExtraMetaManager::getPmOption($this->pm_instance, $meta_key) ?: '--'; |
|
228 | + } catch (Exception $e) { |
|
229 | + $payer_id = '--'; |
|
230 | + } |
|
231 | + return ' ' . EEH_HTML::strong( |
|
232 | + sprintf(esc_html__('Linked account ID: %1$s', 'event_espresso'), $payer_id), |
|
233 | + 'eea_paypal_seller_id_' . $this->pm_slug, |
|
234 | + 'eea-paypal-seller-id' |
|
235 | + ); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Add the PM slug holder. |
|
241 | + * |
|
242 | + * @param array $subsections |
|
243 | + * @return array |
|
244 | + */ |
|
245 | + public function addPmSlugHolder(array $subsections): array |
|
246 | + { |
|
247 | + $subsections['paypal_pm_slug_holder'] = new EE_Form_Section_HTML( |
|
248 | + EEH_HTML::span( |
|
249 | + '', |
|
250 | + 'eea_paypal_pm_slug', |
|
251 | + 'eea-paypal-pm-slug', |
|
252 | + 'display:none;' |
|
253 | + ) |
|
254 | + ); |
|
255 | + return $subsections; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * HTML for onboarding settings dialog. |
|
261 | + * |
|
262 | + * @return EE_Form_Section_Base |
|
263 | + */ |
|
264 | + public function connectDialog(): EE_Form_Section_Base |
|
265 | + { |
|
266 | + return new EE_Form_Section_HTML( |
|
267 | + EEH_HTML::div( |
|
268 | + $this->countriesSelectHtml() . |
|
269 | + $this->paymentOptionsHtml() . |
|
270 | + EEH_HTML::div( |
|
271 | + EEH_HTML::link( |
|
272 | + '', |
|
273 | + 'Cancel', |
|
274 | + 'cancel, go back', |
|
275 | + 'eea_ppc_connect_cancel_' . $this->pm_slug, |
|
276 | + 'eea-ppc-connect-cancel button button--secondary' |
|
277 | + ) . |
|
278 | + EEH_HTML::link( |
|
279 | + '', |
|
280 | + 'Continue', |
|
281 | + 'ok, continue', |
|
282 | + 'eea_ppc_connect_ok_' . $this->pm_slug, |
|
283 | + 'eea-ppc-connect-ok button button--primary-alt' |
|
284 | + ), |
|
285 | + '', |
|
286 | + 'eep-ppc-dialog-yes-no' |
|
287 | + ), |
|
288 | + 'eea_paypal_connect_dialog_' . $this->pm_slug |
|
289 | + ) |
|
290 | + ); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Form a countries select and return as html. |
|
296 | + * |
|
297 | + * @return string |
|
298 | + */ |
|
299 | + public function countriesSelectHtml(): string |
|
300 | + { |
|
301 | + $countries = []; |
|
302 | + $countries_select = EEH_HTML::strong( |
|
303 | + esc_html__('Please select a country where your PayPal account is registered:', 'event_espresso'), |
|
304 | + 'eep_ppc_country_txt_' . $this->pm_slug, |
|
305 | + 'eep-ppc-country-txt' |
|
306 | + ); |
|
307 | + try { |
|
308 | + // Get all countries list. |
|
309 | + $countries_iso = EEM_Country::instance()->get_all_countries(); |
|
310 | + foreach ($countries_iso as $iso => $country) { |
|
311 | + if ($country instanceof EE_Country) { |
|
312 | + $countries [ $iso ] = $country->get('CNT_name'); |
|
313 | + } |
|
314 | + } |
|
315 | + // Now build the select input. |
|
316 | + $select_input = new EE_Select_Input( |
|
317 | + $countries, |
|
318 | + [ |
|
319 | + 'html_name' => 'eep_ppc_country_' . $this->pm_slug, |
|
320 | + 'html_id' => 'eep_ppc_country_' . $this->pm_slug, |
|
321 | + 'html_class' => 'eep-ppc-country-' . $this->pm_slug, |
|
322 | + 'html_label_text' => esc_html__('Select country', 'event_espresso'), |
|
323 | + 'required' => true, |
|
324 | + 'default' => EE_Config::instance()->organization->CNT_ISO ?? 'US' |
|
325 | + ] |
|
326 | + ); |
|
327 | + $countries_select .= $select_input->get_html_for_input(); |
|
328 | + } catch (Exception $e) { |
|
329 | + // Countries list set at this point, so just continue. |
|
330 | + } |
|
331 | + return $countries_select; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Form the payment options checkboxes and return as html. |
|
337 | + * |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + public function paymentOptionsHtml(): string |
|
341 | + { |
|
342 | + $options_lbl = EEH_HTML::strong( |
|
343 | + esc_html__('Select a product you\'d like to allow at checkout:', 'event_espresso'), |
|
344 | + 'eea_ppc_product_txt_' . $this->pm_slug, |
|
345 | + 'eea-ppc-product-txt' |
|
346 | + ); |
|
347 | + $express_checkout_lbl = EEH_HTML::label( |
|
348 | + esc_html__('Accept PayPal ', 'event_espresso') |
|
349 | + . EEH_HTML::img( |
|
350 | + 'https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png', |
|
351 | + '', |
|
352 | + 'eea_ppc_express_checkout_img_' . $this->pm_slug, |
|
353 | + 'eea-ppc-express-checkout-img' |
|
354 | + ), |
|
355 | + '', |
|
356 | + '', |
|
357 | + '', |
|
358 | + 'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-express_checkout"' |
|
359 | + ); |
|
360 | + $ppcp_lbl = EEH_HTML::label( |
|
361 | + esc_html__('Accept credit and debit card payments with PayPal ', 'event_espresso') |
|
362 | + . EEH_HTML::img( |
|
363 | + 'https://www.paypalobjects.com/digitalassets/c/website/marketing/apac/C2/logos-buttons/optimize/Full_Online_Tray_RGB.png', |
|
364 | + '', |
|
365 | + 'eea_ppc_ppcp_img_' . $this->pm_slug, |
|
366 | + 'eea-ppc-ppcp-img' |
|
367 | + ), |
|
368 | + '', |
|
369 | + '', |
|
370 | + '', |
|
371 | + 'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-ppcp"' |
|
372 | + ); |
|
373 | + $checkbox = new EE_Checkbox_Multi_Input( |
|
374 | + [ |
|
375 | + 'express_checkout' => $express_checkout_lbl, |
|
376 | + 'ppcp' => $ppcp_lbl, |
|
377 | + ], |
|
378 | + [ |
|
379 | + 'html_id' => 'eep_ppc_checkout_type_' . $this->pm_slug, |
|
380 | + 'html_label_text' => esc_html__( |
|
381 | + 'Select a product you\'d like to allow at checkout.', |
|
382 | + 'event_espresso' |
|
383 | + ), |
|
384 | + 'html_help_text' => esc_html__( |
|
385 | + 'Select a product you\'d like to allow at checkout.', |
|
386 | + 'event_espresso' |
|
387 | + ), |
|
388 | + 'default' => ['express_checkout', 'ppcp'] |
|
389 | + ] |
|
390 | + ); |
|
391 | + try { |
|
392 | + return EEH_HTML::div( |
|
393 | + $options_lbl |
|
394 | + . $checkbox->get_html_for_input(), |
|
395 | + 'eep_ppc_checkout_types_' . $this->pm_slug, |
|
396 | + 'eep-ppc-checkout-types' |
|
397 | + ); |
|
398 | + } catch (Exception $e) { |
|
399 | + return ''; |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * HTML for onboarding settings dialog. |
|
406 | + * |
|
407 | + * @return EE_Form_Section_Base |
|
408 | + */ |
|
409 | + public function processingMask(): EE_Form_Section_Base |
|
410 | + { |
|
411 | + return new EE_Form_Section_HTML( |
|
412 | + EEH_HTML::div( |
|
413 | + EEH_HTML::div(' ', 'eep_ppc_processing_mask', 'eep-ppc-processing-mask') . |
|
414 | + EEH_HTML::div(' ', 'eep_ppc_processing_spinner', 'ee-spinner ee-spin') . |
|
415 | + EEH_HTML::div( |
|
416 | + esc_html__('The login window should be open. If you don\'t see a new PayPal login window you might need to enable pop-ups in your browser in order to continue.') . |
|
417 | + EEH_HTML::div( |
|
418 | + EEH_HTML::link( |
|
419 | + '#', |
|
420 | + esc_html__('Focus window'), |
|
421 | + esc_html__('Focus window'), |
|
422 | + 'eep_ppc_window_focus_' . $this->pm_slug, |
|
423 | + 'eep-ppc-window-focus' |
|
424 | + ) |
|
425 | + ), |
|
426 | + 'eep_ppc_processing_message', |
|
427 | + 'eep-ppc-processing-message' |
|
428 | + ), |
|
429 | + 'eep_ppc_processing_' . $this->pm_slug, |
|
430 | + 'eep-ppc-processing' |
|
431 | + ) |
|
432 | + ); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * HTML for the disconnect warning dialog. |
|
438 | + * |
|
439 | + * @return EE_Form_Section_Base |
|
440 | + */ |
|
441 | + public function disconnectDialog(): EE_Form_Section_Base |
|
442 | + { |
|
443 | + $message = esc_html__( |
|
444 | + 'Disconnecting your PayPal account will prevent you from offering PayPal services and products on your website.', |
|
445 | + 'event_espresso' |
|
446 | + ); |
|
447 | + return new EE_Form_Section_HTML( |
|
448 | + EEH_HTML::div( |
|
449 | + EEH_HTML::strong( |
|
450 | + $message, |
|
451 | + 'eep_ppc_disconnect_dialog_txt_' . $this->pm_slug, |
|
452 | + 'eep-ppc-disconnect-dialog-txt' |
|
453 | + ) . |
|
454 | + EEH_HTML::div( |
|
455 | + EEH_HTML::link( |
|
456 | + '', |
|
457 | + 'Cancel', |
|
458 | + 'cancel, go back', |
|
459 | + 'eep_ppc_disconnect_cancel_' . $this->pm_slug, |
|
460 | + 'eep-ppc-disconnect-cancel button button--secondary' |
|
461 | + ) . |
|
462 | + EEH_HTML::link( |
|
463 | + '', |
|
464 | + 'Disconnect', |
|
465 | + 'ok, continue', |
|
466 | + 'eep_ppc_disconnect_ok_' . $this->pm_slug, |
|
467 | + 'eep-ppc-disconnect-ok button button--primary-alt' |
|
468 | + ), |
|
469 | + '', |
|
470 | + 'eep-ppc-dialog-yes-no' |
|
471 | + ), |
|
472 | + 'eep_paypal_disconnect_dialog_' . $this->pm_slug |
|
473 | + ) |
|
474 | + ); |
|
475 | + } |
|
476 | 476 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $text, |
102 | 102 | $this->payment_method->get_help_tab_link() |
103 | 103 | ), |
104 | - 'eea_paypal_onboard_heading_' . $this->pm_slug, |
|
104 | + 'eea_paypal_onboard_heading_'.$this->pm_slug, |
|
105 | 105 | 'eea-paypal-onboard-heading' |
106 | 106 | ); |
107 | 107 | } |
@@ -119,26 +119,26 @@ discard block |
||
119 | 119 | // Section to be displayed if not onboard. |
120 | 120 | $subsections['paypal_onboard_btn'] = new EE_Form_Section_HTML( |
121 | 121 | EEH_HTML::tr( |
122 | - $this->getHeader() . |
|
122 | + $this->getHeader(). |
|
123 | 123 | EEH_HTML::td( |
124 | 124 | EEH_HTML::button( |
125 | 125 | $this->onboard_btn_text, |
126 | 126 | 'eea-paypal-onboard-btn button button--primary', |
127 | 127 | '', |
128 | - 'eea_paypal_onboard_btn_' . $this->pm_slug, |
|
128 | + 'eea_paypal_onboard_btn_'.$this->pm_slug, |
|
129 | 129 | ) |
130 | 130 | . EEH_HTML::link( |
131 | 131 | '#', |
132 | 132 | '', |
133 | 133 | '', |
134 | - 'eea_paypal_onboard_trigger_btn_' . $this->pm_slug, |
|
134 | + 'eea_paypal_onboard_trigger_btn_'.$this->pm_slug, |
|
135 | 135 | 'eea-paypal-onboard-trigger-btn', |
136 | 136 | '', |
137 | - 'data-ee-pm-slug="' . $this->pm_slug . '" data-paypal-button="true"' |
|
137 | + 'data-ee-pm-slug="'.$this->pm_slug.'" data-paypal-button="true"' |
|
138 | 138 | ) |
139 | 139 | ), |
140 | - 'eea_paypal_onboard_section_' . $this->pm_slug, |
|
141 | - 'eea-onboard-section eea-onboard-section-' . $this->pm_slug, |
|
140 | + 'eea_paypal_onboard_section_'.$this->pm_slug, |
|
141 | + 'eea-onboard-section eea-onboard-section-'.$this->pm_slug, |
|
142 | 142 | // Are we onboard ? |
143 | 143 | $is_onboard ? 'display:none;' : '' |
144 | 144 | ), |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | $this->getHeader() |
167 | 167 | . EEH_HTML::td( |
168 | 168 | EEH_HTML::img( |
169 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'lib' . DS . 'paypal-onboard.png', |
|
169 | + EEP_PAYPAL_COMMERCE_URL.'assets'.DS.'lib'.DS.'paypal-onboard.png', |
|
170 | 170 | '', |
171 | 171 | 'eea_paypal_offboard_ico', |
172 | 172 | 'eea-paypal-offboard-ico' |
173 | 173 | ) |
174 | 174 | . EEH_HTML::strong( |
175 | 175 | esc_html__('Connected.', 'event_espresso'), |
176 | - 'eea_paypal_offboard_txt_' . $this->pm_slug, |
|
176 | + 'eea_paypal_offboard_txt_'.$this->pm_slug, |
|
177 | 177 | 'eea-paypal-offboard-txt' |
178 | 178 | ) |
179 | 179 | . $onboard_sandbox_section |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | '#', |
183 | 183 | EEH_HTML::span(esc_html__('Disconnect', 'event_espresso')), |
184 | 184 | '', |
185 | - 'eea_paypal_offboard_btn_' . $this->pm_slug, |
|
185 | + 'eea_paypal_offboard_btn_'.$this->pm_slug, |
|
186 | 186 | 'eea-paypal-onboard-btn button button--primary' |
187 | 187 | ) |
188 | 188 | ), |
189 | - 'eea_paypal_offboard_section_' . $this->pm_slug, |
|
190 | - 'eea-offboard-section-' . $this->pm_slug, |
|
189 | + 'eea_paypal_offboard_section_'.$this->pm_slug, |
|
190 | + 'eea-offboard-section-'.$this->pm_slug, |
|
191 | 191 | // Are we onboard ? |
192 | 192 | ! $is_onboard ? 'display:none;' : '' |
193 | 193 | ), |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | { |
207 | 207 | // Is this a test onboarding ? |
208 | 208 | $sandbox_mode_text = $this->pm_instance->debug_mode() ? $this->authed_sandbox_text : ''; |
209 | - return ' ' . EEH_HTML::strong( |
|
209 | + return ' '.EEH_HTML::strong( |
|
210 | 210 | $sandbox_mode_text, |
211 | - 'eea_paypal_onboard_test_txt_' . $this->pm_slug, |
|
211 | + 'eea_paypal_onboard_test_txt_'.$this->pm_slug, |
|
212 | 212 | 'eea-paypal-onboard-test-txt' |
213 | 213 | ); |
214 | 214 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | } catch (Exception $e) { |
229 | 229 | $payer_id = '--'; |
230 | 230 | } |
231 | - return ' ' . EEH_HTML::strong( |
|
231 | + return ' '.EEH_HTML::strong( |
|
232 | 232 | sprintf(esc_html__('Linked account ID: %1$s', 'event_espresso'), $payer_id), |
233 | - 'eea_paypal_seller_id_' . $this->pm_slug, |
|
233 | + 'eea_paypal_seller_id_'.$this->pm_slug, |
|
234 | 234 | 'eea-paypal-seller-id' |
235 | 235 | ); |
236 | 236 | } |
@@ -265,27 +265,27 @@ discard block |
||
265 | 265 | { |
266 | 266 | return new EE_Form_Section_HTML( |
267 | 267 | EEH_HTML::div( |
268 | - $this->countriesSelectHtml() . |
|
269 | - $this->paymentOptionsHtml() . |
|
268 | + $this->countriesSelectHtml(). |
|
269 | + $this->paymentOptionsHtml(). |
|
270 | 270 | EEH_HTML::div( |
271 | 271 | EEH_HTML::link( |
272 | 272 | '', |
273 | 273 | 'Cancel', |
274 | 274 | 'cancel, go back', |
275 | - 'eea_ppc_connect_cancel_' . $this->pm_slug, |
|
275 | + 'eea_ppc_connect_cancel_'.$this->pm_slug, |
|
276 | 276 | 'eea-ppc-connect-cancel button button--secondary' |
277 | - ) . |
|
277 | + ). |
|
278 | 278 | EEH_HTML::link( |
279 | 279 | '', |
280 | 280 | 'Continue', |
281 | 281 | 'ok, continue', |
282 | - 'eea_ppc_connect_ok_' . $this->pm_slug, |
|
282 | + 'eea_ppc_connect_ok_'.$this->pm_slug, |
|
283 | 283 | 'eea-ppc-connect-ok button button--primary-alt' |
284 | 284 | ), |
285 | 285 | '', |
286 | 286 | 'eep-ppc-dialog-yes-no' |
287 | 287 | ), |
288 | - 'eea_paypal_connect_dialog_' . $this->pm_slug |
|
288 | + 'eea_paypal_connect_dialog_'.$this->pm_slug |
|
289 | 289 | ) |
290 | 290 | ); |
291 | 291 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $countries = []; |
302 | 302 | $countries_select = EEH_HTML::strong( |
303 | 303 | esc_html__('Please select a country where your PayPal account is registered:', 'event_espresso'), |
304 | - 'eep_ppc_country_txt_' . $this->pm_slug, |
|
304 | + 'eep_ppc_country_txt_'.$this->pm_slug, |
|
305 | 305 | 'eep-ppc-country-txt' |
306 | 306 | ); |
307 | 307 | try { |
@@ -309,16 +309,16 @@ discard block |
||
309 | 309 | $countries_iso = EEM_Country::instance()->get_all_countries(); |
310 | 310 | foreach ($countries_iso as $iso => $country) { |
311 | 311 | if ($country instanceof EE_Country) { |
312 | - $countries [ $iso ] = $country->get('CNT_name'); |
|
312 | + $countries [$iso] = $country->get('CNT_name'); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | // Now build the select input. |
316 | 316 | $select_input = new EE_Select_Input( |
317 | 317 | $countries, |
318 | 318 | [ |
319 | - 'html_name' => 'eep_ppc_country_' . $this->pm_slug, |
|
320 | - 'html_id' => 'eep_ppc_country_' . $this->pm_slug, |
|
321 | - 'html_class' => 'eep-ppc-country-' . $this->pm_slug, |
|
319 | + 'html_name' => 'eep_ppc_country_'.$this->pm_slug, |
|
320 | + 'html_id' => 'eep_ppc_country_'.$this->pm_slug, |
|
321 | + 'html_class' => 'eep-ppc-country-'.$this->pm_slug, |
|
322 | 322 | 'html_label_text' => esc_html__('Select country', 'event_espresso'), |
323 | 323 | 'required' => true, |
324 | 324 | 'default' => EE_Config::instance()->organization->CNT_ISO ?? 'US' |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | { |
342 | 342 | $options_lbl = EEH_HTML::strong( |
343 | 343 | esc_html__('Select a product you\'d like to allow at checkout:', 'event_espresso'), |
344 | - 'eea_ppc_product_txt_' . $this->pm_slug, |
|
344 | + 'eea_ppc_product_txt_'.$this->pm_slug, |
|
345 | 345 | 'eea-ppc-product-txt' |
346 | 346 | ); |
347 | 347 | $express_checkout_lbl = EEH_HTML::label( |
@@ -349,26 +349,26 @@ discard block |
||
349 | 349 | . EEH_HTML::img( |
350 | 350 | 'https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png', |
351 | 351 | '', |
352 | - 'eea_ppc_express_checkout_img_' . $this->pm_slug, |
|
352 | + 'eea_ppc_express_checkout_img_'.$this->pm_slug, |
|
353 | 353 | 'eea-ppc-express-checkout-img' |
354 | 354 | ), |
355 | 355 | '', |
356 | 356 | '', |
357 | 357 | '', |
358 | - 'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-express_checkout"' |
|
358 | + 'for="'.'eep_ppc_checkout_type_'.$this->pm_slug.'-express_checkout"' |
|
359 | 359 | ); |
360 | 360 | $ppcp_lbl = EEH_HTML::label( |
361 | 361 | esc_html__('Accept credit and debit card payments with PayPal ', 'event_espresso') |
362 | 362 | . EEH_HTML::img( |
363 | 363 | 'https://www.paypalobjects.com/digitalassets/c/website/marketing/apac/C2/logos-buttons/optimize/Full_Online_Tray_RGB.png', |
364 | 364 | '', |
365 | - 'eea_ppc_ppcp_img_' . $this->pm_slug, |
|
365 | + 'eea_ppc_ppcp_img_'.$this->pm_slug, |
|
366 | 366 | 'eea-ppc-ppcp-img' |
367 | 367 | ), |
368 | 368 | '', |
369 | 369 | '', |
370 | 370 | '', |
371 | - 'for="' . 'eep_ppc_checkout_type_' . $this->pm_slug .'-ppcp"' |
|
371 | + 'for="'.'eep_ppc_checkout_type_'.$this->pm_slug.'-ppcp"' |
|
372 | 372 | ); |
373 | 373 | $checkbox = new EE_Checkbox_Multi_Input( |
374 | 374 | [ |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | 'ppcp' => $ppcp_lbl, |
377 | 377 | ], |
378 | 378 | [ |
379 | - 'html_id' => 'eep_ppc_checkout_type_' . $this->pm_slug, |
|
379 | + 'html_id' => 'eep_ppc_checkout_type_'.$this->pm_slug, |
|
380 | 380 | 'html_label_text' => esc_html__( |
381 | 381 | 'Select a product you\'d like to allow at checkout.', |
382 | 382 | 'event_espresso' |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | return EEH_HTML::div( |
393 | 393 | $options_lbl |
394 | 394 | . $checkbox->get_html_for_input(), |
395 | - 'eep_ppc_checkout_types_' . $this->pm_slug, |
|
395 | + 'eep_ppc_checkout_types_'.$this->pm_slug, |
|
396 | 396 | 'eep-ppc-checkout-types' |
397 | 397 | ); |
398 | 398 | } catch (Exception $e) { |
@@ -410,23 +410,23 @@ discard block |
||
410 | 410 | { |
411 | 411 | return new EE_Form_Section_HTML( |
412 | 412 | EEH_HTML::div( |
413 | - EEH_HTML::div(' ', 'eep_ppc_processing_mask', 'eep-ppc-processing-mask') . |
|
414 | - EEH_HTML::div(' ', 'eep_ppc_processing_spinner', 'ee-spinner ee-spin') . |
|
413 | + EEH_HTML::div(' ', 'eep_ppc_processing_mask', 'eep-ppc-processing-mask'). |
|
414 | + EEH_HTML::div(' ', 'eep_ppc_processing_spinner', 'ee-spinner ee-spin'). |
|
415 | 415 | EEH_HTML::div( |
416 | - esc_html__('The login window should be open. If you don\'t see a new PayPal login window you might need to enable pop-ups in your browser in order to continue.') . |
|
416 | + esc_html__('The login window should be open. If you don\'t see a new PayPal login window you might need to enable pop-ups in your browser in order to continue.'). |
|
417 | 417 | EEH_HTML::div( |
418 | 418 | EEH_HTML::link( |
419 | 419 | '#', |
420 | 420 | esc_html__('Focus window'), |
421 | 421 | esc_html__('Focus window'), |
422 | - 'eep_ppc_window_focus_' . $this->pm_slug, |
|
422 | + 'eep_ppc_window_focus_'.$this->pm_slug, |
|
423 | 423 | 'eep-ppc-window-focus' |
424 | 424 | ) |
425 | 425 | ), |
426 | 426 | 'eep_ppc_processing_message', |
427 | 427 | 'eep-ppc-processing-message' |
428 | 428 | ), |
429 | - 'eep_ppc_processing_' . $this->pm_slug, |
|
429 | + 'eep_ppc_processing_'.$this->pm_slug, |
|
430 | 430 | 'eep-ppc-processing' |
431 | 431 | ) |
432 | 432 | ); |
@@ -448,28 +448,28 @@ discard block |
||
448 | 448 | EEH_HTML::div( |
449 | 449 | EEH_HTML::strong( |
450 | 450 | $message, |
451 | - 'eep_ppc_disconnect_dialog_txt_' . $this->pm_slug, |
|
451 | + 'eep_ppc_disconnect_dialog_txt_'.$this->pm_slug, |
|
452 | 452 | 'eep-ppc-disconnect-dialog-txt' |
453 | - ) . |
|
453 | + ). |
|
454 | 454 | EEH_HTML::div( |
455 | 455 | EEH_HTML::link( |
456 | 456 | '', |
457 | 457 | 'Cancel', |
458 | 458 | 'cancel, go back', |
459 | - 'eep_ppc_disconnect_cancel_' . $this->pm_slug, |
|
459 | + 'eep_ppc_disconnect_cancel_'.$this->pm_slug, |
|
460 | 460 | 'eep-ppc-disconnect-cancel button button--secondary' |
461 | - ) . |
|
461 | + ). |
|
462 | 462 | EEH_HTML::link( |
463 | 463 | '', |
464 | 464 | 'Disconnect', |
465 | 465 | 'ok, continue', |
466 | - 'eep_ppc_disconnect_ok_' . $this->pm_slug, |
|
466 | + 'eep_ppc_disconnect_ok_'.$this->pm_slug, |
|
467 | 467 | 'eep-ppc-disconnect-ok button button--primary-alt' |
468 | 468 | ), |
469 | 469 | '', |
470 | 470 | 'eep-ppc-dialog-yes-no' |
471 | 471 | ), |
472 | - 'eep_paypal_disconnect_dialog_' . $this->pm_slug |
|
472 | + 'eep_paypal_disconnect_dialog_'.$this->pm_slug |
|
473 | 473 | ) |
474 | 474 | ); |
475 | 475 | } |
@@ -21,173 +21,173 @@ |
||
21 | 21 | */ |
22 | 22 | class OnboardingForm extends EE_Form_Section_Proper |
23 | 23 | { |
24 | - /** |
|
25 | - * Payment method. |
|
26 | - * |
|
27 | - * @var EE_PMT_Base|null |
|
28 | - */ |
|
29 | - protected $payment_method = null; |
|
24 | + /** |
|
25 | + * Payment method. |
|
26 | + * |
|
27 | + * @var EE_PMT_Base|null |
|
28 | + */ |
|
29 | + protected $payment_method = null; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Payment method instance. |
|
33 | - * |
|
34 | - * @var EE_PMT_Base|null |
|
35 | - */ |
|
36 | - protected $pm_instance = null; |
|
31 | + /** |
|
32 | + * Payment method instance. |
|
33 | + * |
|
34 | + * @var EE_PMT_Base|null |
|
35 | + */ |
|
36 | + protected $pm_instance = null; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Payment method slug. |
|
40 | - * |
|
41 | - * @var EE_PMT_Base|null |
|
42 | - */ |
|
43 | - protected $pm_slug = null; |
|
38 | + /** |
|
39 | + * Payment method slug. |
|
40 | + * |
|
41 | + * @var EE_PMT_Base|null |
|
42 | + */ |
|
43 | + protected $pm_slug = null; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Options field header. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $option_heading = ''; |
|
45 | + /** |
|
46 | + * Options field header. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $option_heading = ''; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Onboarding URL. |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - protected $onboarding_url = ''; |
|
52 | + /** |
|
53 | + * Onboarding URL. |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + protected $onboarding_url = ''; |
|
58 | 58 | |
59 | - /** |
|
60 | - * Onboarding form html entities object. |
|
61 | - * |
|
62 | - * @var OnboardingFormHtml|null |
|
63 | - */ |
|
64 | - protected $form_html = null; |
|
59 | + /** |
|
60 | + * Onboarding form html entities object. |
|
61 | + * |
|
62 | + * @var OnboardingFormHtml|null |
|
63 | + */ |
|
64 | + protected $form_html = null; |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * Class constructor. |
|
69 | - * |
|
70 | - * @param EE_PMT_Base $pmt |
|
71 | - * @param EE_Payment_Method $payment_method |
|
72 | - * @throws EE_Error |
|
73 | - */ |
|
74 | - public function __construct(EE_PMT_Base $pmt, EE_Payment_Method $payment_method) |
|
75 | - { |
|
76 | - $this->payment_method = $pmt; |
|
77 | - $this->pm_instance = $payment_method; |
|
78 | - $this->pm_slug = $this->pm_instance->slug(); |
|
79 | - $this->form_html = new OnboardingFormHtml($pmt, $payment_method); |
|
80 | - // Help tab link as icon. |
|
81 | - $this->option_heading = $this->form_html->getHeader(); |
|
82 | - $options = [ |
|
83 | - 'html_id' => $this->pm_slug . '_pp_commerce_form', |
|
84 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
85 | - 'validation_strategies' => [new EE_Simple_HTML_Validation_Strategy()], |
|
86 | - 'subsections' => $this->onboardSectionContents(), |
|
87 | - ]; |
|
88 | - parent::__construct($options); |
|
89 | - } |
|
67 | + /** |
|
68 | + * Class constructor. |
|
69 | + * |
|
70 | + * @param EE_PMT_Base $pmt |
|
71 | + * @param EE_Payment_Method $payment_method |
|
72 | + * @throws EE_Error |
|
73 | + */ |
|
74 | + public function __construct(EE_PMT_Base $pmt, EE_Payment_Method $payment_method) |
|
75 | + { |
|
76 | + $this->payment_method = $pmt; |
|
77 | + $this->pm_instance = $payment_method; |
|
78 | + $this->pm_slug = $this->pm_instance->slug(); |
|
79 | + $this->form_html = new OnboardingFormHtml($pmt, $payment_method); |
|
80 | + // Help tab link as icon. |
|
81 | + $this->option_heading = $this->form_html->getHeader(); |
|
82 | + $options = [ |
|
83 | + 'html_id' => $this->pm_slug . '_pp_commerce_form', |
|
84 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
85 | + 'validation_strategies' => [new EE_Simple_HTML_Validation_Strategy()], |
|
86 | + 'subsections' => $this->onboardSectionContents(), |
|
87 | + ]; |
|
88 | + parent::__construct($options); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * Add the onboarding options section. |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function onboardSectionContents(): array |
|
98 | - { |
|
99 | - $subsections = []; |
|
100 | - // Get the Onboarding status. |
|
101 | - $is_onboard = EED_PayPalOnboard::isOnboard($this->pm_instance); |
|
102 | - $subsections = $this->form_html->addOnboardButton($subsections, $is_onboard); |
|
103 | - $subsections = $this->form_html->addOffboardButton($subsections, $is_onboard); |
|
104 | - return $this->form_html->addPmSlugHolder($subsections); |
|
105 | - } |
|
92 | + /** |
|
93 | + * Add the onboarding options section. |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function onboardSectionContents(): array |
|
98 | + { |
|
99 | + $subsections = []; |
|
100 | + // Get the Onboarding status. |
|
101 | + $is_onboard = EED_PayPalOnboard::isOnboard($this->pm_instance); |
|
102 | + $subsections = $this->form_html->addOnboardButton($subsections, $is_onboard); |
|
103 | + $subsections = $this->form_html->addOffboardButton($subsections, $is_onboard); |
|
104 | + return $this->form_html->addPmSlugHolder($subsections); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * Add JS needed for this form. |
|
110 | - * This is called automatically when displaying the form. |
|
111 | - * |
|
112 | - * @return void |
|
113 | - * @throws EE_Error |
|
114 | - * @throws ReflectionException |
|
115 | - */ |
|
116 | - public function enqueue_js() |
|
117 | - { |
|
118 | - // Also tell the script about each instance of this PM. |
|
119 | - $pm_versions = []; |
|
120 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active( |
|
121 | - EEM_Payment_Method::scope_cart, |
|
122 | - [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
|
123 | - ); |
|
124 | - foreach ($active_payment_methods as $payment_method) { |
|
125 | - $pm_versions[ $payment_method->slug() ] = [ |
|
126 | - 'pm_slug' => $payment_method->slug(), |
|
127 | - ]; |
|
128 | - } |
|
129 | - $countries_iso = ["US", "AU", "AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", |
|
130 | - "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE"]; |
|
131 | - $parameters = [ |
|
132 | - 'onboard_btn_text' => $this->form_html->onboard_btn_text, |
|
133 | - 'sandbox_btn_text' => $this->form_html->sandbox_btn_text, |
|
134 | - 'sandbox_text' => $this->form_html->authed_sandbox_text, |
|
135 | - 'pm_versions' => $pm_versions, |
|
136 | - 'onboarding_url' => $this->onboarding_url, |
|
137 | - 'supported_countries' => $countries_iso, |
|
138 | - 'connect_dialog' => $this->form_html->connectDialog()->get_html(), |
|
139 | - 'disconnect_dialog' => $this->form_html->disconnectDialog()->get_html(), |
|
140 | - 'processing_mask' => $this->form_html->processingMask()->get_html(), |
|
141 | - 'ee_default_styles' => EE_ADMIN_URL . 'assets/ee-admin-page.css', |
|
142 | - 'wp_stylesheet' => includes_url('css/dashicons.min.css'), |
|
143 | - 'can_disable_input' => method_exists('EE_Form_Input_Base', 'isDisabled'), |
|
144 | - 'connection_notice' => esc_html__('Error while requesting the redirect URL.', 'event_espresso'), |
|
145 | - 'error_response' => esc_html__('Error response received', 'event_espresso'), |
|
146 | - 'request_error' => esc_html__( |
|
147 | - 'Onboarding request Error. Please check the logs on the Payment Methods page.', |
|
148 | - 'event_espresso' |
|
149 | - ), |
|
150 | - 'unknown_container' => esc_html__('Could not specify the parent form.', 'event_espresso'), |
|
151 | - 'pm_nice_name' => esc_html__('PayPal Commerce', 'event_espresso'), |
|
152 | - 'blocked_popup_notice' => esc_html__( |
|
153 | - 'The authentication process could not be executed. Please allow window pop-ups in your browser for this website in order to process a successful authentication.', |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - 'debug_is_on_notice' => esc_html__( |
|
157 | - 'The authentication with PayPal is in sandbox mode! If you wish to process real payments with this payment method, please Offboard and use live credentials to authenticate with PayPal.', |
|
158 | - 'event_espresso' |
|
159 | - ), |
|
160 | - 'debug_is_off_notice' => esc_html__( |
|
161 | - 'The authentication with PayPal is in Live mode! If you wish to test this payment method, please Offboard and use sandbox credentials to authenticate with PayPal.', |
|
162 | - 'event_espresso' |
|
163 | - ), |
|
164 | - 'refresh_alert' => esc_html__( |
|
165 | - 'There was an unexpected error. Please refresh the page and check the logs on the Payment Methods page.', |
|
166 | - 'event_espresso' |
|
167 | - ), |
|
168 | - ]; |
|
169 | - // Styles. |
|
170 | - wp_enqueue_style( |
|
171 | - 'eea_paypal_onboard_form_styles', |
|
172 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-onboard.css', |
|
173 | - [], |
|
174 | - EVENT_ESPRESSO_VERSION |
|
175 | - ); |
|
176 | - // Scripts. |
|
177 | - wp_enqueue_script( |
|
178 | - 'eea_paypal_onboard_form_scripts', |
|
179 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'js' . DS . 'eea-paypal-onboarding.js', |
|
180 | - [], |
|
181 | - EVENT_ESPRESSO_VERSION |
|
182 | - ); |
|
183 | - wp_enqueue_script( |
|
184 | - 'eea_paypal_partner_script', |
|
185 | - 'https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js', |
|
186 | - [], |
|
187 | - EVENT_ESPRESSO_VERSION |
|
188 | - ); |
|
189 | - // Localize the script with some extra data. |
|
190 | - wp_localize_script('eea_paypal_onboard_form_scripts', 'eeaPPOnboardParameters', $parameters); |
|
191 | - parent::enqueue_js(); |
|
192 | - } |
|
108 | + /** |
|
109 | + * Add JS needed for this form. |
|
110 | + * This is called automatically when displaying the form. |
|
111 | + * |
|
112 | + * @return void |
|
113 | + * @throws EE_Error |
|
114 | + * @throws ReflectionException |
|
115 | + */ |
|
116 | + public function enqueue_js() |
|
117 | + { |
|
118 | + // Also tell the script about each instance of this PM. |
|
119 | + $pm_versions = []; |
|
120 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active( |
|
121 | + EEM_Payment_Method::scope_cart, |
|
122 | + [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
|
123 | + ); |
|
124 | + foreach ($active_payment_methods as $payment_method) { |
|
125 | + $pm_versions[ $payment_method->slug() ] = [ |
|
126 | + 'pm_slug' => $payment_method->slug(), |
|
127 | + ]; |
|
128 | + } |
|
129 | + $countries_iso = ["US", "AU", "AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", |
|
130 | + "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE"]; |
|
131 | + $parameters = [ |
|
132 | + 'onboard_btn_text' => $this->form_html->onboard_btn_text, |
|
133 | + 'sandbox_btn_text' => $this->form_html->sandbox_btn_text, |
|
134 | + 'sandbox_text' => $this->form_html->authed_sandbox_text, |
|
135 | + 'pm_versions' => $pm_versions, |
|
136 | + 'onboarding_url' => $this->onboarding_url, |
|
137 | + 'supported_countries' => $countries_iso, |
|
138 | + 'connect_dialog' => $this->form_html->connectDialog()->get_html(), |
|
139 | + 'disconnect_dialog' => $this->form_html->disconnectDialog()->get_html(), |
|
140 | + 'processing_mask' => $this->form_html->processingMask()->get_html(), |
|
141 | + 'ee_default_styles' => EE_ADMIN_URL . 'assets/ee-admin-page.css', |
|
142 | + 'wp_stylesheet' => includes_url('css/dashicons.min.css'), |
|
143 | + 'can_disable_input' => method_exists('EE_Form_Input_Base', 'isDisabled'), |
|
144 | + 'connection_notice' => esc_html__('Error while requesting the redirect URL.', 'event_espresso'), |
|
145 | + 'error_response' => esc_html__('Error response received', 'event_espresso'), |
|
146 | + 'request_error' => esc_html__( |
|
147 | + 'Onboarding request Error. Please check the logs on the Payment Methods page.', |
|
148 | + 'event_espresso' |
|
149 | + ), |
|
150 | + 'unknown_container' => esc_html__('Could not specify the parent form.', 'event_espresso'), |
|
151 | + 'pm_nice_name' => esc_html__('PayPal Commerce', 'event_espresso'), |
|
152 | + 'blocked_popup_notice' => esc_html__( |
|
153 | + 'The authentication process could not be executed. Please allow window pop-ups in your browser for this website in order to process a successful authentication.', |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + 'debug_is_on_notice' => esc_html__( |
|
157 | + 'The authentication with PayPal is in sandbox mode! If you wish to process real payments with this payment method, please Offboard and use live credentials to authenticate with PayPal.', |
|
158 | + 'event_espresso' |
|
159 | + ), |
|
160 | + 'debug_is_off_notice' => esc_html__( |
|
161 | + 'The authentication with PayPal is in Live mode! If you wish to test this payment method, please Offboard and use sandbox credentials to authenticate with PayPal.', |
|
162 | + 'event_espresso' |
|
163 | + ), |
|
164 | + 'refresh_alert' => esc_html__( |
|
165 | + 'There was an unexpected error. Please refresh the page and check the logs on the Payment Methods page.', |
|
166 | + 'event_espresso' |
|
167 | + ), |
|
168 | + ]; |
|
169 | + // Styles. |
|
170 | + wp_enqueue_style( |
|
171 | + 'eea_paypal_onboard_form_styles', |
|
172 | + EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-onboard.css', |
|
173 | + [], |
|
174 | + EVENT_ESPRESSO_VERSION |
|
175 | + ); |
|
176 | + // Scripts. |
|
177 | + wp_enqueue_script( |
|
178 | + 'eea_paypal_onboard_form_scripts', |
|
179 | + EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'js' . DS . 'eea-paypal-onboarding.js', |
|
180 | + [], |
|
181 | + EVENT_ESPRESSO_VERSION |
|
182 | + ); |
|
183 | + wp_enqueue_script( |
|
184 | + 'eea_paypal_partner_script', |
|
185 | + 'https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js', |
|
186 | + [], |
|
187 | + EVENT_ESPRESSO_VERSION |
|
188 | + ); |
|
189 | + // Localize the script with some extra data. |
|
190 | + wp_localize_script('eea_paypal_onboard_form_scripts', 'eeaPPOnboardParameters', $parameters); |
|
191 | + parent::enqueue_js(); |
|
192 | + } |
|
193 | 193 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | // Help tab link as icon. |
81 | 81 | $this->option_heading = $this->form_html->getHeader(); |
82 | 82 | $options = [ |
83 | - 'html_id' => $this->pm_slug . '_pp_commerce_form', |
|
83 | + 'html_id' => $this->pm_slug.'_pp_commerce_form', |
|
84 | 84 | 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
85 | 85 | 'validation_strategies' => [new EE_Simple_HTML_Validation_Strategy()], |
86 | 86 | 'subsections' => $this->onboardSectionContents(), |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | [['PMD_slug' => ['LIKE', '%paypalcheckout%']]] |
123 | 123 | ); |
124 | 124 | foreach ($active_payment_methods as $payment_method) { |
125 | - $pm_versions[ $payment_method->slug() ] = [ |
|
125 | + $pm_versions[$payment_method->slug()] = [ |
|
126 | 126 | 'pm_slug' => $payment_method->slug(), |
127 | 127 | ]; |
128 | 128 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | 'connect_dialog' => $this->form_html->connectDialog()->get_html(), |
139 | 139 | 'disconnect_dialog' => $this->form_html->disconnectDialog()->get_html(), |
140 | 140 | 'processing_mask' => $this->form_html->processingMask()->get_html(), |
141 | - 'ee_default_styles' => EE_ADMIN_URL . 'assets/ee-admin-page.css', |
|
141 | + 'ee_default_styles' => EE_ADMIN_URL.'assets/ee-admin-page.css', |
|
142 | 142 | 'wp_stylesheet' => includes_url('css/dashicons.min.css'), |
143 | 143 | 'can_disable_input' => method_exists('EE_Form_Input_Base', 'isDisabled'), |
144 | 144 | 'connection_notice' => esc_html__('Error while requesting the redirect URL.', 'event_espresso'), |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | // Styles. |
170 | 170 | wp_enqueue_style( |
171 | 171 | 'eea_paypal_onboard_form_styles', |
172 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'css' . DS . 'eea-paypal-onboard.css', |
|
172 | + EEP_PAYPAL_COMMERCE_URL.'assets'.DS.'css'.DS.'eea-paypal-onboard.css', |
|
173 | 173 | [], |
174 | 174 | EVENT_ESPRESSO_VERSION |
175 | 175 | ); |
176 | 176 | // Scripts. |
177 | 177 | wp_enqueue_script( |
178 | 178 | 'eea_paypal_onboard_form_scripts', |
179 | - EEP_PAYPAL_COMMERCE_URL . 'assets' . DS . 'js' . DS . 'eea-paypal-onboarding.js', |
|
179 | + EEP_PAYPAL_COMMERCE_URL.'assets'.DS.'js'.DS.'eea-paypal-onboarding.js', |
|
180 | 180 | [], |
181 | 181 | EVENT_ESPRESSO_VERSION |
182 | 182 | ); |
@@ -24,168 +24,168 @@ |
||
24 | 24 | */ |
25 | 25 | class SettingsForm extends EE_Payment_Method_Form |
26 | 26 | { |
27 | - /** |
|
28 | - * Payment method. |
|
29 | - * |
|
30 | - * @var EE_PMT_Base|null |
|
31 | - */ |
|
32 | - protected $payment_method = null; |
|
27 | + /** |
|
28 | + * Payment method. |
|
29 | + * |
|
30 | + * @var EE_PMT_Base|null |
|
31 | + */ |
|
32 | + protected $payment_method = null; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Payment method instance. |
|
36 | - * |
|
37 | - * @var EE_PMT_Base|null |
|
38 | - */ |
|
39 | - protected $pm_instance = null; |
|
34 | + /** |
|
35 | + * Payment method instance. |
|
36 | + * |
|
37 | + * @var EE_PMT_Base|null |
|
38 | + */ |
|
39 | + protected $pm_instance = null; |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Class constructor. |
|
44 | - * |
|
45 | - * @param EE_PMT_PayPalCheckout $payment_method |
|
46 | - * @param EE_Payment_Method $pm_instance |
|
47 | - * @throws EE_Error |
|
48 | - * @throws ReflectionException |
|
49 | - */ |
|
50 | - public function __construct(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance) |
|
51 | - { |
|
52 | - $form_parameters = []; |
|
53 | - $this->payment_method = $payment_method; |
|
54 | - $this->pm_instance = $pm_instance; |
|
55 | - // Allow Advanced Card Checkout if PPCP checkout type was possible and selected. |
|
56 | - $allowed_type = PayPalExtraMetaManager::getPmOption($pm_instance, Domain::META_KEY_ALLOWED_CHECKOUT_TYPE); |
|
57 | - $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
58 | - if ($is_onboard && ($allowed_type === 'ppcp' || $allowed_type === 'all')) { |
|
59 | - $form_parameters = $this->addCheckoutTypeSelect($form_parameters); |
|
60 | - } |
|
61 | - // Build the PM form. |
|
62 | - parent::__construct($form_parameters); |
|
63 | - // Add a form for PayPal Onboard. |
|
64 | - $this->addOnboardingForm($payment_method, $pm_instance); |
|
65 | - // Add the clear data button. |
|
66 | - $this->clearMetadataButton($pm_instance); |
|
67 | - // Disable inputs if needed. |
|
68 | - $this->toggleSubsections($pm_instance); |
|
69 | - } |
|
42 | + /** |
|
43 | + * Class constructor. |
|
44 | + * |
|
45 | + * @param EE_PMT_PayPalCheckout $payment_method |
|
46 | + * @param EE_Payment_Method $pm_instance |
|
47 | + * @throws EE_Error |
|
48 | + * @throws ReflectionException |
|
49 | + */ |
|
50 | + public function __construct(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance) |
|
51 | + { |
|
52 | + $form_parameters = []; |
|
53 | + $this->payment_method = $payment_method; |
|
54 | + $this->pm_instance = $pm_instance; |
|
55 | + // Allow Advanced Card Checkout if PPCP checkout type was possible and selected. |
|
56 | + $allowed_type = PayPalExtraMetaManager::getPmOption($pm_instance, Domain::META_KEY_ALLOWED_CHECKOUT_TYPE); |
|
57 | + $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
58 | + if ($is_onboard && ($allowed_type === 'ppcp' || $allowed_type === 'all')) { |
|
59 | + $form_parameters = $this->addCheckoutTypeSelect($form_parameters); |
|
60 | + } |
|
61 | + // Build the PM form. |
|
62 | + parent::__construct($form_parameters); |
|
63 | + // Add a form for PayPal Onboard. |
|
64 | + $this->addOnboardingForm($payment_method, $pm_instance); |
|
65 | + // Add the clear data button. |
|
66 | + $this->clearMetadataButton($pm_instance); |
|
67 | + // Disable inputs if needed. |
|
68 | + $this->toggleSubsections($pm_instance); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Adds an onboarding form as a subsection. |
|
74 | - * |
|
75 | - * @param EE_PMT_PayPalCheckout $payment_method |
|
76 | - * @param EE_Payment_Method $pm_instance |
|
77 | - * @return void |
|
78 | - */ |
|
79 | - public function addOnboardingForm(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance): void |
|
80 | - { |
|
81 | - // Add the connect button before the app id field. |
|
82 | - try { |
|
83 | - $this->add_subsections( |
|
84 | - [ |
|
85 | - 'paypal_onboard' => new OnboardingForm($payment_method, $pm_instance), |
|
86 | - ], |
|
87 | - 'PMD_debug_mode', |
|
88 | - false |
|
89 | - ); |
|
90 | - } catch (EE_Error $e) { |
|
91 | - // Simply don't add the form. |
|
92 | - } |
|
93 | - } |
|
72 | + /** |
|
73 | + * Adds an onboarding form as a subsection. |
|
74 | + * |
|
75 | + * @param EE_PMT_PayPalCheckout $payment_method |
|
76 | + * @param EE_Payment_Method $pm_instance |
|
77 | + * @return void |
|
78 | + */ |
|
79 | + public function addOnboardingForm(EE_PMT_PayPalCheckout $payment_method, EE_Payment_Method $pm_instance): void |
|
80 | + { |
|
81 | + // Add the connect button before the app id field. |
|
82 | + try { |
|
83 | + $this->add_subsections( |
|
84 | + [ |
|
85 | + 'paypal_onboard' => new OnboardingForm($payment_method, $pm_instance), |
|
86 | + ], |
|
87 | + 'PMD_debug_mode', |
|
88 | + false |
|
89 | + ); |
|
90 | + } catch (EE_Error $e) { |
|
91 | + // Simply don't add the form. |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * Add a checkout type select. |
|
98 | - * |
|
99 | - * @param array $form_parameters |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function addCheckoutTypeSelect(array $form_parameters): array |
|
103 | - { |
|
104 | - $pm_slug = $this->pm_instance->slug(); |
|
105 | - $allowed_checkout_type = PayPalExtraMetaManager::getPmOption( |
|
106 | - $this->pm_instance, |
|
107 | - Domain::META_KEY_ALLOWED_CHECKOUT_TYPE |
|
108 | - ); |
|
109 | - // Section to be displayed if onboard. |
|
110 | - $form_parameters['extra_meta_inputs'] = [ |
|
111 | - Domain::META_KEY_CHECKOUT_TYPE => new EE_Select_Input( |
|
112 | - [ |
|
113 | - 'express_checkout' => esc_html__('Express Checkout', 'event_espresso'), |
|
114 | - 'ppcp' => esc_html__('Advanced Credit and Debit Card payments', 'event_espresso'), |
|
115 | - 'all' => esc_html__('Both, ACDC and Express Checkout', 'event_espresso'), |
|
116 | - ], |
|
117 | - [ |
|
118 | - 'html_name' => 'eep_checkout_type_option_' . $pm_slug, |
|
119 | - 'html_id' => 'eep_checkout_type_option_' . $pm_slug, |
|
120 | - 'html_class' => 'eep-checkout-type-option-' . $pm_slug, |
|
121 | - 'required' => true, |
|
122 | - 'default' => $allowed_checkout_type, |
|
123 | - ] |
|
124 | - ), |
|
125 | - ]; |
|
126 | - return $form_parameters; |
|
127 | - } |
|
96 | + /** |
|
97 | + * Add a checkout type select. |
|
98 | + * |
|
99 | + * @param array $form_parameters |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function addCheckoutTypeSelect(array $form_parameters): array |
|
103 | + { |
|
104 | + $pm_slug = $this->pm_instance->slug(); |
|
105 | + $allowed_checkout_type = PayPalExtraMetaManager::getPmOption( |
|
106 | + $this->pm_instance, |
|
107 | + Domain::META_KEY_ALLOWED_CHECKOUT_TYPE |
|
108 | + ); |
|
109 | + // Section to be displayed if onboard. |
|
110 | + $form_parameters['extra_meta_inputs'] = [ |
|
111 | + Domain::META_KEY_CHECKOUT_TYPE => new EE_Select_Input( |
|
112 | + [ |
|
113 | + 'express_checkout' => esc_html__('Express Checkout', 'event_espresso'), |
|
114 | + 'ppcp' => esc_html__('Advanced Credit and Debit Card payments', 'event_espresso'), |
|
115 | + 'all' => esc_html__('Both, ACDC and Express Checkout', 'event_espresso'), |
|
116 | + ], |
|
117 | + [ |
|
118 | + 'html_name' => 'eep_checkout_type_option_' . $pm_slug, |
|
119 | + 'html_id' => 'eep_checkout_type_option_' . $pm_slug, |
|
120 | + 'html_class' => 'eep-checkout-type-option-' . $pm_slug, |
|
121 | + 'required' => true, |
|
122 | + 'default' => $allowed_checkout_type, |
|
123 | + ] |
|
124 | + ), |
|
125 | + ]; |
|
126 | + return $form_parameters; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * Adds a button for clearing the PM metadata. |
|
132 | - * |
|
133 | - * @param EE_Payment_Method $pm_instance |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - public function clearMetadataButton(EE_Payment_Method $pm_instance): void |
|
137 | - { |
|
138 | - try { |
|
139 | - $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
140 | - if ($is_onboard) { |
|
141 | - return; |
|
142 | - } |
|
143 | - $button_text = sprintf( |
|
144 | - esc_html__('Clear %1$s metadata', 'event_espresso'), |
|
145 | - $pm_instance->admin_name() |
|
146 | - ); |
|
147 | - $this->add_subsections( |
|
148 | - [ |
|
149 | - 'clear_pm_metadata' => new EE_Form_Section_HTML( |
|
150 | - EEH_HTML::tr( |
|
151 | - EEH_HTML::th(esc_html__('Clear PM metadata ?', 'event_espresso')) . |
|
152 | - EEH_HTML::td( |
|
153 | - EEH_HTML::link( |
|
154 | - '', |
|
155 | - $button_text, |
|
156 | - $button_text, |
|
157 | - 'eea_clear_metadata_' . $pm_instance->slug(), |
|
158 | - 'espresso-button button button--secondary' |
|
159 | - ) |
|
160 | - ) |
|
161 | - ) |
|
162 | - ), |
|
163 | - ], |
|
164 | - 'PMD_order', |
|
165 | - false |
|
166 | - ); |
|
167 | - } catch (EE_Error $e) { |
|
168 | - // Don't add the button if there's some error. |
|
169 | - } |
|
170 | - } |
|
130 | + /** |
|
131 | + * Adds a button for clearing the PM metadata. |
|
132 | + * |
|
133 | + * @param EE_Payment_Method $pm_instance |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + public function clearMetadataButton(EE_Payment_Method $pm_instance): void |
|
137 | + { |
|
138 | + try { |
|
139 | + $is_onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
140 | + if ($is_onboard) { |
|
141 | + return; |
|
142 | + } |
|
143 | + $button_text = sprintf( |
|
144 | + esc_html__('Clear %1$s metadata', 'event_espresso'), |
|
145 | + $pm_instance->admin_name() |
|
146 | + ); |
|
147 | + $this->add_subsections( |
|
148 | + [ |
|
149 | + 'clear_pm_metadata' => new EE_Form_Section_HTML( |
|
150 | + EEH_HTML::tr( |
|
151 | + EEH_HTML::th(esc_html__('Clear PM metadata ?', 'event_espresso')) . |
|
152 | + EEH_HTML::td( |
|
153 | + EEH_HTML::link( |
|
154 | + '', |
|
155 | + $button_text, |
|
156 | + $button_text, |
|
157 | + 'eea_clear_metadata_' . $pm_instance->slug(), |
|
158 | + 'espresso-button button button--secondary' |
|
159 | + ) |
|
160 | + ) |
|
161 | + ) |
|
162 | + ), |
|
163 | + ], |
|
164 | + 'PMD_order', |
|
165 | + false |
|
166 | + ); |
|
167 | + } catch (EE_Error $e) { |
|
168 | + // Don't add the button if there's some error. |
|
169 | + } |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | - /** |
|
174 | - * Toggles subsections depending on the OAuth status etc. |
|
175 | - * |
|
176 | - * @param EE_Payment_Method $pm_instance |
|
177 | - * @return void |
|
178 | - * @throws EE_Error |
|
179 | - */ |
|
180 | - private function toggleSubsections(EE_Payment_Method $pm_instance): void |
|
181 | - { |
|
182 | - $onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
183 | - // Don't allow changing the debug mode setting while connected. |
|
184 | - if ($onboard) { |
|
185 | - $debug_mode_input = $this->get_input('PMD_debug_mode', false); |
|
186 | - if (method_exists($debug_mode_input, 'isDisabled')) { |
|
187 | - $debug_mode_input->disable(); |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
173 | + /** |
|
174 | + * Toggles subsections depending on the OAuth status etc. |
|
175 | + * |
|
176 | + * @param EE_Payment_Method $pm_instance |
|
177 | + * @return void |
|
178 | + * @throws EE_Error |
|
179 | + */ |
|
180 | + private function toggleSubsections(EE_Payment_Method $pm_instance): void |
|
181 | + { |
|
182 | + $onboard = EED_PayPalOnboard::isOnboard($pm_instance); |
|
183 | + // Don't allow changing the debug mode setting while connected. |
|
184 | + if ($onboard) { |
|
185 | + $debug_mode_input = $this->get_input('PMD_debug_mode', false); |
|
186 | + if (method_exists($debug_mode_input, 'isDisabled')) { |
|
187 | + $debug_mode_input->disable(); |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | 191 | } |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | 'all' => esc_html__('Both, ACDC and Express Checkout', 'event_espresso'), |
116 | 116 | ], |
117 | 117 | [ |
118 | - 'html_name' => 'eep_checkout_type_option_' . $pm_slug, |
|
119 | - 'html_id' => 'eep_checkout_type_option_' . $pm_slug, |
|
120 | - 'html_class' => 'eep-checkout-type-option-' . $pm_slug, |
|
118 | + 'html_name' => 'eep_checkout_type_option_'.$pm_slug, |
|
119 | + 'html_id' => 'eep_checkout_type_option_'.$pm_slug, |
|
120 | + 'html_class' => 'eep-checkout-type-option-'.$pm_slug, |
|
121 | 121 | 'required' => true, |
122 | 122 | 'default' => $allowed_checkout_type, |
123 | 123 | ] |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | [ |
149 | 149 | 'clear_pm_metadata' => new EE_Form_Section_HTML( |
150 | 150 | EEH_HTML::tr( |
151 | - EEH_HTML::th(esc_html__('Clear PM metadata ?', 'event_espresso')) . |
|
151 | + EEH_HTML::th(esc_html__('Clear PM metadata ?', 'event_espresso')). |
|
152 | 152 | EEH_HTML::td( |
153 | 153 | EEH_HTML::link( |
154 | 154 | '', |
155 | 155 | $button_text, |
156 | 156 | $button_text, |
157 | - 'eea_clear_metadata_' . $pm_instance->slug(), |
|
157 | + 'eea_clear_metadata_'.$pm_instance->slug(), |
|
158 | 158 | 'espresso-button button button--secondary' |
159 | 159 | ) |
160 | 160 | ) |
@@ -15,243 +15,243 @@ |
||
15 | 15 | */ |
16 | 16 | class EEG_PayPalCheckout extends EE_Onsite_Gateway |
17 | 17 | { |
18 | - /** |
|
19 | - * Currencies supported by this gateway. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $_currencies_supported = [ |
|
24 | - 'AUD', |
|
25 | - 'BRL', |
|
26 | - 'CAD', |
|
27 | - 'CNY', |
|
28 | - 'CZK', |
|
29 | - 'DKK', |
|
30 | - 'EUR', |
|
31 | - 'HKD', |
|
32 | - 'HUF', |
|
33 | - 'ILS', |
|
34 | - 'JPY', |
|
35 | - 'MYR', |
|
36 | - 'MXN', |
|
37 | - 'TWD', |
|
38 | - 'NZD', |
|
39 | - 'NOK', |
|
40 | - 'PHP', |
|
41 | - 'PLN', |
|
42 | - 'GBP', |
|
43 | - 'RUB', |
|
44 | - 'SGD', |
|
45 | - 'SEK', |
|
46 | - 'CHF', |
|
47 | - 'THB', |
|
48 | - 'USD', |
|
49 | - ]; |
|
18 | + /** |
|
19 | + * Currencies supported by this gateway. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $_currencies_supported = [ |
|
24 | + 'AUD', |
|
25 | + 'BRL', |
|
26 | + 'CAD', |
|
27 | + 'CNY', |
|
28 | + 'CZK', |
|
29 | + 'DKK', |
|
30 | + 'EUR', |
|
31 | + 'HKD', |
|
32 | + 'HUF', |
|
33 | + 'ILS', |
|
34 | + 'JPY', |
|
35 | + 'MYR', |
|
36 | + 'MXN', |
|
37 | + 'TWD', |
|
38 | + 'NZD', |
|
39 | + 'NOK', |
|
40 | + 'PHP', |
|
41 | + 'PLN', |
|
42 | + 'GBP', |
|
43 | + 'RUB', |
|
44 | + 'SGD', |
|
45 | + 'SEK', |
|
46 | + 'CHF', |
|
47 | + 'THB', |
|
48 | + 'USD', |
|
49 | + ]; |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @param EE_Payment|null $payment |
|
54 | - * @param array|null $billing_info |
|
55 | - * @return EE_Payment |
|
56 | - * @throws EE_Error |
|
57 | - * @throws ReflectionException |
|
58 | - */ |
|
59 | - public function do_direct_payment($payment, $billing_info = null) |
|
60 | - { |
|
61 | - $failed_status = $this->_pay_model->failed_status(); |
|
62 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
63 | - // Check the payment. |
|
64 | - $payment_valid = $this->validateThisPayment($payment, $request); |
|
65 | - if ($payment_valid->details() === 'error' && $payment_valid->status() === $failed_status) { |
|
66 | - return $payment_valid; |
|
67 | - } |
|
68 | - $transaction = $payment->transaction(); |
|
69 | - $payment_method = $transaction->payment_method(); |
|
52 | + /** |
|
53 | + * @param EE_Payment|null $payment |
|
54 | + * @param array|null $billing_info |
|
55 | + * @return EE_Payment |
|
56 | + * @throws EE_Error |
|
57 | + * @throws ReflectionException |
|
58 | + */ |
|
59 | + public function do_direct_payment($payment, $billing_info = null) |
|
60 | + { |
|
61 | + $failed_status = $this->_pay_model->failed_status(); |
|
62 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
63 | + // Check the payment. |
|
64 | + $payment_valid = $this->validateThisPayment($payment, $request); |
|
65 | + if ($payment_valid->details() === 'error' && $payment_valid->status() === $failed_status) { |
|
66 | + return $payment_valid; |
|
67 | + } |
|
68 | + $transaction = $payment->transaction(); |
|
69 | + $payment_method = $transaction->payment_method(); |
|
70 | 70 | |
71 | - // Get saved order details. |
|
72 | - try { |
|
73 | - $order = PayPalExtraMetaManager::getPmOption($payment_method, Domain::META_KEY_LAST_ORDER); |
|
74 | - } catch (Exception $exception) { |
|
75 | - return $this->setPaymentFailure( |
|
76 | - $payment, |
|
77 | - $failed_status, |
|
78 | - $request->postParams(), |
|
79 | - $exception->getMessage() |
|
80 | - ); |
|
81 | - } |
|
82 | - $order_id = $request->getRequestParam('pp_order_id', '', DataType::STRING); |
|
83 | - $order_invalid = $this->orderInvalid($order_id, $order); |
|
84 | - if ($order_invalid) { |
|
85 | - return $this->setPaymentFailure($payment, $failed_status, [$order, $request->postParams()], $order_invalid); |
|
86 | - } |
|
71 | + // Get saved order details. |
|
72 | + try { |
|
73 | + $order = PayPalExtraMetaManager::getPmOption($payment_method, Domain::META_KEY_LAST_ORDER); |
|
74 | + } catch (Exception $exception) { |
|
75 | + return $this->setPaymentFailure( |
|
76 | + $payment, |
|
77 | + $failed_status, |
|
78 | + $request->postParams(), |
|
79 | + $exception->getMessage() |
|
80 | + ); |
|
81 | + } |
|
82 | + $order_id = $request->getRequestParam('pp_order_id', '', DataType::STRING); |
|
83 | + $order_invalid = $this->orderInvalid($order_id, $order); |
|
84 | + if ($order_invalid) { |
|
85 | + return $this->setPaymentFailure($payment, $failed_status, [$order, $request->postParams()], $order_invalid); |
|
86 | + } |
|
87 | 87 | |
88 | - // Remove the saved order data. |
|
89 | - PayPalExtraMetaManager::deletePmOption($payment_method, Domain::META_KEY_LAST_ORDER); |
|
90 | - // Looks like all is good. Do a payment success. |
|
91 | - return $this->setPaymentSuccess($payment, $transaction, $order); |
|
92 | - } |
|
88 | + // Remove the saved order data. |
|
89 | + PayPalExtraMetaManager::deletePmOption($payment_method, Domain::META_KEY_LAST_ORDER); |
|
90 | + // Looks like all is good. Do a payment success. |
|
91 | + return $this->setPaymentSuccess($payment, $transaction, $order); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | |
95 | - /** |
|
96 | - * Validate the payment. |
|
97 | - * |
|
98 | - * @param mixed $payment |
|
99 | - * @param RequestInterface $request |
|
100 | - * @return EE_Payment |
|
101 | - * @throws EE_Error |
|
102 | - * @throws ReflectionException |
|
103 | - */ |
|
104 | - public function validateThisPayment(?EE_Payment $payment, RequestInterface $request): EE_Payment |
|
105 | - { |
|
106 | - $failed_status = $this->_pay_model->failed_status(); |
|
107 | - // Check the payment. |
|
108 | - if (! $payment instanceof EE_Payment) { |
|
109 | - $payment = EE_Payment::new_instance(); |
|
110 | - $error_message = esc_html__('Error. No associated payment was found.', 'event_espresso'); |
|
111 | - return $this->setPaymentFailure($payment, $failed_status, $request->postParams(), $error_message); |
|
112 | - } |
|
113 | - // Check the transaction. |
|
114 | - $transaction = $payment->transaction(); |
|
115 | - if (! $transaction instanceof EE_Transaction) { |
|
116 | - $error_message = esc_html__( |
|
117 | - 'Could not process this payment because it has no associated transaction.', |
|
118 | - 'event_espresso' |
|
119 | - ); |
|
120 | - return $this->setPaymentFailure($payment, $failed_status, $request->postParams(), $error_message); |
|
121 | - } |
|
122 | - // Check for the payment nonce. |
|
123 | - // $order_nonce = $request->getRequestParam('pp_order_nonce'); |
|
124 | - // if (empty($order_nonce) || ! wp_verify_nonce($order_nonce, Domain::CAPTURE_ORDER_NONCE_NAME)) { |
|
125 | - // $error_message = esc_html__('No or incorrect order capture nonce provided !', 'event_espresso'); |
|
126 | - // return $this->setPaymentFailure($payment, $failed_status, $request->postParams(), $error_message); |
|
127 | - // } |
|
128 | - return $payment; |
|
129 | - } |
|
95 | + /** |
|
96 | + * Validate the payment. |
|
97 | + * |
|
98 | + * @param mixed $payment |
|
99 | + * @param RequestInterface $request |
|
100 | + * @return EE_Payment |
|
101 | + * @throws EE_Error |
|
102 | + * @throws ReflectionException |
|
103 | + */ |
|
104 | + public function validateThisPayment(?EE_Payment $payment, RequestInterface $request): EE_Payment |
|
105 | + { |
|
106 | + $failed_status = $this->_pay_model->failed_status(); |
|
107 | + // Check the payment. |
|
108 | + if (! $payment instanceof EE_Payment) { |
|
109 | + $payment = EE_Payment::new_instance(); |
|
110 | + $error_message = esc_html__('Error. No associated payment was found.', 'event_espresso'); |
|
111 | + return $this->setPaymentFailure($payment, $failed_status, $request->postParams(), $error_message); |
|
112 | + } |
|
113 | + // Check the transaction. |
|
114 | + $transaction = $payment->transaction(); |
|
115 | + if (! $transaction instanceof EE_Transaction) { |
|
116 | + $error_message = esc_html__( |
|
117 | + 'Could not process this payment because it has no associated transaction.', |
|
118 | + 'event_espresso' |
|
119 | + ); |
|
120 | + return $this->setPaymentFailure($payment, $failed_status, $request->postParams(), $error_message); |
|
121 | + } |
|
122 | + // Check for the payment nonce. |
|
123 | + // $order_nonce = $request->getRequestParam('pp_order_nonce'); |
|
124 | + // if (empty($order_nonce) || ! wp_verify_nonce($order_nonce, Domain::CAPTURE_ORDER_NONCE_NAME)) { |
|
125 | + // $error_message = esc_html__('No or incorrect order capture nonce provided !', 'event_espresso'); |
|
126 | + // return $this->setPaymentFailure($payment, $failed_status, $request->postParams(), $error_message); |
|
127 | + // } |
|
128 | + return $payment; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * Validate the Order. |
|
134 | - * |
|
135 | - * @param string $provided_order_id |
|
136 | - * @param $order |
|
137 | - * @return string string if error and empty if valid. |
|
138 | - */ |
|
139 | - public function orderInvalid(string $provided_order_id, $order): string |
|
140 | - { |
|
141 | - // Check the provided order ID. |
|
142 | - if (! $provided_order_id) { |
|
143 | - return esc_html__('Invalid Order ID provided !', 'event_espresso'); |
|
144 | - } |
|
145 | - if (! $order || ! is_array($order)) { |
|
146 | - return esc_html__('Order data in wrong format.', 'event_espresso'); |
|
147 | - } |
|
148 | - if ($order['id'] !== $provided_order_id) { |
|
149 | - return esc_html__('Order ID mismatch.', 'event_espresso'); |
|
150 | - } |
|
151 | - if ($order['status'] !== 'COMPLETED') { |
|
152 | - return esc_html__('Order not completed.', 'event_espresso'); |
|
153 | - } |
|
154 | - return ''; |
|
155 | - } |
|
132 | + /** |
|
133 | + * Validate the Order. |
|
134 | + * |
|
135 | + * @param string $provided_order_id |
|
136 | + * @param $order |
|
137 | + * @return string string if error and empty if valid. |
|
138 | + */ |
|
139 | + public function orderInvalid(string $provided_order_id, $order): string |
|
140 | + { |
|
141 | + // Check the provided order ID. |
|
142 | + if (! $provided_order_id) { |
|
143 | + return esc_html__('Invalid Order ID provided !', 'event_espresso'); |
|
144 | + } |
|
145 | + if (! $order || ! is_array($order)) { |
|
146 | + return esc_html__('Order data in wrong format.', 'event_espresso'); |
|
147 | + } |
|
148 | + if ($order['id'] !== $provided_order_id) { |
|
149 | + return esc_html__('Order ID mismatch.', 'event_espresso'); |
|
150 | + } |
|
151 | + if ($order['status'] !== 'COMPLETED') { |
|
152 | + return esc_html__('Order not completed.', 'event_espresso'); |
|
153 | + } |
|
154 | + return ''; |
|
155 | + } |
|
156 | 156 | |
157 | 157 | |
158 | - /** |
|
159 | - * Set a payment error and log the data. |
|
160 | - * |
|
161 | - * @param EE_Payment $payment |
|
162 | - * @param string $status |
|
163 | - * @param array|string $response_data |
|
164 | - * @param string $err_message |
|
165 | - * @return EE_Payment |
|
166 | - * @throws EE_Error|ReflectionException |
|
167 | - */ |
|
168 | - public function setPaymentFailure( |
|
169 | - EE_Payment $payment, |
|
170 | - string $status, |
|
171 | - $response_data, |
|
172 | - string $err_message = '' |
|
173 | - ): EE_Payment { |
|
174 | - $this->log(['Error request data:' => $response_data], $payment); |
|
175 | - $payment->set_status($status); |
|
176 | - $payment->set_details('error'); |
|
177 | - $payment->set_gateway_response($err_message); |
|
178 | - return $payment; |
|
179 | - } |
|
158 | + /** |
|
159 | + * Set a payment error and log the data. |
|
160 | + * |
|
161 | + * @param EE_Payment $payment |
|
162 | + * @param string $status |
|
163 | + * @param array|string $response_data |
|
164 | + * @param string $err_message |
|
165 | + * @return EE_Payment |
|
166 | + * @throws EE_Error|ReflectionException |
|
167 | + */ |
|
168 | + public function setPaymentFailure( |
|
169 | + EE_Payment $payment, |
|
170 | + string $status, |
|
171 | + $response_data, |
|
172 | + string $err_message = '' |
|
173 | + ): EE_Payment { |
|
174 | + $this->log(['Error request data:' => $response_data], $payment); |
|
175 | + $payment->set_status($status); |
|
176 | + $payment->set_details('error'); |
|
177 | + $payment->set_gateway_response($err_message); |
|
178 | + return $payment; |
|
179 | + } |
|
180 | 180 | |
181 | 181 | |
182 | - /** |
|
183 | - * Set the payment success. |
|
184 | - * |
|
185 | - * @param EE_Payment $payment |
|
186 | - * @param EE_Transaction $transaction |
|
187 | - * @param array $order |
|
188 | - * @return EE_Payment |
|
189 | - * @throws EE_Error|ReflectionException |
|
190 | - */ |
|
191 | - public function setPaymentSuccess(EE_Payment $payment, EE_Transaction $transaction, array $order): EE_Payment |
|
192 | - { |
|
193 | - $amount = $order['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0; |
|
194 | - if (! $amount) { |
|
195 | - $this->log(['Success order but amount is 0 !' => $order], $payment); |
|
196 | - } |
|
197 | - $payment->set_status(EEM_Payment::status_id_approved); |
|
198 | - $payment->set_amount((float) $amount); |
|
199 | - $payment->set_txn_id_chq_nmbr($order['purchase_units'][0]['payments']['captures'][0]['id'] ?? $order['id']); |
|
200 | - $payment->set_gateway_response($order['status'] ?? 'success'); |
|
201 | - $this->saveBillingDetails($payment, $transaction, $order); |
|
202 | - return $payment; |
|
203 | - } |
|
182 | + /** |
|
183 | + * Set the payment success. |
|
184 | + * |
|
185 | + * @param EE_Payment $payment |
|
186 | + * @param EE_Transaction $transaction |
|
187 | + * @param array $order |
|
188 | + * @return EE_Payment |
|
189 | + * @throws EE_Error|ReflectionException |
|
190 | + */ |
|
191 | + public function setPaymentSuccess(EE_Payment $payment, EE_Transaction $transaction, array $order): EE_Payment |
|
192 | + { |
|
193 | + $amount = $order['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0; |
|
194 | + if (! $amount) { |
|
195 | + $this->log(['Success order but amount is 0 !' => $order], $payment); |
|
196 | + } |
|
197 | + $payment->set_status(EEM_Payment::status_id_approved); |
|
198 | + $payment->set_amount((float) $amount); |
|
199 | + $payment->set_txn_id_chq_nmbr($order['purchase_units'][0]['payments']['captures'][0]['id'] ?? $order['id']); |
|
200 | + $payment->set_gateway_response($order['status'] ?? 'success'); |
|
201 | + $this->saveBillingDetails($payment, $transaction, $order); |
|
202 | + return $payment; |
|
203 | + } |
|
204 | 204 | |
205 | 205 | |
206 | - /** |
|
207 | - * Save some transaction details, like billing information. |
|
208 | - * |
|
209 | - * @param EE_Payment $payment |
|
210 | - * @param EE_Transaction $transaction |
|
211 | - * @param array $order |
|
212 | - * @return void |
|
213 | - * @throws EE_Error|ReflectionException |
|
214 | - */ |
|
215 | - public function saveBillingDetails(EE_Payment $payment, EE_Transaction $transaction, array $order): void |
|
216 | - { |
|
217 | - $input_values = []; |
|
218 | - $primary_reg = $transaction->primary_registration(); |
|
219 | - $attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null; |
|
220 | - $transaction = $payment->transaction(); |
|
221 | - $payment_method = $transaction->payment_method(); |
|
222 | - $postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base |
|
223 | - ? 'billing_info_' . $payment_method->type_obj()->system_name() |
|
224 | - : ''; |
|
225 | - if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) { |
|
226 | - // I guess we are done here then. Just save what we have. |
|
227 | - $payment->set_details($order); |
|
228 | - return; |
|
229 | - } |
|
230 | - // Do we have order information from the express checkout (PayPal button) ? |
|
231 | - if (! empty($order['payment_source']['paypal'])) { |
|
232 | - $payer = $order['payment_source']['paypal']; |
|
233 | - $payer_name = $payer['name'] ?? ''; |
|
234 | - $input_values['first_name'] = $payer_name['given_name'] ?? $attendee->fname(); |
|
235 | - $input_values['last_name'] = $payer_name['surname'] ?? $attendee->lname(); |
|
236 | - $input_values['email'] = $payer_name['email_address'] ?? $attendee->email(); |
|
237 | - $input_values['address'] = $payer_name['address_line_1'] ?? $attendee->address(); |
|
238 | - $input_values['address2'] = $payer_name['address_line_2'] ?? $attendee->address2(); |
|
239 | - $input_values['city'] = $payer_name['admin_area_2'] ?? $attendee->city(); |
|
240 | - $input_values['country'] = $payer_name['country_code'] ?? $attendee->country(); |
|
241 | - $input_values['zip'] = $payer_name['postal_code'] ?? $attendee->zip(); |
|
242 | - } |
|
243 | - // Or card information from ACDC ? |
|
244 | - if (! empty($order['payment_source']['card'])) { |
|
245 | - $payer_card = $order['payment_source']['card']; |
|
246 | - if (! empty($payer_card['name'])) { |
|
247 | - $full_name = explode(' ', $payer_card['name']); |
|
248 | - // Don't need to save each field because others should be populated from the billing form. |
|
249 | - $input_values['credit_card'] = $payer_card['last_digits'] ?? ''; |
|
250 | - $input_values['first_name'] = $full_name[0] ?? $attendee->fname(); |
|
251 | - $input_values['last_name'] = $full_name[1] ?? $attendee->lname(); |
|
252 | - } |
|
253 | - } |
|
254 | - update_post_meta($attendee->ID(), $postmeta_name, $input_values); |
|
255 | - $attendee->save(); |
|
256 | - } |
|
206 | + /** |
|
207 | + * Save some transaction details, like billing information. |
|
208 | + * |
|
209 | + * @param EE_Payment $payment |
|
210 | + * @param EE_Transaction $transaction |
|
211 | + * @param array $order |
|
212 | + * @return void |
|
213 | + * @throws EE_Error|ReflectionException |
|
214 | + */ |
|
215 | + public function saveBillingDetails(EE_Payment $payment, EE_Transaction $transaction, array $order): void |
|
216 | + { |
|
217 | + $input_values = []; |
|
218 | + $primary_reg = $transaction->primary_registration(); |
|
219 | + $attendee = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null; |
|
220 | + $transaction = $payment->transaction(); |
|
221 | + $payment_method = $transaction->payment_method(); |
|
222 | + $postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base |
|
223 | + ? 'billing_info_' . $payment_method->type_obj()->system_name() |
|
224 | + : ''; |
|
225 | + if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) { |
|
226 | + // I guess we are done here then. Just save what we have. |
|
227 | + $payment->set_details($order); |
|
228 | + return; |
|
229 | + } |
|
230 | + // Do we have order information from the express checkout (PayPal button) ? |
|
231 | + if (! empty($order['payment_source']['paypal'])) { |
|
232 | + $payer = $order['payment_source']['paypal']; |
|
233 | + $payer_name = $payer['name'] ?? ''; |
|
234 | + $input_values['first_name'] = $payer_name['given_name'] ?? $attendee->fname(); |
|
235 | + $input_values['last_name'] = $payer_name['surname'] ?? $attendee->lname(); |
|
236 | + $input_values['email'] = $payer_name['email_address'] ?? $attendee->email(); |
|
237 | + $input_values['address'] = $payer_name['address_line_1'] ?? $attendee->address(); |
|
238 | + $input_values['address2'] = $payer_name['address_line_2'] ?? $attendee->address2(); |
|
239 | + $input_values['city'] = $payer_name['admin_area_2'] ?? $attendee->city(); |
|
240 | + $input_values['country'] = $payer_name['country_code'] ?? $attendee->country(); |
|
241 | + $input_values['zip'] = $payer_name['postal_code'] ?? $attendee->zip(); |
|
242 | + } |
|
243 | + // Or card information from ACDC ? |
|
244 | + if (! empty($order['payment_source']['card'])) { |
|
245 | + $payer_card = $order['payment_source']['card']; |
|
246 | + if (! empty($payer_card['name'])) { |
|
247 | + $full_name = explode(' ', $payer_card['name']); |
|
248 | + // Don't need to save each field because others should be populated from the billing form. |
|
249 | + $input_values['credit_card'] = $payer_card['last_digits'] ?? ''; |
|
250 | + $input_values['first_name'] = $full_name[0] ?? $attendee->fname(); |
|
251 | + $input_values['last_name'] = $full_name[1] ?? $attendee->lname(); |
|
252 | + } |
|
253 | + } |
|
254 | + update_post_meta($attendee->ID(), $postmeta_name, $input_values); |
|
255 | + $attendee->save(); |
|
256 | + } |
|
257 | 257 | } |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | { |
106 | 106 | $failed_status = $this->_pay_model->failed_status(); |
107 | 107 | // Check the payment. |
108 | - if (! $payment instanceof EE_Payment) { |
|
108 | + if ( ! $payment instanceof EE_Payment) { |
|
109 | 109 | $payment = EE_Payment::new_instance(); |
110 | 110 | $error_message = esc_html__('Error. No associated payment was found.', 'event_espresso'); |
111 | 111 | return $this->setPaymentFailure($payment, $failed_status, $request->postParams(), $error_message); |
112 | 112 | } |
113 | 113 | // Check the transaction. |
114 | 114 | $transaction = $payment->transaction(); |
115 | - if (! $transaction instanceof EE_Transaction) { |
|
115 | + if ( ! $transaction instanceof EE_Transaction) { |
|
116 | 116 | $error_message = esc_html__( |
117 | 117 | 'Could not process this payment because it has no associated transaction.', |
118 | 118 | 'event_espresso' |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | public function orderInvalid(string $provided_order_id, $order): string |
140 | 140 | { |
141 | 141 | // Check the provided order ID. |
142 | - if (! $provided_order_id) { |
|
142 | + if ( ! $provided_order_id) { |
|
143 | 143 | return esc_html__('Invalid Order ID provided !', 'event_espresso'); |
144 | 144 | } |
145 | - if (! $order || ! is_array($order)) { |
|
145 | + if ( ! $order || ! is_array($order)) { |
|
146 | 146 | return esc_html__('Order data in wrong format.', 'event_espresso'); |
147 | 147 | } |
148 | 148 | if ($order['id'] !== $provided_order_id) { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | public function setPaymentSuccess(EE_Payment $payment, EE_Transaction $transaction, array $order): EE_Payment |
192 | 192 | { |
193 | 193 | $amount = $order['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0; |
194 | - if (! $amount) { |
|
194 | + if ( ! $amount) { |
|
195 | 195 | $this->log(['Success order but amount is 0 !' => $order], $payment); |
196 | 196 | } |
197 | 197 | $payment->set_status(EEM_Payment::status_id_approved); |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $transaction = $payment->transaction(); |
221 | 221 | $payment_method = $transaction->payment_method(); |
222 | 222 | $postmeta_name = $payment_method->type_obj() instanceof EE_PMT_Base |
223 | - ? 'billing_info_' . $payment_method->type_obj()->system_name() |
|
223 | + ? 'billing_info_'.$payment_method->type_obj()->system_name() |
|
224 | 224 | : ''; |
225 | 225 | if (empty($order['payment_source']) || ! $attendee instanceof EE_Attendee) { |
226 | 226 | // I guess we are done here then. Just save what we have. |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | return; |
229 | 229 | } |
230 | 230 | // Do we have order information from the express checkout (PayPal button) ? |
231 | - if (! empty($order['payment_source']['paypal'])) { |
|
231 | + if ( ! empty($order['payment_source']['paypal'])) { |
|
232 | 232 | $payer = $order['payment_source']['paypal']; |
233 | 233 | $payer_name = $payer['name'] ?? ''; |
234 | 234 | $input_values['first_name'] = $payer_name['given_name'] ?? $attendee->fname(); |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | $input_values['zip'] = $payer_name['postal_code'] ?? $attendee->zip(); |
242 | 242 | } |
243 | 243 | // Or card information from ACDC ? |
244 | - if (! empty($order['payment_source']['card'])) { |
|
244 | + if ( ! empty($order['payment_source']['card'])) { |
|
245 | 245 | $payer_card = $order['payment_source']['card']; |
246 | - if (! empty($payer_card['name'])) { |
|
246 | + if ( ! empty($payer_card['name'])) { |
|
247 | 247 | $full_name = explode(' ', $payer_card['name']); |
248 | 248 | // Don't need to save each field because others should be populated from the billing form. |
249 | 249 | $input_values['credit_card'] = $payer_card['last_digits'] ?? ''; |
@@ -16,147 +16,147 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_PMT_PayPalCheckout extends EE_PMT_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @param EE_Payment_Method|null $pm_instance |
|
21 | - * @throws ReflectionException |
|
22 | - * @throws EE_Error |
|
23 | - */ |
|
24 | - public function __construct($pm_instance = null) |
|
25 | - { |
|
26 | - $this->_template_path = dirname(__FILE__) . DS . 'templates' . DS; |
|
27 | - $this->_default_description = esc_html__('Please provide the following billing information.', 'event_espresso'); |
|
28 | - $this->_default_button_url = $this->file_url() . 'lib/default-cc-logo.png'; |
|
29 | - $this->_pretty_name = esc_html__('PayPal Commerce', 'event_espresso'); |
|
30 | - $this->_cache_billing_form = true; |
|
31 | - $this->_requires_https = true; |
|
19 | + /** |
|
20 | + * @param EE_Payment_Method|null $pm_instance |
|
21 | + * @throws ReflectionException |
|
22 | + * @throws EE_Error |
|
23 | + */ |
|
24 | + public function __construct($pm_instance = null) |
|
25 | + { |
|
26 | + $this->_template_path = dirname(__FILE__) . DS . 'templates' . DS; |
|
27 | + $this->_default_description = esc_html__('Please provide the following billing information.', 'event_espresso'); |
|
28 | + $this->_default_button_url = $this->file_url() . 'lib/default-cc-logo.png'; |
|
29 | + $this->_pretty_name = esc_html__('PayPal Commerce', 'event_espresso'); |
|
30 | + $this->_cache_billing_form = true; |
|
31 | + $this->_requires_https = true; |
|
32 | 32 | |
33 | - // Load gateway. |
|
34 | - require_once( |
|
35 | - EEP_PAYPAL_COMMERCE_PATH . 'EEG_PayPalCheckout.gateway.php' |
|
36 | - ); |
|
37 | - $this->_gateway = new EEG_PayPalCheckout(); |
|
33 | + // Load gateway. |
|
34 | + require_once( |
|
35 | + EEP_PAYPAL_COMMERCE_PATH . 'EEG_PayPalCheckout.gateway.php' |
|
36 | + ); |
|
37 | + $this->_gateway = new EEG_PayPalCheckout(); |
|
38 | 38 | |
39 | - // Display a refund message at transactions actions area. |
|
40 | - add_action( |
|
41 | - 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
42 | - [__CLASS__, 'refundNotice'], |
|
43 | - 10, |
|
44 | - 1 |
|
45 | - ); |
|
39 | + // Display a refund message at transactions actions area. |
|
40 | + add_action( |
|
41 | + 'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons', |
|
42 | + [__CLASS__, 'refundNotice'], |
|
43 | + 10, |
|
44 | + 1 |
|
45 | + ); |
|
46 | 46 | |
47 | - parent::__construct($pm_instance); |
|
48 | - } |
|
47 | + parent::__construct($pm_instance); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * Generate a new payment method settings form. |
|
53 | - * |
|
54 | - * @return EE_Payment_Method_Form |
|
55 | - * @throws EE_Error |
|
56 | - * @throws ReflectionException |
|
57 | - */ |
|
58 | - public function generate_new_settings_form() |
|
59 | - { |
|
60 | - // Settings form. |
|
61 | - $settings_form = new SettingsForm($this, $this->_pm_instance); |
|
62 | - // Filter the form contents. |
|
63 | - return apply_filters( |
|
64 | - 'FHEE__EE_PMT_PayPalCheckout__generate_new_settings_form__form_filtering', |
|
65 | - $settings_form, |
|
66 | - $this, |
|
67 | - $this->_pm_instance |
|
68 | - ); |
|
69 | - } |
|
51 | + /** |
|
52 | + * Generate a new payment method settings form. |
|
53 | + * |
|
54 | + * @return EE_Payment_Method_Form |
|
55 | + * @throws EE_Error |
|
56 | + * @throws ReflectionException |
|
57 | + */ |
|
58 | + public function generate_new_settings_form() |
|
59 | + { |
|
60 | + // Settings form. |
|
61 | + $settings_form = new SettingsForm($this, $this->_pm_instance); |
|
62 | + // Filter the form contents. |
|
63 | + return apply_filters( |
|
64 | + 'FHEE__EE_PMT_PayPalCheckout__generate_new_settings_form__form_filtering', |
|
65 | + $settings_form, |
|
66 | + $this, |
|
67 | + $this->_pm_instance |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Creates a billing form for this payment method type. |
|
74 | - * |
|
75 | - * @param EE_Transaction|null $transaction |
|
76 | - * @param array|null $extra_args |
|
77 | - * @return EE_Billing_Info_Form|null |
|
78 | - * @throws EE_Error |
|
79 | - * @throws ReflectionException |
|
80 | - */ |
|
81 | - public function generate_new_billing_form(EE_Transaction $transaction = null, ?array $extra_args = []) |
|
82 | - { |
|
83 | - $request = LoaderFactory::getShared(Request::class); |
|
84 | - $request_params = $request->requestParams(); |
|
85 | - // Return the default billing form for the postbox if this is a WP admin transaction info page. |
|
86 | - if (! empty($request_params['page']) && $request_params['page'] === 'espresso_transactions') { |
|
87 | - $default_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, $extra_args); |
|
88 | - $default_form->add_subsections(['credit_card' => new EE_Credit_Card_Input()]); |
|
89 | - return $default_form; |
|
90 | - } |
|
91 | - // Just in case this is used on other admin pages. |
|
92 | - if (empty($transaction) && ! empty($request_params['TXN_ID'])) { |
|
93 | - $txn_instance = EEM_Transaction::instance()->get_one_by_ID($request_params['TXN_ID']); |
|
94 | - $transaction = $txn_instance instanceof EE_Transaction ? $txn_instance : null; |
|
95 | - } |
|
96 | - $options = array_merge( |
|
97 | - [ |
|
98 | - 'transaction' => $transaction, |
|
99 | - 'template_path' => $this->_template_path, |
|
100 | - ], |
|
101 | - $extra_args |
|
102 | - ); |
|
103 | - return new BillingForm($this->_pm_instance, $options); |
|
104 | - } |
|
72 | + /** |
|
73 | + * Creates a billing form for this payment method type. |
|
74 | + * |
|
75 | + * @param EE_Transaction|null $transaction |
|
76 | + * @param array|null $extra_args |
|
77 | + * @return EE_Billing_Info_Form|null |
|
78 | + * @throws EE_Error |
|
79 | + * @throws ReflectionException |
|
80 | + */ |
|
81 | + public function generate_new_billing_form(EE_Transaction $transaction = null, ?array $extra_args = []) |
|
82 | + { |
|
83 | + $request = LoaderFactory::getShared(Request::class); |
|
84 | + $request_params = $request->requestParams(); |
|
85 | + // Return the default billing form for the postbox if this is a WP admin transaction info page. |
|
86 | + if (! empty($request_params['page']) && $request_params['page'] === 'espresso_transactions') { |
|
87 | + $default_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, $extra_args); |
|
88 | + $default_form->add_subsections(['credit_card' => new EE_Credit_Card_Input()]); |
|
89 | + return $default_form; |
|
90 | + } |
|
91 | + // Just in case this is used on other admin pages. |
|
92 | + if (empty($transaction) && ! empty($request_params['TXN_ID'])) { |
|
93 | + $txn_instance = EEM_Transaction::instance()->get_one_by_ID($request_params['TXN_ID']); |
|
94 | + $transaction = $txn_instance instanceof EE_Transaction ? $txn_instance : null; |
|
95 | + } |
|
96 | + $options = array_merge( |
|
97 | + [ |
|
98 | + 'transaction' => $transaction, |
|
99 | + 'template_path' => $this->_template_path, |
|
100 | + ], |
|
101 | + $extra_args |
|
102 | + ); |
|
103 | + return new BillingForm($this->_pm_instance, $options); |
|
104 | + } |
|
105 | 105 | |
106 | 106 | |
107 | - /** |
|
108 | - * Adds PM info to the help tab. |
|
109 | - * |
|
110 | - * @return array |
|
111 | - * @see EE_PMT_Base::help_tabs_config() |
|
112 | - */ |
|
113 | - public function help_tabs_config(): array |
|
114 | - { |
|
115 | - return [ |
|
116 | - $this->get_help_tab_name() => [ |
|
117 | - 'title' => esc_html__('PayPal Commerce settings', 'event_espresso'), |
|
118 | - 'filename' => 'pp-commerce-overview', |
|
119 | - ], |
|
120 | - ]; |
|
121 | - } |
|
107 | + /** |
|
108 | + * Adds PM info to the help tab. |
|
109 | + * |
|
110 | + * @return array |
|
111 | + * @see EE_PMT_Base::help_tabs_config() |
|
112 | + */ |
|
113 | + public function help_tabs_config(): array |
|
114 | + { |
|
115 | + return [ |
|
116 | + $this->get_help_tab_name() => [ |
|
117 | + 'title' => esc_html__('PayPal Commerce settings', 'event_espresso'), |
|
118 | + 'filename' => 'pp-commerce-overview', |
|
119 | + ], |
|
120 | + ]; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * Adds a refund related message section. |
|
126 | - * |
|
127 | - * @param bool $can_edit_payments Flag that tells if user can edit payments. |
|
128 | - * @access public |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public static function refundNotice(bool $can_edit_payments) |
|
132 | - { |
|
133 | - if (! $can_edit_payments) { |
|
134 | - return; |
|
135 | - } |
|
136 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
137 | - $txn_id = $request->getRequestParam('TXN_ID', 0, DataType::INT); |
|
138 | - try { |
|
139 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($txn_id); |
|
140 | - if (! $transaction instanceof EE_Transaction) { |
|
141 | - return; |
|
142 | - } |
|
143 | - // Was this transaction paid using PayPal ? |
|
144 | - if (strpos((string) $transaction->payment_method(), 'PayPal Commerce') === false) { |
|
145 | - return; |
|
146 | - } |
|
147 | - // Try loading the template. |
|
148 | - EE_Registry::instance()->load_helper('Template'); |
|
149 | - } catch (EE_Error|ReflectionException $e) { |
|
150 | - // Just return, adding nothing. |
|
151 | - return; |
|
152 | - } |
|
153 | - $html = EEH_Template::locate_template( |
|
154 | - apply_filters( |
|
155 | - 'FHEEA__EE_PMT_PayPalCheckout__refundNotice', |
|
156 | - dirname(__FILE__) . DS . 'templates' . DS . 'apply-refund-notice.template.php' |
|
157 | - ), |
|
158 | - [] |
|
159 | - ); |
|
160 | - echo $html; |
|
161 | - } |
|
124 | + /** |
|
125 | + * Adds a refund related message section. |
|
126 | + * |
|
127 | + * @param bool $can_edit_payments Flag that tells if user can edit payments. |
|
128 | + * @access public |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + public static function refundNotice(bool $can_edit_payments) |
|
132 | + { |
|
133 | + if (! $can_edit_payments) { |
|
134 | + return; |
|
135 | + } |
|
136 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
137 | + $txn_id = $request->getRequestParam('TXN_ID', 0, DataType::INT); |
|
138 | + try { |
|
139 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($txn_id); |
|
140 | + if (! $transaction instanceof EE_Transaction) { |
|
141 | + return; |
|
142 | + } |
|
143 | + // Was this transaction paid using PayPal ? |
|
144 | + if (strpos((string) $transaction->payment_method(), 'PayPal Commerce') === false) { |
|
145 | + return; |
|
146 | + } |
|
147 | + // Try loading the template. |
|
148 | + EE_Registry::instance()->load_helper('Template'); |
|
149 | + } catch (EE_Error|ReflectionException $e) { |
|
150 | + // Just return, adding nothing. |
|
151 | + return; |
|
152 | + } |
|
153 | + $html = EEH_Template::locate_template( |
|
154 | + apply_filters( |
|
155 | + 'FHEEA__EE_PMT_PayPalCheckout__refundNotice', |
|
156 | + dirname(__FILE__) . DS . 'templates' . DS . 'apply-refund-notice.template.php' |
|
157 | + ), |
|
158 | + [] |
|
159 | + ); |
|
160 | + echo $html; |
|
161 | + } |
|
162 | 162 | } |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct($pm_instance = null) |
25 | 25 | { |
26 | - $this->_template_path = dirname(__FILE__) . DS . 'templates' . DS; |
|
26 | + $this->_template_path = dirname(__FILE__).DS.'templates'.DS; |
|
27 | 27 | $this->_default_description = esc_html__('Please provide the following billing information.', 'event_espresso'); |
28 | - $this->_default_button_url = $this->file_url() . 'lib/default-cc-logo.png'; |
|
28 | + $this->_default_button_url = $this->file_url().'lib/default-cc-logo.png'; |
|
29 | 29 | $this->_pretty_name = esc_html__('PayPal Commerce', 'event_espresso'); |
30 | 30 | $this->_cache_billing_form = true; |
31 | 31 | $this->_requires_https = true; |
32 | 32 | |
33 | 33 | // Load gateway. |
34 | 34 | require_once( |
35 | - EEP_PAYPAL_COMMERCE_PATH . 'EEG_PayPalCheckout.gateway.php' |
|
35 | + EEP_PAYPAL_COMMERCE_PATH.'EEG_PayPalCheckout.gateway.php' |
|
36 | 36 | ); |
37 | 37 | $this->_gateway = new EEG_PayPalCheckout(); |
38 | 38 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $request = LoaderFactory::getShared(Request::class); |
84 | 84 | $request_params = $request->requestParams(); |
85 | 85 | // Return the default billing form for the postbox if this is a WP admin transaction info page. |
86 | - if (! empty($request_params['page']) && $request_params['page'] === 'espresso_transactions') { |
|
86 | + if ( ! empty($request_params['page']) && $request_params['page'] === 'espresso_transactions') { |
|
87 | 87 | $default_form = new EE_Billing_Attendee_Info_Form($this->_pm_instance, $extra_args); |
88 | 88 | $default_form->add_subsections(['credit_card' => new EE_Credit_Card_Input()]); |
89 | 89 | return $default_form; |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public static function refundNotice(bool $can_edit_payments) |
132 | 132 | { |
133 | - if (! $can_edit_payments) { |
|
133 | + if ( ! $can_edit_payments) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
137 | 137 | $txn_id = $request->getRequestParam('TXN_ID', 0, DataType::INT); |
138 | 138 | try { |
139 | 139 | $transaction = EEM_Transaction::instance()->get_one_by_ID($txn_id); |
140 | - if (! $transaction instanceof EE_Transaction) { |
|
140 | + if ( ! $transaction instanceof EE_Transaction) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | // Was this transaction paid using PayPal ? |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | } |
147 | 147 | // Try loading the template. |
148 | 148 | EE_Registry::instance()->load_helper('Template'); |
149 | - } catch (EE_Error|ReflectionException $e) { |
|
149 | + } catch (EE_Error | ReflectionException $e) { |
|
150 | 150 | // Just return, adding nothing. |
151 | 151 | return; |
152 | 152 | } |
153 | 153 | $html = EEH_Template::locate_template( |
154 | 154 | apply_filters( |
155 | 155 | 'FHEEA__EE_PMT_PayPalCheckout__refundNotice', |
156 | - dirname(__FILE__) . DS . 'templates' . DS . 'apply-refund-notice.template.php' |
|
156 | + dirname(__FILE__).DS.'templates'.DS.'apply-refund-notice.template.php' |
|
157 | 157 | ), |
158 | 158 | [] |
159 | 159 | ); |
@@ -15,164 +15,164 @@ |
||
15 | 15 | */ |
16 | 16 | class Domain |
17 | 17 | { |
18 | - /** |
|
19 | - * Name of the extra meta key that stores this PM options as one meta. |
|
20 | - */ |
|
21 | - public const META_KEY_PAYPAL_DATA = 'paypal_data'; |
|
22 | - /** |
|
23 | - * Name of the extra meta key that stores this PM options as one meta. |
|
24 | - */ |
|
25 | - public const META_KEY_PAYPAL_DATA_SANDBOX = 'paypal_data_sandbox'; |
|
26 | - |
|
27 | - /** |
|
28 | - * Name of the extra meta that stores whether the credentials were for the sandbox or live mode. |
|
29 | - */ |
|
30 | - public const META_KEY_SANDBOX_MODE = 'sandbox_mode'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Name of the extra meta that stores the PayPal Access Token that is used get onboarding URL. |
|
34 | - */ |
|
35 | - public const META_KEY_ACCESS_TOKEN = 'access_token'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Name of the extra meta that stores the last request tracking ID. |
|
39 | - */ |
|
40 | - public const META_KEY_TRACKING_ID = 'tracking_id'; |
|
41 | - |
|
42 | - /** |
|
43 | - * Name of the extra meta that stores the Event Espresso PayPal Account's merchant id. |
|
44 | - */ |
|
45 | - public const META_KEY_APP_ID = 'app_id'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Name of the extra meta that holds the seller client ID. |
|
49 | - */ |
|
50 | - public const META_KEY_CLIENT_ID = 'client_id'; |
|
51 | - |
|
52 | - /** |
|
53 | - * Name of the extra meta that holds the seller secret. |
|
54 | - */ |
|
55 | - public const META_KEY_CLIENT_SECRET = 'client_secret'; |
|
56 | - |
|
57 | - /** |
|
58 | - * Name of the extra meta that stores the expiration date of the client ID. |
|
59 | - */ |
|
60 | - public const META_KEY_EXPIRES_IN = 'expires_in'; |
|
61 | - |
|
62 | - /** |
|
63 | - * Name of the extra meta that holds the partner client ID. |
|
64 | - */ |
|
65 | - public const META_KEY_PARTNER_CLIENT_ID = 'partner_client_id'; |
|
66 | - |
|
67 | - /** |
|
68 | - * Name of the extra meta that holds the partner merchant ID. |
|
69 | - */ |
|
70 | - public const META_KEY_PARTNER_MERCHANT_ID = 'partner_merchant_id'; |
|
71 | - |
|
72 | - /** |
|
73 | - * Name of the extra meta that holds the seller merchant ID. |
|
74 | - */ |
|
75 | - public const META_KEY_SELLER_MERCHANT_ID = 'merchantIdInPayPal'; |
|
76 | - |
|
77 | - /** |
|
78 | - * Name of the extra meta that holds the onboarding URL. |
|
79 | - */ |
|
80 | - public const META_KEY_ONBOARDING_URL = 'onboarding_url'; |
|
81 | - |
|
82 | - /** |
|
83 | - * Name of the extra meta that holds the BN / request tracking code. |
|
84 | - */ |
|
85 | - public const META_KEY_BN_CODE = 'bn_code'; |
|
86 | - |
|
87 | - /** |
|
88 | - * Name of the extra meta that holds the last order details. |
|
89 | - */ |
|
90 | - public const META_KEY_LAST_ORDER = 'last_order_details'; |
|
91 | - |
|
92 | - /** |
|
93 | - * Name of the extra meta that stores the allowed PP checkout type selected by merchant while onboarding. |
|
94 | - */ |
|
95 | - public const META_KEY_ALLOWED_CHECKOUT_TYPE = 'allowed_checkout_type'; |
|
96 | - |
|
97 | - /** |
|
98 | - * Name of the extra meta that stores the PP checkout type selected by merchant after onboarding. |
|
99 | - */ |
|
100 | - public const META_KEY_CHECKOUT_TYPE = 'checkout_type'; |
|
101 | - |
|
102 | - /** |
|
103 | - * Name of the PayPal API parameter that holds the auth code. |
|
104 | - */ |
|
105 | - public const API_KEY_AUTH_CODE = 'authCode'; |
|
106 | - |
|
107 | - /** |
|
108 | - * Name of the PayPal API parameter that holds the client token. |
|
109 | - */ |
|
110 | - public const API_KEY_CLIENT_TOKEN = 'client_token'; |
|
111 | - |
|
112 | - /** |
|
113 | - * Name of the extra meta that holds the seller payer ID. |
|
114 | - */ |
|
115 | - public const META_KEY_PAYER_ID = 'payer_id'; |
|
116 | - |
|
117 | - /** |
|
118 | - * Name of the PayPal API parameter that holds the client token expiration time. |
|
119 | - */ |
|
120 | - public const API_KEY_EXPIRES_IN = 'expires_in'; |
|
121 | - |
|
122 | - /** |
|
123 | - * Name of the PayPal API parameter that holds the bool of if permissions were granted. |
|
124 | - */ |
|
125 | - public const API_PARAM_PERMISSIONS_GRANTED = 'permissionsGranted'; |
|
126 | - |
|
127 | - /** |
|
128 | - * Name of the PayPal API parameter that holds the bool of if the primary email was confirmed. |
|
129 | - */ |
|
130 | - public const API_PARAM_PRIM_EMAIL_CONFIRMED = 'primary_email_confirmed'; |
|
131 | - |
|
132 | - /** |
|
133 | - * Name of the PayPal API parameter that holds the bool of if email was confirmed. |
|
134 | - */ |
|
135 | - public const API_PARAM_EMAIL_CONFIRMED = 'isEmailConfirmed'; |
|
136 | - |
|
137 | - /** |
|
138 | - * Name of the PayPal API parameter that holds the partner ID. |
|
139 | - */ |
|
140 | - public const API_PARAM_PARTNER_ID = 'merchantId'; |
|
141 | - |
|
142 | - /** |
|
143 | - * Name of the PayPal API parameter that holds the merchant ID in the Track seller onboarding status request. |
|
144 | - */ |
|
145 | - public const API_PARAM_TRACK_MERCHANT_ID = 'merchant_id'; |
|
146 | - |
|
147 | - /** |
|
148 | - * Name of the PayPal API parameter that holds the payments_receivable status. |
|
149 | - */ |
|
150 | - public const API_PARAM_PAYMENTS_RECEIVABLE = 'payments_receivable'; |
|
151 | - |
|
152 | - /** |
|
153 | - * Name of the nonce used in the capture order request. |
|
154 | - */ |
|
155 | - public const CAPTURE_ORDER_NONCE_NAME = 'eea_pp_commerce_capture_order_payment'; |
|
156 | - |
|
157 | - /** |
|
158 | - * Name of the nonce used in the onboarding process. |
|
159 | - */ |
|
160 | - public const NONCE_NAME_ONBOARDING_RETURN = 'eea_pp_commerce_onboarding_return'; |
|
161 | - |
|
162 | - /** |
|
163 | - * Holds this payment method slug. |
|
164 | - */ |
|
165 | - public const PM_SLUG = 'paypalcheckout'; |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Returns the base PayPal API URL. |
|
170 | - * |
|
171 | - * @param EE_Payment_Method $payment_method |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public static function getPayPalApiUrl(EE_Payment_Method $payment_method): string |
|
175 | - { |
|
176 | - return $payment_method->debug_mode() ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; |
|
177 | - } |
|
18 | + /** |
|
19 | + * Name of the extra meta key that stores this PM options as one meta. |
|
20 | + */ |
|
21 | + public const META_KEY_PAYPAL_DATA = 'paypal_data'; |
|
22 | + /** |
|
23 | + * Name of the extra meta key that stores this PM options as one meta. |
|
24 | + */ |
|
25 | + public const META_KEY_PAYPAL_DATA_SANDBOX = 'paypal_data_sandbox'; |
|
26 | + |
|
27 | + /** |
|
28 | + * Name of the extra meta that stores whether the credentials were for the sandbox or live mode. |
|
29 | + */ |
|
30 | + public const META_KEY_SANDBOX_MODE = 'sandbox_mode'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Name of the extra meta that stores the PayPal Access Token that is used get onboarding URL. |
|
34 | + */ |
|
35 | + public const META_KEY_ACCESS_TOKEN = 'access_token'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Name of the extra meta that stores the last request tracking ID. |
|
39 | + */ |
|
40 | + public const META_KEY_TRACKING_ID = 'tracking_id'; |
|
41 | + |
|
42 | + /** |
|
43 | + * Name of the extra meta that stores the Event Espresso PayPal Account's merchant id. |
|
44 | + */ |
|
45 | + public const META_KEY_APP_ID = 'app_id'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Name of the extra meta that holds the seller client ID. |
|
49 | + */ |
|
50 | + public const META_KEY_CLIENT_ID = 'client_id'; |
|
51 | + |
|
52 | + /** |
|
53 | + * Name of the extra meta that holds the seller secret. |
|
54 | + */ |
|
55 | + public const META_KEY_CLIENT_SECRET = 'client_secret'; |
|
56 | + |
|
57 | + /** |
|
58 | + * Name of the extra meta that stores the expiration date of the client ID. |
|
59 | + */ |
|
60 | + public const META_KEY_EXPIRES_IN = 'expires_in'; |
|
61 | + |
|
62 | + /** |
|
63 | + * Name of the extra meta that holds the partner client ID. |
|
64 | + */ |
|
65 | + public const META_KEY_PARTNER_CLIENT_ID = 'partner_client_id'; |
|
66 | + |
|
67 | + /** |
|
68 | + * Name of the extra meta that holds the partner merchant ID. |
|
69 | + */ |
|
70 | + public const META_KEY_PARTNER_MERCHANT_ID = 'partner_merchant_id'; |
|
71 | + |
|
72 | + /** |
|
73 | + * Name of the extra meta that holds the seller merchant ID. |
|
74 | + */ |
|
75 | + public const META_KEY_SELLER_MERCHANT_ID = 'merchantIdInPayPal'; |
|
76 | + |
|
77 | + /** |
|
78 | + * Name of the extra meta that holds the onboarding URL. |
|
79 | + */ |
|
80 | + public const META_KEY_ONBOARDING_URL = 'onboarding_url'; |
|
81 | + |
|
82 | + /** |
|
83 | + * Name of the extra meta that holds the BN / request tracking code. |
|
84 | + */ |
|
85 | + public const META_KEY_BN_CODE = 'bn_code'; |
|
86 | + |
|
87 | + /** |
|
88 | + * Name of the extra meta that holds the last order details. |
|
89 | + */ |
|
90 | + public const META_KEY_LAST_ORDER = 'last_order_details'; |
|
91 | + |
|
92 | + /** |
|
93 | + * Name of the extra meta that stores the allowed PP checkout type selected by merchant while onboarding. |
|
94 | + */ |
|
95 | + public const META_KEY_ALLOWED_CHECKOUT_TYPE = 'allowed_checkout_type'; |
|
96 | + |
|
97 | + /** |
|
98 | + * Name of the extra meta that stores the PP checkout type selected by merchant after onboarding. |
|
99 | + */ |
|
100 | + public const META_KEY_CHECKOUT_TYPE = 'checkout_type'; |
|
101 | + |
|
102 | + /** |
|
103 | + * Name of the PayPal API parameter that holds the auth code. |
|
104 | + */ |
|
105 | + public const API_KEY_AUTH_CODE = 'authCode'; |
|
106 | + |
|
107 | + /** |
|
108 | + * Name of the PayPal API parameter that holds the client token. |
|
109 | + */ |
|
110 | + public const API_KEY_CLIENT_TOKEN = 'client_token'; |
|
111 | + |
|
112 | + /** |
|
113 | + * Name of the extra meta that holds the seller payer ID. |
|
114 | + */ |
|
115 | + public const META_KEY_PAYER_ID = 'payer_id'; |
|
116 | + |
|
117 | + /** |
|
118 | + * Name of the PayPal API parameter that holds the client token expiration time. |
|
119 | + */ |
|
120 | + public const API_KEY_EXPIRES_IN = 'expires_in'; |
|
121 | + |
|
122 | + /** |
|
123 | + * Name of the PayPal API parameter that holds the bool of if permissions were granted. |
|
124 | + */ |
|
125 | + public const API_PARAM_PERMISSIONS_GRANTED = 'permissionsGranted'; |
|
126 | + |
|
127 | + /** |
|
128 | + * Name of the PayPal API parameter that holds the bool of if the primary email was confirmed. |
|
129 | + */ |
|
130 | + public const API_PARAM_PRIM_EMAIL_CONFIRMED = 'primary_email_confirmed'; |
|
131 | + |
|
132 | + /** |
|
133 | + * Name of the PayPal API parameter that holds the bool of if email was confirmed. |
|
134 | + */ |
|
135 | + public const API_PARAM_EMAIL_CONFIRMED = 'isEmailConfirmed'; |
|
136 | + |
|
137 | + /** |
|
138 | + * Name of the PayPal API parameter that holds the partner ID. |
|
139 | + */ |
|
140 | + public const API_PARAM_PARTNER_ID = 'merchantId'; |
|
141 | + |
|
142 | + /** |
|
143 | + * Name of the PayPal API parameter that holds the merchant ID in the Track seller onboarding status request. |
|
144 | + */ |
|
145 | + public const API_PARAM_TRACK_MERCHANT_ID = 'merchant_id'; |
|
146 | + |
|
147 | + /** |
|
148 | + * Name of the PayPal API parameter that holds the payments_receivable status. |
|
149 | + */ |
|
150 | + public const API_PARAM_PAYMENTS_RECEIVABLE = 'payments_receivable'; |
|
151 | + |
|
152 | + /** |
|
153 | + * Name of the nonce used in the capture order request. |
|
154 | + */ |
|
155 | + public const CAPTURE_ORDER_NONCE_NAME = 'eea_pp_commerce_capture_order_payment'; |
|
156 | + |
|
157 | + /** |
|
158 | + * Name of the nonce used in the onboarding process. |
|
159 | + */ |
|
160 | + public const NONCE_NAME_ONBOARDING_RETURN = 'eea_pp_commerce_onboarding_return'; |
|
161 | + |
|
162 | + /** |
|
163 | + * Holds this payment method slug. |
|
164 | + */ |
|
165 | + public const PM_SLUG = 'paypalcheckout'; |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Returns the base PayPal API URL. |
|
170 | + * |
|
171 | + * @param EE_Payment_Method $payment_method |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public static function getPayPalApiUrl(EE_Payment_Method $payment_method): string |
|
175 | + { |
|
176 | + return $payment_method->debug_mode() ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; |
|
177 | + } |
|
178 | 178 | } |
@@ -16,30 +16,30 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class ClientsApi |
18 | 18 | { |
19 | - /** |
|
20 | - * @var PayPalApi |
|
21 | - */ |
|
22 | - protected $api; |
|
19 | + /** |
|
20 | + * @var PayPalApi |
|
21 | + */ |
|
22 | + protected $api; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $request_url; |
|
24 | + /** |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $request_url; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * ClientsApi constructor. |
|
32 | - * |
|
33 | - * @param PayPalApi $api |
|
34 | - * @param bool $sandbox_mode |
|
35 | - */ |
|
36 | - public function __construct(PayPalApi $api, bool $sandbox_mode = true) |
|
37 | - { |
|
38 | - $this->api = $api; |
|
39 | - // Is this a sandbox request. |
|
40 | - $api_endpoint = $sandbox_mode |
|
41 | - ? 'https://api-m.sandbox.paypal.com/' |
|
42 | - : 'https://api-m.paypal.com/'; |
|
43 | - $this->request_url = $api_endpoint . 'v1/identity'; |
|
44 | - } |
|
30 | + /** |
|
31 | + * ClientsApi constructor. |
|
32 | + * |
|
33 | + * @param PayPalApi $api |
|
34 | + * @param bool $sandbox_mode |
|
35 | + */ |
|
36 | + public function __construct(PayPalApi $api, bool $sandbox_mode = true) |
|
37 | + { |
|
38 | + $this->api = $api; |
|
39 | + // Is this a sandbox request. |
|
40 | + $api_endpoint = $sandbox_mode |
|
41 | + ? 'https://api-m.sandbox.paypal.com/' |
|
42 | + : 'https://api-m.paypal.com/'; |
|
43 | + $this->request_url = $api_endpoint . 'v1/identity'; |
|
44 | + } |
|
45 | 45 | } |
@@ -35,11 +35,11 @@ |
||
35 | 35 | */ |
36 | 36 | public function __construct(PayPalApi $api, bool $sandbox_mode = true) |
37 | 37 | { |
38 | - $this->api = $api; |
|
38 | + $this->api = $api; |
|
39 | 39 | // Is this a sandbox request. |
40 | 40 | $api_endpoint = $sandbox_mode |
41 | 41 | ? 'https://api-m.sandbox.paypal.com/' |
42 | 42 | : 'https://api-m.paypal.com/'; |
43 | - $this->request_url = $api_endpoint . 'v1/identity'; |
|
43 | + $this->request_url = $api_endpoint.'v1/identity'; |
|
44 | 44 | } |
45 | 45 | } |
@@ -18,59 +18,59 @@ |
||
18 | 18 | */ |
19 | 19 | class ClientToken extends ClientsApi |
20 | 20 | { |
21 | - /** |
|
22 | - * ClientToken constructor. |
|
23 | - * |
|
24 | - * @param PayPalApi $api |
|
25 | - * @param bool $sandbox_mode |
|
26 | - */ |
|
27 | - public function __construct( |
|
28 | - PayPalApi $api, |
|
29 | - bool $sandbox_mode |
|
30 | - ) { |
|
31 | - parent::__construct($api, $sandbox_mode); |
|
32 | - $this->request_url = $this->request_url . "/generate-token"; |
|
33 | - } |
|
21 | + /** |
|
22 | + * ClientToken constructor. |
|
23 | + * |
|
24 | + * @param PayPalApi $api |
|
25 | + * @param bool $sandbox_mode |
|
26 | + */ |
|
27 | + public function __construct( |
|
28 | + PayPalApi $api, |
|
29 | + bool $sandbox_mode |
|
30 | + ) { |
|
31 | + parent::__construct($api, $sandbox_mode); |
|
32 | + $this->request_url = $this->request_url . "/generate-token"; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * Get the onboarding status and validate it. |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function getToken(): array |
|
42 | - { |
|
43 | - // Send GET request. |
|
44 | - $response = $this->api->sendRequest([], $this->request_url); |
|
45 | - return $this->validateResponse($response); |
|
46 | - } |
|
36 | + /** |
|
37 | + * Get the onboarding status and validate it. |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function getToken(): array |
|
42 | + { |
|
43 | + // Send GET request. |
|
44 | + $response = $this->api->sendRequest([], $this->request_url); |
|
45 | + return $this->validateResponse($response); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Makes sure that we have received the client token. Returns an error as array if not. |
|
51 | - * |
|
52 | - * @param array $response |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function validateResponse(array $response): array |
|
56 | - { |
|
57 | - // Could this be an error ? |
|
58 | - if (! empty($response['error'])) { |
|
59 | - return $response; |
|
60 | - } |
|
61 | - if (! empty($response['name']) && ! empty($response['message'])) { |
|
62 | - return ['error' => $response['name'], 'message' => $response['message']]; |
|
63 | - } |
|
64 | - // Check the data we received. |
|
65 | - if (empty($response[ Domain::API_KEY_CLIENT_TOKEN ])) { |
|
66 | - $err_msg = esc_html__('No client token was found in the Client Token request response.', 'event_espresso'); |
|
67 | - PayPalLogger::errorLog($err_msg, $response); |
|
68 | - return ['error' => 'ONBOARDING_MISSING_CLIENT_TOKEN', 'message' => $err_msg]; |
|
69 | - } |
|
70 | - return [ |
|
71 | - 'valid' => true, |
|
72 | - 'client_token' => $response[ Domain::API_KEY_CLIENT_TOKEN ], |
|
73 | - 'expires_in' => $response[ Domain::API_KEY_EXPIRES_IN ] |
|
74 | - ]; |
|
75 | - } |
|
49 | + /** |
|
50 | + * Makes sure that we have received the client token. Returns an error as array if not. |
|
51 | + * |
|
52 | + * @param array $response |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function validateResponse(array $response): array |
|
56 | + { |
|
57 | + // Could this be an error ? |
|
58 | + if (! empty($response['error'])) { |
|
59 | + return $response; |
|
60 | + } |
|
61 | + if (! empty($response['name']) && ! empty($response['message'])) { |
|
62 | + return ['error' => $response['name'], 'message' => $response['message']]; |
|
63 | + } |
|
64 | + // Check the data we received. |
|
65 | + if (empty($response[ Domain::API_KEY_CLIENT_TOKEN ])) { |
|
66 | + $err_msg = esc_html__('No client token was found in the Client Token request response.', 'event_espresso'); |
|
67 | + PayPalLogger::errorLog($err_msg, $response); |
|
68 | + return ['error' => 'ONBOARDING_MISSING_CLIENT_TOKEN', 'message' => $err_msg]; |
|
69 | + } |
|
70 | + return [ |
|
71 | + 'valid' => true, |
|
72 | + 'client_token' => $response[ Domain::API_KEY_CLIENT_TOKEN ], |
|
73 | + 'expires_in' => $response[ Domain::API_KEY_EXPIRES_IN ] |
|
74 | + ]; |
|
75 | + } |
|
76 | 76 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | bool $sandbox_mode |
30 | 30 | ) { |
31 | 31 | parent::__construct($api, $sandbox_mode); |
32 | - $this->request_url = $this->request_url . "/generate-token"; |
|
32 | + $this->request_url = $this->request_url."/generate-token"; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -55,22 +55,22 @@ discard block |
||
55 | 55 | public function validateResponse(array $response): array |
56 | 56 | { |
57 | 57 | // Could this be an error ? |
58 | - if (! empty($response['error'])) { |
|
58 | + if ( ! empty($response['error'])) { |
|
59 | 59 | return $response; |
60 | 60 | } |
61 | - if (! empty($response['name']) && ! empty($response['message'])) { |
|
61 | + if ( ! empty($response['name']) && ! empty($response['message'])) { |
|
62 | 62 | return ['error' => $response['name'], 'message' => $response['message']]; |
63 | 63 | } |
64 | 64 | // Check the data we received. |
65 | - if (empty($response[ Domain::API_KEY_CLIENT_TOKEN ])) { |
|
65 | + if (empty($response[Domain::API_KEY_CLIENT_TOKEN])) { |
|
66 | 66 | $err_msg = esc_html__('No client token was found in the Client Token request response.', 'event_espresso'); |
67 | 67 | PayPalLogger::errorLog($err_msg, $response); |
68 | 68 | return ['error' => 'ONBOARDING_MISSING_CLIENT_TOKEN', 'message' => $err_msg]; |
69 | 69 | } |
70 | 70 | return [ |
71 | 71 | 'valid' => true, |
72 | - 'client_token' => $response[ Domain::API_KEY_CLIENT_TOKEN ], |
|
73 | - 'expires_in' => $response[ Domain::API_KEY_EXPIRES_IN ] |
|
72 | + 'client_token' => $response[Domain::API_KEY_CLIENT_TOKEN], |
|
73 | + 'expires_in' => $response[Domain::API_KEY_EXPIRES_IN] |
|
74 | 74 | ]; |
75 | 75 | } |
76 | 76 | } |