Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Unknown error | International-Shippings #5

Closed
ReabRed opened this issue Mar 2, 2017 · 9 comments
Closed

Unknown error | International-Shippings #5

ReabRed opened this issue Mar 2, 2017 · 9 comments
Assignees

Comments

@ReabRed
Copy link

ReabRed commented Mar 2, 2017

hello,
we test your php sdk and have on problem.
We look if a national or international shipping.
If de = national V01PAK and epk is .....0102
else = international V53WPAK and epk is .....0302


if($utf_landcode == 'DE'){    
    $credentials->setEpk('xxxxxxxxxxxx102');
    $shipmentDetails->setProduct((string) DHL_ShipmentDetails::{V01PAK});
} else {
    $credentials->setEpk('xxxxxxxxxxxx302');
    $shipmentDetails->setProduct((string) DHL_ShipmentDetails::{V53WPAK});
}

is not working.

@Petschko
Copy link
Owner

Petschko commented Mar 2, 2017

Please remove the {} after DHL_ShipmentDetails::, they where just to show "placeholder"-Values
You don't need the (string)-Cast, it was just to show the Type of the Value.
I have to use 0101 for national packages, why do you need 0102? Are you sure that this is correct?

Correct is:

// Using my constances:
$shipmentDetails->setProduct(DHL_ShipmentDetails::PRODUCT_TYPE_NATIONAL_PACKAGE);
// OR (If you dont want to use the constances, just the String of your product):
$shipmentDetails->setProduct('V01PAK');

And for the second one:

// Using constances:
$shipmentDetails->setProduct(DHL_ShipmentDetails::PRODUCT_TYPE_INTERNATIONAL_PACKAGE);
// OR as String:
$shipmentDetails->setProduct('V53WPAK');

Please consider using an IDE, it will help you a lot =) (EG: Showing you constances etc)

But I never test it with international packages, please tell me if it works after you fixed the typo =)

May my description in the readme is a little unclear?

@ReabRed
Copy link
Author

ReabRed commented Mar 2, 2017

thx....
yes a littel unclear ;)

Fatal error: Call to a member function setProduct() on null in /XXX/v2_neues_sdk.php on line 28

#if($utf_landcode == 'DE'){    
    $credentials->setEpk('xxxxxxxx0102');
    $shipmentDetails->setProduct('V01PAK');
#} else {
    #$credentials->setEpk('xxxxxxxxxx5302');
    #$shipmentDetails->setProduct('V53WPAK');
#}

kann ich auch auf Deutsch antworten?

@Petschko
Copy link
Owner

Petschko commented Mar 2, 2017

Ja klar, wenns nicht anders geht^^

Hast du den die ganze Datei (Ohne Zugangsdaten) zb auf Pastebin, damit ich mal sehen kann?

@ReabRed
Copy link
Author

ReabRed commented Mar 2, 2017

ich hab die if Abfrage nun raus gemacht.
Jetzt bekommen ich -> Fatal error: Call to a member function setProduct() on null..

Hier mal das Script.
Alle Daten sind in einem Array und werden über eine Schleife gefüllt.

#error_reporting(-1);
ini_set('display_errors', TRUE);
error_reporting(E_ERROR | E_WARNING | E_PARSE);

require_once('includes' . DIRECTORY_SEPARATOR . 'DHL_BusinessShipment.php');

$heute = date("Y-m-d"); 
$utf_name = $name[$key];
$utf_namezusatz = $namezusatz[$key];
$utf_kontakt = $kontakt[$key];
$utf_strasse = $strasse[$key];
$utf_hausnummer = $hausnummer[$key];
$utf_landcode = $landcode[$key];
$utf_plz = $plz[$key];
$utf_ort = $ort[$key];
$utf_email = $email[$key];
$lap_gewicht = $p_gewicht[$key];

$testModus = false;
$version = '2.2';

    $credentials = new DHL_Credentials();
    $credentials->setUser('xxxxx'); // DHL-Account (Same as if you Login with then to create Manual-Labels)
    $credentials->setSignature('xxxxxx'); // DHL-Account-Password


#if($utf_landcode == 'DE'){    
$credentials->setEpk('xxxxx');
$shipmentDetails->setProduct('V01PAK');
#} else {
#$credentials->setEpk('xxxxxx');
#$shipmentDetails->setProduct('V53WPAK');
#}

    $credentials->setApiUser('DHLAPPID'); // Your Applications-ID (You can find it in your DHL-Dev-Account)
    $credentials->setApiPassword('TOKEN'); // Your Applications-Token (You can find it also where you found the App-Id) 

    $shipmentDetails->setShipmentDate($heute);
    $shipmentDetails->setWeight($lap_gewicht);

