@funnelsgrove/payments 0.1.54 → 0.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -35,6 +35,10 @@ const BILLING_INTERVAL_DAYS = {
|
|
|
35
35
|
month: 30,
|
|
36
36
|
year: 365,
|
|
37
37
|
};
|
|
38
|
+
const PAYWALL_DISCOUNT_COOLDOWN_MS = 30 * 60 * 1000;
|
|
39
|
+
const hasDiscountCooldownElapsed = (nowMs, expiresAtMs) => {
|
|
40
|
+
return nowMs >= expiresAtMs + PAYWALL_DISCOUNT_COOLDOWN_MS;
|
|
41
|
+
};
|
|
38
42
|
const clampRemainingSeconds = (value) => {
|
|
39
43
|
if (!Number.isFinite(value) || value <= 0) {
|
|
40
44
|
return 0;
|
|
@@ -142,6 +146,9 @@ const createDiscountStateFromStarts = (input) => {
|
|
|
142
146
|
const expiresAtMs = input.secondStartedAtMs + getDiscountDurationMs(input.discounts, 'second');
|
|
143
147
|
const remainingSeconds = clampRemainingSeconds((expiresAtMs - input.nowMs) / 1000);
|
|
144
148
|
if (remainingSeconds <= 0) {
|
|
149
|
+
if (hasDiscountCooldownElapsed(input.nowMs, expiresAtMs)) {
|
|
150
|
+
return createDiscountStateFromStarts(Object.assign(Object.assign({}, input), { firstStartedAtMs: input.nowMs, secondStartedAtMs: null }));
|
|
151
|
+
}
|
|
145
152
|
return createExpiredDiscountState({
|
|
146
153
|
stage: 'completed',
|
|
147
154
|
firstStartedAtMs: input.firstStartedAtMs,
|
|
@@ -167,6 +174,9 @@ const createDiscountStateFromStarts = (input) => {
|
|
|
167
174
|
const expiresAtMs = input.firstStartedAtMs + getDiscountDurationMs(input.discounts, 'first');
|
|
168
175
|
const remainingSeconds = clampRemainingSeconds((expiresAtMs - input.nowMs) / 1000);
|
|
169
176
|
if (remainingSeconds <= 0) {
|
|
177
|
+
if (hasDiscountCooldownElapsed(input.nowMs, expiresAtMs)) {
|
|
178
|
+
return createDiscountStateFromStarts(Object.assign(Object.assign({}, input), { firstStartedAtMs: input.nowMs, secondStartedAtMs: null }));
|
|
179
|
+
}
|
|
170
180
|
return createExpiredDiscountState({
|
|
171
181
|
stage: 'first',
|
|
172
182
|
firstStartedAtMs: input.firstStartedAtMs,
|
|
@@ -227,7 +237,8 @@ export const advancePaywallDiscountState = (input) => {
|
|
|
227
237
|
};
|
|
228
238
|
export const activateSecondPaywallDiscount = (input) => {
|
|
229
239
|
var _a;
|
|
230
|
-
if (
|
|
240
|
+
if (input.state.status !== 'active' ||
|
|
241
|
+
typeof input.state.secondStartedAtMs === 'number' ||
|
|
231
242
|
input.state.stage === 'completed') {
|
|
232
243
|
return input.state;
|
|
233
244
|
}
|