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
2 changes: 1 addition & 1 deletion assets/js/admin/whatsapp-billing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
26 changes: 26 additions & 0 deletions assets/js/admin/whatsapp-templates.js
Original file line number Diff line number Diff line change
@@ -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);
}
} );
});
} );
13 changes: 6 additions & 7 deletions includes/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down Expand Up @@ -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 ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( ! check_ajax_referer( 'facebook-for-wc-whatsapp-billing-nonce', 'nonce', false ) && ! check_ajax_referer( 'facebook-for-wc-whatsapp-templates-nonce', 'nonce', false ) ) {
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.' );
}

Expand Down Expand Up @@ -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.
*
Expand Down
17 changes: 17 additions & 0 deletions includes/Admin/Settings_Screens/Whatsapp_Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)
);
}


Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const jQueryUIAdminFileNames = [
'whatsapp-billing',
'whatsapp-connection',
'whatsapp-consent',
'whatsapp-templates',
'whatsapp-finish',
'whatsapp-consent-remove',
'whatsapp-events',
Expand Down