From dda3a117cd9b720b315c595bd267364c8dc90b01 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:05:37 -0300 Subject: [PATCH 01/25] feat(ia): audience checkout/payment and donations wizard --- includes/class-newspack.php | 1 + includes/class-wizards.php | 1 + .../audience/class-audience-donations.php | 629 ++++++++++++++++++ .../components/billing-fields/index.tsx | 90 +++ .../components/money-input/index.js | 0 .../components/money-input/style.scss | 0 .../components}/nrh-settings/index.js | 18 +- .../payment-methods/additional-settings.js | 0 .../components}/payment-methods/index.js | 0 .../components}/payment-methods/stripe.js | 0 .../components}/payment-methods/style.scss | 0 .../payment-methods/woopayments.js | 0 .../components}/platform/index.js | 0 .../components}/salesforce/index.js | 18 +- .../{readerRevenue => audience}/constants.js | 0 .../views/donations/configuration}/index.tsx | 210 ++---- .../views/donations}/emails/index.js | 8 +- src/wizards/audience/views/donations/index.js | 53 ++ src/wizards/audience/views/setup/index.js | 8 +- src/wizards/audience/views/setup/payment.js | 30 + src/wizards/audience/views/setup/setup.js | 3 + .../audience/views/setup/woocommerce.js | 25 - src/wizards/index.tsx | 9 + src/wizards/readerRevenue/components/index.js | 1 - src/wizards/readerRevenue/index.js | 86 --- src/wizards/readerRevenue/views/index.js | 6 - .../setup/views/services/ReaderRevenue.js | 4 +- src/wizards/types/hooks.d.ts | 38 ++ src/wizards/types/window.d.ts | 2 +- 29 files changed, 928 insertions(+), 312 deletions(-) create mode 100644 includes/wizards/audience/class-audience-donations.php create mode 100644 src/wizards/audience/components/billing-fields/index.tsx rename src/wizards/{readerRevenue => audience}/components/money-input/index.js (100%) rename src/wizards/{readerRevenue => audience}/components/money-input/style.scss (100%) rename src/wizards/{readerRevenue/views => audience/components}/nrh-settings/index.js (87%) rename src/wizards/{readerRevenue/views => audience/components}/payment-methods/additional-settings.js (100%) rename src/wizards/{readerRevenue/views => audience/components}/payment-methods/index.js (100%) rename src/wizards/{readerRevenue/views => audience/components}/payment-methods/stripe.js (100%) rename src/wizards/{readerRevenue/views => audience/components}/payment-methods/style.scss (100%) rename src/wizards/{readerRevenue/views => audience/components}/payment-methods/woopayments.js (100%) rename src/wizards/{readerRevenue/views => audience/components}/platform/index.js (100%) rename src/wizards/{readerRevenue/views => audience/components}/salesforce/index.js (93%) rename src/wizards/{readerRevenue => audience}/constants.js (100%) rename src/wizards/{readerRevenue/views/donation => audience/views/donations/configuration}/index.tsx (62%) rename src/wizards/{readerRevenue/views => audience/views/donations}/emails/index.js (93%) create mode 100644 src/wizards/audience/views/donations/index.js create mode 100644 src/wizards/audience/views/setup/payment.js delete mode 100644 src/wizards/audience/views/setup/woocommerce.js delete mode 100644 src/wizards/readerRevenue/components/index.js delete mode 100644 src/wizards/readerRevenue/index.js delete mode 100644 src/wizards/readerRevenue/views/index.js diff --git a/includes/class-newspack.php b/includes/class-newspack.php index e626ff304e..4376527fe5 100644 --- a/includes/class-newspack.php +++ b/includes/class-newspack.php @@ -151,6 +151,7 @@ private function includes() { // Audience Wizard. include_once NEWSPACK_ABSPATH . 'includes/wizards/audience/class-audience-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/audience/class-audience-campaigns.php'; + include_once NEWSPACK_ABSPATH . 'includes/wizards/audience/class-audience-donations.php'; // Network Wizard. include_once NEWSPACK_ABSPATH . 'includes/wizards/class-network-wizard.php'; diff --git a/includes/class-wizards.php b/includes/class-wizards.php index 3482fd7ad2..b2417dc625 100644 --- a/includes/class-wizards.php +++ b/includes/class-wizards.php @@ -56,6 +56,7 @@ public static function init() { 'advertising-sponsors' => new Advertising_Sponsors(), 'audience' => new Audience_Wizard(), 'audience-campaigns' => new Audience_Campaigns(), + 'audience-donations' => new Audience_Donations(), 'listings' => new Listings_Wizard(), 'network' => new Network_Wizard(), 'newsletters' => new Newsletters_Wizard(), diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php new file mode 100644 index 0000000000..efe0126540 --- /dev/null +++ b/includes/wizards/audience/class-audience-donations.php @@ -0,0 +1,629 @@ +parent_slug, + $this->get_name(), + esc_html__( 'Donations', 'newspack-plugin' ), + $this->capability, + $this->slug, + [ $this, 'render_wizard' ] + ); + } + + /** + * Enqueue scripts and styles. + */ + public function enqueue_scripts_and_styles() { + if ( ! $this->is_wizard_page() ) { + return; + } + + parent::enqueue_scripts_and_styles(); + + wp_enqueue_script( 'newspack-wizards' ); + + \wp_localize_script( + 'newspack-wizards', + 'newspackAudienceDonations', + [ + 'emails' => Emails::get_emails( [ Reader_Revenue_Emails::EMAIL_TYPES['RECEIPT'] ], false ), + 'email_cpt' => Emails::POST_TYPE, + 'salesforce_redirect_url' => Salesforce::get_redirect_url(), + 'can_use_name_your_price' => Donations::can_use_name_your_price(), + ] + ); + } + + /** + * Prevent rendering of Donate block if Reader Revenue platform is set to 'other. + * + * @param string $block_content The block content about to be rendered. + * @param array $block The data of the block about to be rendered. + */ + public static function prevent_rendering_donate_block( $block_content, $block ) { + if ( + isset( $block['blockName'] ) + && 'newspack-blocks/donate' === $block['blockName'] + && Donations::is_platform_other() + ) { + return ''; + } + return $block_content; + } + + /** + * Register the endpoints needed for the wizard screens. + */ + public function register_api_endpoints() { + // Get all data required to render the Wizard. + \register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug, + [ + 'methods' => \WP_REST_Server::READABLE, + 'callback' => [ $this, 'api_fetch' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + ] + ); + // Save basic data about reader revenue platform. + \register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug, + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'platform' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_platform' ], + ], + 'nrh_organization_id' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + 'nrh_custom_domain' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + 'nrh_salesforce_campaign_id' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + 'donor_landing_page' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + ], + ] + ); + + // Save location info. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/location/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_location' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'countrystate' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + 'address1' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + 'address2' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + 'city' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + 'postcode' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + 'currency' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + ], + ] + ); + + // Save Stripe info. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/stripe/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_stripe_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'activate' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'enabled' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'location_code' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + ], + ] + ); + + // Save WooPayments info. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/woopayments/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_woopayments_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'activate' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'enabled' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + ], + ] + ); + + // Save additional settings info. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/settings/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_additional_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'fee_multiplier' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => function ( $value ) { + if ( (float) $value > 10 ) { + return new WP_Error( + 'newspack_invalid_param', + __( 'Fee multiplier must be smaller than 10.', 'newspack' ) + ); + } + return true; + }, + ], + 'fee_static' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + 'allow_covering_fees' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'allow_covering_fees_default' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'allow_covering_fees_label' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + 'location_code' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + ], + ] + ); + + // Update Donations settings. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/donations/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_donation_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'amounts' => [ + 'required' => false, + ], + 'tiered' => [ + 'required' => false, + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'disabledFrequencies' => [ + 'required' => false, + ], + 'platform' => [ + 'required' => false, + 'sanitize_callback' => 'sanitize_text_field', + ], + ], + ] + ); + + // Save Salesforce settings. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/salesforce/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_salesforce_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'client_id' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + 'client_secret' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + 'access_token' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + 'refresh_token' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + ], + ] + ); + + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/donations/', + [ + 'methods' => \WP_REST_Server::READABLE, + 'callback' => [ $this, 'api_get_donation_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + ] + ); + } + + /** + * Get all Wizard Data + * + * @return WP_REST_Response containing ad units info. + */ + public function api_fetch() { + return \rest_ensure_response( $this->fetch_all_data() ); + } + + /** + * Save top-level data. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Boolean success. + */ + public function api_update( $request ) { + $params = $request->get_params(); + Donations::set_platform_slug( $params['platform'] ); + + // Update NRH settings. + if ( Donations::is_platform_nrh() ) { + NRH::update_settings( $params ); + } + + // Ensure that any Reader Revenue settings changed while the platform wasn't WC are persisted to WC products. + if ( Donations::is_platform_wc() ) { + Donations::update_donation_product( Donations::get_donation_settings() ); + } + + return \rest_ensure_response( $this->fetch_all_data() ); + } + + /** + * Save location info. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Boolean success. + */ + public function api_update_location( $request ) { + $required_plugins_installed = $this->check_required_plugins_installed(); + if ( is_wp_error( $required_plugins_installed ) ) { + return rest_ensure_response( $required_plugins_installed ); + } + $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); + + $params = $request->get_params(); + + $defaults = [ + 'countrystate' => '', + 'address1' => '', + 'address2' => '', + 'city' => '', + 'postcode' => '', + 'currency' => '', + ]; + + $args = wp_parse_args( $params, $defaults ); + $wc_configuration_manager->update_location( $args ); + + // @todo when is the best time to do this? + $wc_configuration_manager->set_smart_defaults(); + + return \rest_ensure_response( $this->fetch_all_data() ); + } + + /** + * Handler for setting Stripe settings. + * + * @param object $settings Stripe settings. + * @return WP_REST_Response with the latest settings. + */ + public function update_stripe_settings( $settings ) { + if ( ! empty( $settings['activate'] ) ) { + // If activating the Stripe Gateway plugin, let's enable it. + $settings = [ 'enabled' => true ]; + } + $result = Stripe_Connection::update_stripe_data( $settings ); + if ( \is_wp_error( $result ) ) { + return $result; + } + + return $this->fetch_all_data(); + } + + /** + * Handler for setting additional settings. + * + * @param object $settings Settings. + * @return WP_REST_Response with the latest settings. + */ + public function update_additional_settings( $settings ) { + if ( isset( $settings['allow_covering_fees'] ) ) { + update_option( 'newspack_donations_allow_covering_fees', $settings['allow_covering_fees'] ); + } + if ( isset( $settings['allow_covering_fees_default'] ) ) { + update_option( 'newspack_donations_allow_covering_fees_default', $settings['allow_covering_fees_default'] ); + } + + if ( isset( $settings['allow_covering_fees_label'] ) ) { + update_option( 'newspack_donations_allow_covering_fees_label', $settings['allow_covering_fees_label'] ); + } + if ( isset( $settings['fee_multiplier'] ) ) { + update_option( 'newspack_blocks_donate_fee_multiplier', $settings['fee_multiplier'] ); + } + if ( isset( $settings['fee_static'] ) ) { + update_option( 'newspack_blocks_donate_fee_static', $settings['fee_static'] ); + } + return $this->fetch_all_data(); + } + + /** + * Save Stripe settings. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Response. + */ + public function api_update_stripe_settings( $request ) { + $params = $request->get_params(); + $result = $this->update_stripe_settings( $params ); + return \rest_ensure_response( $result ); + } + + /** + * Save WooPayments settings. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Response. + */ + public function api_update_woopayments_settings( $request ) { + $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); + + $params = $request->get_params(); + $result = $wc_configuration_manager->update_wc_woopayments_settings( $params ); + return \rest_ensure_response( $result ); + } + + /** + * Save additional payment method settings (e.g. transaction fees). + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Response. + */ + public function api_update_additional_settings( $request ) { + $params = $request->get_params(); + $result = $this->update_additional_settings( $params ); + return \rest_ensure_response( $result ); + } + + /** + * Handler for setting the donation settings. + * + * @param object $settings Donation settings. + * @return WP_REST_Response with the latest settings. + */ + public function update_donation_settings( $settings ) { + $donations_response = Donations::set_donation_settings( $settings ); + if ( is_wp_error( $donations_response ) ) { + return rest_ensure_response( $donations_response ); + } + return \rest_ensure_response( $this->fetch_all_data() ); + } + + /** + * API endpoint for setting the donation settings. + * + * @param WP_REST_Request $request Request containing settings. + * @return WP_REST_Response with the latest settings. + */ + public function api_update_donation_settings( $request ) { + return $this->update_donation_settings( $request->get_params() ); + } + + /** + * API endpoint for setting Salesforce settings. + * + * @param WP_REST_Request $request Request containing settings. + * @return WP_REST_Response with the latest settings. + */ + public function api_update_salesforce_settings( $request ) { + $salesforce_response = Salesforce::set_salesforce_settings( $request->get_params() ); + if ( is_wp_error( $salesforce_response ) ) { + return rest_ensure_response( $salesforce_response ); + } + return \rest_ensure_response( $this->fetch_all_data() ); + } + + /** + * Fetch all data needed to render the Wizard + * + * @return Array + */ + public function fetch_all_data() { + $platform = Donations::get_platform_slug(); + $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); + $wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' ); + $stripe_data = Stripe_Connection::get_stripe_data(); + + $billing_fields = []; + if ( $wc_installed && Donations::is_platform_wc() ) { + $checkout = new \WC_Checkout(); + $fields = $checkout->get_checkout_fields(); + if ( ! empty( $fields['billing'] ) ) { + $billing_fields = $fields['billing']; + } + } + + $args = [ + 'country_state_fields' => newspack_get_countries(), + 'currency_fields' => newspack_get_currencies_options(), + 'location_data' => [], + 'payment_gateways' => [ + 'stripe' => $stripe_data, + 'woopayments' => $wc_configuration_manager->woopayments_data(), + ], + 'additional_settings' => [ + 'allow_covering_fees' => get_option( 'newspack_donations_allow_covering_fees', true ), + 'allow_covering_fees_default' => get_option( 'newspack_donations_allow_covering_fees_default', false ), + 'allow_covering_fees_label' => get_option( 'newspack_donations_allow_covering_fees_label', '' ), + 'fee_multiplier' => get_option( 'newspack_blocks_donate_fee_multiplier', '2.9' ), + 'fee_static' => get_option( 'newspack_blocks_donate_fee_static', '0.3' ), + ], + 'donation_data' => Donations::get_donation_settings(), + 'donation_page' => Donations::get_donation_page_info(), + 'available_billing_fields' => $billing_fields, + 'salesforce_settings' => [], + 'platform_data' => [ + 'platform' => $platform, + ], + 'is_ssl' => is_ssl(), + 'errors' => [], + ]; + if ( 'wc' === $platform ) { + $plugin_status = true; + $managed_plugins = Plugin_Manager::get_managed_plugins(); + $required_plugins = [ + 'woocommerce', + 'woocommerce-subscriptions', + ]; + foreach ( $required_plugins as $required_plugin ) { + if ( 'active' !== $managed_plugins[ $required_plugin ]['Status'] ) { + $plugin_status = false; + } + } + $args = wp_parse_args( + [ + 'salesforce_settings' => Salesforce::get_salesforce_settings(), + 'plugin_status' => $plugin_status, + ], + $args + ); + } elseif ( Donations::is_platform_nrh() ) { + $nrh_config = NRH::get_settings(); + $args['platform_data'] = wp_parse_args( $nrh_config, $args['platform_data'] ); + } + return $args; + } + + /** + * API endpoint for getting donation settings. + * + * @return WP_REST_Response containing info. + */ + public function api_get_donation_settings() { + if ( Donations::is_platform_wc() ) { + $required_plugins_installed = $this->check_required_plugins_installed(); + if ( is_wp_error( $required_plugins_installed ) ) { + return rest_ensure_response( $required_plugins_installed ); + } + } + + return rest_ensure_response( Donations::get_donation_settings() ); + } + + /** + * Check whether WooCommerce is installed and active. + * + * @return bool | WP_Error True on success, WP_Error on failure. + */ + protected function check_required_plugins_installed() { + if ( ! function_exists( 'WC' ) ) { + return new WP_Error( + 'newspack_missing_required_plugin', + esc_html__( 'The WooCommerce plugin is not installed and activated. Install and/or activate it to access this feature.', 'newspack' ), + [ + 'status' => 400, + 'level' => 'fatal', + ] + ); + } + + return true; + } + + /** + * Validate platform ID. + * + * @param mixed $value A param value. + * @return bool + */ + public function api_validate_platform( $value ) { + return in_array( $value, [ 'nrh', 'wc', 'other' ] ); + } +} diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx new file mode 100644 index 0000000000..e4bc900e88 --- /dev/null +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -0,0 +1,90 @@ +/** + * WordPress dependencies. + */ +import { useDispatch } from '@wordpress/data'; +import { __ } from '@wordpress/i18n'; +import { CheckboxControl } from '@wordpress/components'; + +/** + * Internal dependencies. + */ +import { + Button, + Card, + Grid, + SectionHeader, + Wizard, +} from '../../../../components/src'; + +const BillingFields = () => { + const wizardData = Wizard.useWizardData( 'reader-revenue' ) as ReaderRevenueWizardData; + const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); + + if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { + return null; + } + + const changeHandler = ( path: string[] ) => ( value: any ) => + updateWizardSettings( { + slug: 'newspack-reader-revenue-wizard', + path: [ 'donation_data', ...path ], + value, + } ); + + const onSave = () => + saveWizardSettings( { + slug: 'newspack-reader-revenue-wizard', + section: 'donations', + payloadPath: [ 'donation_data' ], + } ); + + const availableFields = wizardData.available_billing_fields; + if ( ! availableFields || ! Object.keys( availableFields ).length ) { + return null; + } + + const billingFields = wizardData.donation_data.billingFields.length + ? wizardData.donation_data.billingFields + : Object.keys( availableFields ); + + return ( + <> + + + + + { Object.keys( availableFields ).map( fieldKey => ( + { + let newFields = [ ...billingFields ]; + if ( billingFields.includes( fieldKey ) ) { + newFields = newFields.filter( field => field !== fieldKey ); + } else { + newFields = [ ...newFields, fieldKey ]; + } + changeHandler( [ 'billingFields' ] )( newFields ); + } } + /> + ) ) } + +
+ +
+ + ); +}; + +export default BillingFields; diff --git a/src/wizards/readerRevenue/components/money-input/index.js b/src/wizards/audience/components/money-input/index.js similarity index 100% rename from src/wizards/readerRevenue/components/money-input/index.js rename to src/wizards/audience/components/money-input/index.js diff --git a/src/wizards/readerRevenue/components/money-input/style.scss b/src/wizards/audience/components/money-input/style.scss similarity index 100% rename from src/wizards/readerRevenue/components/money-input/style.scss rename to src/wizards/audience/components/money-input/style.scss diff --git a/src/wizards/readerRevenue/views/nrh-settings/index.js b/src/wizards/audience/components/nrh-settings/index.js similarity index 87% rename from src/wizards/readerRevenue/views/nrh-settings/index.js rename to src/wizards/audience/components/nrh-settings/index.js index 8ebeab10dd..d2ed7e624d 100644 --- a/src/wizards/readerRevenue/views/nrh-settings/index.js +++ b/src/wizards/audience/components/nrh-settings/index.js @@ -48,8 +48,8 @@ const NRHSettings = () => { { __( 'Save Settings' ) } @@ -59,20 +59,20 @@ const NRHSettings = () => {
changeHandler( 'nrh_organization_id', value ) } /> changeHandler( 'nrh_custom_domain', value ) } /> changeHandler( 'nrh_salesforce_campaign_id', value ) } @@ -82,7 +82,7 @@ const NRHSettings = () => { { settings.hasOwnProperty( 'donor_landing_page' ) && (

-

{ __( 'Donor Landing Page', 'newspack' ) }

+

{ __( 'Donor Landing Page', 'newspack-plugin' ) }

{ __( 'Set a page on your site as a donor landing page. Once a reader donates and lands on this page, they will be considered a donor.', @@ -90,7 +90,7 @@ const NRHSettings = () => { ) }

{ return changeHandler( 'donor_landing_page', item ); } } postTypes={ [ { slug: 'page', label: 'Page' } ] } - postTypeLabel={ __( 'page', 'newspack' ) } - postTypeLabelPlural={ __( 'pages', 'newspack' ) } + postTypeLabel={ __( 'page', 'newspack-plugin' ) } + postTypeLabelPlural={ __( 'pages', 'newspack-plugin' ) } selectedItems={ selectedPage ? [ selectedPage ] : [] } />
diff --git a/src/wizards/readerRevenue/views/payment-methods/additional-settings.js b/src/wizards/audience/components/payment-methods/additional-settings.js similarity index 100% rename from src/wizards/readerRevenue/views/payment-methods/additional-settings.js rename to src/wizards/audience/components/payment-methods/additional-settings.js diff --git a/src/wizards/readerRevenue/views/payment-methods/index.js b/src/wizards/audience/components/payment-methods/index.js similarity index 100% rename from src/wizards/readerRevenue/views/payment-methods/index.js rename to src/wizards/audience/components/payment-methods/index.js diff --git a/src/wizards/readerRevenue/views/payment-methods/stripe.js b/src/wizards/audience/components/payment-methods/stripe.js similarity index 100% rename from src/wizards/readerRevenue/views/payment-methods/stripe.js rename to src/wizards/audience/components/payment-methods/stripe.js diff --git a/src/wizards/readerRevenue/views/payment-methods/style.scss b/src/wizards/audience/components/payment-methods/style.scss similarity index 100% rename from src/wizards/readerRevenue/views/payment-methods/style.scss rename to src/wizards/audience/components/payment-methods/style.scss diff --git a/src/wizards/readerRevenue/views/payment-methods/woopayments.js b/src/wizards/audience/components/payment-methods/woopayments.js similarity index 100% rename from src/wizards/readerRevenue/views/payment-methods/woopayments.js rename to src/wizards/audience/components/payment-methods/woopayments.js diff --git a/src/wizards/readerRevenue/views/platform/index.js b/src/wizards/audience/components/platform/index.js similarity index 100% rename from src/wizards/readerRevenue/views/platform/index.js rename to src/wizards/audience/components/platform/index.js diff --git a/src/wizards/readerRevenue/views/salesforce/index.js b/src/wizards/audience/components/salesforce/index.js similarity index 93% rename from src/wizards/readerRevenue/views/salesforce/index.js rename to src/wizards/audience/components/salesforce/index.js index 9712b61278..761b473b1c 100644 --- a/src/wizards/readerRevenue/views/salesforce/index.js +++ b/src/wizards/audience/components/salesforce/index.js @@ -19,7 +19,7 @@ import { PluginSettings, Notice, Wizard } from '../../../../components/src'; import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; const Salesforce = () => { - const { salesforce_redirect_url: redirectUrl } = window?.newspack_reader_revenue || {}; + const { salesforce_redirect_url: redirectUrl } = window?.newspackAudienceDonations || {}; const [ hasCopied, setHasCopied ] = useState( false ); const { salesforce_settings: salesforceData = {} } = Wizard.useWizardData( 'reader-revenue' ); const [ isConnected, setIsConnected ] = useState( salesforceData.refresh_token ); @@ -73,7 +73,7 @@ const Salesforce = () => { setError( __( 'We couldn’t establish a connection to Salesforce. Please verify your Consumer Key and Secret and try connecting again.', - 'newspack' + 'newspack-plugin' ) ); } @@ -143,21 +143,21 @@ const Salesforce = () => { } } } pluginSlug="newspack/salesforce" - title={ __( 'Salesforce Settings', 'newspack' ) } + title={ __( 'Salesforce Settings', 'newspack-plugin' ) } description={ () => ( <> { error && } { isConnected && ! error && ( ) } { __( 'Establish a connection to sync WooCommerce order data to Salesforce. To connect with Salesforce, create or choose a Connected App for this site in your Salesforce dashboard. Make sure to paste the full URL for this page (', - 'newspack' + 'newspack-plugin' ) } { onFinishCopy={ () => setHasCopied( false ) } > { hasCopied - ? __( 'copied to clipboard!', 'newspack' ) - : __( 'copy to clipboard', 'newspack' ) } + ? __( 'copied to clipboard!', 'newspack-plugin' ) + : __( 'copy to clipboard', 'newspack-plugin' ) } { __( ') into the “Callback URL” field in the Connected App’s settings. ', - 'newspack' + 'newspack-plugin' ) } - { __( 'Learn how to create a Connected App', 'newspack' ) } + { __( 'Learn how to create a Connected App', 'newspack-plugin' ) } ) } diff --git a/src/wizards/readerRevenue/constants.js b/src/wizards/audience/constants.js similarity index 100% rename from src/wizards/readerRevenue/constants.js rename to src/wizards/audience/constants.js diff --git a/src/wizards/readerRevenue/views/donation/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx similarity index 62% rename from src/wizards/readerRevenue/views/donation/index.tsx rename to src/wizards/audience/views/donations/configuration/index.tsx index 7a49c143f3..19a3af95a1 100644 --- a/src/wizards/readerRevenue/views/donation/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -3,14 +3,13 @@ */ import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; -import { ToggleControl, CheckboxControl } from '@wordpress/components'; +import { ToggleControl } from '@wordpress/components'; /** * Internal dependencies. */ -import { MoneyInput } from '../../components'; +import MoneyInput from '../../../components/money-input'; import { - ActionCard, Button, Card, Grid, @@ -19,8 +18,9 @@ import { SelectControl, TextControl, Wizard, -} from '../../../../components/src'; -import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; +} from '../../../../../components/src'; +import WizardsTab from '../../../../wizards-tab'; +import { READER_REVENUE_WIZARD_SLUG } from '../../../constants'; type FrequencySlug = 'once' | 'month' | 'year'; @@ -42,43 +42,8 @@ const FREQUENCIES: { }; const FREQUENCY_SLUGS: FrequencySlug[] = Object.keys( FREQUENCIES ) as FrequencySlug[]; -type WizardData = { - donation_data: - | { errors: { [ key: string ]: string[] } } - | { - amounts: { - [ Key in FrequencySlug as string ]: [ number, number, number, number ]; - }; - disabledFrequencies: { - [ Key in FrequencySlug as string ]: boolean; - }; - currencySymbol: string; - tiered: boolean; - minimumDonation: string; - billingFields: string[]; - }; - platform_data: { - platform: string; - }; - donation_page: { - editUrl: string; - status: string; - }; - available_billing_fields: { - [ key: string ]: { - autocomplete: string; - class: string[]; - label: string; - priority: number; - required: boolean; - type: string; - validate: string[]; - }; - }; -}; - export const DonationAmounts = () => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ) as WizardData; + const wizardData = Wizard.useWizardData( 'reader-revenue' ) as ReaderRevenueWizardData; const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { @@ -104,7 +69,7 @@ export const DonationAmounts = () => { const minimumDonationFloat = parseFloat( minimumDonation ); // Whether we can use the Name Your Price extension. If not, layout is forced to Tiered. - const canUseNameYourPrice = window.newspack_reader_revenue?.can_use_name_your_price; + const canUseNameYourPrice = window.newspackAudienceDonations?.can_use_name_your_price; return ( <> @@ -265,67 +230,8 @@ export const DonationAmounts = () => { ); }; -const BillingFields = () => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ) as WizardData; - const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); - - if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { - return null; - } - - const changeHandler = ( path: string[] ) => ( value: any ) => - updateWizardSettings( { - slug: 'newspack-reader-revenue-wizard', - path: [ 'donation_data', ...path ], - value, - } ); - - const availableFields = wizardData.available_billing_fields; - if ( ! availableFields || ! Object.keys( availableFields ).length ) { - return null; - } - - const billingFields = wizardData.donation_data.billingFields.length - ? wizardData.donation_data.billingFields - : Object.keys( availableFields ); - - return ( - <> - - - - - { Object.keys( availableFields ).map( fieldKey => ( - { - let newFields = [ ...billingFields ]; - if ( billingFields.includes( fieldKey ) ) { - newFields = newFields.filter( field => field !== fieldKey ); - } else { - newFields = [ ...newFields, fieldKey ]; - } - changeHandler( [ 'billingFields' ] )( newFields ); - } } - /> - ) ) } - - - ); -}; - const Donation = () => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ) as WizardData; + const wizardData = Wizard.useWizardData( 'reader-revenue' ) as ReaderRevenueWizardData; const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSaveDonationSettings = () => saveWizardSettings( { @@ -334,71 +240,45 @@ const Donation = () => { payloadPath: [ 'donation_data' ], auxData: { saveDonationProduct: true }, } ); - const onSaveBillingFields = () => - saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, - section: 'donations', - payloadPath: [ 'donation_data' ], - } ); return ( - <> - - { __( 'Save Donation Settings', 'newspack-plugin' ) } - - } - > - { wizardData.donation_page && ( - <> - - - - - { 'publish' === wizardData.donation_page.status ? ( - - ) : ( - - ) } - - ) } - - - - { __( 'Save Modal Checkout Settings', 'newspack-plugin' ) } - - } - > - - - + + { wizardData.donation_page && ( + <> + + + + + { 'publish' === wizardData.donation_page.status ? ( + + ) : ( + + ) } + + ) } + +
+ +
+
); }; diff --git a/src/wizards/readerRevenue/views/emails/index.js b/src/wizards/audience/views/donations/emails/index.js similarity index 93% rename from src/wizards/readerRevenue/views/emails/index.js rename to src/wizards/audience/views/donations/emails/index.js index e64cb745ae..b9cfed3303 100644 --- a/src/wizards/readerRevenue/views/emails/index.js +++ b/src/wizards/audience/views/donations/emails/index.js @@ -1,4 +1,4 @@ -/* globals newspack_reader_revenue*/ +/* globals newspackAudienceDonations */ /** * WordPress dependencies @@ -15,10 +15,10 @@ import values from 'lodash/values'; /** * Internal dependencies */ -import { PluginInstaller, ActionCard, Notice } from '../../../../components/src'; +import { PluginInstaller, ActionCard, Notice } from '../../../../../components/src'; -const EMAILS = values( newspack_reader_revenue.emails ); -const postType = newspack_reader_revenue.email_cpt; +const EMAILS = values( newspackAudienceDonations.emails ); +const postType = newspackAudienceDonations.email_cpt; const Emails = () => { const [ pluginsReady, setPluginsReady ] = useState( null ); diff --git a/src/wizards/audience/views/donations/index.js b/src/wizards/audience/views/donations/index.js new file mode 100644 index 0000000000..86de8f4f4e --- /dev/null +++ b/src/wizards/audience/views/donations/index.js @@ -0,0 +1,53 @@ +import '../../../../shared/js/public-path'; + +/** + * External dependencies. + */ +import values from 'lodash/values'; + +/** + * WordPress dependencies. + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies. + */ +import { Wizard, Notice, withWizard } from '../../../../components/src'; +import Configuration from './configuration'; +import Emails from './emails'; +import { READER_REVENUE_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants'; + +const AudienceDonations = () => { + const { platform_data, donation_data } = Wizard.useWizardData( 'reader-revenue' ); + const usedPlatform = platform_data?.platform; + const sections = [ + { + label: __( 'Configuration', 'newspack-plugin' ), + path: '/configuration', + render: Configuration, + isHidden: usedPlatform === OTHER, + }, + { + label: __( 'Emails', 'newspack-plugin' ), + path: '/emails', + render: Emails, + isHidden: usedPlatform !== NEWSPACK, + }, + ]; + return ( + + values( donation_data?.errors ).map( ( error, i ) => ( + + ) ) + } + requiredPlugins={ [ 'newspack-blocks' ] } + /> + ); +}; + +export default withWizard( AudienceDonations ); diff --git a/src/wizards/audience/views/setup/index.js b/src/wizards/audience/views/setup/index.js index ac41ffff83..48d4eac12c 100644 --- a/src/wizards/audience/views/setup/index.js +++ b/src/wizards/audience/views/setup/index.js @@ -19,7 +19,7 @@ import { withWizard } from '../../../../components/src'; import Router from '../../../../components/src/proxied-imports/router'; import ContentGating from './content-gating'; import TransactionalEmails from './transactional-emails'; -import WooCommerce from './woocommerce'; +import Payment from './payment'; const { HashRouter, Redirect, Route, Switch } = Router; @@ -90,7 +90,7 @@ function AudienceWizard( { pluginRequirements, wizardApiFetch } ) { }, { label: __( 'Checkout & Payment', 'newspack-plugin' ), - path: '/woocommerce', + path: '/payment', }, ]; tabs = tabs.filter( tab => tab ); @@ -139,9 +139,9 @@ function AudienceWizard( { pluginRequirements, wizardApiFetch } ) { ) } /> ( - + ) } /> + + { data?.platform_data?.platform === 'wc' && } + { data?.platform_data?.platform === 'nrh' && } +
+ + + ); +} ); diff --git a/src/wizards/audience/views/setup/setup.js b/src/wizards/audience/views/setup/setup.js index b36430d6ad..e6efefa215 100644 --- a/src/wizards/audience/views/setup/setup.js +++ b/src/wizards/audience/views/setup/setup.js @@ -28,6 +28,7 @@ import MetadataFields from '../../components/metadata-fields'; import Mailchimp from '../../components/mailchimp'; import { HANDOFF_KEY } from '../../../../components/src/consts'; import SortableNewsletterListControl from '../../../../components/src/sortable-newsletter-list-control'; +import Salesforce from '../../components/salesforce'; export default withWizardScreen( ( { config, fetchConfig, updateConfig, saveConfig, prerequisites, espSyncErrors, error, inFlight } ) => { const [ allReady, setAllReady ] = useState( false ); @@ -375,6 +376,8 @@ export default withWizardScreen( ( { config, fetchConfig, updateConfig, saveConf ) }
+
+ ) } diff --git a/src/wizards/audience/views/setup/woocommerce.js b/src/wizards/audience/views/setup/woocommerce.js deleted file mode 100644 index 294110c3ce..0000000000 --- a/src/wizards/audience/views/setup/woocommerce.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies. - */ -import { withWizardScreen } from '../../../../components/src'; -import WizardsTab from '../../../wizards-tab'; - -export default withWizardScreen( function () { - return ( - -

In progress.

- {/* TODO: Add Platform from `/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/`*/} - {/* TODO: Add Modal Checkout Billing Fields Settings from `/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations`*/} - {/* TODO: Add Stripe Setup from `/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/stripe-setup`*/} - {/* TODO: Add Saleforce Settings from `/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/salesforce`*/} -
- ); -} ); diff --git a/src/wizards/index.tsx b/src/wizards/index.tsx index f33c8dce93..1d6428594b 100644 --- a/src/wizards/index.tsx +++ b/src/wizards/index.tsx @@ -64,6 +64,15 @@ const components: Record< string, any > = { ) ), }, + 'newspack-audience-donations': { + label: __( 'Audience Donations', 'newspack-plugin' ), + component: lazy( + () => + import( + /* webpackChunkName: "audience-wizards" */ './audience/views/donations' + ) + ), + }, } as const; const AdminPageLoader = ( { label }: { label: string } ) => { diff --git a/src/wizards/readerRevenue/components/index.js b/src/wizards/readerRevenue/components/index.js deleted file mode 100644 index cea2a876da..0000000000 --- a/src/wizards/readerRevenue/components/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as MoneyInput } from './money-input'; diff --git a/src/wizards/readerRevenue/index.js b/src/wizards/readerRevenue/index.js deleted file mode 100644 index 6ecd543329..0000000000 --- a/src/wizards/readerRevenue/index.js +++ /dev/null @@ -1,86 +0,0 @@ -import '../../shared/js/public-path'; - -/** - * External dependencies. - */ -import values from 'lodash/values'; - -/** - * WordPress dependencies. - */ -import { render, createElement } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies. - */ -import { Wizard, Notice } from '../../components/src'; -import * as Views from './views'; -import { READER_REVENUE_WIZARD_SLUG, NEWSPACK, NRH, OTHER } from './constants'; - -const ReaderRevenueWizard = () => { - const { platform_data, plugin_status, donation_data } = Wizard.useWizardData( 'reader-revenue' ); - const usedPlatform = platform_data?.platform; - const platformSection = { - label: __( 'Platform', 'newspack' ), - path: '/', - render: Views.Platform, - }; - - let sections = [ - { - label: __( 'Donations', 'newspack' ), - path: '/donations', - render: Views.Donation, - isHidden: usedPlatform === OTHER, - }, - { - label: __( 'Payment Methods', 'newspack' ), - path: '/payment-methods', - activeTabPaths: [ '/payment-methods' ], - render: Views.StripeSetup, - isHidden: usedPlatform !== NEWSPACK, - }, - { - label: __( 'Emails', 'newspack' ), - path: '/emails', - render: Views.Emails, - isHidden: usedPlatform !== NEWSPACK, - }, - { - label: __( 'Salesforce', 'newspack' ), - path: '/salesforce', - render: Views.Salesforce, - isHidden: usedPlatform !== NEWSPACK, - }, - { - label: __( 'News Revenue Hub Settings', 'newspack' ), - path: '/settings', - render: Views.NRHSettings, - isHidden: usedPlatform !== NRH, - }, - platformSection, - ]; - if ( usedPlatform === NEWSPACK && ! plugin_status ) { - sections = [ platformSection ]; - } - return ( - - values( donation_data?.errors ).map( ( error, i ) => ( - - ) ) - } - requiredPlugins={ [ 'newspack-blocks' ] } - /> - ); -}; - -render( - createElement( ReaderRevenueWizard ), - document.getElementById( 'newspack-reader-revenue-wizard' ) -); diff --git a/src/wizards/readerRevenue/views/index.js b/src/wizards/readerRevenue/views/index.js deleted file mode 100644 index c92ff44a8c..0000000000 --- a/src/wizards/readerRevenue/views/index.js +++ /dev/null @@ -1,6 +0,0 @@ -export { default as Donation } from './donation'; -export { default as NRHSettings } from './nrh-settings'; -export { default as Platform } from './platform'; -export { default as StripeSetup } from './payment-methods'; -export { default as Emails } from './emails'; -export { default as Salesforce } from './salesforce'; diff --git a/src/wizards/setup/views/services/ReaderRevenue.js b/src/wizards/setup/views/services/ReaderRevenue.js index dc48df0436..b6c1b46639 100644 --- a/src/wizards/setup/views/services/ReaderRevenue.js +++ b/src/wizards/setup/views/services/ReaderRevenue.js @@ -12,8 +12,8 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import Platform from '../../../readerRevenue/views/platform'; -import { DonationAmounts } from '../../../readerRevenue/views/donation'; +import Platform from '../../../audience/components/platform'; +import { DonationAmounts } from '../../../audience/views/donations/configuration'; import { Wizard } from '../../../../components/src'; const ReaderRevenue = ( { className } ) => { diff --git a/src/wizards/types/hooks.d.ts b/src/wizards/types/hooks.d.ts index b34eb5f484..1528554702 100644 --- a/src/wizards/types/hooks.d.ts +++ b/src/wizards/types/hooks.d.ts @@ -56,3 +56,41 @@ type WizardData = { type WizardSelector = { getWizardData: ( slug: string ) => WizardData; }; + +/** + * Reader Revenue Wizard Data + */ +type ReaderRevenueWizardData = { + donation_data: + | { errors: { [ key: string ]: string[] } } + | { + amounts: { + [ Key in FrequencySlug as string ]: [ number, number, number, number ]; + }; + disabledFrequencies: { + [ Key in FrequencySlug as string ]: boolean; + }; + currencySymbol: string; + tiered: boolean; + minimumDonation: string; + billingFields: string[]; + }; + platform_data: { + platform: string; + }; + donation_page: { + editUrl: string; + status: string; + }; + available_billing_fields: { + [ key: string ]: { + autocomplete: string; + class: string[]; + label: string; + priority: number; + required: boolean; + type: string; + validate: string[]; + }; + }; +}; \ No newline at end of file diff --git a/src/wizards/types/window.d.ts b/src/wizards/types/window.d.ts index 12f67b0897..c7df99e387 100644 --- a/src/wizards/types/window.d.ts +++ b/src/wizards/types/window.d.ts @@ -45,7 +45,7 @@ declare global { name: string; } >; }; - newspack_reader_revenue: { + newspackAudienceDonations: { can_use_name_your_price: boolean; }; } From 832b88d21257500b9dffcf778a11bfb51e493d08 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:17:39 -0300 Subject: [PATCH 02/25] feat: improve billing fields section integration --- .../components/billing-fields/index.tsx | 18 ++++++++---------- src/wizards/audience/views/setup/payment.js | 3 +-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx index e4bc900e88..1174b82c2d 100644 --- a/src/wizards/audience/components/billing-fields/index.tsx +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -49,16 +49,14 @@ const BillingFields = () => { return ( <> - - - + { Object.keys( availableFields ).map( fieldKey => ( { data?.platform_data?.platform === 'wc' && } + { data?.platform_data?.platform === 'wc' && } { data?.platform_data?.platform === 'nrh' && } -
- ); } ); From 8419fafb47e81be34e34d5be4b0021faa1ef6308 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:18:03 -0300 Subject: [PATCH 03/25] fix: remove "Emails" and start "Revenue " tab --- .../audience/class-audience-donations.php | 2 - .../audience/views/donations/emails/index.js | 112 ------------------ src/wizards/audience/views/donations/index.js | 7 +- 3 files changed, 3 insertions(+), 118 deletions(-) delete mode 100644 src/wizards/audience/views/donations/emails/index.js diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index efe0126540..9023ccd745 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -75,8 +75,6 @@ public function enqueue_scripts_and_styles() { 'newspack-wizards', 'newspackAudienceDonations', [ - 'emails' => Emails::get_emails( [ Reader_Revenue_Emails::EMAIL_TYPES['RECEIPT'] ], false ), - 'email_cpt' => Emails::POST_TYPE, 'salesforce_redirect_url' => Salesforce::get_redirect_url(), 'can_use_name_your_price' => Donations::can_use_name_your_price(), ] diff --git a/src/wizards/audience/views/donations/emails/index.js b/src/wizards/audience/views/donations/emails/index.js deleted file mode 100644 index b9cfed3303..0000000000 --- a/src/wizards/audience/views/donations/emails/index.js +++ /dev/null @@ -1,112 +0,0 @@ -/* globals newspackAudienceDonations */ - -/** - * WordPress dependencies - */ -import apiFetch from '@wordpress/api-fetch'; -import { useState } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; - -/** - * External dependencies - */ -import values from 'lodash/values'; - -/** - * Internal dependencies - */ -import { PluginInstaller, ActionCard, Notice } from '../../../../../components/src'; - -const EMAILS = values( newspackAudienceDonations.emails ); -const postType = newspackAudienceDonations.email_cpt; - -const Emails = () => { - const [ pluginsReady, setPluginsReady ] = useState( null ); - const [ error, setError ] = useState( false ); - const [ inFlight, setInFlight ] = useState( false ); - const [ emails, setEmails ] = useState( EMAILS ); - - const updateStatus = ( postId, status ) => { - setError( false ); - setInFlight( true ); - apiFetch( { - path: `/wp/v2/${ postType }/${ postId }`, - method: 'post', - data: { status }, - } ) - .then( () => { - setEmails( - emails.map( email => { - if ( email.post_id === postId ) { - return { ...email, status }; - } - return email; - } ) - ); - } ) - .catch( setError ) - .finally( () => setInFlight( false ) ); - }; - - if ( false === pluginsReady ) { - return ( - <> - - { __( - 'Newspack uses Newspack Newsletters to handle editing email-type content. Please activate this plugin to proceed.', - 'newspack' - ) } - - - { __( 'Until this feature is configured, default receipts will be used.', 'newspack' ) } - - setPluginsReady( res.complete ) } - onInstalled={ () => window.location.reload() } - withoutFooterButton={ true } - /> - - ); - } - - return ( - <> - { emails.map( email => { - const isActive = email.status === 'publish'; - return ( - updateStatus( email.post_id, value ? 'publish' : 'draft' ) } - { ...( isActive - ? {} - : { - notification: __( - 'This email is not active. The default receipt will be used.', - 'newspack' - ), - notificationLevel: 'info', - } ) } - > - { error && ( - - ) } - - ); - } ) } - - ); -}; - -export default Emails; diff --git a/src/wizards/audience/views/donations/index.js b/src/wizards/audience/views/donations/index.js index 86de8f4f4e..6b491d453f 100644 --- a/src/wizards/audience/views/donations/index.js +++ b/src/wizards/audience/views/donations/index.js @@ -15,7 +15,6 @@ import { __ } from '@wordpress/i18n'; */ import { Wizard, Notice, withWizard } from '../../../../components/src'; import Configuration from './configuration'; -import Emails from './emails'; import { READER_REVENUE_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants'; const AudienceDonations = () => { @@ -29,9 +28,9 @@ const AudienceDonations = () => { isHidden: usedPlatform === OTHER, }, { - label: __( 'Emails', 'newspack-plugin' ), - path: '/emails', - render: Emails, + label: __( 'Revenue', 'newspack-plugin' ), + path: '/revenue', + render: () => null, isHidden: usedPlatform !== NEWSPACK, }, ]; From 4b02093179b3431941f0ee9cf9aa2ce2cb452805 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:18:25 -0300 Subject: [PATCH 04/25] chore: remove unused import --- src/wizards/audience/components/billing-fields/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx index 1174b82c2d..8a070b4fec 100644 --- a/src/wizards/audience/components/billing-fields/index.tsx +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -10,7 +10,6 @@ import { CheckboxControl } from '@wordpress/components'; */ import { Button, - Card, Grid, SectionHeader, Wizard, From 3244a022c7ed6b71f2c6dbf85a048956eeaf6796 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:33:32 -0300 Subject: [PATCH 05/25] feat: move "cover fees" --- .../components/cover-fees-settings/index.js | 95 ++++++++++++++++ .../payment-methods/additional-settings.js | 105 ------------------ .../components/payment-methods/index.js | 8 -- .../views/donations/configuration/index.tsx | 3 + 4 files changed, 98 insertions(+), 113 deletions(-) create mode 100644 src/wizards/audience/components/cover-fees-settings/index.js delete mode 100644 src/wizards/audience/components/payment-methods/additional-settings.js diff --git a/src/wizards/audience/components/cover-fees-settings/index.js b/src/wizards/audience/components/cover-fees-settings/index.js new file mode 100644 index 0000000000..97a087ea1f --- /dev/null +++ b/src/wizards/audience/components/cover-fees-settings/index.js @@ -0,0 +1,95 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { CheckboxControl } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; + +/** + * Internal dependencies + */ +import { + ActionCard, + Button, + Grid, + TextControl, + Wizard, +} from '../../../../components/src'; +import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; + +export const CoverFeesSettings = () => { + const { additional_settings: settings = {} } = Wizard.useWizardData( 'reader-revenue' ); + const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); + const changeHandler = ( key, value ) => + updateWizardSettings( { + slug: READER_REVENUE_WIZARD_SLUG, + path: [ 'additional_settings', key ], + value, + } ); + + const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); + const onSave = () => + saveWizardSettings( { + slug: READER_REVENUE_WIZARD_SLUG, + section: 'settings', + payloadPath: [ 'additional_settings' ], + } ); + + return ( + { + changeHandler( 'allow_covering_fees', ! settings.allow_covering_fees ); + onSave(); + } } + hasGreyHeader={ settings.allow_covering_fees } + hasWhiteHeader={ ! settings.allow_covering_fees } + actionContent={ settings.allow_covering_fees && ( + + ) } + > + { settings.allow_covering_fees && ( + + changeHandler( 'fee_multiplier', value ) } + /> + changeHandler( 'fee_static', value ) } + /> + changeHandler( 'allow_covering_fees_label', value ) } + /> + changeHandler( 'allow_covering_fees_default', ! settings.allow_covering_fees_default ) } + help={ __( + 'If enabled, the option to cover the transaction fee will be checked by default.', + 'newspack-plugin' + ) } + /> + + ) } + + ); +} diff --git a/src/wizards/audience/components/payment-methods/additional-settings.js b/src/wizards/audience/components/payment-methods/additional-settings.js deleted file mode 100644 index 9884e1e84f..0000000000 --- a/src/wizards/audience/components/payment-methods/additional-settings.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { CheckboxControl } from '@wordpress/components'; -import { useDispatch } from '@wordpress/data'; - -/** - * Internal dependencies - */ -import { - ActionCard, - Button, - Grid, - SectionHeader, - TextControl, - Wizard, -} from '../../../../components/src'; -import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; -import './style.scss'; - -export const AdditionalSettings = ( { settings } ) => { - const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); - const changeHandler = ( key, value ) => - updateWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, - path: [ 'additional_settings', key ], - value, - } ); - - const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); - const onSave = () => - saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, - section: 'settings', - payloadPath: [ 'additional_settings' ], - } ); - - return ( - <> - - { - changeHandler( 'allow_covering_fees', ! settings.allow_covering_fees ); - onSave(); - } } - hasGreyHeader={ settings.allow_covering_fees } - hasWhiteHeader={ ! settings.allow_covering_fees } - actionContent={ settings.allow_covering_fees && ( - - ) } - > - { settings.allow_covering_fees && ( - - changeHandler( 'fee_multiplier', value ) } - /> - changeHandler( 'fee_static', value ) } - /> - changeHandler( 'allow_covering_fees_label', value ) } - /> - changeHandler( 'allow_covering_fees_default', ! settings.allow_covering_fees_default ) } - help={ __( - 'If enabled, the option to cover the transaction fee will be checked by default.', - 'newspack-plugin' - ) } - /> - - ) } - - - ); -} \ No newline at end of file diff --git a/src/wizards/audience/components/payment-methods/index.js b/src/wizards/audience/components/payment-methods/index.js index 28c7da497e..3fdba5f981 100644 --- a/src/wizards/audience/components/payment-methods/index.js +++ b/src/wizards/audience/components/payment-methods/index.js @@ -7,7 +7,6 @@ import { ExternalLink } from '@wordpress/components'; /** * Internal dependencies */ -import { AdditionalSettings } from './additional-settings'; import { Stripe } from './stripe'; import { WooPayments } from './woopayments'; import { Notice, SectionHeader, Wizard } from '../../../../components/src'; @@ -18,7 +17,6 @@ const PaymentGateways = () => { payment_gateways: paymentGateways = {}, is_ssl, errors = [], - additional_settings: settings = {}, plugin_status, platform_data = {}, } = Wizard.useWizardData( 'reader-revenue' ); @@ -27,7 +25,6 @@ const PaymentGateways = () => { } const { stripe = false, woopayments = false } = paymentGateways; - const hasPaymentGateway = Object.keys( paymentGateways ).some( gateway => paymentGateways[ gateway ]?.enabled ); return ( <> { ) } - { hasPaymentGateway && ( - - ) } ); }; diff --git a/src/wizards/audience/views/donations/configuration/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx index 19a3af95a1..a0113e03cf 100644 --- a/src/wizards/audience/views/donations/configuration/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -21,6 +21,7 @@ import { } from '../../../../../components/src'; import WizardsTab from '../../../../wizards-tab'; import { READER_REVENUE_WIZARD_SLUG } from '../../../constants'; +import { CoverFeesSettings } from '../../../components/cover-fees-settings'; type FrequencySlug = 'once' | 'month' | 'year'; @@ -278,6 +279,8 @@ const Donation = () => { { __( 'Save Settings', 'newspack-plugin' ) } + + ); }; From bcdb00b1fab214c80584eab08c399bafc4aeb470 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:34:20 -0300 Subject: [PATCH 06/25] fix: improve NRH settings wizard ui --- .../audience/components/nrh-settings/index.js | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/wizards/audience/components/nrh-settings/index.js b/src/wizards/audience/components/nrh-settings/index.js index d2ed7e624d..d569226556 100644 --- a/src/wizards/audience/components/nrh-settings/index.js +++ b/src/wizards/audience/components/nrh-settings/index.js @@ -9,10 +9,10 @@ import { useEffect, useState } from '@wordpress/element'; * Internal dependencies */ import { - ActionCard, AutocompleteWithSuggestions, Button, Grid, + SectionHeader, TextControl, Wizard, } from '../../../../components/src'; @@ -45,17 +45,11 @@ const NRHSettings = () => { const settings = wizardData?.platform_data || {}; return ( - - { __( 'Save Settings' ) } - - } - > + <> +
{ />
) } -
+
+ +
+ ); }; From c0751d695cae73a98ff4b938c235e33eb0d87109 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:47:57 -0300 Subject: [PATCH 07/25] chore: move donate block rendering block filter --- includes/class-donations.php | 18 ++++++++++++++++++ .../audience/class-audience-donations.php | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/includes/class-donations.php b/includes/class-donations.php index 54d21e369a..702947375e 100644 --- a/includes/class-donations.php +++ b/includes/class-donations.php @@ -75,6 +75,7 @@ public static function init() { add_filter( 'newspack_blocks_donate_billing_fields_keys', [ __CLASS__, 'get_billing_fields' ] ); add_action( 'woocommerce_checkout_create_order_line_item', [ __CLASS__, 'checkout_create_order_line_item' ], 10, 4 ); add_action( 'woocommerce_coupons_enabled', [ __CLASS__, 'disable_coupons' ] ); + add_filter( 'render_block', [ __CLASS__, 'prevent_rendering_donate_block' ], 10, 2 ); } } @@ -1094,5 +1095,22 @@ public static function disable_coupons( $enabled ) { } return false; } + + /** + * Prevent rendering of Donate block if Reader Revenue platform is set to 'other. + * + * @param string $block_content The block content about to be rendered. + * @param array $block The data of the block about to be rendered. + */ + public static function prevent_rendering_donate_block( $block_content, $block ) { + if ( + isset( $block['blockName'] ) + && 'newspack-blocks/donate' === $block['blockName'] + && self::is_platform_other() + ) { + return ''; + } + return $block_content; + } } Donations::init(); diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index 9023ccd745..2d05d10259 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -33,7 +33,6 @@ class Audience_Donations extends Wizard { public function __construct() { parent::__construct(); add_action( 'rest_api_init', [ $this, 'register_api_endpoints' ] ); - add_filter( 'render_block', [ $this, 'prevent_rendering_donate_block' ], 10, 2 ); } /** @@ -81,23 +80,6 @@ public function enqueue_scripts_and_styles() { ); } - /** - * Prevent rendering of Donate block if Reader Revenue platform is set to 'other. - * - * @param string $block_content The block content about to be rendered. - * @param array $block The data of the block about to be rendered. - */ - public static function prevent_rendering_donate_block( $block_content, $block ) { - if ( - isset( $block['blockName'] ) - && 'newspack-blocks/donate' === $block['blockName'] - && Donations::is_platform_other() - ) { - return ''; - } - return $block_content; - } - /** * Register the endpoints needed for the wizard screens. */ From e04818bb0701835296b8648c55926745fbc8b30b Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:51:28 -0300 Subject: [PATCH 08/25] chore: remove RR wizard --- includes/class-newspack.php | 1 - includes/class-salesforce.php | 2 +- .../class-reader-activation.php | 3 +- .../wizards/class-reader-revenue-wizard.php | 624 ------------------ .../components/billing-fields/index.tsx | 4 +- .../audience/components/platform/index.js | 4 +- src/wizards/audience/constants.js | 2 +- .../views/donations/configuration/index.tsx | 2 +- 8 files changed, 8 insertions(+), 634 deletions(-) delete mode 100644 includes/wizards/class-reader-revenue-wizard.php diff --git a/includes/class-newspack.php b/includes/class-newspack.php index 4376527fe5..564f9447ca 100644 --- a/includes/class-newspack.php +++ b/includes/class-newspack.php @@ -163,7 +163,6 @@ private function includes() { include_once NEWSPACK_ABSPATH . 'includes/wizards/class-settings.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-analytics-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-engagement-wizard.php'; - include_once NEWSPACK_ABSPATH . 'includes/wizards/class-reader-revenue-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-site-design-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-syndication-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-health-check-wizard.php'; diff --git a/includes/class-salesforce.php b/includes/class-salesforce.php index 366413fd9c..256da2efd1 100644 --- a/includes/class-salesforce.php +++ b/includes/class-salesforce.php @@ -708,7 +708,7 @@ private static function sync_salesforce( $order ) { * @return string Redirect URL. */ public static function get_redirect_url() { - return get_admin_url( null, 'admin.php?page=newspack-reader-revenue-wizard#/salesforce' ); + return get_admin_url( null, 'admin.php?page=newspack-audience' ); } /** diff --git a/includes/reader-activation/class-reader-activation.php b/includes/reader-activation/class-reader-activation.php index 077a406258..ece512628f 100644 --- a/includes/reader-activation/class-reader-activation.php +++ b/includes/reader-activation/class-reader-activation.php @@ -550,8 +550,7 @@ public static function get_prerequisites_status() { 'description' => __( 'Setting suggested donation amounts is required for enabling a streamlined donation experience.', 'newspack-plugin' ), 'instructions' => __( 'Set platform to "Newspack" or "News Revenue Hub" and configure your default donation settings. If using News Revenue Hub, set an Organization ID and a Donor Landing Page in News Revenue Hub Settings.', 'newspack-plugin' ), 'help_url' => 'https://help.newspack.com/engagement/reader-activation-system', - // @TODO: Update when platform is added. - 'href' => \admin_url( '/admin.php?page=newspack-reader-revenue-wizard' ), + 'href' => \admin_url( '/admin.php?page=newspack-audience#/payment' ), 'action_text' => __( 'Reader Revenue settings' ), ], 'ras_campaign' => [ diff --git a/includes/wizards/class-reader-revenue-wizard.php b/includes/wizards/class-reader-revenue-wizard.php deleted file mode 100644 index dc64c1b703..0000000000 --- a/includes/wizards/class-reader-revenue-wizard.php +++ /dev/null @@ -1,624 +0,0 @@ -slug, - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'api_fetch' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - ] - ); - // Save basic data about reader revenue platform. - \register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug, - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'platform' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_platform' ], - ], - 'nrh_organization_id' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'nrh_custom_domain' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'nrh_salesforce_campaign_id' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'donor_landing_page' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - ], - ] - ); - - // Save location info. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/location/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_location' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'countrystate' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'address1' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'address2' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'city' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'postcode' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'currency' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - ], - ] - ); - - // Save Stripe info. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/stripe/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_stripe_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'activate' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - 'enabled' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - 'location_code' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - ], - ] - ); - - // Save WooPayments info. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/woopayments/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_woopayments_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'activate' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - 'enabled' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - ], - ] - ); - - // Save additional settings info. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/settings/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_additional_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'fee_multiplier' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => function ( $value ) { - if ( (float) $value > 10 ) { - return new WP_Error( - 'newspack_invalid_param', - __( 'Fee multiplier must be smaller than 10.', 'newspack' ) - ); - } - return true; - }, - ], - 'fee_static' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'allow_covering_fees' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - 'allow_covering_fees_default' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - 'allow_covering_fees_label' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'location_code' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - ], - ] - ); - - // Update Donations settings. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/donations/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_donation_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'amounts' => [ - 'required' => false, - ], - 'tiered' => [ - 'required' => false, - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - 'disabledFrequencies' => [ - 'required' => false, - ], - 'platform' => [ - 'required' => false, - 'sanitize_callback' => 'sanitize_text_field', - ], - ], - ] - ); - - // Save Salesforce settings. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/salesforce/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_salesforce_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'client_id' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - 'client_secret' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - 'access_token' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - 'refresh_token' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - ], - ] - ); - - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/donations/', - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'api_get_donation_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - ] - ); - } - - /** - * Get all Wizard Data - * - * @return WP_REST_Response containing ad units info. - */ - public function api_fetch() { - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * Save top-level data. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Boolean success. - */ - public function api_update( $request ) { - $params = $request->get_params(); - Donations::set_platform_slug( $params['platform'] ); - - // Update NRH settings. - if ( Donations::is_platform_nrh() ) { - NRH::update_settings( $params ); - } - - // Ensure that any Reader Revenue settings changed while the platform wasn't WC are persisted to WC products. - if ( Donations::is_platform_wc() ) { - Donations::update_donation_product( Donations::get_donation_settings() ); - } - - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * Save location info. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Boolean success. - */ - public function api_update_location( $request ) { - $required_plugins_installed = $this->check_required_plugins_installed(); - if ( is_wp_error( $required_plugins_installed ) ) { - return rest_ensure_response( $required_plugins_installed ); - } - $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); - - $params = $request->get_params(); - - $defaults = [ - 'countrystate' => '', - 'address1' => '', - 'address2' => '', - 'city' => '', - 'postcode' => '', - 'currency' => '', - ]; - - $args = wp_parse_args( $params, $defaults ); - $wc_configuration_manager->update_location( $args ); - - // @todo when is the best time to do this? - $wc_configuration_manager->set_smart_defaults(); - - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * Handler for setting Stripe settings. - * - * @param object $settings Stripe settings. - * @return WP_REST_Response with the latest settings. - */ - public function update_stripe_settings( $settings ) { - if ( ! empty( $settings['activate'] ) ) { - // If activating the Stripe Gateway plugin, let's enable it. - $settings = [ 'enabled' => true ]; - } - $result = Stripe_Connection::update_stripe_data( $settings ); - if ( \is_wp_error( $result ) ) { - return $result; - } - - return $this->fetch_all_data(); - } - - /** - * Handler for setting additional settings. - * - * @param object $settings Settings. - * @return WP_REST_Response with the latest settings. - */ - public function update_additional_settings( $settings ) { - if ( isset( $settings['allow_covering_fees'] ) ) { - update_option( 'newspack_donations_allow_covering_fees', $settings['allow_covering_fees'] ); - } - if ( isset( $settings['allow_covering_fees_default'] ) ) { - update_option( 'newspack_donations_allow_covering_fees_default', $settings['allow_covering_fees_default'] ); - } - - if ( isset( $settings['allow_covering_fees_label'] ) ) { - update_option( 'newspack_donations_allow_covering_fees_label', $settings['allow_covering_fees_label'] ); - } - if ( isset( $settings['fee_multiplier'] ) ) { - update_option( 'newspack_blocks_donate_fee_multiplier', $settings['fee_multiplier'] ); - } - if ( isset( $settings['fee_static'] ) ) { - update_option( 'newspack_blocks_donate_fee_static', $settings['fee_static'] ); - } - return $this->fetch_all_data(); - } - - /** - * Save Stripe settings. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Response. - */ - public function api_update_stripe_settings( $request ) { - $params = $request->get_params(); - $result = $this->update_stripe_settings( $params ); - return \rest_ensure_response( $result ); - } - - /** - * Save WooPayments settings. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Response. - */ - public function api_update_woopayments_settings( $request ) { - $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); - - $params = $request->get_params(); - $result = $wc_configuration_manager->update_wc_woopayments_settings( $params ); - return \rest_ensure_response( $result ); - } - - /** - * Save additional payment method settings (e.g. transaction fees). - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Response. - */ - public function api_update_additional_settings( $request ) { - $params = $request->get_params(); - $result = $this->update_additional_settings( $params ); - return \rest_ensure_response( $result ); - } - - /** - * Handler for setting the donation settings. - * - * @param object $settings Donation settings. - * @return WP_REST_Response with the latest settings. - */ - public function update_donation_settings( $settings ) { - $donations_response = Donations::set_donation_settings( $settings ); - if ( is_wp_error( $donations_response ) ) { - return rest_ensure_response( $donations_response ); - } - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * API endpoint for setting the donation settings. - * - * @param WP_REST_Request $request Request containing settings. - * @return WP_REST_Response with the latest settings. - */ - public function api_update_donation_settings( $request ) { - return $this->update_donation_settings( $request->get_params() ); - } - - /** - * API endpoint for setting Salesforce settings. - * - * @param WP_REST_Request $request Request containing settings. - * @return WP_REST_Response with the latest settings. - */ - public function api_update_salesforce_settings( $request ) { - $salesforce_response = Salesforce::set_salesforce_settings( $request->get_params() ); - if ( is_wp_error( $salesforce_response ) ) { - return rest_ensure_response( $salesforce_response ); - } - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * Fetch all data needed to render the Wizard - * - * @return Array - */ - public function fetch_all_data() { - $platform = Donations::get_platform_slug(); - $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); - $wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' ); - $stripe_data = Stripe_Connection::get_stripe_data(); - - $billing_fields = []; - if ( $wc_installed && Donations::is_platform_wc() ) { - $checkout = new \WC_Checkout(); - $fields = $checkout->get_checkout_fields(); - if ( ! empty( $fields['billing'] ) ) { - $billing_fields = $fields['billing']; - } - } - - $args = [ - 'country_state_fields' => newspack_get_countries(), - 'currency_fields' => newspack_get_currencies_options(), - 'location_data' => [], - 'payment_gateways' => [ - 'stripe' => $stripe_data, - 'woopayments' => $wc_configuration_manager->woopayments_data(), - ], - 'additional_settings' => [ - 'allow_covering_fees' => get_option( 'newspack_donations_allow_covering_fees', true ), - 'allow_covering_fees_default' => get_option( 'newspack_donations_allow_covering_fees_default', false ), - 'allow_covering_fees_label' => get_option( 'newspack_donations_allow_covering_fees_label', '' ), - 'fee_multiplier' => get_option( 'newspack_blocks_donate_fee_multiplier', '2.9' ), - 'fee_static' => get_option( 'newspack_blocks_donate_fee_static', '0.3' ), - ], - 'donation_data' => Donations::get_donation_settings(), - 'donation_page' => Donations::get_donation_page_info(), - 'available_billing_fields' => $billing_fields, - 'salesforce_settings' => [], - 'platform_data' => [ - 'platform' => $platform, - ], - 'is_ssl' => is_ssl(), - 'errors' => [], - ]; - if ( 'wc' === $platform ) { - $plugin_status = true; - $managed_plugins = Plugin_Manager::get_managed_plugins(); - $required_plugins = [ - 'woocommerce', - 'woocommerce-subscriptions', - ]; - foreach ( $required_plugins as $required_plugin ) { - if ( 'active' !== $managed_plugins[ $required_plugin ]['Status'] ) { - $plugin_status = false; - } - } - $args = wp_parse_args( - [ - 'salesforce_settings' => Salesforce::get_salesforce_settings(), - 'plugin_status' => $plugin_status, - ], - $args - ); - } elseif ( Donations::is_platform_nrh() ) { - $nrh_config = NRH::get_settings(); - $args['platform_data'] = wp_parse_args( $nrh_config, $args['platform_data'] ); - } - return $args; - } - - /** - * API endpoint for getting donation settings. - * - * @return WP_REST_Response containing info. - */ - public function api_get_donation_settings() { - if ( Donations::is_platform_wc() ) { - $required_plugins_installed = $this->check_required_plugins_installed(); - if ( is_wp_error( $required_plugins_installed ) ) { - return rest_ensure_response( $required_plugins_installed ); - } - } - - return rest_ensure_response( Donations::get_donation_settings() ); - } - - /** - * Check whether WooCommerce is installed and active. - * - * @return bool | WP_Error True on success, WP_Error on failure. - */ - protected function check_required_plugins_installed() { - if ( ! function_exists( 'WC' ) ) { - return new WP_Error( - 'newspack_missing_required_plugin', - esc_html__( 'The WooCommerce plugin is not installed and activated. Install and/or activate it to access this feature.', 'newspack' ), - [ - 'status' => 400, - 'level' => 'fatal', - ] - ); - } - - return true; - } - - /** - * Enqueue Subscriptions Wizard scripts and styles. - */ - public function enqueue_scripts_and_styles() { - parent::enqueue_scripts_and_styles(); - if ( filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) !== $this->slug ) { - return; - } - \wp_enqueue_media(); - \wp_register_script( - 'newspack-reader-revenue-wizard', - Newspack::plugin_url() . '/dist/readerRevenue.js', - $this->get_script_dependencies(), - NEWSPACK_PLUGIN_VERSION, - true - ); - \wp_localize_script( - 'newspack-reader-revenue-wizard', - 'newspack_reader_revenue', - [ - 'emails' => Emails::get_emails( [ Reader_Revenue_Emails::EMAIL_TYPES['RECEIPT'] ], false ), - 'email_cpt' => Emails::POST_TYPE, - 'salesforce_redirect_url' => Salesforce::get_redirect_url(), - 'can_use_name_your_price' => Donations::can_use_name_your_price(), - ] - ); - \wp_enqueue_script( 'newspack-reader-revenue-wizard' ); - } - - /** - * Validate platform ID. - * - * @param mixed $value A param value. - * @return bool - */ - public function api_validate_platform( $value ) { - return in_array( $value, [ 'nrh', 'wc', 'other' ] ); - } -} diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx index 8a070b4fec..6cd68ea6ae 100644 --- a/src/wizards/audience/components/billing-fields/index.tsx +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -25,14 +25,14 @@ const BillingFields = () => { const changeHandler = ( path: string[] ) => ( value: any ) => updateWizardSettings( { - slug: 'newspack-reader-revenue-wizard', + slug: 'newspack-audience-donations', path: [ 'donation_data', ...path ], value, } ); const onSave = () => saveWizardSettings( { - slug: 'newspack-reader-revenue-wizard', + slug: 'newspack-audience-donations', section: 'donations', payloadPath: [ 'donation_data' ], } ); diff --git a/src/wizards/audience/components/platform/index.js b/src/wizards/audience/components/platform/index.js index 4f090092a3..8d6a324eaf 100644 --- a/src/wizards/audience/components/platform/index.js +++ b/src/wizards/audience/components/platform/index.js @@ -39,7 +39,7 @@ const Platform = () => { ] } onChange={ value => { saveWizardSettings( { - slug: 'newspack-reader-revenue-wizard', + slug: 'newspack-audience-donations', payloadPath: [ 'platform_data' ], updatePayload: { path: [ 'platform_data', 'platform' ], @@ -55,7 +55,7 @@ const Platform = () => { onStatus={ ( { complete } ) => { if ( complete ) { updateWizardSettings( { - slug: 'newspack-reader-revenue-wizard', + slug: 'newspack-audience-donations', path: [ 'plugin_status' ], value: true, } ); diff --git a/src/wizards/audience/constants.js b/src/wizards/audience/constants.js index 3407971a56..7997bd4969 100644 --- a/src/wizards/audience/constants.js +++ b/src/wizards/audience/constants.js @@ -6,4 +6,4 @@ export const NRH = 'nrh'; export const NEWSPACK = 'wc'; export const OTHER = 'other'; -export const READER_REVENUE_WIZARD_SLUG = 'newspack-reader-revenue-wizard'; +export const READER_REVENUE_WIZARD_SLUG = 'newspack-audience-donations'; diff --git a/src/wizards/audience/views/donations/configuration/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx index a0113e03cf..8d75c36c2e 100644 --- a/src/wizards/audience/views/donations/configuration/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -56,7 +56,7 @@ export const DonationAmounts = () => { const changeHandler = ( path: ( string | number )[] ) => ( value: any ) => updateWizardSettings( { - slug: 'newspack-reader-revenue-wizard', + slug: 'newspack-audience-donations', path: [ 'donation_data', ...path ], value, } ); From bc8994d045cb2301ad7d5d734b84d3f53a2b1463 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 17:53:19 -0300 Subject: [PATCH 09/25] chore: remove RR wizard --- includes/class-wizards.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/class-wizards.php b/includes/class-wizards.php index b2417dc625..2721881779 100644 --- a/includes/class-wizards.php +++ b/includes/class-wizards.php @@ -31,7 +31,6 @@ public static function init() { self::$wizards = [ 'setup' => new Setup_Wizard(), 'site-design' => new Site_Design_Wizard(), - 'reader-revenue' => new Reader_Revenue_Wizard(), 'advertising' => new Advertising_Wizard(), 'syndication' => new Syndication_Wizard(), 'analytics' => new Analytics_Wizard(), From bac1ac894a87f635fc23028e4fa269451f843231 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 18:20:25 -0300 Subject: [PATCH 10/25] chore: update and standardize wizard slugs --- includes/class-newspack.php | 2 +- includes/reader-activation/class-reader-activation.php | 2 +- includes/wizards/audience/class-audience-campaigns.php | 4 ++-- includes/wizards/audience/class-audience-donations.php | 4 ++-- includes/wizards/audience/class-audience-wizard.php | 4 ++-- src/wizards/audience/components/billing-fields/index.tsx | 6 +++--- .../audience/components/cover-fees-settings/index.js | 2 +- src/wizards/audience/components/nrh-settings/index.js | 2 +- src/wizards/audience/components/payment-methods/index.js | 2 +- src/wizards/audience/components/platform/index.js | 6 +++--- src/wizards/audience/components/salesforce/index.js | 2 +- src/wizards/audience/constants.js | 2 +- src/wizards/audience/views/campaigns/settings/index.js | 2 +- .../audience/views/donations/configuration/index.tsx | 6 +++--- src/wizards/audience/views/donations/index.js | 2 +- src/wizards/audience/views/setup/campaign.js | 2 +- src/wizards/audience/views/setup/complete.js | 2 +- src/wizards/audience/views/setup/content-gating.js | 4 ++-- src/wizards/audience/views/setup/index.js | 4 ++-- src/wizards/audience/views/setup/payment.js | 2 +- src/wizards/index.tsx | 6 +++--- src/wizards/setup/views/services/ReaderRevenue.js | 2 +- src/wizards/setup/views/services/index.js | 2 +- 23 files changed, 36 insertions(+), 36 deletions(-) diff --git a/includes/class-newspack.php b/includes/class-newspack.php index 564f9447ca..3bd1426f18 100644 --- a/includes/class-newspack.php +++ b/includes/class-newspack.php @@ -357,7 +357,7 @@ public function wizard_redirect( $current_screen ) { if ( class_exists( '\Newspack_Popups' ) ) { $post_type_mapping[ \Newspack_Popups::NEWSPACK_POPUPS_CPT ] = [ 'base' => 'edit', - 'url' => esc_url( admin_url( 'admin.php?page=newspack-audience-campaigns' ) ), + 'url' => esc_url( admin_url( 'admin.php?page=newspack-audience-campaigns-wizard' ) ), ]; } diff --git a/includes/reader-activation/class-reader-activation.php b/includes/reader-activation/class-reader-activation.php index ece512628f..88b2aca72d 100644 --- a/includes/reader-activation/class-reader-activation.php +++ b/includes/reader-activation/class-reader-activation.php @@ -562,7 +562,7 @@ public static function get_prerequisites_status() { 'label' => __( 'Reader Activation Campaign', 'newspack-plugin' ), 'description' => __( 'Building a set of prompts with default segments and settings allows for an improved experience optimized for Reader Activation.', 'newspack-plugin' ), 'help_url' => 'https://help.newspack.com/engagement/reader-activation-system', - 'href' => self::is_ras_campaign_configured() ? admin_url( '/admin.php?page=newspack-audience-campaigns' ) : admin_url( '/admin.php?page=newspack-audience#/campaign' ), + 'href' => self::is_ras_campaign_configured() ? admin_url( '/admin.php?page=newspack-audience-campaigns-wizard' ) : admin_url( '/admin.php?page=newspack-audience#/campaign' ), 'action_enabled' => self::is_ras_ready_to_configure(), 'action_text' => __( 'Reader Activation campaign', 'newspack-plugin' ), 'disabled_text' => __( 'Waiting for all settings to be ready', 'newspack-plugin' ), diff --git a/includes/wizards/audience/class-audience-campaigns.php b/includes/wizards/audience/class-audience-campaigns.php index c31505fc73..694bf1edc8 100644 --- a/includes/wizards/audience/class-audience-campaigns.php +++ b/includes/wizards/audience/class-audience-campaigns.php @@ -19,14 +19,14 @@ class Audience_Campaigns extends Wizard { * * @var string */ - protected $slug = 'newspack-audience-campaigns'; + protected $slug = 'newspack-audience-campaigns-wizard'; /** * Parent slug. * * @var string */ - protected $parent_slug = 'newspack-audience'; + protected $parent_slug = 'newspack-audience-wizard'; /** * Constructor. diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index 2d05d10259..68b31f4a09 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -18,14 +18,14 @@ class Audience_Donations extends Wizard { * * @var string */ - protected $slug = 'newspack-audience-donations'; + protected $slug = 'newspack-audience-donations-wizard'; /** * Parent slug. * * @var string */ - protected $parent_slug = 'newspack-audience'; + protected $parent_slug = 'newspack-audience-wizard'; /** * Constructor. diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php index 4d81c235f3..7ed3ac5761 100644 --- a/includes/wizards/audience/class-audience-wizard.php +++ b/includes/wizards/audience/class-audience-wizard.php @@ -33,14 +33,14 @@ class Audience_Wizard extends Wizard { * * @var string */ - protected $slug = 'newspack-audience'; + protected $slug = 'newspack-audience-wizard'; /** * The parent menu item name. * * @var string */ - public $parent_menu = 'newspack-audience'; + public $parent_menu = 'newspack-audience-wizard'; /** * Parent menu order relative to the Newspack Dashboard menu item. diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx index 6cd68ea6ae..67c3c98270 100644 --- a/src/wizards/audience/components/billing-fields/index.tsx +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -16,7 +16,7 @@ import { } from '../../../../components/src'; const BillingFields = () => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( 'audience-donations' ) as ReaderRevenueWizardData; const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { @@ -25,14 +25,14 @@ const BillingFields = () => { const changeHandler = ( path: string[] ) => ( value: any ) => updateWizardSettings( { - slug: 'newspack-audience-donations', + slug: 'newspack-audience-donations-wizard', path: [ 'donation_data', ...path ], value, } ); const onSave = () => saveWizardSettings( { - slug: 'newspack-audience-donations', + slug: 'newspack-audience-donations-wizard', section: 'donations', payloadPath: [ 'donation_data' ], } ); diff --git a/src/wizards/audience/components/cover-fees-settings/index.js b/src/wizards/audience/components/cover-fees-settings/index.js index 97a087ea1f..8747fc327a 100644 --- a/src/wizards/audience/components/cover-fees-settings/index.js +++ b/src/wizards/audience/components/cover-fees-settings/index.js @@ -18,7 +18,7 @@ import { import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; export const CoverFeesSettings = () => { - const { additional_settings: settings = {} } = Wizard.useWizardData( 'reader-revenue' ); + const { additional_settings: settings = {} } = Wizard.useWizardData( 'audience-donations' ); const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const changeHandler = ( key, value ) => updateWizardSettings( { diff --git a/src/wizards/audience/components/nrh-settings/index.js b/src/wizards/audience/components/nrh-settings/index.js index d569226556..0f275108ea 100644 --- a/src/wizards/audience/components/nrh-settings/index.js +++ b/src/wizards/audience/components/nrh-settings/index.js @@ -20,7 +20,7 @@ import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; const NRHSettings = () => { const [ selectedPage, setSelectedPage ] = useState( null ); - const wizardData = Wizard.useWizardData( 'reader-revenue' ); + const wizardData = Wizard.useWizardData( 'audience-donations' ); const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); useEffect( () => { diff --git a/src/wizards/audience/components/payment-methods/index.js b/src/wizards/audience/components/payment-methods/index.js index 3fdba5f981..f9934197ab 100644 --- a/src/wizards/audience/components/payment-methods/index.js +++ b/src/wizards/audience/components/payment-methods/index.js @@ -19,7 +19,7 @@ const PaymentGateways = () => { errors = [], plugin_status, platform_data = {}, - } = Wizard.useWizardData( 'reader-revenue' ); + } = Wizard.useWizardData( 'audience-donations' ); if ( false === plugin_status || 'wc' !== platform_data?.platform ) { return null; } diff --git a/src/wizards/audience/components/platform/index.js b/src/wizards/audience/components/platform/index.js index 8d6a324eaf..d804b90475 100644 --- a/src/wizards/audience/components/platform/index.js +++ b/src/wizards/audience/components/platform/index.js @@ -15,7 +15,7 @@ import { NEWSPACK, NRH, OTHER } from '../../constants'; * Platform Selection Screen Component */ const Platform = () => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ); + const wizardData = Wizard.useWizardData( 'audience-donations' ); const { saveWizardSettings, updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); return ( @@ -39,7 +39,7 @@ const Platform = () => { ] } onChange={ value => { saveWizardSettings( { - slug: 'newspack-audience-donations', + slug: 'newspack-audience-donations-wizard', payloadPath: [ 'platform_data' ], updatePayload: { path: [ 'platform_data', 'platform' ], @@ -55,7 +55,7 @@ const Platform = () => { onStatus={ ( { complete } ) => { if ( complete ) { updateWizardSettings( { - slug: 'newspack-audience-donations', + slug: 'newspack-audience-donations-wizard', path: [ 'plugin_status' ], value: true, } ); diff --git a/src/wizards/audience/components/salesforce/index.js b/src/wizards/audience/components/salesforce/index.js index 761b473b1c..442a90ed82 100644 --- a/src/wizards/audience/components/salesforce/index.js +++ b/src/wizards/audience/components/salesforce/index.js @@ -21,7 +21,7 @@ import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; const Salesforce = () => { const { salesforce_redirect_url: redirectUrl } = window?.newspackAudienceDonations || {}; const [ hasCopied, setHasCopied ] = useState( false ); - const { salesforce_settings: salesforceData = {} } = Wizard.useWizardData( 'reader-revenue' ); + const { salesforce_settings: salesforceData = {} } = Wizard.useWizardData( 'audience-donations' ); const [ isConnected, setIsConnected ] = useState( salesforceData.refresh_token ); const [ error, setError ] = useState( null ); diff --git a/src/wizards/audience/constants.js b/src/wizards/audience/constants.js index 7997bd4969..8817fe42e7 100644 --- a/src/wizards/audience/constants.js +++ b/src/wizards/audience/constants.js @@ -6,4 +6,4 @@ export const NRH = 'nrh'; export const NEWSPACK = 'wc'; export const OTHER = 'other'; -export const READER_REVENUE_WIZARD_SLUG = 'newspack-audience-donations'; +export const READER_REVENUE_WIZARD_SLUG = 'newspack-audience-donations-wizard'; diff --git a/src/wizards/audience/views/campaigns/settings/index.js b/src/wizards/audience/views/campaigns/settings/index.js index 529512366e..5c99e35afb 100644 --- a/src/wizards/audience/views/campaigns/settings/index.js +++ b/src/wizards/audience/views/campaigns/settings/index.js @@ -4,7 +4,7 @@ import { withWizardScreen, PluginSettings } from '../../../../../components/src'; const Settings = () => { - return ; + return ; }; export default withWizardScreen( Settings ); diff --git a/src/wizards/audience/views/donations/configuration/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx index 8d75c36c2e..81cbfd69b3 100644 --- a/src/wizards/audience/views/donations/configuration/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -44,7 +44,7 @@ const FREQUENCIES: { const FREQUENCY_SLUGS: FrequencySlug[] = Object.keys( FREQUENCIES ) as FrequencySlug[]; export const DonationAmounts = () => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( 'audience-donations' ) as ReaderRevenueWizardData; const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { @@ -56,7 +56,7 @@ export const DonationAmounts = () => { const changeHandler = ( path: ( string | number )[] ) => ( value: any ) => updateWizardSettings( { - slug: 'newspack-audience-donations', + slug: 'newspack-audience-donations-wizard', path: [ 'donation_data', ...path ], value, } ); @@ -232,7 +232,7 @@ export const DonationAmounts = () => { }; const Donation = () => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( 'audience-donations' ) as ReaderRevenueWizardData; const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSaveDonationSettings = () => saveWizardSettings( { diff --git a/src/wizards/audience/views/donations/index.js b/src/wizards/audience/views/donations/index.js index 6b491d453f..42cd5df59b 100644 --- a/src/wizards/audience/views/donations/index.js +++ b/src/wizards/audience/views/donations/index.js @@ -18,7 +18,7 @@ import Configuration from './configuration'; import { READER_REVENUE_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants'; const AudienceDonations = () => { - const { platform_data, donation_data } = Wizard.useWizardData( 'reader-revenue' ); + const { platform_data, donation_data } = Wizard.useWizardData( 'audience-donations' ); const usedPlatform = platform_data?.platform; const sections = [ { diff --git a/src/wizards/audience/views/setup/campaign.js b/src/wizards/audience/views/setup/campaign.js index 22327fe9dd..96182a98b8 100644 --- a/src/wizards/audience/views/setup/campaign.js +++ b/src/wizards/audience/views/setup/campaign.js @@ -72,7 +72,7 @@ export default withWizardScreen( () => { setSkipped( { ...skipped, status: 'pending' } ); try { const request = await apiFetch( { - path: '/newspack/v1/wizard/newspack-audience/reader-activation/skip-campaign', + path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation/skip-campaign', method: 'POST', data: { skip: ! skipped.isSkipped }, } ); diff --git a/src/wizards/audience/views/setup/complete.js b/src/wizards/audience/views/setup/complete.js index d008126bcf..ca89c5728a 100644 --- a/src/wizards/audience/views/setup/complete.js +++ b/src/wizards/audience/views/setup/complete.js @@ -127,7 +127,7 @@ export default withWizardScreen( ( { fetchConfig } ) => { try { setCompleted( await apiFetch( { - path: '/newspack/v1/wizard/newspack-audience/reader-activation/activate', + path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation/activate', method: 'post', data: { skip_activation: isSkippedCampaignSetup, diff --git a/src/wizards/audience/views/setup/content-gating.js b/src/wizards/audience/views/setup/content-gating.js index ae80f60b46..4ca0f65e6e 100644 --- a/src/wizards/audience/views/setup/content-gating.js +++ b/src/wizards/audience/views/setup/content-gating.js @@ -22,7 +22,7 @@ export default withWizardScreen( () => { setError( false ); setInFlight( true ); apiFetch( { - path: '/newspack/v1/wizard/newspack-audience/content-gating', + path: '/newspack/v1/wizard/newspack-audience-wizard/content-gating', } ) .then( ( data ) => { setConfig( data ); @@ -35,7 +35,7 @@ export default withWizardScreen( () => { setError( false ); setInFlight( true ); apiFetch( { - path: '/newspack/v1/wizard/newspack-audience/content-gating', + path: '/newspack/v1/wizard/newspack-audience-wizard/content-gating', method: 'POST', data: newConfig, } ) diff --git a/src/wizards/audience/views/setup/index.js b/src/wizards/audience/views/setup/index.js index 48d4eac12c..c6728c6eec 100644 --- a/src/wizards/audience/views/setup/index.js +++ b/src/wizards/audience/views/setup/index.js @@ -34,7 +34,7 @@ function AudienceWizard( { pluginRequirements, wizardApiFetch } ) { setError( false ); setInFlight( true ); return wizardApiFetch( { - path: '/newspack/v1/wizard/newspack-audience/reader-activation', + path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation', } ) .then( ( { config: fetchedConfig, prerequisites_status, can_esp_sync } ) => { setPrerequisites( prerequisites_status ); @@ -51,7 +51,7 @@ function AudienceWizard( { pluginRequirements, wizardApiFetch } ) { setError( false ); setInFlight( true ); wizardApiFetch( { - path: '/newspack/v1/wizard/newspack-audience/reader-activation', + path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation', method: 'post', quiet: true, data, diff --git a/src/wizards/audience/views/setup/payment.js b/src/wizards/audience/views/setup/payment.js index 30db346682..34d169b0c1 100644 --- a/src/wizards/audience/views/setup/payment.js +++ b/src/wizards/audience/views/setup/payment.js @@ -14,7 +14,7 @@ import NRHSettings from '../../components/nrh-settings'; import BillingFields from '../../components/billing-fields'; export default withWizardScreen( function () { - const data = Wizard.useWizardData( 'reader-revenue' ); + const data = Wizard.useWizardData( 'audience-donations' ); return ( = { ) ), }, - 'newspack-audience': { + 'newspack-audience-wizard': { label: __( 'Audience', 'newspack-plugin' ), component: lazy( () => @@ -55,7 +55,7 @@ const components: Record< string, any > = { ) ), }, - 'newspack-audience-campaigns': { + 'newspack-audience-campaigns-wizard': { label: __( 'Audience Campaigns', 'newspack-plugin' ), component: lazy( () => @@ -64,7 +64,7 @@ const components: Record< string, any > = { ) ), }, - 'newspack-audience-donations': { + 'newspack-audience-donations-wizard': { label: __( 'Audience Donations', 'newspack-plugin' ), component: lazy( () => diff --git a/src/wizards/setup/views/services/ReaderRevenue.js b/src/wizards/setup/views/services/ReaderRevenue.js index b6c1b46639..01b78ebdde 100644 --- a/src/wizards/setup/views/services/ReaderRevenue.js +++ b/src/wizards/setup/views/services/ReaderRevenue.js @@ -17,7 +17,7 @@ import { DonationAmounts } from '../../../audience/views/donations/configuration import { Wizard } from '../../../../components/src'; const ReaderRevenue = ( { className } ) => { - const wizardData = Wizard.useWizardData( 'reader-revenue' ); + const wizardData = Wizard.useWizardData( 'audience-donations' ); return (
diff --git a/src/wizards/setup/views/services/index.js b/src/wizards/setup/views/services/index.js index 2047f6c20c..14639dc776 100644 --- a/src/wizards/setup/views/services/index.js +++ b/src/wizards/setup/views/services/index.js @@ -56,7 +56,7 @@ const Services = ( { renderPrimaryButton } ) => { const [ services, updateServices ] = hooks.useObjectState( SERVICES_LIST ); const [ isLoading, setIsLoading ] = useState( true ); const slugs = keys( services ); - const readerRevenueWizardData = Wizard.useWizardData( 'reader-revenue' ); + const readerRevenueWizardData = Wizard.useWizardData( 'audience-donations' ); useEffect( () => { apiFetch( { From 8bd413eeb83a835ff0c96f8bd6c5ea86cdf119cc Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 21 Nov 2024 18:22:40 -0300 Subject: [PATCH 11/25] fix: css selector --- src/wizards/audience/components/prompt-action-card/style.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wizards/audience/components/prompt-action-card/style.scss b/src/wizards/audience/components/prompt-action-card/style.scss index 7fdbb2d14f..5df68402c6 100644 --- a/src/wizards/audience/components/prompt-action-card/style.scss +++ b/src/wizards/audience/components/prompt-action-card/style.scss @@ -4,7 +4,7 @@ @use "~@wordpress/base-styles/colors" as wp-colors; -.newspack-audience-campaigns { +.newspack-audience-campaigns-wizard { .newspack-action-card { display: flex; flex-direction: column; From 5749aaaeabcaecb06290f00bd588d68e1db121ef Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Mon, 25 Nov 2024 17:49:55 -0300 Subject: [PATCH 12/25] fix: decouple methods and tweak wizard store --- includes/class-donations.php | 10 +- .../audience/class-audience-campaigns.php | 4 +- .../audience/class-audience-donations.php | 352 ++---------------- .../audience/class-audience-wizard.php | 292 ++++++++++++++- src/components/src/wizard/store/utils.js | 7 +- .../components/billing-fields/index.tsx | 23 +- .../components/payment-methods/index.js | 2 +- .../audience/components/platform/index.js | 6 +- src/wizards/audience/constants.js | 2 +- .../views/donations/configuration/index.tsx | 2 +- src/wizards/audience/views/setup/campaign.js | 2 +- src/wizards/audience/views/setup/complete.js | 2 +- .../audience/views/setup/content-gating.js | 4 +- src/wizards/audience/views/setup/index.js | 4 +- src/wizards/audience/views/setup/payment.js | 2 +- src/wizards/index.tsx | 6 +- src/wizards/syndication/views/intro/index.js | 2 +- src/wizards/types/hooks.d.ts | 2 +- 18 files changed, 354 insertions(+), 370 deletions(-) diff --git a/includes/class-donations.php b/includes/class-donations.php index 702947375e..089f330326 100644 --- a/includes/class-donations.php +++ b/includes/class-donations.php @@ -430,8 +430,7 @@ public static function get_donation_settings() { $parsed_settings['amounts'][ $frequency ] = array_map( 'floatval', $amounts ); } - $parsed_settings['platform'] = self::get_platform_slug(); - $parsed_settings['billingFields'] = self::get_billing_fields(); + $parsed_settings['platform'] = self::get_platform_slug(); // If NYP isn't available, force untiered config. if ( ! self::can_use_name_your_price() ) { @@ -462,13 +461,6 @@ public static function set_donation_settings( $args ) { if ( isset( $args['saveDonationProduct'] ) && $args['saveDonationProduct'] === true ) { self::update_donation_product( $configuration ); } - - // Update the billing fields. - $billing_fields = isset( $args['billingFields'] ) ? $args['billingFields'] : []; - if ( ! empty( $billing_fields ) ) { - $billing_fields = array_map( 'sanitize_text_field', $billing_fields ); - self::update_billing_fields( $billing_fields ); - } } Logger::log( 'Save donation settings' ); diff --git a/includes/wizards/audience/class-audience-campaigns.php b/includes/wizards/audience/class-audience-campaigns.php index 694bf1edc8..c31505fc73 100644 --- a/includes/wizards/audience/class-audience-campaigns.php +++ b/includes/wizards/audience/class-audience-campaigns.php @@ -19,14 +19,14 @@ class Audience_Campaigns extends Wizard { * * @var string */ - protected $slug = 'newspack-audience-campaigns-wizard'; + protected $slug = 'newspack-audience-campaigns'; /** * Parent slug. * * @var string */ - protected $parent_slug = 'newspack-audience-wizard'; + protected $parent_slug = 'newspack-audience'; /** * Constructor. diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index 68b31f4a09..2c50ba28c3 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -18,14 +18,14 @@ class Audience_Donations extends Wizard { * * @var string */ - protected $slug = 'newspack-audience-donations-wizard'; + protected $slug = 'newspack-audience-donations'; /** * Parent slug. * * @var string */ - protected $parent_slug = 'newspack-audience-wizard'; + protected $parent_slug = 'newspack-audience'; /** * Constructor. @@ -84,124 +84,45 @@ public function enqueue_scripts_and_styles() { * Register the endpoints needed for the wizard screens. */ public function register_api_endpoints() { - // Get all data required to render the Wizard. - \register_rest_route( + // Get donations settings. + register_rest_route( NEWSPACK_API_NAMESPACE, '/wizard/' . $this->slug, [ 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'api_fetch' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - ] - ); - // Save basic data about reader revenue platform. - \register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug, - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'platform' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_platform' ], - ], - 'nrh_organization_id' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'nrh_custom_domain' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'nrh_salesforce_campaign_id' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'donor_landing_page' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - ], - ] - ); - - // Save location info. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/location/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_location' ], + 'callback' => [ $this, 'api_get_donation_settings' ], 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'countrystate' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'address1' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'address2' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - 'city' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'postcode' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - 'currency' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], - ], ] ); - // Save Stripe info. + // Update donations settings. register_rest_route( NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/stripe/', + '/wizard/' . $this->slug, [ 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_stripe_settings' ], + 'callback' => [ $this, 'api_update_donation_settings' ], 'permission_callback' => [ $this, 'api_permissions_check' ], 'args' => [ - 'activate' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + 'amounts' => [ + 'required' => false, ], - 'enabled' => [ + 'tiered' => [ + 'required' => false, 'sanitize_callback' => 'Newspack\newspack_string_to_bool', ], - 'location_code' => [ - 'sanitize_callback' => 'Newspack\newspack_clean', - ], - ], - ] - ); - - // Save WooPayments info. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/woopayments/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_woopayments_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'activate' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + 'disabledFrequencies' => [ + 'required' => false, ], - 'enabled' => [ - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + 'platform' => [ + 'required' => false, + 'sanitize_callback' => 'sanitize_text_field', ], ], ] ); - // Save additional settings info. + // Save additional settings. register_rest_route( NEWSPACK_API_NAMESPACE, '/wizard/' . $this->slug . '/settings/', @@ -240,152 +161,6 @@ public function register_api_endpoints() { ], ] ); - - // Update Donations settings. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/donations/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_donation_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'amounts' => [ - 'required' => false, - ], - 'tiered' => [ - 'required' => false, - 'sanitize_callback' => 'Newspack\newspack_string_to_bool', - ], - 'disabledFrequencies' => [ - 'required' => false, - ], - 'platform' => [ - 'required' => false, - 'sanitize_callback' => 'sanitize_text_field', - ], - ], - ] - ); - - // Save Salesforce settings. - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/salesforce/', - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_salesforce_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => [ - 'client_id' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - 'client_secret' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - 'access_token' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - 'refresh_token' => [ - 'sanitize_callback' => 'sanitize_text_field', - ], - ], - ] - ); - - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/donations/', - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'api_get_donation_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - ] - ); - } - - /** - * Get all Wizard Data - * - * @return WP_REST_Response containing ad units info. - */ - public function api_fetch() { - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * Save top-level data. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Boolean success. - */ - public function api_update( $request ) { - $params = $request->get_params(); - Donations::set_platform_slug( $params['platform'] ); - - // Update NRH settings. - if ( Donations::is_platform_nrh() ) { - NRH::update_settings( $params ); - } - - // Ensure that any Reader Revenue settings changed while the platform wasn't WC are persisted to WC products. - if ( Donations::is_platform_wc() ) { - Donations::update_donation_product( Donations::get_donation_settings() ); - } - - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * Save location info. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Boolean success. - */ - public function api_update_location( $request ) { - $required_plugins_installed = $this->check_required_plugins_installed(); - if ( is_wp_error( $required_plugins_installed ) ) { - return rest_ensure_response( $required_plugins_installed ); - } - $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); - - $params = $request->get_params(); - - $defaults = [ - 'countrystate' => '', - 'address1' => '', - 'address2' => '', - 'city' => '', - 'postcode' => '', - 'currency' => '', - ]; - - $args = wp_parse_args( $params, $defaults ); - $wc_configuration_manager->update_location( $args ); - - // @todo when is the best time to do this? - $wc_configuration_manager->set_smart_defaults(); - - return \rest_ensure_response( $this->fetch_all_data() ); - } - - /** - * Handler for setting Stripe settings. - * - * @param object $settings Stripe settings. - * @return WP_REST_Response with the latest settings. - */ - public function update_stripe_settings( $settings ) { - if ( ! empty( $settings['activate'] ) ) { - // If activating the Stripe Gateway plugin, let's enable it. - $settings = [ 'enabled' => true ]; - } - $result = Stripe_Connection::update_stripe_data( $settings ); - if ( \is_wp_error( $result ) ) { - return $result; - } - - return $this->fetch_all_data(); } /** @@ -414,32 +189,6 @@ public function update_additional_settings( $settings ) { return $this->fetch_all_data(); } - /** - * Save Stripe settings. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Response. - */ - public function api_update_stripe_settings( $request ) { - $params = $request->get_params(); - $result = $this->update_stripe_settings( $params ); - return \rest_ensure_response( $result ); - } - - /** - * Save WooPayments settings. - * - * @param WP_REST_Request $request Request object. - * @return WP_REST_Response Response. - */ - public function api_update_woopayments_settings( $request ) { - $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); - - $params = $request->get_params(); - $result = $wc_configuration_manager->update_wc_woopayments_settings( $params ); - return \rest_ensure_response( $result ); - } - /** * Save additional payment method settings (e.g. transaction fees). * @@ -452,20 +201,6 @@ public function api_update_additional_settings( $request ) { return \rest_ensure_response( $result ); } - /** - * Handler for setting the donation settings. - * - * @param object $settings Donation settings. - * @return WP_REST_Response with the latest settings. - */ - public function update_donation_settings( $settings ) { - $donations_response = Donations::set_donation_settings( $settings ); - if ( is_wp_error( $donations_response ) ) { - return rest_ensure_response( $donations_response ); - } - return \rest_ensure_response( $this->fetch_all_data() ); - } - /** * API endpoint for setting the donation settings. * @@ -477,15 +212,15 @@ public function api_update_donation_settings( $request ) { } /** - * API endpoint for setting Salesforce settings. + * Handler for setting the donation settings. * - * @param WP_REST_Request $request Request containing settings. + * @param object $settings Donation settings. * @return WP_REST_Response with the latest settings. */ - public function api_update_salesforce_settings( $request ) { - $salesforce_response = Salesforce::set_salesforce_settings( $request->get_params() ); - if ( is_wp_error( $salesforce_response ) ) { - return rest_ensure_response( $salesforce_response ); + public function update_donation_settings( $settings ) { + $donations_response = Donations::set_donation_settings( $settings ); + if ( is_wp_error( $donations_response ) ) { + return rest_ensure_response( $donations_response ); } return \rest_ensure_response( $this->fetch_all_data() ); } @@ -501,39 +236,16 @@ public function fetch_all_data() { $wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' ); $stripe_data = Stripe_Connection::get_stripe_data(); - $billing_fields = []; - if ( $wc_installed && Donations::is_platform_wc() ) { - $checkout = new \WC_Checkout(); - $fields = $checkout->get_checkout_fields(); - if ( ! empty( $fields['billing'] ) ) { - $billing_fields = $fields['billing']; - } - } - $args = [ - 'country_state_fields' => newspack_get_countries(), - 'currency_fields' => newspack_get_currencies_options(), - 'location_data' => [], - 'payment_gateways' => [ - 'stripe' => $stripe_data, - 'woopayments' => $wc_configuration_manager->woopayments_data(), - ], - 'additional_settings' => [ + 'additional_settings' => [ 'allow_covering_fees' => get_option( 'newspack_donations_allow_covering_fees', true ), 'allow_covering_fees_default' => get_option( 'newspack_donations_allow_covering_fees_default', false ), 'allow_covering_fees_label' => get_option( 'newspack_donations_allow_covering_fees_label', '' ), 'fee_multiplier' => get_option( 'newspack_blocks_donate_fee_multiplier', '2.9' ), 'fee_static' => get_option( 'newspack_blocks_donate_fee_static', '0.3' ), ], - 'donation_data' => Donations::get_donation_settings(), - 'donation_page' => Donations::get_donation_page_info(), - 'available_billing_fields' => $billing_fields, - 'salesforce_settings' => [], - 'platform_data' => [ - 'platform' => $platform, - ], - 'is_ssl' => is_ssl(), - 'errors' => [], + 'donation_data' => Donations::get_donation_settings(), + 'donation_page' => Donations::get_donation_page_info(), ]; if ( 'wc' === $platform ) { $plugin_status = true; @@ -596,14 +308,4 @@ protected function check_required_plugins_installed() { return true; } - - /** - * Validate platform ID. - * - * @param mixed $value A param value. - * @return bool - */ - public function api_validate_platform( $value ) { - return in_array( $value, [ 'nrh', 'wc', 'other' ] ); - } } diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php index 7ed3ac5761..d010bc4b8c 100644 --- a/includes/wizards/audience/class-audience-wizard.php +++ b/includes/wizards/audience/class-audience-wizard.php @@ -33,14 +33,14 @@ class Audience_Wizard extends Wizard { * * @var string */ - protected $slug = 'newspack-audience-wizard'; + protected $slug = 'newspack-audience'; /** * The parent menu item name. * * @var string */ - public $parent_menu = 'newspack-audience-wizard'; + public $parent_menu = 'newspack-audience'; /** * Parent menu order relative to the Newspack Dashboard menu item. @@ -207,6 +207,117 @@ public function register_api_endpoints() { 'permission_callback' => [ $this, 'api_permissions_check' ], ] ); + + // Save Salesforce settings. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/salesforce', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_salesforce_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'client_id' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + 'client_secret' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + 'access_token' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + 'refresh_token' => [ + 'sanitize_callback' => 'sanitize_text_field', + ], + ], + ] + ); + + // Get payment settings data. + \register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/payment', + [ + 'methods' => \WP_REST_Server::READABLE, + 'callback' => [ $this, 'api_get_payment_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + ] + ); + + // Save basic data about reader revenue platform. + \register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/payment', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_payment_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'platform' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_platform' ], + ], + 'billing_fields' => [ + 'sanitize_callback' => [ $this, 'sanitize_billing_fields' ], + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + 'nrh_organization_id' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + 'nrh_custom_domain' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + 'nrh_salesforce_campaign_id' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + 'donor_landing_page' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + ], + ] + ); + + // Save Stripe info. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/stripe/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_stripe_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'activate' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'enabled' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'location_code' => [ + 'sanitize_callback' => 'Newspack\newspack_clean', + ], + ], + ] + ); + + // Save WooPayments info. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/woopayments/', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_woopayments_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'activate' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + 'enabled' => [ + 'sanitize_callback' => 'Newspack\newspack_string_to_bool', + ], + ], + ] + ); } /** @@ -295,6 +406,183 @@ public function api_update_content_gating_settings( $request ) { return rest_ensure_response( self::get_memberships_settings() ); } + /** + * API endpoint for setting Salesforce settings. + * + * @param WP_REST_Request $request Request containing settings. + * @return WP_REST_Response with the latest settings. + */ + public function api_update_salesforce_settings( $request ) { + $salesforce_response = Salesforce::set_salesforce_settings( $request->get_params() ); + if ( is_wp_error( $salesforce_response ) ) { + return rest_ensure_response( $salesforce_response ); + } + return \rest_ensure_response( $this->get_payment_data() ); + } + + /** + * Validate platform ID. + * + * @param mixed $value A param value. + * @return bool + */ + public function api_validate_platform( $value ) { + return in_array( $value, [ 'nrh', 'wc', 'other' ] ); + } + + /** + * Get payment settings. + * + * @return WP_REST_Response containing ad units info. + */ + public function api_get_payment_settings() { + return \rest_ensure_response( $this->get_payment_data() ); + } + + /** + * Sanitize payment billing fields. + * + * @param mixed $value A param value. + * + * @return array + */ + public function sanitize_billing_fields( $value ) { + return is_array( $value ) ? array_map( 'sanitize_text_field', $value ) : []; + } + + /** + * Set payment settings. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Boolean success. + */ + public function api_update_payment_settings( $request ) { + $params = $request->get_params(); + Donations::set_platform_slug( $params['platform'] ); + + // Update NRH settings. + if ( Donations::is_platform_nrh() ) { + NRH::update_settings( $params ); + } + + // Ensure that any Reader Revenue settings changed while the platform wasn't WC are persisted to WC products. + if ( Donations::is_platform_wc() ) { + Donations::update_donation_product( Donations::get_donation_settings() ); + } + + // Update billing fields. + if ( ! empty( $params['billing_fields'] ) ) { + Donations::update_billing_fields( $params['billing_fields'] ); + } + + return \rest_ensure_response( $this->get_payment_data() ); + } + + /** + * Save Stripe settings. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Response. + */ + public function api_update_stripe_settings( $request ) { + $params = $request->get_params(); + $result = $this->update_stripe_settings( $params ); + return \rest_ensure_response( $result ); + } + + /** + * Handler for setting Stripe settings. + * + * @param object $settings Stripe settings. + * @return WP_REST_Response with the latest settings. + */ + public function update_stripe_settings( $settings ) { + if ( ! empty( $settings['activate'] ) ) { + // If activating the Stripe Gateway plugin, let's enable it. + $settings = [ 'enabled' => true ]; + } + $result = Stripe_Connection::update_stripe_data( $settings ); + if ( \is_wp_error( $result ) ) { + return $result; + } + + return $this->get_payment_data(); + } + + /** + * Save WooPayments settings. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Response. + */ + public function api_update_woopayments_settings( $request ) { + $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); + + $params = $request->get_params(); + $result = $wc_configuration_manager->update_wc_woopayments_settings( $params ); + return \rest_ensure_response( $result ); + } + + /** + * Get payment data for the wizard. + * + * @return Array + */ + public function get_payment_data() { + $platform = Donations::get_platform_slug(); + $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); + $wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' ); + $stripe_data = Stripe_Connection::get_stripe_data(); + + $billing_fields = []; + if ( $wc_installed && Donations::is_platform_wc() ) { + $checkout = new \WC_Checkout(); + $fields = $checkout->get_checkout_fields(); + if ( ! empty( $fields['billing'] ) ) { + $billing_fields = $fields['billing']; + } + } + + $args = [ + 'payment_gateways' => [ + 'stripe' => $stripe_data, + 'woopayments' => $wc_configuration_manager->woopayments_data(), + ], + 'available_billing_fields' => $billing_fields, + 'billing_fields' => Donations::get_billing_fields(), + 'salesforce_settings' => [], + 'platform_data' => [ + 'platform' => $platform, + ], + 'is_ssl' => is_ssl(), + 'errors' => [], + ]; + if ( 'wc' === $platform ) { + $plugin_status = true; + $managed_plugins = Plugin_Manager::get_managed_plugins(); + $required_plugins = [ + 'woocommerce', + 'woocommerce-subscriptions', + ]; + foreach ( $required_plugins as $required_plugin ) { + if ( 'active' !== $managed_plugins[ $required_plugin ]['Status'] ) { + $plugin_status = false; + } + } + $args = wp_parse_args( + [ + 'salesforce_settings' => Salesforce::get_salesforce_settings(), + 'plugin_status' => $plugin_status, + ], + $args + ); + } elseif ( Donations::is_platform_nrh() ) { + $nrh_config = NRH::get_settings(); + $args['platform_data'] = wp_parse_args( $nrh_config, $args['platform_data'] ); + } + return $args; + } + /** * Get memberships settings. * diff --git a/src/components/src/wizard/store/utils.js b/src/components/src/wizard/store/utils.js index e9f17efb20..c1c83857ea 100644 --- a/src/components/src/wizard/store/utils.js +++ b/src/components/src/wizard/store/utils.js @@ -10,7 +10,8 @@ import { WIZARD_STORE_NAMESPACE } from '.'; export const createAction = type => payload => ( { type, payload } ); -export const useWizardData = ( wizardName, defaultValue = {} ) => - useSelect( select => - select( WIZARD_STORE_NAMESPACE ).getWizardAPIData( `newspack-${ wizardName }-wizard` ) +export const useWizardData = ( wizardName, defaultValue = {} ) => { + return useSelect( select => + select( WIZARD_STORE_NAMESPACE ).getWizardAPIData( wizardName ) ) || defaultValue; +}; diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx index 67c3c98270..f05c5de050 100644 --- a/src/wizards/audience/components/billing-fields/index.tsx +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -16,25 +16,26 @@ import { } from '../../../../components/src'; const BillingFields = () => { - const wizardData = Wizard.useWizardData( 'audience-donations' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( 'newspack-audience/payment' ) as ReaderRevenueWizardData; const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); - if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { + if ( ! wizardData ) { return null; } - const changeHandler = ( path: string[] ) => ( value: any ) => + /* @TODO Check args */ + const changeHandler = ( value: any ) => updateWizardSettings( { - slug: 'newspack-audience-donations-wizard', - path: [ 'donation_data', ...path ], + slug: 'newspack-audience/payment', + path: [ 'billing_fields' ], value, } ); + /* @TODO Check args */ const onSave = () => saveWizardSettings( { - slug: 'newspack-audience-donations-wizard', - section: 'donations', - payloadPath: [ 'donation_data' ], + slug: 'newspack-audience/payment', + payloadPath: [ 'billing_fields' ], } ); const availableFields = wizardData.available_billing_fields; @@ -42,8 +43,8 @@ const BillingFields = () => { return null; } - const billingFields = wizardData.donation_data.billingFields.length - ? wizardData.donation_data.billingFields + const billingFields = wizardData.billing_fields.length + ? wizardData.billing_fields : Object.keys( availableFields ); return ( @@ -70,7 +71,7 @@ const BillingFields = () => { } else { newFields = [ ...newFields, fieldKey ]; } - changeHandler( [ 'billingFields' ] )( newFields ); + changeHandler( newFields ); } } /> ) ) } diff --git a/src/wizards/audience/components/payment-methods/index.js b/src/wizards/audience/components/payment-methods/index.js index f9934197ab..c977317d88 100644 --- a/src/wizards/audience/components/payment-methods/index.js +++ b/src/wizards/audience/components/payment-methods/index.js @@ -19,7 +19,7 @@ const PaymentGateways = () => { errors = [], plugin_status, platform_data = {}, - } = Wizard.useWizardData( 'audience-donations' ); + } = Wizard.useWizardData( 'newspack-audience/payment' ); if ( false === plugin_status || 'wc' !== platform_data?.platform ) { return null; } diff --git a/src/wizards/audience/components/platform/index.js b/src/wizards/audience/components/platform/index.js index d804b90475..65997dcaad 100644 --- a/src/wizards/audience/components/platform/index.js +++ b/src/wizards/audience/components/platform/index.js @@ -15,7 +15,7 @@ import { NEWSPACK, NRH, OTHER } from '../../constants'; * Platform Selection Screen Component */ const Platform = () => { - const wizardData = Wizard.useWizardData( 'audience-donations' ); + const wizardData = Wizard.useWizardData( 'newspack-audience/payment' ); const { saveWizardSettings, updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); return ( @@ -39,7 +39,7 @@ const Platform = () => { ] } onChange={ value => { saveWizardSettings( { - slug: 'newspack-audience-donations-wizard', + slug: 'newspack-audience/payment', payloadPath: [ 'platform_data' ], updatePayload: { path: [ 'platform_data', 'platform' ], @@ -55,7 +55,7 @@ const Platform = () => { onStatus={ ( { complete } ) => { if ( complete ) { updateWizardSettings( { - slug: 'newspack-audience-donations-wizard', + slug: 'newspack-audience/payment', path: [ 'plugin_status' ], value: true, } ); diff --git a/src/wizards/audience/constants.js b/src/wizards/audience/constants.js index 8817fe42e7..7997bd4969 100644 --- a/src/wizards/audience/constants.js +++ b/src/wizards/audience/constants.js @@ -6,4 +6,4 @@ export const NRH = 'nrh'; export const NEWSPACK = 'wc'; export const OTHER = 'other'; -export const READER_REVENUE_WIZARD_SLUG = 'newspack-audience-donations-wizard'; +export const READER_REVENUE_WIZARD_SLUG = 'newspack-audience-donations'; diff --git a/src/wizards/audience/views/donations/configuration/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx index 81cbfd69b3..6252f50afa 100644 --- a/src/wizards/audience/views/donations/configuration/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -56,7 +56,7 @@ export const DonationAmounts = () => { const changeHandler = ( path: ( string | number )[] ) => ( value: any ) => updateWizardSettings( { - slug: 'newspack-audience-donations-wizard', + slug: 'newspack-audience-donations', path: [ 'donation_data', ...path ], value, } ); diff --git a/src/wizards/audience/views/setup/campaign.js b/src/wizards/audience/views/setup/campaign.js index 96182a98b8..22327fe9dd 100644 --- a/src/wizards/audience/views/setup/campaign.js +++ b/src/wizards/audience/views/setup/campaign.js @@ -72,7 +72,7 @@ export default withWizardScreen( () => { setSkipped( { ...skipped, status: 'pending' } ); try { const request = await apiFetch( { - path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation/skip-campaign', + path: '/newspack/v1/wizard/newspack-audience/reader-activation/skip-campaign', method: 'POST', data: { skip: ! skipped.isSkipped }, } ); diff --git a/src/wizards/audience/views/setup/complete.js b/src/wizards/audience/views/setup/complete.js index ca89c5728a..d008126bcf 100644 --- a/src/wizards/audience/views/setup/complete.js +++ b/src/wizards/audience/views/setup/complete.js @@ -127,7 +127,7 @@ export default withWizardScreen( ( { fetchConfig } ) => { try { setCompleted( await apiFetch( { - path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation/activate', + path: '/newspack/v1/wizard/newspack-audience/reader-activation/activate', method: 'post', data: { skip_activation: isSkippedCampaignSetup, diff --git a/src/wizards/audience/views/setup/content-gating.js b/src/wizards/audience/views/setup/content-gating.js index 4ca0f65e6e..ae80f60b46 100644 --- a/src/wizards/audience/views/setup/content-gating.js +++ b/src/wizards/audience/views/setup/content-gating.js @@ -22,7 +22,7 @@ export default withWizardScreen( () => { setError( false ); setInFlight( true ); apiFetch( { - path: '/newspack/v1/wizard/newspack-audience-wizard/content-gating', + path: '/newspack/v1/wizard/newspack-audience/content-gating', } ) .then( ( data ) => { setConfig( data ); @@ -35,7 +35,7 @@ export default withWizardScreen( () => { setError( false ); setInFlight( true ); apiFetch( { - path: '/newspack/v1/wizard/newspack-audience-wizard/content-gating', + path: '/newspack/v1/wizard/newspack-audience/content-gating', method: 'POST', data: newConfig, } ) diff --git a/src/wizards/audience/views/setup/index.js b/src/wizards/audience/views/setup/index.js index c6728c6eec..48d4eac12c 100644 --- a/src/wizards/audience/views/setup/index.js +++ b/src/wizards/audience/views/setup/index.js @@ -34,7 +34,7 @@ function AudienceWizard( { pluginRequirements, wizardApiFetch } ) { setError( false ); setInFlight( true ); return wizardApiFetch( { - path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation', + path: '/newspack/v1/wizard/newspack-audience/reader-activation', } ) .then( ( { config: fetchedConfig, prerequisites_status, can_esp_sync } ) => { setPrerequisites( prerequisites_status ); @@ -51,7 +51,7 @@ function AudienceWizard( { pluginRequirements, wizardApiFetch } ) { setError( false ); setInFlight( true ); wizardApiFetch( { - path: '/newspack/v1/wizard/newspack-audience-wizard/reader-activation', + path: '/newspack/v1/wizard/newspack-audience/reader-activation', method: 'post', quiet: true, data, diff --git a/src/wizards/audience/views/setup/payment.js b/src/wizards/audience/views/setup/payment.js index 34d169b0c1..35c497de09 100644 --- a/src/wizards/audience/views/setup/payment.js +++ b/src/wizards/audience/views/setup/payment.js @@ -14,7 +14,7 @@ import NRHSettings from '../../components/nrh-settings'; import BillingFields from '../../components/billing-fields'; export default withWizardScreen( function () { - const data = Wizard.useWizardData( 'audience-donations' ); + const data = Wizard.useWizardData( 'newspack-audience/payment' ); return ( = { ) ), }, - 'newspack-audience-wizard': { + 'newspack-audience': { label: __( 'Audience', 'newspack-plugin' ), component: lazy( () => @@ -55,7 +55,7 @@ const components: Record< string, any > = { ) ), }, - 'newspack-audience-campaigns-wizard': { + 'newspack-audience-campaigns': { label: __( 'Audience Campaigns', 'newspack-plugin' ), component: lazy( () => @@ -64,7 +64,7 @@ const components: Record< string, any > = { ) ), }, - 'newspack-audience-donations-wizard': { + 'newspack-audience-donations': { label: __( 'Audience Donations', 'newspack-plugin' ), component: lazy( () => diff --git a/src/wizards/syndication/views/intro/index.js b/src/wizards/syndication/views/intro/index.js index 05120b18ba..c01570b577 100644 --- a/src/wizards/syndication/views/intro/index.js +++ b/src/wizards/syndication/views/intro/index.js @@ -10,7 +10,7 @@ import { useDispatch } from '@wordpress/data'; import { PluginToggle, ActionCard, Wizard } from '../../../../components/src'; const Intro = () => { - const settingsData = Wizard.useWizardData( 'settings' ); + const settingsData = Wizard.useWizardData( 'newspack-settings-wizard' ); const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); return ( <> diff --git a/src/wizards/types/hooks.d.ts b/src/wizards/types/hooks.d.ts index 1528554702..da2e5ba309 100644 --- a/src/wizards/types/hooks.d.ts +++ b/src/wizards/types/hooks.d.ts @@ -73,7 +73,6 @@ type ReaderRevenueWizardData = { currencySymbol: string; tiered: boolean; minimumDonation: string; - billingFields: string[]; }; platform_data: { platform: string; @@ -93,4 +92,5 @@ type ReaderRevenueWizardData = { validate: string[]; }; }; + billing_fields: string[]; }; \ No newline at end of file From 620dd67d1e954c1d7858fad6dbdb377bc3b37941 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 11:41:12 -0300 Subject: [PATCH 13/25] fix: billing fields api endpoint --- includes/class-donations.php | 1 - .../audience/class-audience-wizard.php | 96 ++++++++++++++----- .../components/billing-fields/index.tsx | 9 +- .../audience/components/nrh-settings/index.js | 7 +- 4 files changed, 77 insertions(+), 36 deletions(-) diff --git a/includes/class-donations.php b/includes/class-donations.php index 089f330326..c2b0aaa6c4 100644 --- a/includes/class-donations.php +++ b/includes/class-donations.php @@ -612,7 +612,6 @@ public static function get_platform_slug() { * @param string $platform Platform slug. */ public static function set_platform_slug( $platform ) { - delete_option( self::NEWSPACK_READER_REVENUE_PLATFORM ); update_option( self::NEWSPACK_READER_REVENUE_PLATFORM, $platform, true ); } diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php index d010bc4b8c..fcdea09c78 100644 --- a/includes/wizards/audience/class-audience-wizard.php +++ b/includes/wizards/audience/class-audience-wizard.php @@ -257,10 +257,6 @@ public function register_api_endpoints() { 'sanitize_callback' => 'Newspack\newspack_clean', 'validate_callback' => [ $this, 'api_validate_platform' ], ], - 'billing_fields' => [ - 'sanitize_callback' => [ $this, 'sanitize_billing_fields' ], - 'validate_callback' => [ $this, 'api_validate_not_empty' ], - ], 'nrh_organization_id' => [ 'sanitize_callback' => 'Newspack\newspack_clean', 'validate_callback' => [ $this, 'api_validate_not_empty' ], @@ -278,6 +274,34 @@ public function register_api_endpoints() { ] ); + // Get billing fields info. + \register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/billing-fields', + [ + 'methods' => \WP_REST_Server::READABLE, + 'callback' => [ $this, 'api_get_billing_fields' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + ] + ); + + // Update billing fields info. + \register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/billing-fields', + [ + 'methods' => \WP_REST_Server::EDITABLE, + 'callback' => [ $this, 'api_update_billing_fields' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => [ + 'billing_fields' => [ + 'sanitize_callback' => [ $this, 'sanitize_billing_fields' ], + 'validate_callback' => [ $this, 'api_validate_not_empty' ], + ], + ], + ] + ); + // Save Stripe info. register_rest_route( NEWSPACK_API_NAMESPACE, @@ -458,6 +482,7 @@ public function sanitize_billing_fields( $value ) { */ public function api_update_payment_settings( $request ) { $params = $request->get_params(); + Donations::set_platform_slug( $params['platform'] ); // Update NRH settings. @@ -470,14 +495,46 @@ public function api_update_payment_settings( $request ) { Donations::update_donation_product( Donations::get_donation_settings() ); } - // Update billing fields. - if ( ! empty( $params['billing_fields'] ) ) { - Donations::update_billing_fields( $params['billing_fields'] ); - } - return \rest_ensure_response( $this->get_payment_data() ); } + /** + * API callback to get billing fields. + * + * @return WP_REST_Response Response. + */ + public function api_get_billing_fields() { + return \rest_ensure_response( $this->get_billing_fields() ); + } + + /** + * Update billing fields. + * + * @param WP_REST_Request $request Request object. + * @return WP_REST_Response Response. + */ + public function api_update_billing_fields( $request ) { + $params = $request->get_params(); + Donations::update_billing_fields( $params['billing_fields'] ); + return \rest_ensure_response( $this->get_billing_fields() ); + } + + /** + * Get billing fields data. + */ + public function get_billing_fields() { + $available_billing_fields = []; + $checkout = new \WC_Checkout(); + $fields = $checkout->get_checkout_fields(); + if ( ! empty( $fields['billing'] ) ) { + $available_billing_fields = $fields['billing']; + } + return [ + 'available_billing_fields' => $available_billing_fields, + 'billing_fields' => Donations::get_billing_fields(), + ]; + } + /** * Save Stripe settings. * @@ -534,28 +591,17 @@ public function get_payment_data() { $wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' ); $stripe_data = Stripe_Connection::get_stripe_data(); - $billing_fields = []; - if ( $wc_installed && Donations::is_platform_wc() ) { - $checkout = new \WC_Checkout(); - $fields = $checkout->get_checkout_fields(); - if ( ! empty( $fields['billing'] ) ) { - $billing_fields = $fields['billing']; - } - } - $args = [ - 'payment_gateways' => [ + 'payment_gateways' => [ 'stripe' => $stripe_data, 'woopayments' => $wc_configuration_manager->woopayments_data(), ], - 'available_billing_fields' => $billing_fields, - 'billing_fields' => Donations::get_billing_fields(), - 'salesforce_settings' => [], - 'platform_data' => [ + 'salesforce_settings' => [], + 'platform_data' => [ 'platform' => $platform, ], - 'is_ssl' => is_ssl(), - 'errors' => [], + 'is_ssl' => is_ssl(), + 'errors' => [], ]; if ( 'wc' === $platform ) { $plugin_status = true; diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx index f05c5de050..b27a072b1d 100644 --- a/src/wizards/audience/components/billing-fields/index.tsx +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -16,26 +16,23 @@ import { } from '../../../../components/src'; const BillingFields = () => { - const wizardData = Wizard.useWizardData( 'newspack-audience/payment' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( 'newspack-audience/billing-fields' ) as ReaderRevenueWizardData; const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData ) { return null; } - /* @TODO Check args */ const changeHandler = ( value: any ) => updateWizardSettings( { - slug: 'newspack-audience/payment', + slug: 'newspack-audience/billing-fields', path: [ 'billing_fields' ], value, } ); - /* @TODO Check args */ const onSave = () => saveWizardSettings( { - slug: 'newspack-audience/payment', - payloadPath: [ 'billing_fields' ], + slug: 'newspack-audience/billing-fields', } ); const availableFields = wizardData.available_billing_fields; diff --git a/src/wizards/audience/components/nrh-settings/index.js b/src/wizards/audience/components/nrh-settings/index.js index 0f275108ea..1298271191 100644 --- a/src/wizards/audience/components/nrh-settings/index.js +++ b/src/wizards/audience/components/nrh-settings/index.js @@ -16,11 +16,10 @@ import { TextControl, Wizard, } from '../../../../components/src'; -import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; const NRHSettings = () => { const [ selectedPage, setSelectedPage ] = useState( null ); - const wizardData = Wizard.useWizardData( 'audience-donations' ); + const wizardData = Wizard.useWizardData( 'newspack-audience/payment' ); const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); useEffect( () => { @@ -31,14 +30,14 @@ const NRHSettings = () => { const changeHandler = ( key, value ) => { return updateWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: 'newspack-audience/payment', path: [ 'platform_data', key ], value, } ); }; const onSave = () => saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: 'newspack-audience/payment', payloadPath: [ 'platform_data' ], } ); From 3509fb72b1e25d34b0c05eaec1f43d85e2886efb Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 12:52:56 -0300 Subject: [PATCH 14/25] fix: donations configuration wizard --- includes/wizards/audience/class-audience-donations.php | 5 ++--- .../audience/components/cover-fees-settings/index.js | 2 +- .../audience/views/donations/configuration/index.tsx | 7 +++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index 2c50ba28c3..ca1485b458 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -261,8 +261,7 @@ public function fetch_all_data() { } $args = wp_parse_args( [ - 'salesforce_settings' => Salesforce::get_salesforce_settings(), - 'plugin_status' => $plugin_status, + 'plugin_status' => $plugin_status, ], $args ); @@ -286,7 +285,7 @@ public function api_get_donation_settings() { } } - return rest_ensure_response( Donations::get_donation_settings() ); + return rest_ensure_response( $this->fetch_all_data() ); } /** diff --git a/src/wizards/audience/components/cover-fees-settings/index.js b/src/wizards/audience/components/cover-fees-settings/index.js index 8747fc327a..405a2e34d2 100644 --- a/src/wizards/audience/components/cover-fees-settings/index.js +++ b/src/wizards/audience/components/cover-fees-settings/index.js @@ -18,7 +18,7 @@ import { import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; export const CoverFeesSettings = () => { - const { additional_settings: settings = {} } = Wizard.useWizardData( 'audience-donations' ); + const { additional_settings: settings = {} } = Wizard.useWizardData( READER_REVENUE_WIZARD_SLUG ); const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const changeHandler = ( key, value ) => updateWizardSettings( { diff --git a/src/wizards/audience/views/donations/configuration/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx index 6252f50afa..74f8ff62bc 100644 --- a/src/wizards/audience/views/donations/configuration/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -44,7 +44,7 @@ const FREQUENCIES: { const FREQUENCY_SLUGS: FrequencySlug[] = Object.keys( FREQUENCIES ) as FrequencySlug[]; export const DonationAmounts = () => { - const wizardData = Wizard.useWizardData( 'audience-donations' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( READER_REVENUE_WIZARD_SLUG ) as ReaderRevenueWizardData; const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { @@ -56,7 +56,7 @@ export const DonationAmounts = () => { const changeHandler = ( path: ( string | number )[] ) => ( value: any ) => updateWizardSettings( { - slug: 'newspack-audience-donations', + slug: READER_REVENUE_WIZARD_SLUG, path: [ 'donation_data', ...path ], value, } ); @@ -232,12 +232,11 @@ export const DonationAmounts = () => { }; const Donation = () => { - const wizardData = Wizard.useWizardData( 'audience-donations' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( READER_REVENUE_WIZARD_SLUG ) as ReaderRevenueWizardData; const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSaveDonationSettings = () => saveWizardSettings( { slug: READER_REVENUE_WIZARD_SLUG, - section: 'donations', payloadPath: [ 'donation_data' ], auxData: { saveDonationProduct: true }, } ); From e3d1a66fb6520c4c76d01b9cff8d4907f3db7b4b Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 14:33:57 -0300 Subject: [PATCH 15/25] fix: salesforce settings --- .../audience/class-audience-donations.php | 1 - .../audience/class-audience-wizard.php | 41 ++++++++++++++----- .../audience/components/salesforce/index.js | 6 +-- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index ca1485b458..5c2c578674 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -74,7 +74,6 @@ public function enqueue_scripts_and_styles() { 'newspack-wizards', 'newspackAudienceDonations', [ - 'salesforce_redirect_url' => Salesforce::get_redirect_url(), 'can_use_name_your_price' => Donations::can_use_name_your_price(), ] ); diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php index fcdea09c78..52d578dc4d 100644 --- a/includes/wizards/audience/class-audience-wizard.php +++ b/includes/wizards/audience/class-audience-wizard.php @@ -79,9 +79,10 @@ public function enqueue_scripts_and_styles() { } parent::enqueue_scripts_and_styles(); $data = [ - 'has_memberships' => class_exists( 'WC_Memberships' ), - 'reader_activation_url' => admin_url( 'admin.php?page=newspack-audience#/' ), - 'esp_metadata_fields' => Reader_Activation\Sync\Metadata::get_default_fields(), + 'has_memberships' => class_exists( 'WC_Memberships' ), + 'reader_activation_url' => admin_url( 'admin.php?page=newspack-audience#/' ), + 'esp_metadata_fields' => Reader_Activation\Sync\Metadata::get_default_fields(), + 'salesforce_redirect_url' => Salesforce::get_redirect_url(), ]; if ( method_exists( 'Newspack\Newsletters\Subscription_Lists', 'get_add_new_url' ) ) { @@ -208,6 +209,17 @@ public function register_api_endpoints() { ] ); + // Get Salesforce settings. + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->slug . '/salesforce', + [ + 'methods' => \WP_REST_Server::READABLE, + 'callback' => [ $this, 'api_get_salesforce_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + ] + ); + // Save Salesforce settings. register_rest_route( NEWSPACK_API_NAMESPACE, @@ -430,6 +442,15 @@ public function api_update_content_gating_settings( $request ) { return rest_ensure_response( self::get_memberships_settings() ); } + /** + * API endpoint to get Salesforce settings. + * + * @return WP_REST_Response with Salesforce settings. + */ + public function api_get_salesforce_settings() { + return \rest_ensure_response( Salesforce::get_salesforce_settings() ); + } + /** * API endpoint for setting Salesforce settings. * @@ -441,7 +462,7 @@ public function api_update_salesforce_settings( $request ) { if ( is_wp_error( $salesforce_response ) ) { return rest_ensure_response( $salesforce_response ); } - return \rest_ensure_response( $this->get_payment_data() ); + return \rest_ensure_response( Salesforce::get_salesforce_settings() ); } /** @@ -592,16 +613,15 @@ public function get_payment_data() { $stripe_data = Stripe_Connection::get_stripe_data(); $args = [ - 'payment_gateways' => [ + 'payment_gateways' => [ 'stripe' => $stripe_data, 'woopayments' => $wc_configuration_manager->woopayments_data(), ], - 'salesforce_settings' => [], - 'platform_data' => [ + 'platform_data' => [ 'platform' => $platform, ], - 'is_ssl' => is_ssl(), - 'errors' => [], + 'is_ssl' => is_ssl(), + 'errors' => [], ]; if ( 'wc' === $platform ) { $plugin_status = true; @@ -617,8 +637,7 @@ public function get_payment_data() { } $args = wp_parse_args( [ - 'salesforce_settings' => Salesforce::get_salesforce_settings(), - 'plugin_status' => $plugin_status, + 'plugin_status' => $plugin_status, ], $args ); diff --git a/src/wizards/audience/components/salesforce/index.js b/src/wizards/audience/components/salesforce/index.js index 442a90ed82..84d2a2a241 100644 --- a/src/wizards/audience/components/salesforce/index.js +++ b/src/wizards/audience/components/salesforce/index.js @@ -16,20 +16,18 @@ import { addQueryArgs } from '@wordpress/url'; * Internal dependencies. */ import { PluginSettings, Notice, Wizard } from '../../../../components/src'; -import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; const Salesforce = () => { const { salesforce_redirect_url: redirectUrl } = window?.newspackAudienceDonations || {}; const [ hasCopied, setHasCopied ] = useState( false ); - const { salesforce_settings: salesforceData = {} } = Wizard.useWizardData( 'audience-donations' ); + const salesforceData = Wizard.useWizardData( 'newspack-audience/salesforce' ); const [ isConnected, setIsConnected ] = useState( salesforceData.refresh_token ); const [ error, setError ] = useState( null ); const { saveWizardSettings, wizardApiFetch } = useDispatch( Wizard.STORE_NAMESPACE ); const saveAllSettings = value => saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, - section: 'salesforce', + slug: 'newspack-audience/salesforce', payloadPath: [ 'salesforce_settings' ], updatePayload: { path: [ 'salesforce_settings' ], From 02b79d832cf55fb718b2fa2e22a81191da9b0e57 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 14:39:33 -0300 Subject: [PATCH 16/25] fix: payment gatways endpoints --- includes/wizards/audience/class-audience-wizard.php | 4 ++-- src/wizards/audience/components/payment-methods/stripe.js | 5 ++--- .../audience/components/payment-methods/woopayments.js | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php index 52d578dc4d..f39c036a30 100644 --- a/includes/wizards/audience/class-audience-wizard.php +++ b/includes/wizards/audience/class-audience-wizard.php @@ -317,7 +317,7 @@ public function register_api_endpoints() { // Save Stripe info. register_rest_route( NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/stripe/', + '/wizard/' . $this->slug . '/payment/stripe/', [ 'methods' => \WP_REST_Server::EDITABLE, 'callback' => [ $this, 'api_update_stripe_settings' ], @@ -339,7 +339,7 @@ public function register_api_endpoints() { // Save WooPayments info. register_rest_route( NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug . '/woopayments/', + '/wizard/' . $this->slug . '/payment/woopayments/', [ 'methods' => \WP_REST_Server::EDITABLE, 'callback' => [ $this, 'api_update_woopayments_settings' ], diff --git a/src/wizards/audience/components/payment-methods/stripe.js b/src/wizards/audience/components/payment-methods/stripe.js index f1df8df4c1..9142566189 100644 --- a/src/wizards/audience/components/payment-methods/stripe.js +++ b/src/wizards/audience/components/payment-methods/stripe.js @@ -13,7 +13,6 @@ import { Button, Wizard, } from '../../../../components/src'; -import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; export const Stripe = ( { stripe } ) => { const isLoading = useSelect( select => select( Wizard.STORE_NAMESPACE ).isLoading() ); @@ -21,7 +20,7 @@ export const Stripe = ( { stripe } ) => { const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const changeHandler = ( key, value ) => updateWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: 'newspack-audience/payment', path: [ 'payment_gateways', 'stripe', key ], value, } ); @@ -29,7 +28,7 @@ export const Stripe = ( { stripe } ) => { const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSave = () => saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: 'newspack-audience/payment', section: 'stripe', payloadPath: [ 'payment_gateways', 'stripe' ], } ); diff --git a/src/wizards/audience/components/payment-methods/woopayments.js b/src/wizards/audience/components/payment-methods/woopayments.js index 54f92c013a..e7fb197016 100644 --- a/src/wizards/audience/components/payment-methods/woopayments.js +++ b/src/wizards/audience/components/payment-methods/woopayments.js @@ -13,7 +13,6 @@ import { Button, Wizard, } from '../../../../components/src'; -import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; export const WooPayments = ( { woopayments } ) => { const isLoading = useSelect( select => select( Wizard.STORE_NAMESPACE ).isLoading() ); @@ -21,7 +20,7 @@ export const WooPayments = ( { woopayments } ) => { const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const changeHandler = ( key, value ) => updateWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: 'newspack-audience/payment', path: [ 'payment_gateways', 'woopayments', key ], value, } ); @@ -29,7 +28,7 @@ export const WooPayments = ( { woopayments } ) => { const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSave = () => saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: 'newspack-audience/payment', section: 'woopayments', payloadPath: [ 'payment_gateways', 'woopayments' ], } ); From 33e6fa803a5f4ee9a03167384b903e892b49b4e1 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 14:41:08 -0300 Subject: [PATCH 17/25] chore: update constant --- .../audience/components/cover-fees-settings/index.js | 8 ++++---- src/wizards/audience/constants.js | 2 +- .../audience/views/donations/configuration/index.tsx | 10 +++++----- src/wizards/audience/views/donations/index.js | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/wizards/audience/components/cover-fees-settings/index.js b/src/wizards/audience/components/cover-fees-settings/index.js index 405a2e34d2..7b11c063f4 100644 --- a/src/wizards/audience/components/cover-fees-settings/index.js +++ b/src/wizards/audience/components/cover-fees-settings/index.js @@ -15,14 +15,14 @@ import { TextControl, Wizard, } from '../../../../components/src'; -import { READER_REVENUE_WIZARD_SLUG } from '../../constants'; +import { AUDIENCE_DONATIONS_WIZARD_SLUG } from '../../constants'; export const CoverFeesSettings = () => { - const { additional_settings: settings = {} } = Wizard.useWizardData( READER_REVENUE_WIZARD_SLUG ); + const { additional_settings: settings = {} } = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ); const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const changeHandler = ( key, value ) => updateWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: AUDIENCE_DONATIONS_WIZARD_SLUG, path: [ 'additional_settings', key ], value, } ); @@ -30,7 +30,7 @@ export const CoverFeesSettings = () => { const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSave = () => saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: AUDIENCE_DONATIONS_WIZARD_SLUG, section: 'settings', payloadPath: [ 'additional_settings' ], } ); diff --git a/src/wizards/audience/constants.js b/src/wizards/audience/constants.js index 7997bd4969..46d5c9d56c 100644 --- a/src/wizards/audience/constants.js +++ b/src/wizards/audience/constants.js @@ -6,4 +6,4 @@ export const NRH = 'nrh'; export const NEWSPACK = 'wc'; export const OTHER = 'other'; -export const READER_REVENUE_WIZARD_SLUG = 'newspack-audience-donations'; +export const AUDIENCE_DONATIONS_WIZARD_SLUG = 'newspack-audience-donations'; diff --git a/src/wizards/audience/views/donations/configuration/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx index 74f8ff62bc..b469ee350b 100644 --- a/src/wizards/audience/views/donations/configuration/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -20,7 +20,7 @@ import { Wizard, } from '../../../../../components/src'; import WizardsTab from '../../../../wizards-tab'; -import { READER_REVENUE_WIZARD_SLUG } from '../../../constants'; +import { AUDIENCE_DONATIONS_WIZARD_SLUG } from '../../../constants'; import { CoverFeesSettings } from '../../../components/cover-fees-settings'; type FrequencySlug = 'once' | 'month' | 'year'; @@ -44,7 +44,7 @@ const FREQUENCIES: { const FREQUENCY_SLUGS: FrequencySlug[] = Object.keys( FREQUENCIES ) as FrequencySlug[]; export const DonationAmounts = () => { - const wizardData = Wizard.useWizardData( READER_REVENUE_WIZARD_SLUG ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ) as ReaderRevenueWizardData; const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { @@ -56,7 +56,7 @@ export const DonationAmounts = () => { const changeHandler = ( path: ( string | number )[] ) => ( value: any ) => updateWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: AUDIENCE_DONATIONS_WIZARD_SLUG, path: [ 'donation_data', ...path ], value, } ); @@ -232,11 +232,11 @@ export const DonationAmounts = () => { }; const Donation = () => { - const wizardData = Wizard.useWizardData( READER_REVENUE_WIZARD_SLUG ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ) as ReaderRevenueWizardData; const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSaveDonationSettings = () => saveWizardSettings( { - slug: READER_REVENUE_WIZARD_SLUG, + slug: AUDIENCE_DONATIONS_WIZARD_SLUG, payloadPath: [ 'donation_data' ], auxData: { saveDonationProduct: true }, } ); diff --git a/src/wizards/audience/views/donations/index.js b/src/wizards/audience/views/donations/index.js index 42cd5df59b..2d6c80dd83 100644 --- a/src/wizards/audience/views/donations/index.js +++ b/src/wizards/audience/views/donations/index.js @@ -15,7 +15,7 @@ import { __ } from '@wordpress/i18n'; */ import { Wizard, Notice, withWizard } from '../../../../components/src'; import Configuration from './configuration'; -import { READER_REVENUE_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants'; +import { AUDIENCE_DONATIONS_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants'; const AudienceDonations = () => { const { platform_data, donation_data } = Wizard.useWizardData( 'audience-donations' ); @@ -38,7 +38,7 @@ const AudienceDonations = () => { values( donation_data?.errors ).map( ( error, i ) => ( From 8a933f1e24220bbe3109b17f22ffaad501c6a610 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 14:43:20 -0300 Subject: [PATCH 18/25] chore: update donation wizard data type --- .../audience/components/billing-fields/index.tsx | 2 +- .../views/donations/configuration/index.tsx | 4 ++-- src/wizards/setup/views/services/index.js | 4 ++-- src/wizards/types/hooks.d.ts | 16 ++-------------- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/wizards/audience/components/billing-fields/index.tsx b/src/wizards/audience/components/billing-fields/index.tsx index b27a072b1d..6746f32f51 100644 --- a/src/wizards/audience/components/billing-fields/index.tsx +++ b/src/wizards/audience/components/billing-fields/index.tsx @@ -16,7 +16,7 @@ import { } from '../../../../components/src'; const BillingFields = () => { - const wizardData = Wizard.useWizardData( 'newspack-audience/billing-fields' ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( 'newspack-audience/billing-fields' ); const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData ) { diff --git a/src/wizards/audience/views/donations/configuration/index.tsx b/src/wizards/audience/views/donations/configuration/index.tsx index b469ee350b..426d6c1137 100644 --- a/src/wizards/audience/views/donations/configuration/index.tsx +++ b/src/wizards/audience/views/donations/configuration/index.tsx @@ -44,7 +44,7 @@ const FREQUENCIES: { const FREQUENCY_SLUGS: FrequencySlug[] = Object.keys( FREQUENCIES ) as FrequencySlug[]; export const DonationAmounts = () => { - const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ) as AudienceDonationsWizardData; const { updateWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); if ( ! wizardData.donation_data || 'errors' in wizardData.donation_data ) { @@ -232,7 +232,7 @@ export const DonationAmounts = () => { }; const Donation = () => { - const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ) as ReaderRevenueWizardData; + const wizardData = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ) as AudienceDonationsWizardData; const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); const onSaveDonationSettings = () => saveWizardSettings( { diff --git a/src/wizards/setup/views/services/index.js b/src/wizards/setup/views/services/index.js index 14639dc776..f54dfd94ec 100644 --- a/src/wizards/setup/views/services/index.js +++ b/src/wizards/setup/views/services/index.js @@ -56,7 +56,7 @@ const Services = ( { renderPrimaryButton } ) => { const [ services, updateServices ] = hooks.useObjectState( SERVICES_LIST ); const [ isLoading, setIsLoading ] = useState( true ); const slugs = keys( services ); - const readerRevenueWizardData = Wizard.useWizardData( 'audience-donations' ); + const wizardData = Wizard.useWizardData( 'audience-donations' ); useEffect( () => { apiFetch( { @@ -72,7 +72,7 @@ const Services = ( { renderPrimaryButton } ) => { // Add Reader Revenue Wizard data straight from the Wizard. data[ 'reader-revenue' ] = { ...data[ 'reader-revenue' ], - ...readerRevenueWizardData, + ...wizardData, }; return apiFetch( { path: '/newspack/v1/wizard/newspack-setup-wizard/services', diff --git a/src/wizards/types/hooks.d.ts b/src/wizards/types/hooks.d.ts index da2e5ba309..8dce03a17a 100644 --- a/src/wizards/types/hooks.d.ts +++ b/src/wizards/types/hooks.d.ts @@ -60,7 +60,7 @@ type WizardSelector = { /** * Reader Revenue Wizard Data */ -type ReaderRevenueWizardData = { +type AudienceDonationsWizardData = { donation_data: | { errors: { [ key: string ]: string[] } } | { @@ -81,16 +81,4 @@ type ReaderRevenueWizardData = { editUrl: string; status: string; }; - available_billing_fields: { - [ key: string ]: { - autocomplete: string; - class: string[]; - label: string; - priority: number; - required: boolean; - type: string; - validate: string[]; - }; - }; - billing_fields: string[]; -}; \ No newline at end of file +}; From 0a884219759818ec55b8cf09d55835e84e581559 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 15:10:42 -0300 Subject: [PATCH 19/25] feat: revenue tab --- .../audience/class-audience-donations.php | 4 ++ src/wizards/audience/views/donations/index.js | 5 ++- .../audience/views/donations/revenue/index.js | 39 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/wizards/audience/views/donations/revenue/index.js diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index 5c2c578674..c5405283d4 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -75,6 +75,7 @@ public function enqueue_scripts_and_styles() { 'newspackAudienceDonations', [ 'can_use_name_your_price' => Donations::can_use_name_your_price(), + 'revenue_link' => admin_url( 'admin.php?page=wc-reports' ), ] ); } @@ -236,6 +237,9 @@ public function fetch_all_data() { $stripe_data = Stripe_Connection::get_stripe_data(); $args = [ + 'platform_data' => [ + 'platform' => $platform, + ], 'additional_settings' => [ 'allow_covering_fees' => get_option( 'newspack_donations_allow_covering_fees', true ), 'allow_covering_fees_default' => get_option( 'newspack_donations_allow_covering_fees_default', false ), diff --git a/src/wizards/audience/views/donations/index.js b/src/wizards/audience/views/donations/index.js index 2d6c80dd83..9d2488edbe 100644 --- a/src/wizards/audience/views/donations/index.js +++ b/src/wizards/audience/views/donations/index.js @@ -15,10 +15,11 @@ import { __ } from '@wordpress/i18n'; */ import { Wizard, Notice, withWizard } from '../../../../components/src'; import Configuration from './configuration'; +import Revenue from './revenue'; import { AUDIENCE_DONATIONS_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants'; const AudienceDonations = () => { - const { platform_data, donation_data } = Wizard.useWizardData( 'audience-donations' ); + const { platform_data, donation_data } = Wizard.useWizardData( 'newspack-audience-donations' ); const usedPlatform = platform_data?.platform; const sections = [ { @@ -30,7 +31,7 @@ const AudienceDonations = () => { { label: __( 'Revenue', 'newspack-plugin' ), path: '/revenue', - render: () => null, + render: Revenue, isHidden: usedPlatform !== NEWSPACK, }, ]; diff --git a/src/wizards/audience/views/donations/revenue/index.js b/src/wizards/audience/views/donations/revenue/index.js new file mode 100644 index 0000000000..ab80281431 --- /dev/null +++ b/src/wizards/audience/views/donations/revenue/index.js @@ -0,0 +1,39 @@ +/* globals newspackAudienceDonations */ +/** + * WordPress dependencies. + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies. + */ +import { Button, Card } from '../../../../../components/src'; +import WizardsTab from '../../../../wizards-tab'; + +/** + * Donation Revenues screen. + */ +const DonationsRevenue = () => ( + +
+ +

{ __( 'View Donation Revenue in WooCommerce', 'newspack-plugin' ) }

+

+ { + __( + 'You can view revenue from donations and subscriptions in the WooCommerce plugin.', + 'newspack-plugin' + ) + } +

+ + + +
+
+
+); + +export default DonationsRevenue; From 7d21b9ab8143e8398157b150478a892fccf9d32c Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 16:11:52 -0300 Subject: [PATCH 20/25] test: change wizard to test --- tests/unit-tests/api-wizards-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit-tests/api-wizards-controller.php b/tests/unit-tests/api-wizards-controller.php index e5126feb76..8423c3973a 100644 --- a/tests/unit-tests/api-wizards-controller.php +++ b/tests/unit-tests/api-wizards-controller.php @@ -17,7 +17,7 @@ class Newspack_Test_Wizards_Controller extends WP_UnitTestCase { * * @var string */ - protected $api_route = '/newspack/v1/wizards/reader-revenue'; + protected $api_route = '/newspack/v1/wizards/site-design'; /** * Set up stuff for testing API requests. @@ -61,7 +61,7 @@ public function test_get_wizard_authorized() { $this->assertEquals( 200, $response->get_status() ); $data = $response->get_data(); - $this->assertEquals( 'Reader Revenue', $data['name'] ); + $this->assertEquals( 'Site Design', $data['name'] ); } /** From 835e0cc8b54cc1626f1dcd1ad4f23baedaa7c0f3 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 16:15:39 -0300 Subject: [PATCH 21/25] fix: campaign wizard regressions --- includes/class-newspack.php | 2 +- includes/reader-activation/class-reader-activation.php | 2 +- src/wizards/audience/components/prompt-action-card/style.scss | 2 +- src/wizards/audience/views/campaigns/settings/index.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/class-newspack.php b/includes/class-newspack.php index 3bd1426f18..564f9447ca 100644 --- a/includes/class-newspack.php +++ b/includes/class-newspack.php @@ -357,7 +357,7 @@ public function wizard_redirect( $current_screen ) { if ( class_exists( '\Newspack_Popups' ) ) { $post_type_mapping[ \Newspack_Popups::NEWSPACK_POPUPS_CPT ] = [ 'base' => 'edit', - 'url' => esc_url( admin_url( 'admin.php?page=newspack-audience-campaigns-wizard' ) ), + 'url' => esc_url( admin_url( 'admin.php?page=newspack-audience-campaigns' ) ), ]; } diff --git a/includes/reader-activation/class-reader-activation.php b/includes/reader-activation/class-reader-activation.php index 88b2aca72d..ece512628f 100644 --- a/includes/reader-activation/class-reader-activation.php +++ b/includes/reader-activation/class-reader-activation.php @@ -562,7 +562,7 @@ public static function get_prerequisites_status() { 'label' => __( 'Reader Activation Campaign', 'newspack-plugin' ), 'description' => __( 'Building a set of prompts with default segments and settings allows for an improved experience optimized for Reader Activation.', 'newspack-plugin' ), 'help_url' => 'https://help.newspack.com/engagement/reader-activation-system', - 'href' => self::is_ras_campaign_configured() ? admin_url( '/admin.php?page=newspack-audience-campaigns-wizard' ) : admin_url( '/admin.php?page=newspack-audience#/campaign' ), + 'href' => self::is_ras_campaign_configured() ? admin_url( '/admin.php?page=newspack-audience-campaigns' ) : admin_url( '/admin.php?page=newspack-audience#/campaign' ), 'action_enabled' => self::is_ras_ready_to_configure(), 'action_text' => __( 'Reader Activation campaign', 'newspack-plugin' ), 'disabled_text' => __( 'Waiting for all settings to be ready', 'newspack-plugin' ), diff --git a/src/wizards/audience/components/prompt-action-card/style.scss b/src/wizards/audience/components/prompt-action-card/style.scss index 5df68402c6..7fdbb2d14f 100644 --- a/src/wizards/audience/components/prompt-action-card/style.scss +++ b/src/wizards/audience/components/prompt-action-card/style.scss @@ -4,7 +4,7 @@ @use "~@wordpress/base-styles/colors" as wp-colors; -.newspack-audience-campaigns-wizard { +.newspack-audience-campaigns { .newspack-action-card { display: flex; flex-direction: column; diff --git a/src/wizards/audience/views/campaigns/settings/index.js b/src/wizards/audience/views/campaigns/settings/index.js index 5c99e35afb..529512366e 100644 --- a/src/wizards/audience/views/campaigns/settings/index.js +++ b/src/wizards/audience/views/campaigns/settings/index.js @@ -4,7 +4,7 @@ import { withWizardScreen, PluginSettings } from '../../../../../components/src'; const Settings = () => { - return ; + return ; }; export default withWizardScreen( Settings ); From 10a45f4d8adc804bdb8ec35568b92d6c5fb8a935 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 16:41:02 -0300 Subject: [PATCH 22/25] fix: typo --- src/wizards/audience/views/setup/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wizards/audience/views/setup/index.js b/src/wizards/audience/views/setup/index.js index 48d4eac12c..8d38be42c2 100644 --- a/src/wizards/audience/views/setup/index.js +++ b/src/wizards/audience/views/setup/index.js @@ -85,7 +85,7 @@ function AudienceWizard( { pluginRequirements, wizardApiFetch } ) { path: '/content-gating', }, emails.length > 0 && { - label: __( 'Transacional Emails', 'newspack-plugin' ), + label: __( 'Transactional Emails', 'newspack-plugin' ), path: '/transactional-emails', }, { From 136b27ea1fb66f7cedf59e49795ff0d1f5b5dde9 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 26 Nov 2024 16:53:55 -0300 Subject: [PATCH 23/25] fix: handle wizard loading on wizard tab --- src/wizards/types/hooks.d.ts | 1 + src/wizards/wizards-tab.tsx | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/wizards/types/hooks.d.ts b/src/wizards/types/hooks.d.ts index 8dce03a17a..69db46e6e7 100644 --- a/src/wizards/types/hooks.d.ts +++ b/src/wizards/types/hooks.d.ts @@ -55,6 +55,7 @@ type WizardData = { // Define the type for the selector's return value type WizardSelector = { getWizardData: ( slug: string ) => WizardData; + isLoading: () => boolean; }; /** diff --git a/src/wizards/wizards-tab.tsx b/src/wizards/wizards-tab.tsx index 04eb259d78..0e9e299991 100644 --- a/src/wizards/wizards-tab.tsx +++ b/src/wizards/wizards-tab.tsx @@ -1,3 +1,13 @@ +/** + * WordPress dependencies. + */ +import { useSelect } from '@wordpress/data'; + +/** + * Internal dependencies. + */ +import { WIZARD_STORE_NAMESPACE } from '../components/src/wizard/store'; + /** * Wizards Tab component. */ @@ -15,11 +25,16 @@ function WizardsTab( { className?: string; description?: React.ReactNode; } ) { + const isWizardLoading = useSelect( + ( select: ( namespace: string ) => WizardSelector ) => + select( WIZARD_STORE_NAMESPACE ).isLoading(), + [] + ); const className = props.className || ''; return (

{ title }

From c1e5ae7922ce4c15c8fe052d9edf4f40b7b59e98 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Wed, 27 Nov 2024 10:39:08 -0300 Subject: [PATCH 24/25] fix: deprecate Salesforce --- includes/wizards/audience/class-audience-wizard.php | 2 ++ src/components/src/handoff-message/index.js | 3 --- src/wizards/audience/views/setup/setup.js | 8 ++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php index f39c036a30..4cd744c2c9 100644 --- a/includes/wizards/audience/class-audience-wizard.php +++ b/includes/wizards/audience/class-audience-wizard.php @@ -78,10 +78,12 @@ public function enqueue_scripts_and_styles() { return; } parent::enqueue_scripts_and_styles(); + $salesforce_settings = Salesforce::get_salesforce_settings(); $data = [ 'has_memberships' => class_exists( 'WC_Memberships' ), 'reader_activation_url' => admin_url( 'admin.php?page=newspack-audience#/' ), 'esp_metadata_fields' => Reader_Activation\Sync\Metadata::get_default_fields(), + 'can_use_salesforce' => ! empty( $salesforce_settings['client_id'] ), 'salesforce_redirect_url' => Salesforce::get_redirect_url(), ]; diff --git a/src/components/src/handoff-message/index.js b/src/components/src/handoff-message/index.js index ba8ecaa290..ea4bcf1e73 100644 --- a/src/components/src/handoff-message/index.js +++ b/src/components/src/handoff-message/index.js @@ -30,9 +30,6 @@ export default function HandoffMessage() { setHandoffMessage( false ); } }, 100 ); - - // Clean up the notification when unmounting. - return () => window.localStorage.removeItem( HANDOFF_KEY ); }, [] ); if ( ! handoffMessage ) { return null; diff --git a/src/wizards/audience/views/setup/setup.js b/src/wizards/audience/views/setup/setup.js index e6efefa215..065cbeab01 100644 --- a/src/wizards/audience/views/setup/setup.js +++ b/src/wizards/audience/views/setup/setup.js @@ -376,8 +376,12 @@ export default withWizardScreen( ( { config, fetchConfig, updateConfig, saveConf ) }
-
- + { newspackAudience.can_use_salesforce && ( + <> +
+ + + ) } ) }
From 8b92d159599646558938ade4e5a4fab5bf9a5e24 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Thu, 28 Nov 2024 09:13:29 -0300 Subject: [PATCH 25/25] fix: remove unused code and minor tweaks --- includes/wizards/audience/class-audience-donations.php | 7 +++---- includes/wizards/audience/class-audience-wizard.php | 1 - src/wizards/audience/components/salesforce/index.js | 2 +- src/wizards/audience/views/donations/index.js | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/wizards/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php index c5405283d4..256bcee0b5 100644 --- a/includes/wizards/audience/class-audience-donations.php +++ b/includes/wizards/audience/class-audience-donations.php @@ -7,6 +7,8 @@ namespace Newspack; +use WP_Error; + defined( 'ABSPATH' ) || exit; /** @@ -231,10 +233,7 @@ public function update_donation_settings( $settings ) { * @return Array */ public function fetch_all_data() { - $platform = Donations::get_platform_slug(); - $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); - $wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' ); - $stripe_data = Stripe_Connection::get_stripe_data(); + $platform = Donations::get_platform_slug(); $args = [ 'platform_data' => [ diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php index 4cd744c2c9..c7fc502714 100644 --- a/includes/wizards/audience/class-audience-wizard.php +++ b/includes/wizards/audience/class-audience-wizard.php @@ -611,7 +611,6 @@ public function api_update_woopayments_settings( $request ) { public function get_payment_data() { $platform = Donations::get_platform_slug(); $wc_configuration_manager = Configuration_Managers::configuration_manager_class_for_plugin_slug( 'woocommerce' ); - $wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' ); $stripe_data = Stripe_Connection::get_stripe_data(); $args = [ diff --git a/src/wizards/audience/components/salesforce/index.js b/src/wizards/audience/components/salesforce/index.js index 84d2a2a241..111c6ff9d4 100644 --- a/src/wizards/audience/components/salesforce/index.js +++ b/src/wizards/audience/components/salesforce/index.js @@ -18,7 +18,7 @@ import { addQueryArgs } from '@wordpress/url'; import { PluginSettings, Notice, Wizard } from '../../../../components/src'; const Salesforce = () => { - const { salesforce_redirect_url: redirectUrl } = window?.newspackAudienceDonations || {}; + const { salesforce_redirect_url: redirectUrl } = window?.newspackAudience || {}; const [ hasCopied, setHasCopied ] = useState( false ); const salesforceData = Wizard.useWizardData( 'newspack-audience/salesforce' ); const [ isConnected, setIsConnected ] = useState( salesforceData.refresh_token ); diff --git a/src/wizards/audience/views/donations/index.js b/src/wizards/audience/views/donations/index.js index 9d2488edbe..c14a9fc5fc 100644 --- a/src/wizards/audience/views/donations/index.js +++ b/src/wizards/audience/views/donations/index.js @@ -19,7 +19,7 @@ import Revenue from './revenue'; import { AUDIENCE_DONATIONS_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants'; const AudienceDonations = () => { - const { platform_data, donation_data } = Wizard.useWizardData( 'newspack-audience-donations' ); + const { platform_data, donation_data } = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG ); const usedPlatform = platform_data?.platform; const sections = [ {