Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ia): audience checkout/payment and donations wizard #3564

Merged
merged 27 commits into from
Nov 29, 2024

Conversation

miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Nov 21, 2024

All Submissions:

Changes proposed in this Pull Request:

Implements:

  • Audience Setup Checkout & Payment tab
  • Audience Donations wizard

Most of the effort around this PR is decoupling logic from the existing "Reader Revenue" wizard and placing in different sections of the Audience wizard:

  • Salesforce settings have moved to the Audience Setup tab and should now only render if the publisher already have configured keys for it
  • Payment gateway configuration and checkout billing fields have moved to the Audience Checkout & Payment tab
  • Transaction fees have moved to Audience Donation
  • The Donate block has been updated to use the new API endpoints (see fix(ia): endpoint updates newspack-blocks#1974)
image image image

How to test the changes in this Pull Request:

  1. Reset your RAS setup (CLI: wp option delete newspack_reader_activation_enabled)
  2. Navigate to "Audience -> Setup" and confirm the wizard renders as in the image above
  3. Go through each setup step and confirm they work as expected
  4. On the "Reader Revenue" step, confirm that clicking the "Update Reader Revenue settings" button redirects to the Checkout & Payment view with a notification to return to the RAS setup:
image
  1. Complete the RAS setup
  2. In "Audience -> Setup", scroll down and confirm the Salesforce settings do not render (if you don't have Salesforce settings already)
  3. Add a Salesforce client ID to the database (CLI: wp option update newspack_salesforce_client_id 123), refresh and confirm the Salesforce settings render
  4. Navigate to the Checkout & Payment tab, switch platforms and confirm it behaves as expected
  5. For each platform, tweak the settings, save and refresh the page to confirm the options persist
  6. Navigate to Audience -> Donations and confirm the wizard renders as expected
  7. Tweak the donation options, save and confirm it behaves as expected
  8. Click to edit the donation page (make sure you have fix(ia): endpoint updates newspack-blocks#1974)
  9. Confirm the Donate block render correctly in the editor and you are able to tweak its options
  10. Back to the Audience -> Donations wizard, click the "Revenue" tab and confirm the link redirects to WC's reports admin page

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@miguelpeixe miguelpeixe mentioned this pull request Nov 21, 2024
6 tasks
@miguelpeixe miguelpeixe marked this pull request as ready for review November 27, 2024 13:40
@miguelpeixe miguelpeixe requested a review from a team as a code owner November 27, 2024 13:40
@miguelpeixe miguelpeixe self-assigned this Nov 27, 2024
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Nov 27, 2024
Comment on lines +1089 to +1105

/**
* 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;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this from the wizard class because it's not relevant for the wizard, it makes more sense to live in the more general Donations class.

Comment on lines -34 to -35
// Clean up the notification when unmounting.
return () => window.localStorage.removeItem( HANDOFF_KEY );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed because it instantly removed the handoff message when redirecting from a different tab in the same wizard. That happens because it unmounts the component from the origin tab, given it's a rerender on the same react app.

Comment on lines -13 to +17
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;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this util so wizards can have different slugs outside newspack-{slug}-wizard, which is the case across the IA project.

It should now receive the same argument as updateWizardSettings() and saveWizardSettings(), standardizing it when using the store inside components.

Comment on lines -69 to -73
{ hasPaymentGateway && (
<AdditionalSettings
settings={ settings }
/>
) }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the Audience Donations wizard

@@ -42,43 +43,8 @@ const FREQUENCIES: {
};
const FREQUENCY_SLUGS: FrequencySlug[] = Object.keys( FREQUENCIES ) as FrequencySlug[];

type WizardData = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to src/wizards/types/hooks.d.ts

@@ -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' );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only wizard, other than "Reader Revenue", that used the wizard store and had to update to the new useWizardData()

protected $api_route = '/newspack/v1/wizards/reader-revenue';
protected $api_route = '/newspack/v1/wizards/site-design';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change to a different one because reader-revenue no longer exists

Copy link
Collaborator

@jaredrethman jaredrethman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miguelpeixe thank you for this, a ton of effort went into it.

Functionally it works as described in "How to test the changes in this Pull Request:". I tested+reviewed as thoroughly as I could. Made a few suggestions throughout, nothing too scary.

Comment on lines 235 to 237
$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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last 3 declarations are unused, can we remove?

Suggested change
$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();

* @package Newspack
*/

namespace Newspack;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
namespace Newspack;
namespace Newspack;
use WP_Error;

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' );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is unused.

Suggested change
$wc_installed = 'active' === Plugin_Manager::get_managed_plugin_status( 'woocommerce' );

import { AUDIENCE_DONATIONS_WIZARD_SLUG, NEWSPACK, OTHER } from '../../constants';

const AudienceDonations = () => {
const { platform_data, donation_data } = Wizard.useWizardData( 'newspack-audience-donations' );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { platform_data, donation_data } = Wizard.useWizardData( 'newspack-audience-donations' );
const { platform_data, donation_data } = Wizard.useWizardData( AUDIENCE_DONATIONS_WIZARD_SLUG );


const Salesforce = () => {
const { salesforce_redirect_url: redirectUrl } = window?.newspack_reader_revenue || {};
const { salesforce_redirect_url: redirectUrl } = window?.newspackAudienceDonations || {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { salesforce_redirect_url: redirectUrl } = window?.newspackAudienceDonations || {};
const { salesforce_redirect_url: redirectUrl } = window?.newspackAudience || {};

@miguelpeixe
Copy link
Member Author

Thank you for the review, @jaredrethman! Quite the diff you went through 🙇

Applied all your suggestions in 8b92d15

Copy link
Collaborator

@jaredrethman jaredrethman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work here @miguelpeixe 🎉 , approved!

@miguelpeixe miguelpeixe merged commit f8ca397 into epic/ia Nov 29, 2024
8 checks passed
@miguelpeixe miguelpeixe deleted the feat/ia-audience-donations-2 branch November 29, 2024 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs Review The issue or pull request needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants