latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Payment Notification Hook

Home Forums Community Forum Payment Notification Hook

This topic contains 3 replies, has 2 voices. Last updated by  Jason (Lead Developer) 4 years, 10 months ago.

Topic Author Topic
Posted: Tuesday Feb 7th, 2012 at 6:21 am #4296
ETsol
Username: ets

Seems my last question on this topic has disappeared in the site update…

I’m trying to hook into the payment notification system in s2member, and perform an action when any payment is received. I can see how to do this via the API and a separate page, but in my situation I need to accomplish it via a hook.

The hook I’ve found which I think will suit my purposes is ‘ws_plugin__s2member_after_paypal_notify’, however I’m struggling to work out how to get the users information related to the notification.
All I really need is the user_id and the membership level associated with it.

Again as mentioned, I can see how to do this via the Notification API, but could you advise how I can get that info in my hooked function?

Thanks!

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Thursday Feb 9th, 2012 at 1:14 am #4537
Staff Member

Thanks for the heads up on this thread.

Create this directory and file please.
/wp-content/mu-plugins/s2-hacks.php
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )

<?php
add_action("ws_plugin__s2member_after_paypal_notify", "my_function");
function my_function($vars = array())
	{
		$paypal = $vars&#91;"paypal"&#93;;
		// This array of PayPal variables contains all sorts of information.
		// You can print_r() to get a full list while testing.
		// print_r($paypal);
	}
?>

In this particular Hook, there is not any specific User ID. The Membership Level would be in this variable: $paypal["level"]. If you would like to share exactly what you’re trying to catch and/or do with your function, I’ll point you to the proper Hook/Filter that should be used.

Also, you will find a list of many PayPal related Hooks/Filters here.
http://www.s2member.com/codex/stable/s2member/paypal/package-filters/

Posted: Thursday Feb 9th, 2012 at 1:39 am #4541
ETsol
Username: ets

Thanks for the reply Jason!

That makes more sense now cheers – Just to explain what I’m doing – I’m running a token system on my site for members, and with the system I’ve set up currently I have to manually add these tokens to the members regular WP user_meta when I receive payments. All I’m really looking to do is manage this automatically, so that when a payment notification is received I can check who it was from, their membership level, then automatically update their tokens in their WP user_meta with a function.

This is why I’m trying to find the user_id and membership level (new/current or upgraded).

Thanks again for your help!

Posted: Tuesday Feb 14th, 2012 at 12:25 pm #5042
Staff Member

Thanks for the follow-up.

Well, I wouldn’t use this Hook, because depending on the type of transaction, a User ID might not even exist yet during IPN processing. Instead, I would use s2Member’s API Notification for Payments, which already includes the details you need through Replacement Codes listed in your Dashboard under: s2Member -> API Notifications -> Payment Notifications.

Keep in mind that your custom script connected to an API Notification can also take full advantage of the WordPress/s2Member Framework, by including the /wp-load.php file.

That being said, you might find this function useful in your custom coding endeavor.
c_ws_plugin__s2member_utils_users::get_user_id_with()
See also, source code documentation here.

I hope that helps :)

Viewing 3 replies - 1 through 3 (of 3 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.