| 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 |
|