This should be very similar to a coupon type system in place for the cart. We have some documentation for implementing a coupon system on the eCart support page in the Solution Recipes, here is a link:
ecart/
Take a look at the 'creating a coupon system' Solution Recipe, this will give you a good idea of how this type of thing is implemented. Please give this a try and let us know if you have any questions about any part of it.