fkoessler
fkoessler

Reputation: 7276

subscription handling

I am looking for best practice concerning user subscription handling. The user can subscribe through paypal (handled with paypal IPN) to obtain a status that give them some priviledge on the website. However the subscriptions are for one year. What are best practices to automatically detect when a subscription should be cancelled (one year after subscription is done)? Thank you.

Upvotes: 1

Views: 352

Answers (2)

Topher
Topher

Reputation: 183

Alternatively if you want a platform to handle it, use a tool like Zoho Subscriptions. I use it and it does all of that for me. I just API into it from my website and it has connections to PayPal and other gateways. It's also got good reporting.

Upvotes: 2

Zeritor
Zeritor

Reputation: 313

With use of a database, you could store the expiry date of the subscription as a DateTime of the current time + 1 year.

You could then either have a script run routinely or check on log in, if the current time is greater than the subscription expiry time. If it is, change the user's account to unsubscribed.

In PHP:

$nextyear  = mktime(0, 0, 0, date("d"),   date("m"),   date("Y")+1);

That will tell you the Day/Month/Year of a year from today, so you could store that in the user/subscription table. On log-in, you can then just compare that against:

$today = mktime(0, 0, 0, date("d"),   date("m"),   date("Y"));

If $today is larger than the stored value for the expiry date, then you know to cancel the subscription and/or prompt them to pay for the next year.

Upvotes: 4

Related Questions