Php 使用选项_select将数据传递到paypal IPN

Php 使用选项_select将数据传递到paypal IPN,php,paypal-ipn,Php,Paypal Ipn,我有一个关于将paypal数据从表单传递到IPN的问题 我想做的是做一个选择字段,里面有不同的选项供捐赠者选择。 在IPN中,每个选项都需要以不同的方式处理 由于价格是一样的,但处理是不同的每一个项目,我不能再使用此代码 $amount = $p->ipn_data['mc_gross'] - $p->ipn_data['mc_fee']; $donateamount = 5; $donateamount2 = 10; if($amount == $donateamount){ /

我有一个关于将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>
或者这永远不会奏效

如果是这样,我能尝试实现这一目标的最佳解决方案是什么


提前感谢。

文档说您可以使用参数
custom
传递自定义数据(最大长度=255)

根据您的情况,您还可以传递自定义的
notify_url
,并在IPN url中传递所需的任何数据


p.S.Holy echo的蝙蝠侠。

我已经使用了自定义字段。是的,在通知url中可以选择单独的IPN。但是,真的有必要创建15个不同的ipn文件并为每个项目创建一个表单吗?我只是不知道如何让用户选择的项目。这样ipn就知道要执行什么代码。我已经有了一个代码,但这是基于与eatch其他不同的价格,因此我可以让ipn知道要执行什么代码。但在这种情况下,价格是相同的,我不能使用
$p->ipn_数据['mc_gross']-$p->ipn_数据['mc_fee']不再。哈哈,是的,我会做一些关于echo'sCan的事情。当选项更改时,你可以使用javascript更改
自定义
字段或
通知url
?我已经使用自定义字段做了其他事情。通知url将指向IPN。所以,如果我想做到这一点,我需要做15个ipn(每个项目1个ipn文件),使这个捐赠页面的工作?如果有人做出选择,则通过javascript使用正确的ipn更新notify_url。我认为这是可能的,但最终我会得到大约100个独立的ipn文件。由于这不是完整的捐赠系统,请使用一个IPN文件,并根据用户选择的内容向URL添加一个参数。或者在自定义字段中放置2个值,找到一个在任何一个数据集中都不存在的字符,并用该字符分隔这些值。因此,如果管道“|”永远不存在于值中,那么最终会出现一个自定义字段,看起来像“value1 | value2”。我将尝试在自定义字段上使用两个值。我从没想过那件事。我会找出如何分离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'];