Repository: Automattic/jetpack
Pull request #42214: [gold] :: Add Donation modal warning
Author: login: n3f
Labels: name: Bug
description: When a feature is broken and / or not performing as intended
name: [Plugin] Jetpack
description: Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
name: [Block] Donations
name: I don't care about code coverage for this PR
description: Use this label to ignore the check for insufficient code coveage.
Created: 2025-03-05T00:31:31Z | Merged: 2025-03-11T18:04:02Z

<!--- Provide a general summary of your changes in the Title above -->
<!-- Would you like this feature to be tested by Beta testers?
Please add testing instructions to projects/plugins/jetpack/to-test.md in a new commit as part of your PR. -->
<!-- a12s: If you have an expected version that you're aiming for the PR to add, please use the Milestone field to communicate it. If you leave it blank, that indicates there isn't a preference. -->

Fixes 648-gh-Automattic/gold.

## Proposed changes:
<!--- Explain what functional changes your PR includes -->
* Display this modal on the first usage of the donation block

<img width="927" alt="image" src="https://github.com/user-attachments/assets/7cc3c828-e7e8-4fac-88fb-100767d5036a" />

### Other information:

- [ ] Have you written new tests for your changes, if applicable?
- [ ] Have you checked the E2E test CI results, and verified that your changes do not break them?
- [ ] Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

## Jetpack product discussion
<!-- If you're an Automattician, include a shortlink to the p2 discussion with Jetpack Product here. -->
<!-- Make sure any changes to existing products have been discussed and agreed upon -->
pNPgK-6TY-p2

## Does this pull request change what data or activity we track or use?

No.

## Testing instructions:
<!-- If you were reviewing this PR, how would you like the instructions to be presented? -->
<!-- Please include detailed testing steps, explaining how to test your change. -->
<!-- Bear in mind that context you working on is not obvious for everyone.  -->
<!-- Adding "simple" configuration steps will help reviewers to get to your PR as quickly as possible. -->
<!-- "Before / After" screenshots can also be very helpful when the change is visual. -->

### Setup
#### Jurassic Ninja

* Create a JN site with the jetpack beta plugin and apply the `donation/add-warning` branch.
* Make sure jetpack is connected and you are using a paid jetpack plan (required for donations block)

#### WPCOM simple

* Apply the patch 176131-ghe-Automattic/wpcom (`git checkout -b donation/whitelist-user-endpoint-meta`)
* Run `~/public_html/bin/jetpack-downloader test jetpack donation/add-warning`.
* Sandbox both your site _and_ public-api.wordpress.com.
* Enable writes (e.g. `~/public_html/bin/allow-sandbox-production-writes '1 hour'`)

### Test
1. Create a post and add the donations block.
2. The first time should display the modal above. Check that it looks correct.
3. Subsequent refreshes should not show the modal.

If you want to reset it you'll need to remove the `jetpack_donation_warning_dismissed` user meta from your user. (e.g. `wp user meta delete <user-id> jetpack_donation_warning_dismissed`.)


Diff:
diff --git a/projects/plugins/jetpack/changelog/donation-block-add-warning b/projects/plugins/jetpack/changelog/donation-block-add-warning
new file mode 100644
index 000000000000..c7d829808fda
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/donation-block-add-warning
@@ -0,0 +1,4 @@
+Significance: patch
+Type: other
+
+Donation block: add additional information about accepting donations.
diff --git a/projects/plugins/jetpack/extensions/blocks/donations/donations.php b/projects/plugins/jetpack/extensions/blocks/donations/donations.php
index 8b5966abe76b..cd7a5136b2b5 100644
--- a/projects/plugins/jetpack/extensions/blocks/donations/donations.php
+++ b/projects/plugins/jetpack/extensions/blocks/donations/donations.php
@@ -29,6 +29,17 @@ function register_block() {
 			)
 		);
 	}
+	// Add a meta field to the user to track if the donation warning has been dismissed.
+	\register_meta(
+		'user',
+		'jetpack_donation_warning_dismissed',
+		array(
+			'type'         => 'boolean',
+			'single'       => true,
+			'show_in_rest' => true,
+			'default'      => false,
+		)
+	);
 }
 add_action( 'init', __NAMESPACE__ . '\register_block' );
 
diff --git a/projects/plugins/jetpack/extensions/blocks/donations/edit.js b/projects/plugins/jetpack/extensions/blocks/donations/edit.js
index d62de15ecadb..944f9ce79d14 100644
--- a/projects/plugins/jetpack/extensions/blocks/donations/edit.js
+++ b/projects/plugins/jetpack/extensions/blocks/donations/edit.js
@@ -12,6 +12,8 @@ import { store as membershipProductsStore } from '../../store/membership-product
 import { STORE_NAME as MEMBERSHIPS_PRODUCTS_STORE } from '../../store/membership-products/constants';
 import fetchDefaultProducts from './fetch-default-products';
 import fetchStatus from './fetch-status';
