For someone who want user_id information from IPN call, here is a quick hacking,
file: wp-content/plugins/wp-paypal/paypal-ipn.php
before this line(about line 115), wp_paypal_debug_log("Updating order information", true);
adding following code
$user_id=$_GET['user_id'];
$ipn_response['user_id']=$user_id;
before this line(about line 140), do_action('wp_paypal_order_processed', $post_id);
adding following code
update_post_meta($post_id, '_user_id', $user_id);
do_action('wp_paypal_order_processed_ipn_response', $post_id,$ipn_response,$user_id);
file:wp-content/plugins/wp-paypal/main.php
change this line(about line 296): $atts['callback'] = home_url() . '/?wp_paypal_ipn=1';
to this:
$atts['callback'] = home_url() . '/?wp_paypal_ipn=1&user_id='.get_current_user_id();
after all above changes, you can use following function to hook on the new action and do what you want,
function c9mf_hook_wp_paypal_order_processed_ipn_response($post_id,$ipn_response,$user_id)
{
/* ipn_response sample
(
[transaction_subject] => Monthly fee
[payment_date] => 00:18:30 Oct 22, 2016 PDT
[txn_type] => subscr_payment
[subscr_id] => I-UH1FCT2P80M9
[last_name] => buyer
[residence_country] => CN
[item_name] => Monthly fee
[payment_gross] => 10.00
[mc_currency] => USD
[business] => [email protected]
[payment_type] => instant
[protection_eligibility] => Ineligible
[verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31At3k7RW3LJrgx7UCuT72hnR3sARy
[payer_status] => verified
[test_ipn] => 1
[payer_email] => [email protected]
[txn_id] => 2G162234UC429330Y
[receiver_email] => [email protected]
[first_name] => test
[payer_id] => LQRQ8N8LT4WMG
[receiver_id] => 8BMVT4A9RKB4W
[payment_status] => Completed
[payment_fee] => 0.69
[mc_fee] => 0.69
[mc_gross] => 10.00
[charset] => windows-1252
[notify_version] => 3.8
[ipn_track_id] => ea507fe44d737
)
*/
$payment_status = get_post_meta($post_id, '_payment_status', true);
if(isset($payment_status) && $payment_status=='Completed'){
//do anything here
}
}
add_action('wp_paypal_order_processed_ipn_response','c9mf_hook_wp_paypal_order_processed_ipn_response',10,3);