raigu/x-road-soap-envelope-builder

PHP library for generating X-Road SOAP envelope.

v2.0.0 2023-05-28 08:03 UTC

This package is auto-updated.

Last update: 2024-04-28 10:11:02 UTC


README

Latest Stable Version License: MIT Build Status codecov Scrutinizer

x-road-soap-envelope-builder

PHP library for generating a SOAP envelope for X-Road request.

Requirements

  • php ^8.0
  • DOM extension

(For PHP ^PHP7.2 use version 1.1.1)

Installation

$ composer require raigu/x-road-soap-envelope-builder

Usage

Building SOAP envelope for X-Road request

$builder = \Raigu\XRoad\SoapEnvelope\SoapEnvelopeBuilder::create()
    ->withService('EE/GOV/70008440/rr/RR437/v1')
    ->withClient('EE/COM/12213008/gathering')
    ->withBody(<<<EOD
        <prod:RR437 xmlns:prod="http://rr.x-road.eu/producer">
            <request>
                <Isikukood>00000000000</Isikukood>
            </request>
        </prod:RR437>
EOD;
    );

$envelope = $builder->build();

echo $envelope;

The method's withBody input parameter can be generated from WSDL using free tools like WSDL Analyzer or SOAP UI. The WSDL-s can be found in X-Road catalog.

See short (1:34) demo video how to acquire WSDL and generate a request body.

Builder methods

Method name Mandatory Description
withService Y service id.
Format: {xRoadInstance}/{memberClass}/{memberCode}/(subsystemCode}/{serviceCode}/{serviceVersion}
withClient Y client id.
Format: {xRoadInstance}/{memberClass}/{memberCode}/(subsystemCode}
withBody Y X-Road service request witch is but into the X-Road message body. See short video how you can find the WSDL based on service id and generate body from WSDL. If you use SoapUI make sure you do not miss the XML proper namespace definition.
withUserId N natural person code who is initiating the request. Format: {isoCountryCode2Alfa}/{personCode}. Optional.
withRepresentedParty N Party who is represented by client. See X-Road Third Party Representation Extension for more info.
Format: [{partyClass}/]{partyCode}. Optional.

Making X-Road request

In following samples assign your X-Road security server URL to $securityServerUrl.

Using Guzzle

$client = new \Guzzle\Http\Client();
$request = $client->post(
    $securityServerUrl,
    [ 
        'Content-Type' => 'text/xml',
        'SOAPAction' => ''
    ],
    $envelope
);

$response = $client->send($request);

echo $response->getBody();

Using curl

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $securityServerUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $envelope);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type' => 'text/xml',
        'SOAPAction' => ''
    ]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);

curl_close($ch);

echo $output;

References