贝宝成功付款,用户在php中自动购买后获得价值 [英] Paypal success payment, get the value after user buy something in php automatic

查看:83
本文介绍了贝宝成功付款,用户在php中自动购买后获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查用户是否自动通过php/paypal购买了我的产品?

how can I check if an user bought my product automatically in php/paypal?

我有一个Paypal按钮:

I have a paypal button:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="xxx">
<input type="image" src="/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal">
<img alt="" border="0" src="/pixel.gif" width="1" height="1">
</form>

,然后配置返回网址. 但是我不知道下一步该怎么做才能使付款成功并允许该用户访问我的网站.

and I config a return url. but I don't know what to do next to get payment success and allow this user to access my website.

推荐答案

只需等待IPN 这是一个非常简单的示例,基于这些示例

Here is a very simple sample based on these samples

<?php
// the PHP script that is supposed to receive the IPN request 
require('PaypalIPN.php');

$ipn = new PaypalIPN();
$verified = $ipn->verifyIPN();
if ($verified) {
    /*
     * Process IPN
     * A list of variables is available here:
     * https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
     */
    if(checkPriceForPayPalIPN($_POST['item_number'], $_POST['mc_gross'],$_POST['mc_currency'])){
        // correct payment, allow user to access (activate the product)
    }else{
        // the price paid for the item is not correct  
    }
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
header("HTTP/1.1 200 OK");


function checkPriceForPayPalIPN($item_number, $mc_gross, $mc_currency)
{
    //query the database to check the price of the item here
    // --  select * from myProducts
    // where item_number = ? and mc_gross = ? and mc_currency = ?
    if($correct) return true;
    return false;
}

这篇关于贝宝成功付款,用户在php中自动购买后获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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