Page 1 of 2

Non-Recurring payments: last Payment and renewal?

PostPosted: April 24th, 2011, 5:41 pm
by FrancescoRizzi
Hi all.
The site I'm working on is using non-recurring PayPal payments (aka BuyNow) to give yearly membership.

I have a couple of questions inr egard:

1~ I've found and read about the s2member_last_payment_time global, which should provide access to the date of the current user latest payment. However, as Jason pointed out here:
This will ONLY be available for paying Members, and ONLY if you've used a "Subscription" Button. It won't work for Buy Now transactions.

Is there an equivalent for non-recurring payments? We're trying to display on screen when they paid for the membership (or renewed it).
[I think one option is for us to include a custom field when they pay and then rely on that, but I'd really love to be able to do this without writing more custom code, if possible.]

2~ Speaking of renewals... what'd the recommended approach for letting users renew with BuyNow payments? Off the top of my head, I guess I would include a form in the Members-Only area of the site (aka some page requiring them to be logged in and active members at level 1+); by checking their current membership I can figure out what membership level they currently have and build a form equivalent to what they used to signup the first time, or at least the PayPal CheckOut button that was on it.
Is that the common approach or are there better options?

Thanks in advance,
FR

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 24th, 2011, 8:51 pm
by Cristián Lávaque
Hi Francesco. :)

Every Member will ALWAYS have a registration time associated with their account, so you could probably use this s2Member API Constant to accomplish what you need: S2MEMBER_CURRENT_USER_REGISTRATION_TIME. WP Admin -> s2Member -> API Scripting -> API Constants

Code: Select all
<?php echo S2MEMBER_CURRENT_USER_REGISTRATION_TIME; ?>

or the s2member shortcode equivalent:
Code: Select all
[s2Get constant="S2MEMBER_CURRENT_USER_REGISTRATION_TIME" /]


This may output something like: 1270537981. This is a Unix timestamp, which is based on seconds, and you can format it with the date function. http://php.net/date

Regarding renewals, when adding more time to their membership before their EOT is up, will cause the previous one to end and the new one to start at the time of payment.

This is something we're planning to improve, but in the meantime you can fix it with this trick:

Create this directory and file /wp-content/mu-plugins/s2-hacks.php. Inside the file, add this code. Be sure there are NO spaces or line breaks before or after <?php ?>

* This code is untested, but it should work fine. Please let me know if you have any trouble.

Code: Select all
<?php
add_action
('ws_plugin__s2member_during_paypal_notify_during_before_subscr_signup_w_update_vars', 'during_before_subscr_signup_w_update_vars');
function during_before_subscr_signup_w_update_vars($vars = array())
{
    $GLOBALS['existing_s2_eot_time'] = get_user_option('s2member_auto_eot_time', $vars['user_id']);
}

add_action('ws_plugin__s2member_during_paypal_notify_during_subscr_signup_w_update_vars', 'during_subscr_signup_w_update_vars');
function during_subscr_signup_w_update_vars($vars = array())
{
    if (($eot_time = get_user_option('s2member_auto_eot_time', $vars['user_id'])) && $GLOBALS['existing_s2_eot_time'])
        update_user_option($user_id, 's2member_auto_eot_time', $eot_time + ($GLOBALS['existing_s2_eot_time'] - time ()));
}
?>


Let me know if that helps.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 24th, 2011, 8:57 pm
by FrancescoRizzi
Cristián, thanks for the tips. I'm putting the keyboard down for the night but will test them out asap and let you know. S2MEMBER_CURRENT_USER_REGISTRATION_TIME, in particular, may be the right one for us.
And thanks for the heads-up on the auto-killing of the current membership upon renewal: I'm sure that would have been a headscratcher :)

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 24th, 2011, 9:11 pm
by Cristián Lávaque
;)

I look forward to your update.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 25th, 2011, 3:38 pm
by FrancescoRizzi
Haven't tried yet on the renewal - but the code you shared makes sense to me so I think it may just hit the spot.

Regarding the registration time, I think S2MEMBER_CURRENT_USER_PAID_REGISTRATION_TIME may fit our bill even better than S2MEMBER_CURRENT_USER_REGISTRATION_TIME (but thanks for pointing that out to me), since we're trying to display the time when the user paid for the membership..
However, I'm not sure if either is quite right for us...

