[eluser]kilishan[/eluser]
I'm trying to communicate with the eWay server and had everything working until we ended up needing to switch to a different API. The problem is that SoapClient is creating a different namespace for the header (that includes the authentication) then from the body, which, obviously, doesn't get me any results. Instead, I get eWay's servers saying it must have the authentication information.
Here's my code:
Code: $client = new SoapClient($url.'?WSDL', array('trace'=>TRUE));
// Set our SOAP Headers for authentication
$header_body = array(
'eWAYCustomerID' => $gateway['customer_id'],
'Username' => $gateway['username'],
'Password' => $gateway['password']
);
$header_var = new SoapVar($header_body, SOAP_ENC_OBJECT);
$header = new SOAPHeader('http://www.eway.com.au/gateway/managedpayment', 'eWAYHeader', $header_body);
//$client->__setSoapHeaders($header);
try {
$response = $client->__soapCall($action, $xml, null, $header);
} catch (SoapFault $e)
{
echo 'SOAP Fault: '. $e->getMessage()."<br>\n";
}
As you can see, I've tried it with and without using a SoapVar for the header, all with no luck.
Here's the XML request that is being created:
Code: <soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.eway.com.au/gateway/managedpayment" xmlns:ns2="http://www.eway.com.au/gateway/managedpayment">
<soap-env:header>
<ns2:ewayheader>
<ewaycustomerid>87654321</ewaycustomerid>
<username>[email protected]</username>
<password>test123</password>
</ns2:ewayheader>
</soap-env:header>
<soap-env:body>
<ns1:createcustomer>...</ns1:createcustomer> Does anyone have any ideas here? I've been banging my head on the desk for far too long today.
Thanks.
[eluser]Unknown[/eluser]
Hi,
This has been doing my head in for about a week
have finally managed to get it working using a __doRequest constructor
EWays api don't recognize namespaces correctly
this is what i have
Code: function query_customer() {
$url = 'https://www.eway.com.au/gateway/ManagedPaymentService/test/managedCreditCardPayment.asmx';
$uri = 'https://www.eway.com.au/gateway/managedpayment';
$action = 'CreateCustomer';
$options = array(
);
$xml = array(
// 'managedCustomerID' => '9876543211000'
'CCNameOnCard' => 'John Smith',
'CCExpiryMonth' => '12',
'CCExpiryYear' => '12',
'CCNumber' => '4444333322221111',
'CustomerRef' => 'ref123',
'Title' => 'Mr.',
'FirstName' => 'John',
'LastName' => 'Smith',
'Company' => 'Acme Widgets',
'JobDesc' => 'CEO',
'Email' => '',
'Address' => '',
'Suburb' => '',
'State' => '',
'PostCode' => '2000',
'Country' => 'au',
'Phone' => '',
'Mobile' => '',
'Fax' => '',
'URL' => '',
'Comments' => ''
);
$client = new MSSoapClient($url .'?WSDL', array(
'TRACE' => TRUE,
'location' => $url
));
// Set our SOAP Headers for authentication
$header_body = array(
'eWAYCustomerID' => '87654321',
'Username' => '[email protected]',
'Password' => 'test123',
);
$header_var = new SoapVar($header_body, SOAP_ENC_OBJECT);
$header = new SOAPHeader( 'https://www.eway.com.au/gateway/managedpayment' , 'eWAYHeader', $header_var);
$client->__setSoapHeaders($header);
try {
// $response = $client->__soapCall('QueryCustomer',$xml, null, $header);
// $client->CreateCustomer($header_body);
$response = $client->$action($xml);
} catch (SoapFault $e) {
echo 'SOAP Fault: ' . $e->getMessage() . "<br>\n";
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
echo "Response:\n" . $client->__getLastResponse() . "\n";
}
echo "Response:\n" . $client->__getLastResponse() . "\n";
print_r($response);
}
}
class MSSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version) {
$namespace = "xmlns='https://www.eway.com.au/gateway/managedpayment'";
$request = preg_replace('/<ns1:/', '<', $request);
$request = preg_replace('/ns1:/', '', $request);
$request = preg_replace('/-ENV/', '', $request);
$request = str_replace(':ns1', '', $request);
// $request = str_replace('<eWAYHeader', '<eWAYHeader '.$namespace, $request);
// $request = str_replace('<QueryCustomer>', '<QueryCustomer '.$namespace.'>', $request);
echo $request;
return parent::__doRequest($request, $location, $action, $version);
}
}
and this the XML request
Code: <?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Header>
<eWAYHeader>
<eWAYCustomerID>87654321</eWAYCustomerID>
<Username>[email protected]</Username>
<Password>test123</Password>
</eWAYHeader>
</SOAP:Header>
<SOAP:Body>
<CreateCustomer>
<Title>Mr.</Title>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<Address></Address>
<Suburb></Suburb>
<State></State>
<Company>Acme Widgets</Company>
<PostCode>2000</PostCode>
<Country>au</Country>
<Email></Email>
<Fax></Fax>
<Phone></Phone>
<Mobile></Mobile>
<CustomerRef>ref123</CustomerRef>
<JobDesc>CEO</JobDesc>
<Comments></Comments>
<URL></URL>
<CCNumber>4444333322221111</CCNumber>
<CCNameOnCard>John Smith</CCNameOnCard>
<CCExpiryMonth>12</CCExpiryMonth>
<CCExpiryYear>12</CCExpiryYear>
</CreateCustomer>
</SOAP:Body>
</SOAP:Envelope>
hopefully this helps, let me know if this works
|