Coupon Code Generator

I’m trying to create a coupon code system for my app. I want every user upon subscribing (premium users) to receive a unique code starting with SJ-XXXX (X is a placeholder for a letter) and every code has to be different and unique to the user. I can do it manually but in the future when we need to scale we would need to make it automatic. Is there anyway to to this? The users don’t need to know what the code is. Only I need to know what it is and be able to see it. The coupon code is currently under my user type.

Hopefully, this will give you a start.

You can create a workflow that will generate a random string for your code as its first step, kind of like this:

You’d probably want to create a new row in a table like user_coupons rather than update the user row itself.

Once the code above is done, do a search for user_coupons:count where the user is the user you’re working with and the code is the code you just generated.

  • If the count is 1, you’re done since that means it’s unique for that user.
  • If it’s > 1, then the code has already been used for this user, so delete the user_coupon row you just added and re-schedule the first workflow.

Hope this helps.

1 Like

Sorry, I just re-read your requirements.

Since you want the code to be unique for the user, you will have to also keep track of the past coupons you’ve generated so you can verify that the new coupon code is unique for that user.