Skip to content

Commit

Permalink
feat(ia): audience checkout/payment and donations wizard (#3564)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpeixe authored Nov 29, 2024
1 parent 93abc96 commit f8ca397
Show file tree
Hide file tree
Showing 42 changed files with 1,162 additions and 1,222 deletions.
29 changes: 19 additions & 10 deletions includes/class-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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() ) {
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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();
2 changes: 1 addition & 1 deletion includes/class-newspack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion includes/class-salesforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wizards.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions includes/reader-activation/class-reader-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
Loading

0 comments on commit f8ca397

Please sign in to comment.