Skip to content

Instantly share code, notes, and snippets.

@jrasanen
Created July 14, 2017 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrasanen/aa7d19b6ba2accad0e31dd8045c39104 to your computer and use it in GitHub Desktop.
Save jrasanen/aa7d19b6ba2accad0e31dd8045c39104 to your computer and use it in GitHub Desktop.
Checkout PHP refund example
<?php
$xml = "<?xml version='1.0'?>
<checkout>
<identification>
<merchant>375917</merchant>
<stamp>9191919191999</stamp> <!-- Unique ID for each request -->
</identification>
<message>
<refund>
<stamp>636356238928109320</stamp> <!-- Original trade's stamp -->
<reference>1</reference> <!-- api_reference OR original payment's reference -->
<amount>50</amount> <!-- amount is in cents, maximum amount is the amount of original payment -->
<receiver>
<email>niko.lehtinen@checkout.fi</email>
</receiver>
</refund>
</message>
</checkout>";
$encoded_xml = base64_encode($xml);
$postData = array(
'data' => $encoded_xml,
'mac' => strtoupper(hash_hmac('sha256', $encoded_xml, 'SAIPPUAKAUPPIAS'))
);
var_dump(postData("https://rpcapi.checkout.fi/refund2", $postData));
function postData($url, $postData)
{
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query($postData),
"verify_peer"=>false,
"verify_peer_name"=>false,
),
"ssl" => array(
"verify_peer"=>false,
"verify_peer_name"=>false,
)
));
return file_get_contents($url, false, $context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment