PHP - Need Help In Paypal Buynow Button
HI guys,,
I have created an online booking form with Paypal Buynow button. After Clicking BuyNOW I want the customers to enter their Shipping details when they are on Paypal. Phone and Address How can i do that? and also using on1 and os1 i can enter custom information. but it includes one value for example Select Product Size: The Value will be Small or Large What if want to have multiple values? like Choose Colors: Red, blue, green, white go on. User can choose one of those colors or multiple.. Please tell me how to do it. Thanks Waiting for your responses! Similar TutorialsHello, I wish to secure the PayPal form button. As my button is used on a subscription website, I don't want people changing the parameters and code needs to be hidden from peering eyes with firebug for instance. I have heard that you can pass the data to PayPal be given a CMD URL in return and you simply forward the user to such URL. Anyone know of this? - or another method? The button manager is not acceptable as the values will change in the hidden fields. George. I need some help with showing a Paypal buy button or not if it's sold. Currently if the item is sold I mark it as sold but the button is still there. What I need I believe is an if statement to look at the sold variable to see if it's sold and then not show the Paypal Buy it button for that item only. Any help would be greatly appreciated. Below is some of the code I use. $result = mysql_query("SELECT * FROM $dbname ORDER BY itemno ASC") or die(mysql_error()); // store the record of the "" table into $row $current = ''; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { $id = $row['id']; if (!$current) { echo "<center><div><table border='0' width='520'>"; $current = $id; echo "<div id='box'>"; echo "<h4>Welcome to the Store</h4>"; echo "<p>Questions about store items use link in menu.</p>"; echo "Beads (".$rows4.") "; echo "Cabochons (".$rows3.") "; echo "Earrings (".$rows1.") "; echo "Pendants (".$rows2.") "; echo "Rings (".$rows0.") "; echo "</div>"; echo "<p>Click picture to enlarge.</p>"; echo "<hr width='520'>"; } elseif ($current != $id){ echo "</table></div><br><div><table border='0' width='520'>"; $current = $id; echo "<hr width='520'>"; } ?> <tr><td rowspan="6" width="100"><div class="image"><a href="<?= $row['image']; ?>" rel="lightbox" title="<?= $row['material']; ?>"><img src="<?= $row['image_th']; ?>" align="center" border="0"></a></div></td> <td rowspan="6" width="100"><div class="image"><a href="<?= $row['image2']; ?>" rel="lightbox" title="<?= $row['material']; ?>"><img src="<?= $row['image2_th']; ?>" width="75" border="0"></a></div></td> <th width='100' align="left">Item No.</th><td><?= $row['itemno']; ?></div> </td></tr> <tr><th align="left">Description</th><td><?= $row['description']; ?></td></tr> <tr><th align="left">Carat</th><td><?= $row['carat']; ?></td></tr> <tr><th align="left">Material</th><td><?= $row['material']; ?></td></tr> <tr><th align="left">Price</th><td><?= $row['price']; ?></td></tr> <tr><th align="left">Availability</th><td><?= $row['availability']; ?></td></tr> <tr><th> </th><td> </td><td><form target="paypal" action="https://www.paypal.com" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="add" value="1"> <input type="hidden" name="business" value=""> <input type="hidden" name="item_name" value="<?= $row['description']; ?>"> <input type="hidden" name="item_number" value="<?= $row['itemno']; ?>"> <input type="hidden" name="amount" value="<?= $row['price']; ?>"> <input type="hidden" name="shipping" value="7.00"> <input type="hidden" name="shipping2" value="0.50"> <input type="hidden" name="handling" value="2.00 "> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="return" value="thankyou.html"> <input type="hidden" name="undefined_quantity" value="1"> <input type="image" src="" height="65%" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> </td> </tr> <?php $headers[0] = 'Content-Type: text/namevalue'; $headers[1] = 'X-PAYPAL-SECURITY-USERID: blah'; $headers[2] = 'X-PAYPAL-SECURITY-PASSWORD: blah'; $headers[3] = 'X-PAYPAL-SECURITY-SIGNATU blah'; $headers[4] = 'X-PAYPAL-APPLICATION-ID: blah'; $headers[5] = 'X-PAYPAL-REQUEST-DATA-FORMAT: NV'; $headers[6] = 'X-PAYPAL-RESPONSE-DATA-FORMAT: NV'; $endpoint = 'https://api-3t.paypal.com/nvp'; $method = 'BMGetButtonDetails(hostedbuttonid:AUKAUSD1)'; $options = array('http' => array('header' => 'Content-type: application/x-www-form-urlencoded', 'method' => 'POST', 'content' => http_build_query($method))); $response = file_get_contents($endpoint, $method, $options, $headers); header('Location: gwpvlist.mv?done=aukretrieved&pvi=AUK&actioni=list&identityi=AUKMUSD1&sesx=54467585000E3C510000766200000000&ans='.$response);?>
It seems to go somewhere but there is nothing in $response.
By the way, I am an infant at php usage. (and an imbecile otherwise!)
Hi Does any one know of any good tutorials for paypal web payments pro, or recommend books Thanks in advance Hey Guys, i have another problem, i am using paypal IPN, and i want the details of the order to be stored in my orders table of the databse as well as sending me an email. Im pretty sure the code is ok, but it is not working. Can some one please take a look? <?php include('db_fns.php'); // change these to your paypal settings $paypal_email = "benmunns@gmail.com"; $paypal_currency = 'USD'; $shipping = 10.00; /** * checks if paypal trans id is already in database * @param int $trans_id * @return bool */ function no_paypal_trans_id($trans_id) { $connection = db_connect(); $query = sprintf("SELECT id from orders WHERE paypal_trans_id = '%s'", mysql_real_escape_string($trans_id)); $result = mysql_query($query); $num_results = mysql_num_rows($result); if($num_results == 0) { return true; } return false; } /** * checks to make sure that paypal payment amount is correct * @param int $shipping * @param array $params * @return bool */ function payment_amount_correct($shipping, $params) { $amount = 0.00; for ($i=1; $i <= $params['num_cart_items']; $i++) { $query = sprintf("SELECT price from products where id='%s'", mysql_real_escape_string($params["item_number{$i}"])); $result = mysql_query($query); if($result) { $item_price = mysql_result($result, 0, 'price'); $amount += $item_price * $params["quantity{$i}"]; } } if(($amount+$shipping) == $params['mc_gross']) { return true; } else { return false; } } /** * creates order and adds items * @param array $params * @return bool */ function create_order($params) { db_connect(); $query = sprintf("INSERT INTO orders set orders.firstname = '%s', orders.lastname = '%s', orders.email = '%s', orders.country = '%s', orders.address = '%s', orders.city = '%s', orders.zip_code = '%s', orders.state = '%s', orders.status = '%s', orders.amount = '%s', orders.paypal_trans_id = '%s', created_at = NOW() ", mysql_real_escape_string($params['first_name']), mysql_real_escape_string($params['last_name']), mysql_real_escape_string($params['payer_email']), mysql_real_escape_string($params['address_country']), mysql_real_escape_string($params['address_street']), mysql_real_escape_string($params['address_city']), mysql_real_escape_string($params['address_zip']), mysql_real_escape_string($params['address_state']), mysql_real_escape_string($params['payment_status']), mysql_real_escape_string($params['mc_gross']), mysql_real_escape_string($params['txn_id']) ); $result = mysql_query($query); if(!$result) { return false; } $order_id = mysql_insert_id(); for ($i=1; $i <= $params['num_cart_items'] ; $i++) { $product = find_product($params["item_number{$i}"]); $query = sprintf("INSERT INTO items set order_id = '%s', product_id = '%s', title = '%s', price = '%s', qty = '%s' ", mysql_real_escape_string($order_id), mysql_real_escape_string($product['id']), mysql_real_escape_string($product['title']), mysql_real_escape_string($product['price']), mysql_real_escape_string($params["quantity{$i}"]) ); $result = mysql_query($query); if(!$result) { return false; } } return true; } // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); // assign posted variables to local variables $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']; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if ($_POST['payment_status'] == 'Completed' && no_paypal_trans_id($_POST['txn_id']) && $paypal_email == $_POST['receiver_email'] && $paypal_currency == $_POST['mc_currency'] && payment_amount_correct($shipping, $_POST) ) { // process payment create_order($_POST); } } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation } } fclose ($fp); } ?> Hi all I have a quick PayPal IPN question, is this the right group to post the message and does anyone know much about the PayPal IPN? Thanks Hi, I am new here, so hello everyone. I really need some help with getting Paypal IPN working correctly. This is what I am trying to do. I have a user database, when the user logs in, they have the option to upgrade/subscribe to our website. So when they subscribe and payment is validated, I want a specific field in a specific table updated based on the user's unique ID, not based on [payer_email], so how do I pass on that parameter using IPN? right now I added the "userId" to a hidden field in the Paypal subscription form named "on1".... I hope this isn't confusing - would really appreciate your help - I added code below. Code: [Select] <?php DB info -- // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // PAYMENT VALIDATED & VERIFIED! $email = $_POST['payer_email']; $userId=$_POST['on1']; $membership = '2'; mysql_query("UPDATE users SET membership=".$membership." WHERE userId=".$userId) or die(mysql_error()); $to = $email; $subject = 'subject line'; $message = ' message here '; mail($to, $subject, $message, $headers); } else if (strcmp ($res, "INVALID") == 0) { // PAYMENT INVALID & INVESTIGATE MANUALY! $to = 'my_email'; $subject = 'subject lin'; $message = ' Dear Administrator, A payment has been made but is flagged as INVALID. Please verify the payment manualy and contact the buyer. Buyer Email: '.$email.' '; $headers = 'From:my_email' . "\r\n"; mail($to, $subject, $message, $headers); } } fclose ($fp); } ?> I am trying to get a Paypal IPN working using PHP. I have attached the code I have written that is not working. I have no real way to test it other than nothing is being posted to the databases. The transactions seem to complete with paypal, but I get no information and no emails are generated. Any help would be much appreciated. Hey guys i have created a paypal IPN script and it takes various info from users via paypal. Anyways i store their info into a database along with their email however i dont want them to be able to purchase again with the same email (long story) anways by the time i receive the info from paypal the payments already gone through so its too late for me to do the checking against the database. Is there anyway i can auto refund the payment do paypal allow this? Hope someone can help. Thanks! I just did the ipn page to store paypal transactions into my database but it doesnt seem to be working. Is there anything else that i need to do other than creating the ipn page? <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("pbstore") or die(mysql_error()); // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // PAYMENT VALIDATED & VERIFIED! $email = $_POST['payer_email']; $name = $_POST['item_name']; mysql_query("INSERT into sales (name, email) VALUES('".$name."', '".$email."')")or die(mysql_error()); mysql_query("INSERT INTO users (email, password) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error()); } else if (strcmp ($res, "INVALID") == 0) { // PAYMENT INVALID & INVESTIGATE MANUALY! } } fclose ($fp); } ?> Hey All, I have setup a Paypal API to handle the recurring payments on my website, once the payment is completed I get a token id and ba_token id return. I am storing this in a database, but wondered how people link this with a user table? I could use a cookie to store the user's id before payment and then get it once the payment is complete, but this would not work with the subsequent recurring payments. How do you go about sending the user id when a recurring payment happens? Any advise would be appreciated. Edd Hi guys, my code below works with sanbox for paypal IPN but since it has gone live it doesnt do anything, so i made emails to send me where the issue is and it keep sending me $req = 'cmd=_notify-validate'; could you please tell me what im doing wrong here? my db connection should be fine as it does update the users on sanbox. the account im paying with in paypal keep saying payment status unclaimed. it means the reciever has not recieved the money. I checked the paypal account where i recieve the moeny and looked into my ipn history, nothing there. the same ipn address is used for my account when i tested it on sanbox, thanks <?php $email="princeofpersia@hotmail.co.uk"; include 'global.php'; // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); //$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);//Live // assign posted variables to local variables if (!$fp)// failed to connect to url { //write to file $fh = fopen("logipn.txt", 'a');//open file and create if does not exist fwrite($fh, "\r\n/////////////////////////////////////////\r\n HTTP ERROR \r\n");//Just for spacing in log file fwrite($fh, $errstr);//write data fclose($fh);//close file $mail_From = "From: IPN@tester.com"; $mail_To = $email; $mail_Subject = "HTTP ERROR"; $mail_Body = $errstr;//error string from fsockopen mail($mail_To, $mail_Subject, $mail_Body, $mail_From); } else//successful connect to url { fputs ($fp, $header . $req);//send request while (!feof($fp)) //while not end of file { $res = fgets ($fp, 1024);//get response if (strcmp ($res, "VERIFIED") == 0) { //write to file $fh = fopen("logipn.txt", 'a');//open file and create if does not exist fwrite($fh, "\r\n/////////////////////////////////////////\r\n Verified \r\n");//Just for spacing in log file fwrite($fh, $req);//write data fclose($fh);//close file $mail_From = "From: IPN@tester.com"; $mail_To = $email; $mail_Subject = "VERIFIED IPN"; $mail_Body = $req; mail($mail_To, $mail_Subject, $mail_Body, $mail_From); } else if (strcmp ($res, "INVALID") == 0) { //write to file $fh = fopen("logipn.txt", 'a');//open file and create if does not exist fwrite($fh, "\r\n/////////////////////////////////////////\r\n Invalid \r\n");//Just for spacing in log file fwrite($fh, $req);//write data fclose($fh);//close file $mail_From = "From: IPN@tester.com"; $mail_To = $email; $mail_Subject = "INVALID IPN"; $mail_Body = $req; mail($mail_To, $mail_Subject, $mail_Body, $mail_From); } } fclose ($fp);//close file pointer } $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']; //$username=$_POST['username']; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if (strtolower($payment_status)=="completed") { if ($payment_amount==0.01&&$payment_currency=="GBP") { $update = mysql_query("UPDATE users SET credit= credit+5 WHERE email='$payer_email'"); } } // check the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation } } fclose ($fp); } ?> Hi, i am building a website where users have a choice to buy a subscription to the next level gold, silver, bronze. Now i have used paypal before for one off payments but i'm finding it to be a problem when i have three seperate buy now buttons Code: [Select] <?php if ($payment_status == "Completed"){ if ($item_name == "Bronze Membership" && $payment_amount == 4.99&&$payment_currency == "USD"){ $update = mysql_query("UPDATE users SET membership = '1' WHERE email = '$payer_email'"); } if ($item_name == "Silver Membership" && $payment_amount == 9.99&&$payment_currency == "USD"){ $update = mysql_query("UPDATE users SET membership = '2' WHERE email = '$payer_email'"); } if ($item_name == "Gold Membership" && $payment_amount == 19.99&&$payment_currency == "USD"){ $update = mysql_query("UPDATE users SET membership = '3' WHERE email = '$payer_email'"); } } ?> As you can see i am checking that the item name is the correct name aswell as price but in the sandbox it wont work. Additional info Code: [Select] <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="myemail"> <input type="hidden" name="item_name" value="Bronze Membership"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="amount" value="4.99"> <input type="image" src = "http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" height="30" width="65" alt="Make payments with paypal - it's fast, free and secure!"> </form> Hi, How to get paypal transection id on return after someone pay if i've paypal payment form as following Code: [Select] <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="<?=$line[paypalid]?>"> <input type="hidden" name="item_name" value="Payment Your Hits"> <input type="hidden" name="item_number" value="1"> <input type="hidden" name="amount" value="<?=$usd?>"> <input type="hidden" name="no_shipping" value="0"> <input type="hidden" name="no_note" value="payment from website submittion"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="lc" value="AU"> <input type="hidden" name="bn" value="PP-BuyNowBF"> <input type="hidden" name="return" value="<?=$site_root?>/return.php?id=<?=$line[id]?>"> <button type="submit" class="clean-green">Pay Now</button> </form> on return i will get it by id which is <?$line[id]?> but i want to get the transection id of payment too how it comes ? Hi, I have setup my paypal payment method for a shopping cart on my site, all is well but in order for my server to flag an invoice as paid, the user must return to my website after paying and the query string in the url give the script the go ahead to mark it as paid which in turn alerts the appropriate department that its ok to source the order. ~The problem is, if the user for whatever reason skip the redirect back to my site, the invoice is remain 'unpaid' and has to be changed manually when the payment has been checked in the account. As you might imagine this is a bit of a problem because not only can it cause quite a delay, it also requires manually changing values which can lead to other problems. So if there is a better way i would appreciate the info, thanks a lot. Hi, I've integrated paypal payment pro over my website. I don't know how can i test it. can any one help me out? my site address is : http://pacific-labs.com/paymybill.php Please help Hi me need to implement echeck system in my site with paypal using php script with ipn can any one help me out regarding code for paypal echeck payment system. Thanks For some reason I can't get this script working for my IPN. Please help. <?php include("init.inc.php"); $send = 'cmd=_notify-validate&' . http_build_query($_POST); $head = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n"; $head .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; $head .= 'Content-Length: ' . strlen($send) . "\r\n\r\n"; $fp = fsockopen('sandbox.paypal.com', 80); if ($fp !== false){ fwrite($fp, $head . $send); $response = stream_get_contents($fp); $response = trim(end(explode("\n", $response))); if ($response === 'VERIFIED' && $_POST['payment_status'] === "Completed" && $_POST['mc_gross'] === "10.00" && $_POST['mc_currency'] === "USD") { $payer_email = $_POST['payer_email']; $q = mysql_query("UPDATE `users` SET `test` = '1' WHERE `email` = '$payer_email'"); } } fclose($fp); ?> Hi All, I am using paypal code which as follows below <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="email"> <input type="hidden" name="item_name" value="productname"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="amount" value="<?php echo $totalamount; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> The following are the problems i am facing 1. the page will be redirect to paypal page such that customer having paypal account can pay so how to pay for customers who dont have paypal account. 2. how to get return value after success/failure of payment. 3. it is throwing an error as shown below We notice that you are attempting to pay an Indian resident user. The payment you initiated has been blocked. PayPal only facilitates international payments and cannot be used for domestic payments within India. We suggest you find alternative methods to complete the payment. If you believe that the person you attempted to pay is not based in India, please contact PayPal customer support. Please share your knowledge on above Regard's Girish |