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
ZaqU
post
Post #2





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

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


Oto cały kod:

  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. //paypal or sandbox?
  9. if( $testmode === true ) {
  10. $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
  11. } else {
  12. $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
  13. }
  14.  
  15.  
  16. // read the post from PayPal system and add 'cmd'
  17. $req = 'cmd=_notify-validate';
  18. foreach( $_POST as $key => $value ) {
  19. $value = urlencode(stripslashes(mysqli_real_escape_string($link, $value)));
  20. $req .= "&$key=$value";
  21. }
  22. error_log(date('[Y-m-d H:i e] '). "Req:" . $req . PHP_EOL, 3, LOG_FILE);
  23.  
  24. // Post IPN data back to PayPal to validate the IPN data is genuine
  25. // Without this step anyone can fake IPN data
  26. $ch = curl_init($paypal_url);
  27. if ($ch == FALSE) {
  28. error_log(date('[Y-m-d H:i e] '). "Connection failed!" . PHP_EOL, 3, LOG_FILE);
  29. }
  30. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  31. curl_setopt($ch, CURLOPT_POST, 1);
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  33. curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  34. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  35. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  36. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  37. if( $testmode == true ){
  38. curl_setopt($ch, CURLOPT_HEADER, 1);
  39. curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
  40. }
  41. // CONFIG: Optional proxy configuration
  42. //curl_setopt($ch, CURLOPT_PROXY, $proxy);
  43. //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  44. // Set TCP timeout to 30 seconds
  45. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  46. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
  47.  
  48. $res = curl_exec($ch);
  49.  
  50. error_log(date('[Y-m-d H:i e] '). "Res:" . $res . PHP_EOL, 3, LOG_FILE);
  51.  
  52. if (curl_errno($ch) != 0){ // cURL error
  53. if($testmode == true) {
  54. 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);
  55. }
  56. curl_close($ch);
  57. } else {
  58. // Log the entire HTTP response if debug is switched on.
  59. // Log the entire HTTP response if debug is switched on.
  60. if($testmode == true) {
  61. 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);
  62. error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE);
  63. }
  64. curl_close($ch);
  65. }
  66.  
  67. $tokens = explode("\r\n\r\n", trim($res));
  68. $res = trim(end($tokens));
  69.  
  70. error_log(date('[Y-m-d H:i e] '). "Res (end) (trim): " . $res . PHP_EOL, 3, LOG_FILE);
  71.  
  72. if(strcmp ($res, "VERIFIED") == 0) {
  73. // check whether the payment_status is Completed
  74. // check that txn_id has not been previously processed
  75. // check that receiver_email is your PayPal email
  76. // check that payment_amount/payment_currency are correct
  77. // process payment and mark item as paid.
  78. // assign posted variables to local variables
  79. //$item_name = $_POST['item_name'];
  80. //$item_number = $_POST['item_number'];
  81. //$payment_status = $_POST['payment_status'];
  82. //$payment_amount = $_POST['mc_gross'];
  83. //$payment_currency = $_POST['mc_currency'];
  84. //$txn_id = $_POST['txn_id'];
  85. //$receiver_email = $_POST['receiver_email'];
  86. //$payer_email = $_POST['payer_email'];
  87.  
  88. if($testmode == true) {
  89. error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
  90. }
  91. } else if (strcmp ($res, "INVALID") == 0) {
  92. // log for manual investigation
  93. // Add business logic here which deals with invalid IPN messages
  94. if($testmode == true) {
  95. error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
  96. }
  97. }
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: 24.12.2025 - 15:10