Owns the voucher domain: creating voucher types and vouchers, allocating vouchers to profiles, redeeming them and tracking their status history. Reached from server-side JS as the registered service "voucherManager". Most operations run against a single voucher (found by ID or keyword) or against a voucher type, and are exposed either directly or through the fluent VoucherTypeAllocationBuilder, VoucherAllocationBuilder, VoucherTypeBuilder and VoucherStatusBuilder inner classes for building up allocation, creation and status-change requests.

Group: Managers


Properties

PropertyReturnsDescription
allVoucherExpiryRuleTypesList<VoucherExpiryRuleType>All available voucher expiration date calculators: the account-specific JsVoucherExpiryRuleType instances configured in that account's Queries repo (mirroring PointsManager.getAllPointsExpiryRuleTypes()). No app-registered-builder tier - unlike points expiry rules, this is intended to be custom per-account configuration.
allVoucherTypesList<VoucherType>All voucher types belonging to the current tenant organisation.
voucherStatusCodesMap<String,String>Returns all defined voucher status codes and their human-readable descriptions.

Methods

getAllVoucherExpiryRuleTypes() · voucherExpiryRuleType(String id) · voucherExpiryRuleParams(VoucherType voucherType) · allocate(VoucherType vt, int num, String allocatedTo, Profile curUser, Date now, Organisation org, String notes) · allocate(VoucherType vt, int num, Profile allocatedTo, Profile curUser, Date now, Organisation org, String notes) · customFieldNames(VoucherType voucherType) · getAllVoucherTypes() · findVoucherType(String name) · findVoucher(String voucherId, VoucherType allowedType) · findVouchersForUser(Profile profile, int maxResult, boolean noBlankStatus, Website website) · findVouchersByIds(List<Long> voucherIds, VoucherType voucherType) · findVouchersByKeywords(String voucherQuery, VoucherType voucherType, boolean noBlankStatus, Profile profile, Website website) · findRedeemerOrgs(Profile curUser, Website website) · canRedeem(Voucher voucher) · redeem(Voucher voucher, Profile redeemer, String notes, Organisation redeemerOrg) · fireVoucherChangeEvent(Voucher voucher, String oldStatus) · findVoucherById(Long id) · toVoucherBean(Voucher voucher) · createVouchers(VoucherType voucherType, Long numVouchers) · allocate(VoucherAllocationBuilder b) · findAvailableVoucher(VoucherType vt) · findAvailableVoucher(VoucherType vt, List<Long> excludedVoucherIds) · allocate(Voucher voucher, Profile profile, String allocatedToId, String notes, Organisation redeemerOrg) · generateIdFromTemplate(String voucherIdTemplate) · randomHex(int numDigits) · randomInt(int numDigits) · statusText(String status) · newVoucherAllocationBuilder(VoucherType type) · saveVoucherExtraFieldValues(Voucher voucher, Map<String,String> extraFieldValues) · findVoucherExtraFieldValues(Voucher voucher) · findVoucherTypeExtraFields(VoucherType voucherType) · deleteVoucher(Voucher voucher, Profile profile) · newVoucherTypeBuilder() · newVoucherTypeBuilder(VoucherType voucherType) · getVoucherStatusCodes() · newVoucherStatusBuilder(Voucher voucher)

getAllVoucherExpiryRuleTypes()

Returns: List<VoucherExpiryRuleType>

All available voucher expiration date calculators: the account-specific JsVoucherExpiryRuleType instances configured in that account's Queries repo (mirroring PointsManager.getAllPointsExpiryRuleTypes()). No app-registered-builder tier - unlike points expiry rules, this is intended to be custom per-account configuration.

voucherExpiryRuleType(String id)

Returns: VoucherExpiryRuleType

Looks up one of this account's voucher expiry rule types by ID.

ParameterDescription
idthe voucher expiry rule type id to look up

voucherExpiryRuleParams(VoucherType voucherType)

Returns: Map<String,String>

Parses the voucher type's configured expiration calculator parameters string into a map, for passing to its expiry rule type's calculator.

ParameterDescription
voucherTypethe voucher type to read the expiration calculator config from

allocate(VoucherType vt, int num, String allocatedTo, Profile curUser, Date now, Organisation org, String notes)

Returns: List<Voucher>

Allocates vouchers of the given type without setting the voucher's allocatedTo profile. This method assigns the given identifier to only the allocatedToId property of each allocated voucher.

