Search code examples
phpsoapcallsiteminder

Soap Call for sitemider PHP


Ok guys and girls I really tried... that is not lack of effort in here...

I got a system that books hotel, events and manage it and now I have to connect siteminder and other services. Which is great but I cannot understand how it works at all... all I get is a single error that I cannot get my head how to make it work.

So lets go cooding:

$auth = new \stdClass();
$auth->UsernameToken = new \stdClass();
$auth->UsernameToken->Username = $user;
$auth->UsernameToken->Password = $pw;

$client = new SoapClient($wsdl,array('trace'=>true));
$header = new SOAPHeader($ns, 'Security', $auth, false); 

$hresp = $client->__setSoapHeaders($header);
//This is true... so my authentication is working perfect
//var_dump($hresp);
$arr = array(
    'POS' => array(
        'Source'=> array(
            'RequestorID' => array(
                'type'=>'22',
                'ID'=>$id,
            )
        )
    ),
    'AvailStatusMessages' => array(
        'HotelCode'=>$hc,
        'AvailStatusMessage' => array(
            'StatusApplicationControl' => array(
                'Start'=>'2016-10-01',
                'End'=>'2016-10-01',
                'InvTypeCode'=>'TR',
                'RatePlanCode'=>'BAR'
            ),
            'RestrictionStatus' => array(
                'Status'=>'Close'
            )
        )
    )

);


try{
    //here is my issue
    $data = $client->__call('HotelAvailNotifRQ',array($arr));
    if($data->Errors) {
        foreach($data->Errors as $error) {
            echo "Error: ".$error;
        }
    }else {
        var_dump($data);
    }
} catch (SoapFault  $e) {
    var_dump($e);
    echo $e->faultstring;
}

Trying this I get this Error: Could not locate RequestorID/@ID in soap body

But as you can see I'm sending the requestorID

I tried in different ways, Object, XML values, SoapVar, SoapParam and many other different ways... all I get is that same error... that mean I'm for some reason not sending the requestorID when I'm actually sending it!

Couples of trials done:

$arr = array(
    'POS' => array(
        '_' => array(
            'Source' => array(
                '_' => array(
                    'RequestorID' => array(
                        'type'=>'22',
                        'ID'=>$id,
                    )
                )
            )

        )
    ),
);

$pos = new StdClass();
$pos->source->requestorID = $id;
$pos->source->type = 22;

$asm = new StdClass();
$asm->HotelCode = $hc;
$asm->AvailStatusMessage->StatusApplicationControl->Start = '2016-10-01';
$asm->AvailStatusMessage->StatusApplicationControl->End = '2016-10-02';
$asm->AvailStatusMessage->StatusApplicationControl->InvTypeCode = 'TR';
$asm->AvailStatusMessage->StatusApplicationControl->RatePlanCode = 'BAR';

$arr = array(
    'POS' => $pos
    'AvailStatusMessages' => $asm
);

$xml = "
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'> 
    <SOAP-ENV:Body xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
        <OTA_HotelAvailNotifRQ xmlns='http://www.opentravel.org/OTA/2003/05' Version='1.0' TimeStamp='2005-08-01T09:30:47+08:00' EchoToken='echo-abc123'>
            <POS>
                <Source>
                    <RequestorID Type='22' ID='$id'/>
                </Source>
            </POS>
            <AvailStatusMessages HotelCode='$hc'>
                <AvailStatusMessage>
                    <StatusApplicationControl Start='2010-01-01' End='2010-01-14' InvTypeCode='A1K' RatePlanCode='GLD'/>
                    <RestrictionStatus Restriction='Departure' Status='Close' />
                </AvailStatusMessage>
            </AvailStatusMessages>
        </OTA_HotelAvailNotifRQ> 
    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>";

So basically I have tried all the possible ways... that I could think of to send this to the call and make it work.

Anyone has any idea how to proper do this? I really need help in here...

What I'm trying to do is this: https://siteminder.atlassian.net/wiki/pages/viewpage.action?pageId=2048374#space-menu-link-content

Thanks in advance.


Solution

  • Well as far as I could find out in the internet... nobody had the answer for my question so I had to keep trying until I get it working. And I did!

    Here is my example of how to work with it:

    <?php
    $RID = "BAR"; //Requestor ID
    $url = 'https://cmtpi.siteminder.com/siteconnect/services/siteconnect_v1.1.0.wsdl';
    $endpoint = 'https://cmtpi.siteminder.com/siteconnect/services';
    $service_connect = "this is your endpoint";
    
    $User = "test";  //  username
    $Password = "1234"; // password
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $endpoint);
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $input_xml);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Content-Length: ' . strlen($input_xml)));
    $data = curl_exec($ch);
    
    if(curl_exec($ch) === false){
        echo 'Curl error: ' . curl_error($ch);
    }else {
        Header("Content-type: text/xml");
        echo $data;
    }
    curl_close($ch);
    

    With this basecally the system will POST and XML data and will get a response in XML data as well.

    My $input XML had this data:

    <SOAP-ENV:Envelope xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <SOAP-ENV:Header>
            <wsse:Security SOAP-ENV:mustUnderstand="1">
                <wsse:UsernameToken>
                    <wsse:Username>test</wsse:Username>
                    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234</wsse:Password>
                </wsse:UsernameToken>
            </wsse:Security>
        </SOAP-ENV:Header>
        <SOAP-ENV:Body>
            <OTA_HotelAvailNotifRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.0" EchoToken="3c763f03-6333-4f38-9835-c7cf8433c263" TimeStamp="2016-11-25T18:30:29+01:00">
                <POS>
                    <Source>
                        <RequestorID TYPE="22" ID="BAR"/>
                        <BookingChannel Primary="1" Type="1">
                            <CompanyName Code="TST">TEST</CompanyName>
                        </BookingChannel>
                    </Source>
                </POS>
                <AvailStatusMessages HotelCode="HOTEL_ID">
                    <AvailStatusMessage>
                      <StatusApplicationControl Start="2010-01-01" End="2010-01-01" InvTypeCode="A1K" RatePlanCode="GLD" />
                        <!-- Content omitted -->
                    </AvailStatusMessage>
                    <AvailStatusMessage>
                      <StatusApplicationControl Start="2010-01-02" End="2010-01-02" InvTypeCode="A1K" RatePlanCode="GLD" />
                        <!-- Content omitted -->
                    </AvailStatusMessage>
                    <AvailStatusMessage>
                      <StatusApplicationControl Start="2010-01-03" End="2010-01-03" InvTypeCode="A1K" RatePlanCode="GLD" />
                        <!-- Content omitted -->
                    </AvailStatusMessage>
               </AvailStatusMessages>
            </OTA_HotelAvailNotifRQ>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    When I send them this they will responde with data base... and we start doing transactions.

    My main problem was how to pass the REQUESTOR ID, the requestor ID was basecally the ID attribute from source, that I have showed before I was trying to send it as object or variable... my confusion was I was trying to do a SOAP call into a XML api... and all got messed up :)

    My english is not that good... but at least I'm here to show my solution.

    Maybe this can help someone in the future.