firstred / postnl-api-php

PostNL API PHP bindings
https://postnl-php.readthedocs.io
MIT License
26 stars 37 forks source link

XSL evaluation issue #2

Closed timramakers closed 5 years ago

timramakers commented 6 years ago

Before I start: thank you for writing this brilliant set of bindings!!

I'm using a piece of code derived from the readme example and that works perfectly. After switching out of the sandbox mode, I get the following error:

Evaluation of XSL removeNamespace.xsl failed with reason: "Process instruction target name cannot be xml at line 3 (possibly around char 2416)

This tells me that something is wrong in the data being sent, but I'm not sure how to fix it. My code looks as following:

$sender = Customer::create([
        'CollectionLocation' => 'xxxx',
        'CustomerCode' => 'xxxx',
        'CustomerNumber' => 'xxxxx',
        'ContactPerson' => 'xxxx',
        'Address' => Address::create([
            'AddressType' => '02',
            'City'        => 'xxxx',
            'CompanyName' => 'xxxxx',
            'Countrycode' => 'NL',
            'HouseNr'     => 'xxxx',
            'Street'      => 'xxxxx',
            'Zipcode'     => 'xxxxx',
        ]),
        'Email' => 'xxxxxxx',
        'Name' => 'xxxxxxx',
    ]);

    $apikey = 'xxxxxxx';
    $sandbox = false;

    $postnl = new PostNL($sender, $apikey, $sandbox);

$barcode = $postnl->generateBarcodeByCountryCode("NL");

try {
                $shipment = Shipment::create([
                    'Addresses' => [
                        Address::create([
                            'AddressType'           => '01',
                            'City'                  => $klantarray["woonplaats"],
                            'Countrycode'           => strtoupper($landarray["code"]),
                            'Name'                  => $klantarray["naam"],
                            'HouseNr'               => $adres["number"],
                            'HouseNrExt'            => $adres["numberAddition"],
                            'Street'                => $adres["street"],
                            'Zipcode'               => $klantarray["postcode"],
                        ]),
                    ],
                    'Barcode' => $barcode,
                    'Dimension' => new Dimension($productarray["afmetingen"]),
                    'ProductCodeDelivery' => $productCode,
                ]);

                $label = $postnl->generateLabel($shipment, 'GraphicFile|PDF', true);
                $labels = accessProtected($label->ResponseShipments[0],"Labels");
                $labelPDF = base64_decode(accessProtected($labels[0],"Content"));
                $file = $_SERVER["DOCUMENT_ROOT"]."/temp/".microtime(true).".pdf";
                file_put_contents($file, $labelPDF);

            } catch (Exception $e){
                echo "Error bij kavel ".$array["kavel"]."\r\n";
                print_r($e->getMessage());
            }

Do you have any idea on how to fix this?

firstred commented 6 years ago

Hey, thanks for your kind words! I'm hoping this project will soon abstract away the difficult API methods that PostNL provides, kind of like what Omnipay is to payment gateways.

Do you have any idea on how to fix this?

I'm not sure yet. I have paused this project for the moment since the new PostNL API doesn't seem to be stable enough to use in production. PostNL seems to have made some last-minute changes as well. I'll be rebooting this project from next week. Let's see if we have to change things in this method. Despite this library having alpha status, I am currently using it in production together with the (legacy) SOAP API.

Can you send me the original request (anonymized if necessary)? I bet the info around char 2416 can tell us more.

timramakers commented 6 years ago

Thanks so much for your reply! Can you instruct me in how to get the original request? I've been digging through the source but not sure where to print, echo or dump the request contents.

firstred commented 6 years ago

The request is sent to the HttpClient (cURL or Guzzle). You can dump the $body param in: https://github.com/thirtybees/postnl-api-php/blob/fd6856b8d31a059531135298d246b1ba44f64f21/src/HttpClient/CurlClient.php#L194 for a single request or https://github.com/thirtybees/postnl-api-php/blob/fd6856b8d31a059531135298d246b1ba44f64f21/src/HttpClient/CurlClient.php#L332 when it's part of a multi-request.

Hope that helps!

timramakers commented 6 years ago

Perfect, thanks! I have sent the request to PostNL because it looked perfectly fine, and they found a bug on their side and fixed it, so we made the internet a little bit better today. ;-)

Thanks a bunch!!