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
DonationFormPaymentMethod.php
46 lines
| 1 | <?php |
| 2 | namespace Give\PaymentGateways\PayPalCommerce; |
| 3 | |
| 4 | /** |
| 5 | * Class DonationFormPaymentMethod |
| 6 | * @package Give\PaymentGateways\PayPalCommerce |
| 7 | * |
| 8 | * @since 2.9.6 |
| 9 | */ |
| 10 | class DonationFormPaymentMethod { |
| 11 | /** |
| 12 | * Setup filter hook. |
| 13 | * |
| 14 | * @since 2.9.6 |
| 15 | */ |
| 16 | public function handle() { |
| 17 | // Exit. |
| 18 | if ( ! Utils::gatewayIsActive() ) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | add_filter( 'give_enabled_payment_gateways', [ $this, 'filterEnabledPayments' ], 99 ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Disable PayPal payment option if gateway account is not setup. |
| 27 | * |
| 28 | * @sicne 2.9.6 |
| 29 | * |
| 30 | * @param array $gateways |
| 31 | * |
| 32 | * @return array |
| 33 | */ |
| 34 | public function filterEnabledPayments( $gateways ) { |
| 35 | if ( ! array_key_exists( PayPalCommerce::GATEWAY_ID, $gateways ) ) { |
| 36 | return $gateways; |
| 37 | } |
| 38 | |
| 39 | if ( ! Utils::isAccountReadyToAcceptPayment() ) { |
| 40 | unset( $gateways[ PayPalCommerce::GATEWAY_ID ] ); |
| 41 | } |
| 42 | |
| 43 | return $gateways; |
| 44 | } |
| 45 | } |
| 46 |