Skip to main content

Prepaid Wallet System

The Prepaid Wallet system enables real-time balance checking, reservations, and consumption control.

Use Cases

  • API Billing (like OpenAI) - prevent overage without payment
  • Telecom - real-time call/data deduction
  • IoT - device consumption control
  • Gaming - in-app purchases and virtual currency

Architecture Overview

Key Concepts

Wallet Types

TypeDescriptionBalance Control
PREPAIDPre-funded walletStrict balance enforcement
POSTPAIDPay-after walletNo balance restrictions

Balance Levels

LevelPurpose
lowBalanceLevelTrigger LOW_BALANCE notification
rejectLevelBlock consumption below this level

Operation Status

StatusDescriptionBalance Impact
OPENActive, ready for invoicingDeducted
RESERVEDPrepaid holdHeld (not deducted yet)
TREATEDInvoicedDeducted
CANCELEDReversedRestored

Prepaid vs Postpaid

AspectPrepaidPostpaid
Balance RequiredYes (pre-fund)No
Reject LevelEnforcedIgnored
ReservationRequired for real-timeOptional
Real-time CheckYesNo
Invoice TimingOptionalEnd of cycle
Low Balance AlertYesN/A

Core Entities

WalletTemplate

Configuration template for wallets.

WalletTemplate {
code: String // "PREPAID_API_CREDITS"
walletType: BillingWalletTypeEnum // PREPAID or POSTPAID
lowBalanceLevel: BigDecimal // Trigger notification threshold
rejectLevel: BigDecimal // Reject consumption threshold
lowBalanceLevelEl: String // Dynamic EL expression
rejectLevelEl: String // Dynamic EL expression
}

WalletInstance

Per-user wallet linked to UserAccount.

WalletInstance {
code: String // "PRINCIPAL" or custom
walletTemplate: WalletTemplate
userAccount: UserAccount // Owner
lowBalanceLevel: BigDecimal // Override from template
rejectLevel: BigDecimal // Override from template
}

WalletOperation

Base transaction entity.

WalletOperation {
type: OperationTypeEnum // CREDIT or DEBIT
status: WalletOperationStatusEnum
amountWithoutTax: BigDecimal
amountWithTax: BigDecimal
wallet: WalletInstance
chargeInstance: ChargeInstance
}

Reservation

Tracks prepaid reservation lifecycle.

Reservation {
status: ReservationStatus // OPEN, CONFIRMED, CANCELLED, EXPIRED
reservationDate: Date
expiryDate: Date
quantity: BigDecimal
amountWithTax: BigDecimal
counterPeriodValues: Map // For counter restoration
}

Key Files

Entities:

  • opencell-model/.../billing/WalletInstance.java
  • opencell-model/.../catalog/WalletTemplate.java
  • opencell-model/.../billing/WalletOperation.java
  • opencell-model/.../billing/WalletReservation.java
  • opencell-model/.../billing/Reservation.java

Services:

  • opencell-admin/ejbs/.../WalletService.java
  • opencell-admin/ejbs/.../WalletOperationService.java
  • opencell-admin/ejbs/.../WalletReservationService.java
  • opencell-admin/ejbs/.../ReservationService.java

APIs:

  • opencell-api/.../billing/WalletRs.java
  • opencell-api/.../billing/MediationRs.java