$sender = new DHL_Sender();
    $sender->setName('Firma');
    $sender->setStreetName('Strasse');
    $sender->setStreetNumber('10');
    $sender->setZip('90489');
    $sender->setCity('Nürnberg');
    $sender->setCountry('Germany');
    $sender->setCountryISOCode('DE');
    $sender->setAddressAddition('1 OG');
    $sender->setName2('Firma');
    $sender->setPhone('0911123456789');
    $sender->setEmail('info@mail.de');


$receiver = new DHL_Receiver();
    $receiver->setName($utf_name);
    $receiver->setStreetName($utf_strasse);
    $receiver->setStreetNumber($utf_hausnummer);
    $receiver->setZip($utf_plz);
    $receiver->setCity($utf_ort);
    $receiver->setCountryISOCode($utf_landcode);
    $receiver->setName2($utf_namezusatz);
    $receiver->setEmail($utf_email);
    $receiver->setContactPerson($utf_kontakt);


$service = new DHL_Service();

$dhl = new DHL_BusinessShipment($credentials);

$dhl->setSender($sender);
$dhl->setReceiver($receiver);
$dhl->setService($service);
$dhl->setShipmentDetails($shipmentDetails);
$dhl->setReceiverEmail($utf_email); // Needed if you want inform the receiver via mail
$dhl->setLabelResponseType('URL');

$response = $dhl->createShipment(); 

if($response !== false)
	var_dump($response);
else
	var_dump($dhl->getErrors());

var_dump($dhl->getLastXML());

@Petschko
Copy link
Owner

Petschko commented Mar 2, 2017

Naja du greifst auf $shipmentDetails zu, nirgendwo wurde das deklariert... Daher auch die null-Pointer-Exception

Du musst das Shipment-Detail objekt erstellen^^ (Der Schritt hier)

$shipmentDetails = new DHL_ShipmentDetails($credentials->getEpk(10) . '0101'); 

Musst die Endung eben noch anpassen, da du ja nicht 0101 nutzt, sondern 0102 bzw 0103^^

@ReabRed
Copy link
Author

ReabRed commented Mar 2, 2017

Danke.... und Respekt für die schnellen Antworten.
Ich teste weiter und berichte.
Ich werde mein Script wenn es geht hier Posten.

Sorry, bin net der crack in php.

@Petschko
Copy link
Owner

Petschko commented Mar 2, 2017

Kein Problem und viel Erfolg weiterhin^^ Sag bescheid, ob das mit dem Internationalen Versand funktioniert, so lange lass ich das mal offen ;)

@Petschko Petschko changed the title setProduct in if Unknown error | International-Shippings Mar 2, 2017
@ReabRed
Copy link
Author

ReabRed commented Mar 6, 2017

Getestet und läuft.
Leider werden aber auch Etiketten erstellt, wenn die Leitcodierung einen Fehler zurück wirft.
Man sollte hier wählen können ob eine Etikette bei einem Leitcodierungs-Fehler gedruckt wird oder nicht.

["statusText":"DHL_Response":private]=> string(30) "Weak validation error occured." ["statusMessage":"DHL_Response":private]=> array(2) { [0]=> string(48) "Der angegebene Ort passt nicht zur Postleitzahl." [1]=> string(48) "Der angegebene Ort passt nicht zur Postleitzahl." }

Etikette wird trotzdem erstellt, kostet halt 0,35€ pro Etikette.

Mein Script sieht so aus.

require_once('includes' . DIRECTORY_SEPARATOR . 'DHL_BusinessShipment.php');

$heute = date("Y-m-d"); 
$utf_name = utf8_encode($name[$key]);
$utf_namezusatz = utf8_encode($namezusatz[$key]);
$utf_kontakt = utf8_encode($kontakt[$key]);
$utf_strasse = utf8_encode($strasse[$key]);
$utf_hausnummer = utf8_encode($hausnummer[$key]);
$utf_landcode = utf8_encode($landcode[$key]);
$utf_plz = utf8_encode($plz[$key]);
$utf_ort = utf8_encode($ort[$key]);
$utf_email = utf8_encode($email[$key]);
$lap_gewicht = utf8_encode($p_gewicht[$key]);

$testModus = false;
$version = '2.2';

    $credentials = new DHL_Credentials();
    $credentials->setUser('USER_XXXXXXXXXX'); // DHL-Account (Same as if you Login with then to create Manual-Labels)
    $credentials->setSignature('PW_XXXXXXXXXXXX'); // DHL-Account-Password


