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
| Property | Returns | Description |
|---|---|---|
| currencyId | String | Unique identifier for this currency, derived from the wrapped reward's id. |
| profilePoints | boolean | Whether 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.
| Parameter | Description |
|---|---|
entity | the 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.
| Parameter | Description |
|---|---|
c | the cart the debit is for |
debitItems | the 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.
| Parameter | Description |
|---|---|
c | the cart the debit is for |
debitItems | the individual line items to debit |
parameters | payment-related form parameters supplied by the caller |
websiteBranch | the 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.
| Parameter | Description |
|---|---|
c | the cart the debit is for |
debitItems | the individual line items to debit |
parameters | payment-related form parameters supplied by the caller |
profile | the profile whose account is debited |
websiteBranch | the 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.
| Parameter | Description |
|---|---|
entity | the entity whose balance is checked |
amount | the 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.
| Parameter | Description |
|---|---|
profile | the profile making the purchase |
org | the 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.