我有一个关于将paypal数据从表单传递到IPN的问题。
我要做的是制作一个具有不同选项的选择字段,供捐赠者可以选择。 并且每个选项都需要在IPN中以不同方式处理。
由于价格相同,但每个项目的处理不同,我不能再使用此代码了
$amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee'];
$donateamount = 5;
$donateamount2 = 10;
if($amount == $donateamount){
//custom code
}
if($amount == $donateamount2){
//custom code
}
ETC........
以下是我当前表单代码的示例:
<html>
<head>
</head>
<body>
<?php
// The PayPal enchant Donation option list
echo '<form action="'.$payPalURL.'" method="post" class="payPalForm">';
echo '<input type="hidden" name="cmd" value="_xclick" />';
echo '<input type="hidden" name="item_name" value="Donation" />';
echo '<input type="hidden" name="custom" value="'.$charname.'">';
//Your PayPal email
echo '<input type="hidden" name="business" value="'.$myPayPalEmail.'" />';
// PayPal will send an IPN notification to this URL
echo '<input type="hidden" name="notify_url" value="'.$urlipn.'/ipn_itemenc.php" />';
// The return page to which the user is navigated after the donations is complete
echo '<input type="hidden" name="return" value="'.$urlthx.'/thankyou.php" />';
// Signifies that the transaction data will be passed to the return page by POST
echo '<input type="hidden" name="rm" value="2" /> ';
// General configuration variables for the paypal landing page. Consult';
// http://www.paypal.com/IntegrationCenter/ic_std-variable-ref-donate.html for more info
echo '<input type="hidden" name="no_note" value="1" />';
echo '<input type="hidden" name="cbt" value="Go Back To The Site" />';
echo '<input type="hidden" name="no_shipping" value="1" />';
echo '<input type="hidden" name="lc" value="US" />';
echo '<input type="hidden" name="currency_code" value="USD" />';
echo '<center>';
echo '<table>';
echo '<tr><td><input type="hidden" name="on0" value="enchant">enchant</td></tr><tr><td>';
echo '<select name="os0">';
echo '<option value="+18 helmet">+18 helmet $10.00</option>';
echo '<option value="+18 Breastplate">+18 Breastplate $10.00</option>';
echo '<option value="+18 Leggings">+18 Leggings $10.00</option>';
echo '<option value="+18 Full armor">+18 Full armor $10.00</option>';
echo '<option value="+18 Gloves">+18 Gloves $10.00</option>';
echo '<option value="+18 Boots">+18 Boots $10.00</option>';
echo '<option value="+18 Weapon">+18 Weapon $10.00</option>';
echo '<option value="+18 Shield">+18 Shield $10.00</option>';
echo '<option value="+18 Shirt">+18 Shirt $10.00</option>';
echo '<option value="+18 Belt">+18 Belt $10.00</option>';
echo '<option value="+18 Necklace">+18 Necklace $10.00</option>';
echo '<option value="+18 Lower earring">+18 Lower earring $10.00</option>';
echo '<option value="+18 Upper earring">+18 Upper earring $10.00</option>';
echo '<option value="+18 Lower ring">+18 Lower ring $10.00</option>';
echo '<option value="+18 Upper ring">+18 Upper ring $10.00</option>';
echo '</select> </td></tr>';
echo '<input type="hidden" name="option_index" value="0">';
echo '<input type="hidden" name="option_select0" value="+18 helmet">';
echo '<input type="hidden" name="option_amount0" value="10.00">';
echo '<input type="hidden" name="option_select1" value="+18 Breastplate">';
echo '<input type="hidden" name="option_amount1" value="10.00">';
echo '<input type="hidden" name="option_select2" value="+18 Leggings">';
echo '<input type="hidden" name="option_amount2" value="10.00">';
echo '<input type="hidden" name="option_select3" value="+18 Full armor">';
echo '<input type="hidden" name="option_amount3" value="10.00">';
echo '<input type="hidden" name="option_select4" value="+18 Gloves">';
echo '<input type="hidden" name="option_amount4" value="10.00">';
echo '<input type="hidden" name="option_select5" value="+18 Boots">';
echo '<input type="hidden" name="option_amount5" value="10.00">';
echo '<input type="hidden" name="option_select6" value="+18 Weapon">';
echo '<input type="hidden" name="option_amount6" value="10.00">';
echo '<input type="hidden" name="option_select7" value="+18 Shield">';
echo '<input type="hidden" name="option_amount7" value="10.00">';
echo '<input type="hidden" name="option_select8" value="+18 Shirt">';
echo '<input type="hidden" name="option_amount8" value="10.00">';
echo '<input type="hidden" name="option_select9" value="+18 Belt">';
echo '<input type="hidden" name="option_amount9" value="10.00">';
echo '<input type="hidden" name="option_select10" value="+18 Necklace">';
echo '<input type="hidden" name="option_amount10" value="10.00">';
echo '<input type="hidden" name="option_select11" value="+18 Lower earring">';
echo '<input type="hidden" name="option_amount11" value="10.00">';
echo '<input type="hidden" name="option_select12" value="+18 Upper earring">';
echo '<input type="hidden" name="option_amount12" value="10.00">';
echo '<input type="hidden" name="option_select13" value="+18 Lower ring">';
echo '<input type="hidden" name="option_amount13" value="10.00">';
echo '<input type="hidden" name="option_select14" value="+18 Upper ring">';
echo '<input type="hidden" name="option_amount14" value="10.00">';
echo '</center>';
echo '</table>';
//Here you can change the image of the enchant donation button
echo '<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" />';
echo '<img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />';
echo '<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest" />';
echo '</form>';
?>
</body>
</html>
这就是我试图在IPN中完成的事情。
示例IPN:
<?php
require "../paypal_integration_class/paypal.class.php";
require "../config.php";
require "../connect.php";
$p = new paypal_class;
$p->paypal_url = $payPalURL;
if ($p->validate_ipn()) {
if($p->ipn_data['payment_status']=='Completed')
{
$amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee'];
//here we will make a log of all the donations after the payment status is complete
mysqli_query($link, " INSERT INTO dc_donations (transaction_id,donor_email,amount,original_request)
VALUES (
'".esc($p->ipn_data['txn_id'])."',
'".esc($p->ipn_data['payer_email'])."',
".(float)$amount.",
'".esc(http_build_query($_POST))."'
)");
//get character name from paypal ipn data
$custom = $p->ipn_data['custom'];
// define the value from the donation options
$enchelmet = '+18 helmet';
$encbreastplate = '+18 Breastplate';
$encleggings = '+18 Leggings';
$encfullarmor = '+18 Full armor';
$encgloves = '+18 Gloves';
$encboots = '+18 Boots';
$encweapon = '+18 Weapon';
$encshield = '+18 Shield';
$encshirt = '+18 Shirt';
$encbelt = '+18 Belt';
$encnecklace = '+18 Necklace';
$enclowearring = '+18 Lower earring';
$encupearring = '+18 Upper earring';
$enclowring = '+18 Lower ring';
$encupring = '+18 Upper ring';
// gets the value from the form
$gethelmet = $p->ipn_data['option_select0'];
$getbreastplate = $p->ipn_data['option_select1'];
$getleggings = $p->ipn_data['option_select2'];
$getfullarmor = $p->ipn_data['option_select3'];
$getgloves = $p->ipn_data['option_select4'];
$getboots = $p->ipn_data['option_select5'];
$getweapon = $p->ipn_data['option_select6'];
$getshield = $p->ipn_data['option_select7'];
$getshirt = $p->ipn_data['option_select8'];
$getbelt = $p->ipn_data['option_select9'];
$getnecklace = $p->ipn_data['option_select10'];
$getlowearring = $p->ipn_data['option_select11'];
$getupearring = $p->ipn_data['option_select12'];
$getlowring = $p->ipn_data['option_select13'];
$getupring = $p->ipn_data['option_select14'];
//Get the Charid given according to the char_name
$sql = "SELECT charId FROM characters WHERE char_name='".$custom."'";
$result = mysqli_query($link, $sql);
$total = mysqli_num_rows($result);
// checks if the caracter still exsists.
if($total>0){
// Enchant helmet
if($enchelmet == $gethelmet){
// run custom script
}
// Enchant breastplate
if($encbreastplate == $getbreastplate){
// run custom script
}
// Enchant leggings
if($encleggings == $getleggings){
// run custom script
}
// Enchant full armor
if($encfullarmor == $getfullarmor){
// run custom script
}
// Enchant gloves
if($encgloves == $getgloves){
// run custom script
}
// Enchant boots
if($encboots == $getboots){
// run custom script
}
// Enchant weapon
if($encweapon == $getweapon){
// run custom script
}
// Enchant shield
if($encshield == $getshield){
// run custom script
}
// Enchant shirt
if($encshirt == $getshirt){
// run custom script
}
// Enchant belt
if($encbelt == $getbelt){
// run custom script
}
// Enchant necklace
if($encnecklace == $getnecklace){
// run custom script
}
// Enchant lower earring
if($enclowearring == $getlowearring){
// run custom script
}
// Enchant upper earring
if($encupearring == $getupearring){
// run custom script
}
// Enchant lower ring
if($enclowring == $getlowring){
// run custom script
}
// Enchant upper ring
if($encupring == $getupring){
// run custom script
}
}
}
}
function esc($str)
{
global $link;
return mysqli_real_escape_string($link, $str);
}
?>
我的问题:这是请求此类数据的正确方法吗?
$gethelmet = $p->ipn_data['option_select0'];
或者这会不会起作用?
如果是这样,我可以尝试实现这一目标的最佳解决方案是什么?
提前致谢。
答案 0 :(得分:0)
文档说您可以使用参数custom
来传递自定义数据(最大长度= 255)https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/
根据您的情况,您还可以传递自定义notify_url
并在IPN网址中传递您想要的任何数据。
P.S。神圣回声的蝙蝠侠。