File: //var/www/shoetique/wp-content/plugins/facebook-for-woocommerce/assets/js/admin/whatsapp-finish.js
/**
* 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 the whatsapp finish button click
$( '#wc-whatsapp-onboarding-finish' ).click( function( event ) {
// call the connect API to create configs and check payment
$.post( facebook_for_woocommerce_whatsapp_finish.ajax_url, {
action: 'wc_facebook_whatsapp_finish_onboarding',
nonce: facebook_for_woocommerce_whatsapp_finish.nonce
}, function ( response ) {
if ( response.success ) {
// If success, redirect to utility settings page
let url = new URL(window.location.href);
let params = new URLSearchParams(url.search);
params.set('view', 'utility_settings');
url.search = params.toString();
window.location.href = url.toString();
console.log( 'Whatsapp Connect Success', response );
} else {
var message;
const error = response.data;
console.log( 'Whatsapp Connect Failure', response );
switch (error) {
case "Incorrect payment setup":
message = facebook_for_woocommerce_whatsapp_finish.i18n.payment_setup_error;
break;
case "Onboarding is not complete or has failed.":
message = facebook_for_woocommerce_whatsapp_finish.i18n.onboarding_incomplete_error;
break;
default:
message = facebook_for_woocommerce_whatsapp_finish.i18n.generic_error;
}
const errorNoticeHtml = `
<div class="notice-error">
<p>${message}</p>
</div>
`;
$( '#payment-method-error-notice' ).html( errorNoticeHtml ).show();
}
} );
});
} );