Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: PayPal API
Forum PHP.pl > Forum > PHP
xierip
Witam, pisze sobie sklepik do gry,
aktualnie mam już prawie wszystkie płatności, zostało mi jedynie dodanie pay safe card, oraz pay pal'a

Jak widzicie temat dotyczy PP, mam problem z tym że po prostu nie działa, choć powinno.
Czy ktoś mógł poratować przykładami jak tego używać, chodzi mi o to że osoba logouje sie na strone, wchodzi w panel, wpisuje wartość i klika guzik, jest przekierowywana na strone ppala płaci (tyle mam), ale nie umiem sprawdzić czy płatność dotarła, ustawiłem return URL'a, lecz POST jest pusty, a ja pieniążki dostaje na paypala (sprawdzałem), zamieszczam kodzik niżej:


test.php (czyli główny)
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. <FORM ACTION="https://www.paypal.com/cgi-bin/webscr" METHOD="POST">
  8. <INPUT TYPE="hidden" NAME="cmd" VALUE="_xclick">
  9. <INPUT TYPE="hidden" NAME="NOSHIPPING" VALUE="2">
  10. <INPUT TYPE="hidden" NAME="business" VALUE="xierip@gmail.com">
  11. <INPUT TYPE="hidden" NAME="user_id" VALUE="fffff user id">
  12. <INPUT TYPE="hidden" NAME="item_name" VALUE="Monety w sklepie serwerowym">
  13. <INPUT TYPE="number" NAME="amount"/>
  14. <INPUT TYPE="hidden" NAME="currency_code" VALUE="PLN">
  15. <input type="hidden" value="http://darkelite.pl/return2.php" name="return">
  16. <INPUT TYPE="image" NAME="submit" BORDER="0" SRC="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" ALT="PayPal - The safer, easier way to pay online">
  17. <img alt="" border="" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif">
  18. </FORM>
  19.  



return.php czyli plik podany do odbioru na stronie ppala:
  1. <?php
  2. ini_set('display_errors', 'On');
  3. // CONFIG: Enable debug mode. This means we'll log requests into 'ipn.log' in the same directory.
  4. // Especially useful if you encounter network errors or other intermittent problems with IPN (validation).
  5. // Set this to 0 once you go live or don't require logging.
  6. define("DEBUG", 1);
  7. // Set to 0 once you're ready to go live
  8. define("USE_SANDBOX", 1);
  9. define("LOG_FILE", "./ipn.log");
  10. // Read POST data
  11. // reading posted data directly from $_POST causes serialization
  12. // issues with array data in POST. Reading raw POST data from input stream instead.
  13. $raw_post_data = file_get_contents('php://input');
  14. $raw_post_array = explode('&', $raw_post_data);
  15. $myPost = array();
  16. foreach ($raw_post_array as $keyval) {
  17. $keyval = explode ('=', $keyval);
  18. if (count($keyval) == 2)
  19. $myPost[$keyval[0]] = urldecode($keyval[1]);
  20. }
  21. // read the post from PayPal system and add 'cmd'
  22. $req = 'cmd=_notify-validate';
  23. if(function_exists('get_magic_quotes_gpc')) {
  24. $get_magic_quotes_exists = true;
  25. }
  26. foreach ($myPost as $key => $value) {
  27. if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
  28. $value = urlencode(stripslashes($value));
  29. } else {
  30. $value = urlencode($value);
  31. }
  32. $req .= "&$key=$value";
  33. }
  34. // Post IPN data back to PayPal to validate the IPN data is genuine
  35. // Without this step anyone can fake IPN data
  36. if(USE_SANDBOX == true) {
  37. $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
  38. } else {
  39. $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
  40. }
  41. $ch = curl_init($paypal_url);
  42. if ($ch == FALSE) {
  43. return FALSE;
  44. }
  45. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  46. curl_setopt($ch, CURLOPT_POST, 1);
  47. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  48. curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  49. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  50. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  51. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  52. if(DEBUG == true) {
  53. curl_setopt($ch, CURLOPT_HEADER, 1);
  54. curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
  55. }
  56. // CONFIG: Optional proxy configuration
  57. //curl_setopt($ch, CURLOPT_PROXY, $proxy);
  58. //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  59. // Set TCP timeout to 30 seconds
  60. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  61. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
  62. // CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
  63. // of the certificate as shown below. Ensure the file is readable by the webserver.
  64. // This is mandatory for some environments.
  65. //$cert = __DIR__ . "./cacert.pem";
  66. //curl_setopt($ch, CURLOPT_CAINFO, $cert);
  67. $res = curl_exec($ch);
  68. if (curl_errno($ch) != 0) // cURL error
  69. {
  70. if(DEBUG == true) {
  71. error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
  72. }
  73. curl_close($ch);
  74. echo"curl error";
  75. } else {
  76. // Log the entire HTTP response if debug is switched on.
  77. if(DEBUG == true) {
  78. error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE);
  79. error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
  80. }
  81. curl_close($ch);
  82. }
  83. // Inspect IPN validation result and act accordingly
  84. // Split response headers and payload, a better way for strcmp
  85. $tokens = explode("\r\n\r\n", trim($res));
  86. $res = trim(end($tokens));
  87. if (strcmp ($res, "VERIFIED") == 0) {
  88. // check whether the payment_status is Completed
  89. // check that txn_id has not been previously processed
  90. // check that receiver_email is your PayPal email
  91. // check that payment_amount/payment_currency are correct
  92. // process payment and mark item as paid.
  93. // assign posted variables to local variables
  94. //$item_name = $_POST['item_name'];
  95. //$item_number = $_POST['item_number'];
  96. //$payment_status = $_POST['payment_status'];
  97. //$payment_amount = $_POST['mc_gross'];
  98. //$payment_currency = $_POST['mc_currency'];
  99. //$txn_id = $_POST['txn_id'];
  100. //$receiver_email = $_POST['receiver_email'];
  101. //$payer_email = $_POST['payer_email'];
  102.  
  103. if(DEBUG == true) {
  104. error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
  105. }
  106. echo"dziala".$_POST['item_name']."x".$_POST['payment_status']."x".$_POST['payer_email']."x".$_POST['receiver_email']."x".$_POST['mc_gross'].$_POST['user_id'];
  107. } else if (strcmp ($res, "INVALID") == 0) {
  108. // log for manual investigation
  109. // Add business logic here which deals with invalid IPN messages
  110. if(DEBUG == true) {
  111. error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
  112. }
  113. echo"nie dziala";
  114. }
  115. ?>



zawsze zwraca "nie dziala", prosze o pomoc, ew przykłady kodu, nie musi być to IPN.

Po zakończeniu płatności chce dodać rekord do bazy danych.
Pozdrawiam i dziękuje za wszelkie odpowiedzi.
irytek
Hej,

to nie jest return lecz notify_url

http://irytek.com/paypal-standard-html/
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.