<?php
// Procedure pour créer les comptes WALLET des producteurs

ini_set('soap.wsdl_cache_ttl', 1);

define('WS_GATEWAY','https://test-ws.hipay.com/soap/');
define('WS_LOGIN', 'd4a919efc4843389def7d56922c56c58'); // hipay@lrqdo.fr
define('WS_PSW', 'a2e33c6fdad9cbd3685cbf3fe8c868e0'); // hipay@lrqdo.fr
define('WEBSITE', '7432'); // hipay@lrqdo.fr		

$new_account = 'merchant' . time().'@lrqdo.com';

// 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',
	'trace' => 1
);

// 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'			=> $new_account
)));
var_dump($result);
// STEP 4 : Soap call on createWithWebsite method of user-account-v2 webservice if email available
if ($result->isAvailableResult->isAvailable) {
	$queryparameters = array('parameters'=>array(
	'wsLogin'=> WS_LOGIN,
	'wsPassword'=> WS_PSW,
	'userAccountBasic'=> array(
		'email'=> $new_account,
		'title'=> 1,
		'firstname'=> 'James',
		'lastname'=> 'Dupont',
		'currency'=> 'EUR',
		'locale' => 'en_GB',
		'ipAddress'=> '127.0.0.1',
		'entity'	=>	'wallet'
	),
	'userAccountDetails'=> array(
		'legalStatus'=> 1,
		'structure'=> 'ltd',
		'companyName'=> 'your company',
		'directorTitle'=> 1,
		'directorRole'=> 'CEO',
		'cpf'=> 'test',
		'identificationNumberType' => 'ID',
		'identificationNumber' => '1234567890',
		'address' => 'victoria st, 1200',
		'zipCode' => '34512',
		'city'=> 'london',
		'country' => 'GB',
		'language'=> 'en',
		'timeZone'=> 'Europe/Dublin',
		'birthDate'=> '12/11/1965',
		'contactEmail'=> 'jdupont@free.fr',
		'phoneNumber'=> '123456',
		'mobilePhoneNumber'=> '123456',
		'faxNumber'=> '123456',
		'europeanVATNumber'=> '123456',
		'businessId'=> '123456',
		'businessLineId' => 12,
		'question1'=> 1,
		'answer1' => 'test',
		'question2'=> 2,
		'answer2' => 'test',
		'antiPhishingKey' => 'testtest',
		'receiveHipayInformation' => 1,
		'receiveCommercialInformation'=>1,
		'termsAgreed'=>1
	),
	'websites'=> array(
		'item'=> array(
			'websiteBusinessLineId'=> 12,
			'websiteTopicId' => 13,
			'websiteContactEmail'=> 'jdupont@free.fr',
			'websiteName'=> 'merchant.com',
			'websiteUrl'=> 'http://www.merchant.com',
			'websiteMerchantPassword' => 'passwdtest'
		)
	),
	));

	// STEP 5 : Soap call on createFullUserAccount method of user-account-v2 webservice
	$result2 = $client->createFullUserAccount($queryparameters);
}
else {
	echo $request['email'] . " is not available";
//	print_r($result);
}

echo $client->__getLastRequest();
echo $client->__getLastResponse();


?>