A shopping cart Currency backed by a reward's points balance, letting a profile pay for cart items with points instead of, or as well as, real money. Wraps a single Reward and delegates balance lookups and debits to RewardService, resolving the participant (profile or organisation) that owns the balance via isForEntity. A simple in-memory lock, keyed by profile or organisation id, prevents two concurrent purchases from the same account being debited against a stale balance.

Implements: Currency


Properties

PropertyReturnsDescription
currencyIdStringUnique identifier for this currency, derived from the wrapped reward's id.
profilePointsbooleanWhether the wrapped reward's points are held per profile, as opposed to per organisation.

Inherited from Currency

Methods

balance(BaseEntity entity)

Returns: BigDecimal

Calculates the current balance of this currency held by the given entity, for example a profile or organisation.

ParameterDescription
entitythe entity whose balance is calculated

debit(Cart c, List<DebitItem> debitItems)

Returns: void

Debits the appropriate account for the given cart by the total of the supplied debit items.

ParameterDescription
cthe cart the debit is for
debitItemsthe individual line items to debit

debit(Cart c, List<DebitItem> debitItems, Map<String,String> parameters, Branch websiteBranch)

Returns: String

Debits the appropriate account for the given cart by the total of the supplied debit items, using the given form parameters and website branch to complete the payment.

ParameterDescription
cthe cart the debit is for
debitItemsthe individual line items to debit
parameterspayment-related form parameters supplied by the caller
websiteBranchthe website branch the payment is being made against

debit(Cart c, List<DebitItem> debitItems, Map<String,String> parameters, Profile profile, Branch websiteBranch)

Returns: String

Debits the appropriate account for the given cart on behalf of the given profile, by the total of the supplied debit items.

ParameterDescription
cthe cart the debit is for
debitItemsthe individual line items to debit
parameterspayment-related form parameters supplied by the caller
profilethe profile whose account is debited
websiteBranchthe website branch the payment is being made against

isBalanceSufficient(BaseEntity entity, BigDecimal amount)

Returns: boolean

Checks whether the given entity's balance in this currency is at least the given amount.

ParameterDescription
entitythe entity whose balance is checked
amountthe amount that must be available

isForEntity(Profile profile, Organisation org)

Returns: BaseEntity

Resolves the entity, either the profile or its organisation, that holds the account for this currency.

ParameterDescription
profilethe profile making the purchase
orgthe profile's organisation

Methods

getCurrencyId()

Returns: String

Unique identifier for this currency, derived from the wrapped reward's id.

isProfilePoints()

Returns: boolean

Whether the wrapped reward's points are held per profile, as opposed to per organisation.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.