Banners
2 years ago
DataTransferObjects
4 years ago
Exceptions
3 years ago
Migrations
2 years ago
Models
2 years ago
PayPalCheckoutSdk
2 years ago
Repositories
2 years ago
Webhooks
2 years ago
AccountAdminNotices.php
4 years ago
AdminSettingFields.php
1 year ago
AdvancedCardFields.php
4 years ago
AjaxRequestHandler.php
1 year ago
DonationDetailsPage.php
4 years ago
DonationFormPaymentMethod.php
2 years ago
PayPalClient.php
2 years ago
PayPalCommerce.php
2 years ago
RefreshToken.php
2 years ago
RefundPaymentHandler.php
4 years ago
ScriptLoader.php
2 years ago
Utils.php
2 years ago
onBoardingRedirectHandler.php
1 year ago
AccountAdminNotices.php
92 lines
| 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 |