AUTOMATIC RENEWALS USING THE WEBSITE MEMBERSHIP PLUGIN - Jan 31st, 2023


This is a rather long recipe, covering the process of automatically renewing memberships based on a specified membership
period.

There are a number of pieces to this puzzle:

Setting the expiration date when a member first signs up and creates their member record

Determining when a renewal has expired

Directing the member to a renewal page for payment

After payment, updating the member record to reflect the “new” expiry date so the process can repeat automatically.

Automatically sending a renewal letter on expiration

SETTING THE INITIAL EXPIRATION DATE AND DETERMINING WHEN A RENEWAL HAS EXPIRED
Since my membership period is 1 year, when a member signs up, the “expiresDate” field in the accounts database is
automatically populated with a date that is 1 year from the date that the member record was created. I also set the
“neverExpires” checkbox to zero using this code in my sign-up form. (you can read more about sign-up form
modification elsewhere in this chapter).


expiresDate = (NOW() + INTERVAL 1 YEAR),
neverExpires = '0',


NOTE: Although I could have used the neverExpires field, to deal with special memberships that should never expire, I
chose to create a “special_membership” check box field in the database.

REDIRECTING EXPIRED MEMBERS TO A RENEWAL PAGE
Thanks to some advice from Dave Edis from Interactive Tools, I inserted this code near the top of all of the “members
only” pages (after the login_redirect) to redirect members to a “renew_now” page if their membership had expired.


<?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>

<?php
$isMembershipExpired = strtotime($CURRENT_USER['expiresDate']) <= time();
$notSpecial = ($CURRENT_USER['special_membership'] == 0);
if (
$isMembershipExpired && $notSpecial) { redirectBrowserToURL("renew_now.php"); }
?>


The renewal page includes a PayPal link and I use the program “Linklok” to handle transaction verification and to
redirect the user to a hidden “thank you” page on the site after a successful payment.

