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%)
-----


Hejki,
to jest bardzo stary listener. Powinien zadziałać jeśli zmienisz HTTP NA 1.1 w linii 22 oraz 41 $res zmień na trim($res).

Jednakże proponuje wykorzystać curla i oficjalny kod listnera:
https://github.com/paypal/ipn-code-samples/.../paypal_ipn.php

Sprawdzi tylko czy masz curl włączony.

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