Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $URL = 'http://www.reefservices.co.uk/leadws/lead.asmx';
- function createRequestXML($params = array()) {
- $DealerCode = (array_key_exists('DealerCode',$params)) ? $params['DealerCode'] : 123456; // required
- $LeadType = (array_key_exists('LeadType',$params)) ? $params['LeadType'] : 'Used Car Enquiry'; // required
- $LeadSource = (array_key_exists('LeadSource',$params)) ? $params['LeadSource'] : 'Website'; // required
- $LeadId = (array_key_exists('LeadId',$params)) ? $params['LeadId'] : '123456'; // not required
- $CustomerType = (array_key_exists('CustomerType',$params)) ? $params['CustomerType'] : 1; // required. can be : 0 for Company, 1 for Individual
- $Title = (array_key_exists('Title',$params)) ? $params['Title'] : 'Master'; // not required
- $Forename = (array_key_exists('Forename',$params)) ? $params['Forename'] : 'Test'; // required
- $Lastname = (array_key_exists('Lastname',$params)) ? $params['Lastname'] : 'Name'; // required
- $Companyname = (array_key_exists('Companyname',$params)) ? $params['Companyname'] : 'Company'; // not required
- /* One of the following fields is required to have a value */
- $Homephone = (array_key_exists('Homephone',$params)) ? $params['Homephone'] : '0123456789';
- $Workphone = (array_key_exists('Workphone',$params)) ? $params['Workphone'] : '0123456789';
- $Mobilephone = (array_key_exists('Mobilephone',$params)) ? $params['Mobilephone'] : '0123456789';
- $Email = (array_key_exists('Email',$params)) ? $params['Email'] : 'test@test.co.uk';
- /* One of the above fields is required to have a value */
- $Address1 = (array_key_exists('Address1',$params)) ? $params['Address1'] : 'AAAAAA'; // not required
- $Address2 = (array_key_exists('Address2',$params)) ? $params['Address2'] : 'BBBBBB'; // not required
- $City = (array_key_exists('City',$params)) ? $params['City'] : 'CCCCCCC'; // not required
- $County = (array_key_exists('County',$params)) ? $params['County'] : 'DDDDDDDD'; // not required
- $Postcode = (array_key_exists('Postcode',$params)) ? $params['Postcode'] : 'EEEEE'; // not required
- $dpapostal = (array_key_exists('dpapostal',$params)) ? $params['dpapostal'] : 'Y'; // required. can be Y/N
- $dpasms = (array_key_exists('dpasms',$params)) ? $params['dpasms'] : 'Y'; // required. can be Y/N
- $dpstel = (array_key_exists('dpstel',$params)) ? $params['dpstel'] : 'Y'; // required. can be Y/N
- $dpaemail = (array_key_exists('dpaemail',$params)) ? $params['dpaemail'] : 'Y'; // required. can be Y/N
- $Methodofcontact = (array_key_exists('Methodofcontact',$params)) ? $params['Methodofcontact'] : 'Internet'; // not required
- $Sourceofenquiry = (array_key_exists('Sourceofenquiry',$params)) ? $params['Sourceofenquiry'] : 'Autotrader'; // not required
- $Message = (array_key_exists('Message',$params)) ? $params['Message'] : 'I would like to buy a car please.'; // not required
- $Regno = (array_key_exists('Regno',$params)) ? $params['Regno'] : 'R33FBS'; // not required
- $Newused = (array_key_exists('Newused',$params)) ? $params['Newused'] : 'USED'; // not required. can be "NEW"/"USED"
- $Make = (array_key_exists('Make',$params)) ? $params['Make'] : 'BMW'; // not required
- $Model = (array_key_exists('Model',$params)) ? $params['Model'] : '3 Series'; // not required
- $Derivative = (array_key_exists('Derivative',$params)) ? $params['Derivative'] : '330D Coupe'; // not required
- $Fuel = (array_key_exists('Fuel',$params)) ? $params['Fuel'] : 'Diesel'; // not required
- $Colour = (array_key_exists('Colour',$params)) ? $params['Colour'] : 'Silver'; // not required
- $PartEx_Regno = (array_key_exists('PartEx_Regno',$params)) ? $params['PartEx_Regno'] : 'N476AKV'; // not required
- $PartEx_Mileage = (array_key_exists('PartEx_Mileage',$params)) ? $params['PartEx_Mileage'] : '45600'; // not required
- $xml = ' <?xml version="1.0" encoding="UTF-8" ?>
- <SecurityInfo>
- <Username>'.REEF_USERNAME.'</Username>
- <Password>'.REEF_PASSWORD.'</Password>
- </SecurityInfo>
- <Lead>
- <DealerCode>'.$DealerCode.'</DealerCode>
- <LeadType>'.$LeadType.'</LeadType>
- <LeadSource>'.$LeadSource.'</LeadSource>
- <LeadId>'.$LeadId.'</LeadId>
- <Customer>
- <CustomerType>'.$CustomerType.'</CustomerType>
- <Title>'.$Title.'</Title>
- <Forename>'.$Forename.'</Forename>
- <Lastname>'.$Lastname.'</Lastname>
- <Companyname>'.$Companyname.'</Companyname>
- <Homephone>'.$Homephone.'</Homephone>
- <Workphone>'.$Workphone.'</Workphone>
- <Mobilephone>'.$Mobilephone.'</Mobilephone>
- <Email>'.$Email.'</Email>
- <Address>
- <Address1>'.$Address1.'</Address1>
- <Address2>'.$Address2.'</Address2>
- <City>'.$City.'</City>
- <County>'.$County.'</County>
- <Postcode>'.$Postcode.'</Postcode>
- </Address>
- <Dpa>
- <dpapostal>'.$dpapostal.'</dpapostal>
- <dpasms>'.$dpasms.'</dpasms>
- <dpstel>'.$dpstel.'</dpstel>
- <dpaemail>'.$dpaemail.'</dpaemail>
- </Dpa>
- <Marketing>
- <Methodofcontact>'.$Methodofcontact.'</Methodofcontact>
- <Sourceofenquiry>'.$Sourceofenquiry.'</Sourceofenquiry>
- </Marketing>
- <Message>'.$Message.'</Message>
- </Customer>
- <Vehicle>
- <Regno>'.$Regno.'</Regno>
- <Newused>'.$Newused.'</Newused>
- <Make>'.$Make.'</Make>
- <Model>'.$Model.'</Model>
- <Derivative>'.$Derivative.'</Derivative>
- <Fuel>'.$Fuel.'</Fuel>
- <Colour>'.$Colour.'</Colour>
- </Vehicle>
- <PartEx>
- <Regno>'.$PartEx_Regno.'</Regno>
- <Mileage>'.$PartEx_Mileage.'</Mileage>
- </PartEx>
- </Lead>';
- return str_replace("\n","",$xml);
- }
- $send = createRequestXML(array(
- 'DealerCode' => 123456,
- 'Title' => 'Mr',
- 'Companyname' => 'Reef',
- 'Email' => 'test@test.com',
- 'Methodofcontact' => 'Internet',
- 'Sourceofenquiry' => 'Stackoverflow',
- 'Message' => 'I would like to buy a car',
- 'Newused' => 'USED',
- 'Make' => 'BMW',
- 'Model' => '3 Series',
- 'Derivative' => '330D Coupe',
- 'Fuel' => 'Diesel',
- 'Colour' => 'Silver',
- 'PartEx_Mileage' => '45600'
- ));
- try {
- $client = new SoapClient("http://www.reefservices.co.uk/leadws/lead.asmx?WSDL",array(
- 'location' => $URL,
- 'uri' => "http://www.reefservices.co.uk/leadws/",
- 'trace' => 1,
- 'exceptions' => true
- ));
- $return = $client->Submit(array('Data' => $send));
- $the_xml = str_replace("\n",'',rtrim($return->SubmitResult,','));
- preg_match_all("/<SUMMARY[^>]*>(.*?)<\/SUMMARY>/si", $the_xml, $summary, PREG_PATTERN_ORDER);
- preg_match_all("/<LEADID[^>]*>(.*?)<\/LEADID>/si", $the_xml, $lead, PREG_PATTERN_ORDER);
- preg_match_all("/<REEFID[^>]*>(.*?)<\/REEFID>/si", $the_xml, $ref, PREG_PATTERN_ORDER);
- $entries = array();
- if(count($lead) == count($ref)) {
- foreach($lead[1] AS $key => $value) {
- $entries[$key] = array(
- 'lead' => trim($value),
- 'ref' => trim($ref[1][$key])
- );
- }
- }
- $final = array(
- 'summary' => $summary[1],
- 'leads' => $entries
- );
- echo '<pre>';
- print_r($final);
- echo '</pre>';
- } catch(SoapFault $e) {
- echo '<h3>Exception</h3>';
- echo '<pre>';
- print_r($e);
- echo '</pre>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement