@@ -9,6 +9,7 @@ import { LicenseIdleTimeouts } from "@cocalc/util/consts/site-license";
9
9
import type { Uptime } from "@cocalc/util/consts/site-license" ;
10
10
import { MAX } from "@cocalc/util/licenses/purchase/consts" ;
11
11
import { round2up } from "../misc" ;
12
+ import { CURRENT_VERSION } from "@cocalc/util/licenses/purchase/consts" ;
12
13
13
14
export interface Changes {
14
15
end ?: Date ;
@@ -104,7 +105,9 @@ export default function costToEditLicense(
104
105
log ( "editLicense with start date updated:" , { origInfo } ) ;
105
106
106
107
// Make copy of data with modified params.
107
- const modifiedInfo = cloneDeep ( origInfo ) ;
108
+ // modifiedInfo uses the current default pricing algorithm, since that the cost today
109
+ // to make this purchase, hence changing version below.
110
+ const modifiedInfo = { ...cloneDeep ( origInfo ) , version : CURRENT_VERSION } ;
108
111
if ( changes . start != null ) {
109
112
modifiedInfo . start = changes . start ;
110
113
}
@@ -222,6 +225,8 @@ export default function costToEditLicense(
222
225
log ( { modifiedInfo } ) ;
223
226
224
227
// Determine price for the change
228
+
229
+ // the value of the license the user currently owned. The pricing algorithm version is important here.
225
230
const currentValue = currentLicenseValue ( origInfo ) ;
226
231
227
232
if ( numChanges > 0 && modifiedInfo . type == "quota" ) {
@@ -234,6 +239,9 @@ export default function costToEditLicense(
234
239
delete modifiedInfo . cost_per_hour ;
235
240
}
236
241
242
+ // Determine price for the modified license they would like to switch to.
243
+ // modifiedInfo uses the current default pricing algorithm, since that the cost today
244
+ // to make this purchase, hence changing version below.
237
245
const modifiedValue = currentLicenseValue ( modifiedInfo ) ;
238
246
// cost can be negative, when we give user a refund.
239
247
// **We round away from zero!** The reason is because
@@ -288,17 +296,17 @@ function currentLicenseValue(info: PurchaseInfo): number {
288
296
// Perhaps we won't raise rates before switching to a full
289
297
// pay as you go model....
290
298
291
- // if (info.cost_per_hour) {
292
- // // if this is set, we use it to compute the value
293
- // // The value is cost_per_hour times the number of hours left until info.end.
294
- // const end = dayjs(info.end);
295
- // const start = dayjs(info.start);
296
- // const hoursRemaining = end.diff(start, "hours", true);
297
- // // the hoursRemaining can easily be *negative* if info.end is
298
- // // in the past.
299
- // // However the value of a license is never negative, so we max with 0.
300
- // return Math.max(0, hoursRemaining * info.cost_per_hour);
301
- // }
299
+ // if (info.cost_per_hour) {
300
+ // // if this is set, we use it to compute the value
301
+ // // The value is cost_per_hour times the number of hours left until info.end.
302
+ // const end = dayjs(info.end);
303
+ // const start = dayjs(info.start);
304
+ // const hoursRemaining = end.diff(start, "hours", true);
305
+ // // the hoursRemaining can easily be *negative* if info.end is
306
+ // // in the past.
307
+ // // However the value of a license is never negative, so we max with 0.
308
+ // return Math.max(0, hoursRemaining * info.cost_per_hour);
309
+ // }
302
310
303
311
// Compute value using the current rate.
304
312
// As mentioned above, we can keep old rates if/when we change the rate,
0 commit comments