Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> PayPal Sandbox - jak testować?
ZaqU
post
Post #1





Grupa: Zarejestrowani
Postów: 71
Pomógł: 1
Dołączył: 21.01.2013

Ostrzeżenie: (0%)
-----


Witajcie,

Natknąłem się na pewien problem z którym nie mogę sobie poradzić. Pytanie do osób, które miały już styczność z podłączaniem i testowaniem płatności PayPal. Mam do dyspozycji skrypt systemu depozytów z codecanyon
http://codecanyon.net/item/deposit-system/59753
i chciałbym go dostosować do własnych potrzeb. Działa on na takiej zasadzie, że wysyła następujący formularz:
  1. <form name="depositform" id="depositform" method="post" action="<?php echo self::payment_action(); ?>">
  2. <input type="hidden" name="rm" value="2"/>
  3. <input type="hidden" name="cmd" value="_xclick"/>
  4. <input type="hidden" name="business" value="<?php echo $paypalmail; ?>"/>
  5. <input type="hidden" name="item_name" value="Deposit cash"/>
  6. <input type="hidden" name="no_shipping" value="1"/>
  7. <input type="hidden" name="return" value="<?php echo $siteurl; ?>deposit_example.php?action=success"/>
  8. <input type="hidden" name="notify_url" value="<?php echo $siteurl; ?>includes/depositipn.php"/>
  9. <input type="hidden" name="cancel_return" value="<?php echo $siteurl; ?>deposit_example.php?action=cancel"/>
  10. <input type="hidden" name="custom" value="<?php echo $useridentify; ?>" />
  11. <input type="hidden" name="amount" value="<?php echo $amount; ?>" />
  12. <p><?php echo $depositconfirm; ?></p>
  13. <input type="submit" name="checkout" value="Proceed with payment" />
  14. </form>

na adres: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=...&dispatch=...

Niestety nie wiem co dalej. Po wypełnieniu formularza pojawia się informacja że płatność została zaakceptowana, na podany adres e-mail przyjdzie potwierdzenie, a niestety nie działa to tak jak powinno, tj. nie wysyła maila i nie zapisuje w systemie płatności. Muszę przetestować czy ten system działa, ale jak na razie nie wiem jak. To czego potrzebuję, to informacja na temat tego jakie API wykorzystuje podana wyżej metoda i gdzie szukać dokumentacji do niej (PayPal oferuje dziesiątki różnych API i trudno się połapać, a nigdy wcześniej nie korzystałem z tego systemu).
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
irytek
post
Post #2





Grupa: Zarejestrowani
Postów: 16
Pomógł: 5
Dołączył: 31.12.2014

Ostrzeżenie: (0%)
-----


Proponowałbym jednak aż tak nie modyfikować kodu w szczególności początku gdzie szczytuje się dane z posta które są bardzo podatne na serializacje. Nie dodawaj do $req żadnych dodatkowych znaków gdyż dane wysłane do PayPal muszą być identyczne do tych które otrzymasz poddane urlencode.

Proponuje zostawić kod w niezmienionej formie i przetestować go najpierw z symulatorem:
https://developer.paypal.com/webapps/develo...s/ipn_simulator

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


Ten post edytował irytek 10.01.2015, 22:50:21
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 17:35