payment-kit 1.13.263 → 1.13.264

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.
@@ -314,6 +314,7 @@ export async function startCheckoutSessionFromPaymentLink(id: string, req: Reque
314
314
  const raw: Partial<CheckoutSession> = await formatCheckoutSession(link, false);
315
315
  raw.livemode = link.livemode;
316
316
  raw.created_via = 'portal';
317
+ raw.submit_type = link.submit_type;
317
318
  raw.currency_id = link.currency_id || req.currency.id;
318
319
  raw.payment_link_id = link.id;
319
320
  raw.subscription_data = merge(link.subscription_data, getDataObjectFromQuery(req.query, 'subscription_data'), {
@@ -325,9 +326,15 @@ export async function startCheckoutSessionFromPaymentLink(id: string, req: Reque
325
326
  description: link.after_completion?.hosted_confirmation?.custom_message,
326
327
  };
327
328
  } else {
329
+ const descriptions: { [key: string]: string } = {
330
+ payment: 'Thanks for your purchase',
331
+ subscription: 'Thanks for your subscribing',
332
+ setup: 'Thanks for your subscribing',
333
+ donate: 'Thanks for your support',
334
+ };
335
+ const mode = link.submit_type === 'donate' ? 'donate' : raw.mode;
328
336
  raw.payment_intent_data = {
329
- // TODO: bake default into this
330
- description: 'Thanks for your purchase',
337
+ description: descriptions[mode || 'payment'],
331
338
  };
332
339
  }
333
340
  if (link.after_completion?.redirect?.url) {
@@ -1,6 +1,7 @@
1
- import { fromTokenToUnit } from '@ocap/util';
1
+ import { BN, fromTokenToUnit } from '@ocap/util';
2
2
  import { Router } from 'express';
3
3
  import Joi from 'joi';
4
+ import cloneDeep from 'lodash/cloneDeep';
4
5
  import pick from 'lodash/pick';
5
6
 
6
7
  import { createListParamSchema, getWhereFromKvQuery, getWhereFromQuery } from '../libs/api';
@@ -299,4 +300,67 @@ router.delete('/:id', auth, async (req, res) => {
299
300
  }
300
301
  });
301
302
 
303
+ // This is a dangerous operation, only allow to run with a special env variable
304
+ // Only meant to be used in DID Domain
305
+ router.post('/batch-price-update', auth, async (req, res) => {
306
+ if (process.env.PAYMENT_CHANGE_LOCKED_PRICE !== '1') {
307
+ return res.status(403).json({ error: 'forbidden' });
308
+ }
309
+
310
+ const dryRun = typeof req.body.dryRun === 'undefined' || req.body.dryRun !== '0';
311
+ const factor = Number(req.body.factor);
312
+ if (Number.isNaN(factor)) {
313
+ return res.status(400).json({ error: 'factor is required' });
314
+ }
315
+ if (factor <= 0) {
316
+ return res.status(400).json({ error: 'factor must be positive' });
317
+ }
318
+ if (!req.body.description) {
319
+ return res.status(400).json({ error: 'description is required' });
320
+ }
321
+
322
+ try {
323
+ const updated: any[] = [];
324
+ const products = await Product.findAll({ where: { active: true, livemode: !!req.livemode } });
325
+ await Promise.all(
326
+ products.map(async (product) => {
327
+ if (!product.metadata?.domain) {
328
+ return;
329
+ }
330
+
331
+ const prices = await Price.findAll({ where: { product_id: product.id } });
332
+ for (const price of prices) {
333
+ if (price.currency_id === req.currency.id) {
334
+ const unit = new BN(price.unit_amount).div(new BN(factor)).toString();
335
+ const options = cloneDeep(price.currency_options);
336
+ const option = options.find((x) => x.currency_id === price.currency_id);
337
+ if (option) {
338
+ option.unit_amount = unit;
339
+ }
340
+
341
+ const metadata = price.metadata || {};
342
+ metadata.update_history = [metadata.update_history, req.body.description].filter(Boolean).join(';');
343
+
344
+ if (dryRun) {
345
+ updated.push({ price: price.toJSON(), metadata, unit_amount: unit, currency_options: options });
346
+ } else {
347
+ // eslint-disable-next-line
348
+ await Price.update(
349
+ { metadata, unit_amount: unit, currency_options: options },
350
+ { where: { id: price.id } }
351
+ );
352
+ updated.push(product.id);
353
+ }
354
+ }
355
+ }
356
+ })
357
+ );
358
+
359
+ return res.json(updated);
360
+ } catch (err) {
361
+ logger.error('batch price update error', err);
362
+ return res.status(400).json({ error: err.message });
363
+ }
364
+ });
365
+
302
366
  export default router;
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.13.263
17
+ version: 1.13.264
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.13.263",
3
+ "version": "1.13.264",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -51,7 +51,7 @@
51
51
  "@arcblock/ux": "^2.9.80",
52
52
  "@arcblock/validator": "^1.18.120",
53
53
  "@blocklet/logger": "1.16.26",
54
- "@blocklet/payment-react": "1.13.263",
54
+ "@blocklet/payment-react": "1.13.264",
55
55
  "@blocklet/sdk": "1.16.26",
56
56
  "@blocklet/ui-react": "^2.9.80",
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.263",
119
+ "@blocklet/payment-types": "1.13.264",
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": "be124b5d7d0e96734ac36d20a01c493a15cd443e"
158
+ "gitHead": "cd570450d39c6918d49bf67d29c4907705e69078"
159
159
  }