<?php
require_once 'conf.php';

// STEP 0 : Get the values 
foreach ($_REQUEST as $var => $val) {
	$request[$var] = $val;
}

// STEP 1 : soap flow options
$options = array(
	'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
	'cache_wsdl' => WSDL_CACHE_NONE,
	'soap_version' => SOAP_1_1,
	'encoding' => 'UTF-8'
);

// STEP 2 : Soap client initialization
$client = new SoapClient(WS_GATEWAY . 'user-account-v2?wsdl', $options);

// STEP 3 : Check is the email is free in Hipay
$result = $client->isAvailable(array('parameters'=>array(
	'wsLogin'=> WS_LOGIN,
	'wsPassword'=> WS_PSW,
	'email'=> $request['email']
)));

// STEP 4 : Soap call on createWithWebsite method of user-account-v2 webservice if email available
if ($result->isAvailableResult->isAvailable) {
	$result2 = $client->createWithWebsite(array('parameters'=>array(
		'wsLogin'=>  WS_LOGIN,
		'wsPassword'=> WS_PSW,
		'email'=> $request['email'],
		'websiteId'=> WEBSITE,
		'firstname'=> $request['firstname'],
		'lastname'=> $request['lastname'],
		'currency'=> $request['currency'],
		'locale' => $request['locale'],
		'ipAddress'=> '127.0.0.1',
		'websiteBusinessLineId'=> $request['websiteBusinessLineId'],
		'websiteTopicId' => $request['websiteTopicId'],
		'websiteContactEmail'=> $request['websiteContactEmail'],
		'websiteName'=> $request['websiteName'],
		'websiteUrl'=> $request['websiteUrl'],
		'websiteMerchantPassword' => $request['websiteMerchantPassword']
	)));
	// STEP 5 : Response
	var_dump($result2);
		
}
else {
	echo $request['email'] . " is not available";
	print_r($result);
}
?>
<?php 
 /*
  * 
  object(stdClass)#2 (1) {
  ["createWithWebsiteResult"]=>
  object(stdClass)#3 (5) {
    ["code"]=>
    int(0)
    ["description"]=>
    string(26) "Account creation succeeded"
    ["userAccountId"]=>
    int(85597)
    ["userSpaceId"]=>
    int(71358)
    ["websiteId"]=>
    int(3249)
  }
}
  * 
  * */
?>