Based on the API/Scripting documentation,
for S2MEMBER_CURRENT_USER_PAID_REGISTRATION_TIME
[...] However, this will be 0 if they're not logged in; or if they've never paid you at all ( i.e. if they're still a Free Subscriber ). This holds the recorded time at which the Member originally registered their Username (or upgraded for) any type of "paid" access to your site. This value is preserved for the lifetime of their account, even if they upgrade, and even if they're demoted at some point. Once this value is recorded, it never changes under any circumstance.

So if I have a user that registers... then pays for membership on Jan 1st... then renews or upgrades on Feb 1st... if I'm reading the docs correctly S2MEMBER_CURRENT_USER_PAID_REGISTRATION_TIME would report Jan 1st (whereas we'd love to say "Your membership was renewed on Feb 1st")

And S2MEMBER_CURRENT_USER_REGISTRATION_TIME is not quite it either, since it
holds the recorded time at which the User originally registered their Username for access to your site; for free or otherwise.


Hmm... is
Code: Select all
get_user_option ("s2member_auto_eot_time", $uid);
going to give me the time when the user's membership expires? 'cause.. well, our memberships are annual, I might just take 365 days away from that value...

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 25th, 2011, 8:02 pm
by Cristián Lávaque
Yeah, I see what you mean with the constants. Those are the ones available right now.

FrancescoRizzi wrote:Hmm... is
Code: Select all
get_user_option ("s2member_auto_eot_time", $uid);
going to give me the time when the user's membership expires? 'cause.. well, our memberships are annual, I might just take 365 days away from that value...


Yeah, that could work to figure out the last time a payment was made. Good thinking. :)

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 26th, 2011, 1:21 am
by Cristián Lávaque
I'm looking at s2Member Pro's Import tool's documentation and one of the fields is "Last Payment Date ( mm/dd/yyyy )", so it looks like the date you want may be there in the database already.

Why don't you try this?

Code: Select all
get_user_option('s2member_last_payment_date', S2MEMBER_CURRENT_USER_ID); 


I don't have paid members in my installation of s2Member, so I can't confirm that it works, but I thought I'd let you know.

I hope that helps. :)

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 26th, 2011, 5:48 am
by FrancescoRizzi
It does, it does! Thanks Cristián for looking into this: you're awesome, man!

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 26th, 2011, 10:34 am
by Cristián Lávaque
Great! :)

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 26th, 2011, 1:12 pm
by Cristián Lávaque
Actually, I think you don't even need to use the ID of the user...

Code: Select all
<?php echo get_user_option("s2member_last_payment_time"); ?>


That may return a Unix timestamp in seconds, which you'd format with date. http://php.net/date

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: April 27th, 2011, 12:33 am
by Jason Caldwell
Cristián Lávaque wrote:Actually, I think you don't even need to use the ID of the user...

Code: Select all
<?php echo get_user_option("s2member_last_payment_time"); ?>


That may return a Unix timestamp in seconds, which you'd format with date. http://php.net/date

Yes, this is the one you'd want to use in this circumstance.
Yes, this returns a Unix Timestamp.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 7th, 2011, 11:03 am
by FrancescoRizzi
Hey Cristián (/wave Jason).
Regarding the sniplet you gave me here:
Cristián Lávaque wrote:Regarding renewals, when adding more time to their membership before their EOT is up, will cause the previous one to end and the new one to start at the time of payment.

This is something we're planning to improve, but in the meantime you can fix it with this trick:

Create this directory and file /wp-content/mu-plugins/s2-hacks.php. Inside the file, add this code. Be sure there are NO spaces or line breaks before or after <?php ?>

* This code is untested, but it should work fine. Please let me know if you have any trouble.

Code: Select all
<?php
add_action
('ws_plugin__s2member_during_paypal_notify_during_before_subscr_signup_w_update_vars', 'during_before_subscr_signup_w_update_vars');
function during_before_subscr_signup_w_update_vars($vars = array())
{
    $GLOBALS['existing_s2_eot_time'] = get_user_option('s2member_auto_eot_time', $vars['user_id']);
}

add_action('ws_plugin__s2member_during_paypal_notify_during_subscr_signup_w_update_vars', 'during_subscr_signup_w_update_vars');
function during_subscr_signup_w_update_vars($vars = array())
{
    if (($eot_time = get_user_option('s2member_auto_eot_time', $vars['user_id'])) && $GLOBALS['existing_s2_eot_time'])
        update_user_option($user_id, 's2member_auto_eot_time', $eot_time + ($GLOBALS['existing_s2_eot_time'] - time ()));
}
?>




