From b5116befa617d3b93e0b2660962963c491019e06 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 12:15:55 +0530 Subject: [PATCH 01/32] feat: add migration banner on gateway setting page --- assets/src/css/admin/give-admin.scss | 1 + .../paypal-donations-migration-banners.scss | 32 ++++++++++++ .../Banners/GatewaySettingPageBanner.php | 49 +++++++++++++++++++ src/PaymentGateways/ServiceProvider.php | 17 +++++++ 4 files changed, 99 insertions(+) create mode 100644 assets/src/css/admin/paypal-donations-migration-banners.scss create mode 100644 src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php diff --git a/assets/src/css/admin/give-admin.scss b/assets/src/css/admin/give-admin.scss index b428d3f5b4..9c81309244 100644 --- a/assets/src/css/admin/give-admin.scss +++ b/assets/src/css/admin/give-admin.scss @@ -46,6 +46,7 @@ @import 'tabs'; @import 'upsells'; @import 'sale-banners'; +@import 'paypal-donations-migration-banners'; @import '_components.admin-header'; @import '../../../../src/DonorDashboards/resources/styles/upgradenotice.scss'; diff --git a/assets/src/css/admin/paypal-donations-migration-banners.scss b/assets/src/css/admin/paypal-donations-migration-banners.scss new file mode 100644 index 0000000000..1bd1f8eace --- /dev/null +++ b/assets/src/css/admin/paypal-donations-migration-banners.scss @@ -0,0 +1,32 @@ +/** + * PayPal Donations Migration Banners + * -------------------------------------------------- + */ + +// Banner for gateways setting page. +.give-paypal-migration-banner{ + &.gateway-settiing-page{ + background-color: #F29718; + padding: 8px 14px; + border: 1px solid #F29718; + + .message{ + color: white; + font-size: 15px; + + a{ + color: white; + text-decoration: none; + font-weight: bold; + } + + .label{ + text-transform: uppercase; + color: #F29718; + background-color: white; + padding: 3px 7px; + margin-right: 10px; + } + } + } +} diff --git a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php new file mode 100644 index 0000000000..3327be56f1 --- /dev/null +++ b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php @@ -0,0 +1,49 @@ + +

+ %1$s%2$s %4$s +

+ ', + esc_html__('Important', 'give'), + esc_html__('PayPal Standard is no longer supported by PayPal. It is recommended to migrate to PayPal Donations.', 'give'), + '#', + esc_html__('How to migrate safely', 'give') + ); + } +} diff --git a/src/PaymentGateways/ServiceProvider.php b/src/PaymentGateways/ServiceProvider.php index 60aa969714..69a6e2a3f3 100644 --- a/src/PaymentGateways/ServiceProvider.php +++ b/src/PaymentGateways/ServiceProvider.php @@ -14,6 +14,7 @@ use Give\PaymentGateways\Gateways\Stripe\Controllers\UpdateStatementDescriptorAjaxRequestController; use Give\PaymentGateways\Gateways\Stripe\Migrations\AddMissingTransactionIdForUncompletedDonations; use Give\PaymentGateways\Gateways\Stripe\Migrations\AddStatementDescriptorToStripeAccounts; +use Give\PaymentGateways\PayPalCommerce\Banners\GatewaySettingPageBanner; use Give\PaymentGateways\PayPalCommerce\Migrations\RegisterPayPalDonationsRefreshTokenCronJobByMode; use Give\PaymentGateways\PayPalCommerce\Migrations\RemoveLogWithCardInfo; use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; @@ -65,6 +66,8 @@ public function boot() */ Hooks::addAction('wp_footer', CheckoutGateway::class, 'maybeHandleRedirect', 99999); Hooks::addAction('give_embed_footer', CheckoutGateway::class, 'maybeHandleRedirect', 99999); + + $this->registerPayPalDonationsMigrationBanners(); } /** @@ -79,4 +82,18 @@ private function registerMigrations() RegisterPayPalDonationsRefreshTokenCronJobByMode::class ]); } + + /** + * This method registers the banners for the migration from PayPal Standard to PayPal Donations. + * @unreleased + * @return void + */ + private function registerPayPalDonationsMigrationBanners() + { + if (! is_admin()) { + return; + } + + give(GatewaySettingPageBanner::class)->setupHook(); + } } From a30b478cc2a22a4e003baf85dc1b42a32b906284 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 12:18:18 +0530 Subject: [PATCH 02/32] feat: show banner only if paypal standard if active --- .../Banners/GatewaySettingPageBanner.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php index 3327be56f1..7eded106fb 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php @@ -29,8 +29,13 @@ public function setupHook() */ public function render() { - // Bailout if not on the gateway settings page. - if ('gateways-settings' !== give_get_current_setting_section()) { + // Bailout if: + // - not on the gateway settings page, or + // - PayPal Standard is not active. + if ( + 'gateways-settings' !== give_get_current_setting_section() || + ! give_is_gateway_active('paypal') + ) { return; } @@ -41,7 +46,10 @@ public function render()

