简体   繁体   English

paypal网站支付专业解决方案iframe的工作示例?

[英]Working example of paypal Website Payments Pro Hosted Solution 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. 我希望使用paypals 网站付款专业托管解决方案,以便我们可以通过paypal接受付款,而我们的用户不会觉得他们离开网站,而且我们不必遵守PCI。

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请求被发送到服务器以验证数量/计算总数等
  • AJAX request returns url for iframe AJAX请求返回iframe的url
  • Iframe is populated with the page, then once it has finished loading the iframe is shown 使用页面填充iframe,然后在加载完iframe后显示
  • User fills in credit card details and paypal completes the transaction 用户填写信用卡详细信息,paypal完成交易
  • The success page which paypal redirects the iframe to calls some javascript in the parent page to redirect to another url. paypal重定向iframe的成功页面调用父页面中的一些javascript以重定向到另一个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. 我不知道怎么做是从这一点发送请求到paypal获取iframe的url。

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? 我做错了什么/我需要做些什么呢?

Actually, try the following API call and let me know if this works for you: 实际上,请尝试以下API调用,并告诉我这是否适合您:

METHOD=BMCreateButton& METHOD = BMCreateButton&
BUTTONTYPE=PAYMENT& 按钮类型=付款和
BUTTONCODE=TOKEN& BUTTONCODE =令牌
L_BUTTONVAR0=subtotal=11& L_BUTTONVAR0 =小计= 11&
L_BUTTONVAR1=tax=2& L_BUTTONVAR1 =税= 2&
L_BUTTONVAR2=shipping=3& L_BUTTONVAR2 =航运= 3&
L_BUTTONVAR3=handling=4& L_BUTTONVAR3 =装卸= 4&
L_BUTTONVAR4=template=templateC L_BUTTONVAR4 =模板= templateC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM