@blocklet/payment-react 1.14.36 → 1.14.37

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.
@@ -9,6 +9,7 @@ import { fromTokenToUnit } from "@ocap/util";
9
9
  import { useSetState } from "ahooks";
10
10
  import { useEffect, useState } from "react";
11
11
  import { FormProvider, useForm, useWatch } from "react-hook-form";
12
+ import trim from "lodash/trim";
12
13
  import { usePaymentContext } from "../contexts/payment.js";
13
14
  import api from "../libs/api.js";
14
15
  import { findCurrency, formatError, getStatementDescriptor, isMobileSafari, isValidCountry } from "../libs/util.js";
@@ -145,14 +146,21 @@ function PaymentInner({
145
146
  setState({ checkoutSession: result.checkoutSession });
146
147
  onPaid(result);
147
148
  };
149
+ let trialInDays = Number(state.checkoutSession?.subscription_data?.trial_period_days || 0);
150
+ let trialEnd = Number(state.checkoutSession?.subscription_data?.trial_end || 0);
151
+ const trialCurrencyIds = (state.checkoutSession?.subscription_data?.trial_currency || "").split(",").map(trim).filter(Boolean);
152
+ if (trialCurrencyIds.length > 0 && trialCurrencyIds.includes(currencyId) === false) {
153
+ trialInDays = 0;
154
+ trialEnd = 0;
155
+ }
148
156
  return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : mode === "inline" ? 4 : 8 } }, children: [
149
157
  !hideSummaryCard && /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "base-card cko-overview", direction: "column", children: [
150
158
  /* @__PURE__ */ jsx(
151
159
  PaymentSummary,
152
160
  {
153
161
  items: state.checkoutSession.line_items,
154
- trialInDays: state.checkoutSession.subscription_data?.trial_period_days || 0,
155
- trialEnd: state.checkoutSession.subscription_data?.trial_end || 0,
162
+ trialInDays,
163
+ trialEnd,
156
164
  billingThreshold: Math.max(
157
165
  state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
158
166
  // @ts-ignore
@@ -16,6 +16,7 @@ var _util = require("@ocap/util");
16
16
  var _ahooks = require("ahooks");
17
17
  var _react = require("react");
18
18
  var _reactHookForm = require("react-hook-form");
19
+ var _trim = _interopRequireDefault(require("lodash/trim"));
19
20
  var _payment = require("../contexts/payment");
20
21
  var _api = _interopRequireDefault(require("../libs/api"));
21
22
  var _util2 = require("../libs/util");
@@ -195,6 +196,13 @@ function PaymentInner({
195
196
  });
196
197
  onPaid(result);
197
198
  };
199
+ let trialInDays = Number(state.checkoutSession?.subscription_data?.trial_period_days || 0);
200
+ let trialEnd = Number(state.checkoutSession?.subscription_data?.trial_end || 0);
201
+ const trialCurrencyIds = (state.checkoutSession?.subscription_data?.trial_currency || "").split(",").map(_trim.default).filter(Boolean);
202
+ if (trialCurrencyIds.length > 0 && trialCurrencyIds.includes(currencyId) === false) {
203
+ trialInDays = 0;
204
+ trialEnd = 0;
205
+ }
198
206
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.FormProvider, {
199
207
  ...methods,
200
208
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
@@ -211,8 +219,8 @@ function PaymentInner({
211
219
  direction: "column",
212
220
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_summary.default, {
213
221
  items: state.checkoutSession.line_items,
214
- trialInDays: state.checkoutSession.subscription_data?.trial_period_days || 0,
215
- trialEnd: state.checkoutSession.subscription_data?.trial_end || 0,
222
+ trialInDays,
223
+ trialEnd,
216
224
  billingThreshold: Math.max(state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
217
225
  // @ts-ignore
218
226
  state.checkoutSession.subscription_data?.min_stake_amount || 0),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.14.36",
3
+ "version": "1.14.37",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -93,7 +93,7 @@
93
93
  "@babel/core": "^7.25.2",
94
94
  "@babel/preset-env": "^7.25.2",
95
95
  "@babel/preset-react": "^7.24.7",
96
- "@blocklet/payment-types": "1.14.36",
96
+ "@blocklet/payment-types": "1.14.37",
97
97
  "@storybook/addon-essentials": "^7.6.20",
98
98
  "@storybook/addon-interactions": "^7.6.20",
99
99
  "@storybook/addon-links": "^7.6.20",
@@ -123,5 +123,5 @@
123
123
  "vite-plugin-babel": "^1.2.0",
124
124
  "vite-plugin-node-polyfills": "^0.21.0"
125
125
  },
126
- "gitHead": "927e39d554524434d20f22a950eec503166ae529"
126
+ "gitHead": "645ae0bdbab463eec878af0521eb982b51499639"
127
127
  }
@@ -18,6 +18,7 @@ import { fromTokenToUnit } from '@ocap/util';
18
18
  import { useSetState } from 'ahooks';
19
19
  import { useEffect, useState } from 'react';
20
20
  import { FormProvider, useForm, useWatch } from 'react-hook-form';
21
+ import trim from 'lodash/trim';
21
22
  import type { LiteralUnion } from 'type-fest';
22
23
 
23
24
  import { usePaymentContext } from '../contexts/payment';
@@ -176,6 +177,18 @@ function PaymentInner({
176
177
  onPaid(result);
177
178
  };
178
179
 
180
+ // trialing can be limited with trial_currency, which can be a list
181
+ let trialInDays = Number(state.checkoutSession?.subscription_data?.trial_period_days || 0);
182
+ let trialEnd = Number(state.checkoutSession?.subscription_data?.trial_end || 0);
183
+ const trialCurrencyIds = (state.checkoutSession?.subscription_data?.trial_currency || '')
184
+ .split(',')
185
+ .map(trim)
186
+ .filter(Boolean);
187
+ if (trialCurrencyIds.length > 0 && trialCurrencyIds.includes(currencyId) === false) {
188
+ trialInDays = 0;
189
+ trialEnd = 0;
190
+ }
191
+
179
192
  return (
180
193
  <FormProvider {...methods}>
181
194
  <Stack className="cko-container" sx={{ gap: { sm: mode === 'standalone' ? 0 : mode === 'inline' ? 4 : 8 } }}>
@@ -184,8 +197,8 @@ function PaymentInner({
184
197
  <Stack className="base-card cko-overview" direction="column">
185
198
  <PaymentSummary
186
199
  items={state.checkoutSession.line_items}
187
- trialInDays={state.checkoutSession.subscription_data?.trial_period_days || 0}
188
- trialEnd={state.checkoutSession.subscription_data?.trial_end || 0}
200
+ trialInDays={trialInDays}
201
+ trialEnd={trialEnd}
189
202
  billingThreshold={Math.max(
190
203
  state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
191
204
  // @ts-ignore