Skip to content

Move Simple Payments to PayPal Payments package #43413

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

Draft
wants to merge 42 commits into
base: trunk
Choose a base branch
from

Conversation

allie500
Copy link
Contributor

@allie500 allie500 commented May 8, 2025

Fixes PAYPAL-13

Proposed changes:

  • This PR moves the Simple Payments block code to the PayPal Payments package.

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

Does this pull request change what data or activity we track or use?

Testing instructions:

  • TBD
Copy link
Contributor

github-actions bot commented May 8, 2025

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. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the update/move-simple-payments-to-paypal-payments-pkg branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/move-simple-payments-to-paypal-payments-pkg
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/move-simple-payments-to-paypal-payments-pkg

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
@github-actions github-actions bot added [Block] Pay With Paypal aka Simple Payments [Package] Paypal Payments [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests Docs labels May 8, 2025
Copy link
Contributor

github-actions bot commented May 8, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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 🤖


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 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: June 3, 2025
    • Code freeze: June 2, 2025

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

@allie500 allie500 changed the title Update/move simple payments to paypal payments pkg May 8, 2025
@allie500
Copy link
Contributor Author

allie500 commented May 8, 2025

@jeherve, so far I've only moved and lightly modified the Simple Payments block code. I see there is also a simple-payments directory within the jetpack/projects/plugins/jetpack/modules directory:
https://github.com/Automattic/jetpack/tree/update/move-simple-payments-to-paypal-payments-pkg/projects/plugins/jetpack/modules/simple-payments

Should I make a modules directory in projects/packages/paypal-payments and move the three files there? Or would it be better to simply move the three files directly into the projects/packages/paypal-payments directory?

Thanks in advance for your feedback!

Copy link

jp-launch-control bot commented May 8, 2025

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/modules/simple-payments/simple-payments.php 0/373 (0.00%) 0.00% 17 💔
projects/plugins/jetpack/modules/module-headings.php 206/1000 (20.60%) 0.08% 0 💚
projects/plugins/jetpack/modules/widgets/simple-payments.php 0/3 (0.00%) 0.00% -281 💚

4 files are newly checked for coverage.

File Coverage
projects/packages/paypal-payments/src/block/simple-payments.php 0/36 (0.00%) 💔
projects/packages/paypal-payments/src/legacy/class-simple-payments.php 0/371 (0.00%) 💔
projects/packages/paypal-payments/src/widget/class-simple-payments-widget.php 0/277 (0.00%) 💔
projects/plugins/jetpack/modules/simple-payments.php 0/3 (0.00%) 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@jeherve
Copy link
Member

jeherve commented May 9, 2025

That's going to be a multi-step process I think. Here is how I would personally go about it, but that's just my personal opinion, feel free to take a different approach :)

The main entry point for the whole functionality is projects/plugins/jetpack/modules/simple-payments/simple-payments.php. I would recommend copying this to the package first, alongside the related files in that projects/plugins/jetpack/modules/simple-payments/ directory.

Once that's ported to the package, we can start requiring the package in the Jetpack plugin's composer.json file, stop requiring the file here:

'simple-payments/simple-payments.php',

And instead create a new modules/simple-payments.php file that would instantiate the class from the package.

Once that's done, you could copy the contents of projects/plugins/jetpack/modules/widgets/simple-payments.php to the package, and then replace the contents of that widget file by a call to the same code in the package.

Then, the next step would be to copy the actual block from projects/plugins/jetpack/extensions/blocks/simple-payments/ into a new dir in the package, and create the webpack config file to build it, so you get build files that we'll be able to require in the Jetpack plugin and later on in the new standalone plugin. The Forms package has an example you could follow. Here is their webpack file for example: projects/packages/forms/tools/webpack.config.blocks.js.
Once you have that set up, you would probably create a new class in the package, that would handle registering that block. You can see the Contact_Form_Block for an example of a block that lives in a package, is registered in a package, and then registration is called from the Jetpack plugin in projects/plugins/jetpack/extensions/blocks/contact-form/contact-form.php.

Once that's all done, you'll be able to deprecate the old classes from the Jetpack plugin, and they could then be removed entirely in a few releases.

