VirtueMart Forum

VirtueMart General => Commercial Jobs => Topic started by: billthecat on February 25, 2012, 02:28:03 AM

Title: Needing help with examples, for me to continue through
Post by: billthecat on February 25, 2012, 02:28:03 AM
Hi,
I want to sell services through Virtuemart, which are tied to another system via HTTPS REST requests.  So when a customer purchases a service, after payment the request is processed through cURL and a record of it saved to the Joomla database.  And this is neither physical goods nor downloadable files, so I will need a way to prevent shipping or download options...I assume that's through the templates, but I'm not positive.  Please let me know how that works, also.

Essentially the order process would work like this:

$neworder = https://testapisite/newaccount/add.xml
$fields = array(
'name' => $name,
'customerid' => $customerid,
'months'=> $planid
);
function save_order($neworder,$fields) {
$fields_string = '';
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection

$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$neworder);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute POST
$result = curl_exec($ch);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
$db = JFactory::getDBO();
$data =new stdClass();
$data->name;
$data->customerid;
$data->months;
if (!$db->insertObject( '#__customers', $data)) {
echo $db->stderr();
return false;
} else {
return true;
}
} else {
return false;
}
}