fix: create product endpoint for old versions
This commit is contained in:
@@ -113,3 +113,37 @@ export const cusEntToMaxPurchase = ({
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
// NEW CUS ENT UTILS
|
||||
export const cusEntToGrantedBalance = ({
|
||||
cusEnt,
|
||||
entityId,
|
||||
withRollovers = false,
|
||||
}: {
|
||||
cusEnt: FullCusEntWithFullCusProduct;
|
||||
entityId?: string;
|
||||
withRollovers?: boolean;
|
||||
}) => {
|
||||
const rollover = getRolloverFields({
|
||||
cusEnt,
|
||||
entityId,
|
||||
});
|
||||
|
||||
const { count: entityCount } = getCusEntBalance({
|
||||
cusEnt,
|
||||
entityId,
|
||||
});
|
||||
|
||||
const grantedBalance = cusEnt.entitlement.allowance || 0;
|
||||
|
||||
const total = new Decimal(grantedBalance).mul(entityCount).toNumber();
|
||||
|
||||
if (withRollovers && rollover) {
|
||||
return new Decimal(total)
|
||||
.add(rollover.balance)
|
||||
.add(rollover.usage)
|
||||
.toNumber();
|
||||
}
|
||||
|
||||
return total;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user