<?php
function create_token_eway()
{
$testUrl = "https://www.eway.com.au/gateway/ManagedPaymentService/test/managedCreditCardPayment.asmx";
$liveUrl = "https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx";
$eWaySOAPActionURL = "https://www.eway.com.au/gateway/managedpayment";
$eWayCustomerId = "87654321";
/* test account */
$eWayCustomerEmail = "test@eway.com.au";
/* test email */
$eWayCustomerPassword = "test123";
/* test password */
$updateCustomer = false;
$customTag = "CreateCustomer";
/* For update customer: "UpdateCustomer". */
/**
* If you want to update existing customer do the following -
*/
if ($updateCustomer) {
$updateCustomerEWayId = "9876543211000";
/* Already saved customer id. */
$customTag = "UpdateCustomer";
$updateCustomerEWayId = "<managedCustomerID>" .
$updateCustomerEWayId .
"</managedCustomerID>";
}
$directXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap12:Envelope
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">
<soap12:Header>
<eWAYHeader xmlns=\"" . $eWaySOAPActionURL . "\">
<eWAYCustomerID>" . $eWayCustomerId . "</eWAYCustomerID>
<Username>" . $eWayCustomerEmail . "</Username>
<Password>" . $eWayCustomerPassword . "</Password>
</eWAYHeader>
</soap12:Header>
<soap12:Body>
<" . $customTag . " xmlns=\"" . $eWaySOAPActionURL . "\">
" . $updateCustomerEWayId . "
<Title>Mr.</Title>
<FirstName>Pritom</FirstName>
<LastName>Kumar Mondal</LastName>
<Address></Address>
<Suburb></Suburb>
<State></State>
<Company>Khulna University</Company>
<PostCode></PostCode>
<Country>au</Country>
<Email>pritomkucse@gmail.com</Email>
<Fax></Fax>
<Phone></Phone>
<Mobile></Mobile>
<CustomerRef>CSE-060238</CustomerRef>
<JobDesc></JobDesc>
<Comments></Comments>
<URL></URL>
<CCNumber>4444333322221111</CCNumber>
<CCNameOnCard>Pritom K Mondal</CCNameOnCard>
<CCExpiryMonth>12</CCExpiryMonth>
<CCExpiryYear>15</CCExpiryYear>
</" . $customTag . ">
</soap12:Body>
</soap12:Envelope>";
$result = makeCurlCall(
$testUrl, /* CURL URL */
"POST", /* CURL CALL METHOD */
array(
/* CURL HEADERS */
"Content-Type: text/xml; charset=utf-8",
"Accept: text/xml",
"Pragma: no-cache",
"SOAPAction: " . $eWaySOAPActionURL . "/" . $customTag,
"Content_length: " . strlen(trim($directXML))
),
null, /* CURL GET PARAMETERS */
$directXML /* CURL POST PARAMETERS AS XML */ );
if ($result != null && isset($result["response"])) {
echo $result["response"]; /* Result printed below */
}
die("");
}
/* makeCurlCall */
function makeCurlCall($url, $method = "GET", $headers = null, $gets = null, $posts = null)
{
$ch = curl_init();
if ($gets != null) {
$url .= "?" . (http_build_query($gets));
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ($posts != null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $posts);
}
if ($method == "POST") {
curl_setopt($ch, CURLOPT_POST, true);
} else if ($method == "PUT") {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
} else if ($method == "HEAD") {
curl_setopt($ch, CURLOPT_NOBODY, true);
}
if ($headers != null && is_array($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array(
"code" => $code,
"response" => $response
);
}
create_token_eway();?>
Output
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <CreateCustomerResponse
xmlns="https://www.eway.com.au/gateway/managedpayment"> <CreateCustomerResult>9876543211000</CreateCustomerResult> </CreateCustomerResponse> </soap:Body> </soap:Envelope>
No comments:
Post a Comment