2016-01-28 5 views
0

Я пытаюсь настроить sagepay-сообщение api для запроса транзакций.Примеры отчетов sagepay и примеры api-кода admin в php

У меня есть код из другого вопроса, который почти меня охватывает, но то, что я хочу сделать, это сохранить возвращенный XML и сохранить его в базе данных. Как мне это сделать?

<?php 

$command = 'getTransactionList'; 
$vendor = 'vendor'; 
$user = 'user'; 
$password = 'password'; 
$startdate = '01/10/2015 00:00:01'; 
$enddate = '31/10/2015 23:59:59'; 

$string = '<command>'.$command.'</command><vendor>'.$vendor.'</vendor><user>'.$user.'</user><startdate>'.$startdate.'</startdate><enddate>'.$enddate.'</enddate>'; 

$crypt = MD5($string . '<password>' . $password . '</password>'); 

$curl = curl_init('https://test.sagepay.com/access/access.htm'); 
curl_setopt($curl, CURLOPT_FAILONERROR, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$result = curl_exec($curl); 

$rxml = new SimpleXMLElement($result); 

?> 

<html> 
<body> 

<form method="post" action="https://test.sagepay.com/access/access.htm" enctype="application/x-www-form-urlencoded"> 
<input type="hidden" name="XML" value="<vspaccess><?php echo $string; ?><signature><?php echo $crypt; ?></signature></vspaccess>" /> 
<input type="submit" name="Button" value="Send" /> 
</form> 

</body> 
</html> 

Спасибо за любую помощь, которую вы можете дать.

+1

Если у вас есть решение, либо удалить этот вопрос , или отправить ответ. Редактирование контента никому не помогает. – deceze

+0

Точка взята. См. Ответ. – user4715855

ответ

2

Ответьте ниже, если кто-либо заинтересован.

<?php 

$command = 'getTransactionList'; 
$vendor = 'vendor'; 
$user = 'user'; 
$password = 'password'; 
$startdate = '20/10/2015 00:00:01'; 
$enddate = '22/10/2015 23:59:59'; 

$string = '<command>'.$command.'</command><vendor>'.$vendor.'</vendor><user>'.$user.'</user><startdate>'.$startdate.'</startdate><enddate>'. $enddate.'</enddate><txtypes><txtype>PAYMENT</txtype></txtypes><result>failure</result>'; 

$crypt = MD5($string . '<password>' . $password . '</password>'); 

$xml = 'XML=<vspaccess>'.$string.'<signature>'.$crypt.'</signature></vspaccess>'; 

$curl = curl_init('https://test.sagepay.com/access/access.htm'); 
curl_setopt($curl, CURLOPT_FAILONERROR, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); 
$result = curl_exec($curl); 

$rxml = new SimpleXMLElement($result); 

foreach($rxml->transactions->transaction as $transx) 
{ 
    echo '<p>Payment Type = '.$transx->transactiontype.'</p>'; 
    echo '<p>Amount = '.$transx->amount.'</p>'; 
    echo '<p>Name = '.$transx->cardholder.'</p>'; 
    echo '<p>Result = '.$transx->result.'</p>'; 
} 

?> 

Я только повторил информацию на экране, однако вы можете принять возвращенные данные и хранить в базе данных, выполнить запрос и т.д ..

+0

ничего не получает :( – shzyincu

Смежные вопросы