Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

PayPal Payment Buttons: only register the onboarding endpoint while the API-managed buttons flag is on.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\Feature_Flags\Feature_Flags;

if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
Expand Down Expand Up @@ -126,6 +127,12 @@ public function __construct() {
* Register REST API routes.
*/
public function register_routes() {
// Hard-coded: mu-wpcom cannot reach PayPal_Payment_Buttons::API_MANAGED_BUTTONS_FLAG.
// Unregistered here, so only a `jetpack_feature_flag_enabled_*` filter flips it on wpcom.
if ( ! Feature_Flags::is_enabled( 'paypal-payments-api-managed-buttons' ) ) {
return;
}

register_rest_route(
$this->namespace,
$this->rest_base . '/signup-link',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,38 @@ private function token_response() {
* not collide with the editor-facing wpcom/v2/paypal/onboarding/signup-link
* that the paypal-payments package registers on these same hosts.
*/
/**
* The flag is unregistered here, so this also covers the unregistered-default path:
* only a `jetpack_feature_flag_enabled_*` filter can turn the route on.
*/
public function test_no_route_is_registered_while_the_flag_is_off() {
$routes = $this->build_routes();

$this->assertArrayNotHasKey( '/wpcom/v2/paypal/platform/signup-link', $routes );
}

public function test_the_route_is_registered_once_the_flag_is_on() {
add_filter( 'jetpack_feature_flag_enabled_paypal-payments-api-managed-buttons', '__return_true' );

$routes = $this->build_routes();

remove_all_filters( 'jetpack_feature_flag_enabled_paypal-payments-api-managed-buttons' );

$this->assertArrayHasKey( '/wpcom/v2/paypal/platform/signup-link', $routes );
}

/**
* Rebuild the route table from a fresh REST server, the way the package suite does.
*/
private function build_routes() {
global $wp_rest_server;
$wp_rest_server = null;

$routes = rest_get_server()->get_routes();

return $routes;
}

public function test_endpoint_is_registered_under_the_platform_path() {
$this->assertNotFalse(
has_action( 'rest_api_init', array( $this->endpoint, 'register_routes' ) ),
Expand Down
2 changes: 2 additions & 0 deletions projects/packages/paypal-payments/.gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ webpack.config.blocks.js production-exclude
/src/**/*.scss production-exclude
/src/**/*.jsx production-exclude
/src/paypal-payment-buttons/**/*.js production-exclude
/docs/** production-exclude
DEVELOPMENT.md production-exclude
19 changes: 19 additions & 0 deletions projects/packages/paypal-payments/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ jp docker up -d && jp docker install

Credentials are encrypted with `AUTH_KEY`, so a `wp-config.php` still carrying the `put your unique phrase here` placeholder will refuse to store them — generate real salts first. Then connect with sandbox credentials from [developer.paypal.com](https://developer.paypal.com/dashboard/applications/sandbox); the admin screen is at **Jetpack → Payment Links**, or **Settings → Payment Links** when Jetpack is not active.

### Turning on the API-managed buttons

The API-managed flow — the connection wizard, the `wpcom/v2/paypal/*` REST routes, and the Payment Links admin page — ships behind the `paypal-payments-api-managed-buttons` feature flag, off by default. While it is off the block shows the paste-code editor, and a button created through the API keeps rendering but is read-only in the editor.

On Jurassic Ninja, the Companion plugin toggles it:

```bash
wp companion feature-flag enable paypal-payments-api-managed-buttons
wp companion feature-flag list # read the `effective` column
```

In `jp docker`, or anywhere without Companion, force it from an mu-plugin:

```php
add_filter( 'jetpack_feature_flag_enabled_paypal-payments-api-managed-buttons', '__return_true' );
```

On WordPress.com Simple and Atomic, Automatticians can flip it under **Tools → Feature Flags**.

## Options and Transients

| Key | Kind | Holds |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Add a feature flag for the API-managed payment buttons; the block keeps the paste-code editor while it is off.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Significance: minor
Type: added

Add API-driven payment buttons: connect a PayPal account from WordPress, create and manage payment links without leaving the editor, choose a Button, Link, or QR format, and pick a Light, Auto, or Dark style preset.
Add API-managed payment buttons behind a feature flag that is not yet enabled. Once it is on, you can connect a PayPal account from WordPress, create and manage payment links without leaving the editor, choose a Button, Link, or QR format, and pick a Light, Auto, or Dark style preset.
1 change: 1 addition & 0 deletions projects/packages/paypal-payments/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"automattic/jetpack-assets": "@dev",
"automattic/jetpack-plans": "@dev",
"automattic/jetpack-connection": "@dev",
"automattic/jetpack-feature-flags": "@dev",
"automattic/jetpack-blocks": "@dev",
"automattic/jetpack-status": "@dev"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/packages/paypal-payments/docs/test_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Items marked 🔧 Manual are genuinely manual-only (accessibility, live PayPal A
| Install standalone plugin in WordPress Playground | 🔧 Manual (environment-dependent) |
| Insert block in new post — editor UI loads | 🔧 Manual (environment-dependent) |
| Open post with existing PayPal block — no "doesn't include support" error | 🔧 Manual (environment-dependent) |
| Block works in full Jetpack context (stub is no-op) | 🔧 Manual (environment-dependent) |
| Block works in full Jetpack context | 🔧 Manual (environment-dependent) |

---

Expand All @@ -218,7 +218,7 @@ These cannot be automated and require a human tester with the specified environm
- [ ] Standalone plugin installs cleanly in WordPress Playground
- [ ] Create a new post → insert PayPal Payment Buttons block → editor UI loads (no "doesn't include support" error)
- [ ] Open a post containing an existing PayPal block → block renders without error
- [ ] Same block works correctly in full Jetpack monorepo context (stub is a no-op when real `jetpack-script-data` handle is registered)
- [ ] Standalone and Playground load the real `jetpack-script-data` handle, so the editor gets `isWpcomPlatformSite`

### Live PayPal API (WOOPTP-163 + WOOPTP-164)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"buttonType": {
"type": "string",
"enum": [ "stacked", "single" ],
"default": "single"
"default": "stacked"
},
"scriptSrc": {
"type": "string",
Expand Down Expand Up @@ -136,8 +136,5 @@
"enum": [ "BUTTON", "LINK", "QR" ],
"default": "BUTTON"
}
},
"editorScript": "file:../../dist/paypal-payment-buttons/editor.js",
"editorStyle": "file:../../dist/paypal-payment-buttons/editor.css",
"style": "file:../../dist/paypal-payment-buttons/style.css"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ public static function count_published_embeds() {
return $counts;
}

/**
* Initialize admin hooks when the API-managed buttons are enabled.
*
* @since $$next-version$$
* @return void
*/
public static function maybe_init() {
if ( ! PayPal_Payment_Buttons::is_api_managed_enabled() ) {
return;
}

self::init();
}

/**
* Initialize admin hooks.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ class PayPal_Email_Sender {
*/
const AJAX_ACTION = 'paypal_send_payment_link';

/**
* Initialize AJAX hooks when the API-managed buttons are enabled.
*
* @since $$next-version$$
* @return void
*/
public static function maybe_init() {
if ( ! PayPal_Payment_Buttons::is_api_managed_enabled() ) {
return;
}

self::init();
}

/**
* Initialize AJAX hooks.
*/
Expand Down
Loading
Loading