<?php
$action = route(2,'ping');
$secret = route(3);

if(isset($config['woocommerce_webhooks_secret']) && $config['woocommerce_webhooks_secret'] != '')
{
    $woocommerce_webhooks_secret = $config['woocommerce_webhooks_secret'];
    if($secret != $woocommerce_webhooks_secret)
    {
        jsonResponse([
            'success' => false,
            'errors' => [
                'secret' => 'Invalid secret.'
            ]
        ]);
    }
}
else{
    jsonResponse([
        'success' => false,
        'errors' => [
            'secret' => 'Not configured.'
        ]
    ]);
}


switch ($action)
{
    case 'ping':

        echo 'ok';

        break;

    case 'customer-created':

        $data = $request->all();

        _log(json_encode($data));


        break;

    case 'customer-updated':

        break;

    case 'customer-deleted':

        break;

    case 'order-created':

        break;

    case 'order-updated':

        break;

    case 'order-deleted':

        break;

    case 'product-created':

        break;

    case 'product-updated':

        break;

    case 'product-deleted':

        break;


}