<?php

namespace auctionforge\ajax;

use Exception;
use auctionforge\ajax\abs\AjaxHandler;
use auctionforge\inc\BidSpiritRequest;

class BidSpiritGate extends AJAXHandler
{
    function callback ()
    {
        check_ajax_referer( 'bp-ajax-string', 'security' );

        $this->setAction("account/getFavorites");
        $data = $this->bidSpiritData($_POST);

        $this->setAction($data["action"]);
        unset($data["action"]);

        $response = BidSpiritRequest::send($this->getAction(), $data);

        wp_send_json_success($response);
    }

    private function bidSpiritData($post) {
        if (!empty($post["bidSpirit"])) {
            return $post["bidSpirit"];
        } else {
            wp_send_json_error([
                "data" => "Data not set"
            ]);
        }
    }
}
$gate = new BidSpiritGate();
$gate->init('do_bidspirit');