function CancelAmzFBAOrder($order_id)
{
    AmzFBA_Woo_Log("DEBUG", "Order", __FUNCTION__, "Entering");
    $level = "Neutral";
    $category = "Order";
    $title = "FBA Cancel Order - Woo ID:" . $order_id;
    AmzFBA_Woo_Log($level, $category, $title, "Canceling FBA order for Woo id " . $order_id);
    $MissingConfig = CheckForMissingConfig();
    if ($MissingConfig == true) {
        $returnmessage = 'Cancel FBA Order: Required configuration missing in Woo settings.';
        $order->add_order_note($returnmessage, 0);
        //Add to Log
        $level = "Bad";
        $title = "Cancel FBA Order - Order ID:" . $order_id;
        AmzFBA_Woo_Log($level, $category, $title, $returnmessage);
        return $returnmessage;
    }
    $FBAOrderID = get_post_meta($order_id, "FBA_OrderId", TRUE);
    AmzFBA_Woo_Log($level, $category, $title, "FBA order id = " . $FBAOrderID);
    if (empty($FBAOrderID) || $FBAOrderID == "") {
        $returnmessage = 'Cancel FBA Order: FBA Order id is missing.';
        $order->add_order_note($returnmessage, 0);
        //Add to Log
        $level = "Bad";
        $title = "Cancel FBA Order - Order ID:" . $order_id;
        AmzFBA_Woo_Log($level, $category, $title, $returnmessage);
        return $returnmessage;
    }
    $FBA_Status = get_post_meta($order_id, "FBA_Status", TRUE);
    AmzFBA_Woo_Log($level, $category, $title, "FBA  status = " . $FBA_Status);
    /*
        $fba_status_cancelable={'RECEIVED','PLANNING','PROCESSING','COMPLETED'};
    
        if (!in_array($FBA_Status, $fba_status_cancelable)) {
            $returnmessage = 'Cancel FBA Order: FBA Status is not cancelable';
            $order->add_order_note($returnmessage, 0);
            //Add to Log
            $level    = "Bad";
            $title    = "Cancel FBA Order - Order ID:" . $order_id;
            AmzFBA_Woo_Log($level, $category, $title, $returnmessage);
            return $returnmessage;
        }
    */
    $UserSettings = get_option('woocommerce_amazonfba_settings');
    $ChosenMarketplace = $UserSettings['AmzFBA_Marketplace'];
    $MWSEndpointURL = GetMWSEndpointURL('FulfillmentOutboundShipment', $ChosenMarketplace);
    $config = array('ServiceURL' => $MWSEndpointURL, 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3);
    $service = new FBAOutboundServiceMWS_Client(ACCESS_KEY_ID, SECRET_ACCESS_KEY, $config, APPLICATION_NAME, APPLICATION_VERSION);
    $request = new FBAOutboundServiceMWS_Model_CancelFulfillmentOrderRequest();
    $request->setSellerId(SELLER_ID);
    $request->setSellerFulfillmentOrderId($FBAOrderID);
    AmzFBA_Woo_Log($level, $category, $title, "Calling Amazon to cancel FBA order id " . $FBAOrderID);
    invokeCancelFulfillmentOrder($service, $request, $order_id, $FBAOrderID);
    update_post_meta($order_id, "FBA_Status", "Cancelling");
    AmzFBA_Woo_Log("DEBUG", "Order", __FUNCTION__, "Exiting");
}
 * Responses are loaded from local XML files. You can tweak XML files to
 * experiment with various outputs during development
 *
 * XML files available under FBAOutboundServiceMWS/Mock tree
 *
 ***********************************************************************/
// $service = new FBAOutboundServiceMWS_Mock();
/************************************************************************
 * Setup request parameters and uncomment invoke to try out
 * sample for Cancel Fulfillment Order Action
 ***********************************************************************/
// @TODO: set request. Action can be passed as FBAOutboundServiceMWS_Model_CancelFulfillmentOrder
$request = new FBAOutboundServiceMWS_Model_CancelFulfillmentOrderRequest();
$request->setSellerId(MERCHANT_ID);
// object or array of parameters
invokeCancelFulfillmentOrder($service, $request);
/**
 * Get Cancel Fulfillment Order Action Sample
 * Gets competitive pricing and related information for a product identified by
 * the MarketplaceId and ASIN.
 *
 * @param FBAOutboundServiceMWS_Interface $service instance of FBAOutboundServiceMWS_Interface
 * @param mixed $request FBAOutboundServiceMWS_Model_CancelFulfillmentOrder or array of parameters
 */
function invokeCancelFulfillmentOrder(FBAOutboundServiceMWS_Interface $service, $request)
{
    try {
        $response = $service->CancelFulfillmentOrder($request);
        echo "Service Response\n";
        echo "=============================================================================\n";
        $dom = new DOMDocument();