/* Refund using eWay */
function refund_using_eway()
{
$testUrl = "https://www.eway.com.au/gateway/xmltest/refund_test.asp";
$liveUrl = "https://www.eway.com.au/gateway/xmlpaymentrefund.asp";
$eWaySOAPActionURL = "https://www.eway.com.au/gateway/managedpayment";
$eWayCustomerId = "87654321";
$eWayTotalAmount = 100;
$directXML = "<ewaygateway>" .
"<ewayCustomerID>" . $eWayCustomerId . "</ewayCustomerID>" .
"<ewayOriginalTrxnNumber>20488</ewayOriginalTrxnNumber>" .
"<ewayTotalAmount>" . $eWayTotalAmount . "</ewayTotalAmount>" .
"<ewayCardExpiryMonth>01</ewayCardExpiryMonth>" .
"<ewayCardExpiryYear>2015</ewayCardExpiryYear>" .
"<ewayOption1></ewayOption1>" .
"<ewayOption2></ewayOption2>" .
"<ewayOption3></ewayOption3>" .
"<ewayRefundPassword>test123</ewayRefundPassword>" .
"</ewaygateway>";
$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,
"Content_length: " . strlen(trim($directXML))
),
null, /* CURL GET PARAMETERS */
$directXML /* CURL POST PARAMETERS AS XML */
);
if ($result != null && isset($result["response"])) {
$response = new SimpleXMLElement($result["response"]);
$response = simpleXMLToArray($response);
print_r2($response);
}
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
);
}
/* Response */
Array
(
[ewayTrxnStatus] => Array
(
[__cdata] => False
)
[ewayTrxnNumber] => Array
(
[__cdata] =>
)
[ewayTrxnOption1] => Array
(
[__cdata] =>
)
[ewayTrxnOption2] => Array
(
[__cdata] =>
)
[ewayTrxnOption3] => Array
(
[__cdata] =>
)
[ewayAuthCode] => Array
(
[__cdata] =>
)
[ewayReturnAmount] => Array
(
[__cdata] => 100
)
[ewayTrxnError] => Array
(
[__cdata] => Error: Invalid Original Transaction Number. Your credit card has not been billed for this transaction.
)
)
/* Dont worry about ewayTrxnError, when you refund live it will work */
Wednesday, August 7, 2013
Refund transaction using php api using eWay account
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment