diff --git a/assets/js/admin/whatsapp-billing.js b/assets/js/admin/whatsapp-billing.js index 755321b01..0a27ff830 100644 --- a/assets/js/admin/whatsapp-billing.js +++ b/assets/js/admin/whatsapp-billing.js @@ -26,7 +26,7 @@ jQuery( document ).ready( function( $ ) { $('#wc-whatsapp-add-payment').click(function(event) { $.post( facebook_for_woocommerce_whatsapp_billing.ajax_url, { - action: 'wc_facebook_whatsapp_fetch_billing_url_info', + action: 'wc_facebook_whatsapp_fetch_url_info', nonce: facebook_for_woocommerce_whatsapp_billing.nonce }, function ( response ) { if ( response.success ) { diff --git a/assets/js/admin/whatsapp-templates.js b/assets/js/admin/whatsapp-templates.js new file mode 100644 index 000000000..be01ba924 --- /dev/null +++ b/assets/js/admin/whatsapp-templates.js @@ -0,0 +1,26 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved + * + * This source code is licensed under the license found in the + * LICENSE file in the root directory of this source tree. + * + * @package FacebookCommerce + */ + +jQuery( document ).ready( function( $ ) { + // handle whatsapp view insights link click should open template insights in WhatsSpp Manager + $( '#woocommerce-whatsapp-manager-insights' ).click( function( event ) { + $.post( facebook_for_woocommerce_whatsapp_templates.ajax_url, { + action: 'wc_facebook_whatsapp_fetch_url_info', + nonce: facebook_for_woocommerce_whatsapp_templates.nonce + }, function ( response ) { + console.log(response); + if ( response.success ) { + var business_id = response.data.business_id; + var asset_id = response.data.waba_id; + const MANAGE_TEMPLATES_URL = `https://business.facebook.com/latest/whatsapp_manager/message_templates?business_id=${business_id}&asset_id=${asset_id}`; + window.open(MANAGE_TEMPLATES_URL); + } + } ); + }); +} ); diff --git a/includes/AJAX.php b/includes/AJAX.php index 9c62a907a..708e85c53 100644 --- a/includes/AJAX.php +++ b/includes/AJAX.php @@ -55,8 +55,8 @@ public function __construct() { // update the wp_options with wc_facebook_whatsapp_consent_collection_setting_status to enabled add_action( 'wp_ajax_wc_facebook_whatsapp_consent_collection_enable', array( $this, 'whatsapp_consent_collection_enable' ) ); - // fetch billing url info - waba id and business id - add_action( 'wp_ajax_wc_facebook_whatsapp_fetch_billing_url_info', array( $this, 'wc_facebook_whatsapp_fetch_billing_url_info' ) ); + // fetch url info - waba id and business id + add_action( 'wp_ajax_wc_facebook_whatsapp_fetch_url_info', array( $this, 'wc_facebook_whatsapp_fetch_url_info' ) ); // action to fetch required info and make api call to meta to finish onboarding add_action( 'wp_ajax_wc_facebook_whatsapp_finish_onboarding', array( $this, 'wc_facebook_whatsapp_finish_onboarding' ) ); @@ -188,15 +188,15 @@ public function get_sync_status() { } /** - * Get data for creating the billing hub url for whatsapp account. + * Get data for creating the billing or whatsapp manager url for whatsapp account. * * @internal * * @since 1.10.0 */ - public function wc_facebook_whatsapp_fetch_billing_url_info() { - facebook_for_woocommerce()->log( 'Fetching billing url info' ); - if ( ! check_ajax_referer( 'facebook-for-wc-whatsapp-billing-nonce', 'nonce', false ) ) { + public function wc_facebook_whatsapp_fetch_url_info() { + facebook_for_woocommerce()->log( 'Fetching url info for whatsapp pages' ); + if ( ! check_ajax_referer( 'facebook-for-wc-whatsapp-billing-nonce', 'nonce', false ) && ! check_ajax_referer( 'facebook-for-wc-whatsapp-templates-nonce', 'nonce', false ) ) { wp_send_json_error( 'Invalid security token sent.' ); } @@ -291,7 +291,6 @@ public function whatsapp_fetch_library_template_info() { } WhatsAppUtilityConnection::get_template_library_content( $bisu_token ); } - /** * Maybe triggers a modal warning when the merchant toggles sync enabled status in bulk. * diff --git a/includes/Admin/Settings_Screens/Whatsapp_Utility.php b/includes/Admin/Settings_Screens/Whatsapp_Utility.php index ed25dd777..355c83d18 100644 --- a/includes/Admin/Settings_Screens/Whatsapp_Utility.php +++ b/includes/Admin/Settings_Screens/Whatsapp_Utility.php @@ -170,6 +170,23 @@ public function enqueue_assets() { ), ) ); + wp_enqueue_script( + 'facebook-for-woocommerce-whatsapp-templates', + facebook_for_woocommerce()->get_asset_build_dir_url() . '/admin/whatsapp-templates.js', + array( 'jquery', 'jquery-blockui', 'jquery-tiptip', 'wc-enhanced-select' ), + \WC_Facebookcommerce::PLUGIN_VERSION + ); + wp_localize_script( + 'facebook-for-woocommerce-whatsapp-templates', + 'facebook_for_woocommerce_whatsapp_templates', + array( + 'ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'facebook-for-wc-whatsapp-templates-nonce' ), + 'i18n' => array( + 'result' => true, + ), + ) + ); } diff --git a/webpack.config.js b/webpack.config.js index 12b955c2c..df74e1c8c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -16,6 +16,7 @@ const jQueryUIAdminFileNames = [ 'whatsapp-billing', 'whatsapp-connection', 'whatsapp-consent', + 'whatsapp-templates', 'whatsapp-finish', 'whatsapp-consent-remove', 'whatsapp-events',