ParameterDescription
vtthe voucher type to allocate from
numthe number of vouchers to allocate
allocatedTothe identifier of the recipient, stored as allocatedToId
curUserthe profile performing the allocation
nowthe date the allocation is happening
orgthe organisation the vouchers are allocated for redemption at
notesnotes to record against each allocation

allocate(VoucherType vt, int num, Profile allocatedTo, Profile curUser, Date now, Organisation org, String notes)

Returns: List<Voucher>

Allocates vouchers of the given type to a known profile. This method assigns the value to both the allocatedToId and allocatedTo properties of each allocated voucher.

ParameterDescription
vtthe voucher type to allocate from
numthe number of vouchers to allocate
allocatedTothe profile to allocate the vouchers to
curUserthe profile performing the allocation
nowthe date the allocation is happening
orgthe organisation the vouchers are allocated for redemption at
notesnotes to record against each allocation

customFieldNames(VoucherType voucherType)

Returns: List<String>

Returns an ordered list of the names of the custom fields configured on the given voucher type's fieldset.

ParameterDescription
voucherTypethe voucher type to read custom field names from

getAllVoucherTypes()

Returns: List<VoucherType>

All voucher types belonging to the current tenant organisation.

findVoucherType(String name)

Returns: VoucherType

Looks up a voucher type belonging to the current tenant organisation by its name.

ParameterDescription
namethe voucher type's name

findVoucher(String voucherId, VoucherType allowedType)

Returns: Voucher

Looks up a voucher by its user-facing ID, restricted to a specific voucher type.

ParameterDescription
voucherIdthe voucher's user-facing ID
allowedTypethe voucher type the voucher must belong to

findVouchersForUser(Profile profile, int maxResult, boolean noBlankStatus, Website website)

Returns: List<Voucher>

Returns the vouchers available to a profile, based on the redeemer organisations it belongs to for the given website.

ParameterDescription
profilethe profile to find vouchers for
maxResultthe maximum number of vouchers to return
noBlankStatusif true, exclude all vouchers with null or empty status
websitethe website whose redeemer role memberships determine the profile's organisations

findVouchersByIds(List<Long> voucherIds, VoucherType voucherType)

Returns: List<Voucher>

Returns the vouchers of the given type matching a list of voucher IDs.

ParameterDescription
voucherIdsthe internal IDs of the vouchers to find
voucherTypethe voucher type the vouchers must belong to

findVouchersByKeywords(String voucherQuery, VoucherType voucherType, boolean noBlankStatus, Profile profile, Website website)

Returns: List<Voucher>

Searches for vouchers of a given type matching a keyword query, restricted to the organisations the profile can redeem vouchers at on the given website.

ParameterDescription
voucherQuerythe search keywords
voucherTypethe voucher type to search within
noBlankStatusif true, exclude all vouchers with null or empty status
profilethe profile whose redeemer organisations scope the search
websitethe website whose redeemer role memberships determine the profile's organisations

findRedeemerOrgs(Profile curUser, Website website)

Returns: List<Organisation>

Finds the organisations at which the given profile holds the voucher redeemer role for the given website, resolving each membership to its effective within-organisation.

ParameterDescription
curUserthe profile to look up redeemer memberships for, or null
websitethe website the redeemer role is checked against

canRedeem(Voucher voucher)

Returns: boolean

Checks whether a voucher is currently available for redemption, i.e. not already redeemed, expired or deleted.

ParameterDescription
voucherthe voucher to check

redeem(Voucher voucher, Profile redeemer, String notes, Organisation redeemerOrg)

Returns: boolean

Redeems a voucher: asks registered apps whether the redemption should be allowed, then changes the voucher's status to redeemed and fires the voucher change event. Throws if any app objects to the redemption.

ParameterDescription
voucherthe voucher to redeem
redeemerthe profile redeeming the voucher
notesnotes to record against the redemption
redeemerOrgthe organisation the voucher is being redeemed at

fireVoucherChangeEvent(Voucher voucher, String oldStatus)

Returns: void

Fires the voucher-updated index event and, if the voucher's status actually changed, a voucher funnel event (issued or state-changed as appropriate). Called after any operation that changes a voucher's status.

ParameterDescription
voucherthe voucher whose status may have changed
oldStatusthe voucher's status before the change

findVoucherById(Long id)

Returns: Voucher

Looks up a voucher belonging to the current tenant organisation by its internal ID.

ParameterDescription
idthe voucher's internal ID, or null

toVoucherBean(Voucher voucher)

