malkocoglu Posted January 15, 2014 Share Posted January 15, 2014 Hello everyone, I have been searching on internet about using paypal payment for a minicab booking form I havebut I couldnt find anything that I could use. What I have; The visitor comes to website and start completing the form. They get a price on the second page and the third page is the process page. The data goes to database and customer gets an email and the website admin gets the booking form in email. What I want to do; I want to enable paypal payment so visitor can pay for the minicab journey online. I need the get this working in a way that visitor gets the second page and sees the price, clicks Book & Pay by paypal button and visitor is redirected to paypal for payment, after payment, all the data enters the database (The variables are about 10-15) and customer gets the email and also lands on the success page. If the payment is not successfull then nothing goes to data base and visitor does not get email and visitor then is redirected to cancellation page. I hope I could explained, Could anyone help me how to do it or where I can find the information I needed. Regards Quote Link to comment Share on other sites More sharing options...
TinyI Posted January 15, 2014 Share Posted January 15, 2014 Look at the developers' guide on paypal's site. This gives you all the help you'd need to do this. Quote Link to comment Share on other sites More sharing options...
malkocoglu Posted January 15, 2014 Author Share Posted January 15, 2014 Thanks for the reply, I already have and i couldnt find the information I needed. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 15, 2014 Share Posted January 15, 2014 what you are asking is "how do i do a basic operation" and that is what the documentation is for. you are going to need to have a specific question or problem with some code you have written in order to get help on a php help forum. all you have stated is what you want and in programming, going from what you want to having the code that does that takes programming and effort. Quote Link to comment Share on other sites More sharing options...
malkocoglu Posted January 16, 2014 Author Share Posted January 16, 2014 (edited) Ok, I have the follwing code. I inserted mail() functions to check the process of the codes. Emails come up to Section 3 Completed and stops. So there is a little problem with section 4. I think payment status is not Completed but I am not sure how to check that. Could anyone give me his opinion how to go from here? <?php ini_set('log_errors', true); ini_set('error_log', 'ipn_errors.log'); //connect to database //$error = "Problem connecting"; //mysql_connect('localhost','_prince','getmeout') or die($error); //mysql_select_db('hmt_cms') or die($error); mail('email@gmail.com', 'IPN Progress', 'Section 1 Completed'); // 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"; } mail('email@gmail.com', 'IPN Progress', 'Section 2 Completed'); // 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); mail('email@gmail.com', 'IPN Progress', 'Section 3 Completed'); // 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) { mail('email@gmail.com', 'IPN Progress', 'IPN Error 1'); } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { if ($payment_status == "Completed") { mail('email@gmail.com', 'IPN Progress', 'Section 4 Completed'); if ($payment_amount==0.01 && $payment_currency=="GBP") { mail('email@gmail.com', 'IPN Progress', 'Section 5 Completed'); //$update = mysql_query("UPDATE cms SET premium='1' 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 mail('email@gmail.com', 'IPN Progress', 'IPN Error 2'); } } fclose ($fp); } ?> Edited January 16, 2014 by malkocoglu Quote Link to comment Share on other sites More sharing options...
malkocoglu Posted January 16, 2014 Author Share Posted January 16, 2014 Quick Update, I found out that the payment status is "Pending". I am not sure why but this is why the section 4 is not completed. So could anyone tell me how to change the status to "Completed" Quote Link to comment Share on other sites More sharing options...
malkocoglu Posted January 16, 2014 Author Share Posted January 16, 2014 Update: I managed to changed the payment status to "Completed" but I still dont get the email confirming that. see code below if ($payment_status == "Completed"){ mail('testemail@gmail.com', 'IPN Progress', 'Section 4 Completed'); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.