@blocklet/launcher-workflow 1.8.26 → 1.8.27
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/lib/locales/en.js +1 -26
- package/lib/locales/zh.js +1 -26
- package/lib/purchase.js +44 -209
- package/package.json +11 -11
- package/lib/components/payment-method.js +0 -69
- package/lib/components/plan.js +0 -98
- package/lib/components/stripe/checkout.js +0 -215
- package/lib/components/stripe/paying.js +0 -86
- package/lib/index.js +0 -82
package/lib/locales/en.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
PAYMENT_STATUS
|
|
5
|
-
} = require('@blocklet/launcher-util/lib/constant');
|
|
6
|
-
|
|
7
3
|
module.exports = {
|
|
8
4
|
common: {
|
|
9
5
|
paymentMethod: 'Payment Method',
|
|
10
6
|
serverType: 'Blocklet Server Type',
|
|
11
7
|
paying: 'Paying',
|
|
12
|
-
pay: 'Pay',
|
|
13
8
|
name: 'Name',
|
|
14
9
|
description: 'Description',
|
|
15
10
|
retry: 'Retry',
|
|
@@ -25,19 +20,7 @@ module.exports = {
|
|
|
25
20
|
},
|
|
26
21
|
plan: {
|
|
27
22
|
title: 'Select Blocklet Server Plan',
|
|
28
|
-
subTitle: 'Select payment method and plan'
|
|
29
|
-
loadListFailed: 'Plan list load error',
|
|
30
|
-
paymentCredit: {
|
|
31
|
-
status: {
|
|
32
|
-
[PAYMENT_STATUS.unpaid]: 'Waiting for payment',
|
|
33
|
-
[PAYMENT_STATUS.paid]: 'Payment completed, waiting for order completion',
|
|
34
|
-
[PAYMENT_STATUS.done]: 'Completed!',
|
|
35
|
-
[PAYMENT_STATUS.expired]: 'Order has expired'
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
useCrypto: 'Crypto',
|
|
39
|
-
useFiat: 'Credit Card',
|
|
40
|
-
noPlan: 'No blocklet server available for purchase'
|
|
23
|
+
subTitle: 'Select payment method and plan'
|
|
41
24
|
},
|
|
42
25
|
license: {
|
|
43
26
|
title: 'End User License Agreement',
|
|
@@ -94,14 +77,6 @@ module.exports = {
|
|
|
94
77
|
success: 'Your redeem request is being processing'
|
|
95
78
|
}
|
|
96
79
|
},
|
|
97
|
-
purchase: {
|
|
98
|
-
dialog: {
|
|
99
|
-
title: 'Purchase Blocklet Server',
|
|
100
|
-
scan: 'Scan the QR code below with your DID wallet to complete purchase',
|
|
101
|
-
confirm: 'Confirm on your DID Wallet',
|
|
102
|
-
success: 'Purchase Success'
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
80
|
launchPrepare: {
|
|
106
81
|
formError: {
|
|
107
82
|
nameExceed: 'Blocklet Server name cannot exceed {length}',
|
package/lib/locales/zh.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
PAYMENT_STATUS
|
|
5
|
-
} = require('@blocklet/launcher-util/lib/constant');
|
|
6
|
-
|
|
7
3
|
module.exports = {
|
|
8
4
|
common: {
|
|
9
5
|
paymentMethod: '付款方式',
|
|
10
6
|
serverType: '节点信息',
|
|
11
7
|
paying: '支付中',
|
|
12
|
-
pay: '支付',
|
|
13
8
|
name: '名称',
|
|
14
9
|
description: '描述',
|
|
15
10
|
retry: '重试',
|
|
@@ -25,19 +20,7 @@ module.exports = {
|
|
|
25
20
|
},
|
|
26
21
|
plan: {
|
|
27
22
|
title: '选择节点类型',
|
|
28
|
-
subTitle: '请选择支付方式和节点型号'
|
|
29
|
-
loadListFailed: '加载节点类型列表出错',
|
|
30
|
-
paymentCredit: {
|
|
31
|
-
status: {
|
|
32
|
-
[PAYMENT_STATUS.unpaid]: '支付中',
|
|
33
|
-
[PAYMENT_STATUS.paid]: '支付完成, 等待订单完成',
|
|
34
|
-
[PAYMENT_STATUS.done]: '已完成!',
|
|
35
|
-
[PAYMENT_STATUS.expired]: '订单已过期'
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
useCrypto: '数字货币支付',
|
|
39
|
-
useFiat: '信用卡支付',
|
|
40
|
-
noPlan: '没有可购买的节点类型'
|
|
23
|
+
subTitle: '请选择支付方式和节点型号'
|
|
41
24
|
},
|
|
42
25
|
license: {
|
|
43
26
|
title: '节点用户协议',
|
|
@@ -94,14 +77,6 @@ module.exports = {
|
|
|
94
77
|
success: '兑换成功'
|
|
95
78
|
}
|
|
96
79
|
},
|
|
97
|
-
purchase: {
|
|
98
|
-
dialog: {
|
|
99
|
-
title: '购买节点',
|
|
100
|
-
scan: '用您的 DID 钱包扫描下面的二维码完成购买',
|
|
101
|
-
confirm: '在您的 DID 钱包上确认',
|
|
102
|
-
success: '支付成功'
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
80
|
launchPrepare: {
|
|
106
81
|
formError: {
|
|
107
82
|
nameExceed: '节点名称不能超过 {length}',
|
package/lib/purchase.js
CHANGED
|
@@ -11,30 +11,20 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
|
|
12
12
|
var _reactRouterDom = require("react-router-dom");
|
|
13
13
|
|
|
14
|
-
var _reactUse = require("react-use");
|
|
15
|
-
|
|
16
14
|
var _lodash = _interopRequireDefault(require("lodash.get"));
|
|
17
15
|
|
|
18
16
|
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
19
17
|
|
|
20
18
|
var _jsCookie = _interopRequireDefault(require("js-cookie"));
|
|
21
19
|
|
|
22
|
-
var
|
|
20
|
+
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
23
21
|
|
|
24
|
-
var
|
|
22
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
25
23
|
|
|
26
24
|
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
27
25
|
|
|
28
26
|
var _Spinner = _interopRequireDefault(require("@arcblock/ux/lib/Spinner"));
|
|
29
27
|
|
|
30
|
-
var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect"));
|
|
31
|
-
|
|
32
|
-
var _Empty = _interopRequireDefault(require("@arcblock/ux/lib/Empty"));
|
|
33
|
-
|
|
34
|
-
var _Tabs = _interopRequireDefault(require("@arcblock/ux/lib/Tabs"));
|
|
35
|
-
|
|
36
|
-
var _Alert = _interopRequireDefault(require("@arcblock/ux/lib/Alert"));
|
|
37
|
-
|
|
38
28
|
var _compactLayout = _interopRequireDefault(require("@blocklet/launcher-layout/lib/compact-layout"));
|
|
39
29
|
|
|
40
30
|
var _pageHeader = _interopRequireDefault(require("@blocklet/launcher-layout/lib/page-header"));
|
|
@@ -45,9 +35,11 @@ var _submit = _interopRequireDefault(require("@blocklet/launcher-ux/lib/hot-key/
|
|
|
45
35
|
|
|
46
36
|
var _useMediaQuery = _interopRequireDefault(require("@mui/material/useMediaQuery"));
|
|
47
37
|
|
|
48
|
-
var
|
|
38
|
+
var _payment = _interopRequireDefault(require("@did-pay/react/lib/payment"));
|
|
39
|
+
|
|
40
|
+
var _list = _interopRequireDefault(require("@did-pay/react/lib/payment-method/list"));
|
|
49
41
|
|
|
50
|
-
var
|
|
42
|
+
var _list2 = _interopRequireDefault(require("@did-pay/react/lib/plan/list"));
|
|
51
43
|
|
|
52
44
|
var _query = _interopRequireDefault(require("./hooks/query"));
|
|
53
45
|
|
|
@@ -55,12 +47,8 @@ var _locale = require("./contexts/locale");
|
|
|
55
47
|
|
|
56
48
|
var _session = require("./contexts/session");
|
|
57
49
|
|
|
58
|
-
var _request = _interopRequireDefault(require("./contexts/request"));
|
|
59
|
-
|
|
60
50
|
var _router = _interopRequireWildcard(require("./contexts/router"));
|
|
61
51
|
|
|
62
|
-
var _paymentMethod = _interopRequireDefault(require("./components/payment-method"));
|
|
63
|
-
|
|
64
52
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
65
53
|
|
|
66
54
|
var _templateObject;
|
|
@@ -73,106 +61,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
73
61
|
|
|
74
62
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
75
63
|
|
|
76
|
-
function
|
|
64
|
+
function PurchasePage(_ref) {
|
|
65
|
+
var _session$user;
|
|
77
66
|
|
|
78
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
79
|
-
|
|
80
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
81
|
-
|
|
82
|
-
const formatTokenPrice = token => "".concat((0, _util.fromUnitToToken)(token.value, token.decimal), " ").concat(token.symbol);
|
|
83
|
-
|
|
84
|
-
const formatFiatPrice = price => "".concat(price.symbol || price.unit).concat(price.value);
|
|
85
|
-
|
|
86
|
-
function PlanList(_ref) {
|
|
87
67
|
let {
|
|
88
|
-
|
|
89
|
-
onSelect,
|
|
90
|
-
onLoaded
|
|
68
|
+
baseURL
|
|
91
69
|
} = _ref;
|
|
92
|
-
const {
|
|
93
|
-
api
|
|
94
|
-
} = (0, _request.default)();
|
|
95
|
-
const [plan, setPlan] = (0, _react.useState)(null);
|
|
96
|
-
const {
|
|
97
|
-
t
|
|
98
|
-
} = (0, _locale.useLocaleContext)();
|
|
99
|
-
const selectPlan = (0, _react.useCallback)(value => {
|
|
100
|
-
setPlan(value);
|
|
101
|
-
onSelect(value); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
-
}, []);
|
|
103
|
-
const plansState = (0, _reactUse.useAsync)(async () => {
|
|
104
|
-
const {
|
|
105
|
-
data
|
|
106
|
-
} = await api.get("/plans?paymentMethod=".concat(paymentMethod._id));
|
|
107
|
-
const plans = (data || []).map(item => {
|
|
108
|
-
item.prices = {
|
|
109
|
-
crypto: formatTokenPrice(item.prices.crypto),
|
|
110
|
-
fiat: formatFiatPrice(item.prices.fiat)
|
|
111
|
-
};
|
|
112
|
-
return item;
|
|
113
|
-
}).sort((itemX, itemY) => itemX.weight - itemY.weight);
|
|
114
|
-
onLoaded();
|
|
115
|
-
return {
|
|
116
|
-
plans
|
|
117
|
-
};
|
|
118
|
-
}, [paymentMethod]);
|
|
119
|
-
(0, _react.useEffect)(() => {
|
|
120
|
-
if (plansState.loading === false && plansState.value) {
|
|
121
|
-
const {
|
|
122
|
-
plans
|
|
123
|
-
} = plansState.value;
|
|
124
|
-
|
|
125
|
-
if (plans.length > 0) {
|
|
126
|
-
selectPlan(plans[0]);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, [plansState, selectPlan]);
|
|
130
|
-
|
|
131
|
-
if (plansState.loading) {
|
|
132
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Center.default, {
|
|
133
|
-
relative: "parent",
|
|
134
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {})
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (plansState.error) {
|
|
139
|
-
console.error('load plans error', plansState.error);
|
|
140
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
|
|
141
|
-
type: "error",
|
|
142
|
-
children: t('plan.loadListFailed')
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const {
|
|
147
|
-
plans
|
|
148
|
-
} = plansState.value;
|
|
149
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Container, {
|
|
150
|
-
className: "select-plan small-select-plan-".concat(plans.length),
|
|
151
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
152
|
-
className: "selector-container container-padding",
|
|
153
|
-
children: plans.length ? plans.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_plan.default, {
|
|
154
|
-
paymentMethod: paymentMethod.type,
|
|
155
|
-
onClick: () => selectPlan(item),
|
|
156
|
-
selected: plan && plan._id === item._id,
|
|
157
|
-
data: item
|
|
158
|
-
}, item._id)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Empty.default, {
|
|
159
|
-
children: t('plan.noPlan')
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
PlanList.propTypes = {
|
|
166
|
-
paymentMethod: _propTypes.default.any.isRequired,
|
|
167
|
-
onSelect: _propTypes.default.func.isRequired,
|
|
168
|
-
onLoaded: _propTypes.default.func.isRequired
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
function PurchasePage() {
|
|
172
|
-
const {
|
|
173
|
-
api,
|
|
174
|
-
create: createRequest
|
|
175
|
-
} = (0, _request.default)();
|
|
176
70
|
const query = (0, _query.default)();
|
|
177
71
|
const navigate = (0, _reactRouterDom.useNavigate)();
|
|
178
72
|
const disabledBack = (0, _router.useDisabledBack)();
|
|
@@ -185,7 +79,6 @@ function PurchasePage() {
|
|
|
185
79
|
locale
|
|
186
80
|
} = (0, _locale.useLocaleContext)();
|
|
187
81
|
const [paying, setPaying] = (0, _react.useState)(false);
|
|
188
|
-
const [paymentInfo, setPaymentInfo] = (0, _react.useState)(null);
|
|
189
82
|
const [buttonInFix, setButtonInFix] = (0, _react.useState)(false);
|
|
190
83
|
const [paymentMethod, setPaymentMethod] = (0, _react.useState)(null);
|
|
191
84
|
const routerPrefix = (0, _router.usePrefix)();
|
|
@@ -199,41 +92,6 @@ function PurchasePage() {
|
|
|
199
92
|
} // eslint-disable-next-line
|
|
200
93
|
|
|
201
94
|
}, [paymentMethod, userDid]);
|
|
202
|
-
const paymentMethodsState = (0, _reactUse.useAsync)(async () => {
|
|
203
|
-
const {
|
|
204
|
-
data
|
|
205
|
-
} = await api.get('/payment-methods');
|
|
206
|
-
const methods = (data || []).map(item => {
|
|
207
|
-
item.label = /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentMethod.default, {
|
|
208
|
-
type: item.type
|
|
209
|
-
});
|
|
210
|
-
item.value = item.type;
|
|
211
|
-
return item;
|
|
212
|
-
}).sort(itemX => {
|
|
213
|
-
if (itemX.type === _constant.PAYMENT_METHODS.crypto) {
|
|
214
|
-
return -1;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return 1;
|
|
218
|
-
});
|
|
219
|
-
setPaymentMethod(methods[0]);
|
|
220
|
-
return methods;
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
if (paymentMethodsState.loading) {
|
|
224
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Center.default, {
|
|
225
|
-
relative: "parent",
|
|
226
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {})
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (paymentMethodsState.error) {
|
|
231
|
-
console.error('load plans error', paymentMethodsState.error);
|
|
232
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
|
|
233
|
-
type: "error",
|
|
234
|
-
children: t('plan.loadListFailed')
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
95
|
|
|
238
96
|
const handlePaid = (_ref2, decrypt) => {
|
|
239
97
|
let {
|
|
@@ -249,10 +107,6 @@ function PurchasePage() {
|
|
|
249
107
|
navigate((0, _router.default)(routerPrefix, url));
|
|
250
108
|
};
|
|
251
109
|
|
|
252
|
-
const handleCloseAuthDialog = () => {
|
|
253
|
-
setPaying(false);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
110
|
const getPurchaseParams = () => {
|
|
257
111
|
const obj = {
|
|
258
112
|
productId: plan ? plan._id : null,
|
|
@@ -269,7 +123,6 @@ function PurchasePage() {
|
|
|
269
123
|
|
|
270
124
|
const handleCancelPay = () => {
|
|
271
125
|
setPaying(false);
|
|
272
|
-
setPaymentInfo(null);
|
|
273
126
|
};
|
|
274
127
|
|
|
275
128
|
const handlePay = async payment => {
|
|
@@ -285,28 +138,6 @@ function PurchasePage() {
|
|
|
285
138
|
}
|
|
286
139
|
|
|
287
140
|
setPaying(true);
|
|
288
|
-
|
|
289
|
-
if (payment === _constant.PAYMENT_METHODS.crypto) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (payment === _constant.PAYMENT_METHODS.fiat) {
|
|
294
|
-
try {
|
|
295
|
-
const {
|
|
296
|
-
data
|
|
297
|
-
} = await api.post('/pay', _objectSpread(_objectSpread({}, params), {}, {
|
|
298
|
-
userDid
|
|
299
|
-
}));
|
|
300
|
-
setPaymentInfo({
|
|
301
|
-
paymentId: data.paymentId,
|
|
302
|
-
clientSecret: data.clientSecret,
|
|
303
|
-
status: data.status
|
|
304
|
-
});
|
|
305
|
-
} catch (error) {
|
|
306
|
-
console.error(error);
|
|
307
|
-
setPaying(false);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
141
|
};
|
|
311
142
|
|
|
312
143
|
const handleRedeem = () => {
|
|
@@ -315,13 +146,24 @@ function PurchasePage() {
|
|
|
315
146
|
});
|
|
316
147
|
};
|
|
317
148
|
|
|
149
|
+
const handlePayFailed = () => {
|
|
150
|
+
setImmediate(() => {
|
|
151
|
+
_Toast.default.error(t('common.payFailed'));
|
|
152
|
+
|
|
153
|
+
setPaying(false);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
318
157
|
const clickBack = () => {
|
|
319
158
|
navigate(-1);
|
|
320
159
|
};
|
|
321
160
|
|
|
322
|
-
const
|
|
161
|
+
const handlePaymentMethodsLoaded = method => {
|
|
162
|
+
setPaymentMethod(method);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const handleSelectPaymenMethod = method => {
|
|
323
166
|
setPlanLoaded(false);
|
|
324
|
-
const method = paymentMethodsState.value.find(item => item.type === value);
|
|
325
167
|
setPaymentMethod(method);
|
|
326
168
|
};
|
|
327
169
|
|
|
@@ -369,12 +211,15 @@ function PurchasePage() {
|
|
|
369
211
|
onClickBack: disabledBack.includes('purchase') ? '' : clickBack
|
|
370
212
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
371
213
|
className: "select-payment",
|
|
372
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
onChange:
|
|
214
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_list.default, {
|
|
215
|
+
locale: locale,
|
|
216
|
+
baseURL: baseURL,
|
|
217
|
+
onChange: handleSelectPaymenMethod,
|
|
218
|
+
onLoaded: handlePaymentMethodsLoaded
|
|
376
219
|
})
|
|
377
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
220
|
+
}), paymentMethod && /*#__PURE__*/(0, _jsxRuntime.jsx)(_list2.default, {
|
|
221
|
+
locale: locale,
|
|
222
|
+
baseURL: baseURL,
|
|
378
223
|
paymentMethod: paymentMethod,
|
|
379
224
|
onSelect: v => setPlan(v),
|
|
380
225
|
onLoaded: () => setPlanLoaded(true)
|
|
@@ -382,36 +227,26 @@ function PurchasePage() {
|
|
|
382
227
|
})
|
|
383
228
|
})
|
|
384
229
|
})
|
|
385
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
onSuccess: handlePaid,
|
|
391
|
-
onClose: handleCloseAuthDialog,
|
|
392
|
-
checkTimeout: 60 * 5000,
|
|
393
|
-
extraParams: getPurchaseParams(),
|
|
394
|
-
showDownload: false,
|
|
395
|
-
locale: locale,
|
|
396
|
-
messages: {
|
|
397
|
-
title: t('purchase.dialog.title'),
|
|
398
|
-
scan: t('purchase.dialog.scan'),
|
|
399
|
-
confirm: t('purchase.dialog.confirm'),
|
|
400
|
-
success: t('purchase.dialog.success')
|
|
401
|
-
}
|
|
402
|
-
}), paymentInfo && /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkout.default, {
|
|
403
|
-
clientSecret: paymentInfo.clientSecret,
|
|
404
|
-
paymentId: paymentInfo.paymentId,
|
|
405
|
-
userDid: userDid,
|
|
230
|
+
}), paying && /*#__PURE__*/(0, _jsxRuntime.jsx)(_payment.default, {
|
|
231
|
+
baseURL: (0, _urlJoin.default)(window.location.origin, baseURL),
|
|
232
|
+
method: paymentMethod.type,
|
|
233
|
+
userDid: session === null || session === void 0 ? void 0 : (_session$user = session.user) === null || _session$user === void 0 ? void 0 : _session$user.did,
|
|
234
|
+
productId: plan._id,
|
|
406
235
|
onComplete: handlePaid,
|
|
407
|
-
|
|
408
|
-
|
|
236
|
+
onFailed: handlePayFailed,
|
|
237
|
+
onCancel: handleCancelPay
|
|
409
238
|
})]
|
|
410
239
|
})
|
|
411
240
|
);
|
|
412
241
|
}
|
|
413
242
|
|
|
414
|
-
const Container = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n .select-payment {\n display: flex;\n justify-content: center;\n align-items: center;\n padding-top: 30px;\n }\n
|
|
243
|
+
const Container = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n .select-payment {\n display: flex;\n justify-content: center;\n align-items: center;\n padding-top: 30px;\n }\n\n .page-body {\n position: relative;\n flex: 1;\n margin-top: 0;\n }\n .page-body-article {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n overflow-y: auto;\n }\n\n .button-container {\n display: flex;\n justify-content: center;\n align-items: center;\n padding-bottom: 15px;\n padding-top: 15px;\n > button {\n width: 200px;\n }\n &.has-shadow {\n box-shadow: 0px -1px 1px 0px rgba(168, 180, 197, 0.12);\n }\n }\n .container-padding {\n padding-left: 24px;\n padding-right: 24px;\n }\n"])));
|
|
415
244
|
|
|
245
|
+
PurchasePage.propTypes = {
|
|
246
|
+
baseURL: _propTypes.default.string
|
|
247
|
+
};
|
|
248
|
+
PurchasePage.defaultProps = {
|
|
249
|
+
baseURL: '/'
|
|
250
|
+
};
|
|
416
251
|
var _default = PurchasePage;
|
|
417
252
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/launcher-workflow",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.27",
|
|
4
4
|
"description": "Purchase components for Launcher UI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"author": "polunzh <polunzh@gmail.com>",
|
|
12
12
|
"homepage": "https://github.com/blocklet/launcher/ux#readme",
|
|
13
13
|
"license": "ISC",
|
|
14
|
-
"main": "lib/index.js",
|
|
15
14
|
"files": [
|
|
16
15
|
"lib",
|
|
17
16
|
"LICENSE",
|
|
@@ -37,19 +36,20 @@
|
|
|
37
36
|
"react": ">=18.1.0"
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"@arcblock/did-connect": "^2.4.
|
|
41
|
-
"@arcblock/icons": "^2.4.
|
|
42
|
-
"@arcblock/license": "^2.4.
|
|
43
|
-
"@arcblock/ux": "^2.4.
|
|
44
|
-
"@blocklet/launcher-layout": "1.8.
|
|
45
|
-
"@blocklet/launcher-util": "1.8.
|
|
46
|
-
"@blocklet/launcher-ux": "1.8.
|
|
39
|
+
"@arcblock/did-connect": "^2.4.23",
|
|
40
|
+
"@arcblock/icons": "^2.4.23",
|
|
41
|
+
"@arcblock/license": "^2.4.23",
|
|
42
|
+
"@arcblock/ux": "^2.4.23",
|
|
43
|
+
"@blocklet/launcher-layout": "1.8.27",
|
|
44
|
+
"@blocklet/launcher-util": "1.8.27",
|
|
45
|
+
"@blocklet/launcher-ux": "1.8.27",
|
|
46
|
+
"@did-pay/react": "^1.8.22",
|
|
47
47
|
"@emotion/react": "^11.10.4",
|
|
48
48
|
"@emotion/styled": "^11.10.4",
|
|
49
49
|
"@mui/icons-material": "^5.10.3",
|
|
50
50
|
"@mui/lab": "^5.0.0-alpha.97",
|
|
51
51
|
"@mui/material": "^5.10.3",
|
|
52
|
-
"@ocap/util": "^1.17.
|
|
52
|
+
"@ocap/util": "^1.17.19",
|
|
53
53
|
"@stripe/react-stripe-js": "^1.10.0",
|
|
54
54
|
"@stripe/stripe-js": "^1.35.0",
|
|
55
55
|
"axios": "^0.26.1",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"@babel/preset-react": "^7.18.6",
|
|
71
71
|
"babel-plugin-inline-react-svg": "^2.0.1"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "afab4067914cabf289e5999397b087b7e6a388c9"
|
|
74
74
|
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = PaymentMethod;
|
|
7
|
-
|
|
8
|
-
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
9
|
-
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
var _constant = require("@blocklet/launcher-util/lib/constant");
|
|
13
|
-
|
|
14
|
-
var _CreditCard = _interopRequireDefault(require("@mui/icons-material/CreditCard"));
|
|
15
|
-
|
|
16
|
-
var _MonetizationOn = _interopRequireDefault(require("@mui/icons-material/MonetizationOn"));
|
|
17
|
-
|
|
18
|
-
var _locale = require("../contexts/locale");
|
|
19
|
-
|
|
20
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
-
|
|
22
|
-
var _templateObject;
|
|
23
|
-
|
|
24
|
-
const _excluded = ["type"];
|
|
25
|
-
|
|
26
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
|
|
28
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
29
|
-
|
|
30
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
-
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
-
|
|
34
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
35
|
-
|
|
36
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
37
|
-
|
|
38
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
39
|
-
|
|
40
|
-
function PaymentMethod(_ref) {
|
|
41
|
-
let {
|
|
42
|
-
type
|
|
43
|
-
} = _ref,
|
|
44
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
t
|
|
48
|
-
} = (0, _locale.useLocaleContext)();
|
|
49
|
-
|
|
50
|
-
if (type === _constant.PAYMENT_METHODS.crypto) {
|
|
51
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, _objectSpread(_objectSpread({}, props), {}, {
|
|
52
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_MonetizationOn.default, {
|
|
53
|
-
className: "payment-icon"
|
|
54
|
-
}), t('plan.useCrypto')]
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, _objectSpread(_objectSpread({}, props), {}, {
|
|
59
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_CreditCard.default, {
|
|
60
|
-
className: "payment-icon"
|
|
61
|
-
}), t('plan.useFiat')]
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const Container = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n justify-content: center;\n align-items: center;\n\n .payment-icon {\n margin-right: 4px;\n }\n"])));
|
|
66
|
-
|
|
67
|
-
PaymentMethod.propTypes = {
|
|
68
|
-
type: _propTypes.default.oneOf([_constant.PAYMENT_METHODS.crypto, _constant.PAYMENT_METHODS.stripe, _constant.PAYMENT_METHODS.fiat]).isRequired
|
|
69
|
-
};
|
package/lib/components/plan.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = NodeType;
|
|
7
|
-
|
|
8
|
-
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
9
|
-
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
var _lodash = _interopRequireDefault(require("lodash.get"));
|
|
13
|
-
|
|
14
|
-
var _constant = require("@blocklet/launcher-util/lib/constant");
|
|
15
|
-
|
|
16
|
-
var _util = require("@blocklet/launcher-util/lib/util");
|
|
17
|
-
|
|
18
|
-
var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
|
|
19
|
-
|
|
20
|
-
var _Check = _interopRequireDefault(require("@mui/icons-material/Check"));
|
|
21
|
-
|
|
22
|
-
var _locale = require("../contexts/locale");
|
|
23
|
-
|
|
24
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
|
-
|
|
26
|
-
var _templateObject;
|
|
27
|
-
|
|
28
|
-
const _excluded = ["data", "selected", "paymentMethod"];
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
33
|
-
|
|
34
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
-
|
|
36
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
37
|
-
|
|
38
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
39
|
-
|
|
40
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
41
|
-
|
|
42
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
43
|
-
|
|
44
|
-
function NodeType(_ref) {
|
|
45
|
-
let {
|
|
46
|
-
data,
|
|
47
|
-
selected,
|
|
48
|
-
paymentMethod
|
|
49
|
-
} = _ref,
|
|
50
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
51
|
-
|
|
52
|
-
const {
|
|
53
|
-
locale
|
|
54
|
-
} = (0, _locale.useLocaleContext)();
|
|
55
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, _objectSpread(_objectSpread({}, props), {}, {
|
|
56
|
-
className: selected ? 'item-selected' : '',
|
|
57
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
58
|
-
className: "name",
|
|
59
|
-
component: "span",
|
|
60
|
-
children: "".concat((0, _lodash.default)(data, "name.".concat(locale)), " (").concat((0, _util.prettyDuration)(data.duration, locale), ")")
|
|
61
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
62
|
-
className: "price",
|
|
63
|
-
component: "span",
|
|
64
|
-
children: data.prices[paymentMethod]
|
|
65
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
66
|
-
className: "rights",
|
|
67
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
68
|
-
className: "rights-list",
|
|
69
|
-
children: data.features.map(feat => /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
70
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
71
|
-
className: "item-block",
|
|
72
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
73
|
-
className: "item-desc",
|
|
74
|
-
children: feat[locale]
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
}, feat[locale]))
|
|
78
|
-
})
|
|
79
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
80
|
-
className: "check-container",
|
|
81
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Check.default, {
|
|
82
|
-
className: "check-icon"
|
|
83
|
-
})
|
|
84
|
-
})]
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
NodeType.propTypes = {
|
|
89
|
-
data: _propTypes.default.object.isRequired,
|
|
90
|
-
paymentMethod: _propTypes.default.string,
|
|
91
|
-
selected: _propTypes.default.bool
|
|
92
|
-
};
|
|
93
|
-
NodeType.defaultProps = {
|
|
94
|
-
selected: false,
|
|
95
|
-
paymentMethod: _constant.CURRENCY_TYPE.crypto
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const Container = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n border: 1px solid ", ";\n border-radius: 8px;\n padding: 16px;\n cursor: pointer;\n transition: background-color ease 0.2s, border ease 0.2s;\n\n &.item-selected {\n background-color: #ecfbfd;\n border-color: #ecfbfd;\n cursor: default;\n }\n\n .name {\n color: ", ";\n font-size: 16px;\n line-height: 20px;\n font-weight: 500;\n }\n\n .price {\n margin-top: 8px;\n font-size: 24px;\n font-weight: 700;\n color: ", ";\n }\n\n .rights {\n font-size: 14px;\n\n & > ul li {\n list-style-type: none;\n margin: 0;\n vertical-align: middle;\n color: ", ";\n }\n\n & > ul li:not(:first-of-type) {\n margin-top: 8px;\n }\n\n .rights-list {\n margin-top: 8px;\n }\n }\n\n .item-block {\n display: flex;\n .item-icon {\n margin-right: 6px;\n font-size: 14px;\n color: ", ";\n flex-shrink: 0;\n }\n .item-desc {\n flex: 1;\n }\n }\n\n .check-container {\n position: absolute;\n right: 0;\n bottom: 0;\n display: flex;\n justify-content: flex-end;\n align-items: flex-end;\n width: 30px;\n height: 30px;\n border-radius: 0 0 7px 0;\n color: ", ";\n overflow: hidden;\n transition: all ease 0.3s;\n &:after {\n position: absolute;\n z-index: 0;\n left: 30px;\n top: 30px;\n display: block;\n width: 0;\n height: 0;\n border-top: transparent solid 15px;\n border-left: transparent solid 15px;\n border-bottom: ", " solid 15px;\n border-right: ", " solid 15px;\n transition: all ease 0.1s;\n content: '';\n }\n\n .check-icon {\n position: relative;\n z-index: 2;\n margin: 0 1px 1px 0;\n font-size: 16px;\n transform: scale(0);\n transition: all ease 0.2s;\n }\n }\n\n &.item-selected {\n .check-container {\n &:after {\n left: 0;\n top: 0;\n }\n .check-icon {\n transform: scale(1);\n }\n }\n }\n"])), props => props.theme.palette.grey[200], props => props.theme.palette.grey[900], props => props.theme.palette.primary.main, props => props.theme.palette.grey[700], props => props.theme.palette.primary.main, props => props.theme.palette.common.white, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main);
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = Checkout;
|
|
7
|
-
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
13
|
-
|
|
14
|
-
var _stripeJs = require("@stripe/stripe-js");
|
|
15
|
-
|
|
16
|
-
var _reactStripeJs = require("@stripe/react-stripe-js");
|
|
17
|
-
|
|
18
|
-
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
19
|
-
|
|
20
|
-
var _Spinner = _interopRequireDefault(require("@arcblock/ux/lib/Spinner"));
|
|
21
|
-
|
|
22
|
-
var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
|
|
23
|
-
|
|
24
|
-
var _Center = _interopRequireDefault(require("@arcblock/ux/lib/Center"));
|
|
25
|
-
|
|
26
|
-
var _constant = require("@blocklet/launcher-util/lib/constant");
|
|
27
|
-
|
|
28
|
-
var _locale = require("../../contexts/locale");
|
|
29
|
-
|
|
30
|
-
var _paying = _interopRequireDefault(require("./paying"));
|
|
31
|
-
|
|
32
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
|
-
|
|
34
|
-
var _templateObject;
|
|
35
|
-
|
|
36
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
-
|
|
38
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
39
|
-
|
|
40
|
-
function CheckoutForm(_ref) {
|
|
41
|
-
let {
|
|
42
|
-
clientSecret,
|
|
43
|
-
onLoad
|
|
44
|
-
} = _ref;
|
|
45
|
-
const stripe = (0, _reactStripeJs.useStripe)();
|
|
46
|
-
const elements = (0, _reactStripeJs.useElements)();
|
|
47
|
-
const {
|
|
48
|
-
t
|
|
49
|
-
} = (0, _locale.useLocaleContext)();
|
|
50
|
-
const [message, setMessage] = (0, _react.useState)(null);
|
|
51
|
-
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
52
|
-
const [elementReady, setElementReady] = (0, _react.useState)(false);
|
|
53
|
-
(0, _react.useEffect)(() => {
|
|
54
|
-
if (!stripe) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!clientSecret) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
stripe.retrievePaymentIntent(clientSecret).then(_ref2 => {
|
|
63
|
-
let {
|
|
64
|
-
paymentIntent
|
|
65
|
-
} = _ref2;
|
|
66
|
-
|
|
67
|
-
switch (paymentIntent.status) {
|
|
68
|
-
case 'succeeded':
|
|
69
|
-
setMessage(t('plan.paymentCredit.preparePayMessage.succeeded'));
|
|
70
|
-
break;
|
|
71
|
-
|
|
72
|
-
case 'processing':
|
|
73
|
-
setMessage(t('plan.paymentCredit.preparePayMessage.processing'));
|
|
74
|
-
break;
|
|
75
|
-
|
|
76
|
-
case 'requires_payment_method':
|
|
77
|
-
// 忽略该状态
|
|
78
|
-
break;
|
|
79
|
-
|
|
80
|
-
default:
|
|
81
|
-
setMessage(t('plan.paymentCredit.preparePayMessage.default'));
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}, [stripe, clientSecret, t]);
|
|
86
|
-
|
|
87
|
-
const handleSubmit = async e => {
|
|
88
|
-
e.preventDefault();
|
|
89
|
-
|
|
90
|
-
if (!stripe || !elements) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
setIsLoading(true);
|
|
95
|
-
const {
|
|
96
|
-
error
|
|
97
|
-
} = await stripe.confirmPayment({
|
|
98
|
-
elements,
|
|
99
|
-
redirect: 'if_required'
|
|
100
|
-
});
|
|
101
|
-
setIsLoading(false);
|
|
102
|
-
|
|
103
|
-
if (error) {
|
|
104
|
-
if (error.type === 'card_error' || error.type === 'validation_error') {
|
|
105
|
-
setMessage(error.message);
|
|
106
|
-
} else {
|
|
107
|
-
setMessage(t('plan.paymentCredit.submitPayError'));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
onLoad();
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Content, {
|
|
117
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
|
|
118
|
-
onSubmit: handleSubmit,
|
|
119
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactStripeJs.PaymentElement, {
|
|
120
|
-
onReady: () => setElementReady(true)
|
|
121
|
-
}), (!stripe || !elements || !elementReady) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Center.default, {
|
|
122
|
-
relative: "parent",
|
|
123
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {})
|
|
124
|
-
}), stripe && elements && elementReady && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
|
|
125
|
-
id: "submit",
|
|
126
|
-
type: "submit",
|
|
127
|
-
disabled: isLoading,
|
|
128
|
-
variant: "contained",
|
|
129
|
-
color: "primary",
|
|
130
|
-
children: isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
131
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {
|
|
132
|
-
size: 12
|
|
133
|
-
}), t('common.paying')]
|
|
134
|
-
}) : t('common.pay')
|
|
135
|
-
}), message && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
136
|
-
id: "payment-message",
|
|
137
|
-
children: message
|
|
138
|
-
})]
|
|
139
|
-
})
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const Content = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n width: 100%;\n height: 100%;\n\n #submit {\n margin-top: 16px;\n width: 100%;\n }\n\n #payment-message {\n margin-top: 16px;\n color: ", ";\n }\n"])), props => props.theme.palette.error.main);
|
|
144
|
-
|
|
145
|
-
CheckoutForm.propTypes = {
|
|
146
|
-
clientSecret: _propTypes.default.string.isRequired,
|
|
147
|
-
onLoad: _propTypes.default.func.isRequired
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
function Checkout(_ref3) {
|
|
151
|
-
let {
|
|
152
|
-
clientSecret,
|
|
153
|
-
paymentId,
|
|
154
|
-
onComplete,
|
|
155
|
-
onCancel,
|
|
156
|
-
status
|
|
157
|
-
} = _ref3;
|
|
158
|
-
const [open, setOpen] = (0, _react.useState)(true);
|
|
159
|
-
const {
|
|
160
|
-
t
|
|
161
|
-
} = (0, _locale.useLocaleContext)();
|
|
162
|
-
const [showCloseButton, setShowCloseButton] = (0, _react.useState)(true);
|
|
163
|
-
const [waitingCompleted, setWaitingCompleted] = (0, _react.useState)(status === _constant.PAYMENT_STATUS.paid);
|
|
164
|
-
const stripePromise = (0, _stripeJs.loadStripe)(window.env.stripePublicKey);
|
|
165
|
-
const options = {
|
|
166
|
-
clientSecret,
|
|
167
|
-
appearance: {
|
|
168
|
-
theme: 'stripe'
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const handleLoad = () => setWaitingCompleted(true);
|
|
173
|
-
|
|
174
|
-
const handlePaid = () => setShowCloseButton(false);
|
|
175
|
-
|
|
176
|
-
const handleClose = (_, reason) => {
|
|
177
|
-
if (reason === 'backdropClick') {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
setOpen(false);
|
|
182
|
-
onCancel();
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Dialog.default, {
|
|
186
|
-
title: t('common.pay'),
|
|
187
|
-
showCloseButton: showCloseButton,
|
|
188
|
-
open: open,
|
|
189
|
-
onClose: handleClose,
|
|
190
|
-
disableEscapeKeyDown: true,
|
|
191
|
-
children: [waitingCompleted && /*#__PURE__*/(0, _jsxRuntime.jsx)(_paying.default, {
|
|
192
|
-
paymentId: paymentId,
|
|
193
|
-
onComplete: onComplete,
|
|
194
|
-
onPaid: handlePaid
|
|
195
|
-
}), !waitingCompleted && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactStripeJs.Elements, {
|
|
196
|
-
options: options,
|
|
197
|
-
stripe: stripePromise,
|
|
198
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CheckoutForm, {
|
|
199
|
-
clientSecret: clientSecret,
|
|
200
|
-
onLoad: handleLoad
|
|
201
|
-
})
|
|
202
|
-
})]
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
Checkout.propTypes = {
|
|
207
|
-
clientSecret: _propTypes.default.string.isRequired,
|
|
208
|
-
paymentId: _propTypes.default.string.isRequired,
|
|
209
|
-
status: _propTypes.default.number.isRequired,
|
|
210
|
-
onComplete: _propTypes.default.func.isRequired,
|
|
211
|
-
onCancel: _propTypes.default.func
|
|
212
|
-
};
|
|
213
|
-
Checkout.defaultProps = {
|
|
214
|
-
onCancel: () => {}
|
|
215
|
-
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = Paying;
|
|
7
|
-
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
|
|
10
|
-
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
11
|
-
|
|
12
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
|
-
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
15
|
-
|
|
16
|
-
var _useInterval = _interopRequireDefault(require("react-use/lib/useInterval"));
|
|
17
|
-
|
|
18
|
-
var _Spinner = _interopRequireDefault(require("@arcblock/ux/lib/Spinner"));
|
|
19
|
-
|
|
20
|
-
var _constant = require("@blocklet/launcher-util/lib/constant");
|
|
21
|
-
|
|
22
|
-
var _Check = _interopRequireDefault(require("@mui/icons-material/Check"));
|
|
23
|
-
|
|
24
|
-
var _locale = require("../../contexts/locale");
|
|
25
|
-
|
|
26
|
-
var _request = _interopRequireDefault(require("../../contexts/request"));
|
|
27
|
-
|
|
28
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
29
|
-
|
|
30
|
-
var _templateObject;
|
|
31
|
-
|
|
32
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
-
|
|
34
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
35
|
-
|
|
36
|
-
function Paying(_ref) {
|
|
37
|
-
let {
|
|
38
|
-
paymentId,
|
|
39
|
-
onPaid,
|
|
40
|
-
onComplete
|
|
41
|
-
} = _ref;
|
|
42
|
-
const {
|
|
43
|
-
t
|
|
44
|
-
} = (0, _locale.useLocaleContext)();
|
|
45
|
-
const [needFetchOrderStatus, setNeedFetchOrderStatus] = (0, _react.useState)(true);
|
|
46
|
-
const [status, setStatus] = (0, _react.useState)(_constant.PAYMENT_STATUS.unpaid);
|
|
47
|
-
const {
|
|
48
|
-
api
|
|
49
|
-
} = (0, _request.default)();
|
|
50
|
-
const fetchOrder = (0, _lodash.default)(async () => {
|
|
51
|
-
const {
|
|
52
|
-
data: payment
|
|
53
|
-
} = await api.get("/payments/".concat(paymentId));
|
|
54
|
-
|
|
55
|
-
if (payment.status === _constant.PAYMENT_STATUS.done) {
|
|
56
|
-
fetchOrder.cancel();
|
|
57
|
-
setNeedFetchOrderStatus(false);
|
|
58
|
-
setTimeout(() => onComplete({
|
|
59
|
-
nftId: payment.nftId
|
|
60
|
-
}), 2000);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (payment.status >= _constant.PAYMENT_STATUS.paid) {
|
|
64
|
-
onPaid();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setStatus(payment.status);
|
|
68
|
-
}, 3000);
|
|
69
|
-
(0, _useInterval.default)(fetchOrder, needFetchOrderStatus ? 3000 : null);
|
|
70
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Content, {
|
|
71
|
-
children: [status <= _constant.PAYMENT_STATUS.paid && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {}), status === _constant.PAYMENT_STATUS.done && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Check.default, {
|
|
72
|
-
className: "status--succeed_icon"
|
|
73
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
74
|
-
className: "status",
|
|
75
|
-
children: t("plan.paymentCredit.status.".concat(status))
|
|
76
|
-
})]
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
Paying.propTypes = {
|
|
81
|
-
paymentId: _propTypes.default.string.isRequired,
|
|
82
|
-
onPaid: _propTypes.default.func.isRequired,
|
|
83
|
-
onComplete: _propTypes.default.func.isRequired
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const Content = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n width: 100%;\n height: 100%;\n\n .status {\n margin-top: 32px;\n }\n\n .status--succeed_icon {\n background-color: #3ab39d;\n display: inline-flex;\n justify-content: center;\n align-items: center;\n width: 48px;\n height: 48px;\n border-radius: 100%;\n color: ", ";\n }\n"])), props => props.theme.palette.common.white);
|
package/lib/index.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PaymentMethod = PaymentMethod;
|
|
7
|
-
exports.Stripe = Stripe;
|
|
8
|
-
|
|
9
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
-
|
|
11
|
-
var _checkout = _interopRequireDefault(require("./components/stripe/checkout"));
|
|
12
|
-
|
|
13
|
-
var _paymentMethod = _interopRequireDefault(require("./components/payment-method"));
|
|
14
|
-
|
|
15
|
-
var _locales = require("./locales");
|
|
16
|
-
|
|
17
|
-
var _request = require("./contexts/request");
|
|
18
|
-
|
|
19
|
-
var _locale = require("./contexts/locale");
|
|
20
|
-
|
|
21
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
|
|
23
|
-
const _excluded = ["locale", "baseURL"],
|
|
24
|
-
_excluded2 = ["locale"];
|
|
25
|
-
|
|
26
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
|
|
28
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
29
|
-
|
|
30
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
-
|
|
32
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
33
|
-
|
|
34
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
35
|
-
|
|
36
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
37
|
-
|
|
38
|
-
function Stripe(_ref) {
|
|
39
|
-
let {
|
|
40
|
-
locale,
|
|
41
|
-
baseURL
|
|
42
|
-
} = _ref,
|
|
43
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
-
|
|
45
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_locale.LocaleProvider, {
|
|
46
|
-
translations: _locales.translations,
|
|
47
|
-
locale: locale,
|
|
48
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_request.RequestProvider, {
|
|
49
|
-
baseURL: baseURL,
|
|
50
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkout.default, _objectSpread({}, rest))
|
|
51
|
-
})
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
Stripe.propTypes = {
|
|
56
|
-
locale: _propTypes.default.string,
|
|
57
|
-
baseURL: _propTypes.default.string
|
|
58
|
-
};
|
|
59
|
-
Stripe.defaultProps = {
|
|
60
|
-
locale: 'en',
|
|
61
|
-
baseURL: '/'
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
function PaymentMethod(_ref2) {
|
|
65
|
-
let {
|
|
66
|
-
locale
|
|
67
|
-
} = _ref2,
|
|
68
|
-
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
69
|
-
|
|
70
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_locale.LocaleProvider, {
|
|
71
|
-
translations: _locales.translations,
|
|
72
|
-
locale: locale,
|
|
73
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentMethod.default, _objectSpread({}, props))
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
PaymentMethod.propTypes = {
|
|
78
|
-
locale: _propTypes.default.string
|
|
79
|
-
};
|
|
80
|
-
PaymentMethod.defaultProps = {
|
|
81
|
-
locale: 'en'
|
|
82
|
-
};
|