payment-kit 1.13.309 → 1.14.0

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.
@@ -751,12 +751,44 @@ router.put('/:id/submit', user, ensureCheckoutSessionOpen, async (req, res) => {
751
751
  .status(403)
752
752
  .json({ code: 'SUBSCRIPTION_INVALID', error: 'Checkout session subscription status unexpected' });
753
753
  }
754
+ const setup = getSubscriptionCreateSetup(lineItems, paymentCurrency.id, trialInDays, trialEnds);
754
755
  subscription = await subscription.update({
755
756
  currency_id: paymentCurrency.id,
756
757
  customer_id: customer.id,
757
758
  default_payment_method_id: paymentMethod.id,
759
+ current_period_start: setup.period.start,
760
+ current_period_end: setup.period.end,
761
+ billing_cycle_anchor: checkoutSession.subscription_data?.billing_cycle_anchor || setup.cycle.anchor,
762
+ trial_end: setup.trial.end,
763
+ trial_start: setup.trial.start,
764
+ pending_invoice_item_interval: setup.recurring,
758
765
  pending_setup_intent: setupIntent?.id,
759
766
  });
767
+ logger.info('subscription updated on checkout session resubmit', {
768
+ session: checkoutSession.id,
769
+ subscription: subscription.id,
770
+ });
771
+
772
+ // rebuild subscription items
773
+ await SubscriptionItem.destroy({ where: { subscription_id: subscription.id } });
774
+ const items = await Promise.all(
775
+ lineItems
776
+ .filter((x) => x.price.type === 'recurring')
777
+ .map((x) =>
778
+ SubscriptionItem.create({
779
+ livemode: !!checkoutSession.livemode,
780
+ // @ts-ignore
781
+ subscription_id: subscription.id,
782
+ price_id: x.upsell_price_id || x.price_id,
783
+ quantity: x.quantity,
784
+ metadata: checkoutSession.metadata as any,
785
+ })
786
+ )
787
+ );
788
+ logger.info('subscription items rebuilt on checkout session resubmit', {
789
+ session: checkoutSession.id,
790
+ items: items.map((x) => x.id),
791
+ });
760
792
  } else {
761
793
  // FIXME: @wangshijun respect all checkoutSession.subscription_data fields
762
794
  const setup = getSubscriptionCreateSetup(lineItems, paymentCurrency.id, trialInDays, trialEnds);
@@ -802,7 +834,6 @@ router.put('/:id/submit', user, ensureCheckoutSessionOpen, async (req, res) => {
802
834
  subscription: subscription.id,
803
835
  });
804
836
 
805
- // FIXME: @wangshijun what if we have have changed subscription items when resubmit
806
837
  // create subscription items
807
838
  const items = await Promise.all(
808
839
  lineItems
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.309
17
+ version: 1.14.0
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.309",
3
+ "version": "1.14.0",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -52,7 +52,7 @@
52
52
  "@arcblock/validator": "^1.18.124",
53
53
  "@blocklet/js-sdk": "1.16.28",
54
54
  "@blocklet/logger": "1.16.28",
55
- "@blocklet/payment-react": "1.13.309",
55
+ "@blocklet/payment-react": "1.14.0",
56
56
  "@blocklet/sdk": "1.16.28",
57
57
  "@blocklet/ui-react": "^2.10.3",
58
58
  "@blocklet/uploader": "^0.1.20",
@@ -118,7 +118,7 @@
118
118
  "devDependencies": {
119
119
  "@abtnode/types": "1.16.28",
120
120
  "@arcblock/eslint-config-ts": "^0.3.2",
121
- "@blocklet/payment-types": "1.13.309",
121
+ "@blocklet/payment-types": "1.14.0",
122
122
  "@types/cookie-parser": "^1.4.7",
123
123
  "@types/cors": "^2.8.17",
124
124
  "@types/debug": "^4.1.12",
@@ -160,5 +160,5 @@
160
160
  "parser": "typescript"
161
161
  }
162
162
  },
163
- "gitHead": "bb892b5514943397caa1d96f9c6b355fcf7a0e71"
163
+ "gitHead": "f39e47fae8a2c10598c6ee28e10b76f338b14c97"
164
164
  }