File "dbx_dpd.php"
Full path: /home/kosmetik/public_html/api/dpd/dbx_dpd.php
File
size: 7.29 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
class DPD_API
{
protected function send_dbx_data($data = null, $endpoint = null)
{
if ($data != null && $endpoint != null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.dpd.ro/v1/' . $endpoint);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$server_output = curl_exec($ch);
$httpcode = curl_getinfo($ch);
curl_close($ch);
return $server_output;
}
}
public function calculeaza($site_id = null)
{
$service = array('pickupDate' => $_REQUEST['pickup_date'], 'autoAdjustPickupDate' => 'true', 'saturdayDelivery' => $_REQUEST['saturday'], 'serviceIds' => array($_REQUEST['service_id']), 'additionalServices' => array('cod' => array('amount' => $_REQUEST['val_ramburs'], 'currency' => $_REQUEST['currency']), 'declaredValue' => array('amount' => $_REQUEST['val_decl'], 'fragile' => $_REQUEST['fragile'])));
$recipient = array('privatePerson' => $_REQUEST['private'], 'addressLocation' => array('siteId' => $site_id, 'postcode' => $_REQUEST['postcode']));
$content = array('parcelsCount' => $_REQUEST['nr_colete'], 'totalWeight' => $_REQUEST['greutate']);
$payment = array('courierServicePayer' => $_REQUEST['payer']);
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'service' => $service, 'recipient' => $recipient, 'content' => $content, 'payment' => $payment);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'calculate');
}
public function tracking_awb()
{
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'lastOperationOnly' => $_REQUEST['last_only'], 'parcels' => array(array('id' => $_REQUEST['awb_id'])));
$data = json_encode($awb_data);
$rasp = $this->send_dbx_data($data, 'track');
return $rasp;
}
public function pickup_dpd()
{
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'visitEndTime' => $_REQUEST['end_time'], 'pickupScope' => 'ALL_CREATED_BY_SAME_CONTRACT_USERS', 'autoAdjustPickupDate' => $_REQUEST['auto_adjust']);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'pickup');
}
public function get_contract()
{
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd']);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'client/contract');
}
public function findOffice($site_id = null)
{
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'countryId' => $_REQUEST['countryId'], 'siteId' => $site_id, 'limit' => $_REQUEST['limit']);
$data = json_encode($awb_data);
var_dump($data);
exit;
return $this->send_dbx_data($data, 'location/office');
}
public function findSite()
{
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'countryId' => $_REQUEST['countryId'], 'name' => $_REQUEST['site_name'], 'region' => $_REQUEST['region']);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'location/site');
}
public function delete_awb()
{
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'shipmentId' => $_REQUEST['awb_id'], 'comment' => $_REQUEST['comment']);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'shipment/cancel');
}
public function get_services()
{
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd']);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'services');
}
public function create_awb()
{
$additionalServices = array('cod' => array('amount' => $_REQUEST['cod_amount'], 'currencyCode' => $_REQUEST['currency']));
$service_data = array('serviceId' => $_REQUEST['service_id'], 'autoAdjustPickupDate' => 'true', 'additionalServices' => $additionalServices);
$content = array('parcelsCount' => $_REQUEST['parcels_no'], 'pendingParcels' => 'false', 'totalWeight' => $_REQUEST['weight'], 'contents' => $_REQUEST['content'], 'package' => 'BOX');
$payment = array('courierServicePayer' => $_REQUEST['payer']);
$recipient = array('phone1' => array('number' => $_REQUEST['phone_no']), 'privatePerson' => $_REQUEST['private'], 'clientName' => $_REQUEST['client_name'], 'contactName' => $_REQUEST['contact_name'], 'email' => $_REQUEST['email'], 'address' => array('siteName' => $_REQUEST['site_name'], 'countryId' => $_REQUEST['country_id'], 'postCode' => $_REQUEST['postcode'], 'addressLine1' => $_REQUEST['addressline'], 'addressLine2' => $_REQUEST['addressline2']));
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'service' => $service_data, 'content' => $content, 'payment' => $payment, 'recipient' => $recipient, 'fragile' => $_REQUEST['fragile'], 'saturdayDelivery' => $_REQUEST['saturday'], 'pickupDate ' => rawurlencode($_REQUEST['pickup_date']), 'shipmentNote' => $_REQUEST['shipment_note'], 'ref1' => $_REQUEST['ref1'], 'ref2' => $_REQUEST['ref2']);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'shipment');
}
public function create_awb_ro()
{
$additionalServices = array('cod' => array('amount' => $_REQUEST['cod_amount'], 'currencyCode' => $_REQUEST['currency']));
$service_data = array('serviceId' => $_REQUEST['service_id'], 'autoAdjustPickupDate' => 'true', 'additionalServices' => $additionalServices);
$content = array('parcelsCount' => $_REQUEST['parcels_no'], 'totalWeight' => $_REQUEST['weight'], 'contents' => $_REQUEST['content'], 'package' => 'BOX');
$payment = array('courierServicePayer' => $_REQUEST['payer']);
$recipient = array('phone1' => array('number' => $_REQUEST['phone_no']), 'privatePerson' => $_REQUEST['private'], 'clientName' => $_REQUEST['client_name'], 'contactName' => $_REQUEST['contact_name'], 'email' => $_REQUEST['email'], 'address' => array('siteName' => $_REQUEST['site_name'], 'countryId' => $_REQUEST['country_id'], 'siteId' => $_REQUEST['site_id'], 'stateId' => $_REQUEST['state_id'], 'postCode' => $_REQUEST['postcode'], 'addressNote' => $_REQUEST['addressline'] . $_REQUEST['addressline2']));
$awb_data = array('userName' => $_REQUEST['username_dpd'], 'password' => $_REQUEST['password_dpd'], 'service' => $service_data, 'content' => $content, 'payment' => $payment, 'recipient' => $recipient, 'fragile' => $_REQUEST['fragile'], 'saturdayDelivery' => $_REQUEST['saturday'], 'pickupDate ' => rawurlencode($_REQUEST['pickup_date']), 'shipmentNote' => $_REQUEST['shipment_note'], 'ref1' => $_REQUEST['ref1'], 'ref2' => $_REQUEST['ref2']);
$data = json_encode($awb_data);
return $this->send_dbx_data($data, 'shipment');
}
}