Paypal success payment, get the value after user buy something in php automatic

╄→гoц情女王★ 提交于 2019-12-24 10:32:45

问题


how can I check if an user bought my product automatically in php/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.


回答1:


Just wait for the IPN instant-payment-notification request from the PayPal servers

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


来源:https://stackoverflow.com/questions/49867135/paypal-success-payment-get-the-value-after-user-buy-something-in-php-automatic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!