+import FirstTimeModal from './first-time-modal';
+import './first-time-modal.scss';
 import LoadingError from './loading-error';
 import Tabs from './tabs';
 
@@ -22,9 +24,12 @@ const Edit = props => {
 	const blockProps = useBlockProps();
 	const [ loadingError, setLoadingError ] = useState( '' );
 	const [ products, setProducts ] = useState( [] );
+	const [ showFirstTimeModal, setShowFirstTimeModal ] = useState( false );
 	const isUserConnected = useIsUserConnected();
 
 	const { lockPostSaving, unlockPostSaving } = useDispatch( 'core/editor' );
+	const { getEntityRecord, getCurrentUser } = useSelect( 'core' );
+	const { editEntityRecord, saveEditedEntityRecord } = useDispatch( 'core' );
 	const post = useSelect( select => select( 'core/editor' ).getCurrentPost(), [] );
 	const isPostSavingLocked = useSelect(
 		select => select( 'core/editor' ).isPostSavingLocked(),
@@ -72,6 +77,29 @@ const Edit = props => {
 		);
 	};
 
+	//
+	// Check if this is the first time using the donations block
+	//
+
+	// Add this to preload the user entity
+	const currentUser = getCurrentUser();
+	useEffect( () => {
+		if ( currentUser?.id ) {
+			// Ensure the user entity is loaded
+			getEntityRecord( 'root', 'user', currentUser.id );
+		}
+	}, [ currentUser?.id, getEntityRecord ] );
+
+	const hasDismissedDonationWarning =
+		currentUser?.meta?.jetpack_donation_warning_dismissed || false;
+
+	// Show the modal if the user has not dismissed the warning
+	useEffect( () => {
+		if ( currentUser?.id && hasDismissedDonationWarning === false ) {
+			setShowFirstTimeModal( true );
+		}
+	}, [ currentUser, hasDismissedDonationWarning ] );
+
 	useEffect( () => {
 		lockPostSaving( 'donations' );
 
@@ -156,7 +184,35 @@ const Edit = props => {
 		content = <Tabs { ...props } products={ products } />;
 	}
 
-	return <div { ...blockProps }>{ content }</div>;
+	// When the first time modal is closed, update the user meta to mark the donation warning as dismissed
+	const handleModalClose = async () => {
+		setShowFirstTimeModal( false );
+
+		if ( ! currentUser?.id ) {
+			// eslint-disable-next-line no-console
+			console.error( 'Cannot update user meta: User not loaded' );
+			return;
+		}
+
+		try {
+			await editEntityRecord( 'root', 'user', currentUser.id, {
+				meta: {
+					jetpack_donation_warning_dismissed: true,
+				},
+			} );
+			await saveEditedEntityRecord( 'root', 'user', currentUser.id );
+		} catch ( error ) {
+			// eslint-disable-next-line no-console
+			console.error( 'Failed to update user meta:', error );
+		}
+	};
+
+	return (
+		<div { ...blockProps }>
+			{ content }
+			{ showFirstTimeModal && <FirstTimeModal onClose={ handleModalClose } /> }
+		</div>
+	);
 };
 
 export default Edit;
diff --git a/projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js b/projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js
new file mode 100644
index 000000000000..60c741946251
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js
@@ -0,0 +1,62 @@
+import { Modal, Button } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+const FirstTimeModal = ( { onClose } ) => {
+	return (
+		<Modal
+			className="jetpack-donations-first-time-modal"
+			onRequestClose={ onClose }
+			title={ __( 'Accept Donations with Stripe', 'jetpack' ) }
+		>
+			<div className="jetpack-donations-first-time-modal__content">
+				<p>
+					{ __(
+						"To accept donations on your site, you'll need to connect your Stripe account. Here's what you need to do:",
+						'jetpack'
+					) }{ ' ' }
+					<a
+						href="https://wordpress.com/support/wordpress-editor/blocks/donations/#about-donations"
+						target="_blank"
+						rel="noopener noreferrer"
+					>
+						{ __( 'Learn more about donations.', 'jetpack' ) }
+					</a>
+				</p>
+				<ol>
+					<li>{ __( 'Connect your Stripe account to your WordPress.com account', 'jetpack' ) }</li>
+					<li>{ __( 'Set up your business information in Stripe', 'jetpack' ) }</li>
+					<li>{ __( 'Configure your payment settings and supported currencies', 'jetpack' ) }</li>
+				</ol>
+				<p>
+					{ __(
+						'Once connected, you can customize your donation form and start accepting payments.',
+						'jetpack'
+					) }
+				</p>
+				<p>
+					{ __(
+						'Please note that accepting donations has additional requirements from Stripe. Learn more about',
+						'jetpack'
+					) }
+					&nbsp;
+					<a
+						href="https://support.stripe.com/questions/requirements-for-accepting-tips-or-donations"
+						target="_blank"
+						rel="noopener noreferrer"
+					>
+						{ __( 'requirements for accepting donations', 'jetpack' ) }
+					</a>
+					.
+				</p>
+
+				<div className="jetpack-donations-first-time-modal__actions">
+					<Button variant="primary" onClick={ onClose }>
+						{ __( 'Got it', 'jetpack' ) }
+					</Button>
+				</div>
+			</div>
+		</Modal>
+	);
+};
+
+export default FirstTimeModal;
diff --git a/projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.scss b/projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.scss
new file mode 100644
index 000000000000..932c8a02323b
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.scss
@@ -0,0 +1,24 @@
+.jetpack-donations-first-time-modal {
+	&__content {
+		padding: 16px 0;
+
+		p {
+			margin-bottom: 16px;
+		}
+
+		ul {
+			margin: 16px 0;
+			padding-left: 24px;
+
+			li {
+				margin-bottom: 8px;
+			}
+		}
+	}
+
+	&__actions {
+		display: flex;
+		justify-content: flex-end;
+		margin-top: 24px;
+	}
+}


Reviews:
user: login: chrisfromthelc
body: Got the popup as expected on the first time, and no time afterwards.
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-10T21:51:37Z
user: login: simison
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-19T12:13:17Z
user: login: simison
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-19T12:16:07Z
user: login: n3f
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T17:05:54Z
user: login: simison
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-19T17:08:48Z

Review comments:
diff_hunk: @@ -0,0 +1,62 @@
+import { Modal, Button } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+const FirstTimeModal = ( { onClose } ) => {
+	return (
+		<Modal
+			className="jetpack-donations-first-time-modal"
+			onRequestClose={ onClose }
+			title={ __( 'Accept Donations with Stripe', 'jetpack' ) }
+		>
+			<div className="jetpack-donations-first-time-modal__content">
+				<p>
+					{ __(
+						"To accept donations on your site, you'll need to connect your Stripe account. Here's what you need to do:",
+						'jetpack'
+					) }{ ' ' }
+					<a
+						href="https://wordpress.com/support/wordpress-editor/blocks/donations/#about-donations"
+						target="_blank"
+						rel="noopener noreferrer"
+					>
+						{ __( 'Learn more about donations.', 'jetpack' ) }
+					</a>
+				</p>
+				<ol>
+					<li>{ __( 'Connect your Stripe account to your WordPress.com account', 'jetpack' ) }</li>
+					<li>{ __( 'Set up your business information in Stripe', 'jetpack' ) }</li>
+					<li>{ __( 'Configure your payment settings and supported currencies', 'jetpack' ) }</li>
+				</ol>
+				<p>
+					{ __(
+						'Once connected, you can customize your donation form and start accepting payments.',
+						'jetpack'
+					) }
+				</p>
+				<p>
+					{ __(
+						'Please note that accepting donations has additional requirements from Stripe. Learn more about',
+						'jetpack'
+					) }
+					&nbsp;
+					<a
+						href="https://support.stripe.com/questions/requirements-for-accepting-tips-or-donations"
+						target="_blank"
+						rel="noopener noreferrer"
+					>
+						{ __( 'requirements for accepting donations', 'jetpack' ) }
path: projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js
user: login: simison
body: You could use [`createInterpolateElement`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-element/#createinterpolateelement) to avoid partial strings, see PCYsg-3hI-p2#partial-strings-and-concatenation
created_at: 2025-03-19T12:13:17Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,62 @@
+import { Modal, Button } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+const FirstTimeModal = ( { onClose } ) => {
+	return (
+		<Modal
+			className="jetpack-donations-first-time-modal"
+			onRequestClose={ onClose }
+			title={ __( 'Accept Donations with Stripe', 'jetpack' ) }
+		>
+			<div className="jetpack-donations-first-time-modal__content">
+				<p>
+					{ __(
+						"To accept donations on your site, you'll need to connect your Stripe account. Here's what you need to do:",
+						'jetpack'
+					) }{ ' ' }
+					<a
+						href="https://wordpress.com/support/wordpress-editor/blocks/donations/#about-donations"
path: projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js
user: login: simison
body: Would be better if you used https://jetpack.com/support/jetpack-blocks/donations-block/ for Jetpack sites and above link for WP.com sites. Even better to rely on `getRedirectUrl` from `@automattic/jetpack-components` as is typical at Jetpack. :-)
created_at: 2025-03-19T12:16:07Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,62 @@
+import { Modal, Button } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+const FirstTimeModal = ( { onClose } ) => {
+	return (
+		<Modal
+			className="jetpack-donations-first-time-modal"
+			onRequestClose={ onClose }
+			title={ __( 'Accept Donations with Stripe', 'jetpack' ) }
+		>
+			<div className="jetpack-donations-first-time-modal__content">
+				<p>
+					{ __(
+						"To accept donations on your site, you'll need to connect your Stripe account. Here's what you need to do:",
+						'jetpack'
+					) }{ ' ' }
+					<a
+						href="https://wordpress.com/support/wordpress-editor/blocks/donations/#about-donations"
path: projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js
user: login: n3f
body: Thanks @simison I'll add these fixes next week (after a support rotation)!
created_at: 2025-03-19T17:05:54Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,62 @@
+import { Modal, Button } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+const FirstTimeModal = ( { onClose } ) => {
+	return (
+		<Modal
+			className="jetpack-donations-first-time-modal"
+			onRequestClose={ onClose }
+			title={ __( 'Accept Donations with Stripe', 'jetpack' ) }
+		>
+			<div className="jetpack-donations-first-time-modal__content">
+				<p>
+					{ __(
+						"To accept donations on your site, you'll need to connect your Stripe account. Here's what you need to do:",
+						'jetpack'
+					) }{ ' ' }
+					<a
+						href="https://wordpress.com/support/wordpress-editor/blocks/donations/#about-donations"
path: projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js
user: login: simison
body: Nothing urgent, thanks! :-)
created_at: 2025-03-19T17:08:48Z
author_association: MEMBER

PR comments:
user: login: github-actions[bot]
created_at: 2025-03-05T00:32:28Z
body: **Thank you for your PR!**

When contributing to Jetpack, we have [a few suggestions](https://github.com/Automattic/jetpack/blob/trunk/.github/PULL_REQUEST_TEMPLATE.md) that can help us test and review your patch:<br>
- :white_check_mark: Include a description of your PR changes.<br>
- :white_check_mark: Add a "[Status]" label (In Progress, Needs Review, ...).<br>
- :white_check_mark: Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).<br>
- :white_check_mark: Add testing instructions.<br>
- :white_check_mark: Specify whether this PR includes any changes to data or privacy.<br>
- :white_check_mark: Add changelog entries to affected projects<br>


This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation :robot:

******

**Follow this PR Review Process:**

1. Ensure all required checks appearing at the bottom of this PR are passing.
2. Make sure to test your changes on all platforms that it applies to. *You're responsible for the quality of the code you ship*.
3. You can use [GitHub's Reviewers functionality](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/requesting-a-pull-request-review) to request a review.
4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!
******

**Jetpack plugin:**

The Jetpack plugin has different release cadences depending on the platform:

- WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
- WoA releases happen weekly.
- Releases to self-hosted sites happen monthly:
    - Scheduled release: _April 1, 2025_
    - Code freeze: _March 30, 2025_


If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-03-05T00:46:59Z
body: <!-- wpcom-reminder-comment -->
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

- To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate [the Jetpack Beta plugin](https://jetpack.com/download-jetpack-beta/). Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the `donation/add-warning` branch.
- To test on Simple, run the following command on your sandbox:
```
bin/jetpack-downloader test jetpack donation/add-warning
```

*Interested in more tips and information?*

- In your local development environment, use the `jetpack rsync` command to sync your changes to a WoA dev blog.
- Read more about our development workflow here: PCYsg-eg0-p2
- Figure out **when your changes will be shipped to customers** here: PCYsg-eg5-p2
author_association: CONTRIBUTOR
user: login: jp-launch-control[bot]
created_at: 2025-03-05T00:54:25Z
body: ### Code Coverage Summary

Coverage changed in 2 files.

| File | Coverage | Δ% | Δ Uncovered |
| :--- | :------: | :---: | :---: |
| projects/plugins/jetpack/extensions/blocks/donations/edit.js | 0/86 (0.00%) | 0.00% | 20 💔 |
| projects/plugins/jetpack/extensions/blocks/donations/donations.php | 0/176 (0.00%) | 0.00% | 10 💔 |

1 file is newly checked for coverage.

| File | Coverage |
| :--- | :------: |
| projects/plugins/jetpack/extensions/blocks/donations/first-time-modal.js | 0/2 (0.00%) 💔 |



[Full summary](https://jetpackcodecoverage.atomicsites.blog/prs/42214/) · [PHP report](https://jetpackcodecoverage.atomicsites.blog/prs/42214/php/) · [JS report](https://jetpackcodecoverage.atomicsites.blog/prs/42214/js/)

<sub>Coverage check overridden by https://github.com/Automattic/jetpack/labels/I%20don%27t%20care%20about%20code%20coverage%20for%20this%20PR.</sub>
author_association: NONE