Skip to content

Commit 586825f

Browse files
committed
1.1.2
1 parent f275ed2 commit 586825f

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

classes/DpdLabelGenerator.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Order;
2626
use Address;
2727
use Country;
28+
use Currency;
2829
use DbQuery;
2930
use Product;
3031
use LinkCore;
@@ -74,6 +75,15 @@ public function __construct()
7475
]));
7576
$this->dpdClient = $clientBuilder->buildAuthenticatedByPassword($username, $password);
7677

78+
$this->dpdClient->getAuthentication()->setJwtToken(
79+
Configuration::get('dpdconnect_jwt_token') ?: null
80+
);
81+
82+
$this->dpdClient->getAuthentication()->setTokenUpdateCallback(function ($jwtToken) {
83+
Configuration::updateValue('dpdconnect_jwt_token', $jwtToken);
84+
$this->dpdClient->getAuthentication()->setJwtToken($jwtToken);
85+
});
86+
7787
$this->dpdError = new DpdError();
7888
$this->dpdParcelPredict = new DpdParcelPredict();
7989
}
@@ -225,6 +235,8 @@ public function generateShipmentInfo($orderId, $parcelCount, $return)
225235
'phoneNumber' => Configuration::get('PS_SHOP_PHONE'),
226236
'email' => Configuration::get('dpdconnect_email'),
227237
'commercialAddress' => true,
238+
'vatnumber' => (Configuration::get('dpdconnect_vatnumber') === null) ? 'null' : Configuration::get('dpdconnect_vatnumber'),
239+
'eorinumber' => (Configuration::get('dpdconnect_eorinumber') === null) ? 'null' : Configuration::get('dpdconnect_eorinumber'),
228240
],
229241
'receiver' => [
230242
'name1' => $fullName,
@@ -234,12 +246,13 @@ public function generateShipmentInfo($orderId, $parcelCount, $return)
234246
'city' => $address->city,
235247
'phoneNumber' => $phone,
236248
'commercialAddress' => false,
237-
'vat_number' => Configuration::get('dpdconnect_vatnumber'),
238-
'eori_number' => Configuration::get('dpdconnect_eorinumber'),
249+
'vatnumber' => (Configuration::get('dpdconnect_vatnumber') === null) ? 'null' : Configuration::get('dpdconnect_vatnumber'),
250+
'eorinumber' => (Configuration::get('dpdconnect_eorinumber') === null) ? 'null' : Configuration::get('dpdconnect_eorinumber'),
239251
],
240252
'product' => [
241253
'productCode' => $productCode,
242254
'saturdayDelivery' => $saturdayDelivery,
255+
'homeDelivery' => $this->dpdParcelPredict->checkIfPredictCarrier($orderId) || $this->dpdParcelPredict->checkIfSaturdayCarrier($orderId)
243256
],
244257
];
245258

@@ -276,9 +289,10 @@ public function generateShipmentInfo($orderId, $parcelCount, $return)
276289
array_push($shipment['parcels'], $parcelInfo);
277290
}
278291

292+
$currency = new Currency($tempOrder->id_currency);
279293
$shipment['customs'] = [
280294
'terms' => 'DAP',
281-
'totalCurrency' => 'EUR',
295+
'totalCurrency' => $currency->iso_code,
282296
];
283297

284298
$totalAmount = 0;
@@ -311,16 +325,19 @@ public function generateShipmentInfo($orderId, $parcelCount, $return)
311325

312326
$shipment['customs']['totalAmount'] = (float) $totalAmount;
313327

314-
$consignee = [
328+
$consignor = [
315329
'name1' => Configuration::get('dpdconnect_company'),
316330
'street' => Configuration::get('dpdconnect_street'),
317331
'postalcode' => Configuration::get('dpdconnect_postalcode'),
318332
'city' => Configuration::get('dpdconnect_place'),
319333
'country' => strtoupper(Configuration::get('dpdconnect_country')),
320334
'commercialAddress' => true,
335+
'sprn' => Configuration::get('dpdconnect_spr') ?: '',
336+
'vatnumber' => (Configuration::get('dpdconnect_vatnumber') === null) ? 'null' : Configuration::get('dpdconnect_vatnumber'),
337+
'eorinumber' => (Configuration::get('dpdconnect_eorinumber') === null) ? 'null' : Configuration::get('dpdconnect_eorinumber'),
321338
];
322339

323-
$consignor = [
340+
$consignee = [
324341
'name1' => $fullName,
325342
'street' => $street,
326343
'postalcode' => $address->postcode,

classes/DpdParcelPredict.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public function __construct()
5353
]));
5454
$this->dpdClient = $clientBuilder->buildAuthenticatedByPassword($username, $password);
5555

56+
$this->dpdClient->getAuthentication()->setJwtToken(
57+
Configuration::get('dpdconnect_jwt_token') ?: null
58+
);
59+
60+
$this->dpdClient->getAuthentication()->setTokenUpdateCallback(function ($jwtToken) {
61+
Configuration::updateValue('dpdconnect_jwt_token', $jwtToken);
62+
$this->dpdClient->getAuthentication()->setJwtToken($jwtToken);
63+
});
64+
5665
$this->Gmaps = new Gmaps();
5766
}
5867

classes/Gmaps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function getGeoData($postal_code, $isoCode)
1212
$gmapsKey = Configuration::get('gmaps_server_key');
1313

1414
$data = urlencode('country:' . $isoCode . '|postal_code:' . $postal_code);
15-
$url = "https://maps.googleapis.com/maps/api/geocode/json?key=". $gmapsKey . "&address=". $data . '&sensor=false';
15+
$url = "https://maps.googleapis.com/maps/api/geocode/json?key=". $gmapsKey . "&components=". $data . '&sensor=false';
1616
$source = file_get_contents($url);
1717

1818
$gmapsData = json_decode($source);

dpdconnect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ public function getContent()
343343
],
344344
[
345345
'type' => 'text',
346-
'label' => $this->l('SPRN'),
347-
'hint' => $this->l('Heeft u een registratienummer van HMRC (douane in UK) beschikbaar, vul deze dan hier in: https://www.gov.uk/guidance/register-for-import-vat-on-parcels-you-sell-to-uk-buyers'),
346+
'label' => $this->l('HMRC number'),
347+
'hint' => $this->l('Mandatory if the value of the parcel is ≤ £ 135.'),
348348
'name' => 'spr',
349349
'required' => false
350350
],

0 commit comments

Comments
 (0)