At that point, you'll have a standalone package with code that can register a block, register a widget, and you'll be able to register that block or that widget from the Jetpack plugin and also from any other standalone plugin we create in the future.

Let me know if that makes sense.

@allie500
Copy link
Contributor Author

@jeherve I'm finally getting back over to this. Thanks so much for the detailed guidance. I'm going to follow that to get this moving forward.

@allie500
Copy link
Contributor Author

That's going to be a multi-step process I think. Here is how I would personally go about it, but that's just my personal opinion, feel free to take a different approach :)

The main entry point for the whole functionality is projects/plugins/jetpack/modules/simple-payments/simple-payments.php. I would recommend copying this to the package first, alongside the related files in that projects/plugins/jetpack/modules/simple-payments/ directory.

Once that's ported to the package, we can start requiring the package in the Jetpack plugin's composer.json file, stop requiring the file here:

'simple-payments/simple-payments.php',

And instead create a new modules/simple-payments.php file that would instantiate the class from the package.

@jeherve I have completed all of the above. At this point, I have tried running the PHP unit tests for Jetpack plugin just to make sure everything is working. The tests fail to run with the error:

Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
- Required package "automattic/jetpack-paypal-payments" is not present in the lock file.

I think at this point, I would need to publish the package to Packagist as the lock file doesn't get updated if I run composer update. I would publish using the PayPal Payments mirror repo, correct?

@github-actions github-actions bot added the [Feature] Pay with PayPal aka Simple Payments label May 13, 2025
@allie500
Copy link
Contributor Author

I just realized I totally skipped a command to properly add the package to the Jetpack plugin's composer.json file. I've run that and now I've got the lock file updated as well.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

I think at this point, I would need to publish the package to Packagist as the lock file doesn't get updated if I run composer update. I would publish using the PayPal Payments mirror repo, correct?

I took care of that in the last PR, when you introduced the package skeleton. The package lives here:
https://packagist.org/packages/automattic/jetpack-paypal-payments

UndefError PhanUndeclaredConstant Reference to undeclared constant \JETPACK__VERSION

Now that this lives in the package, you can use the package version (PACKAGE_VERSION) instead.

plugins_url

You may have to make some changes where scripts and styles are registered, since the files are no longer in the same location. Assets::register_script() can be a good replacement at times.

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend against moving the files ; I would suggest copying instead, and marking the different classes and methods that are left in the Jetpack plugin as deprecated with _deprecated_function. It will make it easier to spot anything we've left behind, and it will also ensure we do not create fatal errors on plugin update, for sites that have aggressive caching setups and that may continue to require a file that no longer exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Should I revert all my commits from yesterday and re-do all the steps but instead of moving the files, just copy them over and modify both sets as needed?

For the old ones mark them with _deprecated_function, and the new files in the package make needed changes to register assets, update constants, etc etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the simple-payments module directory and the three files within it in 72901a9.

I deprecated all the public functions in projects/plugins/jetpack/modules/simple-payments/simple-payments.php in 5ece6e7.

* @package automattic/jetpack
*/

require_once __DIR__ . '/../packages/paypal-payments/class-simple-payments.php';
Copy link
Member

Choose a reason for hiding this comment

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

That won't work on production since the required package will not live in this directory in the production version of the plugin.

Since the package will be autoloaded, you do not have to worry about requiring the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the require_once statement in 0169271.

That said, do I need to add a use statement to import the correct one? After removing the require_once my IDE is showing it using the Jetpack_Simple_Payments::get_instance(); from the deprecated class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added that use statement to get it to use the correct class in 0b47eca.

@@ -34,7 +34,6 @@
'external-media/external-media.php',
'plugin-search.php',
'scan/scan.php', // Shows Jetpack Scan alerts in the admin bar if threats found.
'simple-payments/simple-payments.php',
Copy link
Member

Choose a reason for hiding this comment

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

Here I would recommend that you replace loading the file by loading the module file, 'simple-payments.php'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this! Updated in a042df9.

Update style and script registration
@allie500
Copy link
Contributor Author

allie500 commented May 14, 2025

@jeherve I think I may have a mis-configuration in the package's phan config. It is throwing errors for things that I haven't changed in the file that weren't being flagged in the file when it was part of the Jetpack plugin.