Returns: VoucherBean

Converts a voucher entity to its bean representation for use in templates.

ParameterDescription
voucherthe voucher to convert, or null

createVouchers(VoucherType voucherType, Long numVouchers)

Returns: List<Voucher>

Creates a batch of new, unallocated vouchers of the given type, generating a unique voucher ID for each one.

ParameterDescription
voucherTypethe voucher type to create vouchers for
numVouchershow many vouchers to create

allocate(VoucherAllocationBuilder b)

Returns: Voucher

Executes an allocation request built with newVoucherAllocationBuilder(): allocates the builder's specific voucher if one was set, otherwise finds and allocates an available voucher of the builder's voucher type.

ParameterDescription
bthe populated builder describing the allocation

findAvailableVoucher(VoucherType vt)

Returns: Voucher

Finds a single unallocated voucher of the given type, i.e. one with no status set yet.

ParameterDescription
vtthe voucher type to search

findAvailableVoucher(VoucherType vt, List<Long> excludedVoucherIds)

Returns: Voucher

Finds a single unallocated voucher of the given type, i.e. one with no status set yet, ignoring any voucher whose ID is in excludedVoucherIds.

ParameterDescription
vtthe voucher type to search
excludedVoucherIdsinternal IDs of vouchers to exclude from the search

allocate(Voucher voucher, Profile profile, String allocatedToId, String notes, Organisation redeemerOrg)

Returns: Voucher

Allocates a specific voucher to a profile, changing its status to allocated.

ParameterDescription
voucherthe voucher to allocate
profilethe profile to allocate the voucher to
allocatedToIdthe identifier to record as the voucher's allocatedToId
notesnotes to record against the allocation
redeemerOrgthe organisation the voucher is allocated for redemption at

generateIdFromTemplate(String voucherIdTemplate)

Returns: String

Evaluates an MVEL voucher ID template expression against this manager, to produce a voucher ID.

ParameterDescription
voucherIdTemplatethe MVEL template expression to evaluate

randomHex(int numDigits)

Returns: String

Generates a random hexadecimal string of exactly the requested length.

ParameterDescription
numDigitsthe required length of the returned string

randomInt(int numDigits)

Returns: String

Generates a random numeric string of exactly the requested length, left-padded with zeros.

ParameterDescription
numDigitsthe required length of the returned string

statusText(String status)

Returns: String

Converts a voucher status code to human-friendly display text.

ParameterDescription
statusthe status code to convert

newVoucherAllocationBuilder(VoucherType type)

Returns: VoucherAllocationBuilder

Creates a new, empty allocation request builder for the given voucher type.

ParameterDescription
typethe voucher type to allocate from

saveVoucherExtraFieldValues(Voucher voucher, Map<String,String> extraFieldValues)

Returns: void

Saves values for a voucher's extra (custom) fields, replacing its field set with a new one carrying the merged values, and fires the voucher-updated event if anything changed.

ParameterDescription
voucherthe voucher to update
extraFieldValuesa map of extra field name to new value

findVoucherExtraFieldValues(Voucher voucher)

Returns: Map<String,String>

Returns all extra (custom) field values currently set on the voucher.

ParameterDescription
voucherthe voucher to read extra field values from

findVoucherTypeExtraFields(VoucherType voucherType)

Returns: List<ExtraField>

Returns the extra (custom) field definitions configured on the voucher type's fieldset, sorted by their ordering, falling back to name order for fields without an ordering set.

ParameterDescription
voucherTypethe voucher type to read extra field definitions from

deleteVoucher(Voucher voucher, Profile profile)

Returns: void

Soft-deletes a voucher and fires the voucher-deleted index event.

ParameterDescription
voucherthe voucher to delete
profilethe profile performing the deletion, must not be null

newVoucherTypeBuilder()

Returns: VoucherTypeBuilder

Creates a new, empty voucher type builder for creating or updating a voucher type.

newVoucherTypeBuilder(VoucherType voucherType)

Returns: VoucherTypeAllocationBuilder

Creates a new allocation request builder for the given voucher type.

ParameterDescription
voucherTypethe voucher type to allocate from

getVoucherStatusCodes()

Returns: Map<String,String>

Returns all defined voucher status codes and their human-readable descriptions.

newVoucherStatusBuilder(Voucher voucher)

Returns: VoucherStatusBuilder

Creates a new status-change builder for the given voucher.

ParameterDescription
voucherthe voucher to build a status change for
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.