php - Passing data to paypal IPN using option_select -
i have question passing paypal data form ipn.
what i'm trying making select field different options donator can choose from. , every option needs handled differently in ipn.
since prices same, handling different on every item cannot use code anymore
$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........
here example current form code:
<html> <head> </head> <body> <?php // 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 send ipn notification url echo '<input type="hidden" name="notify_url" value="'.$urlipn.'/ipn_itemenc.php" />'; // return page user navigated after donations complete echo '<input type="hidden" name="return" value="'.$urlthx.'/thankyou.php" />'; // signifies transaction data passed return page post echo '<input type="hidden" name="rm" value="2" /> '; // general configuration variables paypal landing page. consult'; // http://www.paypal.com/integrationcenter/ic_std-variable-ref-donate.html more info echo '<input type="hidden" name="no_note" value="1" />'; echo '<input type="hidden" name="cbt" value="go 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 can change image of enchant donation button echo '<input type="image" src="https://www.paypal.com/en_us/i/btn/btn_donate_lg.gif" name="submit" alt="paypal - safer, easier way 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>
and try accomplish in ipn.
example 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 make log of donations after payment status complete mysqli_query($link, " insert 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 paypal ipn data $custom = $p->ipn_data['custom']; // define value 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 value 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 charid given according char_name $sql = "select charid characters char_name='".$custom."'"; $result = mysqli_query($link, $sql); $total = mysqli_num_rows($result); // checks if 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); } ?>
my question: correct way request such data ?
$gethelmet = $p->ipn_data['option_select0'];
or never work ?
if so, best solution can try accomplish ?
thanks in advance.
the docs can use parameter custom
pass custom data (max length=255) https://developer.paypal.com/docs/classic/ipn/integration-guide/ipnandpdtvariables/
depending on situation pass custom notify_url
, pass data wanted in ipn url.
p.s. holy echo's batman.
Comments
Post a Comment