Broadleaf Microservices
  • v1.0.0-latest-prod

Granting Credit That Can Expire

Overview

For store credit accounts, it’s possible to grant credit that expires at some point in the future. Before the expiration date, a portion or all of this credited amount can be debited. Once the expiration date is hit, any unused amount from this credit transaction will be expired.

To setup expiring credit, add the expirationDate property in the request body when creating the Credit Account or executing a CREDIT transaction.

To track a credit transaction’s unused expiring amount, we introduced the Transaction#amountRemaining field. Once the transaction expires, this value is set to 0. For example, if the credit amount is $50 and the customer used $10, the amountRemaining will be updated to $40 (50 - 10).If the credit is expired, we update this value to 0.

As the expiring credit amount is used, we keep track of related debit transactions and their amounts in Transaction#relatedTransactionDetails. When the transaction expires, a record is added to this collection correlating to a debit of any remaining amount - i.e. expiring the remaining amount.

Credit Expiration Scheduled Job

To help manage expiring credit, a scheduled job was added to check if there are any expired credit transactions, which executes the DEBIT transaction to expire any remaining amounts.

The job’s type is FINALIZE_CART_AWAITING_PAYMENT_RESULT and the listener for this event is com.broadleafcommerce.creditaccount.service.messaging.CreditExpirationJobListener. By default, this job executes every day at midnight, & it processes expired transactions using a default batch size of 50. If you’d like to modify the batch size, you can add a batchSize-named job detail.