-
-
Save thinkerman/faebce43254a27d6340e6f993aea7568 to your computer and use it in GitHub Desktop.
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 | |
$id = 75482; | |
$password = '3A90E5J0f6OUIfqN1Qu59gYrjDgDblfL'; | |
$card = '4627081718568608'; | |
$ssl_verify = TRUE; | |
$data = <<<XML | |
<oper>cmt</oper> | |
<wait>0</wait> | |
<test>0</test> | |
<payment id="test3"> | |
<prop name="b_card_or_acc" value="$card" /> | |
<prop name="amt" value="1" /> | |
<prop name="ccy" value="UAH" /> | |
<prop name="details" value="test%20merch%20not%20active" /> | |
</payment> | |
XML; | |
// normalization | |
$data = preg_replace('/>\s+</', "><", $data); | |
$data = trim($data); | |
$signature = sha1(md5($data . $password)); | |
$data = <<<XML | |
<request> | |
<merchant> | |
<id>$id</id> | |
<signature>$signature</signature> | |
</merchant> | |
<data>$data</data> | |
</request> | |
XML; | |
$curl = curl_init("https://api.privatbank.ua/p24api/pay_pb"); | |
if (FALSE == $ssl_verify) { | |
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | |
} | |
// do not output to stdout | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($curl, CURLOPT_POST, TRUE); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | |
$response = curl_exec($curl); | |
if (!$response) | |
file_put_contents('php://stderr', curl_error($curl)); | |
$xml = simplexml_load_string($response); | |
$error = $xml->xpath('//error'); | |
if ($error) { | |
$attributes = $error[0]->attributes(); | |
file_put_contents('php://stderr', $attributes['message']); | |
} | |
else { | |
$payment = $xml->xpath('//payment'); | |
echo json_encode($payment); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment