Redeemer

Redeemer is an ExpressionEngine module for managing coupon codes. You can create them from the control panel, and even let users create their own codes based on an action they perform. On Twitter I mentioned I was building this and I got a couple of responses along the lines of "why don't you just use EE's built in Weblog to create coupons?" I could have done this, and thought about it, but you can only create a basic coupon code system with EE's built in features. You won't be able to easily, if at all, manage the number of times a coupon can be redeemed before it is invalid, limit by the user's IP address, or member ID. You also won't be able to generate new codes in the templates, and creating randomized codes would still require an extension or plug-in.

You can use the template tags with Ajax calls to validate a code without a page refresh, but if you use the URL Redirect feature will not work if you're calling the exp:redeemer:validate method in an Ajax call for obvious reasons.

This is my first full featured module for EE. It is LG Addon Updater and should be MSM compatible as well. The exp:redeemer:generate method has not been used in a production environment. I added this after the original module was complete for a client project, so don't hold it against me if it isn't fully fleshed out.

Here is a demo with an Ajax request to validate a code, and another using the URL redirections.

For further information please go to the forum post over at ExpressionEngine.com

Requirements

  • ExpressionEngine 1.6.8 (this module uses the new view files)
  • jQuery for the Control Panel Extension (comes with EE, just enable it)

Compatibility

  • LG Add-on Updater, Multi-Site Manager

Tags

{exp:redeemer:validate} {/exp:redeemer:validate}

Parameters

name="offer_code" (required)

This is the POST or GET name used in submitting a code

redeem="n"

If "y" or "yes", then the submitted code will be instantly redeemed and tallied. If you wish do to any further template or page rendering after submitting the code, do not define this parameter and use the {exp:redeemer:redeem} method elsewhere.

limit_by="ip" or "member"

You can limit the number of code redemptions based on the member's ID, if they're logged in, or by their IP address.

limit_ip="1"

If limit_by="ip", set the number of times a code can be redeemed under the same IP address.

limit_member="1"

If limit_by="member", set the number of times a code can be redeemed under the same member ID.

save_in_session="y" or "n"

By default, all submitted codes are saved in the session. If you are not using {exp:redeemer:redeem} method, or are using the redeem="y" parameter in the {exp:redeemer:validate} method, then you can set this to "n".

Variables

{valid}

Boolean value to be used in a conditional. If the submitted code is considered valid, then this will return true.

{invalid}

Boolean value to be used in a conditional. If the submitted code is considered invalid, then this will return false.

{invalid_message}

If a default invalid message is defined in the settings, this variable will print out the message.

{valid_message}

If a default valid message is defined in the settings, this variable will print out the message.

{detailed_message}

This will print a detailed message explaining why a code was not considered valid. These messages are defined in the language file.

{entered_code}

This will print the code the user entered, regardless if it is valid or invalid.

Usage

{exp:redeemer:validate name="offer_code"}
    You entered: {entered_code}
    {if valid} 
        Do whatever you want! 
    {/if}
    {if invalid} 
        Show the default {invalid_message}, and do something else 
    {/if}
{/exp:redeemer:validate}

{exp:redeemer:redeem}

This tag will take the code saved in the session and redeem it. Once this is done, the code limit is adjusted. If you used the limit_by, limit_ip, or limit_member parameters in {exp:redeemer:validate} you will need to enter the same parameters for the redeem method as well.

{exp:redeemer:generate}{/exp:redeemer:generate}

Parameters

start_date="yyyy-mm-dd"

If no start date is defined, the code will be instantly redeemable.

end_date="yyyy-mm-dd"

If no end date is defined, the code will be redeemable until it reaches a limit, if defined, or until it is closed.

pattern="[AN*4]-[AN*4]"

The pattern can be changed in the settings, or by defining a new pattern in the parameter. The default pattern will create two 4 digit alpha-neumeric strings separated by a dash. An example custom pattern can be [A*3]-[N*5]-[AN*8].

title="Auto Generated: [code value]"

If title is not defined, the title created is "Auto Generated: [code value]"

description=""

Lets you provide a longer description for the code. This description is not available on the front-end, it is only available in the control panel for your reference.

valid_url=""

Define a URL to redirect to when this code is validated.

valid_url_default="n" or "y"

If you want this code to use the default valid URL defined in the settings when validated.

invalid_url_default="n" or "y"

If you want this code to use the default invalid URL defined in the settings when validated.

redemption_limit="1"

The number of times this code is allowed to be redeemed.

status="open"

The default status of the code when it is created. If you set it to "closed", then the only way to set it as "open" is in the control panel.

Variables

{code}

This prints out the generated code for the user to see.

Usage

{exp:redeemer:generate start_date="2009-12-09" end_date="2009-12-10"}
    Your code is: {code}
{/exp:redeemer:generate}