', esc_html__('Important', 'give'), - esc_html__('PayPal Standard is no longer supported by PayPal. It is recommended to migrate to PayPal Donations.', 'give'), + esc_html__( + 'PayPal Standard is no longer supported by PayPal. It is recommended to migrate to PayPal Donations.', + 'give' + ), '#', esc_html__('How to migrate safely', 'give') ); From 5568f26f446e83fe42c984cf046428b103058ebe Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 12:35:46 +0530 Subject: [PATCH 03/32] doc: edit comment --- src/PaymentGateways/ServiceProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PaymentGateways/ServiceProvider.php b/src/PaymentGateways/ServiceProvider.php index 69a6e2a3f3..14703731a2 100644 --- a/src/PaymentGateways/ServiceProvider.php +++ b/src/PaymentGateways/ServiceProvider.php @@ -84,7 +84,7 @@ private function registerMigrations() } /** - * This method registers the banners for the migration from PayPal Standard to PayPal Donations. + * This method registers the banners. * @unreleased * @return void */ @@ -94,6 +94,7 @@ private function registerPayPalDonationsMigrationBanners() return; } + // Banner for the migration from PayPal Standard to PayPal Donations. give(GatewaySettingPageBanner::class)->setupHook(); } } From bd8ed14003a7e2c93d9aaf45cac676d4858143e5 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 12:36:01 +0530 Subject: [PATCH 04/32] feat: add banner for paypal donations --- .../paypal-donations-migration-banners.scss | 43 +++++++++++++++--- .../PayPalCommerce/AdminSettingFields.php | 2 + .../PayPalDonationsSettingPageBanner.php | 44 +++++++++++++++++++ 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php diff --git a/assets/src/css/admin/paypal-donations-migration-banners.scss b/assets/src/css/admin/paypal-donations-migration-banners.scss index 1bd1f8eace..42c812049c 100644 --- a/assets/src/css/admin/paypal-donations-migration-banners.scss +++ b/assets/src/css/admin/paypal-donations-migration-banners.scss @@ -3,21 +3,36 @@ * -------------------------------------------------- */ -// Banner for gateways setting page. +// Banners. .give-paypal-migration-banner{ + padding: 8px 14px; + border-style: solid; + border-width: 1px; + + // Common styles. + .message{ + font-size: 15px; + + .label{ + margin-right: 10px; + } + + a{ + text-decoration: none; + font-weight: 600; + } + } + + // Banner for gateways setting page. &.gateway-settiing-page{ background-color: #F29718; - padding: 8px 14px; - border: 1px solid #F29718; + border-color: #E48100; .message{ color: white; - font-size: 15px; a{ color: white; - text-decoration: none; - font-weight: bold; } .label{ @@ -25,8 +40,22 @@ color: #F29718; background-color: white; padding: 3px 7px; - margin-right: 10px; } } } + + // Banner for PayPal Donations setting page. + &.paypal-donations-setting-page{ + background-color: #FFF0A6; + color: #594B05; + border-color: #ffea82; + + .label{ + vertical-align: middle; + } + + a{ + color: #594B05; + } + } } diff --git a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php index b9b15726b2..5b62e7f23c 100644 --- a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php +++ b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php @@ -2,6 +2,7 @@ namespace Give\PaymentGateways\PayPalCommerce; +use Give\PaymentGateways\PayPalCommerce\Banners\PayPalDonationsSettingPageBanner; use Give\PaymentGateways\PayPalCommerce\Models\MerchantDetail; use Give\PaymentGateways\PayPalCommerce\Repositories\MerchantDetails; use Give\PaymentGateways\PayPalCommerce\Repositories\Settings; @@ -468,6 +469,7 @@ class="js-give-paypal-disconnect-paypal-account"

  • + render(); ?> printErrors($mechantDetailsRepository); ?> diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php new file mode 100644 index 0000000000..45d827e59a --- /dev/null +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php @@ -0,0 +1,44 @@ + +

    + %1$s%2$s %4$s +

    + ', + $this->getIcon(), + esc_html__( + 'Make sure you enable PayPal Donation in the gateway settings to receive payment on your form.', + 'give' + ), + '#', + esc_html__('Go to gateway settings', 'give') + ); + } + + /** + * @unreleased + * @return string + */ + private function getIcon() + { + return ' + + +'; + } +} From f8675f009c3e0226f8b187f5894e2981ee401a65 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 16:55:21 +0530 Subject: [PATCH 05/32] fix: show banner only if paypal donation is connect but not active --- src/PaymentGateways/PayPalCommerce/AdminSettingFields.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php index 5b62e7f23c..892e131ce8 100644 --- a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php +++ b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php @@ -469,7 +469,11 @@ class="js-give-paypal-disconnect-paypal-account"

  • - render(); ?> + render(); + } + ?> printErrors($mechantDetailsRepository); ?> From 1ac94d1855963c5b7b47557cbea3187ffa930f3f Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 16:59:16 +0530 Subject: [PATCH 06/32] feat: link to gateway setting page --- .../PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php index 45d827e59a..b125d4112d 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php @@ -25,7 +25,7 @@ public function render(): string 'Make sure you enable PayPal Donation in the gateway settings to receive payment on your form.', 'give' ), - '#', + esc_url(admin_url('edit.php?post_type=give_forms&page=give-settings&tab=gateways')), esc_html__('Go to gateway settings', 'give') ); } From 33858923c6b88f14046e0652e4c723615626c40e Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 17:46:29 +0530 Subject: [PATCH 07/32] feat: add paypal standard to donation migration banner --- ...andardToDonationsMigrationGlobalBanner.php | 100 ++++++++++++++++++ src/PaymentGateways/ServiceProvider.php | 2 + 2 files changed, 102 insertions(+) create mode 100644 src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php new file mode 100644 index 0000000000..bbb37024c6 --- /dev/null +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -0,0 +1,100 @@ +getModalScript()); + } + }); + } + + /** + * Render the banner. + * + * @unreleased + */ + public function getModalScript(): string + { + $modalTitle = esc_html__( + 'PayPal Standard Deprecation', + 'give' + ); + + $modalSubHeading = esc_html__( + 'Paypal Standard is no longer supported by PayPal', + 'give' + ); + + $modalDescription = esc_html__( + 'Migrate to PayPal Donations, which fully supports PayPal\'s latest API updates. As PayPal Standard is being deprecated, it will soon be removed from our platform.', + 'give' + ); + + $modalCancelButtonTitle = esc_html__( + 'Read Documentation', + 'give' + ); + + $modalConfirmButtonTitle = esc_html__( + 'Connect PayPal Donations', + 'give' + ); + + $linkToPayPalDonationsSettingPage = esc_url_raw(admin_url( + 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=paypal' + )); + + return << { + new Give.modal.GiveConfirmModal( { + classes: { + modalWrapper: 'give-paypal-standard-to-donations-migration-banner', + }, + modalContent: { + title: '$modalTitle', + body: ` +
    + $modalSubHeading +

    $modalDescription

    +
    + `.trim(), + cancelBtnTitle: '$modalCancelButtonTitle', + confirmBtnTitle: '$modalConfirmButtonTitle' + }, + closeOnBgClick: true, + callbacks: { + open: () => { + const modal = document.querySelector('.give-modal'); + + modal.querySelector('.give-popup-close-button').addEventListener('click', () => { + window.location.assign('https://google.com'); + }); + + modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { + window.location.assign('$linkToPayPalDonationsSettingPage'); + }); + } + } + } ).render(); + }); +EOT; + } +} diff --git a/src/PaymentGateways/ServiceProvider.php b/src/PaymentGateways/ServiceProvider.php index 14703731a2..afa6aeb516 100644 --- a/src/PaymentGateways/ServiceProvider.php +++ b/src/PaymentGateways/ServiceProvider.php @@ -15,6 +15,7 @@ use Give\PaymentGateways\Gateways\Stripe\Migrations\AddMissingTransactionIdForUncompletedDonations; use Give\PaymentGateways\Gateways\Stripe\Migrations\AddStatementDescriptorToStripeAccounts; use Give\PaymentGateways\PayPalCommerce\Banners\GatewaySettingPageBanner; +use Give\PaymentGateways\PayPalCommerce\Banners\PayPalStandardToDonationsMigrationGlobalBanner; use Give\PaymentGateways\PayPalCommerce\Migrations\RegisterPayPalDonationsRefreshTokenCronJobByMode; use Give\PaymentGateways\PayPalCommerce\Migrations\RemoveLogWithCardInfo; use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; @@ -96,5 +97,6 @@ private function registerPayPalDonationsMigrationBanners() // Banner for the migration from PayPal Standard to PayPal Donations. give(GatewaySettingPageBanner::class)->setupHook(); + give(PayPalStandardToDonationsMigrationGlobalBanner::class)->setHook(); } } From 3e79a798ebfaa190a05e93f92c1c0d689029d26d Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 17:54:20 +0530 Subject: [PATCH 08/32] feat: show close button in modal header --- .../Banners/PayPalStandardToDonationsMigrationGlobalBanner.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index bbb37024c6..22fa46331d 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -80,12 +80,13 @@ classes: { confirmBtnTitle: '$modalConfirmButtonTitle' }, closeOnBgClick: true, + showCloseBtn: true, callbacks: { open: () => { const modal = document.querySelector('.give-modal'); modal.querySelector('.give-popup-close-button').addEventListener('click', () => { - window.location.assign('https://google.com'); + window.open('https://google.com', '_blank') }); modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { From aa4809112713eb9d7929599212375e47fc1ae296 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 18:05:41 +0530 Subject: [PATCH 09/32] feat: allow to set custom event handle to cancel button in modal --- assets/src/js/plugins/modal.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/src/js/plugins/modal.js b/assets/src/js/plugins/modal.js index db11fc1fee..e92ea750af 100644 --- a/assets/src/js/plugins/modal.js +++ b/assets/src/js/plugins/modal.js @@ -147,7 +147,10 @@ class GiveModal { */ static __closePopup( event ) { event.preventDefault(); - jQuery.magnificPopup.instance.close(); + + if( ! event.target.classList.contains( 'js-has-event-handler' )){ + jQuery.magnificPopup.instance.close(); + } } /** From c5799508d7a9c14d6613cafb13d8ddd9c62ba959 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 18:06:00 +0530 Subject: [PATCH 10/32] fix: add custom event handle to close button --- .../Banners/PayPalStandardToDonationsMigrationGlobalBanner.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 22fa46331d..0c32eb2d1e 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -67,6 +67,7 @@ public function getModalScript(): string new Give.modal.GiveConfirmModal( { classes: { modalWrapper: 'give-paypal-standard-to-donations-migration-banner', + cancelBtn: 'give-button--secondary js-has-event-handler', }, modalContent: { title: '$modalTitle', From 8edc2a263877b4a1ab05421f790a3713f9077ff4 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 18:13:00 +0530 Subject: [PATCH 11/32] fix: add icon to modal heading --- ...alStandardToDonationsMigrationGlobalBanner.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 0c32eb2d1e..b85df234c9 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -38,6 +38,8 @@ public function getModalScript(): string 'give' ); + $modalTitle = $this->getIcon() . "  $modalTitle"; + $modalSubHeading = esc_html__( 'Paypal Standard is no longer supported by PayPal', 'give' @@ -70,8 +72,8 @@ classes: { cancelBtn: 'give-button--secondary js-has-event-handler', }, modalContent: { - title: '$modalTitle', body: ` +

    $modalTitle

    $modalSubHeading

    $modalDescription

    @@ -99,4 +101,15 @@ classes: { }); EOT; } + + /** + * @unreleased + * @return string + */ + private function getIcon(): string + { + return ' + +'; + } } From c925ce6b7fb68dcde000dbec144ee28b657c0a02 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 18:30:33 +0530 Subject: [PATCH 12/32] feat: add logic to dismiss banner by user --- ...ayPalStandardToDonationsMigrationGlobalBanner.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index b85df234c9..e61d7701e2 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -33,6 +33,9 @@ public function setHook() */ public function getModalScript(): string { + $bannerId = 'PayPalStandardToDonationsMigrationGlobalBanner'; + $nonce = wp_create_nonce("give_edit_{$bannerId}_notice"); + $modalTitle = esc_html__( 'PayPal Standard Deprecation', 'give' @@ -95,6 +98,15 @@ classes: { modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { window.location.assign('$linkToPayPalDonationsSettingPage'); }); + }, + close: () => { + wp.ajax.post({ + 'give-action': 'dismiss_notices', + 'notice_id': '$bannerId', + 'dismissible_type': 'user', + 'dismiss_interval': 'permanent', + '_wpnonce': '$nonce' + }); } } } ).render(); From 74861aca5b0c4f6a2be55aa31ef832f966fcb36c Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 18:40:02 +0530 Subject: [PATCH 13/32] feat: disable banner by user permanenetly --- ...andardToDonationsMigrationGlobalBanner.php | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index e61d7701e2..388a4ee09a 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -7,10 +7,17 @@ /** * Class PayPalStandardToDonationsMigrationGlobalBanner * + * Note: This class uses notice api to disable the banner for the user. + * * @unreleased */ class PayPalStandardToDonationsMigrationGlobalBanner { + /** + * @unreleased + * @var string + */ + private $bannerId = 'PayPalStandardToDonationsMigrationGlobalBanner'; /** * @unreleased @@ -18,7 +25,6 @@ class PayPalStandardToDonationsMigrationGlobalBanner */ public function setHook() { - add_action('admin_enqueue_scripts', function () { if (give_is_gateway_active(PayPalStandard::id())) { wp_add_inline_script('give-admin-scripts', $this->getModalScript()); @@ -33,8 +39,11 @@ public function setHook() */ public function getModalScript(): string { - $bannerId = 'PayPalStandardToDonationsMigrationGlobalBanner'; - $nonce = wp_create_nonce("give_edit_{$bannerId}_notice"); + if ($this->isBannerDisabledForUser()) { + return ''; + } + + $nonce = wp_create_nonce("give_edit_{$this->bannerId}_notice"); $modalTitle = esc_html__( 'PayPal Standard Deprecation', @@ -63,9 +72,11 @@ public function getModalScript(): string 'give' ); - $linkToPayPalDonationsSettingPage = esc_url_raw(admin_url( - 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=paypal' - )); + $linkToPayPalDonationsSettingPage = esc_url_raw( + admin_url( + 'edit.php?post_type=give_forms&page=give-settings&tab=gateways§ion=paypal' + ) + ); return << { @@ -102,7 +113,7 @@ classes: { close: () => { wp.ajax.post({ 'give-action': 'dismiss_notices', - 'notice_id': '$bannerId', + 'notice_id': '$this->bannerId', 'dismissible_type': 'user', 'dismiss_interval': 'permanent', '_wpnonce': '$nonce' @@ -124,4 +135,16 @@ private function getIcon(): string '; } + + /** + * @unreleased + * @return bool + */ + private function isBannerDisabledForUser(): bool + { + $optionKey = give()->notices->get_notice_key($this->bannerId, 'permanent', get_current_user_id()); + $optionData = \Give_Cache::get($optionKey, true); + + return ! empty($optionData) && ! is_wp_error($optionData); + } } From 60a5801449ddbc4bfa562d286f33ad2a0c78b6c4 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 23:28:16 +0530 Subject: [PATCH 14/32] refactor: print banner before account country setting field --- .../PayPalCommerce/AdminSettingFields.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php index 892e131ce8..3b375b8ad2 100644 --- a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php +++ b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php @@ -133,7 +133,15 @@ public function payPalCommerceAccountManagerField() 'give' ); $paypalSandboxSetting->isRecurringAddonActive = $isRecurringAddonActive; + echo $this->getPayPalConnectionSettingView($paypalSandboxSetting); + + if ( + give(MerchantDetail::class)->accountIsReady + && ! give_is_gateway_active(PayPalCommerce::id()) + ) { + echo give(PayPalDonationsSettingPageBanner::class)->render(); + } } /** @@ -469,11 +477,6 @@ class="js-give-paypal-disconnect-paypal-account"
  • - render(); - } - ?> printErrors($mechantDetailsRepository); ?> From 294703f8ca8c5ede3f92a7e8c5c3232ef86fefb9 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 23:37:49 +0530 Subject: [PATCH 15/32] fix: add style to link --- assets/src/css/admin/paypal-donations-migration-banners.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/src/css/admin/paypal-donations-migration-banners.scss b/assets/src/css/admin/paypal-donations-migration-banners.scss index 42c812049c..f715ebcd89 100644 --- a/assets/src/css/admin/paypal-donations-migration-banners.scss +++ b/assets/src/css/admin/paypal-donations-migration-banners.scss @@ -18,7 +18,7 @@ } a{ - text-decoration: none; + text-decoration: underline; font-weight: 600; } } From 9ee765338fa9b54c4b871c87d524d5b6373a9a92 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 23:40:32 +0530 Subject: [PATCH 16/32] fix: set font size for modal --- .../src/css/admin/paypal-donations-migration-banners.scss | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/src/css/admin/paypal-donations-migration-banners.scss b/assets/src/css/admin/paypal-donations-migration-banners.scss index f715ebcd89..f7439e1a36 100644 --- a/assets/src/css/admin/paypal-donations-migration-banners.scss +++ b/assets/src/css/admin/paypal-donations-migration-banners.scss @@ -59,3 +59,9 @@ } } } + +.give-paypal-standard-to-donations-migration-banner{ + p, strong{ + font-size: 15px + } +} From c4ec029acd4a74723d22d86b02317bcd7bf006cc Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 23:48:08 +0530 Subject: [PATCH 17/32] fix: show banner if user has capability to edit givewp settings --- .../PayPalStandardToDonationsMigrationGlobalBanner.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 388a4ee09a..353e28c885 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -25,6 +25,11 @@ class PayPalStandardToDonationsMigrationGlobalBanner */ public function setHook() { + // Bailout if user is not can not edit GiveWP settings. + if (! current_user_can('manage_give_settings')) { + return; + } + add_action('admin_enqueue_scripts', function () { if (give_is_gateway_active(PayPalStandard::id())) { wp_add_inline_script('give-admin-scripts', $this->getModalScript()); From fbea25c702ca59cbf0e63e08a60be5139742dc95 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 23:51:24 +0530 Subject: [PATCH 18/32] feat: update links --- .../PayPalCommerce/Banners/GatewaySettingPageBanner.php | 3 +-- .../Banners/PayPalStandardToDonationsMigrationGlobalBanner.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php index 7eded106fb..ed7a5c73db 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php @@ -42,7 +42,7 @@ public function render() printf( '

    - %1$s%2$s %4$s + %1$s%2$s %3$s

    ', esc_html__('Important', 'give'), @@ -50,7 +50,6 @@ public function render() 'PayPal Standard is no longer supported by PayPal. It is recommended to migrate to PayPal Donations.', 'give' ), - '#', esc_html__('How to migrate safely', 'give') ); } diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 353e28c885..c23ab6f2c1 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -108,7 +108,7 @@ classes: { const modal = document.querySelector('.give-modal'); modal.querySelector('.give-popup-close-button').addEventListener('click', () => { - window.open('https://google.com', '_blank') + window.open('https://docs.givewp.com/paypal-migration-doc', '_blank') }); modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { From 81af8588779e3845f64c21320d274f80934f9d40 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 10 Aug 2023 23:52:18 +0530 Subject: [PATCH 19/32] fix: open link in new tab --- .../PayPalCommerce/Banners/GatewaySettingPageBanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php index ed7a5c73db..fed1b3aeb8 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php @@ -42,7 +42,7 @@ public function render() printf( '

    - %1$s%2$s %3$s + %1$s%2$s %3$s

    ', esc_html__('Important', 'give'), From b0919455f5e3d1d6d4002982355cff899c6dfc3f Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 11 Aug 2023 18:56:51 +0530 Subject: [PATCH 20/32] fix: change text to normal --- .../PayPalCommerce/Banners/GatewaySettingPageBanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php index fed1b3aeb8..3759ae57a6 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/GatewaySettingPageBanner.php @@ -42,7 +42,7 @@ public function render() printf( '

    - %1$s%2$s %3$s + %1$s%2$s %3$s

    ', esc_html__('Important', 'give'), From 4d00a3b6d7cc842d159d34b2d880b0eccb230bd8 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 11 Aug 2023 19:26:47 +0530 Subject: [PATCH 21/32] fix: add border radius to label in banner --- .../css/admin/paypal-donations-migration-banners.scss | 11 ++++++++--- .../Banners/PayPalDonationsSettingPageBanner.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/assets/src/css/admin/paypal-donations-migration-banners.scss b/assets/src/css/admin/paypal-donations-migration-banners.scss index f7439e1a36..60da2f1b86 100644 --- a/assets/src/css/admin/paypal-donations-migration-banners.scss +++ b/assets/src/css/admin/paypal-donations-migration-banners.scss @@ -11,16 +11,21 @@ // Common styles. .message{ - font-size: 15px; + font-size: 15px; .label{ - margin-right: 10px; + border-radius: 4px; + font-weight: 600; } a{ text-decoration: underline; font-weight: 600; } + + .icon, .label{ + margin-right: 10px; + } } // Banner for gateways setting page. @@ -50,7 +55,7 @@ color: #594B05; border-color: #ffea82; - .label{ + .icon{ vertical-align: middle; } diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php index b125d4112d..bdcd3393cd 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalDonationsSettingPageBanner.php @@ -17,7 +17,7 @@ public function render(): string return sprintf( '

    - %1$s%2$s %4$s + %1$s%2$s %4$s

    ', $this->getIcon(), From 0a73da0a7aad6d9fbb7c1e82dc3e11f7234a10ba Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 15 Aug 2023 08:48:17 +0530 Subject: [PATCH 22/32] Update src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php Co-authored-by: Jason Adams --- .../Banners/PayPalStandardToDonationsMigrationGlobalBanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index c23ab6f2c1..7173cd2a70 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -63,7 +63,7 @@ public function getModalScript(): string ); $modalDescription = esc_html__( - 'Migrate to PayPal Donations, which fully supports PayPal\'s latest API updates. As PayPal Standard is being deprecated, it will soon be removed from our platform.', + 'Migrate to PayPal Donations, which fully supports PayPal\'s latest API updates. As PayPal Standard is being deprecated, it will soon be removed from our platform. PayPal Standard will continue to work a while longer, but we strongly recommend migrating to PayPal Donations as soon as you can.', 'give' ); From 227f98d2af6b85d218f4123b530783b564d86309 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 15 Aug 2023 11:53:29 +0530 Subject: [PATCH 23/32] fix: move banner to below paypal samdbox connection --- assets/src/images/admin/alert-triangle.svg | 3 ++ .../PayPalCommerce/AdminSettingFields.php | 42 ++++++++++++++----- .../PayPalDonationsSettingPageBanner.php | 15 +------ 3 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 assets/src/images/admin/alert-triangle.svg diff --git a/assets/src/images/admin/alert-triangle.svg b/assets/src/images/admin/alert-triangle.svg new file mode 100644 index 0000000000..276ac09282 --- /dev/null +++ b/assets/src/images/admin/alert-triangle.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php index 3b375b8ad2..2c5cf04b4b 100644 --- a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php +++ b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php @@ -136,12 +136,7 @@ public function payPalCommerceAccountManagerField() echo $this->getPayPalConnectionSettingView($paypalSandboxSetting); - if ( - give(MerchantDetail::class)->accountIsReady - && ! give_is_gateway_active(PayPalCommerce::id()) - ) { - echo give(PayPalDonationsSettingPageBanner::class)->render(); - } + echo $this->getBanner(); } /** @@ -161,13 +156,13 @@ public function introductionSection() esc_html_e( 'Allow your donors to give using Debit or Credit Cards directly on your website with no additional fees.', 'give' - ); ?>

    + ); ?>

    @@ -272,7 +267,7 @@ public function getAdminGuidanceNotice($completeMessage = true) * * @since 2.9.6 */ - private function printErrors( MerchantDetails $merchantDetailsRepository ) + private function printErrors(MerchantDetails $merchantDetailsRepository) { $accountErrors = $merchantDetailsRepository->getAccountErrors(); @@ -287,7 +282,7 @@ private function printErrors( MerchantDetails $merchantDetailsRepository ) 'There is an issue with your PayPal account that is preventing you from being able to accept donations.', 'give' ), - $this->getAdminGuidanceNotice() + $this->getAdminGuidanceNotice() ) ?>

    @@ -423,7 +418,7 @@ class="button-wrap connection-setting   connectButtonLabel; ?> - mode): ?> + mode) : ?> @@ -486,4 +481,29 @@ class="js-give-paypal-disconnect-paypal-account" accountIsReady + && ! give_is_gateway_active(PayPalCommerce::id()) + ) { + return ''; + } + ?> + + + + + render(); ?> + + +

    - %1$s%2$s %4$s + %1$s %3$s

    ', - $this->getIcon(), esc_html__( 'Make sure you enable PayPal Donation in the gateway settings to receive payment on your form.', 'give' @@ -29,16 +28,4 @@ public function render(): string esc_html__('Go to gateway settings', 'give') ); } - - /** - * @unreleased - * @return string - */ - private function getIcon() - { - return ' - - -'; - } } From a0be90a16e6e327fd01af13c941e6df483f7e5ae Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 15 Aug 2023 11:58:55 +0530 Subject: [PATCH 24/32] refactor: store icon file --- assets/src/css/admin/paypal-donations-migration-banners.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/src/css/admin/paypal-donations-migration-banners.scss b/assets/src/css/admin/paypal-donations-migration-banners.scss index 60da2f1b86..53a894d956 100644 --- a/assets/src/css/admin/paypal-donations-migration-banners.scss +++ b/assets/src/css/admin/paypal-donations-migration-banners.scss @@ -57,6 +57,8 @@ .icon{ vertical-align: middle; + background: url(../images/admin/alert-triangle.svg) no-repeat center center; + padding-right: 16px; } a{ From 352b1c10556678ec7699b9ebc9223dc29684c6fb Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 15 Aug 2023 12:07:27 +0530 Subject: [PATCH 25/32] fix: dismiss modal when admin click on confirm button --- ...andardToDonationsMigrationGlobalBanner.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 7173cd2a70..6f7f52370f 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -85,6 +85,16 @@ public function getModalScript(): string return << { + const dismissModalAjaxRequest = () => { + wp.ajax.post({ + 'give-action': 'dismiss_notices', + 'notice_id': '$this->bannerId', + 'dismissible_type': 'user', + 'dismiss_interval': 'permanent', + '_wpnonce': '$nonce' + }); + }; + new Give.modal.GiveConfirmModal( { classes: { modalWrapper: 'give-paypal-standard-to-donations-migration-banner', @@ -112,17 +122,12 @@ classes: { }); modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { + dismissModalAjaxRequest(); window.location.assign('$linkToPayPalDonationsSettingPage'); }); }, close: () => { - wp.ajax.post({ - 'give-action': 'dismiss_notices', - 'notice_id': '$this->bannerId', - 'dismissible_type': 'user', - 'dismiss_interval': 'permanent', - '_wpnonce': '$nonce' - }); + dismissModalAjaxRequest(); } } } ).render(); From 57c00eceae1ada0d733145567b81d6439ca9234d Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 15 Aug 2023 12:09:39 +0530 Subject: [PATCH 26/32] format: improve code formatting --- .../PayPalCommerce/AdminSettingFields.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php index 2c5cf04b4b..2fb86758a8 100644 --- a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php +++ b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php @@ -152,17 +152,20 @@ public function introductionSection()

    -

    +

    + ); + ?> +

    @@ -276,13 +279,14 @@ private function printErrors(MerchantDetails $merchantDetailsRepository)

    - getAdminGuidanceNotice() + $this->getAdminGuidanceNotice() ) ?>

    From f333384c523773935feb8ddbf07316b0b5e390ca Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Wed, 16 Aug 2023 20:58:17 +0530 Subject: [PATCH 27/32] format: replace tab with space --- ...andardToDonationsMigrationGlobalBanner.php | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 6f7f52370f..799247642b 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -85,15 +85,15 @@ public function getModalScript(): string return << { - const dismissModalAjaxRequest = () => { - wp.ajax.post({ - 'give-action': 'dismiss_notices', - 'notice_id': '$this->bannerId', - 'dismissible_type': 'user', - 'dismiss_interval': 'permanent', - '_wpnonce': '$nonce' - }); - }; + const dismissModalAjaxRequest = () => { + wp.ajax.post({ + 'give-action': 'dismiss_notices', + 'notice_id': '$this->bannerId', + 'dismissible_type': 'user', + 'dismiss_interval': 'permanent', + '_wpnonce': '$nonce' + }); + }; new Give.modal.GiveConfirmModal( { classes: { @@ -114,22 +114,22 @@ classes: { closeOnBgClick: true, showCloseBtn: true, callbacks: { - open: () => { - const modal = document.querySelector('.give-modal'); - - modal.querySelector('.give-popup-close-button').addEventListener('click', () => { - window.open('https://docs.givewp.com/paypal-migration-doc', '_blank') - }); - - modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { - dismissModalAjaxRequest(); - window.location.assign('$linkToPayPalDonationsSettingPage'); - }); - }, - close: () => { - dismissModalAjaxRequest(); - } - } + open: () => { + const modal = document.querySelector('.give-modal'); + + modal.querySelector('.give-popup-close-button').addEventListener('click', () => { + window.open('https://docs.givewp.com/paypal-migration-doc', '_blank') + }); + + modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { + dismissModalAjaxRequest(); + window.location.assign('$linkToPayPalDonationsSettingPage'); + }); + }, + close: () => { + dismissModalAjaxRequest(); + } + } } ).render(); }); EOT; From db7ed14fe7878576fe5ad22399ad491afc2ce8a6 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Wed, 16 Aug 2023 21:00:05 +0530 Subject: [PATCH 28/32] fix: do not display banner if paypal donations is active --- src/PaymentGateways/PayPalCommerce/AdminSettingFields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php index 2fb86758a8..03d745e9ed 100644 --- a/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php +++ b/src/PaymentGateways/PayPalCommerce/AdminSettingFields.php @@ -495,7 +495,7 @@ private function getBanner(): string if ( give(MerchantDetail::class)->accountIsReady - && ! give_is_gateway_active(PayPalCommerce::id()) + && give_is_gateway_active(PayPalCommerce::id()) ) { return ''; } From bd5122ea07ae948d734e6161bec23ebc58dbd088 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 24 Aug 2023 00:04:03 +0530 Subject: [PATCH 29/32] format: fix typo --- .../Banners/PayPalStandardToDonationsMigrationGlobalBanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 799247642b..c1091fa671 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -58,7 +58,7 @@ public function getModalScript(): string $modalTitle = $this->getIcon() . "  $modalTitle"; $modalSubHeading = esc_html__( - 'Paypal Standard is no longer supported by PayPal', + 'PayPal Standard is no longer supported by PayPal', 'give' ); From f4093b98d63af56f93fd6c84e7794416623f0ee3 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 24 Aug 2023 00:16:06 +0530 Subject: [PATCH 30/32] format: fix typo --- src/PaymentGateways/PayPalCommerce/PayPalCommerce.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/PayPalCommerce.php b/src/PaymentGateways/PayPalCommerce/PayPalCommerce.php index e996e912fa..b36207f4c8 100644 --- a/src/PaymentGateways/PayPalCommerce/PayPalCommerce.php +++ b/src/PaymentGateways/PayPalCommerce/PayPalCommerce.php @@ -161,7 +161,7 @@ public function getOptions() 'id' => 'paypal_commerce_accept_venmo', 'type' => 'radio_inline', 'desc' => esc_html__( - 'Displays a button allowing Donors to pay with Venmo (a PayPal Company). Donations still come into your PayPal account and are subject to normal PayPal transaction fees.', + 'Displays a button allowing Donors to pay with Venmo (US-only). Donations still come into your PayPal account and are subject to normal PayPal transaction fees.', 'give' ), 'default' => 'enabled', From bcd8c061773718d15e7b90f35fc907b9daf738ee Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 24 Aug 2023 11:40:42 +0530 Subject: [PATCH 31/32] refactor: display migration banner only on give pages --- assets/src/js/plugins/give-api/api.js | 7 ++-- .../V2/DonationFormsAdminPage.php | 5 ++- ...andardToDonationsMigrationGlobalBanner.php | 35 ++++++++++++------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/assets/src/js/plugins/give-api/api.js b/assets/src/js/plugins/give-api/api.js index 4976890ed2..8ef67bad5c 100644 --- a/assets/src/js/plugins/give-api/api.js +++ b/assets/src/js/plugins/give-api/api.js @@ -187,12 +187,15 @@ const Give = { /** * Get global param * + * @unreleased Return default value of global param if param not found. * @since 2.2.4 * * @return {object} WordPress localized global param. */ - getGlobal: function() { - return ( 'undefined' === typeof give_global_vars ) ? give_vars : give_global_vars; + getGlobal: function () { + return ('undefined' === typeof give_global_vars) + ? (window.give_vars || {}) + : (window.give_global_vars || {}); }, /** diff --git a/src/DonationForms/V2/DonationFormsAdminPage.php b/src/DonationForms/V2/DonationFormsAdminPage.php index 4bfec5927e..2f62e7aacf 100644 --- a/src/DonationForms/V2/DonationFormsAdminPage.php +++ b/src/DonationForms/V2/DonationFormsAdminPage.php @@ -73,6 +73,8 @@ public function highlightAllFormsMenuItem() /** * Load scripts + * + * @unreleased Set admin script and style dependencies to display PayPal Standard to Donations Migration banner. */ public function loadScripts() { @@ -87,6 +89,7 @@ public function loadScripts() ]; EnqueueScript::make('give-admin-donation-forms', 'assets/dist/js/give-admin-donation-forms.js') + ->dependencies(['give-admin-scripts']) ->loadInFooter() ->registerTranslations() ->registerLocalizeData('GiveDonationForms', $data)->enqueue(); @@ -94,7 +97,7 @@ public function loadScripts() wp_enqueue_style( 'give-admin-ui-font', 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400..700&display=swap', - [], + ['give-admin-styles'], null ); } diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index c1091fa671..5eaa4633f9 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -31,8 +31,13 @@ public function setHook() } add_action('admin_enqueue_scripts', function () { - if (give_is_gateway_active(PayPalStandard::id())) { - wp_add_inline_script('give-admin-scripts', $this->getModalScript()); + $isGivePage = ( isset($_GET['page']) && 'give-forms' === $_GET['page'] ) + || ( isset($_GET['post_type']) && 'give_forms' === $_GET['post_type'] ); + + if ($isGivePage && give_is_gateway_active(PayPalStandard::id())) { + add_action('admin_footer', function () { + wp_print_inline_script_tag($this->getModalScript()); + }); } }); } @@ -84,15 +89,19 @@ public function getModalScript(): string ); return << { - const dismissModalAjaxRequest = () => { - wp.ajax.post({ - 'give-action': 'dismiss_notices', - 'notice_id': '$this->bannerId', - 'dismissible_type': 'user', - 'dismiss_interval': 'permanent', - '_wpnonce': '$nonce' - }); + const givePayPalStandardToDonationsMigrationGlobalBanner = () => { + const dismissModalAjaxRequest = async () => { + const formData = new FormData(); + formData.append('give-action', 'dismiss_notices'); + formData.append('notice_id', '$this->bannerId'); + formData.append('dismissible_type', 'user'); + formData.append('dismiss_interval', 'permanent'); + formData.append('_wpnonce', '$nonce'); + + await fetch(ajaxurl, { + method: 'POST', + body: formData, + }) }; new Give.modal.GiveConfirmModal( { @@ -131,7 +140,9 @@ classes: { } } } ).render(); - }); + }; + + givePayPalStandardToDonationsMigrationGlobalBanner(); EOT; } From bdde4cefea5d430682d4c51a23dc47aa1a9dcb99 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 24 Aug 2023 11:49:36 +0530 Subject: [PATCH 32/32] fix: wait for dismiss modal ajax request before exit page --- .../PayPalStandardToDonationsMigrationGlobalBanner.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php index 5eaa4633f9..cd0c0d05e1 100644 --- a/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php +++ b/src/PaymentGateways/PayPalCommerce/Banners/PayPalStandardToDonationsMigrationGlobalBanner.php @@ -130,8 +130,8 @@ classes: { window.open('https://docs.givewp.com/paypal-migration-doc', '_blank') }); - modal.querySelector('.give-popup-confirm-button').addEventListener('click', () => { - dismissModalAjaxRequest(); + modal.querySelector('.give-popup-confirm-button').addEventListener('click', async () => { + await dismissModalAjaxRequest(); window.location.assign('$linkToPayPalDonationsSettingPage'); }); },