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