我希望使用paypals Website Payments Pro Hosted Solution,因此我们可以通过paypal接受付款,而不会让用户觉得他们离开了网站而且我们不必遵守PCI。
我们希望以这种格式工作:
所以,
我有数量选择页面,
我知道如何将数据发送到服务器并验证数量/计算总数
我不知道怎么做是从这一点发送请求到paypal获取iframe的网址。
我尝试过的(作为一个非常基本的独立示例)是:
<?php
class paypal {
private $APIuser;
private $APIpass;
private $APIsign;
private $APIvers = '74.0';
private $APIaddr = 'https://api-3t.sandbox.paypal.com/nvp';
private $post_params = array();
function __construct($APIuser, $APIpass, $APIsign){
$this->APIuser = $APIuser;
$this->APIpass = $APIpass;
$this->APIsign = $APIsign;
}
function param($name, $value = null){
$this->post_params[$name] = $value;
return $this;
}
function getUrl(){
$post = $this->post_params;
$post['pwd'] = $this->APIpass;
$post['user'] = $this->APIuser;
$post['method'] = 'BMCreateButton';
$post['version'] = $this->APIvers;
$post['signature'] = $this->APIsign;
$post['buttoncode'] = 'CLEARTEXT';
$post['buttontype'] = 'PAYMENT';
$post_string = '?';
foreach($post as $k => $v)
$post_string .= $k.'='.urlencode($v).'&';
$post_string = substr($post_string, 0, -1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->APIaddr.$post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$out = curl_exec($ch);
curl_close($ch);
$out = explode('&', $out);
$final = array();
foreach($out as $k => &$v){
$v = explode('=', $v);
$final[$v[0]] = urldecode($v[1]);
}
return $final;
}
}
//mock variables
$price = 10.00;
$APIu = 'xxxxxxxxxx';
$APIp = 'xxxxxxxxxx';
$APIs = 'xxxxxxxxxx';
$paypal = new paypal($APIu, $APIp, $APIs);
$paypal->param('L_BUTTONVAR0=subtotal', $price*$_GET['quantity']);
$paypal->param('L_BUTTONVAR1=template', 'templateD');
$resp = $paypal->getUrl();
?>
<iframe width="100%" height=100%" src="<?php echo $resp['EMAILLINK']; ?>"></iframe>
最初似乎工作正常,直到您输入测试买家信用卡详细信息并被
命中请返回付款页面并更正地址。
我做错了什么/我需要做些什么?
答案 0 :(得分:0)
实际上,请尝试以下API调用,并告诉我这是否适合您:
METHOD = BMCreateButton&安培;
按钮类型=付款&安培;
BUTTONCODE = TOKEN&安培;
L_BUTTONVAR0 =小计= 11&安培;
L_BUTTONVAR1 =税= 2及
L_BUTTONVAR2 =航运= 3及
L_BUTTONVAR3 =装卸= 4和;
L_BUTTONVAR4 =模板= templateC