Created
July 14, 2017 10:44
-
-
Save jrasanen/aa7d19b6ba2accad0e31dd8045c39104 to your computer and use it in GitHub Desktop.
Checkout PHP refund example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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