metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
213 stars 156 forks source link

Add support for firstname and surname in *.fi domain contact info responses #47

Closed aksl closed 8 years ago

aksl commented 8 years ago

In some Ficora contact info responses (where contact type is 0 (person)), the name is transmitted with separate firstname and lastname fields which are not recognized and transferred properly to eppContactPostalInfo. Example response:

<?xml version="1.0" encoding="utf-8"?>
<epp xmlns:host="urn:ietf:params:xml:ns:host-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xmlns:obj="urn:ietf:params:xml:ns:obj-1.0" xmlns="urn:ietf:params:xml:ns:epp-1.0">
  <response>
    <result code="1000">
      <msg>Command completed successfully</msg>
    </result>
    <resData>
      <contact:infData>
        <contact:id>C000000</contact:id>
        <contact:role>5</contact:role>
        <contact:type>0</contact:type>
        <contact:postalInfo type="loc">
          <contact:firstname>Firstname</contact:firstname>
          <contact:lastname>Lastname</contact:lastname>
          <contact:addr>
            <contact:street>Street</contact:street>
            <contact:city>City</contact:city>
            <contact:pc>00000</contact:pc>
            <contact:cc>FI</contact:cc>
          </contact:addr>
        </contact:postalInfo>
        <contact:voice>+358123456</contact:voice>
        <contact:legalemail>email@email.email</contact:legalemail>
        <contact:clID>C0000contact:clID>
        <contact:crDate>2016-07-13T20:59:52.097</contact:crDate>
      </contact:infData>
    </resData>
    <trID>
      <clTRID>...</clTRID>
      <svTRID>...</svTRID>
    </trID>
  </response>
</epp>

Simple fix: alter eppInfoContactResponse->getContactPostalInfo() to search for firstname and lastname if name field is not present (around line 314):

            if ($testname->length > 0) {
                $name = $testname->item(0)->nodeValue;
            } else {
                $testfirstname = $postalresult->getElementsByTagName('firstname');
                $testlastname = $postalresult->getElementsByTagName('lastname');
                if ($testfirstname->length > 0 && $testlastname->length > 0) {
                    $name = $testfirstname->item(0)->nodeValue . ' ' . $testlastname->item(0)->nodeValue;
                }
            }
aksl commented 8 years ago

Also, it might be beneficial to add functions for getting firstname and lastname separately. One approach could be to extend eppInfoContactResponse with ficoraEppInfoContactResponse and add the required methods there for getting the first name and last name. ficoraEppConnection constructor can then override previous command response for Metaregistrar\EPP\eppInfoContactRequest.

Also note that some contact info responses have the contact:postalInfo > contact:name, so don't drop support for it completely on Ficora contact info responses. It is used for specifying contact person or department for a company or other organisation.

aksl commented 8 years ago

One additional thing: if you decide to extend the eppInfoContactRequest, you could add support for retrieving legalemail which is present for contact type 5 (registrant). For contact type 5, it is possible that regular email is not present, but legal email is (as seen from the xml above). Both of them can be present at the same time.

metaregistrar commented 8 years ago

Hello Aksi,

The php-epp-client has been written in such a way that you can extend the eppInfoContactResponse to include extra fields that are created by some registries (and not by others). I would not recommend altering the default eppInfoContactResponse, because that might break your implementation if you connect to a different registry than Ficora.

Unfortunately, Ficora has not made its EPP extensions "the EPP way". Instead of implementing them as an extension object in XML, they have incorporated their changes into the main EPP structure.

But that does not matter. If you examine Protocols/EPP/eppExtensions/Ficora, you can see an example of extending the CheckBalance object.

This directory can also be used for writing additional extensions for Ficora, for example for extending the eppInfoContactResponse with extra fields.

aksl commented 8 years ago

I'll go with that way then, might do a pull request once I have something actually usable.

Handling the special fields in postal info would require extending the eppContactPostalInfo. Sadly, that would mean rewriting the entire base logic for eppInfoContactResponse->getContactPostalInfo(). Would it be possible to split the logic from getContactPostalInfo into two parts? One (getContactPostalInfoData, protected) would return an array of arrays containing the parsed elements (name, city, country, etc.) and the raw xpath query result, and then the actual getContactPostalInfo would use this for assigning them into objects. That way one could use the getContactPostalInfoData(), do additional logic on xpath query results and then use a different class if needed.

metaregistrar commented 8 years ago

Why don't you extend the eppContactPostalInfo object with a new object (like ficoraEppContactPostalObject) and add / substitute functions where needed? I see no reason the rewrite the base logic? It is just a simple object that will convert XML into text or a PHP object structure.

aksl commented 8 years ago

That was the plan. However, I can't then use the original eppInfoContactResponse->getContactPostalInfo(), as it can't return extended objects. Guess I'll just have to rewrite that too.

metaregistrar commented 8 years ago

And that is exactly why it is a bad thing that Ficora did not use the recommended way to extend EPP.

metaregistrar commented 8 years ago

Merged the pull request, thanks for your contribution