Skip to content

Commit cd00f18

Browse files
committed
Added: methods for calculating price and terms of delivery
postReceiptCalculate postReceiptCalculateSimple
1 parent eb4ca20 commit cd00f18

2 files changed

Lines changed: 89 additions & 5 deletions

File tree

src/Delivery/DeliveryAutoApi2.php

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/DeliveryAutoApi2Test.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,23 @@ function testGetDeliveryScheme() {
137137
$result = $this->da->getDeliveryScheme();
138138
$this->assertTrue($result['status']);
139139
}
140+
141+
/**
142+
* Test PostReceiptCalculateSimple
143+
*/
144+
function testPostReceiptCalculateSimple() {
145+
// Random params, IDs from manual
146+
$result = $this->da->postReceiptCalculateSimple(
147+
'4fc948a7-3729-e311-8b0d-00155d037960',
148+
'e3ac6f68-3529-e311-8b0d-00155d037960',
149+
'1c828aa6-70c8-e211-9902-00155d037919',
150+
'd908c5e1-b36b-e211-81e9-00155d012a15',
151+
1000000,
152+
'13.06.2014',
153+
3,
154+
1,
155+
1
156+
);
157+
$this->assertTrue($result['status']);
158+
}
140159
}

0 commit comments

Comments
 (0)