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
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
AdminSettingFields.php
225 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\PaymentGateways\PayPalCommerce\Repositories\Settings; |
| 8 | use Give_HTML_Elements; |
| 9 | use Give_License; |
| 10 | |
| 11 | /** |
| 12 | * Class AdminSettingFields |
| 13 | * @since 2.9.0 |
| 14 | * @package Give\PaymentGateways\PayPalCommerce |
| 15 | * |
| 16 | */ |
| 17 | class AdminSettingFields { |
| 18 | /** |
| 19 | * Bootstrap fields. |
| 20 | * |
| 21 | * @since 2.9.0 |
| 22 | */ |
| 23 | public function boot() { |
| 24 | add_action( 'give_admin_field_paypal_commerce_account_manger', [ $this, 'payPalCommerceAccountManagerField' ] ); |
| 25 | add_action( 'give_admin_field_paypal_commerce_account_country', [ $this, 'accountCountryField' ] ); |
| 26 | add_action( 'give_admin_field_paypal_commerce_introduction', [ $this, 'introductionSection' ] ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Render account country field. |
| 31 | * |
| 32 | * @since 2.9.0 |
| 33 | */ |
| 34 | public function accountCountryField() { |
| 35 | /* @var MerchantDetail $merchantModel */ |
| 36 | $merchantModel = give( MerchantDetail::class ); |
| 37 | |
| 38 | /* @var MerchantDetails $merchantRepository */ |
| 39 | $merchantRepository = give( MerchantDetails::class ); |
| 40 | |
| 41 | /* @var Give_HTML_Elements $htmlElements */ |
| 42 | $htmlElements = give( 'html' ); |
| 43 | |
| 44 | /* @var Settings $settingRepository */ |
| 45 | $settingRepository = give( Settings::class ); |
| 46 | |
| 47 | $settingHtml = $htmlElements->select( |
| 48 | [ |
| 49 | 'id' => 'paypal_commerce_account_country', |
| 50 | 'options' => give_get_country_list(), |
| 51 | 'chosen' => true, |
| 52 | 'placeholder' => esc_html__( 'Choose a country', 'give' ), |
| 53 | 'show_option_all' => false, |
| 54 | 'show_option_none' => false, |
| 55 | 'data' => [ |
| 56 | 'search-type' => 'no_ajax', |
| 57 | ], |
| 58 | 'selected' => $merchantModel->accountCountry ?: $settingRepository->getAccountCountry(), |
| 59 | ] |
| 60 | ); |
| 61 | |
| 62 | $trClass = $merchantRepository->accountIsConnected() ? |
| 63 | 'js-fields-has-custom-saving-logic hide-with-position' : |
| 64 | 'js-fields-has-custom-saving-logic'; |
| 65 | ?> |
| 66 | <tr valign="top" class="<?php echo $trClass; ?>"> |
| 67 | <th scope="row" class="titledesc"> |
| 68 | <label for="give_paypal_commerce_country"><?php esc_html_e( 'Account Country', 'give' ); ?></label> |
| 69 | </th> |
| 70 | <td class="give-forminp"> |
| 71 | <?php |
| 72 | printf( |
| 73 | '%1$s<div class="give-field-description">%2$s</div>', |
| 74 | $settingHtml, |
| 75 | esc_html__( 'The country your site operates from.', 'give' ) |
| 76 | ) |
| 77 | ?> |
| 78 | </td> |
| 79 | </tr> |
| 80 | <?php |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Paypal Checkout account manager custom field |
| 85 | * |
| 86 | * @since 2.9.0 |
| 87 | */ |
| 88 | public function payPalCommerceAccountManagerField() { |
| 89 | $recurringAddonInfo = Give_License::get_plugin_by_slug( 'give-recurring' ); |
| 90 | $isRecurringAddonActive = isset( $recurringAddonInfo['Status'] ) && 'active' === $recurringAddonInfo['Status']; |
| 91 | ?> |
| 92 | <tr valign="top"> |
| 93 | <th scope="row" class="titledesc"> |
| 94 | <label for="give_paypal_commerce_country"><?php esc_html_e( 'PayPal Connection', 'give' ); ?></label> |
| 95 | </th> |
| 96 | <td class="give-forminp"> |
| 97 | <div id="give-paypal-commerce-account-manager-field-wrap"> |
| 98 | <div class="connect-button-wrap"> |
| 99 | <?php |
| 100 | /** @var MerchantDetails $accountRepository */ |
| 101 | $accountRepository = give( MerchantDetails::class ); |
| 102 | ?> |
| 103 | <div |
| 104 | class="button-wrap connection-setting <?php echo $accountRepository->accountIsConnected() ? 'give-hidden' : ''; ?>"> |
| 105 | <div> |
| 106 | <button class="button button-primary button-large" id="js-give-paypal-on-boarding-handler"> |
| 107 | <i class="fab fa-paypal"></i> |
| 108 | <?php |
| 109 | esc_html_e( |
| 110 | 'Connect with PayPal', |
| 111 | 'give' |
| 112 | ); |
| 113 | ?> |
| 114 | </button> |
| 115 | <a class="give-hidden" target="_blank" |
| 116 | data-paypal-onboard-complete="givePayPalOnBoardedCallback" href="#" |
| 117 | data-paypal-button="true"> |
| 118 | <?php esc_html_e( 'Sign up for PayPal', 'give' ); ?> |
| 119 | </a> |
| 120 | <span class="tooltip"> |
| 121 | <span class="left-arrow"></span> |
| 122 | <?php esc_html_e( 'Click to get started!', 'give' ); ?> |
| 123 | </span> |
| 124 | </div> |
| 125 | <span class="give-field-description"> |
| 126 | <i class="fa fa-exclamation"></i> |
| 127 | <?php esc_html_e( 'PayPal is currently NOT connected.', 'give' ); ?> |
| 128 | </span> |
| 129 | </div> |
| 130 | <div |
| 131 | class="button-wrap disconnection-setting <?php echo ! $accountRepository->accountIsConnected() ? 'give-hidden' : ''; ?>"> |
| 132 | <div> |
| 133 | <button class="button button-large disabled" disabled="disabled"> |
| 134 | <i class="fab fa-paypal"></i> <?php esc_html_e( 'Connected', 'give' ); ?> |
| 135 | </button> |
| 136 | </div> |
| 137 | <div> |
| 138 | <span class="give-field-description"> |
| 139 | <i class="fa fa-check"></i> |
| 140 | <?php |
| 141 | printf( |
| 142 | '%1$s <span class="paypal-account-email">%2$s</span>', |
| 143 | esc_html__( 'Connected for payments as', 'give' ), |
| 144 | give( MerchantDetail::class )->merchantId |
| 145 | ); |
| 146 | ?> |
| 147 | </span> |
| 148 | <span class="actions"> |
| 149 | <a href="#" |
| 150 | id="js-give-paypal-disconnect-paypal-account"><?php esc_html_e( 'Disconnect', 'give' ); ?></a> |
| 151 | </span> |
| 152 | </div> |
| 153 | <div class="api-access-feature-list-wrap"> |
| 154 | <p><?php esc_html_e( 'APIs Connected:', 'give' ); ?></p> |
| 155 | <ul> |
| 156 | <li><?php esc_html_e( 'Payments', 'give' ); ?></li> |
| 157 | <?php if ( $isRecurringAddonActive ) : ?> |
| 158 | <li><?php esc_html_e( 'Subscriptions', 'give' ); ?></li> |
| 159 | <?php endif; ?> |
| 160 | <li><?php esc_html_e( 'Refunds', 'give' ); ?></li> |
| 161 | </ul> |
| 162 | </div> |
| 163 | |
| 164 | <?php $accountErrors = give( MerchantDetails::class )->getAccountErrors(); ?> |
| 165 | <?php if ( ! empty( $accountErrors ) ) : ?> |
| 166 | <div> |
| 167 | <span> |
| 168 | <p class="error-message"><?php esc_html_e( 'Warning, your account is not ready to accept donations. Please review the following list:', 'give' ); ?></p> |
| 169 | <ul class="ul-disc"> |
| 170 | <?php |
| 171 | foreach ( $accountErrors as $error ) { |
| 172 | echo "<li>{$error}</li>"; |
| 173 | } |
| 174 | ?> |
| 175 | </ul> |
| 176 | <p><a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=paypal&paypalStatusCheck' ); ?>"><?php esc_html_e( 'Re-Check Account Status', 'give' ); ?></a></p> |
| 177 | </span> |
| 178 | </div> |
| 179 | <?php endif; ?> |
| 180 | </div> |
| 181 | </div> |
| 182 | </div> |
| 183 | </td> |
| 184 | </tr> |
| 185 | <?php |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /** |
| 190 | * PayPal Commerce introduction section. |
| 191 | * |
| 192 | * @since 2.9.0 |
| 193 | */ |
| 194 | public function introductionSection() { |
| 195 | ?> |
| 196 | <div id="give-paypal-commerce-introduction-wrap"> |
| 197 | <div class="hero-section"> |
| 198 | <div> |
| 199 | <h2><?php esc_html_e( 'Accept Donations with PayPal Donations', 'give' ); ?></h2> |
| 200 | <p class="give-field-description"><?php esc_html_e( 'Allow your donors to give using Debit or Credit Cards directly on your website with no additional fees.', 'give' ); ?></p> |
| 201 | </div> |
| 202 | <div class="paypal-logo"> |
| 203 | <img src="<?php echo GIVE_PLUGIN_URL . '/assets/dist/images/admin/paypal-logo.svg'; ?>" width="316" height="84" alt="<?php esc_attr_e( 'PayPal Logo Image', 'give' ); ?>"> |
| 204 | </div> |
| 205 | </div> |
| 206 | <div class="feature-list"> |
| 207 | <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Credit and Debit Card Donations', 'give' ); ?> |
| 208 | </div> |
| 209 | <div> |
| 210 | <i class="fa fa-angle-right"></i><?php esc_html_e( 'Improve donation conversion rates', 'give' ); ?> |
| 211 | </div> |
| 212 | <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Easy no-API key connection', 'give' ); ?></div> |
| 213 | <div> |
| 214 | <i class="fa fa-angle-right"></i><?php esc_html_e( 'Accept payments from around the world', 'give' ); ?> |
| 215 | </div> |
| 216 | <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Donate via PayPal accounts', 'give' ); ?> |
| 217 | </div> |
| 218 | <div><i class="fa fa-angle-right"></i><?php esc_html_e( 'Supports 3D Secure payments', 'give' ); ?> |
| 219 | </div> |
| 220 | </div> |
| 221 | </div> |
| 222 | <?php |
| 223 | } |
| 224 | } |
| 225 |