payment-kit 1.13.252 → 1.13.253
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import env from '@blocklet/sdk/lib/env';
|
|
2
|
+
import merge from 'lodash/merge';
|
|
2
3
|
import pick from 'lodash/pick';
|
|
3
4
|
import pWaitFor from 'p-wait-for';
|
|
4
5
|
import type Stripe from 'stripe';
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
Subscription,
|
|
15
16
|
SubscriptionItem,
|
|
16
17
|
TEventExpanded,
|
|
18
|
+
TInvoiceItem,
|
|
17
19
|
} from '../../../store/models';
|
|
18
20
|
|
|
19
21
|
export async function handleStripeInvoicePaid(invoice: Invoice, event: TEventExpanded) {
|
|
@@ -37,6 +39,21 @@ export async function handleStripeInvoicePaid(invoice: Invoice, event: TEventExp
|
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
export function getStripeInvoicePeriod(invoice: any) {
|
|
43
|
+
const lineItem: TInvoiceItem = (invoice.lines.data || []).find((x: any) => !x.proration && x.type === 'subscription');
|
|
44
|
+
if (lineItem && lineItem.period) {
|
|
45
|
+
return {
|
|
46
|
+
period_start: lineItem.period.start,
|
|
47
|
+
period_end: lineItem.period.end,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
period_start: invoice.period_start,
|
|
53
|
+
period_end: invoice.period_end,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
export async function syncStripeInvoice(invoice: Invoice) {
|
|
41
58
|
if (!invoice.metadata?.stripe_id) {
|
|
42
59
|
return;
|
|
@@ -52,21 +69,24 @@ export async function syncStripeInvoice(invoice: Invoice) {
|
|
|
52
69
|
if (stripeInvoice) {
|
|
53
70
|
await invoice.update(
|
|
54
71
|
// @ts-ignore
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
merge(
|
|
73
|
+
pick(stripeInvoice, [
|
|
74
|
+
'amount_due',
|
|
75
|
+
'amount_paid',
|
|
76
|
+
'amount_remaining',
|
|
77
|
+
'last_finalization_error',
|
|
78
|
+
'paid_out_of_band',
|
|
79
|
+
'paid',
|
|
80
|
+
'status_transitions',
|
|
81
|
+
'status',
|
|
82
|
+
'subtotal_excluding_tax',
|
|
83
|
+
'subtotal',
|
|
84
|
+
'tax',
|
|
85
|
+
'total_discount_amounts',
|
|
86
|
+
'total',
|
|
87
|
+
]),
|
|
88
|
+
getStripeInvoicePeriod(stripeInvoice)
|
|
89
|
+
)
|
|
70
90
|
);
|
|
71
91
|
logger.info('stripe invoice synced', { locale: invoice.id, remote: stripeInvoice.id });
|
|
72
92
|
}
|
|
@@ -219,7 +219,7 @@ router.get('/:id', authPortal, async (req, res) => {
|
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
if (doc) {
|
|
222
|
-
if (doc.status !== 'paid'
|
|
222
|
+
if (doc.metadata?.stripe_id && (doc.status !== 'paid' || req.query.forceSync)) {
|
|
223
223
|
await syncStripeInvoice(doc);
|
|
224
224
|
}
|
|
225
225
|
if (doc.payment_intent_id) {
|
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.253",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@arcblock/ux": "^2.9.77",
|
|
52
52
|
"@arcblock/validator": "^1.18.116",
|
|
53
53
|
"@blocklet/logger": "1.16.26",
|
|
54
|
-
"@blocklet/payment-react": "1.13.
|
|
54
|
+
"@blocklet/payment-react": "1.13.253",
|
|
55
55
|
"@blocklet/sdk": "1.16.26",
|
|
56
56
|
"@blocklet/ui-react": "^2.9.77",
|
|
57
57
|
"@blocklet/uploader": "^0.1.6",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@abtnode/types": "1.16.26",
|
|
118
118
|
"@arcblock/eslint-config-ts": "^0.3.0",
|
|
119
|
-
"@blocklet/payment-types": "1.13.
|
|
119
|
+
"@blocklet/payment-types": "1.13.253",
|
|
120
120
|
"@types/cookie-parser": "^1.4.7",
|
|
121
121
|
"@types/cors": "^2.8.17",
|
|
122
122
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -155,5 +155,5 @@
|
|
|
155
155
|
"parser": "typescript"
|
|
156
156
|
}
|
|
157
157
|
},
|
|
158
|
-
"gitHead": "
|
|
158
|
+
"gitHead": "4ad023bae87cc6b0c7480e701e5ba51b7b66ca19"
|
|
159
159
|
}
|