DataTransferObjects
5 years ago
Models
5 years ago
Repositories
5 years ago
Webhooks
5 years ago
AccountAdminNotices.php
5 years ago
AdminSettingFields.php
5 years ago
AdvancedCardFields.php
5 years ago
AjaxRequestHandler.php
5 years ago
DonationDetailsPage.php
5 years ago
DonationFormPaymentMethod.php
5 years ago
DonationProcessor.php
5 years ago
PayPalClient.php
5 years ago
PayPalCommerce.php
5 years ago
RefreshToken.php
5 years ago
RefundPaymentHandler.php
5 years ago
ScriptLoader.php
5 years ago
Utils.php
5 years ago
onBoardingRedirectHandler.php
5 years ago
AdvancedCardFields.php
76 lines
| 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 | * @var Settings |
| 17 | */ |
| 18 | private $payPalDonationsSettings; |
| 19 | |
| 20 | /** |
| 21 | * AdvancedCardFields constructor. |
| 22 | * |
| 23 | * @param Settings $payPalDonationsSettings |
| 24 | */ |
| 25 | public function __construct( Settings $payPalDonationsSettings ) { |
| 26 | $this->payPalDonationsSettings = $payPalDonationsSettings; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * PayPal commerce uses smart buttons to accept payment. |
| 31 | * |
| 32 | * @since 2.9.0 |
| 33 | * @since 2.11.1 Show billing fields conditionally. |
| 34 | * |
| 35 | * @param int $formId Donation Form ID. |
| 36 | */ |
| 37 | public function addCreditCardForm( $formId ) { |
| 38 | $this->registerCustomBillingFieldsSectionLabel(); |
| 39 | if ( ! $this->payPalDonationsSettings->canCollectBillingInformation() ) { |
| 40 | $this->removeBillingField(); |
| 41 | } |
| 42 | give_get_cc_form( $formId ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Remove Address Fields if user has option enabled. |
| 47 | * |
| 48 | * @since 2.9.0 |
| 49 | */ |
| 50 | private function removeBillingField() { |
| 51 | remove_action( 'give_after_cc_fields', [ $this, 'addBillingFieldsSectionLabel' ], 1 ); |
| 52 | remove_action( 'give_after_cc_fields', 'give_default_cc_address_fields' ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @since 2.11.1 |
| 57 | */ |
| 58 | private function registerCustomBillingFieldsSectionLabel() { |
| 59 | if ( 'sequoia' !== Template::getActiveID() ) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | add_action( 'give_after_cc_fields', [ $this, 'addBillingFieldsSectionLabel' ], 1 ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @since 2.11.1 |
| 68 | */ |
| 69 | public function addBillingFieldsSectionLabel() { |
| 70 | echo sprintf( |
| 71 | '<div class="paypal-commerce_billing_fields_section_label"><p>%1$s</p></div>', |
| 72 | esc_html__( 'Billing Details', 'give' ) |
| 73 | ); |
| 74 | } |
| 75 | } |
| 76 |