paypal网站付款专业解决方案iframe的工作示例? [英] Working example of paypal Website Payments Pro Hosted Solution Iframe?

查看:158
本文介绍了paypal网站付款专业解决方案iframe的工作示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用pay payals 网站付款专业版托管解决方案因此我们可以通过PayPal接受付款,而我们的用户不会觉得他们离开了网站而且我们不必遵守PCI。

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:


  • 用户点击商品的购买页面并选择数量并点击立即购买按钮

  • AJAX请求被发送到服务器以验证数量/计算总数等。

  • AJAX请求返回iframe的URL

  • iframe填充了页面,然后一旦完成加载,就会显示iframe

  • 用户填写信用卡详细信息并且paypal完成交易

  • paypal重定向iframe的成功页面调用父页面中的一些javascript以重定向到另一个URL。

  • 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

我不知道知道如何做是从这一点发送请求到paypal获取iframe的url。

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?

推荐答案

实际上,请尝试以下API调用并告诉我这是否适合您:

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

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

这篇关于paypal网站付款专业解决方案iframe的工作示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