PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / PaymentGateways / PayPalCommerce / AdvancedCardFields.php

AdvancedCardFields.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/PaymentGateways/PayPalCommerce/AdvancedCardFields.php

89 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\PayPalCommerce;
4
5 use Give\Helpers\Form\Template;
6 use Give\PaymentGateways\PayPalCommerce\Repositories\Settings;
7
8 /**
9 * Class AdvancedCardFields
10 * @package Give\PaymentGateways\PayPalCommerce
11 *
12 * @since 2.9.0
13 */
14 class AdvancedCardFields
15 {
16 /**
17 * @var Settings
18 */
19 private $payPalDonationsSettings;
20
21 /**
22 * AdvancedCardFields constructor.
23 *
24 * @param Settings $payPalDonationsSettings
25 */
26 public function __construct(Settings $payPalDonationsSettings)
27 {
28 $this->payPalDonationsSettings = $payPalDonationsSettings;
29 }
30
31 /**
32 * PayPal commerce uses smart buttons to accept payment.
33 *
34 * @since 2.9.0
35 * @since 2.11.1 Show billing fields conditionally.
36 *
37 * @param int $formId Donation Form ID.
38 *
39 * @return string
40 */
41 public function addCreditCardForm($formId)
42 {
43 ob_start();
44
45 $this->registerCustomBillingFieldsSectionLabel();
46 if (!$this->payPalDonationsSettings->canCollectBillingInformation()) {
47 $this->removeBillingField();
48 }
49
50 give_get_cc_form($formId);
51
52 return ob_get_clean();
53 }
54
55 /**
56 * Remove Address Fields if user has option enabled.
57 *
58 * @since 2.9.0
59 */
60 private function removeBillingField()
61 {
62 remove_action('give_after_cc_fields', [$this, 'addBillingFieldsSectionLabel'], 1);
63 remove_action('give_after_cc_fields', 'give_default_cc_address_fields');
64 }
65
66 /**
67 * @since 2.11.1
68 */
69 private function registerCustomBillingFieldsSectionLabel()
70 {
71 if ('sequoia' !== Template::getActiveID()) {
72 return;
73 }
74
75 add_action('give_after_cc_fields', [$this, 'addBillingFieldsSectionLabel'], 1);
76 }
77
78 /**
79 * @since 2.11.1
80 */
81 public function addBillingFieldsSectionLabel()
82 {
83 echo sprintf(
84 '<div class="paypal-commerce_billing_fields_section_label"><p>%1$s</p></div>',
85 esc_html__('Billing Details', 'give')
86 );
87 }
88 }
89