// No direct access to this file
defined('_JEXEC') or die('Restricted access');
$pathbase = JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_bookingforconnector' . DIRECTORY_SEPARATOR;
require_once $pathbase . 'defines.php';
require_once $pathbase . 'helpers/BFCHelper.php';
require_once $pathbase . 'helpers/wsQueryHelper.php';
$wsHelper = new wsQueryHelper(COM_BOOKINGFORCONNECTOR_WSURL, COM_BOOKINGFORCONNECTOR_APIKEY);
$checkUrl = $wsHelper->url_exists();
$result = null;
$resultOk = false;
$msg = "";
if ($checkUrl) {
    $options = array('path' => '/Checkstatus', 'data' => array('$format' => 'json'));
    $url = $wsHelper->getQuery($options);
    //$r = $this->helper->executeQuery($url);
    $r = $wsHelper->executeQuery($url);
    if (isset($r)) {
        $res = json_decode($r);
        //echo "<pre>";
        //echo print_r($res);
        //echo "</pre>";
        //
        if (!empty($res->d->results)) {
            $result = $res->d->results;
        } elseif (!empty($res->d)) {
            $result = $res->d;
        } elseif (!empty($res)) {
            $result = $res;
        }
    }
    if (!empty($result)) {
 public function getUrl()
 {
     $bankUrl = '';
     $data = 'id=' . $this->merchantNumber . '&password='******'&action=' . $this->action . '&amt=' . number_format($this->amt, 2, '.', '') . '&currencycode=' . $this->currencycode . '&langid=' . $this->langid . '&responseurl=' . $this->responseUrl . '&errorurl=' . $this->errorUrl . '&trackid=' . $this->trackid . '&udf1=' . $this->udf1 . '&udf4=' . $this->udf4;
     $this->dataSend = $this->paymentUrl . "?" . $data;
     $buffer = wsQueryHelper::executeQuery($this->dataSend, "POST", false);
     $token = explode(":", $buffer, 2);
     $tid = $token[0];
     $paymenturl = $token[1];
     $bankUrl = $paymenturl . "?PaymentID=" . $tid;
     /*salvo i dati inviati alla banca e cosa mi ritorna la banca come url di invio*/
     $this->donation = $donation;
     if (!$this->isdonation) {
         if (isset($this->suffixOrder) && $this->suffixOrder != "") {
             BFCHelper::setOrderStatus($this->orderId, null, false, false, $data . '&bankUrl=' . $bankUrl . '&paymentUrl=' . $this->paymentUrl);
         } else {
             BFCHelper::setOrderStatus($this->orderId, 1, false, false, $data . '&bankUrl=' . $bankUrl . '&paymentUrl=' . $this->paymentUrl);
         }
     }
     return $bankUrl;
 }