@blocklet/payment-react 1.14.34 → 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.
- package/es/payment/index.js +10 -2
- package/es/payment/summary.js +18 -15
- package/lib/payment/index.js +10 -2
- package/lib/payment/summary.js +18 -15
- package/package.json +3 -3
- package/src/payment/index.tsx +15 -2
- package/src/payment/summary.tsx +23 -15
package/es/payment/index.js
CHANGED
|
@@ -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
|
|
155
|
-
trialEnd
|
|
162
|
+
trialInDays,
|
|
163
|
+
trialEnd,
|
|
156
164
|
billingThreshold: Math.max(
|
|
157
165
|
state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
158
166
|
// @ts-ignore
|
package/es/payment/summary.js
CHANGED
|
@@ -54,24 +54,27 @@ function getStakingSetup(items, currency, billingThreshold = 0) {
|
|
|
54
54
|
licensed: new BN(0),
|
|
55
55
|
metered: new BN(0)
|
|
56
56
|
};
|
|
57
|
-
items.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
const recurringItems = items.map((x) => x.upsell_price || x.price).filter((x) => x.type === "recurring" && x.recurring);
|
|
58
|
+
if (recurringItems.length > 0) {
|
|
59
|
+
if (+billingThreshold) {
|
|
60
|
+
return fromTokenToUnit(billingThreshold, currency.decimal).toString();
|
|
61
|
+
}
|
|
62
|
+
items.forEach((x) => {
|
|
63
|
+
const price = x.upsell_price || x.price;
|
|
64
|
+
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
65
|
+
const amount = new BN(unit).mul(new BN(x.quantity));
|
|
66
|
+
if (price.type === "recurring" && price.recurring) {
|
|
67
|
+
if (price.recurring.usage_type === "licensed") {
|
|
68
|
+
staking.licensed = staking.licensed.add(amount);
|
|
69
|
+
}
|
|
70
|
+
if (price.recurring.usage_type === "metered") {
|
|
69
71
|
staking.metered = staking.metered.add(amount);
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
});
|
|
75
|
+
return staking.licensed.add(staking.metered).toString();
|
|
76
|
+
}
|
|
77
|
+
return "0";
|
|
75
78
|
}
|
|
76
79
|
PaymentSummary.defaultProps = {
|
|
77
80
|
onUpsell: noop,
|
package/lib/payment/index.js
CHANGED
|
@@ -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
|
|
215
|
-
trialEnd
|
|
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/lib/payment/summary.js
CHANGED
|
@@ -61,24 +61,27 @@ function getStakingSetup(items, currency, billingThreshold = 0) {
|
|
|
61
61
|
licensed: new _util.BN(0),
|
|
62
62
|
metered: new _util.BN(0)
|
|
63
63
|
};
|
|
64
|
-
items.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
const recurringItems = items.map(x => x.upsell_price || x.price).filter(x => x.type === "recurring" && x.recurring);
|
|
65
|
+
if (recurringItems.length > 0) {
|
|
66
|
+
if (+billingThreshold) {
|
|
67
|
+
return (0, _util.fromTokenToUnit)(billingThreshold, currency.decimal).toString();
|
|
68
|
+
}
|
|
69
|
+
items.forEach(x => {
|
|
70
|
+
const price = x.upsell_price || x.price;
|
|
71
|
+
const unit = (0, _util2.getPriceUintAmountByCurrency)(price, currency);
|
|
72
|
+
const amount = new _util.BN(unit).mul(new _util.BN(x.quantity));
|
|
73
|
+
if (price.type === "recurring" && price.recurring) {
|
|
74
|
+
if (price.recurring.usage_type === "licensed") {
|
|
75
|
+
staking.licensed = staking.licensed.add(amount);
|
|
76
|
+
}
|
|
77
|
+
if (price.recurring.usage_type === "metered") {
|
|
76
78
|
staking.metered = staking.metered.add(amount);
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
});
|
|
82
|
+
return staking.licensed.add(staking.metered).toString();
|
|
83
|
+
}
|
|
84
|
+
return "0";
|
|
82
85
|
}
|
|
83
86
|
PaymentSummary.defaultProps = {
|
|
84
87
|
onUpsell: _noop.default,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.14.
|
|
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.
|
|
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": "
|
|
126
|
+
"gitHead": "645ae0bdbab463eec878af0521eb982b51499639"
|
|
127
127
|
}
|
package/src/payment/index.tsx
CHANGED
|
@@ -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={
|
|
188
|
-
trialEnd={
|
|
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
|
package/src/payment/summary.tsx
CHANGED
|
@@ -100,25 +100,33 @@ function getStakingSetup(items: TLineItemExpanded[], currency: TPaymentCurrency,
|
|
|
100
100
|
metered: new BN(0),
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
const recurringItems = items
|
|
104
|
+
.map((x) => x.upsell_price || x.price)
|
|
105
|
+
.filter((x) => x.type === 'recurring' && x.recurring);
|
|
106
|
+
|
|
107
|
+
if (recurringItems.length > 0) {
|
|
108
|
+
if (+billingThreshold) {
|
|
109
|
+
return fromTokenToUnit(billingThreshold, currency.decimal).toString();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
items.forEach((x) => {
|
|
113
|
+
const price = x.upsell_price || x.price;
|
|
114
|
+
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
115
|
+
const amount = new BN(unit).mul(new BN(x.quantity));
|
|
116
|
+
if (price.type === 'recurring' && price.recurring) {
|
|
117
|
+
if (price.recurring.usage_type === 'licensed') {
|
|
118
|
+
staking.licensed = staking.licensed.add(amount);
|
|
119
|
+
}
|
|
120
|
+
if (price.recurring.usage_type === 'metered') {
|
|
115
121
|
staking.metered = staking.metered.add(amount);
|
|
116
122
|
}
|
|
117
123
|
}
|
|
118
|
-
}
|
|
119
|
-
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return staking.licensed.add(staking.metered).toString();
|
|
127
|
+
}
|
|
120
128
|
|
|
121
|
-
return
|
|
129
|
+
return '0';
|
|
122
130
|
}
|
|
123
131
|
|
|
124
132
|
PaymentSummary.defaultProps = {
|