Skip to content

Commit

Permalink
Merge pull request #2793 from woocommerce/release/3.2.8
Browse files Browse the repository at this point in the history
Release v3.2.8
  • Loading branch information
ibndawood authored Sep 3, 2024
2 parents 2cb1144 + d4cc696 commit 6c9621b
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 16 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*** Facebook for WooCommerce Changelog ***

= 3.2.8 - 2024-09-03 =
* Update - Access Token retrieval procedure.
* Update - Use get_title() for content_name to match catalog name.

= 3.2.7 - 2024-08-13 =
* Dev - Updated `phpcs` ruleset.
* Fix - Update failing due to undefined constant error in Lifecycle.
Expand Down
10 changes: 5 additions & 5 deletions facebook-commerce-events-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public function inject_view_content_event() {
$event_data = array(
'event_name' => 'ViewContent',
'custom_data' => array(
'content_name' => $product->get_title(),
'content_name' => \WC_Facebookcommerce_Utils::clean_string( $product->get_title() ),
'content_ids' => wp_json_encode( \WC_Facebookcommerce_Utils::get_fb_content_ids( $product ) ),
'content_type' => $content_type,
'contents' => wp_json_encode(
Expand Down Expand Up @@ -583,7 +583,7 @@ public function inject_add_to_cart_event( $cart_item_key, $product_id, $quantity
'event_name' => 'AddToCart',
'custom_data' => array(
'content_ids' => wp_json_encode( \WC_Facebookcommerce_Utils::get_fb_content_ids( $product ) ),
'content_name' => $product->get_name(),
'content_name' => \WC_Facebookcommerce_Utils::clean_string( $product->get_title() ),
'content_type' => 'product',
'contents' => wp_json_encode(
array(
Expand Down Expand Up @@ -655,7 +655,7 @@ public function add_add_to_cart_event_fragment( $fragments ) {

$params = array(
'content_ids' => wp_json_encode( \WC_Facebookcommerce_Utils::get_fb_content_ids( $product ) ),
'content_name' => $product->get_name(),
'content_name' => \WC_Facebookcommerce_Utils::clean_string( $product->get_title() ),
'content_type' => 'product',
'contents' => wp_json_encode(
array(
Expand Down Expand Up @@ -846,7 +846,7 @@ public function inject_purchase_event( $order_id ) {

if ( $product ) {
$product_ids[] = \WC_Facebookcommerce_Utils::get_fb_content_ids( $product );
$product_names[] = $product->get_name();
$product_names[] = \WC_Facebookcommerce_Utils::clean_string( $product->get_title() );

if ( 'product_group' !== $content_type && $product->is_type( 'variable' ) ) {
$content_type = 'product_group';
Expand Down Expand Up @@ -1061,7 +1061,7 @@ private function get_cart_content_names() {

if ( isset( $item['data'] ) && $item['data'] instanceof \WC_Product ) {

$product_names[] = $item['data']->get_name();
$product_names[] = \WC_Facebookcommerce_Utils::clean_string( $item['data']->get_title() );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions facebook-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Description: Grow your business on Facebook! Use this official plugin to help sell more of your products using Facebook. After completing the setup, you'll be ready to create ads that promote your products and you can also create a shop section on your Page where customers can browse your products on Facebook.
* Author: Facebook
* Author URI: https://www.facebook.com/
* Version: 3.2.7
* Version: 3.2.8
* Requires at least: 5.6
* Requires PHP: 7.4
* Text Domain: facebook-for-woocommerce
Expand Down Expand Up @@ -49,7 +49,7 @@ class WC_Facebook_Loader {
/**
* @var string the plugin version. This must be in the main plugin file to be automatically bumped by Woorelease.
*/
const PLUGIN_VERSION = '3.2.7'; // WRCS: DEFINED_VERSION.
const PLUGIN_VERSION = '3.2.8'; // WRCS: DEFINED_VERSION.

// Minimum PHP version required by this plugin.
const MINIMUM_PHP_VERSION = '7.4.0';
Expand Down
60 changes: 54 additions & 6 deletions includes/Handlers/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class Connection {
const OAUTH_URL = 'https://facebook.com/dialog/oauth';

/** @var string WooCommerce connection proxy URL */
const PROXY_URL = 'https://api.woocommerce.com/integrations/auth/facebook/';
const PROXY_URL = 'https://api.woocommerce.com/integrations/v2/auth/facebook/';

const PROXY_TOKEN_EXCHANGE_URL = 'https://api.woocommerce.com/integrations/v2/exchange/facebook/';

/** @var string WooCommerce connection for APP Store login URL */
const APP_STORE_LOGIN_URL = 'https://api.woocommerce.com/integrations/app-store-login/facebook/';
Expand All @@ -48,6 +50,8 @@ class Connection {
/** @var string the action callback for the connection */
const ACTION_CONNECT = 'wc_facebook_connect';

const ACTION_EXCHANGE = 'wc_facebook_exchange';

/** @var string the action callback for the disconnection */
const ACTION_DISCONNECT = 'wc_facebook_disconnect';

Expand Down Expand Up @@ -246,14 +250,58 @@ public function handle_connect() {
if ( empty( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['nonce'] ) ), self::ACTION_CONNECT ) ) {
throw new ApiException( 'Invalid nonce' );
}
$is_error = ! empty( $_GET['err'] ) ? true : false;
$error_code = ! empty( $_GET['err_code'] ) ? stripslashes( wc_clean( wp_unslash( $_GET['err_code'] ) ) ) : '';
$merchant_access_token = ! empty( $_GET['merchant_access_token'] ) ? wc_clean( wp_unslash( $_GET['merchant_access_token'] ) ) : '';
$system_user_access_token = ! empty( $_GET['system_user_access_token'] ) ? wc_clean( wp_unslash( $_GET['system_user_access_token'] ) ) : '';
$system_user_id = ! empty( $_GET['system_user_id'] ) ? wc_clean( wp_unslash( $_GET['system_user_id'] ) ) : '';

$is_error = ! empty( $_GET['err'] );
$error_code = ! empty( $_GET['err_code'] ) ? stripslashes( wc_clean( wp_unslash( $_GET['err_code'] ) ) ) : '';
if ( $is_error && $error_code ) {
throw new ConnectApiException( $error_code );
}

$facebook_auth_code = $_GET['code'] ?? '';
if ( empty( $facebook_auth_code ) ) {
throw new ApiException( 'Facebook auth code is missing.' );
}

$state = $_GET['state'] ?? '';
if ( empty( $state ) ) {
throw new ApiException( 'Missing state query parameter.' );
}

$parameters_string = '?' . http_build_query( array(
'nonce' => wp_create_nonce( self::ACTION_EXCHANGE ),
'code' => $facebook_auth_code,
'external_business_id' => $this->get_external_business_id(),
'type' => self::AUTH_TYPE_STANDARD,
'state' => $state,
) );

$request_url = self::PROXY_TOKEN_EXCHANGE_URL . $parameters_string;
$response = wp_safe_remote_get(
$request_url,
array(
'timeout' => 60,
)
);

if ( is_wp_error( $response ) ) {
throw new ApiException( 'WooCommerce Connect Server token exchange has failed.' );
}

$token_data = json_decode( wp_remote_retrieve_body( $response ), true );

if ( isset( $token_data[ 'status' ] ) && $token_data[ 'status' ] === 500 ) {
throw new ApiException( 'WooCommerce Connect Server token exchange has failed.' );
}

// Check that request was initiated from the server.
if ( ! wp_verify_nonce( $token_data['nonce'] ?? '', self::ACTION_EXCHANGE ) ) {
throw new ApiException( 'Exchange nonce is not valid.' );
}

$merchant_access_token = wc_clean( wp_unslash( $token_data['merchant_access_token'] ?? '' ) ) ;
$system_user_access_token = wc_clean( wp_unslash( $token_data['system_user_access_token'] ?? '' ) ) ;
$system_user_id = wc_clean( wp_unslash( $token_data['system_user_id'] ?? '' ) ) ;

if ( ! $merchant_access_token ) {
throw new ApiException( 'Access token is missing' );
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facebook-for-woocommerce",
"version": "3.2.7",
"version": "3.2.8",
"author": "Facebook",
"homepage": "https://woocommerce.com/products/facebook/",
"license": "GPL-2.0",
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: facebook, automattic, woothemes
Tags: facebook, woocommerce, marketing, product catalog feed, pixel
Requires at least: 5.6
Tested up to: 6.6
Stable tag: 3.2.7
Stable tag: 3.2.8
Requires PHP: 7.4
MySQL: 5.6 or greater
License: GPLv2 or later
Expand Down Expand Up @@ -40,6 +40,10 @@ When opening a bug on GitHub, please give us as many details as possible.

== Changelog ==

= 3.2.8 - 2024-09-03 =
* Update - Access Token retrieval procedure.
* Update - Use get_title() for content_name to match catalog name.

= 3.2.7 - 2024-08-13 =
* Dev - Updated `phpcs` ruleset.
* Fix - Update failing due to undefined constant error in Lifecycle.
Expand Down

0 comments on commit 6c9621b

Please sign in to comment.