payment-kit 1.13.172 → 1.13.174
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.
|
@@ -309,7 +309,7 @@ export async function getSubscriptionRefundSetup(subscription: Subscription, anc
|
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
export function shouldCancelSubscription(
|
|
312
|
-
subscription: Pick<Subscription, 'status' | 'current_period_end' | 'cancel_at'>
|
|
312
|
+
subscription: Pick<Subscription, 'status' | 'current_period_end' | 'cancel_at' | 'cancel_at_period_end'>
|
|
313
313
|
) {
|
|
314
314
|
if (['past_due', 'active', 'trialing'].includes(subscription.status)) {
|
|
315
315
|
const now = dayjs().unix();
|
|
@@ -317,8 +317,10 @@ export function shouldCancelSubscription(
|
|
|
317
317
|
if (subscription.cancel_at <= now) {
|
|
318
318
|
return true;
|
|
319
319
|
}
|
|
320
|
-
} else if (subscription.
|
|
321
|
-
|
|
320
|
+
} else if (subscription.cancel_at_period_end) {
|
|
321
|
+
if (subscription.current_period_end <= now) {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
322
324
|
}
|
|
323
325
|
}
|
|
324
326
|
|
|
@@ -688,8 +688,9 @@ router.put('/:id/submit', user, ensureCheckoutSessionOpen, async (req, res) => {
|
|
|
688
688
|
formatSubscriptionProduct(lineItems.filter((x) => x.price.type === 'recurring')),
|
|
689
689
|
proration_behavior: checkoutSession.subscription_data?.proration_behavior || 'none',
|
|
690
690
|
payment_behavior: 'default_incomplete',
|
|
691
|
-
days_until_due: checkoutSession.metadata?.days_until_due,
|
|
692
|
-
days_until_cancel:
|
|
691
|
+
days_until_due: checkoutSession.subscription_data?.days_until_due || checkoutSession.metadata?.days_until_due,
|
|
692
|
+
days_until_cancel:
|
|
693
|
+
checkoutSession.subscription_data?.days_until_cancel || checkoutSession.metadata?.days_until_cancel,
|
|
693
694
|
metadata: checkoutSession.metadata as any,
|
|
694
695
|
});
|
|
695
696
|
|
|
@@ -168,6 +168,8 @@ export class CheckoutSession extends Model<InferAttributes<CheckoutSession>, Inf
|
|
|
168
168
|
missing_payment_method: LiteralUnion<'cancel' | 'pause' | 'create_invoice', string>;
|
|
169
169
|
};
|
|
170
170
|
};
|
|
171
|
+
days_until_due?: number;
|
|
172
|
+
days_until_cancel?: number;
|
|
171
173
|
};
|
|
172
174
|
|
|
173
175
|
// 3rd party payment tx hash
|
|
@@ -269,9 +269,15 @@ describe('shouldCancelSubscription', () => {
|
|
|
269
269
|
expect(result).toBe(true);
|
|
270
270
|
});
|
|
271
271
|
|
|
272
|
-
it('should return
|
|
272
|
+
it('should return false when status is "active" and current_period_end is less than or equal to now', () => {
|
|
273
273
|
const subscription = { status: 'active', current_period_end: now - 1 };
|
|
274
274
|
const result = shouldCancelSubscription(subscription as any);
|
|
275
|
+
expect(result).toBe(false);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('should return true when status is "active" and current_period_end is less than or equal to now', () => {
|
|
279
|
+
const subscription = { status: 'active', current_period_end: now - 1, cancel_at_period_end: true };
|
|
280
|
+
const result = shouldCancelSubscription(subscription as any);
|
|
275
281
|
expect(result).toBe(true);
|
|
276
282
|
});
|
|
277
283
|
|
|
@@ -287,9 +293,15 @@ describe('shouldCancelSubscription', () => {
|
|
|
287
293
|
expect(result).toBe(false);
|
|
288
294
|
});
|
|
289
295
|
|
|
290
|
-
it('should return false when current_period_end is greater than now', () => {
|
|
296
|
+
it('should return false when current_period_end is greater than now #1', () => {
|
|
291
297
|
const subscription = { status: 'active', current_period_end: now + 1 };
|
|
292
298
|
const result = shouldCancelSubscription(subscription as any);
|
|
293
299
|
expect(result).toBe(false);
|
|
294
300
|
});
|
|
301
|
+
|
|
302
|
+
it('should return false when current_period_end is greater than now #2', () => {
|
|
303
|
+
const subscription = { status: 'active', current_period_end: now + 1, cancel_at_period_end: false };
|
|
304
|
+
const result = shouldCancelSubscription(subscription as any);
|
|
305
|
+
expect(result).toBe(false);
|
|
306
|
+
});
|
|
295
307
|
});
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.174",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "cross-env COMPONENT_STORE_URL=https://test.store.blocklet.dev blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@arcblock/jwt": "^1.18.110",
|
|
51
51
|
"@arcblock/ux": "^2.9.39",
|
|
52
52
|
"@blocklet/logger": "1.16.23",
|
|
53
|
-
"@blocklet/payment-react": "1.13.
|
|
53
|
+
"@blocklet/payment-react": "1.13.174",
|
|
54
54
|
"@blocklet/sdk": "1.16.23",
|
|
55
55
|
"@blocklet/ui-react": "^2.9.39",
|
|
56
56
|
"@blocklet/uploader": "^0.0.74",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@abtnode/types": "1.16.23",
|
|
112
112
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
113
|
-
"@blocklet/payment-types": "1.13.
|
|
113
|
+
"@blocklet/payment-types": "1.13.174",
|
|
114
114
|
"@types/cookie-parser": "^1.4.6",
|
|
115
115
|
"@types/cors": "^2.8.17",
|
|
116
116
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -149,5 +149,5 @@
|
|
|
149
149
|
"parser": "typescript"
|
|
150
150
|
}
|
|
151
151
|
},
|
|
152
|
-
"gitHead": "
|
|
152
|
+
"gitHead": "6aa0d712bf8f36a3592fd564f14fd9ca05b5c7a9"
|
|
153
153
|
}
|