473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to confirm payment in paypal using IPN

134 100+
Hi

i m a working with paypal to integrate it with my website.,

users can book the hall regarding time basis.

so i m sending the amount to paypal by paynow button created through my paypal test account.

and i inserted the ipn coding in the notify_url specified.

here is the code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Read the post from PayPal system and add 'cmd'
  3. $req = 'cmd=_notify-validate';
  4. foreach ($_POST as $key => $value) {
  5. $value = urlencode(stripslashes($value));
  6. $req .= "&$key=$value";
  7. }
  8. // post back to PayPal system to validate
  9. $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  10. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  11. $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  12. $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
  13. // assign posted variables to local variables
  14. $item_name = $_POST['item_name'];
  15. $item_number = $_POST['item_number'];
  16. $payment_status = $_POST['payment_status'];
  17. $payment_amount = $_POST['mc_gross'];
  18. $payment_currency = $_POST['mc_currency'];
  19. $txn_id = $_POST['txn_id'];
  20. $receiver_email = $_POST['receiver_email'];
  21. $payer_email = $_POST['payer_email'];
  22. $payment_date = $_POST['payment_date'];
  23. $first_name = $_POST['first_name'];
  24. $last_name = $_POST['last_name'];
  25. $payment_type = $_POST['payment_type'];
  26. $payment_status = $_POST['payment_status'];
  27. $payment_gross = $_POST['payment_gross'];
  28. $payment_fee = $_POST['payment_fee'];
  29. $settle_amount = $_POST['settle_amount'];
  30. $memo = $_POST['memo'];
  31. $payer_email = $_POST['payer_email'];
  32. $receiver_email = $_POST['receiver_email'];
  33. $txn_id = $_POST['txn_id'];
  34. $txn_type = $_POST['txn_type'];
  35. $payer_status = $_POST['payer_status'];
  36. $address_street = $_POST['address_street'];
  37. $address_city = $_POST['address_city'];
  38. $address_state = $_POST['address_state'];
  39. $address_zip = $_POST['address_zip'];
  40. $address_country = $_POST['address_country'];
  41. $address_status = $_POST['address_status'];
  42. $item_name = $_POST['item_name'];
  43. $item_number = $_POST['item_number'];
  44. $tax = $_POST['tax'];
  45. $option_name1 = $_POST['option_name1'];
  46. $option_selection1 = $_POST['option_selection1'];
  47. $option_name2 = $_POST['option_name2'];
  48. $option_selection2 = $_POST['option_selection2'];
  49. $for_auction = $_POST['for_auction'];
  50. $invoice = $_POST['invoice'];
  51. $subscr_id = $_POST['subscr_id'];
  52. if (!$fp) {
  53. // HTTP ERROR
  54. } else {
  55. fputs ($fp, $header . $req);
  56. while (!feof($fp)) {
  57. $res = fgets ($fp, 1024);
  58.  
  59. if (strcmp ($res, "VERIFIED") == 0) {
  60. // check the payment_status is Completed
  61. // check that txn_id has not been previously processed
  62. // check that receiver_email is your Primary PayPal email
  63. // check that payment_amount and payment_currency are correct
  64. // process payment
  65. // Send a custom email to the value of payer_email
  66. // Set variables needed for email.
  67.  
  68. //manually checked by writing the output into a text file
  69. $fp1 = fopen('data1.txt', 'w');
  70. fwrite($fp1, $payment_status.$receiver_email);
  71. fwrite($fp1, $req);
  72. fclose($fp1);
  73.  
  74. $from = "Example name";
  75. $subject = "Thanks for your purchase";
  76. $msg = "Thank you for your purchase. You have successfully finished your payment. ...";
  77. mail($payer_email, $subject, $msg, "From: $from");
  78. }
  79. else if (strcmp ($res, "INVALID") == 0) {
  80. // log for manual investigation
  81. }
  82. }
  83. fclose ($fp);
  84. }
  85. ?>
  86.  
all works fine.

payment gets paid and data's are transferred to the notify_url.

I checked it by writing all the output data's into a text file.

but when the payment is complete the payment_status is "Pending" when it returns to the notify_url.

it gets changed to "Confirmed" only when i log in to my paypal test account and accept the payment.

why that it so happen..

i need to update my database when payment is completed and issue the user a receipt that he had done the booking successfully.

Can i proceed when payment_status is "Pending".

or what should i do.

thanks

regards
vijay
Sep 16 '10 #1
1 4643
vjayis
134 100+
Oops., found the answer.,

Payment Review is enabled in my sandbox account.

Solution:
Turn off this feature in your sandbox account by logging in at https://developer.paypal.com >> click on test accounts >> then, next to your sandbox account, click on 'enabled' under Payment review to disable it.

found it in paypal developer central.
Sep 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Adam King | last post by:
Hey, I'm trying to set-up a PayPal Instant Payment Notification backend to a site. The problem is that I cannot post back to PayPal using "fsockopen()" since my service provider (1and1.co.uk)...
1
by: Robert Fitzpatrick | last post by:
I tried posting this to PHP-DB list, but no answers since yesterday. I'm thinking it is not possible, but just trying to confirm. I am using pg_exec($dbh, "COPY sometable FROM stdin USING...
0
by: cameron | last post by:
I am currently writing a C++ program that has to calculate and display the monthly mortgage payment amount using the amout of the mortgage, the term, and interest rate as input by the user. Next, I...
7
by: shil | last post by:
Hi all, Can any one direct me in how to use javascript confirm() function when a condition is met from codebehind. I don't want to attach this to a button. When I submit the page, I want to...
0
by: PayPal Security Measures! | last post by:
<P><A href="http://www.paypal.com/cgi-bin/webscr?cmd=_home" target=_blank><IMG src="https://www.paypal.com/en_US/i/logo/paypal_logo.gif" border=0></A</P> <TABLE cellSpacing=0 cellPadding=0...
14
by: ykhamitkar | last post by:
Hi there, I am working on paypal payment gateway using php. How can I set return url with some arguments Thanks, Yogesh
1
by: namartajhamb | last post by:
I have one Confirm Message Box using Confirm() javascript function which display two buttons Ok and Cancel. I want to Change these buttons lables into YES/NO. how can i change lables of buttons....
2
by: n.p.roopesh | last post by:
I want to know ,How i can implement the online payment system in my web site using PHP
0
by: yuwenwu006 | last post by:
5% paypal handling charge supports the online payment! PayPal cheap Guess wallet Dear friend welcome to shopping on www.Shoes-paypal.cn 1.5% paypal handling charge supports the online payment!...
1
by: bejovial | last post by:
how to make shopping cart with the help of PayPal using asp.net with c#, and i am using sql server 2005 as back end
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.