@blocklet/payment-react 1.13.210 → 1.13.212
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/checkout/donate.d.ts +20 -0
- package/es/checkout/donate.js +199 -0
- package/es/checkout/form.d.ts +2 -1
- package/es/checkout/form.js +13 -2
- package/es/components/blockchain/tx.d.ts +2 -0
- package/es/components/blockchain/tx.js +16 -5
- package/es/components/safe-guard.d.ts +3 -0
- package/es/components/safe-guard.js +4 -0
- package/es/index.d.ts +3 -1
- package/es/index.js +5 -1
- package/es/locales/en.js +8 -0
- package/es/locales/zh.js +8 -0
- package/es/payment/error.d.ts +3 -1
- package/es/payment/error.js +4 -3
- package/es/payment/form/currency.js +10 -12
- package/es/payment/form/index.d.ts +1 -1
- package/es/payment/form/index.js +15 -3
- package/es/payment/index.d.ts +3 -3
- package/es/payment/index.js +38 -13
- package/es/payment/product-donation.d.ts +7 -0
- package/es/payment/product-donation.js +99 -0
- package/es/payment/skeleton/overview.js +2 -2
- package/es/payment/skeleton/payment.js +2 -5
- package/es/payment/success.d.ts +2 -1
- package/es/payment/success.js +21 -12
- package/es/payment/summary.d.ts +8 -2
- package/es/payment/summary.js +46 -29
- package/es/types/index.d.ts +2 -0
- package/es/util.d.ts +2 -0
- package/es/util.js +47 -3
- package/lib/checkout/donate.d.ts +20 -0
- package/lib/checkout/donate.js +284 -0
- package/lib/checkout/form.d.ts +2 -1
- package/lib/checkout/form.js +5 -2
- package/lib/components/blockchain/tx.d.ts +2 -0
- package/lib/components/blockchain/tx.js +3 -1
- package/lib/components/safe-guard.d.ts +3 -0
- package/lib/components/safe-guard.js +12 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +16 -0
- package/lib/locales/en.js +8 -0
- package/lib/locales/zh.js +8 -0
- package/lib/payment/error.d.ts +3 -1
- package/lib/payment/error.js +5 -3
- package/lib/payment/form/currency.js +10 -12
- package/lib/payment/form/index.d.ts +1 -1
- package/lib/payment/form/index.js +16 -4
- package/lib/payment/index.d.ts +3 -3
- package/lib/payment/index.js +56 -24
- package/lib/payment/product-donation.d.ts +7 -0
- package/lib/payment/product-donation.js +169 -0
- package/lib/payment/skeleton/overview.js +2 -2
- package/lib/payment/skeleton/payment.js +4 -8
- package/lib/payment/success.d.ts +2 -1
- package/lib/payment/success.js +3 -2
- package/lib/payment/summary.d.ts +8 -2
- package/lib/payment/summary.js +30 -7
- package/lib/types/index.d.ts +2 -0
- package/lib/util.d.ts +2 -0
- package/lib/util.js +44 -4
- package/package.json +6 -6
- package/src/checkout/donate.tsx +256 -0
- package/src/checkout/form.tsx +13 -4
- package/src/components/blockchain/tx.tsx +8 -1
- package/src/components/safe-guard.tsx +5 -0
- package/src/index.ts +4 -0
- package/src/locales/en.tsx +8 -0
- package/src/locales/zh.tsx +8 -0
- package/src/payment/error.tsx +4 -2
- package/src/payment/form/currency.tsx +11 -13
- package/src/payment/form/index.tsx +14 -4
- package/src/payment/index.tsx +40 -14
- package/src/payment/product-donation.tsx +118 -0
- package/src/payment/skeleton/overview.tsx +2 -2
- package/src/payment/skeleton/payment.tsx +1 -4
- package/src/payment/success.tsx +7 -2
- package/src/payment/summary.tsx +47 -28
- package/src/types/index.ts +2 -0
- package/src/util.ts +54 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { DonationSettings, TCheckoutSessionExpanded, TPaymentCurrency, TPaymentMethod } from '@blocklet/payment-types';
|
|
3
|
+
import { CheckoutProps } from '../types';
|
|
4
|
+
export type DonateHistory = {
|
|
5
|
+
supporters: TCheckoutSessionExpanded[];
|
|
6
|
+
currency: TPaymentCurrency;
|
|
7
|
+
method: TPaymentMethod;
|
|
8
|
+
total: number;
|
|
9
|
+
};
|
|
10
|
+
export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
11
|
+
settings: DonationSettings;
|
|
12
|
+
livemode?: boolean;
|
|
13
|
+
};
|
|
14
|
+
declare function CheckoutDonate({ settings, livemode, onPaid, onError }: DonateProps): import("react").JSX.Element;
|
|
15
|
+
declare namespace CheckoutDonate {
|
|
16
|
+
var defaultProps: {
|
|
17
|
+
livemode: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export default CheckoutDonate;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = CheckoutDonate;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
|
|
9
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
10
|
+
var _material = require("@mui/material");
|
|
11
|
+
var _ahooks = require("ahooks");
|
|
12
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
13
|
+
var _unionBy = _interopRequireDefault(require("lodash/unionBy"));
|
|
14
|
+
var _react = require("react");
|
|
15
|
+
var _api = _interopRequireDefault(require("../api"));
|
|
16
|
+
var _tx = _interopRequireDefault(require("../components/blockchain/tx"));
|
|
17
|
+
var _util = require("../util");
|
|
18
|
+
var _form = _interopRequireDefault(require("./form"));
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
+
const donationCache = {};
|
|
21
|
+
const createOrUpdateDonation = (settings, livemode = true) => {
|
|
22
|
+
if (!donationCache[settings.target]) {
|
|
23
|
+
donationCache[settings.target] = _api.default.post(`/api/donations?livemode=${livemode}`, (0, _omit.default)(settings, ["appearance"])).then(res => res.data).finally(() => {
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
delete donationCache[settings.target];
|
|
26
|
+
}, 3e3);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return donationCache[settings.target];
|
|
30
|
+
};
|
|
31
|
+
const supporterCache = {};
|
|
32
|
+
const fetchSupporters = target => {
|
|
33
|
+
if (!supporterCache[target]) {
|
|
34
|
+
supporterCache[target] = _api.default.get(`/api/donations?&target=${target}`).then(res => res.data).finally(() => {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
delete supporterCache[target];
|
|
37
|
+
}, 3e3);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return supporterCache[target];
|
|
41
|
+
};
|
|
42
|
+
function SupporterAvatar({
|
|
43
|
+
supporters = [],
|
|
44
|
+
total,
|
|
45
|
+
currency,
|
|
46
|
+
method
|
|
47
|
+
}) {
|
|
48
|
+
const {
|
|
49
|
+
t
|
|
50
|
+
} = (0, _context.useLocaleContext)();
|
|
51
|
+
const customers = (0, _unionBy.default)(supporters, "customer_did");
|
|
52
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
53
|
+
display: "flex",
|
|
54
|
+
flexDirection: "column",
|
|
55
|
+
alignItems: "center",
|
|
56
|
+
sx: {
|
|
57
|
+
".MuiAvatar-root": {
|
|
58
|
+
width: "32px",
|
|
59
|
+
height: "32px"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
gap: {
|
|
63
|
+
xs: 0.5,
|
|
64
|
+
sm: 1
|
|
65
|
+
},
|
|
66
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
67
|
+
component: "p",
|
|
68
|
+
color: "text.secondary",
|
|
69
|
+
children: t("payment.checkout.donation.summary", {
|
|
70
|
+
total
|
|
71
|
+
})
|
|
72
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.AvatarGroup, {
|
|
73
|
+
total,
|
|
74
|
+
max: 20,
|
|
75
|
+
children: customers.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
|
|
76
|
+
title: x.customer?.name,
|
|
77
|
+
src: `/.well-known/service/user/avatar/${x.customer?.did}?imageFilter=resize&w=48&h=48`,
|
|
78
|
+
variant: "circular",
|
|
79
|
+
sx: {
|
|
80
|
+
width: 32,
|
|
81
|
+
height: 32
|
|
82
|
+
}
|
|
83
|
+
}, x.id))
|
|
84
|
+
})]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function SupporterTable({
|
|
88
|
+
supporters = [],
|
|
89
|
+
total,
|
|
90
|
+
currency,
|
|
91
|
+
method
|
|
92
|
+
}) {
|
|
93
|
+
const {
|
|
94
|
+
t
|
|
95
|
+
} = (0, _context.useLocaleContext)();
|
|
96
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
97
|
+
display: "flex",
|
|
98
|
+
flexDirection: "column",
|
|
99
|
+
alignItems: "center",
|
|
100
|
+
sx: {
|
|
101
|
+
width: "100%"
|
|
102
|
+
},
|
|
103
|
+
gap: {
|
|
104
|
+
xs: 0.5,
|
|
105
|
+
sm: 1
|
|
106
|
+
},
|
|
107
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
108
|
+
component: "p",
|
|
109
|
+
color: "text.secondary",
|
|
110
|
+
children: t("payment.checkout.donation.summary", {
|
|
111
|
+
total
|
|
112
|
+
})
|
|
113
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Table, {
|
|
114
|
+
size: "small",
|
|
115
|
+
sx: {
|
|
116
|
+
width: "100%",
|
|
117
|
+
overflow: "hidden"
|
|
118
|
+
},
|
|
119
|
+
children: supporters.map(x => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.TableRow, {
|
|
120
|
+
sx: {
|
|
121
|
+
"> td": {
|
|
122
|
+
padding: "8px 16px 8px 0",
|
|
123
|
+
borderTop: "1px solid #e0e0e0",
|
|
124
|
+
borderBottom: "1px solid #e0e0e0"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TableCell, {
|
|
128
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
129
|
+
direction: "row",
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
spacing: 0.5,
|
|
132
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
|
|
133
|
+
src: `/.well-known/service/user/avatar/${x.customer?.did}?imageFilter=resize&w=48&h=48`,
|
|
134
|
+
variant: "circular",
|
|
135
|
+
sx: {
|
|
136
|
+
width: 24,
|
|
137
|
+
height: 24
|
|
138
|
+
}
|
|
139
|
+
}, x.id), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Hidden, {
|
|
140
|
+
smDown: true,
|
|
141
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
142
|
+
children: x.customer?.name
|
|
143
|
+
})
|
|
144
|
+
})]
|
|
145
|
+
})
|
|
146
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TableCell, {
|
|
147
|
+
align: "right",
|
|
148
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
149
|
+
direction: "row",
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
justifyContent: "flex-end",
|
|
152
|
+
spacing: 0.5,
|
|
153
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
154
|
+
fontWeight: 500,
|
|
155
|
+
component: "strong",
|
|
156
|
+
children: (0, _util.formatAmount)(x.amount_total, currency.decimal)
|
|
157
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
158
|
+
component: "span",
|
|
159
|
+
children: currency.symbol
|
|
160
|
+
})]
|
|
161
|
+
})
|
|
162
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Hidden, {
|
|
163
|
+
smDown: true,
|
|
164
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TableCell, {
|
|
165
|
+
align: "right",
|
|
166
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
167
|
+
children: (0, _util.formatDateTime)(x.created_at)
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TableCell, {
|
|
171
|
+
align: "right",
|
|
172
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_tx.default, {
|
|
173
|
+
method,
|
|
174
|
+
details: x.payment_details,
|
|
175
|
+
mode: "customer",
|
|
176
|
+
align: "right"
|
|
177
|
+
})
|
|
178
|
+
})]
|
|
179
|
+
}, x.id))
|
|
180
|
+
})]
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function CheckoutDonate({
|
|
184
|
+
settings,
|
|
185
|
+
livemode,
|
|
186
|
+
onPaid,
|
|
187
|
+
onError
|
|
188
|
+
}) {
|
|
189
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
190
|
+
open: false,
|
|
191
|
+
supporterLoaded: false,
|
|
192
|
+
exist: false
|
|
193
|
+
});
|
|
194
|
+
const donation = (0, _ahooks.useRequest)(() => createOrUpdateDonation(settings, livemode));
|
|
195
|
+
const supporters = (0, _ahooks.useRequest)(() => donation.data ? fetchSupporters(donation.data.id) : Promise.resolve({}));
|
|
196
|
+
(0, _react.useEffect)(() => {
|
|
197
|
+
if (donation.data && state.supporterLoaded === false) {
|
|
198
|
+
setState({
|
|
199
|
+
supporterLoaded: true
|
|
200
|
+
});
|
|
201
|
+
supporters.runAsync().catch(console.error);
|
|
202
|
+
}
|
|
203
|
+
}, [donation.data]);
|
|
204
|
+
const handlePaid = (...args) => {
|
|
205
|
+
if (onPaid) {
|
|
206
|
+
onPaid(...args);
|
|
207
|
+
}
|
|
208
|
+
supporters.runAsync().catch(console.error);
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
setState({
|
|
211
|
+
open: false
|
|
212
|
+
});
|
|
213
|
+
}, 3e3);
|
|
214
|
+
};
|
|
215
|
+
if (donation.error) {
|
|
216
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Alert, {
|
|
217
|
+
severity: "error",
|
|
218
|
+
children: (0, _util.formatError)(donation.error)
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (donation.loading || !donation.data) {
|
|
222
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {});
|
|
223
|
+
}
|
|
224
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
225
|
+
sx: {
|
|
226
|
+
width: "100%",
|
|
227
|
+
minWidth: 300,
|
|
228
|
+
maxWidth: 720
|
|
229
|
+
},
|
|
230
|
+
display: "flex",
|
|
231
|
+
flexDirection: "column",
|
|
232
|
+
alignItems: "center",
|
|
233
|
+
gap: {
|
|
234
|
+
xs: 1,
|
|
235
|
+
sm: 2
|
|
236
|
+
},
|
|
237
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
238
|
+
size: settings.appearance?.button?.size || "medium",
|
|
239
|
+
color: settings.appearance?.button?.color || "primary",
|
|
240
|
+
variant: settings.appearance?.button?.variant || "contained",
|
|
241
|
+
onClick: () => setState({
|
|
242
|
+
open: true
|
|
243
|
+
}),
|
|
244
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
245
|
+
direction: "row",
|
|
246
|
+
alignItems: "center",
|
|
247
|
+
spacing: 0.5,
|
|
248
|
+
children: [settings.appearance.button.icon, typeof settings.appearance.button.text === "string" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
249
|
+
children: settings.appearance.button.text
|
|
250
|
+
}) : settings.appearance.button.text]
|
|
251
|
+
})
|
|
252
|
+
}), supporters.data && settings.appearance.history.variant === "avatar" && /* @__PURE__ */(0, _jsxRuntime.jsx)(SupporterAvatar, {
|
|
253
|
+
...supporters.data
|
|
254
|
+
}), supporters.data && settings.appearance.history.variant === "table" && /* @__PURE__ */(0, _jsxRuntime.jsx)(SupporterTable, {
|
|
255
|
+
...supporters.data
|
|
256
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_Dialog.default, {
|
|
257
|
+
open: state.open,
|
|
258
|
+
title: settings.title,
|
|
259
|
+
maxWidth: "md",
|
|
260
|
+
showCloseButton: true,
|
|
261
|
+
disableBackdropClick: true,
|
|
262
|
+
disableEscapeKeyDown: true,
|
|
263
|
+
onClose: (e, reason) => setState({
|
|
264
|
+
open: reason === "backdropClick"
|
|
265
|
+
}),
|
|
266
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
267
|
+
sx: {
|
|
268
|
+
mb: 1,
|
|
269
|
+
mt: -2
|
|
270
|
+
},
|
|
271
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
|
|
272
|
+
id: donation.data.id,
|
|
273
|
+
onPaid: handlePaid,
|
|
274
|
+
onError,
|
|
275
|
+
action: settings.appearance?.button?.text,
|
|
276
|
+
mode: "inline"
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
})]
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
CheckoutDonate.defaultProps = {
|
|
283
|
+
livemode: true
|
|
284
|
+
};
|
package/lib/checkout/form.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CheckoutProps } from '../types';
|
|
3
|
-
declare function CheckoutForm({ id, mode, onPaid, onError, onChange, goBack, extraParams }: CheckoutProps): import("react").JSX.Element;
|
|
3
|
+
declare function CheckoutForm({ id, mode, onPaid, onError, onChange, goBack, extraParams, action, }: CheckoutProps): import("react").JSX.Element;
|
|
4
4
|
declare namespace CheckoutForm {
|
|
5
5
|
var defaultProps: {
|
|
6
6
|
onPaid: any;
|
|
@@ -9,6 +9,7 @@ declare namespace CheckoutForm {
|
|
|
9
9
|
(message?: any, ...optionalParams: any[]): void;
|
|
10
10
|
};
|
|
11
11
|
mode: string;
|
|
12
|
+
action: string;
|
|
12
13
|
extraParams: {};
|
|
13
14
|
};
|
|
14
15
|
}
|
package/lib/checkout/form.js
CHANGED
|
@@ -37,7 +37,8 @@ function CheckoutForm({
|
|
|
37
37
|
onError,
|
|
38
38
|
onChange,
|
|
39
39
|
goBack,
|
|
40
|
-
extraParams
|
|
40
|
+
extraParams,
|
|
41
|
+
action
|
|
41
42
|
}) {
|
|
42
43
|
if (!id.startsWith("plink_") && !id.startsWith("cs_")) {
|
|
43
44
|
throw new Error("Either a checkoutSession or a paymentLink id is required.");
|
|
@@ -81,12 +82,14 @@ function CheckoutForm({
|
|
|
81
82
|
onError: handleError,
|
|
82
83
|
onChange,
|
|
83
84
|
goBack,
|
|
84
|
-
mode
|
|
85
|
+
mode,
|
|
86
|
+
action
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
89
|
CheckoutForm.defaultProps = {
|
|
88
90
|
onPaid: _noop.default,
|
|
89
91
|
onError: console.error,
|
|
90
92
|
mode: "inline",
|
|
93
|
+
action: "",
|
|
91
94
|
extraParams: {}
|
|
92
95
|
};
|
|
@@ -4,10 +4,12 @@ declare function TxLink(props: {
|
|
|
4
4
|
details: PaymentDetails;
|
|
5
5
|
method: TPaymentMethod;
|
|
6
6
|
mode?: 'customer' | 'dashboard';
|
|
7
|
+
align?: 'left' | 'right';
|
|
7
8
|
}): import("react").JSX.Element;
|
|
8
9
|
declare namespace TxLink {
|
|
9
10
|
var defaultProps: {
|
|
10
11
|
mode: string;
|
|
12
|
+
align: string;
|
|
11
13
|
};
|
|
12
14
|
}
|
|
13
15
|
export default TxLink;
|
|
@@ -10,7 +10,8 @@ var _iconsMaterial = require("@mui/icons-material");
|
|
|
10
10
|
var _material = require("@mui/material");
|
|
11
11
|
var _util = require("../../util");
|
|
12
12
|
TxLink.defaultProps = {
|
|
13
|
-
mode: "dashboard"
|
|
13
|
+
mode: "dashboard",
|
|
14
|
+
align: "left"
|
|
14
15
|
};
|
|
15
16
|
function TxLink(props) {
|
|
16
17
|
const {
|
|
@@ -36,6 +37,7 @@ function TxLink(props) {
|
|
|
36
37
|
component: "span",
|
|
37
38
|
direction: "row",
|
|
38
39
|
alignItems: "center",
|
|
40
|
+
justifyContent: props.align === "left" ? "flex-start" : "flex-end",
|
|
39
41
|
spacing: 1,
|
|
40
42
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
41
43
|
component: "span",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = SafeGuard;
|
|
7
|
+
var _util = require("../util");
|
|
8
|
+
function SafeGuard({
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
return (0, _util.isPaymentKitMounted)() ? children : null;
|
|
12
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import api from './api';
|
|
2
|
+
import CheckoutDonate from './checkout/donate';
|
|
2
3
|
import CheckoutForm from './checkout/form';
|
|
3
4
|
import CheckoutTable from './checkout/table';
|
|
4
5
|
import TxLink from './components/blockchain/tx';
|
|
@@ -6,6 +7,7 @@ import ConfirmDialog from './components/confirm';
|
|
|
6
7
|
import FormInput from './components/input';
|
|
7
8
|
import Livemode from './components/livemode';
|
|
8
9
|
import PricingTable from './components/pricing-table';
|
|
10
|
+
import SafeGuard from './components/safe-guard';
|
|
9
11
|
import Status from './components/status';
|
|
10
12
|
import Switch from './components/switch-button';
|
|
11
13
|
import dayjs from './dayjs';
|
|
@@ -23,4 +25,4 @@ import PaymentSummary from './payment/summary';
|
|
|
23
25
|
export * from './util';
|
|
24
26
|
export * from './contexts/payment';
|
|
25
27
|
export { translations, createTranslator } from './locales';
|
|
26
|
-
export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, };
|
|
28
|
+
export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, SafeGuard, };
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
api: true,
|
|
8
|
+
CheckoutDonate: true,
|
|
8
9
|
CheckoutForm: true,
|
|
9
10
|
CheckoutTable: true,
|
|
10
11
|
TxLink: true,
|
|
@@ -12,6 +13,7 @@ var _exportNames = {
|
|
|
12
13
|
FormInput: true,
|
|
13
14
|
Livemode: true,
|
|
14
15
|
PricingTable: true,
|
|
16
|
+
SafeGuard: true,
|
|
15
17
|
Status: true,
|
|
16
18
|
Switch: true,
|
|
17
19
|
dayjs: true,
|
|
@@ -41,6 +43,12 @@ Object.defineProperty(exports, "Amount", {
|
|
|
41
43
|
return _amount.default;
|
|
42
44
|
}
|
|
43
45
|
});
|
|
46
|
+
Object.defineProperty(exports, "CheckoutDonate", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _donate.default;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
44
52
|
Object.defineProperty(exports, "CheckoutForm", {
|
|
45
53
|
enumerable: true,
|
|
46
54
|
get: function () {
|
|
@@ -125,6 +133,12 @@ Object.defineProperty(exports, "ProductSkeleton", {
|
|
|
125
133
|
return _productSkeleton.default;
|
|
126
134
|
}
|
|
127
135
|
});
|
|
136
|
+
Object.defineProperty(exports, "SafeGuard", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function () {
|
|
139
|
+
return _safeGuard.default;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
128
142
|
Object.defineProperty(exports, "Status", {
|
|
129
143
|
enumerable: true,
|
|
130
144
|
get: function () {
|
|
@@ -174,6 +188,7 @@ Object.defineProperty(exports, "translations", {
|
|
|
174
188
|
}
|
|
175
189
|
});
|
|
176
190
|
var _api = _interopRequireDefault(require("./api"));
|
|
191
|
+
var _donate = _interopRequireDefault(require("./checkout/donate"));
|
|
177
192
|
var _form = _interopRequireDefault(require("./checkout/form"));
|
|
178
193
|
var _table = _interopRequireDefault(require("./checkout/table"));
|
|
179
194
|
var _tx = _interopRequireDefault(require("./components/blockchain/tx"));
|
|
@@ -181,6 +196,7 @@ var _confirm = _interopRequireDefault(require("./components/confirm"));
|
|
|
181
196
|
var _input = _interopRequireDefault(require("./components/input"));
|
|
182
197
|
var _livemode = _interopRequireDefault(require("./components/livemode"));
|
|
183
198
|
var _pricingTable = _interopRequireDefault(require("./components/pricing-table"));
|
|
199
|
+
var _safeGuard = _interopRequireDefault(require("./components/safe-guard"));
|
|
184
200
|
var _status = _interopRequireDefault(require("./components/status"));
|
|
185
201
|
var _switchButton = _interopRequireDefault(require("./components/switch-button"));
|
|
186
202
|
var _dayjs = _interopRequireDefault(require("./dayjs"));
|
package/lib/locales/en.js
CHANGED
|
@@ -94,6 +94,7 @@ module.exports = (0, _flat.default)({
|
|
|
94
94
|
try: "Try for free",
|
|
95
95
|
include: "This includes:",
|
|
96
96
|
subscription: "Subscribe",
|
|
97
|
+
donate: "Donate",
|
|
97
98
|
select: "Select",
|
|
98
99
|
selected: "Selected",
|
|
99
100
|
noPricing: "No items to purchase",
|
|
@@ -109,6 +110,12 @@ module.exports = (0, _flat.default)({
|
|
|
109
110
|
title: "Staking Required",
|
|
110
111
|
tooltip: "Staking is used to ensure that future invoices can be paid normally. Revoking the staking from DID Wallet means canceling the subscription."
|
|
111
112
|
},
|
|
113
|
+
donation: {
|
|
114
|
+
between: "Please enter an amount between {min} and {max}.",
|
|
115
|
+
custom: "Custom Amount",
|
|
116
|
+
select: "Select Amount",
|
|
117
|
+
summary: "{total} supporters"
|
|
118
|
+
},
|
|
112
119
|
cardPay: "{action} with card",
|
|
113
120
|
empty: "No thing to pay",
|
|
114
121
|
per: "per",
|
|
@@ -124,6 +131,7 @@ module.exports = (0, _flat.default)({
|
|
|
124
131
|
payment: "Thanks for your purchase",
|
|
125
132
|
subscription: "Thanks for your subscribing",
|
|
126
133
|
setup: "Thanks for your subscribing",
|
|
134
|
+
donate: "Thanks for your support",
|
|
127
135
|
tip: "A payment to {payee} has been completed. You can view the details of this payment in your account."
|
|
128
136
|
},
|
|
129
137
|
confirm: "By confirming your subscription, you allow {payee} to charge your account or slashing your staking for this and future payments in accordance with their terms. You can always cancel your subscription, or revoking your staking from DID Wallet.",
|
package/lib/locales/zh.js
CHANGED
|
@@ -94,6 +94,7 @@ module.exports = (0, _flat.default)({
|
|
|
94
94
|
try: "\u514D\u8D39\u8BD5\u7528",
|
|
95
95
|
include: "\u5305\u62EC\uFF1A",
|
|
96
96
|
subscription: "\u8BA2\u9605",
|
|
97
|
+
donate: "\u6350\u8D60",
|
|
97
98
|
select: "\u9009\u62E9",
|
|
98
99
|
selected: "\u5DF2\u9009",
|
|
99
100
|
noPricing: "\u6CA1\u6709\u53EF\u8D2D\u4E70\u7684\u7269\u54C1",
|
|
@@ -109,6 +110,12 @@ module.exports = (0, _flat.default)({
|
|
|
109
110
|
title: "\u8D28\u62BC\u6570\u91CF",
|
|
110
111
|
tooltip: "\u8D28\u62BC\u76F8\u5F53\u4E8E\u4FDD\u8BC1\u91D1\uFF0C\u7528\u4E8E\u786E\u4FDD\u672A\u6765\u7684\u8D26\u5355\u80FD\u591F\u6B63\u5E38\u6263\u6B3E\uFF0C\u5982\u679C\u4F60\u4ECE DID Wallet \u64A4\u9500\u8D28\u62BC\uFF0C\u8BA2\u9605\u4E5F\u4F1A\u88AB\u53D6\u6D88\u3002"
|
|
111
112
|
},
|
|
113
|
+
donation: {
|
|
114
|
+
between: "\u91D1\u989D\u5FC5\u987B\u5927\u4E8E {min} \u4E14\u5C0F\u4E8E {max}",
|
|
115
|
+
custom: "\u8F93\u5165\u91D1\u989D",
|
|
116
|
+
select: "\u9009\u62E9\u91D1\u989D",
|
|
117
|
+
summary: "\u5DF2\u7ECF\u6709 {total} \u4EBA\u652F\u6301"
|
|
118
|
+
},
|
|
112
119
|
cardPay: "\u4F7F\u7528\u5361\u7247{action}",
|
|
113
120
|
empty: "\u6CA1\u6709\u53EF\u652F\u4ED8\u7684\u9879\u76EE",
|
|
114
121
|
per: "\u6BCF",
|
|
@@ -124,6 +131,7 @@ module.exports = (0, _flat.default)({
|
|
|
124
131
|
payment: "\u611F\u8C22\u60A8\u7684\u8D2D\u4E70",
|
|
125
132
|
subscription: "\u611F\u8C22\u60A8\u7684\u8BA2\u9605",
|
|
126
133
|
setup: "\u611F\u8C22\u60A8\u7684\u8BA2\u9605",
|
|
134
|
+
donate: "\u611F\u8C22\u60A8\u7684\u652F\u6301",
|
|
127
135
|
tip: "\u5411{payee}\u7684\u4ED8\u6B3E\u5DF2\u5B8C\u6210\u3002\u60A8\u53EF\u4EE5\u5728\u60A8\u7684\u8D26\u6237\u4E2D\u67E5\u770B\u6B64\u4ED8\u6B3E\u7684\u8BE6\u7EC6\u4FE1\u606F\u3002"
|
|
128
136
|
},
|
|
129
137
|
confirm: "\u901A\u8FC7\u786E\u8BA4\u60A8\u7684\u8BA2\u9605\uFF0C\u60A8\u5141\u8BB8{payee}\u6309\u7167\u5176\u6761\u6B3E\u5BF9\u60A8\u7684\u8D26\u6237\u8FDB\u884C\u4ED8\u6B3E\u6216\u8005\u7F5A\u6CA1\u60A8\u7684\u8D28\u62BC\u3002\u60A8\u968F\u65F6\u53EF\u4EE5\u53D6\u6D88\u60A8\u7684\u8BA2\u9605\uFF0C\u6216\u8005\u64A4\u9500\u8D28\u62BC\u3002",
|
package/lib/payment/error.d.ts
CHANGED
|
@@ -3,11 +3,13 @@ type Props = {
|
|
|
3
3
|
title: string;
|
|
4
4
|
description: string;
|
|
5
5
|
button?: string;
|
|
6
|
+
mode?: string;
|
|
6
7
|
};
|
|
7
|
-
declare function PaymentError({ title, description, button }: Props): import("react").JSX.Element;
|
|
8
|
+
declare function PaymentError({ title, description, button, mode }: Props): import("react").JSX.Element;
|
|
8
9
|
declare namespace PaymentError {
|
|
9
10
|
var defaultProps: {
|
|
10
11
|
button: string;
|
|
12
|
+
mode: string;
|
|
11
13
|
};
|
|
12
14
|
}
|
|
13
15
|
export default PaymentError;
|
package/lib/payment/error.js
CHANGED
|
@@ -9,11 +9,12 @@ var _material = require("@mui/material");
|
|
|
9
9
|
function PaymentError({
|
|
10
10
|
title,
|
|
11
11
|
description,
|
|
12
|
-
button
|
|
12
|
+
button,
|
|
13
|
+
mode
|
|
13
14
|
}) {
|
|
14
15
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
15
16
|
sx: {
|
|
16
|
-
height: "100vh"
|
|
17
|
+
height: mode === "inline" ? "auto" : "100vh"
|
|
17
18
|
},
|
|
18
19
|
alignItems: "center",
|
|
19
20
|
justifyContent: "center",
|
|
@@ -48,5 +49,6 @@ function PaymentError({
|
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
PaymentError.defaultProps = {
|
|
51
|
-
button: "Back"
|
|
52
|
+
button: "Back",
|
|
53
|
+
mode: "standalone"
|
|
52
54
|
};
|
|
@@ -13,6 +13,7 @@ function CurrencySelector({
|
|
|
13
13
|
onChange
|
|
14
14
|
}) {
|
|
15
15
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Root, {
|
|
16
|
+
count: currencies.length,
|
|
16
17
|
style: {
|
|
17
18
|
display: currencies.length > 1 ? "grid" : "block",
|
|
18
19
|
gridTemplateColumns: "50% 50%",
|
|
@@ -60,9 +61,9 @@ function CurrencySelector({
|
|
|
60
61
|
const Root = (0, _system.styled)("section")`
|
|
61
62
|
.cko-payment-card {
|
|
62
63
|
position: relative;
|
|
63
|
-
border:
|
|
64
|
-
padding:
|
|
65
|
-
margin:
|
|
64
|
+
border: 1px solid ${props => props.theme.palette.primary.main};
|
|
65
|
+
padding: 4px 8px;
|
|
66
|
+
margin: 8px 0 0;
|
|
66
67
|
cursor: pointer;
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -77,18 +78,15 @@ const Root = (0, _system.styled)("section")`
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
.cko-payment-card-unselect {
|
|
80
|
-
border:
|
|
81
|
-
padding:
|
|
82
|
-
margin:
|
|
81
|
+
border: 1px solid #ddd;
|
|
82
|
+
padding: 4px 8px;
|
|
83
|
+
margin: 8px 0 0;
|
|
83
84
|
cursor: pointer;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
.cko-payment-card:nth-child(odd)
|
|
87
|
-
margin-right: 8px;
|
|
88
|
-
}
|
|
89
|
-
|
|
87
|
+
.cko-payment-card:nth-child(odd),
|
|
90
88
|
.cko-payment-card-unselect:nth-child(odd) {
|
|
91
|
-
margin-right:
|
|
89
|
+
margin-right: ${props => props.count > 1 ? 8 : 0}px;
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
.cko-payment-card::after {
|
|
@@ -98,7 +96,7 @@ const Root = (0, _system.styled)("section")`
|
|
|
98
96
|
position: absolute;
|
|
99
97
|
right: 3px;
|
|
100
98
|
bottom: 3px;
|
|
101
|
-
border:
|
|
99
|
+
border: 1px solid #fff;
|
|
102
100
|
border-top-color: transparent;
|
|
103
101
|
border-left-color: transparent;
|
|
104
102
|
transform: rotate(35deg);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import 'react-international-phone/style.css';
|
|
3
3
|
import { CheckoutCallbacks, CheckoutContext } from '../../types';
|
|
4
4
|
type PageData = CheckoutContext & CheckoutCallbacks;
|
|
5
|
-
declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, customer, onPaid, onError, mode, }: PageData): import("react").JSX.Element;
|
|
5
|
+
declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, mode, action, }: PageData): import("react").JSX.Element;
|
|
6
6
|
declare namespace PaymentForm {
|
|
7
7
|
var defaultProps: {};
|
|
8
8
|
}
|
|
@@ -53,10 +53,12 @@ function PaymentForm({
|
|
|
53
53
|
checkoutSession,
|
|
54
54
|
paymentMethods,
|
|
55
55
|
paymentIntent,
|
|
56
|
+
paymentLink,
|
|
56
57
|
customer,
|
|
57
58
|
onPaid,
|
|
58
59
|
onError,
|
|
59
|
-
mode
|
|
60
|
+
mode,
|
|
61
|
+
action
|
|
60
62
|
}) {
|
|
61
63
|
const theme = (0, _Theme.useTheme)();
|
|
62
64
|
const {
|
|
@@ -116,8 +118,18 @@ function PaymentForm({
|
|
|
116
118
|
return false;
|
|
117
119
|
}, [domSize, theme]);
|
|
118
120
|
const payee = (0, _util.getStatementDescriptor)(checkoutSession.line_items);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
let buttonText = "";
|
|
122
|
+
if (paymentLink?.donation_settings) {
|
|
123
|
+
if (action) {
|
|
124
|
+
buttonText = action;
|
|
125
|
+
} else {
|
|
126
|
+
buttonText = t("payment.checkout.donate");
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
buttonText = t(`payment.checkout.${checkoutSession.mode}`);
|
|
130
|
+
}
|
|
131
|
+
buttonText = session?.user ? buttonText : t("payment.checkout.connect", {
|
|
132
|
+
action: buttonText
|
|
121
133
|
});
|
|
122
134
|
const method = paymentMethods.find(x => x.id === paymentMethod);
|
|
123
135
|
const handleConnected = async () => {
|
|
@@ -369,7 +381,7 @@ function PaymentForm({
|
|
|
369
381
|
className: "cko-payment-methods",
|
|
370
382
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
371
383
|
sx: {
|
|
372
|
-
mb:
|
|
384
|
+
mb: 1,
|
|
373
385
|
color: "text.primary",
|
|
374
386
|
fontWeight: 600
|
|
375
387
|
},
|