【问题标题】:Paypal success payment, get the value after user buy something in php automaticpaypal成功支付,用户在php中自动购买东西后获取价值
【发布时间】:2018-04-16 22:25:25
【问题描述】:

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

我有一个 paypal 按钮:

<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>

我配置了一个返回 url。 但我不知道下一步该怎么做才能获得付款成功并允许该用户访问我的网站。

【问题讨论】:

标签: php paypal


【解决方案1】:

等待来自 PayPal 服务器的 IPN instant-payment-notification 请求

这是一个基于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;
}

【讨论】:

    猜你喜欢
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 2016-05-29
    • 2012-11-11
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    相关资源
    最近更新 更多