if($utf_landcode == 'DE'){
$credentials->setEpk('XXXXXXXXX_0102');
$shipmentDetails = new DHL_ShipmentDetails($credentials->getEpk(10) . '0102');
$shipmentDetails->setProduct('V01PAK');
} else {
$credentials->setEpk('XXXXXXXXXXX_5302');
$shipmentDetails = new DHL_ShipmentDetails($credentials->getEpk(10) . '5302');
$shipmentDetails->setProduct('V53WPAK');
}

    $credentials->setApiUser('PHPAPPID'); // Your Applications-ID (You can find it in your DHL-Dev-Account)
    $credentials->setApiPassword('TOKEN'); // Your Applications-Token (You can find it also where you found the App-Id) 

    $shipmentDetails->setShipmentDate($heute);
    $shipmentDetails->setWeight($lap_gewicht);

$sender = new DHL_Sender();
    $sender->setName('Absender');
    $sender->setStreetName('Absender Str');
    $sender->setStreetNumber('Absender HNr.');
    $sender->setZip('Absender PLZ');
    $sender->setCity('Absender Stadt');
    $sender->setCountry('Germany');
    $sender->setCountryISOCode('DE');
    $sender->setAddressAddition('Zb. 1 OG');
    $sender->setName2('Absender Name2');
    $sender->setPhone('Rufnummer');
    $sender->setEmail('Absender');


$receiver = new DHL_Receiver();
    $receiver->setName($utf_name);
    $receiver->setStreetName($utf_strasse);
    $receiver->setStreetNumber($utf_hausnummer);
    $receiver->setZip($utf_plz);
    $receiver->setCity($utf_ort);
    $receiver->setCountryISOCode($utf_landcode);
    $receiver->setName2($utf_namezusatz);
    $receiver->setEmail($utf_email);
    $receiver->setContactPerson($utf_kontakt);


$service = new DHL_Service();

$dhl = new DHL_BusinessShipment($credentials);

$dhl->setSender($sender);
$dhl->setReceiver($receiver);
$dhl->setService($service);
$dhl->setShipmentDetails($shipmentDetails);
$dhl->setReceiverEmail($utf_email); // Needed if you want inform the receiver via mail
$dhl->setLabelResponseType('URL');

$response = $dhl->createShipment(); 

if($response !== false)
	var_dump($response);
else
	var_dump($dhl->getErrors());

var_dump($dhl->getLastXML());


$sendungsnummer = $response->getShipmentNumber();
$label_url = $response->getLabel(); // Returns the Label URL or Base64-Label-String or null
$label_url2 = $response->getReturnLabel(); // Returns the ReturnLabel (URL/B64) or null
$sepnr = $response->getSequenceNumber(); // Returns your provided sequence number or null
$status_code = $response->getStatusCode(); // Returns the Status-Code (Difference to DHL - Weak-Validation is 1 not 0)
$status_text = $response->getStatusText(); // Returns the Status-Text or null
$status_message = $response->getStatusMessage(); // Returns the Status-Message (More details) or null

echo "<br>
$sendungsnummer <br>
$label_url <br>
$label_url2 <br>
$sepnr <br>
$status_code <br>
$status_text <br>
$status_message <br>
";

 // Speichert das Lappel im Ordner label.
file_put_contents("./label/$sendungsnummer.pdf", file_get_contents($label_url));

@Petschko
Copy link
Owner

Petschko commented Mar 6, 2017

Super, es läuft =)! Danke dir fürs testen.

Soweit ich weiß, muss man selbst fehlerhafte Etiketten stornieren. Das kannst du mit der Funktion hier tun: (Findest du in der DHL_BusinessShipment-Klasse, also selbe mit der du das auch erstellt hast)

	/**
	 * Deletes a Shipment
	 *
	 * @param string $shipmentNumber - Shipment-Number of the Shipment to delete
	 * @return bool|DHL_Response - Response
	 */
	public function deleteShipment($shipmentNumber) { /* (...) */ }

Du könntest das selbstverständlich auch automatisieren, indem du bei einem Weak-Validation-Error einfach automatisch diese funktion mit der Sende-Nummer aufrufst.

zb:

if($response !== false) {
	if($response->getStatusCode() === DHL_Response::DHL_ERROR_WEAK_WARNING)
		$dhl->deleteShipment($response->getShipmentNumber());
}

Allerdings sind da die Lösungen bei dir, da ich schlecht prüfen kann ob es die Adresse gibt/mit der PLZ übereinstimmt^^ Da kannste ja dich einfach auf die Response verlassen.

Nun gut, super das alles soweit geht, ich schließe das hier mal. Danke fürs testen =)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants