AccountManagerSettingField.php
4 years ago
CreditCardSettingField.php
4 years ago
CustomizeAccountField.php
4 years ago
AccountManagerSettingField.php
567 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Stripe\Admin; |
| 4 | |
| 5 | use Give\PaymentGateways\Stripe\Repositories\AccountDetail; |
| 6 | use Give\PaymentGateways\Stripe\Repositories\Settings; |
| 7 | use Give_Admin_Settings; |
| 8 | use function _e; |
| 9 | use function add_query_arg; |
| 10 | use function do_action; |
| 11 | use function esc_html; |
| 12 | use function esc_html__; |
| 13 | use function esc_html_e; |
| 14 | use function esc_url_raw; |
| 15 | use function get_site_url; |
| 16 | use function give; |
| 17 | use function esc_attr; |
| 18 | use function give_has_upgrade_completed; |
| 19 | use function give_stripe_connection_type_name; |
| 20 | use function give_stripe_is_premium_active; |
| 21 | |
| 22 | /** |
| 23 | * Class AccountManagerSettingField |
| 24 | * |
| 25 | * @package Give\PaymentGateways\Stripe\Admin |
| 26 | * @since 2.13.0 |
| 27 | */ |
| 28 | class AccountManagerSettingField { |
| 29 | |
| 30 | /** |
| 31 | * @var AccountDetail |
| 32 | */ |
| 33 | private $accountDetailRepository; |
| 34 | |
| 35 | /** |
| 36 | * @var array |
| 37 | */ |
| 38 | private $stripeAccounts; |
| 39 | |
| 40 | /** |
| 41 | * @var string |
| 42 | */ |
| 43 | private $defaultStripeAccountSlug; |
| 44 | /** |
| 45 | * @var Settings |
| 46 | */ |
| 47 | private $settings; |
| 48 | |
| 49 | /** |
| 50 | * AccountManagerSettingField constructor. |
| 51 | * |
| 52 | * @since 2.13.0 |
| 53 | * |
| 54 | * @param AccountDetail $accountDetailRepository |
| 55 | * @param Settings $settings |
| 56 | */ |
| 57 | public function __construct( AccountDetail $accountDetailRepository, Settings $settings ) { |
| 58 | $this->accountDetailRepository = $accountDetailRepository; |
| 59 | $this->settings = $settings; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @since 2.13.0 |
| 64 | */ |
| 65 | private function setUpProperties() { |
| 66 | global $post; |
| 67 | $this->stripeAccounts = $this->settings->getAllStripeAccounts(); |
| 68 | $this->defaultStripeAccountSlug = $this->isGlobalSettingPage() ? |
| 69 | $this->settings->getDefaultStripeAccountSlug() : |
| 70 | $this->settings->getDefaultStripeAccountSlugForDonationForm( $post->ID ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Render Stripe account manager setting field. |
| 75 | * |
| 76 | * @since 2.13.0 |
| 77 | * |
| 78 | * @param array $field |
| 79 | */ |
| 80 | public function handle( $field ) { |
| 81 | $this->setUpProperties(); |
| 82 | $classes = ! empty( $field['wrapper_class'] ) ? esc_attr( $field['wrapper_class'] ) : '' |
| 83 | ?> |
| 84 | <div class="<?php echo $classes; ?>"> |
| 85 | |
| 86 | <div id="give-stripe-account-manager-errors"></div> |
| 87 | <?php $this->getIntroductionSectionMarkup(); ?> |
| 88 | <div class="give-stripe-account-manager-container"> |
| 89 | <div class="main-heading"> |
| 90 | <h2 class="give-stripe-setting-heading"><?php esc_html_e( 'Connected Accounts', 'give' ); ?></h2> |
| 91 | </div> |
| 92 | <?php |
| 93 | $this->getStripeAccountListSectionMarkup(); |
| 94 | $this->getAddNewStripeAccountSectionMarkup(); |
| 95 | ?> |
| 96 | </div> |
| 97 | <?php $this->getDefaultStripeAccountNotice(); ?> |
| 98 | </div> |
| 99 | <?php |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @since 2.13.0 |
| 104 | */ |
| 105 | private function getIntroductionSectionMarkup() { |
| 106 | // Show introduction content only on global setting edit screen. |
| 107 | if ( ! $this->isGlobalSettingPage() ) { |
| 108 | return; |
| 109 | } |
| 110 | ?> |
| 111 | <div id="give-stripe-account-manager-description"> |
| 112 | <h2><?php esc_html_e( 'Accept Donations with Stripe', 'give' ); ?></h2> |
| 113 | |
| 114 | <?php if ( give_stripe_is_premium_active() ) : ?> |
| 115 | <div class="give-stripe-pro-badge"> |
| 116 | <div class="give-tooltip" data-tooltip=" |
| 117 | <?php |
| 118 | esc_html_e( |
| 119 | 'You are using the Pro version of the GiveWP add-on which includes additional payment methods, zero additional fees, and premium support.', |
| 120 | 'give' |
| 121 | ); |
| 122 | ?> |
| 123 | "> |
| 124 | <span class="dashicons dashicons-yes"></span> |
| 125 | <?php esc_html_e( 'Pro Version Active', 'give' ); ?> |
| 126 | </div> |
| 127 | </div> |
| 128 | <?php endif; ?> |
| 129 | |
| 130 | <p class="give-stripe-subheading-description"> |
| 131 | <?php |
| 132 | esc_html_e( |
| 133 | 'Connect to the Stripe payment gateway using this section. Multiple Stripe accounts can be connected simultaneously. All donation forms will use the "Default Account" unless configured otherwise. To specify a different Stripe account for a form, configure the settings within the "Stripe Account" tab on the individual form edit screen.', |
| 134 | 'give' |
| 135 | ); |
| 136 | ?> |
| 137 | </p> |
| 138 | <?php |
| 139 | if ( $this->canShowFreeStripeVersionNotice() ) { |
| 140 | $this->getFreeStripeVersionNoticeMarkup(); |
| 141 | } |
| 142 | ?> |
| 143 | <hr style="margin: 25px 0; display: block" /> |
| 144 | </div> |
| 145 | <?php |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @since 2.13.0 |
| 150 | */ |
| 151 | private function getStripeAccountListSectionMarkup() { |
| 152 | $this->getStripeAccountOnBoardingModalMarkup(); |
| 153 | if ( ! $this->stripeAccounts || ( ! $this->isGlobalSettingPage() && 1 === count( $this->stripeAccounts ) ) ) : |
| 154 | $this->getNoStripeAccountMarkup(); |
| 155 | |
| 156 | return; |
| 157 | endif; |
| 158 | ?> |
| 159 | |
| 160 | <div class="give-stripe-account-manager-list"> |
| 161 | <?php |
| 162 | foreach ( $this->stripeAccounts as $stripeAccountDetails ) { |
| 163 | $this->getStripeAccountMarkup( $stripeAccountDetails ); |
| 164 | } |
| 165 | ?> |
| 166 | </div> |
| 167 | <?php |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @since 2.13.0 |
| 172 | */ |
| 173 | private function getAddNewStripeAccountSectionMarkup() { |
| 174 | if ( $this->canShowCompatibilityNotice() ) { |
| 175 | $this->getCompatibilityNoticeMarkup(); |
| 176 | |
| 177 | return; |
| 178 | } |
| 179 | ?> |
| 180 | <div class="give-stripe-account-manager-add-section<?php echo give_stripe_is_premium_active() ? ' give-settings-premium-active' : ''; ?>"> |
| 181 | |
| 182 | <div class="stripe-logo-with-circle"> |
| 183 | <svg width="21" height="31" viewBox="0 0 21 31" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 184 | <path fill-rule="evenodd" clip-rule="evenodd" d="M8.41683 9.55871C8.41683 8.29941 9.4501 7.81507 11.1614 7.81507C13.6155 7.81507 16.7153 8.55773 19.1693 9.8816V2.29355C16.4892 1.22799 13.8415 0.808228 11.1614 0.808228C4.60666 0.808228 0.247559 4.23093 0.247559 9.94618C0.247559 18.8581 12.5176 17.4374 12.5176 21.2798C12.5176 22.7652 11.226 23.2495 9.4178 23.2495C6.73777 23.2495 3.31507 22.1517 0.602744 20.6663V28.3513C3.60568 29.6428 6.6409 30.1918 9.4178 30.1918C16.134 30.1918 20.7515 26.8659 20.7515 21.0861C20.7192 11.4638 8.41683 13.1751 8.41683 9.55871Z" fill="#6772E5" /> |
| 185 | </svg> |
| 186 | </div> |
| 187 | <h3 class="give-stripe-heading"><?php esc_html_e( 'Add a New Stripe Account', 'give' ); ?></h3> |
| 188 | |
| 189 | <div class="give-setting-tab-body-gateways"> |
| 190 | |
| 191 | <?php |
| 192 | |
| 193 | // Output Stripe Connect Button. |
| 194 | echo $this->getStripeConnectButtonMarkup(); |
| 195 | |
| 196 | // Check if premium is active. |
| 197 | if ( give_stripe_is_premium_active() ) { |
| 198 | /** |
| 199 | * This action hook will be used to load Manual API fields for premium addon. |
| 200 | * |
| 201 | * @param array $this- >stripeAccounts All Stripe accounts. |
| 202 | * |
| 203 | * @since 2.7.0 |
| 204 | * |
| 205 | */ |
| 206 | do_action( 'give_stripe_premium_manual_api_fields', $this->stripeAccounts ); |
| 207 | } |
| 208 | ?> |
| 209 | </div> |
| 210 | </div> |
| 211 | <?php |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @since 2.13.0 |
| 216 | * |
| 217 | * @param array $stripeAccount |
| 218 | */ |
| 219 | private function getStripeAccountMarkup( $stripeAccount ) { |
| 220 | $accountName = $stripeAccount['account_name']; |
| 221 | $accountEmail = $stripeAccount['account_email']; |
| 222 | $stripeAccountId = $stripeAccount['account_id']; |
| 223 | $stripeAccountSlug = $stripeAccount['account_slug']; |
| 224 | |
| 225 | // Do not print global default Stripe account in donation form setting. |
| 226 | if ( $this->isGlobalDefaultStripeAccount( $stripeAccountSlug ) ) { |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | $disconnectUrl = add_query_arg( |
| 231 | [ |
| 232 | 'account_type' => $stripeAccount['type'], |
| 233 | 'action' => 'disconnect_stripe_account', |
| 234 | 'account_slug' => $stripeAccountSlug, |
| 235 | ], |
| 236 | wp_nonce_url( admin_url( 'admin-ajax.php' ), 'give_disconnect_connected_stripe_account_' . $stripeAccountSlug ) |
| 237 | ); |
| 238 | |
| 239 | $classes = $stripeAccountSlug === $this->defaultStripeAccountSlug ? ' give-stripe-boxshadow-option-wrap__selected' : ''; |
| 240 | ?> |
| 241 | <div |
| 242 | id="give-stripe-<?php echo $stripeAccountSlug; ?>" |
| 243 | class="give-stripe-account-manager-list-item give-stripe-boxshadow-option-wrap<?php echo $classes; ?>" |
| 244 | > |
| 245 | <input type="hidden" name="stripe-account-slug" value="<?php echo $stripeAccountSlug; ?>" readonly> |
| 246 | <input type="hidden" name="setting-page" value="<?php echo $this->isGlobalSettingPage() ? 'global' : 'form'; ?>" readonly> |
| 247 | <?php if ( $stripeAccountSlug === $this->defaultStripeAccountSlug ) : ?> |
| 248 | <div class="give-stripe-account-default-checkmark"> |
| 249 | <svg width="33" height="33" viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 250 | <path d="M32.375 16.1875C32.375 25.1276 25.1276 32.375 16.1875 32.375C7.24737 32.375 0 25.1276 0 16.1875C0 7.24737 7.24737 0 16.1875 0C25.1276 0 32.375 7.24737 32.375 16.1875ZM14.3151 24.7586L26.3252 12.7486C26.733 12.3407 26.733 11.6795 26.3252 11.2717L24.8483 9.79474C24.4404 9.38686 23.7792 9.38686 23.3713 9.79474L13.5766 19.5894L9.00371 15.0165C8.59589 14.6086 7.93462 14.6086 7.52673 15.0165L6.04982 16.4934C5.642 16.9012 5.642 17.5625 6.04982 17.9703L12.8381 24.7586C13.246 25.1665 13.9072 25.1665 14.3151 24.7586Z" fill="#69B868" /> |
| 251 | </svg> |
| 252 | </div> |
| 253 | <?php endif; ?> |
| 254 | |
| 255 | <div class="give-stripe-account-fieldset give-stripe-account-name"> |
| 256 | <span class="give-stripe-label"><?php esc_html_e( 'Account name:', 'give' ); ?></span> |
| 257 | <span class="give-stripe-connect-data-field"> |
| 258 | <?php echo esc_html( $accountName ); ?> |
| 259 | </span> |
| 260 | </div> |
| 261 | |
| 262 | <?php if ( ! empty( $accountEmail ) ) : ?> |
| 263 | <div class="give-stripe-account-fieldset give-stripe-account-email"> |
| 264 | <span class="give-stripe-label"><?php esc_html_e( 'Account email:', 'give' ); ?></span> |
| 265 | <div class="give-stripe-connect-data-field"> |
| 266 | <?php echo esc_html( $accountEmail ); ?> |
| 267 | </div> |
| 268 | </div> |
| 269 | <?php endif; ?> |
| 270 | |
| 271 | <?php if ( ! empty( $stripeAccountId ) ) : ?> |
| 272 | <div class="give-stripe-account-fieldset give-stripe-account-id"> |
| 273 | <span class="give-stripe-label"><?php esc_html_e( 'Account ID:', 'give' ); ?></span> |
| 274 | <div class="give-stripe-connect-data-field"> |
| 275 | <?php echo esc_html( $stripeAccountId ); ?> |
| 276 | </div> |
| 277 | </div> |
| 278 | <?php endif; ?> |
| 279 | |
| 280 | <div class="give-stripe-account-fieldset give-stripe-connection-method"> |
| 281 | <span class="give-stripe-label"> |
| 282 | <?php esc_html_e( 'Connection Method:', 'give' ); ?> |
| 283 | </span> |
| 284 | <div class="give-stripe-connect-data-field"> |
| 285 | <?php echo give_stripe_connection_type_name( $stripeAccount['type'] ); ?> |
| 286 | </div> |
| 287 | </div> |
| 288 | |
| 289 | <?php |
| 290 | /** |
| 291 | * Filter fire. |
| 292 | * |
| 293 | * Developer can utilize this hook to add custom action to stripe account |
| 294 | * |
| 295 | * @since 2.13.3 |
| 296 | */ |
| 297 | $stripeAccountActionsHtml = apply_filters( 'give_stripe_manage_account_actions_html', '', $stripeAccount, $this->stripeAccounts, $this->defaultStripeAccountSlug ); |
| 298 | |
| 299 | if ( $stripeAccountActionsHtml ) { |
| 300 | printf( |
| 301 | '<div class="give-stripe-account-fieldset give-stripe-account-edit">%s</div>', |
| 302 | $stripeAccountActionsHtml |
| 303 | ); |
| 304 | } |
| 305 | ?> |
| 306 | |
| 307 | <div class="give-stripe-account-fieldset"> |
| 308 | <span class="give-stripe-label"><?php esc_html_e( 'Connection Status:', 'give' ); ?></span> |
| 309 | <div class="give-stripe-account-actions"> |
| 310 | <span class="give-stripe-account-connected give-stripe-connect-data-field"> |
| 311 | <?php esc_html_e( 'Connected', 'give' ); ?> |
| 312 | </span> |
| 313 | <?php if ( $stripeAccountSlug !== $this->defaultStripeAccountSlug || 1 === count( $this->stripeAccounts ) ) : ?> |
| 314 | <span class="give-stripe-account-disconnect"> |
| 315 | <a |
| 316 | class="give-stripe-disconnect-account-btn" |
| 317 | href="<?php echo $disconnectUrl; ?>" |
| 318 | ><span class="dashicons dashicons-editor-unlink"></span><?php esc_html_e( 'Remove', 'give' ); ?></a> |
| 319 | </span> |
| 320 | <?php endif; ?> |
| 321 | </div> |
| 322 | </div> |
| 323 | |
| 324 | <?php if ( $stripeAccountSlug === $this->defaultStripeAccountSlug ) : ?> |
| 325 | <div class="give-stripe-account-badge"> |
| 326 | <?php esc_html_e( 'Default Account', 'give' ); ?> |
| 327 | </div> |
| 328 | <?php else : ?> |
| 329 | <div class="give-stripe-account-default"> |
| 330 | <a |
| 331 | data-account="<?php echo $stripeAccountSlug; ?>" |
| 332 | class="give-stripe-account-set-default" |
| 333 | href="#" |
| 334 | ><?php esc_html_e( 'Set as Default', 'give' ); ?></a> |
| 335 | </div> |
| 336 | <?php endif; ?> |
| 337 | </div> |
| 338 | <?php |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * @since 2.13.0 |
| 343 | */ |
| 344 | private function getStripeAccountOnBoardingModalMarkup() { |
| 345 | global $post; |
| 346 | |
| 347 | $site_url = get_site_url(); |
| 348 | $redirectUrl = $this->isGlobalSettingPage() ? |
| 349 | admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=stripe-settings' ) : |
| 350 | admin_url( "post.php?post=$post->ID&action=edit&give_tab=stripe_form_account_options" ); |
| 351 | |
| 352 | $modal_title = sprintf( |
| 353 | '<strong>%1$s</strong>', |
| 354 | esc_html__( |
| 355 | 'You are connected! Now this is important: Please configure your Stripe webhook to finalize the setup.', |
| 356 | 'give' |
| 357 | ) |
| 358 | ); |
| 359 | $modal_first_detail = sprintf( |
| 360 | '%1$s %2$s', |
| 361 | esc_html__( |
| 362 | 'In order for Stripe to function properly, you must add a new Stripe webhook endpoint. To do this please visit the <a href=\'https://dashboard.stripe.com/webhooks\' target=\'_blank\'>Webhooks Section of your Stripe Dashboard</a> and click the <strong>Add endpoint</strong> button and paste the following URL:', |
| 363 | 'give' |
| 364 | ), |
| 365 | "<strong>{$site_url}?give-listener=stripe</strong>" |
| 366 | ); |
| 367 | $modal_second_detail = esc_html__( |
| 368 | 'Stripe webhooks are required so GiveWP can communicate properly with the payment gateway to confirm payment completion, renewals, and more.', |
| 369 | 'give' |
| 370 | ); |
| 371 | $can_display = ! empty( $_GET['stripe_account'] ) ? '0' : '1'; |
| 372 | ?> |
| 373 | <div |
| 374 | id="give-stripe-connected" |
| 375 | class="stripe-btn-disabled give-hidden" |
| 376 | data-status="connected" |
| 377 | data-title="<?php echo $modal_title; ?>" |
| 378 | data-first-detail="<?php echo $modal_first_detail; ?>" |
| 379 | data-second-detail="<?php echo $modal_second_detail; ?>" |
| 380 | data-display="<?php echo $can_display; ?>" |
| 381 | data-redirect-url="<?php echo esc_url_raw( $redirectUrl ); ?>" |
| 382 | > |
| 383 | </div> |
| 384 | <?php |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * @since 2.13.0 |
| 389 | */ |
| 390 | private function getCompatibilityNoticeMarkup() { |
| 391 | ?> |
| 392 | <div class="give-stripe-account-manager-add-section"> |
| 393 | <?php |
| 394 | Give()->notices->print_admin_notices( |
| 395 | [ |
| 396 | 'description' => sprintf( |
| 397 | '%1$s <a href="%2$s">%3$s</a> %4$s', |
| 398 | esc_html__( |
| 399 | 'Give 2.7.0 introduces the ability to connect a single site to multiple Stripe accounts. To use this feature, you need to complete database updates. ', |
| 400 | 'give' |
| 401 | ), |
| 402 | esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ), |
| 403 | esc_html__( 'Click here', 'give' ), |
| 404 | esc_html__( 'to complete your pending database updates.', 'give' ) |
| 405 | ), |
| 406 | 'dismissible' => false, |
| 407 | ] |
| 408 | ); |
| 409 | ?> |
| 410 | </div> |
| 411 | <?php |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * @since 2.13.0 |
| 416 | */ |
| 417 | private function getFreeStripeVersionNoticeMarkup() { |
| 418 | ?> |
| 419 | <p class="give-stripe-subheading-description"> |
| 420 | <?php |
| 421 | printf( |
| 422 | __( |
| 423 | 'NOTE: You are using the free Stripe payment gateway integration. This includes an additional 2%% fee for processing one-time donations. This fee is removed by activating the premium <a href="%1$s" target="_blank">Stripe add-on</a> and never applies to subscription donations made through the <a href="%2$s" target="_blank">Recurring Donations add-on</a>. <a href="%3$s" target="_blank">Learn More ></a>', |
| 424 | 'give' |
| 425 | ), |
| 426 | esc_url( 'http://docs.givewp.com/settings-stripe-addon' ), |
| 427 | esc_url( 'http://docs.givewp.com/settings-stripe-recurring' ), |
| 428 | esc_url( 'http://docs.givewp.com/settings-stripe-free' ) |
| 429 | ); |
| 430 | ?> |
| 431 | </p> |
| 432 | <?php |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * @since 2.13.0 |
| 437 | */ |
| 438 | public function getNoStripeAccountMarkup() { |
| 439 | ?> |
| 440 | <div class="no-stripe-account-connected"> |
| 441 | <div class="no-stripe-account-connected-inner"> |
| 442 | <span class="dashicons dashicons-info"></span> |
| 443 | <h3 class="give-stripe-settings-heading"> |
| 444 | <?php |
| 445 | echo $this->isGlobalSettingPage() ? |
| 446 | esc_html__( 'No Stripe Accounts Connected', 'give' ) : |
| 447 | esc_html__( 'Connect a New Stripe Account', 'give' ); |
| 448 | ?> |
| 449 | </h3> |
| 450 | <p id="give-stripe-connect-invite"> |
| 451 | <?php |
| 452 | echo $this->isGlobalSettingPage() ? |
| 453 | esc_html__( 'Connect an account to get started!', 'give' ) : |
| 454 | esc_html__( 'Add a new account to customize the Stripe account used for this donation form.', 'give' ) |
| 455 | ?> |
| 456 | </p> |
| 457 | <?php echo $this->getStripeConnectButtonMarkup(); ?> |
| 458 | </div> |
| 459 | </div> |
| 460 | <?php |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * @since 2.13.0 |
| 465 | * @return string |
| 466 | */ |
| 467 | public function getStripeConnectButtonMarkup() { |
| 468 | // Prepare Stripe Connect URL. |
| 469 | $link = add_query_arg( |
| 470 | [ |
| 471 | 'stripe_action' => 'connect', |
| 472 | 'mode' => give_is_test_mode() ? 'test' : 'live', |
| 473 | 'return_url' => ! $this->isGlobalSettingPage() ? |
| 474 | rawurlencode( |
| 475 | sprintf( |
| 476 | admin_url( 'post.php?post=%d&action=edit&give_tab=stripe_form_account_options' ), |
| 477 | get_the_ID() |
| 478 | ) |
| 479 | ) : |
| 480 | rawurlencode( admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=stripe-settings' ) ), |
| 481 | 'website_url' => get_bloginfo( 'url' ), |
| 482 | 'give_stripe_connected' => '0', |
| 483 | ], |
| 484 | esc_url_raw( 'https://connect.givewp.com/stripe/connect.php' ) |
| 485 | ); |
| 486 | |
| 487 | $stripeSvgIcon = '<svg width="15" height="21" viewBox="0 0 15 21" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 488 | <path d="M6.05469 6.55469C6.05469 5.69531 6.75781 5.34375 7.92969 5.34375C9.64844 5.34375 11.7969 5.85156 13.4766 6.78906V1.55469C11.6406 0.8125 9.80469 0.5 7.92969 0.5C3.4375 0.5 0.429688 2.88281 0.429688 6.82812C0.429688 13 8.86719 11.9844 8.86719 14.6406C8.86719 15.6953 7.96875 16.0078 6.75781 16.0078C4.88281 16.0078 2.5 15.2656 0.664062 14.25V19.25C2.5 20.0703 4.57031 20.5 6.75781 20.5391C11.3672 20.5391 14.5703 18.5469 14.5703 14.5234C14.5703 7.88281 6.05469 9.05469 6.05469 6.55469Z" fill="white"/> |
| 489 | </svg> |
| 490 | '; |
| 491 | |
| 492 | return sprintf( |
| 493 | '<a href="%1$s" class="give-stripe-connect" title="%2$s"><span class="stripe-logo">%3$s</span><span>%2$s</span></a>', |
| 494 | esc_url( $link ), |
| 495 | esc_html__( 'Connect with Stripe', 'give' ), |
| 496 | $stripeSvgIcon |
| 497 | ); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * @since 2.13.0 |
| 502 | */ |
| 503 | private function getDefaultStripeAccountNotice() { |
| 504 | ?> |
| 505 | <div class="give-stripe-default-account-notice"> |
| 506 | <span class="dashicons dashicons-info"></span> |
| 507 | <div class="give-stripe-default-account-notice__inner"> |
| 508 | <p class="give-stripe-default-account-notice__bold"><strong> |
| 509 | <?php |
| 510 | echo $this->isGlobalSettingPage() ? |
| 511 | esc_html__( 'All payments go to the default account', 'give' ) : |
| 512 | esc_html__( 'Stripe donations process through the account set above', 'give' ); |
| 513 | ?> |
| 514 | </strong></p> |
| 515 | <p> |
| 516 | <?php |
| 517 | echo $this->isGlobalSettingPage() ? |
| 518 | esc_html__( 'You can set this globally (for all donation forms) or override the Stripe account per donation form.', 'give' ) : |
| 519 | esc_html__( 'This overrides the global default account setting for this donation form.', 'give' ); |
| 520 | ?> |
| 521 | </p> |
| 522 | </div> |
| 523 | </div> |
| 524 | <?php |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * @since 2.13.0 |
| 529 | * @return bool |
| 530 | */ |
| 531 | private function canShowFreeStripeVersionNotice() { |
| 532 | return ! give_stripe_is_premium_active(); |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * @return bool |
| 537 | */ |
| 538 | private function canShowCompatibilityNotice() { |
| 539 | return ! give_has_upgrade_completed( 'v270_store_stripe_account_for_donation' ); |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * @since 2.13.0 |
| 544 | * @return bool |
| 545 | */ |
| 546 | private function isGlobalSettingPage() { |
| 547 | return Give_Admin_Settings::is_setting_page( 'gateways', 'stripe-settings' ); |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * @since 2.13.0 |
| 552 | * |
| 553 | * @param string $accountSlug Stripe account slug |
| 554 | * |
| 555 | * @return bool |
| 556 | */ |
| 557 | private function isGlobalDefaultStripeAccount( $accountSlug ) { |
| 558 | $globalDefaultStripeAccountDetail = give_stripe_get_default_account(); |
| 559 | |
| 560 | if ( empty( $globalDefaultStripeAccountDetail ) ) { |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | return ! $this->isGlobalSettingPage() && $globalDefaultStripeAccountDetail['account_slug'] === $accountSlug; |
| 565 | } |
| 566 | } |
| 567 |