projects/packages/paypal-payments/class-simple-payments.php:131
Error: TypeError PhanTypeMismatchArgument Argument 5 ($media) is false of type false but \wp_register_style() takes string defined at /home/runner/work/jetpack/jetpack/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php:114599

And it is complaining about undeclared classes, but if I had the namespace to them, my IDE complains that those classes don't exist and Phan still flags them. 🤔

projects/packages/paypal-payments/class-simple-payments.php:115
Error: UndefError PhanUndeclaredClassMethod Call to method register_script from undeclared class \Automattic\Jetpack\Assets
projects/packages/paypal-payments/class-simple-payments.php:238
Error: UndefError PhanUndeclaredClassMethod Call to method is_connection_ready from undeclared class \Jetpack

Maybe I'm just missing a simple setting somewhere?

@jeherve
Copy link
Member

jeherve commented May 15, 2025

As we discussed in Slack:

  • Moving the new files into src will help.
  • Since you're introducing new files, you will indeed need to fix those issues reported by Phan, and then run jetpack phan --update-baseline packages/paypal-payments.
Comment on lines 12 to 13
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
Copy link
Member

Choose a reason for hiding this comment

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

Since you're using specific packages inside the PayPal Payments package, you would need to add them as dependencies to the PayPal Payments package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. Addressed in ceccdd8.

Comment on lines 14 to 16
use Jetpack;
use Jetpack_Components;
use Jetpack_Currencies;
Copy link
Member

Choose a reason for hiding this comment

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

Those Jetpack-the-plugin specific dependencies aren't great. That means you won't be able to use that class on a site that doesn't run the Jetpack plugin.

I think we'll need to replace them by functionality available in packages, or move those classes to packages to be able to use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in Slack, I've added a check in get_instance() to bail if this classes don't exist in 302ea6d.

* Simple_Payments
*/
class Simple_Payments {
// These have to be under 20 chars because that is CPT limit.
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a left-over from something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was. I forgot to remove it. Removed in 83ee3d0.

Comment on lines 75 to 85
/**
* Original singleton.
*
* @todo Remove this when nothing calles getInstance anymore.
*
* @deprecated 10.8
*/
public static function getInstance() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
_deprecated_function( __METHOD__, 'Jetpack 10.7.0', 'Simple_Payments::get_instance' );
return self::get_instance();
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this in the new class in the package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't. I removed it in 83ee3d0.

class Simple_Payments {
// These have to be under 20 chars because that is CPT limit.

const PACKAGE_VERSION = '0.1.0-alpha';
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the PACKAGE_VERSION from the main PayPal_Payments class here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we should do that. Thanks for catching this. Addressed in 83ee3d0.

}

return ( ( defined( 'IS_WPCOM' ) && IS_WPCOM )
|| Jetpack::is_connection_ready() )
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to switch to relying on the Connection package for this (and thus require the connection package in the PayPal Payments package).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for flagging this and sharing the Connection package. I've added the package as a dependency in 1632a85.

I've replaced the method call in e784072.

$data['id'] = $attrs['id'];

if ( ! $this->is_enabled_jetpack_simple_payments() ) {
if ( jetpack_is_frontend() ) {
Copy link
Member

Choose a reason for hiding this comment

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

this is a Jetpack-the-plugin only function. I think you'll need to move it to a package to start using it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a check in get_instance() for this function. If it doesn't exist it returns null. Added in 302ea6d.

@allie500
Copy link
Contributor Author

Copying the Simple Payments block code to the package in this commit is the cause of unrelated extensions' JS tests to fail. I haven't been able to track down the root cause.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be removed. It's an npm lockfile, and we use pnpm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for flagging it. I probably accidentally ran npm at some point instead of pnpm. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in d12889d.

@allie500
Copy link
Contributor Author

allie500 commented May 16, 2025

Copying the Simple Payments block code to the package in this commit is the cause of unrelated extensions' JS tests to fail. I haven't been able to track down the root cause.

I got some assistance in Slack (p1747425409956389/1746628203.330399-slack-CDLH4C1UZ) to figure out my error. Some of the dependencies in the package didn't match the dependencies in the the Jetpack plugin. This caused issues. I've addressed it in ff0eb51. Tests are passing for me locally now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants