Page 1 of 1

Equivalent hook for notification API url

PostPosted: December 20th, 2011, 5:53 pm
by hoststreamsell
Hi, I am trying to figure out which hook gets called when a buy now paypal payment is made. I can get the notification API to call a url but would like to be able to have more control over this by way of a hook.

I have tried the following but it doesn't seem to fire.
add_action('ws_plugin__s2member_after_paypal_notify', 'my_method');

I have got other hooks to work once the user returns back to the website from paypal, but I would like to use the hook which fires when the payment is made just like the notification API url.

Thanks,
Gavin

Re: Equivalent hook for notification API url

PostPosted: December 22nd, 2011, 8:39 am
by hoststreamsell
Anybody? I have tried to find this myself but not having any luck

Re: Equivalent hook for notification API url

PostPosted: December 22nd, 2011, 5:07 pm
by Raam Dev
Hello,

If the payment is being made on PayPal's website, there won't be any way to hook into that from s2Member (since the user isn't on your site anymore, they're on PayPal's website). You might want to try hooking into the checkout process itself instead.

See the list of s2Member PayPal hooks and try searching for "checkout".

Re: Equivalent hook for notification API url

PostPosted: December 22nd, 2011, 5:25 pm
by hoststreamsell
Hi Raam Dev, first off thanks for the reply. The payment is indeed being made on paypal's site, but the notification API url gets triggered as soon as the payment is made, even though it is on the paypal site. So I am thinking there must be some part of the code that is being triggered even before the user comes back to the site from paypal?

I'll look at the hooks again as you suggest and see if I can find something.

Re: Equivalent hook for notification API url

PostPosted: December 23rd, 2011, 2:00 pm
by Raam Dev
Ah yes, the PayPal does send the IPN notification upon payment, but I'm not sure if there's a way to hook into that. I just looked through the s2Member Codex and didn't find anything related to IPN messages.

Did you find anything in the PayPal Hooks that might work for your scenario?

Re: Equivalent hook for notification API url

PostPosted: December 26th, 2011, 4:29 pm
by Jason Caldwell
Thanks for the heads up on this thread.

There are about 200 Hooks/Filters specifically related to IPNs and Payment Data Transfer, making it very possible to filter and/or hook into s2Member's processing routines in all sorts of creative ways.
See: viewtopic.php?f=40&t=12778&src_doc_v=111220

This is one of the most popular Hooks, and might do nicely in your scenario:
Code: Select all
ws_plugin__s2member_during_paypal_notify_during_subscr_signup_wo_update_vars
See: viewtopic.php?f=40&t=14521&src_doc_v=111220#src_doc_line_454

There is also this Hook, which deals with modifications, instead of initial purchases:
Code: Select all
ws_plugin__s2member_during_paypal_notify_during_subscr_signup_w_update_vars
See: viewtopic.php?f=40&t=14521&src_doc_v=111220#src_doc_line_296

Re: Equivalent hook for notification API url

PostPosted: January 4th, 2012, 9:25 am
by hoststreamsell
Hi Jason, only getting a chance to try this out now after the holidays. After a quick test it looks to do what I want. Thanks for the information!

Actually my mistake, it is still only the notification url that is being called. This is what I am doing in my plugin...

Code: Select all
add_action('ws_plugin__s2member_during_paypal_notify_during_subscr_signup_wo_update_vars', 'do_paypal_ccap');

function do_paypal_ccap($vars = array()){
        $fh = fopen('/home/.sites/_default/logs/s3_log.txt', 'a');
        fwrite($fh, "do_paypal_ccap\n");
        $item_number = $vars["paypal"]["item_number"];
        $user_id = $vars["user_id"];
        fwrite($fh, "3 USER:".$user_id." ITEM:".$item_number."\n");
}


Re: Equivalent hook for notification API url

PostPosted: January 4th, 2012, 5:10 pm
by hoststreamsell
Ok, I figured out why it's not working. I am using buy now buttons but the hooks you provided are for subscription buttons (I should have noticed sooner given the action names). I have got it working if I use a subscription button for a member level, but I also want to be able to use buy now buttons for custom capabilities. Is there an equivalent hook for buy now purchases?

Thanks!

Re: Equivalent hook for notification API url

PostPosted: January 4th, 2012, 8:33 pm
by Raam Dev
Have you tried searching the Package s2Member\PayPal ( 197 Hooks/Filters ) list for "ws_plugin__s2member_during_paypal_notify_during_"? Will any of those hooks work for you?

Perhaps this one:
Code: Select all
ws_plugin__s2member_during_paypal_notify_during_before_new_ccaps


Or this one:
Code: Select all
ws_plugin__s2member_during_paypal_notify_during_new_ccaps

Re: Equivalent hook for notification API url

PostPosted: January 5th, 2012, 4:02 am
by hoststreamsell
Thanks, that works. Both this

Code: Select all
ws_plugin__s2member_during_paypal_notify_before_new_ccaps


and this

Code: Select all
ws_plugin__s2member_during_paypal_notify_during_before_new_ccaps


seem to get called once the pay button is clicked. Awesome!

I am not sure why you would use one rather than the other? Is it maybe possible with the later to perform some logic within my system to check whether I want the purchase to proceed or not, and force the paypal payment to fail if there is some internal condition in my system not met? Just curious as to what else is possible...

Re: Equivalent hook for notification API url

PostPosted: January 5th, 2012, 5:26 pm
by Raam Dev
I'm not entirely sure. That would require digging into the code here (during_before_new_ccaps) and here (before_new_ccaps).

It looks like during_before_new_ccaps gets called before the user is added or ccaps are updated.