pmpro_ipnFailedPayment

Send an email RE a failed payment.

Description

pmpro_ipnFailedPayment( $last_order ); 

$last_order passed in is the previous order for this subscription.

Parameters (1)

0. $last_order
The last order.

Usage

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

Defined (1)

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

/services/ipnhandler.php  
  1. function pmpro_ipnFailedPayment( $last_order ) { 
  2. //hook to do other stuff when payments fail 
  3. do_action( "pmpro_subscription_payment_failed", $last_order ); 
  4.  
  5. //create a blankorderfor the email 
  6. $morder = new MemberOrder(); 
  7. $morder->user_id = $last_order->user_id; 
  8.  
  9. $user = new WP_User( $last_order->user_id ); 
  10. $user->membership_level = pmpro_getMembershipLevelForUser( $user->ID ); 
  11.  
  12. //add billing information if appropriate 
  13. if ( $last_order->gateway == "paypal" ) //website payments pro 
  14. $morder->billing->name = $_POST['address_name']; 
  15. $morder->billing->street = $_POST['address_street']; 
  16. $morder->billing->city = $_POST['address_city ']; 
  17. $morder->billing->state = $_POST['address_state']; 
  18. $morder->billing->zip = $_POST['address_zip']; 
  19. $morder->billing->country = $_POST['address_country_code']; 
  20. $morder->billing->phone = get_user_meta( $morder->user_id, "pmpro_bphone", true ); 
  21.  
  22. //get CC info that is on file 
  23. $morder->cardtype = get_user_meta( $morder->user_id, "pmpro_CardType", true ); 
  24. $morder->accountnumber = hideCardNumber( get_user_meta( $morder->user_id, "pmpro_AccountNumber", true ), false ); 
  25. $morder->expirationmonth = get_user_meta( $morder->user_id, "pmpro_ExpirationMonth", true ); 
  26. $morder->expirationyear = get_user_meta( $morder->user_id, "pmpro_ExpirationYear", true ); 
  27.  
  28. // Email the user and ask them to update their creditcardinformation 
  29. $pmproemail = new PMProEmail(); 
  30. $pmproemail->sendBillingFailureEmail( $user, $morder ); 
  31.  
  32. // Email admin so they are aware of the failure 
  33. $pmproemail = new PMProEmail(); 
  34. $pmproemail->sendBillingFailureAdminEmail( get_bloginfo( "admin_email" ), $morder ); 
  35.  
  36. ipnlog( "Payment failed. Emails sent to " . $user->user_email . " and " . get_bloginfo( "admin_email" ) . "." ); 
  37.  
  38. return true;