sagepay卷曲请求

问题描述:

我想处理通过我的网站上进行付款,并希望使用sagepay用于这一目的。我已经通过指导走了sagepay去这里直接集成提到: http://www.sagepay.com/sites/default/files/pdf/user_guides/sagepaydirectprotocolandintegrationguidelines_0.pdf 现在, 我已经创建所需的字段来处理HTTP请求的脚本做出必要的修改。这里是代码:sagepay卷曲请求

<?php 
//extract data from the post 
extract($_POST); 

//set POST variables 
$url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp'; 
$txcode = 'prefix_' . time() . rand(0, 9999); 
$fields = array(
         'VPSProtocol'=>urlencode("2.23"), 
         'TxType'=>urlencode("PAYMENT"), 
         'Vendor'=>urlencode("myvendorname"), 
         'VendorTxCode'=>urlencode($txcode), 
         'Amount'=>urlencode("2.00"), 
         'Currency'=>urlencode("GBP"), 
         'Description'=>urlencode("payment for my site"), 
         'CardHolder'=>urlencode('DELTA'), 
         'CardNumber'=>urlencode(4929000000006), 
         'ExpiryDate'=>urlencode(1213), 
         'CV2'=>urlencode(123), 
         'CardType'=>urlencode('VISA'), 
         'BillingSurname'=>urlencode('surname'), 
         'BillingFirstnames'=>urlencode('name'), 
         'BillingAddress1'=>urlencode(' clifton'), 
         'BillingCity'=>urlencode('Bristol'), 
         'BillingPostCode'=>urlencode('BS82UE'), 
         'BillingCountry'=>urlencode('United Kingdom'), 
         'DeliverySurname'=>urlencode('surname'), 
         'DeliveryFirstnames'=>urlencode('name'), 
         'DeliveryAddress1'=>urlencode(' clifton'), 
         'DeliveryCity'=>urlencode('Bristol'), 
         'DeliveryPostCode'=>urlencode('bs82ue'), 
         'DeliveryCountry'=>urlencode('united kingdom'), 

       ); 

//url-ify the data for the POST 
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
rtrim($fields_string,'&'); 

//open connection 
$ch = curl_init(); 

//set the url, number of POST vars, POST data 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_POST,count($fields)); 
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); 

//execute post 
$result = curl_exec($ch); 
print_r($result); 
echo "end"; 
//close connection 
curl_close($ch); 
?> 

但我没有得到任何回应回..可能是什么问题呢?它在wamp服务器和非https网址。

此代码对我的作品。我添加了几个CURL函数并删除了一个,这就实现了这个功能。

<?php 
//extract data from the post 
extract($_POST); 

//set POST variables 
$url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp'; 
$txcode = 'prefix_' . time() . rand(0, 9999); 
$fields = array(
         'VPSProtocol'=>urlencode("2.23"), 
         'TxType'=>urlencode("PAYMENT"), 
         'Vendor'=>urlencode("myvendorname"), 
         'VendorTxCode'=>urlencode($txcode), 
         'Amount'=>urlencode("2.00"), 
         'Currency'=>urlencode("GBP"), 
         'Description'=>urlencode("payment for my site"), 
         'CardHolder'=>urlencode('DELTA'), 
         'CardNumber'=>urlencode(4111111111111111), 
         'ExpiryDate'=>urlencode(1213), 
         'CV2'=>urlencode(123), 
         'CardType'=>urlencode('VISA'), 
         'BillingSurname'=>urlencode('surname'), 
         'BillingFirstnames'=>urlencode('name'), 
         'BillingAddress1'=>urlencode(' clifton'), 
         'BillingCity'=>urlencode('Bristol'), 
         'BillingPostCode'=>urlencode('BS82UE'), 
         'BillingCountry'=>urlencode('United Kingdom'), 
         'DeliverySurname'=>urlencode('surname'), 
         'DeliveryFirstnames'=>urlencode('name'), 
         'DeliveryAddress1'=>urlencode(' clifton'), 
         'DeliveryCity'=>urlencode('Bristol'), 
         'DeliveryPostCode'=>urlencode('bs82ue'), 
         'DeliveryCountry'=>urlencode('united kingdom'), 

       ); 

//url-ify the data for the POST 
$fields_string = http_build_query($fields); 

//open connection 
$ch = curl_init(); 

//set the url, number of POST vars, POST data 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_HEADER, 0); 

//execute post 
$result = curl_exec($ch); 
print_r($result); 
echo "end"; 
//close connection 
curl_close($ch); 
?> 

仅供参考,使用http_build_query()非常适合构建query_strings。

$fields_string = http_build_query($fields); 

如果添加字段

Crypt='Your encryption password in your account setting in sagepay test'; 

但是如果你使用卷曲后,它会被重定向到

https://test.sagepay.com/gateway/service/cardselection?vpstxid={BDBF098F-9BB5-3822-8CAE-AC0645A2CC57} 

如果你使用它返回空字符串此代码将工作的Http POST。

Goodluck