@@ -117,16 +117,28 @@ private function prepare($data) {
117117 *
118118 * @param string $model Model name
119119 * @param string $method Method name
120+ * @param bool $curl Use curl for request
120121 * @param array $params Required params
121122 */
122- private function request ($ model , $ method , $ params = NULL ) {
123+ private function request ($ model , $ method , $ params = NULL , $ curl = FALSE ) {
123124 // Get json result
124125 $ params ['culture ' ] = $ this ->culture ;
125- $ uri_part = '' ;
126- foreach ($ params as $ value => $ param ) {
127- $ uri_part .= $ value .'= ' .$ param .'& ' ;
126+ $ url = 'http://www.delivery-auto.com.ua/api/v2 ' ;
127+ if ($ curl ) {
128+ $ ch = curl_init ($ url .'/ ' .$ model .'/ ' .$ method );
129+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
130+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , array ('Content-Type: application/json ' ));
131+ curl_setopt ($ ch , CURLOPT_HEADER , 0 );
132+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 0 );
133+ // curl_setopt($ch, CURLOPT_POST, 1);
134+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ($ params ));
135+ $ result = curl_exec ($ ch );
136+ curl_close ($ ch );
137+ } else {
138+ $ uri_part = http_build_query ($ params );
139+ $ result = file_get_contents ($ url .'/ ' .$ model .'/ ' .$ method .'? ' .$ uri_part );
128140 }
129- $ result = file_get_contents ( ' http://www.delivery-auto.com.ua/api/ ' . $ model . ' / ' . $ method . ' ? ' . $ uri_part );
141+
130142 return $ this ->prepare ($ result );
131143 }
132144
@@ -319,4 +331,57 @@ function getTariffCategory() {
319331 function getDeliveryScheme () {
320332 return $ this ->request ('Public ' , 'GetDeliveryScheme ' );
321333 }
334+
335+ /**
336+ * Calculate price of shipping
337+ *
338+ * @param array $params Params for shipping. Required fields:
339+ * areasSendId => string, areasResiveId => string, warehouseSendId => string, warehouseResiveId => string, InsuranceValue => float,
340+ * dateSend => string (format 13.06.2014), deliveryScheme => int,
341+ * category => array(array(
342+ * categoryId => string, countPlace => int, helf => int, size => int
343+ * ))
344+ *
345+ * @return mixed
346+ */
347+ function postReceiptCalculate ($ params ) {
348+ return $ this ->request ('Public ' , 'PostReceiptCalculate ' , $ params , TRUE );
349+ }
350+
351+ /**
352+ * Calculate price of shipping (simplest method. only required fields)
353+ *
354+ * @param string $areasSendId Sender City ID
355+ * @param string $areasResiveId Recipient City ID
356+ * @param string $warehouseSendId Sender Warehouse ID
357+ * @param string $warehouseResiveId Recipient Warehouse ID
358+ * @param float $InsuranceValue Insurance value for parcel, price of goods
359+ * @param string $dateSend Date of shipping, format 13.06.2014
360+ * @param int $countPlace Count of places
361+ * @param ing $weight Weight
362+ * @param string $volume Size at m^3
363+ *
364+ * @return mixed
365+ */
366+ function postReceiptCalculateSimple ($ areasSendId , $ areasResiveId , $ warehouseSendId , $ warehouseResiveId ,
367+ $ InsuranceValue , $ dateSend , $ countPlace , $ weight , $ volume ) {
368+ return $ this ->postReceiptCalculate (array (
369+ 'areasSendId ' => $ areasSendId ,
370+ 'areasResiveId ' => $ areasResiveId ,
371+ 'warehouseSendId ' => $ warehouseSendId ,
372+ 'warehouseResiveId ' => $ warehouseResiveId ,
373+ 'InsuranceValue ' => (float ) $ InsuranceValue ,
374+ 'dateSend ' => $ dateSend ,
375+ 'deliveryScheme ' => 2 ,
376+ 'category ' => array (
377+ array (
378+ 'categoryId ' => "00000000-0000-0000-0000-000000000000 " ,
379+ 'countPlace ' => $ countPlace ,
380+ 'helf ' => $ weight ,
381+ 'size ' => $ volume ,
382+ ),
383+ )
384+ ));
385+ }
386+
322387}
0 commit comments