--- ./pg_roboxchange_old.module	2010-10-31 10:12:08.000000000 +0500
+++ ./pg_roboxchange_new.module	2011-02-01 18:56:28.831808002 +0500
@@ -6,7 +6,7 @@
  ********************************************************************/
 
 define("cRoboXchangeActionUrl" ,"https://merchant.roboxchange.com/Index.aspx");
-define("cRoboXchangeRateUrl"    ,"http://www.roboxchange.com/xml/rate.asp");
+define("cRoboXchangeRateUrl"    ,"https://merchant.roboxchange.com/WebService/Service.asmx/GetRates");
 define("XML_SERIALIZER_URL"    , "http://pear.php.net/package/XML_Serializer/");
 
 /********************************************************************
@@ -80,29 +80,32 @@ function pg_roboxchange_cron(){
   $unserializer = &new XML_Unserializer($unserializer_options);
 
 // make request
-$data = "<robox.rate.req>
-  <merchant_login>".variable_get('pg_roboxchange_mrh','')."</merchant_login>
-</robox.rate.req>";
-
   $ch = curl_init();
-  curl_setopt($ch, CURLOPT_URL, variable_get('pg_roboxchange_rate_url',cRoboXchangeRateUrl));
+  $url = variable_get('pg_roboxchange_rate_url',cRoboXchangeRateUrl)
+      ."?MerchantLogin=".variable_get('pg_roboxchange_mrh','testRobokassaTest')."&"
+      ."IncCurrLabel=&"
+      ."OutSum=1&" //In order to get rate value, count for 1 currency element
+      ."Language=ru";
+  curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_HEADER, 0);
-  curl_setopt($ch, CURLOPT_POST, 1);
-  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
-// CURLOPT_RETURNTRANSFER doesn't work
+  curl_setopt($ch, CURLOPT_POST, 0);
+  if (substr($url,0,5) == 'https') {
+    //required for https urls
+    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); 
+  }
   $fp = tmpfile();
   curl_setopt ($ch, CURLOPT_FILE, $fp);
   if (!curl_exec($ch)) {
-   form_set_error('rate_url', t('%err', array('%err' => curl_error($ch))));
+   form_set_error('rate_url', t('Error curl: %err', array('%err' => curl_error($ch))));
    return "";
   }
   curl_close($ch);
   fseek($fp,0,SEEK_SET);
 
   $result = $unserializer->unserialize($fp);
-
+  
   if(isset($result->message)){
-    form_set_error('rate_url', t('%err', array('%err' => $result->message)));
+    form_set_error('rate_url', t('Error result: %err', array('%err' => $result->message)));
     return "";
   }
 
@@ -114,12 +117,26 @@ $data = "<robox.rate.req>
   }
   switch($data['retval']){
     case 0:
-				variable_set('pg_roboxchange_out_curr',$data['out_curr']);
+        //variable_set('pg_roboxchange_out_curr',$data['out_curr']);
+        
 				variable_set('pg_roboxchange_last_update',$data['date']);
 				db_query("DELETE FROM {pg_roboxchange_rates}");
-				
-				foreach($data['ratelist']['rate'] as $key => $rate){
-				  db_query("INSERT INTO {pg_roboxchange_rates} (type,name,rate) VALUES ('%s','%s','%f')", $rate['in_curr'],$rate['in_curr_name'],$rate['value']);
+				foreach($data['Groups']['Group'] as $index_group => $currency_group){
+				  //if currency group have more than one item there's additional
+				  //array layer, so we have to check this out
+				  if (is_array($currency_group['Items']['Currency'][0])) {
+  				  foreach($currency_group['Items']['Currency'] as $index_item => $currency) {
+  				    db_query("INSERT INTO {pg_roboxchange_rates} (type,name,rate) VALUES ('%s','%s','%f')",
+                   $currency['Label'],$currency['Name'],$currency['Rate']['IncSum']
+              );
+  				  }
+          //else the whole group is just a currency record 
+          } else {
+            $currency = $currency_group['Items']['Currency'];
+            db_query("INSERT INTO {pg_roboxchange_rates} (type,name,rate) VALUES ('%s','%s','%f')",
+                   $currency['Label'],$currency['Name'],$currency['Rate']['IncSum']
+              );
+          }
 				}
 	    break;
     case -100:
@@ -303,3 +320,4 @@ function theme_pg_roboxchange_settings_t
   return $output;
 }
 
+
