payment-kit 1.13.166 → 1.13.167
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.
|
@@ -43,7 +43,7 @@ export async function syncStripeInvoice(invoice: Invoice) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const method = await PaymentMethod.findByPk(invoice.default_payment_method_id);
|
|
46
|
-
if (!method) {
|
|
46
|
+
if (!method || method.type !== 'stripe') {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -216,6 +216,10 @@ export async function handleStripeInvoiceCreated(event: TEventExpanded, client:
|
|
|
216
216
|
logger.warn('abort because local subscription not exist', { id: event.id, type: event.type });
|
|
217
217
|
return null;
|
|
218
218
|
}
|
|
219
|
+
const method = await PaymentMethod.findByPk(subscription.default_payment_method_id);
|
|
220
|
+
if (!method || method.type !== 'stripe') {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
219
223
|
|
|
220
224
|
logger.info('valid event for subscription detected', {
|
|
221
225
|
id: event.id,
|
|
@@ -262,8 +266,8 @@ export async function handleInvoiceEvent(event: TEventExpanded, client: Stripe)
|
|
|
262
266
|
if (subscription) {
|
|
263
267
|
const method = await PaymentMethod.findByPk(subscription.default_payment_method_id);
|
|
264
268
|
if (method && method.type === 'stripe') {
|
|
265
|
-
const
|
|
266
|
-
localInvoiceId =
|
|
269
|
+
const invoice = await ensureStripeInvoice(event.data.object, subscription, method.getStripeClient());
|
|
270
|
+
localInvoiceId = invoice.id;
|
|
267
271
|
}
|
|
268
272
|
}
|
|
269
273
|
} else {
|
|
@@ -232,6 +232,7 @@ export async function ensureStripeSubscription(
|
|
|
232
232
|
customer: customer.id,
|
|
233
233
|
items: recurringItems,
|
|
234
234
|
add_invoice_items: onetimeItems,
|
|
235
|
+
collection_method: 'charge_automatically',
|
|
235
236
|
payment_behavior: 'default_incomplete',
|
|
236
237
|
payment_settings: { save_default_payment_method: 'on_subscription' },
|
|
237
238
|
metadata: {
|
|
@@ -186,6 +186,49 @@ export const startInvoiceQueue = async () => {
|
|
|
186
186
|
invoiceQueue.push({ id: x.id, job: { invoiceId: x.id, retryOnError: true } });
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
|
+
|
|
190
|
+
// handle stripe invoice
|
|
191
|
+
const stripeMethods = await PaymentMethod.findAll({ where: { type: 'stripe' } });
|
|
192
|
+
const stripeInvoices = await Invoice.findAll({
|
|
193
|
+
where: {
|
|
194
|
+
status: ['draft', 'open'],
|
|
195
|
+
'metadata.stripe_id': { [Op.not]: null },
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
stripeInvoices.forEach(async (x) => {
|
|
199
|
+
const stripeInvoiceId = x.metadata?.stripe_id;
|
|
200
|
+
if (!stripeInvoiceId) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const method = stripeMethods.find((m) => m.livemode === x.livemode);
|
|
205
|
+
if (!method) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
const client = method.getStripeClient();
|
|
211
|
+
const exist = await client.invoices.retrieve(stripeInvoiceId);
|
|
212
|
+
if (exist) {
|
|
213
|
+
if (exist.status === 'draft') {
|
|
214
|
+
await client.invoices.finalizeInvoice(stripeInvoiceId);
|
|
215
|
+
logger.info('stripe invoice finalized', { local: x.id, stripe: stripeInvoiceId });
|
|
216
|
+
}
|
|
217
|
+
await client.invoices.pay(stripeInvoiceId);
|
|
218
|
+
logger.info('stripe invoice payment requested', { local: x.id, stripe: stripeInvoiceId });
|
|
219
|
+
} else {
|
|
220
|
+
await Invoice.destroy({ where: { id: x.id } });
|
|
221
|
+
logger.warn('stripe invoice purged', { local: x.id, stripe: stripeInvoiceId });
|
|
222
|
+
}
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (error.message.includes('No such invoice')) {
|
|
225
|
+
await Invoice.destroy({ where: { id: x.id } });
|
|
226
|
+
logger.warn('stripe invoice purged', { local: x.id, stripe: stripeInvoiceId });
|
|
227
|
+
} else {
|
|
228
|
+
logger.error('stripe invoice finalize error', error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
189
232
|
};
|
|
190
233
|
|
|
191
234
|
invoiceQueue.on('failed', ({ id, job, error }) => {
|
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.167",
|
|
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.167",
|
|
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.167",
|
|
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": "3c91569392e38ac71d4d04d72bbb468fd144ace4"
|
|
153
153
|
}
|