Introduction

The module’s integration allows you to

  • generate vouchers,

  • send them to your loyal customers and

  • let them buy products and services with a discount.

Business

Development

Core

Entity Definitions

The definitions in this module have id discriminators in the range 310-320.

VoucherEntityDefinition

The VoucherEntityDefinition extends the DiscountEntityDefinition. The DiscountEntityDefinition, on the other hand, extends the AbstractEntityDefinition, the AbstractActivatableEntityDefinition, the AbstractExpensableEntityDefinition, the AbstractCatalogableEntityDefinition and AbstractPurchasableEntityDefinition. See the diagram below:

asciidoctor diagram voucher entity definition

Via the respective getter-setter pairs, the following information can be retrieved/stored in the database:

Property Description

freeShipping

a straight-forward boolean value, identifying if free shipping is included in the voucher or not

priority

information about the priority of the voucher

site

which site the voucher is applicable for

asciidoctor diagram VoucherInvalidationEntityDefinition

Via the respective getter-setter pairs, the following information can be retrieved/stored in the database:

Property Description

status

the status of the current voucher

voucher

the voucher this voucher invalidation is

Spring Data JPA Repositories

VoucherRepository

The VoucherRepository is the corresponding Spring Data JPA repository for the VoucherEntityDefinition.

The extended interfaces are ActivatableRepository and BaseEntityRepository. See the diagram below:

asciidoctor diagram VoucherRepository
VoucherInvalidationRepository

The VoucherInvalidationRepository is the corresponding Spring Data JPA repository for the VoucherInvalidationEntityDefinition.

The extended interface is BaseEntityRepository.

asciidoctor diagram VoucherInvalidationRepository

Business Services

Voucher Service

The VoucherService provides logic for performing various operations with vouchers.
The defined methods allow:

Description Method

to apply a voucher with the given code for the given cart entity

applyVoucher()

to check if the given voucher code is valid

checkVoucherCode()

to check if the given voucher could be applied to the given order

isApplicable()

Facade

MapperFactoryConfigurers

VoucherCartMapperFactoryConfigurer

The VoucherCartMapperFactoryConfigurer implements the MapperFactoryConfigurer interface, converting the CartEntityDefinition into CartVoucherDtoDefinition.

asciidoctor diagram VoucherCartMapperFactoryConfigurer

The conversion is customized.

More about the mapping configurations you may read in the respective Orika guide.

Dto definitions

CartVoucherDtoDefinition

The CartVoucherDtoDefinition is the corresponding Dto for the CartEntityDefinition.

VoucherCartDtoDefinition

The extended interfaces are 2 - CartDtoDefinition and CartVoucherDtoDefinition. Please. follow the links for better understanding of the inheritance dependencies.

asciidoctor diagram VoucherCartDtoDefinition

Facades

VoucherFacade

Some helper methods, related to vouchers, are defined within the VoucherFacade. Among the functionalities included here, are:

  • to redeem a voucher with the given code against the current user cart

  • to redeem a voucher with the given code against the given cart,

  • to return a list of applied voucher codes for the current cart’s user

  • to return a list of applied voucher invalidations for the order with the given code.

Storefront

VoucherController

The VoucherController handles an HTTP request, expecting a parameter promoCode to be passed.

For further details on mapping, check the corresponding mapping actuator accessible at /platform/mappings.

Integration

The integration with the Nemesis platform is pretty straight-forward - just add the module in your classpath:

<dependency>
    <groupId>io.nemesis.platform.module</groupId>
    <artifactId>nemesis-module-voucher</artifactId>
</dependency>