Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNS-883-audit-future-subscription-diff-charge #1220

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions x/subscription/keeper/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ func (k Keeper) CreateFutureSubscription(ctx sdk.Context,
newPlanPrice := plan.GetPrice()
newPlanPrice.Amount = newPlanPrice.Amount.MulRaw(int64(duration))
k.applyPlanDiscountIfEligible(duration, &plan, &newPlanPrice)
chargePrice := newPlanPrice

if sub.FutureSubscription != nil {
// Consumer already has a future subscription
Expand All @@ -635,13 +636,8 @@ func (k Keeper) CreateFutureSubscription(ctx sdk.Context,
)
}

consumerBoughDuration := sub.FutureSubscription.DurationBought
consumerPaid := currentPlan.GetPrice()
consumerPaid.Amount = consumerPaid.Amount.MulRaw(int64(consumerBoughDuration))
k.applyPlanDiscountIfEligible(consumerBoughDuration, &plan, &consumerPaid)

if newPlanPrice.Amount.GT(consumerPaid.Amount) {
newPlanPrice.Amount = newPlanPrice.Amount.Sub(consumerPaid.Amount)
if newPlanPrice.Amount.GT(sub.FutureSubscription.Credit.Amount) {
chargePrice.Amount = newPlanPrice.Amount.Sub(sub.FutureSubscription.Credit.Amount)

details := map[string]string{
"creator": creator,
Expand All @@ -658,7 +654,7 @@ func (k Keeper) CreateFutureSubscription(ctx sdk.Context,
}
}

err = k.chargeFromCreatorAccountToModule(ctx, creatorAcct, newPlanPrice)
err = k.chargeFromCreatorAccountToModule(ctx, creatorAcct, chargePrice)
if err != nil {
return err
}
oren-lava marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading