DivideBV / Postnl

Library to connect to PostNL's SOAP service called CIF
GNU General Public License v2.0
31 stars 40 forks source link

Get warnings #68

Closed Peterbins closed 5 years ago

Peterbins commented 5 years ago

i have input a nonexistent postal code. If i turn it on debug mode the message is 'onbekend adres' but if it bij the function getWarnings :

code: $result = $client->generateLabel($shipment, 'GraphicFile|PDF|MergeA'); var_dump($result->getWarnings());

output: object(DivideBV\Postnl\ComplexTypes\ArrayOfWarning)#27 (1) { ["Warning":protected]=> NULL }

or is there another way to show the warnings?

ameenross commented 5 years ago

That's correct. But ArrayOfWarning is an object which basically contains a list of Warning objects. The ArrayOf objects are iterable.

So you would have this:

foreach ($result->getWarnings() as $warning) {
    echo "Error {$warning->getCode()}: {$warning->getDescription()}";
}
ameenross commented 5 years ago

By the way, your var_dump shows that in this case, there were no warnings

Peterbins commented 5 years ago

Thank but still nog working for me. I'm doing something wrong but do not know what! A part of de debug data of the respone;

[response] => m9vdCAxIDAgUg0KL0luZm8gMiAwIFINCj4+DQpzdGFydHhyZWYNCjY4ODENCiUlRU9GDQo= </a:Content>

  |   | Label</a:Labeltype>   | </a:Label>   | </a:Labels>   | 3085</a:ProductCodeDelivery>   |   | 1280103</a:Code>   | Adres is onbekend</a:Description>   | </a:Warnings>   | </a:ResponseShipment>   | </a:ResponseShipments>   |   | </s:Body>   | </s:Envelope>

My code:

$result = $client->generateLabel($shipment, 'GraphicFile|PDF|MergeA');

--- i use generateLabel en not generateLabels so i think to show the warnings..

To show the warnings : var_dump($result->getWarnings()->getWarning());

Result Null but de response in debug mode tells something else.

The code : foreach ($result->getWarnings() as $warning) { echo "Error {$warning->getCode()}: {$warning->getDescription()}"; }

result in een error : Fatal error: Uncaught InvalidArgumentException: Passed variable is not an array or object

ameenross commented 5 years ago

Which version are you using?

Peterbins commented 5 years ago

"dividebv/postnl": "V2.0.0-beta2"

ameenross commented 5 years ago

I tried it myself, here's the response XML:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://postnl.nl/cif/domain/LabellingWebService/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <s:Body>
    <GenerateLabelResponse xmlns="http://postnl.nl/cif/services/LabellingWebService/">
      <a:MergedLabels i:nil="true"/>
      <a:ResponseShipments>
        <a:ResponseShipment>
          <a:Barcode>3SABCD1234567</a:Barcode>
          <a:DownPartnerBarcode i:nil="true"/>
          <a:DownPartnerID i:nil="true"/>
          <a:DownPartnerLocation i:nil="true"/>
          <a:Labels>
            <a:Label>
              <a:Content>BaSe64StUfF=</a:Content>
              <a:Contenttype i:nil="true"/>
              <a:Labeltype>Label</a:Labeltype>
            </a:Label>
          </a:Labels>
          <a:ProductCodeDelivery>3085</a:ProductCodeDelivery>
          <a:Warnings>
            <a:Code>1280103</a:Code>
            <a:Description>Adres is onbekend</a:Description>
          </a:Warnings>
        </a:ResponseShipment>
      </a:ResponseShipments>
    </GenerateLabelResponse>
  </s:Body>
</s:Envelope>

This seems to be (another) violation of their WSDL/XSD:

ameenross commented 5 years ago
  <xs:complexType name="ResponseShipment">
    <xs:sequence>
      <xs:element minOccurs="0" name="Barcode" nillable="true" type="xs:string"/>
      <xs:element minOccurs="0" name="DownPartnerBarcode" nillable="true" type="xs:string"/>
      <xs:element minOccurs="0" name="DownPartnerID" nillable="true" type="xs:string"/>
      <xs:element minOccurs="0" name="DownPartnerLocation" nillable="true" type="xs:string"/>
      <xs:element minOccurs="0" name="Labels" nillable="true" type="tns:ArrayOfLabel"/>
      <xs:element minOccurs="0" name="ProductCodeDelivery" nillable="true" type="xs:string"/>
      <xs:element minOccurs="0" name="Warnings" nillable="true" type="tns:ArrayOfWarning"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="ResponseShipment" nillable="true" type="tns:ResponseShipment"/>

  <xs:complexType name="ArrayOfWarning">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Warning" nillable="true" type="tns:Warning"/>
    </xs:sequence>
  </xs:complexType>

  <xs:element name="ArrayOfWarning" nillable="true" type="tns:ArrayOfWarning"/>

  <xs:complexType name="Warning">
    <xs:sequence>
      <xs:element minOccurs="0" name="Code" nillable="true" type="xs:string"/>
      <xs:element minOccurs="0" name="Description" nillable="true" type="xs:string"/></xs:sequence>
  </xs:complexType>

  <xs:element name="Warning" nillable="true" type="tns:Warning"/>
Peterbins commented 5 years ago
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://postnl.nl/cif/domain/LabellingWebService/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <s:Body>
    <GenerateLabelResponse xmlns="http://postnl.nl/cif/services/LabellingWebService/">
      <a:MergedLabels i:nil="true"/>
      <a:ResponseShipments>
        <a:ResponseShipment>
          <a:Barcode>3SABCD1234567</a:Barcode>
          <a:DownPartnerBarcode i:nil="true"/>
          <a:DownPartnerID i:nil="true"/>
          <a:DownPartnerLocation i:nil="true"/>
          <a:Labels>
            <a:Label>
              <a:Content>BaSe64StUfF=</a:Content>
              <a:Contenttype i:nil="true"/>
              <a:Labeltype>Label</a:Labeltype>
            </a:Label>
          </a:Labels>
          <a:ProductCodeDelivery>3085</a:ProductCodeDelivery>
          <a:Warnings>
            <a:Code>1280103</a:Code>
            <a:Description>Adres is onbekend</a:Description>
          </a:Warnings>
        </a:ResponseShipment>
      </a:ResponseShipments>
    </GenerateLabelResponse>
  </s:Body>
</s:Envelope>

so we have the same output. Dit you get the warnings by : ($result->getWarnings() ?

ameenross commented 5 years ago

so we have the same output. Dit you get the warnings by : ($result->getWarnings() ?

Nope. Because PostNL gives the result in a format that's not in accordance to their WSDL/XSD.

<!-- What it should be: -->
<a:Warnings>
  <a:Warning>
    <a:Code>12345678</a:Code>
    <a:Description>Foo bar baz</a:Description>
  </a:Warning>
</a:Warnings>

<!-- What it actually is: -->
<a:Warnings>
  <a:Code>12345678</a:Code>
  <a:Description>Foo bar baz</a:Description>
</a:Warnings>
ameenross commented 5 years ago

And that's actually what it is in the old environment. I just checked:

screenshot from 2018-10-24 09-54-21

ameenross commented 5 years ago

Acknowledged by PostNL

Peterbins commented 5 years ago

what is going to happen now? does postnl make a change in their software?

ameenross commented 5 years ago

They told me they were working on it and they do regular releases.

It's not fixed yet though.

Peterbins commented 5 years ago

Ok thanks!

ameenross commented 5 years ago

Still not fixed.

ameenross commented 5 years ago

It seems to be fixed at last!