Table of Contents

Class VoucherService

Namespace
Dynamicweb.Ecommerce.Orders.Vouchers
Assembly
Dynamicweb.Ecommerce.dll

Manages vouchers: reading them, generating new codes for a voucher list, validating a code before it is accepted on an order, and marking it as used once the order is placed.

public class VoucherService
Inheritance
VoucherService
Inherited Members

Methods

CheckVouchers(IEnumerable<string>)

Gets the subset of the given codes that exist as vouchers.

public virtual IEnumerable<string> CheckVouchers(IEnumerable<string> vouchers)

Parameters

vouchers IEnumerable<string>

The voucher codes to look for.

Returns

IEnumerable<string>

Delete(Voucher)

Deletes a voucher.

public virtual void Delete(Voucher voucher)

Parameters

voucher Voucher

The voucher to delete.

GenerateVoucher(int, int)

Generates a single voucher code for a voucher list.

public virtual string GenerateVoucher(int listId, int numberOfSymbols = 8)

Parameters

listId int

The voucher list to add the code to.

numberOfSymbols int

The length of the generated code.

Returns

string

GenerateVouchers(int, int, int)

Generates voucher codes for a voucher list. Each code is unique among the existing vouchers.

public virtual IEnumerable<string> GenerateVouchers(int number, int listId, int numberOfSymbols = 8)

Parameters

number int

How many codes to generate.

listId int

The voucher list to add the codes to.

numberOfSymbols int

The length of each generated code.

Returns

IEnumerable<string>

GetAllVouchers()

Gets every voucher, across all voucher lists.

public virtual IEnumerable<Voucher> GetAllVouchers()

Returns

IEnumerable<Voucher>

GetAllVouchersForList(int)

Gets the vouchers belonging to a voucher list.

public virtual IEnumerable<Voucher> GetAllVouchersForList(int listId)

Parameters

listId int

The voucher list identifier.

Returns

IEnumerable<Voucher>

GetVoucherByCode(string)

Gets a voucher by its code.

public virtual Voucher? GetVoucherByCode(string voucherCode)

Parameters

voucherCode string

The voucher code.

Returns

Voucher

The voucher, or null when no voucher has that code.

GetVoucherByCode(string, int)

Gets a voucher by its code within a specific voucher list.

public virtual Voucher? GetVoucherByCode(string voucherCode, int listId)

Parameters

voucherCode string

The voucher code.

listId int

The voucher list identifier.

Returns

Voucher

The voucher, or null when that list has no voucher with that code.

GetVoucherById(int)

Gets a voucher by its identifier.

public virtual Voucher? GetVoucherById(int id)

Parameters

id int

The voucher identifier.

Returns

Voucher

The voucher, or null when no voucher has that identifier.

GetVoucherCodesFromString(string)

Splits a voucher code string into the individual codes it contains.

public virtual IEnumerable<string> GetVoucherCodesFromString(string voucherCodesString)

Parameters

voucherCodesString string

One or more voucher codes, separated by comma, semicolon or space.

Returns

IEnumerable<string>

The codes, or an empty sequence when the string holds none.

GetVoucherListUsings(IEnumerable<VoucherList>)

Gets how many orders have used vouchers from each of the given voucher lists.

public virtual IEnumerable<VoucherListUsing> GetVoucherListUsings(IEnumerable<VoucherList> voucherLists)

Parameters

voucherLists IEnumerable<VoucherList>

The voucher lists to count usage for.

Returns

IEnumerable<VoucherListUsing>

HasAnyVoucherCode(VoucherList, IEnumerable<string>, bool, bool)

Gets a value indicating whether any of the given codes belongs to the given voucher list.

public virtual bool HasAnyVoucherCode(VoucherList list, IEnumerable<string> codes, bool searchInActiveListsOnly, bool checkUnusedCodesOnly)

Parameters

list VoucherList

The voucher list to search. Returns false when null.

codes IEnumerable<string>

The voucher codes to look for.

searchInActiveListsOnly bool

When true, an inactive list never matches.

checkUnusedCodesOnly bool

When true, an already used voucher never matches.

Returns

bool

IsValidVoucher(string)

Validates a voucher code with comprehensive checks including voucher list status, discount matrix, and loyalty rewards.

public virtual bool IsValidVoucher(string voucherCode)

Parameters

voucherCode string

The voucher code to validate

Returns

bool

True if the voucher is valid and can be used; otherwise, false

IsValidVoucher(string, int)

Validates a voucher code with comprehensive checks including voucher list status, discount matrix, and loyalty rewards.

public virtual bool IsValidVoucher(string voucherCode, int listId)

Parameters

voucherCode string

The voucher code to validate

listId int

The voucher list ID

Returns

bool

True if the voucher is valid and can be used; otherwise, false

MarkVoucherAsUsed(string, string)

Marks the vouchers in a code string as used by an order. Only unused vouchers belonging to an active voucher list are marked, and nothing happens when the order does not accept vouchers.

public virtual void MarkVoucherAsUsed(string voucherCode, string orderId)

Parameters

voucherCode string

One or more voucher codes, separated by comma, semicolon or space.

orderId string

The identifier of the order using the vouchers.

Save(Voucher)

Creates or updates a voucher.

public virtual void Save(Voucher voucher)

Parameters

voucher Voucher

The voucher to save.

UpdateVouchersOrderId(string, string)

Moves the unused vouchers reserved for one order over to another order.

public virtual void UpdateVouchersOrderId(string orderId, string newOrderId)

Parameters

orderId string

The order the vouchers are currently reserved for.

newOrderId string

The order to move them to.

UpdateVouchersStatus(int, string)

Sets the status on every voucher in a list that does not have one yet.

public virtual void UpdateVouchersStatus(int listId, string status)

Parameters

listId int

The voucher list identifier.

status string

The status to set.

To top