JSMA vouchers

Overview

The JSMA vouchers allows access of vouchers (voucher campaigns) used in carts and orders.

What can JSMA vouchers do for me?

With the JSMA vouchers you can create and find vouchers for carts and orders on your shopping website.

You can use it to dynamically generate voucher campains which, in combination with JSMA voucher, allows you to synchronize IKONA with an external voucher system.

Index

Methods

The JSMA vouchers provides the following methods:

voucher vouchers.create({attributes})

Creates a JSMA voucher campain with the parameters given in the attributes object.

Example

...
vouchers.create({'validFrom' : date.getTime(), 'validUntil' : dateInOneWeek.getTime(), 'discountType' : 'absolute', 'affectShipping' : false, 'value' : 500});
...

Parameter attributes (required)

The attributes objects can take in the following keys:

string title (optional)

A title for your voucher campain.

int minValue (optional)

Minimal value a voucher can be redeemed for. Must be a positive integer in cents.

int validFrom

Time in milliseconds from when a voucher will be valid from.

int validUntil

Time in milliseconds up to when a voucher will be valid until.

int value

Value of the voucher. Must be a positive integer in cents for absolute vouchers or a percentage for relative vouchers.


voucher vouchers.findById(id)

Returns a JSMA voucher for given parameter id.

Avoid usage of findById

Ids change whenever a package is reimported. So please avoid using ids whenever possible. Also delivering contents to users by id might make it possible for users to flip through the files (and by that see contents of others possibly) by changing the ids in requests.

Example

CartApi.prototype.doAddVoucher = function (id) 
{
  [...]

  var voucherCampaign = vouchers.findById(id); 

  if (!voucherCampaign) {
   throw new Error("ERROR_VOUCHER_FOR_ID_NOT_FOUND"); }

  [...]
}

Parameter id:int (required)


voucher vouchers.findByName(name)

Returns a JSMA voucher for given parameter name.

Example

CartApi.prototype.doAddVoucher = function (token) 
{
  [...]

  var voucherCampaign = vouchers.findByName("Gutschein");
              
  voucherCampaign.addToken(voucherCode);

  [...]
}

Parameter name:string (required)

voucher vouchers.findByToken(token)

Returns a JSMA voucher for given parameter token.

Example

CartApi.prototype.doAddVoucher = function (token)
{
  [...]

  var voucherCampaign = vouchers.findByToken(token);
    
  if (!voucherCampaign) {
    throw new Error("ERROR_VOUCHER_COULD_NOT_BE_ADDED");
  }

  [...]
}

Parameter token:string (required)