From a72a7c4a8ebea2deeaa0fda75d2d5d12aed749c6 Mon Sep 17 00:00:00 2001 From: artpi Date: Wed, 27 Mar 2019 16:41:39 +0100 Subject: [PATCH] Make it work --- .../core-api/wpcom-endpoints/memberships.php | 5 +-- extensions/blocks/membership-button/edit.jsx | 32 +++++++++---------- .../memberships/class-jetpack-memberships.php | 4 +-- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/_inc/lib/core-api/wpcom-endpoints/memberships.php b/_inc/lib/core-api/wpcom-endpoints/memberships.php index 00b3536cc6386..9aa6232df98f3 100644 --- a/_inc/lib/core-api/wpcom-endpoints/memberships.php +++ b/_inc/lib/core-api/wpcom-endpoints/memberships.php @@ -79,7 +79,7 @@ public function create_product( $request ) { $blog_id = Jetpack_Options::get_option( 'id' ); $response = Jetpack_Client::wpcom_json_api_request_as_blog( "/sites/$blog_id/{$this->rest_base}/product", - 'v2', + '2', array( 'method' => 'POST', ), @@ -88,7 +88,8 @@ public function create_product( $request ) { 'price' => $request['price'], 'currency' => $request['currency'], 'interval' => $request['interval'], - ) + ), + 'wpcom' ); if ( is_wp_error( $response ) ) { return new WP_Error( 'wpcom_connection_error', 'Could not connect to WP.com', 404 ); diff --git a/extensions/blocks/membership-button/edit.jsx b/extensions/blocks/membership-button/edit.jsx index b345a55d7af08..d72df86989046 100644 --- a/extensions/blocks/membership-button/edit.jsx +++ b/extensions/blocks/membership-button/edit.jsx @@ -63,16 +63,12 @@ class MembershipsButtonEdit extends Component { const fetch = { path, method }; apiFetch( fetch ).then( result => { - this.setState( { - products: this.state.products.concat( [ - { - id: result.id, - title: result.title, - interval: result.interval, - price: result.price, - }, - ] ), - } ); + const connectURL = result.connect_url; + const products = result.products; + const connected = result.connected_account_id + ? API_STATE_CONNECTED + : API_STATE_NOTCONNECTED; + this.setState( { connected, connectURL, products } ); } // result => { // const connectURL = null; @@ -117,12 +113,16 @@ class MembershipsButtonEdit extends Component { const fetch = { path, method, data }; apiFetch( fetch ).then( result => { - const connectURL = result.connect_url; - const products = result.products; - const connected = result.connected_account_id - ? API_STATE_CONNECTED - : API_STATE_NOTCONNECTED; - this.setState( { connected, connectURL, products } ); + this.setState( { + products: this.state.products.concat( [ + { + id: result.id, + title: result.title, + interval: result.interval, + price: result.price, + }, + ] ), + } ); } // result => { // const connectURL = null; diff --git a/modules/memberships/class-jetpack-memberships.php b/modules/memberships/class-jetpack-memberships.php index 75b1e814ac880..2b53037ab4c3d 100644 --- a/modules/memberships/class-jetpack-memberships.php +++ b/modules/memberships/class-jetpack-memberships.php @@ -17,7 +17,7 @@ class Jetpack_Memberships { * * @var string */ - static private $css_classname_prefix = 'jetpack-memberships'; + static public $css_classname_prefix = 'jetpack-memberships'; /** * Increase this number each time there's a change in CSS or JS to bust cache. * @@ -245,7 +245,7 @@ public function render_button( $attrs ) { $button_styles, sprintf( 'color: %s', - sanitize_hex_color( $attr['customTextButtonColor'] ) + sanitize_hex_color( $attrs['customTextButtonColor'] ) ) ); }