| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\PaymentGateways\PayPalCommerce; |
| 4 |
|
| 5 |
use Give\PaymentGateways\PayPalCommerce\Repositories\MerchantDetails; |
| 6 |
use Give_Admin_Settings; |
| 7 |
|
| 8 |
class AccountAdminNotices |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @since 2.9.0 |
| 12 |
* |
| 13 |
* @var MerchantDetails |
| 14 |
*/ |
| 15 |
private $merchantRepository; |
| 16 |
|
| 17 |
/** |
| 18 |
* AccountAdminNotices constructor. |
| 19 |
* |
| 20 |
* @param MerchantDetails $merchantRepository |
| 21 |
*/ |
| 22 |
public function __construct(MerchantDetails $merchantRepository) |
| 23 |
{ |
| 24 |
$this->merchantRepository = $merchantRepository; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Displays the admin notices in the right conditions |
| 29 |
* |
| 30 |
* @since 2.9.0 |
| 31 |
*/ |
| 32 |
public function displayNotices() |
| 33 |
{ |
| 34 |
if (Utils::gatewayIsActive() && ! give_is_test_mode()) { |
| 35 |
$this->checkForConnectedLiveAccount(); |
| 36 |
$this->checkForAccountReadiness(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Displays a notice if the account is not connected |
| 42 |
* |
| 43 |
* @since 2.9.0 |
| 44 |
*/ |
| 45 |
public function checkForConnectedLiveAccount() |
| 46 |
{ |
| 47 |
if ( ! $this->merchantRepository->accountIsConnected()) { |
| 48 |
$connectUrl = admin_url('edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=paypal'); |
| 49 |
Give_Admin_Settings::add_message( |
| 50 |
'paypal-commerce-not-connected', |
| 51 |
sprintf( |
| 52 |
"<strong>%1\$s</strong> %2\$s <a href='{$connectUrl}'>%3\$s</a>", |
| 53 |
esc_html__('PayPal Donations:', 'give'), |
| 54 |
esc_html__('Please connect to your account so donations may be processed.', 'give'), |
| 55 |
esc_html__('Connect Account', 'give') |
| 56 |
) |
| 57 |
); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Displays a notice if the account is connected but not ready |
| 63 |
* |
| 64 |
* @since 2.9.0 |
| 65 |
*/ |
| 66 |
public function checkForAccountReadiness() |
| 67 |
{ |
| 68 |
if ( ! $this->merchantRepository->accountIsConnected()) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
$merchantDetails = $this->merchantRepository->getDetails(); |
| 73 |
if ($merchantDetails->accountIsReady) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
$connectUrl = admin_url('edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=paypal'); |
| 78 |
Give_Admin_Settings::add_message( |
| 79 |
'paypal-commerce-account-not-ready', |
| 80 |
sprintf( |
| 81 |
"<strong>%1\$s</strong> %2\$s <a href='{$connectUrl}'>%3\$s</a>", |
| 82 |
esc_html__('PayPal Donations:', 'give'), |
| 83 |
esc_html__( |
| 84 |
'Please check your account status as additional setup is needed before you may accept donations.', |
| 85 |
'give' |
| 86 |
), |
| 87 |
esc_html__('Account Status', 'give') |
| 88 |
) |
| 89 |
); |
| 90 |
} |
| 91 |
} |
| 92 |
|