Could this go in my theme's functions.php file instead?
Our WP installation is not running MU/MultiSite enabled so I'm not sure if I want/need to mess with /wp-content/mu-plugins/s2-hacks.php...

Thanks,
F

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 7th, 2011, 12:32 pm
by Jason Caldwell
FrancescoRizzi wrote:Could this go in my theme's functions.php file instead?
Our WP installation is not running MU/MultiSite enabled so I'm not sure if I want/need to mess with /wp-content/mu-plugins/s2-hacks.php...

The /wp-content/mu-plugins/ directory.
(mu) stands for MUST USE plugins, and these are not *just* for Multisite Networking, they can be used on any WordPress® installation. If you don't have this directory, /wp-content/mu-plugins/ please create it.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 7th, 2011, 1:08 pm
by FrancescoRizzi
Jason Caldwell wrote:The /wp-content/mu-plugins/ directory.
(mu) stands for MUST USE plugins, and these are not *just* for Multisite Networking,


ach! my hash for 2-letter acronyms collided, sorry.
Thanks for the clarification: mu shall work then ;)

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 10th, 2011, 4:19 pm
by Jason Caldwell
Cool. Thanks for reporting back on this.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 24th, 2011, 2:25 am
by adamarling
Hi,

Can anyone else verify this hack works for them?
>> /wp-content/mu-plugins/s2-hacks.php

I can only offer non-recurring memberships, which last for 1 year, in my system. I just tried a test renewal, and it updated the EOT date to 1 year from today's date. However when I renew the same account a second time, I assume it would push the EOT date on the membership to 2 years into the future, but it stays '2012', just one year ahead.

Do you know if this hack accounts for multiple years in advance 'renewing' a non-recurring membership?

I'm looking for a situation as such:
Original Membership 10/28/2010.
Renewed on 5/20/2011 (say they would like to renew 6 months in advance)
New EOT for Membership would be 10/28/2012.

(ps. the reason I can't offer recurring memberships is that members will often be paying with company or university credit cards and generally are not allowed to pay by recurring payment).

thanks.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 24th, 2011, 11:08 am
by Cristián Lávaque
This hack is to achieve what you're asking for. You can try it yourself and see if it works. :)

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 24th, 2011, 1:25 pm
by adamarling
Hey Cristian, thanks for the reply. Sorry to be unclear in my previous post, however I did create the directory, the file, and all was in place prior to me making this post. When I ran the 'renewal' subscription, the year does not update. So for me, I guess it didn't work...

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 24th, 2011, 1:36 pm
by Cristián Lávaque
OK. I think the coming release of s2Member will have this included, so you won't need the hack anymore. Any day now. :)

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 24th, 2011, 4:57 pm
by adamarling
Awesome. Looking forward to it. s2Member Pro is the best money I've spent in quite some time. You guys rule.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 24th, 2011, 7:54 pm
by Jason Caldwell
Thanks for the kudos. Yes, this is coming in the next release. It's a configurable option under: s2Member -> PayPal Options -> EOT Behavior. If you're an s2Member Pro customer with an Unlimited Site License, it's already available inside your account at s2Member.com. We're currently running tests against the release candidate with Unlimited Site Licenses.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 27th, 2011, 4:41 pm
by adamarling
Hi Jason,

2 quick questions:

1.) Do you know an estimated release date of s2Member Pro which will include this feature?
2.) Working with existing functions available and some coding on my end, is it possible to create a custom mod to make this work on my end?

thanks,
Adam

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: May 27th, 2011, 5:03 pm
by Jason Caldwell
Should be within a week Adam. So far all tests have returned positive results. Unless we have something major come up, I don't see any reason we can't release it publicly next week.

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: June 6th, 2011, 1:22 pm
by adamarling
Hi Jason,

Not to be a bother, but any ETA on the EOT Renewal feature noted above? I'm starting to get duplicate records added to my s2Member system when expired members renew, so if it will be a while I'll attempt a workaround.

thanks,
Adam

Re: Non-Recurring payments: last Payment and renewal?

PostPosted: June 6th, 2011, 4:18 pm
by Cristián Lávaque
The setting is in there in the latest release. WP Admin -> s2Member -> PayPal Options -> Automatic EOT Behavior -> Fixed-Term Extensions (auto-extend) :)