Testing whether a Coupon Code (Promotion Code) is valid before applying it to a basket.

Coupon Codes come in a variety of flavors:
  1. Private
  2. Public
  3. Restricted
We can use the PromoCodeDefinitionManager and the LookupPromoCodeDefinitionByCode(string promoCode) function to test whether a Promotion Code exists (!= null).

However; just because a promotion code exists does *not* mean it’s valid.

For example:
A Coupon Code can have: a limit number of uses, an associated user profile, or both.

A valid Coupon Code with a limited number of uses and an associated user profile would have to be validated against something like the following:

If Promo Code exists
If Promo Code has uses remaining
If User Profile EQUAL TO the Promo Code mapped current User Profile
Validate True

As far as I can see this functionality exists in the pipeline, but is not exposed through the APIs.

Basically I want to display an error message for each of the following cases:
  • Promotion code is in invalid format
  • Promotion code does not exist
  • Promotion code has expired
  • Promotion code invalid for products purchased
Any suggestions



Answer this question

Testing whether a Coupon Code (Promotion Code) is valid before applying it to a basket.

  • Whoisit

    Hi Adam,

    Just to clarify things for anyone else reading out there as these questions come up from time to time:

    Running the basket pipeline is the only way to validate promo codes. You then can check your OrderForm.PromoCodeRecords collection to see the status of the codes. If they are valid, if they have reached a use limit, if they apply to your basket, etc.

    A specific promo code does not expire. A promo code can be used by several different discounts, and it is the discount which has an expiration date.

    To answer your specific question if the promo code is invalid for the products purchased, that is actually the PromoCodeRecord.PromoApplied == False you called out above.

    PromoCodeRecord.PromoCodeStatus will tell you if you are the right user for the code, the code has been used too many times, it's an invalid code, or if it's fine. See http://msdn.microsoft.com/library/default.asp url=/library/en-us/sdkmref/html/T_Microsoft_CommerceServer_Orders_PromoCodeState.asp

    Hope this helps,
    David


  • LarkinAtTheBar

    Thanks David,

    Here are a couple more helpful links related to Coupon Codes / Promotion Codes:


  • bankit

    In response to my own post:

    If PromoCode == Empty
    Throw “promo code is invalid or does not exist”

    Add the Promotional Code to the basket
    Run the basket related pipelines
    Save the basket

    Enumerate through the PromoCodeRecordCollection
    If PromoCodeRecord.PromoApplied == False
    Throw “promo code has expired error”

    I have yet to figure out how to test if the promo code is invalid for products purchased.

    Links I found useful:


  • Testing whether a Coupon Code (Promotion Code) is valid before applying it to a basket.