paypal 网站支付 Pro 托管解决方案 Iframe 的工作示例?
我希望使用 paypals 网站支付专业托管解决方案< /a> 因此,我们可以通过 PayPal 接受付款,而我们的用户不会感觉他们要离开网站,而且我们也不必遵守 PCI 合规性。
我们希望它以这种格式工作:
- 用户点击商品的购买页面并选择数量,然后点击“立即购买”按钮
- AJAX 请求发送到服务器以验证数量/计算总数等
- AJAX 请求返回 url iframe
- Iframe 填充页面,一旦加载完成,就会显示 iframe
- 用户填写信用卡详细信息,paypal 完成交易
- Paypal 重定向 iframe 的成功页面调用父页面中的一些 javascript 进行重定向到另一个网址。
所以, 我有数量选择页面,
我知道如何将数据发送到服务器并验证数量/计算总数
我不知道该怎么做,从现在开始向 paypal 发送请求以获取 iframe 的 url。
我尝试做的(作为一个非常基本的独立示例)是:
<?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>
起初似乎工作正常,直到您输入测试买家信用卡详细信息并受到打击
请返回付款页面并更正地址。
我做错了什么/我需要什么才能完成这项工作?
I am looking to use use paypals Website Payments Pro Hosted Solution so we can accept payments through paypal without our users feeling like they are leaving the site and without us having to be PCI compliant.
We are wanting this to work in this format:
- user hits buy page for an item and selects quantity and hits buy now button
- AJAX request is sent to server to validate quantity/calculate total etc
- AJAX request returns url for iframe
- Iframe is populated with the page, then once it has finished loading the iframe is shown
- User fills in credit card details and paypal completes the transaction
- The success page which paypal redirects the iframe to calls some javascript in the parent page to redirect to another url.
So,
I have the quantity select page,
I know how to send the data to the server and validate quantity/calculate total
What I don't know how to do is from this point send the request to paypal to get the url for the iframe.
What I have tried doing (as a very basic standalone example) is:
<?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>
Which at first seems to work fine, until you enter your test buyers credit card details and get hit with
Please return to the payment page and correct the address.
What am I doing wrong/ what do I need to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,请尝试以下 API 调用,并告诉我这是否适合您:
METHOD=BMCreateButton&
BUTTONTYPE=付款&
BUTTONCODE=令牌&
L_BUTTONVAR0=小计=11&
L_BUTTONVAR1=税=2&
L_BUTTONVAR2=运费=3&
L_BUTTONVAR3=处理=4&
L_BUTTONVAR4=模板=模板C
Actually, try the following API call and let me know if this works for you:
METHOD=BMCreateButton&
BUTTONTYPE=PAYMENT&
BUTTONCODE=TOKEN&
L_BUTTONVAR0=subtotal=11&
L_BUTTONVAR1=tax=2&
L_BUTTONVAR2=shipping=3&
L_BUTTONVAR3=handling=4&
L_BUTTONVAR4=template=templateC