diff --git a/extensions/blocks/recurring-payments/edit.jsx b/extensions/blocks/recurring-payments/edit.jsx
index cc8237bd006fa..95ed555027624 100644
--- a/extensions/blocks/recurring-payments/edit.jsx
+++ b/extensions/blocks/recurring-payments/edit.jsx
@@ -1,13 +1,15 @@
/**
* External dependencies
*/
-
import classnames from 'classnames';
import SubmitButton from '../../shared/submit-button';
import apiFetch from '@wordpress/api-fetch';
import { __, sprintf } from '@wordpress/i18n';
import { trimEnd } from 'lodash';
import formatCurrency, { getCurrencyDefaults } from '@automattic/format-currency';
+import { addQueryArgs, getQueryArg, isURL } from '@wordpress/url';
+import { compose } from '@wordpress/compose';
+import { withSelect } from '@wordpress/data';
import {
Button,
@@ -91,7 +93,14 @@ class MembershipsButtonEdit extends Component {
const connected = result.connected_account_id
? API_STATE_CONNECTED
: API_STATE_NOTCONNECTED;
- this.setState( { connected, connectURL, products, shouldUpgrade, upgradeURL, siteSlug } );
+ this.setState( {
+ connected,
+ connectURL,
+ products,
+ shouldUpgrade,
+ upgradeURL,
+ siteSlug,
+ } );
},
result => {
const connectURL = null;
@@ -313,9 +322,36 @@ class MembershipsButtonEdit extends Component {
);
};
+ getConnectUrl() {
+ const { postId } = this.props;
+ const { connectURL } = this.state;
+
+ if ( ! postId || ! isURL( connectURL ) ) {
+ return null;
+ }
+
+ const state = getQueryArg( connectURL, 'state' );
+ let decodedState;
+
+ try {
+ decodedState = JSON.parse( atob( state ) );
+ } catch ( err ) {
+ if ( process.env.NODE_ENV !== 'production' ) {
+ console.error( err ); // eslint-disable-line no-console
+ }
+ return connectURL;
+ }
+
+ decodedState.from_editor_post_id = postId;
+
+ return addQueryArgs( connectURL, { state: btoa( JSON.stringify( decodedState ) ) } );
+ }
+
render = () => {
const { className, notices } = this.props;
- const { connected, connectURL, products } = this.state;
+ const { connected, products } = this.state;
+
+ const stripeConnectUrl = this.getConnectUrl();
const inspectorControls = (