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