pmpro_ipnValidate

Validate the $_POST with PayPal.

Description

pmpro_ipnValidate(); 

Usage

  1. if ( !function_exists( 'pmpro_ipnValidate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/services/ipnhandler.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = pmpro_ipnValidate(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/services/ipnhandler.php  
  1. function pmpro_ipnValidate() { 
  2. //read the post from PayPal system and add 'cmd' 
  3. $req = 'cmd=_notify-validate'; 
  4.  
  5. //generate string to check with PayPal 
  6. foreach ( $_POST as $key => $value ) { 
  7. $value = urlencode( stripslashes( $value ) ); 
  8. $req .= "&$key=$value"; 
  9.  
  10. //post back to PayPal system to validate 
  11. $gateway_environment = pmpro_getOption( "gateway_environment" ); 
  12. if ( $gateway_environment == "sandbox" ) { 
  13. $paypal_url = 'https://www.' . $gateway_environment . '.paypal.com/cgi-bin/webscr'; 
  14. } else { 
  15. $paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; 
  16.  
  17. $paypal_params = array( 
  18. "body" => $req,  
  19. "httpversion" => "1.1",  
  20. "Host" => "www.paypal.com",  
  21. "Connection" => "Close",  
  22. "user-agent" => PMPRO_USER_AGENT 
  23. ); 
  24.  
  25. $fp = wp_remote_post( $paypal_url, $paypal_params ); 
  26.  
  27. //log post vars 
  28. ipnlog( print_r( $_POST, true ) ); 
  29.  
  30. //assume invalid 
  31. $r = false; 
  32.  
  33. if ( empty( $fp ) ) { 
  34. //HTTP ERROR 
  35. ipnlog( "HTTP ERROR" ); 
  36.  
  37. $r = false; 
  38. } elseif ( ! empty( $fp->errors ) ) { 
  39. //error from PayPal 
  40. ipnlog( "ERROR" ); 
  41. ipnlog( "Error Info: " . print_r( $fp->errors, true ) . "\n" ); 
  42.  
  43. //log fb object 
  44. ipnlog( print_r( $fp, true ) ); 
  45.  
  46. $r = false; 
  47. } else { 
  48. ipnlog( "FP!" ); 
  49.  
  50. //log fb object 
  51. ipnlog( print_r( $fp, true ) ); 
  52.  
  53. $res = wp_remote_retrieve_body( $fp ); 
  54. ipnlog( print_r( $res, true ) ); 
  55.  
  56. if ( strcmp( $res, "VERIFIED" ) == 0 ) { 
  57. //all good so far 
  58. ipnlog( "VERIFIED" ); 
  59. $r = true; 
  60. } else { 
  61. //log for manual investigation 
  62. ipnlog( "INAVLID" ); 
  63. $r = false; 
  64.  
  65. /** 
  66. * Filter if an ipn request is valid or not. 
  67. * @since 1.8.6.3 
  68. * @param bool $r true or false if the request is valid 
  69. * @param mixed $fp remote post object from request to PayPal 
  70. */ 
  71. $r = apply_filters( 'pmpro_ipn_validate', $r, $fp ); 
  72.  
  73. return $r;