<?php

class Ambient_Routee_Helper_Data extends Mage_Core_Helper_Abstract {

    public function creteuuid() {
        $requestcont = array();
        $requestcont['username'] = Mage::getStoreConfig('routeesection/routeegroup/routee_username');
        $requestcont['password'] = Mage::getStoreConfig('routeesection/routeegroup/routee_pwd');
        $requestcont['source'] = "Magento";
        $requestcont['type'] = "E-COMMERCE";
        $requestcont['version'] = Mage::getVersion();
        $requestcont['domain'] = Mage::getBaseUrl();

        $json = Mage::helper('core')->jsonEncode($requestcont);

        $url = "https://waymore.routee.net/api/authenticate";

        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        curl_setopt($c, CURLOPT_POST, true);
        curl_setopt($c, CURLOPT_POSTFIELDS, $json);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($c, CURLOPT_TIMEOUT, 30);
        $response = curl_exec($c);
        curl_close($c);
        
        $result = Mage::helper('core')->jsonDecode($response);

        return $result['uuid'];
    }

}
