@rdlabo/workers-hono-kit 0.6.15 → 0.6.17
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.
- package/dist/stripe/subscription.js +25 -17
- package/package.json +1 -1
|
@@ -3,35 +3,43 @@ export const STRIPE_RECONCILE_INVOICE_EXPAND = ['payments.data.payment.payment_i
|
|
|
3
3
|
export function stripePaymentIntent(invoice) {
|
|
4
4
|
const payment = invoice.payments?.data[0]?.payment;
|
|
5
5
|
// Stripe's generated type treats data[0] as present, but genuine trials return an empty payments array.
|
|
6
|
-
|
|
6
|
+
const paymentIntent = payment?.type === 'payment_intent' ? payment.payment_intent : null;
|
|
7
|
+
return typeof paymentIntent === 'object' && paymentIntent !== null ? paymentIntent : null;
|
|
7
8
|
}
|
|
8
9
|
export function buildStripeReconcilePlan(options) {
|
|
9
10
|
const { subscription, invoice, customerId } = options;
|
|
10
11
|
const formatDate = options.formatDate ?? ((value) => value);
|
|
11
12
|
const paymentIntent = stripePaymentIntent(invoice);
|
|
12
13
|
const action = classifyStripeReconcile({ ...subscription, latest_invoice: invoice });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const payment = action === 'trial'
|
|
19
|
-
? {
|
|
20
|
-
customerId,
|
|
21
|
-
recursionsId: invoice.id,
|
|
22
|
-
status: 'trialing',
|
|
23
|
-
detail: JSON.stringify(invoice),
|
|
24
|
-
...dates,
|
|
14
|
+
let payment = null;
|
|
15
|
+
if (action === 'trial' || paymentIntent) {
|
|
16
|
+
const period = subscription.items.data.at(0);
|
|
17
|
+
if (!period) {
|
|
18
|
+
throw new Error(`Subscription has no items: ${subscription.id}`);
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
const dates = {
|
|
21
|
+
limitAt: formatDate(new Date(period.current_period_end * 1000)),
|
|
22
|
+
createdAt: formatDate(new Date(period.current_period_start * 1000)),
|
|
23
|
+
};
|
|
24
|
+
if (action === 'trial') {
|
|
25
|
+
payment = {
|
|
26
|
+
customerId,
|
|
27
|
+
recursionsId: invoice.id,
|
|
28
|
+
status: 'trialing',
|
|
29
|
+
detail: JSON.stringify(invoice),
|
|
30
|
+
...dates,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (paymentIntent) {
|
|
34
|
+
payment = {
|
|
28
35
|
customerId,
|
|
29
36
|
recursionsId: paymentIntent.id,
|
|
30
37
|
status: paymentIntent.status,
|
|
31
38
|
detail: JSON.stringify(paymentIntent),
|
|
32
39
|
...dates,
|
|
33
|
-
}
|
|
34
|
-
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
return { action, paymentIntent, payment };
|
|
36
44
|
}
|
|
37
45
|
export async function assertStripeCustomerUpdated(options) {
|