@blocklet/payment-react 1.13.159 → 1.13.161
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/components/input.d.ts +3 -1
- package/es/components/input.js +12 -3
- package/es/history/invoice/list.js +1 -1
- package/es/history/payment/list.js +1 -1
- package/es/index.d.ts +5 -1
- package/es/index.js +8 -0
- package/es/locales/en.js +13 -3
- package/es/locales/zh.js +13 -3
- package/es/payment/form/address.js +2 -1
- package/es/payment/form/currency.d.ts +9 -0
- package/es/payment/form/currency.js +81 -0
- package/es/payment/form/index.js +10 -44
- package/es/payment/index.js +11 -49
- package/es/payment/product-item.d.ts +4 -3
- package/es/payment/product-item.js +13 -4
- package/es/payment/success.d.ts +8 -2
- package/es/payment/success.js +5 -2
- package/es/payment/summary.d.ts +21 -8
- package/es/payment/summary.js +28 -12
- package/es/util.d.ts +6 -3
- package/es/util.js +19 -8
- package/lib/components/input.d.ts +3 -1
- package/lib/components/input.js +4 -2
- package/lib/history/invoice/list.js +1 -1
- package/lib/history/payment/list.js +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +32 -0
- package/lib/locales/en.js +13 -3
- package/lib/locales/zh.js +13 -3
- package/lib/payment/form/address.js +4 -1
- package/lib/payment/form/currency.d.ts +9 -0
- package/lib/payment/form/currency.js +106 -0
- package/lib/payment/form/index.js +8 -60
- package/lib/payment/index.js +13 -49
- package/lib/payment/product-item.d.ts +4 -3
- package/lib/payment/product-item.js +5 -4
- package/lib/payment/success.d.ts +8 -2
- package/lib/payment/success.js +6 -2
- package/lib/payment/summary.d.ts +21 -8
- package/lib/payment/summary.js +26 -11
- package/lib/util.d.ts +6 -3
- package/lib/util.js +22 -9
- package/package.json +10 -10
- package/src/components/input.tsx +12 -2
- package/src/history/invoice/list.tsx +1 -1
- package/src/history/payment/list.tsx +1 -1
- package/src/index.ts +8 -0
- package/src/locales/en.tsx +14 -1
- package/src/locales/zh.tsx +12 -1
- package/src/payment/form/address.tsx +1 -0
- package/src/payment/form/currency.tsx +91 -0
- package/src/payment/form/index.tsx +12 -53
- package/src/payment/index.tsx +18 -50
- package/src/payment/product-item.tsx +16 -11
- package/src/payment/success.tsx +9 -2
- package/src/payment/summary.tsx +41 -21
- package/src/util.ts +24 -10
package/lib/payment/index.js
CHANGED
|
@@ -223,6 +223,12 @@ function PaymentInner({
|
|
|
223
223
|
_Toast.default.error((0, _util.formatError)(err));
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
+
const handlePaid = result => {
|
|
227
|
+
setState({
|
|
228
|
+
checkoutSession: result.checkoutSession
|
|
229
|
+
});
|
|
230
|
+
onPaid(result);
|
|
231
|
+
};
|
|
226
232
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.FormProvider, {
|
|
227
233
|
...methods,
|
|
228
234
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
|
|
@@ -252,12 +258,15 @@ function PaymentInner({
|
|
|
252
258
|
children: [mode === "standalone" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_header.default, {
|
|
253
259
|
checkoutSession: state.checkoutSession
|
|
254
260
|
}) : null, /* @__PURE__ */(0, _jsxRuntime.jsx)(_summary.default, {
|
|
255
|
-
|
|
261
|
+
items: state.checkoutSession.line_items,
|
|
262
|
+
trialInDays: state.checkoutSession.subscription_data?.trial_period_days || 0,
|
|
256
263
|
currency,
|
|
257
264
|
onUpsell,
|
|
258
265
|
onDownsell,
|
|
259
266
|
onApplyCrossSell,
|
|
260
|
-
onCancelCrossSell
|
|
267
|
+
onCancelCrossSell,
|
|
268
|
+
checkoutSessionId: state.checkoutSession.id,
|
|
269
|
+
crossSellBehavior: state.checkoutSession.cross_sell_behavior
|
|
261
270
|
})]
|
|
262
271
|
})
|
|
263
272
|
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
@@ -267,13 +276,14 @@ function PaymentInner({
|
|
|
267
276
|
children: [completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_success.default, {
|
|
268
277
|
payee: (0, _util.getStatementDescriptor)(state.checkoutSession.line_items),
|
|
269
278
|
action: state.checkoutSession.mode,
|
|
279
|
+
subscriptionId: state.checkoutSession.subscription_id,
|
|
270
280
|
message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${state.checkoutSession.mode}`)
|
|
271
281
|
}), !completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
|
|
272
282
|
checkoutSession: state.checkoutSession,
|
|
273
283
|
paymentMethods,
|
|
274
284
|
paymentIntent,
|
|
275
285
|
customer,
|
|
276
|
-
onPaid,
|
|
286
|
+
onPaid: handlePaid,
|
|
277
287
|
onError,
|
|
278
288
|
mode
|
|
279
289
|
})]
|
|
@@ -365,52 +375,6 @@ const Root = exports.Root = (0, _system.styled)(_material.Box)`
|
|
|
365
375
|
.cko-payment-methods {
|
|
366
376
|
}
|
|
367
377
|
|
|
368
|
-
.cko-payment-card {
|
|
369
|
-
position: relative;
|
|
370
|
-
border: 2px solid #3773f2;
|
|
371
|
-
padding: 5px 10px;
|
|
372
|
-
margin: 5px 0;
|
|
373
|
-
cursor: pointer;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
.cko-payment-card::before {
|
|
377
|
-
content: '';
|
|
378
|
-
position: absolute;
|
|
379
|
-
right: 0;
|
|
380
|
-
top: 0;
|
|
381
|
-
border: 12px solid #3773f2;
|
|
382
|
-
border-bottom-color: transparent;
|
|
383
|
-
border-left-color: transparent;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
.cko-payment-card-unselect {
|
|
387
|
-
border: 2px solid #ddd;
|
|
388
|
-
padding: 5px 10px;
|
|
389
|
-
margin: 5px 0;
|
|
390
|
-
cursor: pointer;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
.cko-payment-card:nth-child(odd) {
|
|
394
|
-
margin-right: 8px;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
.cko-payment-card-unselect:nth-child(odd) {
|
|
398
|
-
margin-right: 8px;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
.cko-payment-card::after {
|
|
402
|
-
content: '';
|
|
403
|
-
width: 6px;
|
|
404
|
-
height: 10px;
|
|
405
|
-
position: absolute;
|
|
406
|
-
right: 3px;
|
|
407
|
-
top: 0px;
|
|
408
|
-
border: 2px solid #fff;
|
|
409
|
-
border-top-color: transparent;
|
|
410
|
-
border-left-color: transparent;
|
|
411
|
-
transform: rotate(35deg);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
378
|
.cko-payment-submit {
|
|
415
379
|
.MuiButtonBase-root {
|
|
416
380
|
border-radius: 0;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
3
3
|
type Props = {
|
|
4
4
|
item: TLineItemExpanded;
|
|
5
|
-
|
|
5
|
+
items: TLineItemExpanded[];
|
|
6
|
+
trialInDays: number;
|
|
6
7
|
currency: TPaymentCurrency;
|
|
7
8
|
onUpsell: Function;
|
|
8
9
|
onDownsell: Function;
|
|
9
10
|
mode?: 'normal' | 'cross-sell';
|
|
10
11
|
children?: React.ReactNode;
|
|
11
12
|
};
|
|
12
|
-
declare function ProductItem({ item,
|
|
13
|
+
declare function ProductItem({ item, items, trialInDays, currency, mode, children, onUpsell, onDownsell, }: Props): import("react").JSX.Element;
|
|
13
14
|
declare namespace ProductItem {
|
|
14
15
|
var defaultProps: {
|
|
15
16
|
mode: string;
|
|
@@ -18,7 +18,8 @@ ProductItem.defaultProps = {
|
|
|
18
18
|
};
|
|
19
19
|
function ProductItem({
|
|
20
20
|
item,
|
|
21
|
-
|
|
21
|
+
items,
|
|
22
|
+
trialInDays,
|
|
22
23
|
currency,
|
|
23
24
|
mode,
|
|
24
25
|
children,
|
|
@@ -29,10 +30,10 @@ function ProductItem({
|
|
|
29
30
|
t,
|
|
30
31
|
locale
|
|
31
32
|
} = (0, _context.useLocaleContext)();
|
|
32
|
-
const pricing = (0, _util.formatLineItemPricing)(item, currency,
|
|
33
|
-
const saving = (0, _util.formatUpsellSaving)(
|
|
33
|
+
const pricing = (0, _util.formatLineItemPricing)(item, currency, trialInDays, locale);
|
|
34
|
+
const saving = (0, _util.formatUpsellSaving)(items, currency);
|
|
34
35
|
const metered = item.price?.recurring?.usage_type === "metered" ? t("common.metered") : "";
|
|
35
|
-
const canUpsell = mode === "normal" &&
|
|
36
|
+
const canUpsell = mode === "normal" && items.length === 1;
|
|
36
37
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
37
38
|
direction: "column",
|
|
38
39
|
alignItems: "flex-start",
|
package/lib/payment/success.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ type Props = {
|
|
|
3
3
|
message: string;
|
|
4
4
|
action: string;
|
|
5
5
|
payee: string;
|
|
6
|
+
subscriptionId?: string;
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
declare function PaymentSuccess({ message, action, payee, subscriptionId }: Props): import("react").JSX.Element;
|
|
9
|
+
declare namespace PaymentSuccess {
|
|
10
|
+
var defaultProps: {
|
|
11
|
+
subscriptionId: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export default PaymentSuccess;
|
package/lib/payment/success.js
CHANGED
|
@@ -13,7 +13,8 @@ var _payment = require("../contexts/payment");
|
|
|
13
13
|
function PaymentSuccess({
|
|
14
14
|
message,
|
|
15
15
|
action,
|
|
16
|
-
payee
|
|
16
|
+
payee,
|
|
17
|
+
subscriptionId
|
|
17
18
|
}) {
|
|
18
19
|
const {
|
|
19
20
|
t
|
|
@@ -61,7 +62,7 @@ function PaymentSuccess({
|
|
|
61
62
|
mt: 2
|
|
62
63
|
},
|
|
63
64
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Link, {
|
|
64
|
-
href: (0, _ufo.joinURL)(prefix,
|
|
65
|
+
href: (0, _ufo.joinURL)(prefix, `/customer/subscription/${subscriptionId}`),
|
|
65
66
|
children: t("payment.checkout.portal", {
|
|
66
67
|
payee
|
|
67
68
|
})
|
|
@@ -70,6 +71,9 @@ function PaymentSuccess({
|
|
|
70
71
|
})
|
|
71
72
|
});
|
|
72
73
|
}
|
|
74
|
+
PaymentSuccess.defaultProps = {
|
|
75
|
+
subscriptionId: ""
|
|
76
|
+
};
|
|
73
77
|
const Div = (0, _system.styled)("div")`
|
|
74
78
|
width: 80px;
|
|
75
79
|
height: 115px;
|
package/lib/payment/summary.d.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
3
3
|
type Props = {
|
|
4
|
-
|
|
4
|
+
items: TLineItemExpanded[];
|
|
5
5
|
currency: TPaymentCurrency;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
trialInDays: number;
|
|
7
|
+
onUpsell?: Function;
|
|
8
|
+
onDownsell?: Function;
|
|
9
|
+
onApplyCrossSell?: Function;
|
|
10
|
+
onCancelCrossSell?: Function;
|
|
11
|
+
checkoutSessionId?: string;
|
|
12
|
+
crossSellBehavior?: string;
|
|
10
13
|
};
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
declare function PaymentSummary({ items, currency, trialInDays, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, checkoutSessionId, crossSellBehavior, ...rest }: Props): import("react").JSX.Element;
|
|
15
|
+
declare namespace PaymentSummary {
|
|
16
|
+
var defaultProps: {
|
|
17
|
+
onUpsell: any;
|
|
18
|
+
onDownsell: any;
|
|
19
|
+
onApplyCrossSell: any;
|
|
20
|
+
onCancelCrossSell: any;
|
|
21
|
+
checkoutSessionId: string;
|
|
22
|
+
crossSellBehavior: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export default PaymentSummary;
|
package/lib/payment/summary.js
CHANGED
|
@@ -47,13 +47,25 @@ async function fetchCrossSell(id) {
|
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
PaymentSummary.defaultProps = {
|
|
51
|
+
onUpsell: _noop.default,
|
|
52
|
+
onDownsell: _noop.default,
|
|
53
|
+
onApplyCrossSell: _noop.default,
|
|
54
|
+
onCancelCrossSell: _noop.default,
|
|
55
|
+
checkoutSessionId: "",
|
|
56
|
+
crossSellBehavior: ""
|
|
57
|
+
};
|
|
50
58
|
function PaymentSummary({
|
|
51
|
-
|
|
59
|
+
items,
|
|
52
60
|
currency,
|
|
61
|
+
trialInDays,
|
|
53
62
|
onUpsell,
|
|
54
63
|
onDownsell,
|
|
55
64
|
onApplyCrossSell,
|
|
56
|
-
onCancelCrossSell
|
|
65
|
+
onCancelCrossSell,
|
|
66
|
+
checkoutSessionId,
|
|
67
|
+
crossSellBehavior,
|
|
68
|
+
...rest
|
|
57
69
|
}) {
|
|
58
70
|
const {
|
|
59
71
|
t,
|
|
@@ -66,8 +78,8 @@ function PaymentSummary({
|
|
|
66
78
|
const {
|
|
67
79
|
data,
|
|
68
80
|
runAsync
|
|
69
|
-
} = (0, _ahooks.useRequest)(() => fetchCrossSell(
|
|
70
|
-
const headlines = (0, _util.formatCheckoutHeadlines)(
|
|
81
|
+
} = (0, _ahooks.useRequest)(() => checkoutSessionId ? fetchCrossSell(checkoutSessionId) : Promise.resolve(null));
|
|
82
|
+
const headlines = (0, _util.formatCheckoutHeadlines)(items, currency, trialInDays, locale);
|
|
71
83
|
(0, _useBus.default)("error.REQUIRE_CROSS_SELL", () => {
|
|
72
84
|
setState({
|
|
73
85
|
shake: true
|
|
@@ -121,6 +133,7 @@ function PaymentSummary({
|
|
|
121
133
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
122
134
|
className: "cko-product",
|
|
123
135
|
direction: "column",
|
|
136
|
+
...rest,
|
|
124
137
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
125
138
|
className: "cko-product-summary",
|
|
126
139
|
direction: "column",
|
|
@@ -146,9 +159,10 @@ function PaymentSummary({
|
|
|
146
159
|
})]
|
|
147
160
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
148
161
|
spacing: 2,
|
|
149
|
-
children:
|
|
162
|
+
children: items.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_productItem.default, {
|
|
150
163
|
item: x,
|
|
151
|
-
|
|
164
|
+
items,
|
|
165
|
+
trialInDays,
|
|
152
166
|
currency,
|
|
153
167
|
onUpsell: handleUpsell,
|
|
154
168
|
onDownsell: handleDownsell,
|
|
@@ -162,7 +176,7 @@ function PaymentSummary({
|
|
|
162
176
|
children: t("payment.checkout.cross_sell.remove")
|
|
163
177
|
})
|
|
164
178
|
}, x.price_id))
|
|
165
|
-
}), data &&
|
|
179
|
+
}), data && items.some(x => x.price_id === data.id) === false && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Grow, {
|
|
166
180
|
in: true,
|
|
167
181
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
168
182
|
direction: "column",
|
|
@@ -185,7 +199,8 @@ function PaymentSummary({
|
|
|
185
199
|
price_id: data.id,
|
|
186
200
|
cross_sell: true
|
|
187
201
|
},
|
|
188
|
-
|
|
202
|
+
items,
|
|
203
|
+
trialInDays,
|
|
189
204
|
currency,
|
|
190
205
|
onUpsell: _noop.default,
|
|
191
206
|
onDownsell: _noop.default
|
|
@@ -197,7 +212,7 @@ function PaymentSummary({
|
|
|
197
212
|
width: 1
|
|
198
213
|
},
|
|
199
214
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
200
|
-
children:
|
|
215
|
+
children: crossSellBehavior === "required" && /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
201
216
|
label: t("payment.checkout.required"),
|
|
202
217
|
color: "info",
|
|
203
218
|
variant: "outlined",
|
|
@@ -208,8 +223,8 @@ function PaymentSummary({
|
|
|
208
223
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
|
|
209
224
|
size: "small",
|
|
210
225
|
loadingPosition: "end",
|
|
211
|
-
color:
|
|
212
|
-
variant:
|
|
226
|
+
color: crossSellBehavior === "required" ? "info" : "info",
|
|
227
|
+
variant: crossSellBehavior === "required" ? "text" : "text",
|
|
213
228
|
loading: state.loading,
|
|
214
229
|
onClick: handleApplyCrossSell,
|
|
215
230
|
children: t("payment.checkout.cross_sell.add")
|
package/lib/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { PriceCurrency, PriceRecurring,
|
|
2
|
+
import type { PriceCurrency, PriceRecurring, TLineItemExpanded, TPaymentCurrency, TPaymentMethodExpanded, TPrice, TSubscriptionExpanded, TSubscriptionItemExpanded } from '@blocklet/payment-types';
|
|
3
3
|
export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
4
4
|
export declare const getPrefix: () => any;
|
|
5
5
|
export declare function formatToDate(date: Date | string | number, locale?: string): any;
|
|
@@ -34,8 +34,8 @@ export declare function getCheckoutAmount(items: TLineItemExpanded[], currency:
|
|
|
34
34
|
tax: string;
|
|
35
35
|
};
|
|
36
36
|
export declare function getRecurringPeriod(recurring: PriceRecurring): number;
|
|
37
|
-
export declare function formatUpsellSaving(
|
|
38
|
-
export declare function formatCheckoutHeadlines(
|
|
37
|
+
export declare function formatUpsellSaving(items: TLineItemExpanded[], currency: TPaymentCurrency): string;
|
|
38
|
+
export declare function formatCheckoutHeadlines(items: TLineItemExpanded[], currency: TPaymentCurrency, trialInDays: number, locale?: string): {
|
|
39
39
|
action: string;
|
|
40
40
|
amount: string;
|
|
41
41
|
then?: string;
|
|
@@ -57,3 +57,6 @@ export declare const getSubscriptionAction: (subscription: TSubscriptionExpanded
|
|
|
57
57
|
canRenew: boolean;
|
|
58
58
|
} | null;
|
|
59
59
|
export declare const mergeExtraParams: (extra?: Record<string, any>) => string;
|
|
60
|
+
export declare const flattenPaymentMethods: (methods?: TPaymentMethodExpanded[]) => import("sequelize").InferAttributes<import("@blocklet/payment-types").PaymentCurrency, {
|
|
61
|
+
omit: never;
|
|
62
|
+
}>[];
|
package/lib/util.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.PAYMENT_KIT_DID = void 0;
|
|
7
7
|
exports.findCurrency = findCurrency;
|
|
8
|
+
exports.flattenPaymentMethods = void 0;
|
|
8
9
|
exports.formatAmount = formatAmount;
|
|
9
10
|
exports.formatCheckoutHeadlines = formatCheckoutHeadlines;
|
|
10
11
|
exports.formatDateTime = formatDateTime;
|
|
@@ -341,8 +342,7 @@ function getRecurringPeriod(recurring) {
|
|
|
341
342
|
throw new Error(`Unsupported recurring interval: ${interval}`);
|
|
342
343
|
}
|
|
343
344
|
}
|
|
344
|
-
function formatUpsellSaving(
|
|
345
|
-
const items = session.line_items;
|
|
345
|
+
function formatUpsellSaving(items, currency) {
|
|
346
346
|
if (items[0]?.upsell_price_id) {
|
|
347
347
|
return "0";
|
|
348
348
|
}
|
|
@@ -365,9 +365,8 @@ function formatUpsellSaving(session, currency) {
|
|
|
365
365
|
const after = new _util.BN(to.total);
|
|
366
366
|
return Number(before.sub(after).mul(new _util.BN(100)).div(before).toString()).toFixed(0);
|
|
367
367
|
}
|
|
368
|
-
function formatCheckoutHeadlines(
|
|
369
|
-
const
|
|
370
|
-
const trial = session.subscription_data?.trial_period_days || 0;
|
|
368
|
+
function formatCheckoutHeadlines(items, currency, trialInDays, locale = "en") {
|
|
369
|
+
const trial = trialInDays || 0;
|
|
371
370
|
const brand = getStatementDescriptor(items);
|
|
372
371
|
const {
|
|
373
372
|
total
|
|
@@ -526,9 +525,6 @@ const getSubscriptionTimeSummary = subscription => {
|
|
|
526
525
|
exports.getSubscriptionTimeSummary = getSubscriptionTimeSummary;
|
|
527
526
|
const getSubscriptionAction = subscription => {
|
|
528
527
|
if (subscription.status === "active" || subscription.status === "trialing") {
|
|
529
|
-
if (subscription.cancel_at) {
|
|
530
|
-
return null;
|
|
531
|
-
}
|
|
532
528
|
if (subscription.cancel_at_period_end) {
|
|
533
529
|
if (subscription.cancelation_details?.reason === "payment_failed") {
|
|
534
530
|
return null;
|
|
@@ -540,6 +536,9 @@ const getSubscriptionAction = subscription => {
|
|
|
540
536
|
canRenew: false
|
|
541
537
|
};
|
|
542
538
|
}
|
|
539
|
+
if (subscription.cancel_at && subscription.cancel_at !== subscription.current_period_end) {
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
543
542
|
return {
|
|
544
543
|
action: "cancel",
|
|
545
544
|
variant: "outlined",
|
|
@@ -574,4 +573,18 @@ const mergeExtraParams = (extra = {}) => {
|
|
|
574
573
|
});
|
|
575
574
|
return params.toString();
|
|
576
575
|
};
|
|
577
|
-
exports.mergeExtraParams = mergeExtraParams;
|
|
576
|
+
exports.mergeExtraParams = mergeExtraParams;
|
|
577
|
+
const flattenPaymentMethods = (methods = []) => {
|
|
578
|
+
const out = [];
|
|
579
|
+
methods.forEach(method => {
|
|
580
|
+
const currencies = method.paymentCurrencies || method.payment_currencies || [];
|
|
581
|
+
currencies.forEach(currency => {
|
|
582
|
+
out.push({
|
|
583
|
+
...currency,
|
|
584
|
+
method
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
return out;
|
|
589
|
+
};
|
|
590
|
+
exports.flattenPaymentMethods = flattenPaymentMethods;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.161",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@arcblock/did-connect": "^2.9.
|
|
56
|
-
"@arcblock/ux": "^2.9.
|
|
57
|
-
"@mui/icons-material": "^5.15.
|
|
58
|
-
"@mui/lab": "^5.0.0-alpha.
|
|
59
|
-
"@mui/material": "^5.15.
|
|
60
|
-
"@mui/styles": "^5.15.
|
|
61
|
-
"@mui/system": "^5.15.
|
|
55
|
+
"@arcblock/did-connect": "^2.9.39",
|
|
56
|
+
"@arcblock/ux": "^2.9.39",
|
|
57
|
+
"@mui/icons-material": "^5.15.11",
|
|
58
|
+
"@mui/lab": "^5.0.0-alpha.166",
|
|
59
|
+
"@mui/material": "^5.15.11",
|
|
60
|
+
"@mui/styles": "^5.15.11",
|
|
61
|
+
"@mui/system": "^5.15.11",
|
|
62
62
|
"@ocap/util": "^1.18.110",
|
|
63
63
|
"@stripe/react-stripe-js": "^2.4.0",
|
|
64
64
|
"@stripe/stripe-js": "^2.4.0",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"@babel/core": "^7.23.9",
|
|
90
90
|
"@babel/preset-env": "^7.23.9",
|
|
91
91
|
"@babel/preset-react": "^7.23.3",
|
|
92
|
-
"@blocklet/payment-types": "1.13.
|
|
92
|
+
"@blocklet/payment-types": "1.13.161",
|
|
93
93
|
"@storybook/addon-essentials": "^7.6.13",
|
|
94
94
|
"@storybook/addon-interactions": "^7.6.13",
|
|
95
95
|
"@storybook/addon-links": "^7.6.13",
|
|
@@ -118,5 +118,5 @@
|
|
|
118
118
|
"vite-plugin-babel": "^1.2.0",
|
|
119
119
|
"vite-plugin-node-polyfills": "^0.19.0"
|
|
120
120
|
},
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "55cb16d9cd06b91b949a1a1c88b14670b0c1aca8"
|
|
122
122
|
}
|
package/src/components/input.tsx
CHANGED
|
@@ -8,6 +8,7 @@ type InputProps = TextFieldProps & {
|
|
|
8
8
|
placeholder?: string;
|
|
9
9
|
errorPosition?: 'right' | 'bottom';
|
|
10
10
|
rules?: RegisterOptions;
|
|
11
|
+
wrapperStyle?: React.CSSProperties;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
FormInput.defaultProps = {
|
|
@@ -15,6 +16,7 @@ FormInput.defaultProps = {
|
|
|
15
16
|
placeholder: '',
|
|
16
17
|
errorPosition: 'bottom',
|
|
17
18
|
rules: {},
|
|
19
|
+
wrapperStyle: {},
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export function FormInputError({ error }: { error: string }) {
|
|
@@ -27,7 +29,15 @@ export function FormInputError({ error }: { error: string }) {
|
|
|
27
29
|
);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export default function FormInput({
|
|
32
|
+
export default function FormInput({
|
|
33
|
+
name,
|
|
34
|
+
label,
|
|
35
|
+
placeholder,
|
|
36
|
+
rules,
|
|
37
|
+
errorPosition,
|
|
38
|
+
wrapperStyle,
|
|
39
|
+
...rest
|
|
40
|
+
}: InputProps) {
|
|
31
41
|
const { control, formState } = useFormContext();
|
|
32
42
|
const error = get(formState.errors, name)?.message as string;
|
|
33
43
|
return (
|
|
@@ -36,7 +46,7 @@ export default function FormInput({ name, label, placeholder, rules, errorPositi
|
|
|
36
46
|
control={control}
|
|
37
47
|
rules={rules}
|
|
38
48
|
render={({ field }) => (
|
|
39
|
-
<Box sx={{ width: '100%',
|
|
49
|
+
<Box sx={{ width: '100%', ...wrapperStyle }}>
|
|
40
50
|
{!!label && <FormLabel>{label}</FormLabel>}
|
|
41
51
|
<TextField
|
|
42
52
|
fullWidth
|
|
@@ -85,7 +85,7 @@ export default function CustomerPaymentList({ customer_id }: Props) {
|
|
|
85
85
|
</Box>
|
|
86
86
|
<Box flex={2}>
|
|
87
87
|
<Typography textAlign="right">
|
|
88
|
-
{fromUnitToToken(item.
|
|
88
|
+
{fromUnitToToken(item.amount_received, item.paymentCurrency.decimal)}
|
|
89
89
|
{item.paymentCurrency.symbol}
|
|
90
90
|
</Typography>
|
|
91
91
|
</Box>
|
package/src/index.ts
CHANGED
|
@@ -13,9 +13,13 @@ import CustomerInvoiceList from './history/invoice/list';
|
|
|
13
13
|
import MiniInvoiceList from './history/mini-invoice/list';
|
|
14
14
|
import CustomerPaymentList from './history/payment/list';
|
|
15
15
|
import Amount from './payment/amount';
|
|
16
|
+
import AddressForm from './payment/form/address';
|
|
17
|
+
import CurrencySelector from './payment/form/currency';
|
|
16
18
|
import PhoneInput from './payment/form/phone';
|
|
19
|
+
import StripeForm from './payment/form/stripe';
|
|
17
20
|
import Payment from './payment/index';
|
|
18
21
|
import ProductSkeleton from './payment/product-skeleton';
|
|
22
|
+
import PaymentSummary from './payment/summary';
|
|
19
23
|
|
|
20
24
|
export * from './util';
|
|
21
25
|
export * from './contexts/payment';
|
|
@@ -27,13 +31,17 @@ export {
|
|
|
27
31
|
dayjs,
|
|
28
32
|
FormInput,
|
|
29
33
|
PhoneInput,
|
|
34
|
+
AddressForm,
|
|
35
|
+
StripeForm,
|
|
30
36
|
Status,
|
|
31
37
|
Livemode,
|
|
32
38
|
Switch,
|
|
33
39
|
ConfirmDialog,
|
|
34
40
|
CheckoutForm,
|
|
35
41
|
CheckoutTable,
|
|
42
|
+
CurrencySelector,
|
|
36
43
|
Payment,
|
|
44
|
+
PaymentSummary,
|
|
37
45
|
PricingTable,
|
|
38
46
|
ProductSkeleton,
|
|
39
47
|
Amount,
|
package/src/locales/en.tsx
CHANGED
|
@@ -189,7 +189,7 @@ export default flat({
|
|
|
189
189
|
title: 'Renew your subscription',
|
|
190
190
|
description: 'Your subscription will no longer be canceled, it will renew on {date}',
|
|
191
191
|
},
|
|
192
|
-
|
|
192
|
+
changePlan: {
|
|
193
193
|
button: 'Update',
|
|
194
194
|
current: 'Current',
|
|
195
195
|
pay: 'Payment Required',
|
|
@@ -203,6 +203,18 @@ export default flat({
|
|
|
203
203
|
appliedCredit: 'Credit applied',
|
|
204
204
|
newCredit: 'Credit issued',
|
|
205
205
|
remaining: 'Amount due today',
|
|
206
|
+
tableNotFound: 'Plan updates are not available',
|
|
207
|
+
},
|
|
208
|
+
changePayment: {
|
|
209
|
+
limit:
|
|
210
|
+
'Your changes to payment method will not affect existing open or past-due invoices, all future payments will use the new payment method unless you change it again.',
|
|
211
|
+
review: 'Review subscription items',
|
|
212
|
+
select: 'Select payment method',
|
|
213
|
+
submit: 'Confirm change',
|
|
214
|
+
confirm:
|
|
215
|
+
'By confirming this change, you allow {payee} to charge {symbol} from your account for future payments in accordance with their terms. You can always change your payment method.',
|
|
216
|
+
completed:
|
|
217
|
+
'Your payment method has been successfully updated, all future payments will use the new payment method unless you change it again.',
|
|
206
218
|
},
|
|
207
219
|
invoice: {
|
|
208
220
|
summary: 'Summary',
|
|
@@ -233,6 +245,7 @@ export default flat({
|
|
|
233
245
|
title: 'Manage subscriptions',
|
|
234
246
|
current: 'Current subscription',
|
|
235
247
|
empty: 'There are no subscriptions here',
|
|
248
|
+
changePayment: 'Change payment method',
|
|
236
249
|
},
|
|
237
250
|
},
|
|
238
251
|
},
|
package/src/locales/zh.tsx
CHANGED
|
@@ -184,7 +184,7 @@ export default flat({
|
|
|
184
184
|
title: '续订您的订阅',
|
|
185
185
|
description: '您的订阅将不再被取消,将在{date}续订',
|
|
186
186
|
},
|
|
187
|
-
|
|
187
|
+
changePlan: {
|
|
188
188
|
button: '更新',
|
|
189
189
|
current: '当前订阅',
|
|
190
190
|
pay: '需要支付',
|
|
@@ -198,6 +198,16 @@ export default flat({
|
|
|
198
198
|
appliedCredit: '信用扣除',
|
|
199
199
|
newCredit: '信用增加',
|
|
200
200
|
remaining: '还需支付',
|
|
201
|
+
tableNotFound: '套餐变更不可用',
|
|
202
|
+
},
|
|
203
|
+
changePayment: {
|
|
204
|
+
limit:
|
|
205
|
+
'你对支付方式的变更不会影响已经生成或者欠费的账单,只会影响未来的账单。你可以在下一张账单生成之前变更支付方式。',
|
|
206
|
+
review: '查看订阅详情',
|
|
207
|
+
select: '选择支付方式',
|
|
208
|
+
submit: '确认变更',
|
|
209
|
+
confirm: '确认变更方式意味着你允许{payee}使用新的支付方式支付你的未来账单。你可以随时再次变更支付方式。',
|
|
210
|
+
completed: '你的支付方式 已经更新成功。你可以在你的账户中查看此支付方式的详细信息。',
|
|
201
211
|
},
|
|
202
212
|
invoice: {
|
|
203
213
|
summary: '摘要',
|
|
@@ -228,6 +238,7 @@ export default flat({
|
|
|
228
238
|
title: '订阅管理',
|
|
229
239
|
current: '当前订阅',
|
|
230
240
|
empty: '没有任何订阅',
|
|
241
|
+
changePayment: '切换支付方式',
|
|
231
242
|
},
|
|
232
243
|
},
|
|
233
244
|
},
|