php - Failed inserting more items in database using IPN, Paypal, add to cart -
i adapted ipn script purchase button , after include add together cart button.
this purchase button: <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="return" value="http://www.company.develway.com/company_user?id= <?php echo $id; ?>"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="custom" value="<?php echo $id; ?>"/> <input type="hidden" name="quantity" value="1"> <input type="hidden" name="item_name" value="<?php echo 'premium content ' . $name; ?>"> <input type="hidden" name="hosted_button_id" value="tv4swl86ehyyq"> <input type="image" src="https://www.paypalobjects.com/en_us/i/btn/btn_buynowcc_lg.gif" border="0" name="submit" alt="paypal - safer, easier way pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_us/i/scr/pixel.gif" width="1" height="1"> </form> add together cart button: <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="image" src="https://www.paypal.com/en_us/i/btn/x-click-but22.gif" border="0" name="submit" alt="make payments paypal - it'sfast, free , secure!"> <input type="hidden" name="add" value="1"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="finciucsergiu@gmail.com"> <input type="hidden" name="custom" value="<?php echo $id; ?>"/> <input type="hidden" name="item_name" value="<?php echo 'premium content ' . $name; ?>"> <input name="notify_url" value="http://www.company.develway.com/ipn.php" type="hidden"> <input type="hidden" name="item_number" value="wid-001"> <input type="hidden" name="amount" value="0.01"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="usd"> <input name="notify_url" value="http://www.company.develway.com/ipn.php" type="hidden"> </form>
and main part of ipn file:
if (strcmp ($res, "verified") == 0) { $item_name = $_post['item_name']; $item_number = $_post['item_number']; $payment_status = $_post['payment_status']; $payment_amount = $_post['mc_gross']; $payment_currency = $_post['mc_currency']; $txn_id = $_post['txn_id']; $receiver_email = $_post['receiver_email']; $payer_email = $_post['payer_email']; $custom = $_post['custom']; $txn_type = $_post['txn_type']; $number_of_items = $_post['num_cart_items']; $connection = mysql_connect("hhh", "fff", "lll"); $db_select = mysql_select_db("company", $connection); mysql_query("insert paid_companies(users_email, companies_id) values('$payer_email', '$custom') ") or die(mysql_error());
}
al works first-class purchase , add together cart if 1 item, if insert more 1 in database included lastly item. doing wrong?
when have more 1 item in cart have loop through items included in ipn of items in database.
check out...
// cart items $num_cart_items = isset($_post['num_cart_items']) ? $_post['num_cart_items'] : ''; $i = 1; $cart_items = array(); while(isset($_post['item_number' . $i])) { $item_number = isset($_post['item_number' . $i]) ? $_post['item_number' . $i] : ''; $item_name = isset($_post['item_name' . $i]) ? $_post['item_name' . $i] : ''; $quantity = isset($_post['quantity' . $i]) ? $_post['quantity' . $i] : ''; $mc_gross = isset($_post['mc_gross_' . $i]) ? $_post['mc_gross_' . $i] : 0; $mc_handling = isset($_post['mc_handling' . $i]) ? $_post['mc_handling' . $i] : 0; $mc_shipping = isset($_post['mc_shipping' . $i]) ? $_post['mc_shipping' . $i] : 0; $custom = isset($_post['custom' . $i]) ? $_post['custom' . $i] : ''; $option_name1 = isset($_post['option_name1_' . $i]) ? $_post['option_name1_' . $i] : ''; $option_selection1 = isset($_post['option_selection1_' . $i]) ? $_post['option_selection1_' . $i] : ''; $option_name2 = isset($_post['option_name2_' . $i]) ? $_post['option_name2_' . $i] : ''; $option_selection2 = isset($_post['option_selection2_' . $i]) ? $_post['option_selection2_' . $i] : ''; $option_name3 = isset($_post['option_name3_' . $i]) ? $_post['option_name3_' . $i] : ''; $option_selection3 = isset($_post['option_selection3_' . $i]) ? $_post['option_selection3_' . $i] : ''; $option_name4 = isset($_post['option_name4_' . $i]) ? $_post['option_name4_' . $i] : ''; $option_selection4 = isset($_post['option_selection4_' . $i]) ? $_post['option_selection4_' . $i] : ''; $option_name5 = isset($_post['option_name5_' . $i]) ? $_post['option_name5_' . $i] : ''; $option_selection5 = isset($_post['option_selection5_' . $i]) ? $_post['option_selection5_' . $i] : ''; $option_name6 = isset($_post['option_name6_' . $i]) ? $_post['option_name6_' . $i] : ''; $option_selection6 = isset($_post['option_selection6_' . $i]) ? $_post['option_selection6_' . $i] : ''; $option_name7 = isset($_post['option_name7_' . $i]) ? $_post['option_name7_' . $i] : ''; $option_selection7 = isset($_post['option_selection7_' . $i]) ? $_post['option_selection7_' . $i] : ''; $option_name8 = isset($_post['option_name8_' . $i]) ? $_post['option_name8_' . $i] : ''; $option_selection8 = isset($_post['option_selection8_' . $i]) ? $_post['option_selection8_' . $i] : ''; $option_name9 = isset($_post['option_name9_' . $i]) ? $_post['option_name9_' . $i] : ''; $option_selection9 = isset($_post['option_selection9_' . $i]) ? $_post['option_selection9_' . $i] : ''; $btn_id = isset($_post['btn_id' . $i]) ? $_post['btn_id' . $i] : ''; $current_item = array( 'item_number' => $item_number, 'item_name' => $item_name, 'quantity' => $quantity, 'mc_gross' => $mc_gross, 'mc_handling' => $mc_handling, 'mc_shipping' => $mc_shipping, 'custom' => $custom, 'option_name1' => $option_name1, 'option_selection1' => $option_selection1, 'option_name2' => $option_name2, 'option_selection2' => $option_selection2, 'option_name3' => $option_name3, 'option_selection3' => $option_selection3, 'option_name4' => $option_name4, 'option_selection4' => $option_selection4, 'option_name5' => $option_name5, 'option_selection5' => $option_selection5, 'option_name6' => $option_name6, 'option_selection6' => $option_selection6, 'option_name7' => $option_name7, 'option_selection7' => $option_selection7, 'option_name8' => $option_name8, 'option_selection8' => $option_selection8, 'option_name9' => $option_name9, 'option_selection9' => $option_selection9, 'btn_id' => $btn_id ); array_push($cart_items, $current_item); $i++; }
that leave array called $cart_items contains of items. add together database inserts loop provided, or utilize gather cart items $cart_items , utilize work from.
either way, need loop through items.
php insert paypal shopping-cart paypal-ipn
No comments:
Post a Comment