Voucherify Showcase Cart - "Cart.js"

Read Documentation | API Reference | Help Center

This example shows how you can make Voucherify API work with a simple cart checkout example. You can see for yourself that a simple integration with voucherify API gives you easy access to a multitude of validation strategies that can be managed and modified from voucherify dashboard without or with very little impact on code.

You can browse the code (and quickly spin up your own rendition of this example) here and see a working live example at https://voucherify-cart.glitch.me/.

In the example you will find usages of a wide range of voucherify endpoints and functionalities. The server.js uses redemptions, vouchers, products and customers namespaces of voucherify client. This is more convenient than hitting the API endpoints directly, the client does all the groundwork of constructing REST requests for you.

Useful links

How to use this repository


Setup

Sign up to get your auth keys. The authorization keys should be set up in a .env file in the root directory, as follows (you can copy env_template to .env file):

# Application ID from your voucherify Project Settings
APPLICATION_ID=''
# Application Secret Key from your voucherify Project Settings
CLIENT_SECRET_KEY=''

After this initial setup you should run node ./setup.js to feed your voucherify account with data necessary for this example to work. This will:

  • Create 12 campaigns with different settings
  • Add 4 products
  • Setup a customer segment for customers from Germany (you can read more about customer segments here)
  • Setup validation rules for 5 different campaigns which will be used to validate voucher redemptions (read more about validation rules here)

AND DONE! You are ready to run npm start or open the live glitch and play around.

Done playing with the example?

When you are done with the example and want a clean voucherify experience, just run node ./cleanup.js. This will remove the vast majority of the data we put there. With some exceptions:

  • customers tracked in this example won't be removed (if you wish to do it yourself, just filter by metadata {from: 'voucherify-showcase'} - the example adds this to every customer)
  • the created segment will be removed based on ./.data/segments.json file, so if you misplace or remove it, segments will stay on your voucherify account

After this operation you might need to clean your browser local storage if you wish to use the example again.