2

I need to build the following XML in PHP.

<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-
secext-1.0.xsd" xmlns:wsu="http://docs.oasisopen.
org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-102">
<wsse:Username> string </wsse:Username>
<wsse:Password Type="http://docs.oasisopen.
org/wss/2004/01/oasis-200401-wss-username-token-profile-
1.0#PasswordText"> string </wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<her:UserToken> string </her:UserToken>
</soapenv:Header>

Now i can connect to the Service with the following Class.

class connect {

    const USER = 'XXX';
    const PASSWORD = 'XXX';
    const NS_WSSE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
    const NS_WSU = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
    const PASSWORD_TYPE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
    const ENCODING_TYPE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
    const WSDLFILE = '/var/www/vhosts/eteil.stillatwork.de/httpdocs/inc/hermes/ProPS_sbx.wsdl';
    const BENUTZERNAME = 'XXX';
    const KENNWORT = 'XXX';

    public function soapClientWSSecurityHeader($token)
    {

        // Initializing namespaces
        $headers = array();

        // Creating WSS identification header using SimpleXML
        $root = new SimpleXMLElement('<root/>');

        $security = $root->addChild('wsse:Security', null, SELF::NS_WSSE);


        $usernameToken = $security->addChild('wsse:UsernameToken', null);
        $usernameToken->addChild('wsse:Username', SELF::USER, SELF::NS_WSSE);
        $usernameToken->addChild('wsse:Password', SELF::PASSWORD, SELF::NS_WSSE)->addAttribute('Type', SELF::PASSWORD_TYPE);

        // Recovering XML value from that object
        $root->registerXPathNamespace('wsse', SELF::NS_WSSE);

        $full = $root->xpath('/root/wsse:Security');
        $auth = $full[0]->asXML();

        $auth_u = "<her:UserToken>".$token."</her:UserToken>";

        $headers[] = new SoapHeader(SELF::NS_WSSE,'Security', new SoapVar( $auth, XSD_ANYXML), true);
        if($token != '') {
            $headers[] = new SoapHeader(NULL, 'UserToken',new SoapVar( $auth_u, XSD_ANYXML));
        }

        return $headers;

    }

    public function generateclient($token){
        $this->client = new SoapClient(SELF::WSDLFILE);
        $this->client->__setSoapHeaders($this->soapClientWSSecurityHeader($token));
    }

    public function login(){
        $this->generateclient();
        $user = array('benutzername' => SELF::BENUTZERNAME,'kennwort' => SELF::KENNWORT);
        $result = $this->client->propsUserLogin(array('login' => $user));

        return $result->propsUserLoginReturn;
    }

    public function listOrder($token){
        $this->generateclient($token);
        $result = $this->client->propsListOfProductsATG();

        return $result->propsListOfProductsATGReturn;
    }

    public function check($token){
        $this->generateclient($token);
        $result = $this->client->propsCheckAvailability();

        return $result->propsCheckAvailabilityReturn;
    }

    public function order($token, $order){
        $this->generateclient($token);
        $result = $this->client->propsOrderSave($order);

        return $result->propsOrderSaveReturn;
    }
}

The login to the API Service works perfectly. It gives the right token back.

But for further requests e.g. to place an order it's necessary to send the token inside of the SOAP Header.

For any reason if I try to place an order or I try recieve the list of the available Products the response of the API is:

"Fault occurred while processing."

It would be a great help if anybody can help me to solute the problem.

For your information: An excerpt of the documentation about the authentication and the placement of an order.

The SOAP header is also used to authenticate the relevant services at the ProfiParcelService portal. In the SOAP header, an encrypted UserToken is transferred that contains the necessary authentication details. This UserToken must be requested by the The propsUserLogin service. This service anticipates a user name and password for an active portal user account and delivers an encrypted UserToken. The UserToken is valid for six months.

3.1. Authentication at service launch

At each service launch, the Partner ID and the API password have to be transferred in the SOAP header. The UserToken only has to be filled in when the service requires authentication at the ProfiParcelService portal. Each launch of a service contains the following SOAP header:

4.5. The propsOrderSave service

This service is used to create new shipping orders or to edit existing ones. The shipping order comprises the recipient's address, a customer reference, details of the shipment by COD and the parcel size. The shipper's address is the collection address of the querying ProfiParcelService customer. This address is stored when registering for the ProfiParcelService portal and may no longer be amended when orders are created or edited. It is only possible to amend this default collection address in the ProfiParcelService portal. Whether a shipping order is created or an existing order edited depends on whether an order number has been entered. If an order number is transferred, the shipping order with this number is loaded for editing, otherwise a new order is added. A shipping order can only be edited before it is printed.

4.5.1. propsOrderSave input parameters

Besides the authentication details Partner ID, API password and User Token (see Section 3) in the SOAP header, the SOAP body requires details of the shipping order as input parameters. These are taken from PropsOrder (see 4.2.2).

<soapenv:Body>
<propsOrderSave>
<propsOrder>PropsOrder</propsOrder>
</propsOrderSave>
</soapenv:Body>

4.2.2. PropsOrder

This type of data represents the data of a shipping order. This data type is used to create new orders or to edit existing ones.

<PropsOrder>
<orderNo>string</orderNo>
<receiver>Address</receiver>
<clientReferenceNumber>string</clientReferenceNumber>
<parcelClass>string</parcelClass>
<amountCashOnDeliveryEurocent>int</amountCashOnDeliveryEurocent>
<includeCashOnDelivery>boolean</includeCashOnDelivery>
<withBulkGoods>boolean</withBulkGoods>
</PropsOrder>

4.2.1. Address

Within shipping orders, 'address' data is used as the recipient's address. Neither P.O. boxes nor packing stations can be used for the recipient's address.

<Address>
<firstname>string</firstname>
<lastname>string</lastname>
<street>string</street>
<houseNumber>string</houseNumber>
<addressAdd>string</addressAdd>
<postcode>string</postcode>
<city>string</city>
<district>string</district>
<countryCode>string</countryCode>
<email>string</email>
<telephoneNumber>string</telephoneNumber>
<telephonePrefix>string</telephonePrefix>
</Address>
monkee
  • 21
  • 2

0 Answers0