diff --git a/includes/class-donations.php b/includes/class-donations.php
index 54d21e369a..c2b0aaa6c4 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 );
}
}
@@ -429,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() ) {
@@ -461,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' );
@@ -619,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 );
}
@@ -1094,5 +1086,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/class-newspack.php b/includes/class-newspack.php
index 1824a7d106..a5e933c4d2 100644
--- a/includes/class-newspack.php
+++ b/includes/class-newspack.php
@@ -148,6 +148,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';
@@ -159,7 +160,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/class-wizards.php b/includes/class-wizards.php
index 6c833aeba7..06f31897fb 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(),
'syndication' => new Syndication_Wizard(),
'analytics' => new Analytics_Wizard(),
'components-demo' => new Components_Demo(),
@@ -55,6 +54,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/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/audience/class-audience-donations.php b/includes/wizards/audience/class-audience-donations.php
new file mode 100644
index 0000000000..256bcee0b5
--- /dev/null
+++ b/includes/wizards/audience/class-audience-donations.php
@@ -0,0 +1,312 @@
+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',
+ [
+ 'can_use_name_your_price' => Donations::can_use_name_your_price(),
+ 'revenue_link' => admin_url( 'admin.php?page=wc-reports' ),
+ ]
+ );
+ }
+
+ /**
+ * Register the endpoints needed for the wizard screens.
+ */
+ public function register_api_endpoints() {
+ // Get donations settings.
+ register_rest_route(
+ NEWSPACK_API_NAMESPACE,
+ '/wizard/' . $this->slug,
+ [
+ 'methods' => \WP_REST_Server::READABLE,
+ 'callback' => [ $this, 'api_get_donation_settings' ],
+ 'permission_callback' => [ $this, 'api_permissions_check' ],
+ ]
+ );
+
+ // Update donations settings.
+ register_rest_route(
+ NEWSPACK_API_NAMESPACE,
+ '/wizard/' . $this->slug,
+ [
+ '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 additional settings.
+ 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',
+ ],
+ ],
+ ]
+ );
+ }
+
+ /**
+ * 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 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 );
+ }
+
+ /**
+ * 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() );
+ }
+
+ /**
+ * 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() );
+ }
+
+ /**
+ * Fetch all data needed to render the Wizard
+ *
+ * @return Array
+ */
+ public function fetch_all_data() {
+ $platform = Donations::get_platform_slug();
+
+ $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 ),
+ '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(),
+ ];
+ 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(
+ [
+ '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( $this->fetch_all_data() );
+ }
+
+ /**
+ * 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;
+ }
+}
diff --git a/includes/wizards/audience/class-audience-wizard.php b/includes/wizards/audience/class-audience-wizard.php
index 4d81c235f3..c7fc502714 100644
--- a/includes/wizards/audience/class-audience-wizard.php
+++ b/includes/wizards/audience/class-audience-wizard.php
@@ -78,10 +78,13 @@ 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(),
+ '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(),
];
if ( method_exists( 'Newspack\Newsletters\Subscription_Lists', 'get_add_new_url' ) ) {
@@ -207,6 +210,152 @@ public function register_api_endpoints() {
'permission_callback' => [ $this, 'api_permissions_check' ],
]
);
+
+ // 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,
+ '/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' ],
+ ],
+ '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',
+ ],
+ ],
+ ]
+ );
+
+ // 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,
+ '/wizard/' . $this->slug . '/payment/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 . '/payment/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 +444,211 @@ 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.
+ *
+ * @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( Salesforce::get_salesforce_settings() );
+ }
+
+ /**
+ * 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() );
+ }
+
+ 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.
+ *
+ * @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' );
+ $stripe_data = Stripe_Connection::get_stripe_data();
+
+ $args = [
+ 'payment_gateways' => [
+ 'stripe' => $stripe_data,
+ 'woopayments' => $wc_configuration_manager->woopayments_data(),
+ ],
+ '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(
+ [
+ '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/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/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/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
new file mode 100644
index 0000000000..6746f32f51
--- /dev/null
+++ b/src/wizards/audience/components/billing-fields/index.tsx
@@ -0,0 +1,85 @@
+/**
+ * WordPress dependencies.
+ */
+import { useDispatch } from '@wordpress/data';
+import { __ } from '@wordpress/i18n';
+import { CheckboxControl } from '@wordpress/components';
+
+/**
+ * Internal dependencies.
+ */
+import {
+ Button,
+ Grid,
+ SectionHeader,
+ Wizard,
+} from '../../../../components/src';
+
+const BillingFields = () => {
+ const wizardData = Wizard.useWizardData( 'newspack-audience/billing-fields' );
+ const { updateWizardSettings, saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE );
+
+ if ( ! wizardData ) {
+ return null;
+ }
+
+ const changeHandler = ( value: any ) =>
+ updateWizardSettings( {
+ slug: 'newspack-audience/billing-fields',
+ path: [ 'billing_fields' ],
+ value,
+ } );
+
+ const onSave = () =>
+ saveWizardSettings( {
+ slug: 'newspack-audience/billing-fields',
+ } );
+
+ const availableFields = wizardData.available_billing_fields;
+ if ( ! availableFields || ! Object.keys( availableFields ).length ) {
+ return null;
+ }
+
+ const billingFields = wizardData.billing_fields.length
+ ? wizardData.billing_fields
+ : Object.keys( availableFields );
+
+ return (
+ <>
+
{ __( '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 +83,7 @@ const NRHSettings = () => { ) }
+ { + __( + 'You can view revenue from donations and subscriptions in the WooCommerce plugin.', + 'newspack-plugin' + ) + } +
+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`*/} -