THE RENEW_NOW.PHP CODE
At the top of the page:


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('server_path_to_your_root_directory/','','../','../../','../../../');
foreach (
$dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!
function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
?>

<?php if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can
access this page."); } ?>



And in the body:


<div align="center">
<br /><h1><span class="Page-Titles">Thank's For</span><br />
<span class="Page-Titles">
Being a Subsciber!</span></h1>
<h3><span class="X-Large-Text">Unfortunately, your subscription has expired,<br />
and you'll need to renew your subscription to enjoy <br />
another full year of uninterupted access to the Cookbook</span>.</h3>
<h2><span class="X-Large-Text">Great News! </span></h2>

<h3><span class="X-Large-Text">If you renew now with PayPal, <br />
</span><span class="X-Large-Text"> <br />
your special annual renewal rate is only <br />
</span></h3>
<h2><span class="X-Large-Text">$15.00 US!</span></h2>
<h3><span class="X-Large-Text">which is $40% off the current subscription rate. <br />
</span></h3>
<table width="75%" border="0" cellpadding="15">
<tr>
<td valign="top"><div align="center"> <img src="images/paypal-logo.jpg" alt="" height="99" width="100" border="0"
/></div></td>
<td valign="top"><p align="center"> </p>
<div align="center"> <a class="special" href="https://www.paypal.com/cgi-bin/webscr?amount=15.00
&amp;item_number=Your_Item_Number
&amp;item_name=Your Renewal
&amp;business=payments@your_site.com
&amp;cpp_header_image=http://www.your_site.com/images/CMSBPP.png
&amp;currency_code=USD&amp;lc=US&amp;add=1
&amp;cmd=_cart&amp;no_shipping=0
&amp;return=http://www.your_site.com/linklokipnret.php
&amp;notify_url=http://www.your_site.com/linklokipn.php
&amp;no_note=1&amp;bn value=PP-ShopCartBF&amp;">
<img src="/images/btn_buynowCC_LG.gif" /></a><br />
</div></td>
</tr> <tr>
<td align="center" valign="middle"><span class="Large-Text">Renew you subscription now, for only <s>$24.95</s>
</span><span class="X-Large-Text">$15.00</span></td>
</tr>
</table>


Linklok implementation proved to be easy.

The URL for Linklok is:

http://www.vibralogix.com/linklokipn/

If you should decide to purchase linklok, or any other Vibralogic programs, I'd appreciate your using my affiliate link:

http://www.shareasale.com/r.cfm?B=12671&U=520135&M=3826

Although the documentation outlines many ways to customize your installation, for a basic implementation there are only
two files required for linklok to operate: linklokipn.php and linklokipnret.php

linklokipn.php is the only file that you’ll need to customize, and all the user defined parameters appear at the top
of the file:

The information included in the $Products variable is: "unique_product_id,product name,product currency and minimum
price accepted,path to your hidden directory and the URL of your "your_update_page.php" page, leave this one set to
“0",the number of minutes until the link sent to the purchaser expires";


$Products[] = "Your_Product_ID,Your Product name,USD=99.95,soyerveortmvobd/your_update_page.php,0,1440";

// Setup admin and security variables
$LinklokURL = "http://www.your_site.com/linklokipn.php"; // URL of the linlok.php page on your site
$PaypalEmail = "payments@your_site.com"; // PRIMARY Paypal email address
$SellerCompany = "Your Company"; // Your company name
$SellerEmail = "info@your_site.com"; // Your email address for order inquiries
$SellerURL = "http://www.your_site.com"; // Your website URL
$LinkKey = "orange23"; // Encryption key for download links
$PDTtoken="12876Vdwerwrol_dmYMHfewrwurjdE3QsupkkvTo4Fv39-7y"; // Auto Return PDT token from paypal-profile-website
payment preferences

$DelayEchecks = "Y"; // Set to Y to delay eCheck orders until cleared.
$EmailTemplate = ""; // Optional Email Template in either .txt or .html format
$DownloadTemplate = ""; // Optional download page template
$ErrorTemplate = ""; // Optional Error page template
$CopyEmail = "any_email@your_provider.net"; // Receive copy of order emails.
email address or ""
$ManualPassword = "kookamonga"; // Password for manual order entry. "" to disable
$HTMLEmail = "Y"; // Set to Y to use HTML formatted emails or N to send in
plain-text
$Txnid = ""; // Optional to stop possible multiple calls from IPN
$WarningTemplate = ""; // Check payment warning email template
$WarningTemplatePage= ""; // Check payment warning thankyou page template


UPDATING THE MEMBER’S RECORD (The soyerveortmvobd/your_update_page.php file)

Current versions of CMSB include password encryption, so matching an encrypted password with a submitted plain text
password is not possible. Fortunately, it is possible to use the built in login functionality to make the hidden update
function pretty straight forward:


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/path_to_your_server/','','../','../../','../../../');
foreach (
$dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!
function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
if (!@
$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can
access this page."); }
if (!
$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>
<?php
mysqlStrictMode(false);
mysql_query("UPDATE `{$TABLE_PREFIX}accounts`
SET expiresDate = NOW() + INTERVAL 1 YEAR
WHERE num = '".mysql_escape( $CURRENT_USER['num'] )."'")
or die(
"MySQL Error:\n". htmlspecialchars(mysql_error()) . "\n");
$userNum = mysql_insert_id();
// redirect after a successful update
header("Location: http://www.your_site.com/your_update_success_page.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="noindex,nofollow" />
</head>
<body>
</body>
</html>


AUTOMATING THE RENEWAL PROCESS WITH AUTOMATIC E-MAILS
Although my specific application did not require notification prior to membership expiration, you might want to send out
mailings a few weeks before a member’s account expires.

I did not implement this, but here are some preliminary manual steps you can use:

GENERATING EMAIL LISTS OF EXPIRING MEMBERS
Here’s the code for the top of your page:


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/server_path_to_your_root_directory/','','../','../../','../../../');
foreach (
$dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!
function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => " '{$CURRENT_USER['isAdmin']}' ",
));

?>


The code: 'where' => " '{$CURRENT_USER['isAdmin']}' ", prevents anyone who is not an admin from generating an email
list.

And in the body of the page:
The trick is to only list emails for those non-special members whose accounts have expired.
Using an if statement with a further modification of Dave’s Expired Account checking code solved that challenge:

<hr />
<div align="left">
?php foreach ($accountsRecords as $record): ?>
<?php $isMembershipExpired = strtotime ($record['expiresDate']) <= time(); ?>
<?php if ($record['special_membership'] == '0' && $isMembershipExpired == '1'): ?>
<span class="your_class"><?php echo $record['email'] ?>;&nbsp;</span>
<?php endif ?>
<?php endforeach ?>
</div>
<hr />


If you want to send emails to different lists of expired members here are some approaches:

GENERATE A LIST OF MEMBERS WHOSE ACCOUNTS HAVE RECENTLY EXPIRED
You can compare the updatedDate value with the current date and only generate a list of those member records that have
expired and who fall between the two dates.

GENERATE A LIST OF EXPIRED MEMBERS THAT WERE SENT A LETTER AND DIDN’T RENEW
Here you’ll need a field that contains the last date that you sent out a letter so you can compare that date with
those members whose accounts expired before that date. (Yu can also generate a list of those who expired after that
date.) The Last Mailing Date can be in a single record editor if you have one.

If your service provider limits the amount of email recipients that can be included in one email, you can break your
lists down into groups using the information in the recipe “BREAKING E-MAIL LISTS INTO GROUPS OF "N" ADDRESSES EACH”



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service