@blocklet/payment-react 1.18.0 → 1.18.2
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.js +55 -10
- package/es/checkout/form.d.ts +2 -1
- package/es/checkout/form.js +32 -45
- package/es/components/payment-beneficiaries.d.ts +24 -0
- package/es/components/payment-beneficiaries.js +70 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -1
- package/es/locales/en.js +13 -1
- package/es/locales/zh.js +13 -1
- package/es/payment/donation-form.d.ts +24 -0
- package/es/payment/donation-form.js +604 -0
- package/es/payment/error.d.ts +1 -1
- package/es/payment/error.js +11 -1
- package/es/payment/form/index.d.ts +9 -3
- package/es/payment/form/index.js +60 -12
- package/es/payment/product-donation.js +101 -56
- package/es/payment/skeleton/donation.d.ts +1 -0
- package/es/payment/skeleton/donation.js +30 -0
- package/es/theme/index.js +13 -0
- package/es/types/index.d.ts +2 -0
- package/lib/checkout/donate.js +85 -10
- package/lib/checkout/form.d.ts +2 -1
- package/lib/checkout/form.js +39 -49
- package/lib/components/payment-beneficiaries.d.ts +24 -0
- package/lib/components/payment-beneficiaries.js +113 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +8 -0
- package/lib/locales/en.js +13 -1
- package/lib/locales/zh.js +13 -1
- package/lib/payment/donation-form.d.ts +24 -0
- package/lib/payment/donation-form.js +645 -0
- package/lib/payment/error.d.ts +1 -1
- package/lib/payment/error.js +2 -2
- package/lib/payment/form/index.d.ts +9 -3
- package/lib/payment/form/index.js +60 -8
- package/lib/payment/product-donation.js +143 -72
- package/lib/payment/skeleton/donation.d.ts +1 -0
- package/lib/payment/skeleton/donation.js +66 -0
- package/lib/theme/index.js +13 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +3 -3
- package/src/checkout/donate.tsx +64 -11
- package/src/checkout/form.tsx +17 -31
- package/src/components/payment-beneficiaries.tsx +97 -0
- package/src/index.ts +2 -0
- package/src/locales/en.tsx +12 -0
- package/src/locales/zh.tsx +12 -0
- package/src/payment/donation-form.tsx +647 -0
- package/src/payment/error.tsx +13 -4
- package/src/payment/form/index.tsx +66 -11
- package/src/payment/product-donation.tsx +94 -39
- package/src/payment/skeleton/donation.tsx +35 -0
- package/src/theme/index.tsx +13 -0
- package/src/types/index.ts +2 -0
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Root = void 0;
|
|
7
|
+
module.exports = DonationForm;
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
10
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
11
|
+
var _Header = _interopRequireDefault(require("@blocklet/ui-react/lib/Header"));
|
|
12
|
+
var _iconsMaterial = require("@mui/icons-material");
|
|
13
|
+
var _material = require("@mui/material");
|
|
14
|
+
var _system = require("@mui/system");
|
|
15
|
+
var _util = require("@ocap/util");
|
|
16
|
+
var _ahooks = require("ahooks");
|
|
17
|
+
var _react = require("react");
|
|
18
|
+
var _reactHookForm = require("react-hook-form");
|
|
19
|
+
var _ufo = require("ufo");
|
|
20
|
+
var _payment = require("../contexts/payment");
|
|
21
|
+
var _api = _interopRequireDefault(require("../libs/api"));
|
|
22
|
+
var _util2 = require("../libs/util");
|
|
23
|
+
var _error = _interopRequireDefault(require("./error"));
|
|
24
|
+
var _form = _interopRequireDefault(require("./form"));
|
|
25
|
+
var _success = _interopRequireDefault(require("./success"));
|
|
26
|
+
var _mobile = require("../hooks/mobile");
|
|
27
|
+
var _productDonation = _interopRequireDefault(require("./product-donation"));
|
|
28
|
+
var _confirm = _interopRequireDefault(require("../components/confirm"));
|
|
29
|
+
var _paymentBeneficiaries = _interopRequireDefault(require("../components/payment-beneficiaries"));
|
|
30
|
+
var _donation = _interopRequireDefault(require("./skeleton/donation"));
|
|
31
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
32
|
+
const getBenefits = async (id, url) => {
|
|
33
|
+
const {
|
|
34
|
+
data
|
|
35
|
+
} = await _api.default.get(`/api/payment-links/${id}/benefits?${url ? `url=${url}` : ""}`);
|
|
36
|
+
return data;
|
|
37
|
+
};
|
|
38
|
+
PaymentInner.defaultProps = {
|
|
39
|
+
completed: false,
|
|
40
|
+
showCheckoutSummary: true,
|
|
41
|
+
formRender: {}
|
|
42
|
+
};
|
|
43
|
+
function PaymentInner({
|
|
44
|
+
checkoutSession,
|
|
45
|
+
paymentMethods,
|
|
46
|
+
paymentLink,
|
|
47
|
+
paymentIntent,
|
|
48
|
+
customer,
|
|
49
|
+
completed,
|
|
50
|
+
mode,
|
|
51
|
+
onPaid,
|
|
52
|
+
onError,
|
|
53
|
+
onChange,
|
|
54
|
+
action,
|
|
55
|
+
formRender,
|
|
56
|
+
benefits
|
|
57
|
+
}) {
|
|
58
|
+
const {
|
|
59
|
+
t
|
|
60
|
+
} = (0, _context.useLocaleContext)();
|
|
61
|
+
const {
|
|
62
|
+
settings,
|
|
63
|
+
session
|
|
64
|
+
} = (0, _payment.usePaymentContext)();
|
|
65
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
66
|
+
checkoutSession,
|
|
67
|
+
submitting: false,
|
|
68
|
+
paying: false,
|
|
69
|
+
paid: false,
|
|
70
|
+
paymentIntent,
|
|
71
|
+
stripeContext: void 0,
|
|
72
|
+
customer,
|
|
73
|
+
customerLimited: false,
|
|
74
|
+
stripePaying: false
|
|
75
|
+
});
|
|
76
|
+
const query = (0, _util2.getQueryParams)(window.location.href);
|
|
77
|
+
const defaultCurrencyId = query.currencyId || state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
|
|
78
|
+
const defaultMethodId = paymentMethods.find(m => m.payment_currencies.some(c => c.id === defaultCurrencyId))?.id;
|
|
79
|
+
const items = state.checkoutSession.line_items;
|
|
80
|
+
const donationSettings = paymentLink?.donation_settings;
|
|
81
|
+
const [benefitsState, setBenefitsState] = (0, _ahooks.useSetState)({
|
|
82
|
+
open: false,
|
|
83
|
+
amount: "0"
|
|
84
|
+
});
|
|
85
|
+
const methods = (0, _reactHookForm.useForm)({
|
|
86
|
+
defaultValues: {
|
|
87
|
+
customer_name: customer?.name || session?.user?.fullName || "",
|
|
88
|
+
customer_email: customer?.email || session?.user?.email || "",
|
|
89
|
+
customer_phone: customer?.phone || session?.user?.phone || "",
|
|
90
|
+
payment_method: defaultMethodId,
|
|
91
|
+
payment_currency: defaultCurrencyId,
|
|
92
|
+
billing_address: Object.assign({
|
|
93
|
+
country: "",
|
|
94
|
+
state: "",
|
|
95
|
+
city: "",
|
|
96
|
+
line1: "",
|
|
97
|
+
line2: "",
|
|
98
|
+
postal_code: ""
|
|
99
|
+
}, customer?.address || {}, {
|
|
100
|
+
country: (0, _util2.isValidCountry)(customer?.address?.country || "") ? customer?.address?.country : "us"
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
(0, _react.useEffect)(() => {
|
|
105
|
+
if (!(0, _util2.isMobileSafari)()) {
|
|
106
|
+
return () => {};
|
|
107
|
+
}
|
|
108
|
+
let scrollTop = 0;
|
|
109
|
+
const focusinHandler = () => {
|
|
110
|
+
scrollTop = window.scrollY;
|
|
111
|
+
};
|
|
112
|
+
const focusoutHandler = () => {
|
|
113
|
+
window.scrollTo(0, scrollTop);
|
|
114
|
+
};
|
|
115
|
+
document.body.addEventListener("focusin", focusinHandler);
|
|
116
|
+
document.body.addEventListener("focusout", focusoutHandler);
|
|
117
|
+
return () => {
|
|
118
|
+
document.body.removeEventListener("focusin", focusinHandler);
|
|
119
|
+
document.body.removeEventListener("focusout", focusoutHandler);
|
|
120
|
+
};
|
|
121
|
+
}, []);
|
|
122
|
+
(0, _react.useEffect)(() => {
|
|
123
|
+
if (!methods || query.currencyId) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (state.checkoutSession.currency_id !== defaultCurrencyId) {
|
|
127
|
+
methods.setValue("payment_currency", state.checkoutSession.currency_id);
|
|
128
|
+
}
|
|
129
|
+
}, [state.checkoutSession, defaultCurrencyId, query.currencyId]);
|
|
130
|
+
const currencyId = (0, _reactHookForm.useWatch)({
|
|
131
|
+
control: methods.control,
|
|
132
|
+
name: "payment_currency",
|
|
133
|
+
defaultValue: defaultCurrencyId
|
|
134
|
+
});
|
|
135
|
+
const currency = (0, _util2.findCurrency)(paymentMethods, currencyId) || settings.baseCurrency;
|
|
136
|
+
(0, _react.useEffect)(() => {
|
|
137
|
+
if (onChange) {
|
|
138
|
+
onChange(methods.getValues());
|
|
139
|
+
}
|
|
140
|
+
}, [currencyId]);
|
|
141
|
+
const onChangeAmount = async ({
|
|
142
|
+
priceId,
|
|
143
|
+
amount
|
|
144
|
+
}) => {
|
|
145
|
+
const amountStr = (0, _util.fromTokenToUnit)(amount, currency.decimal).toString();
|
|
146
|
+
setBenefitsState({
|
|
147
|
+
amount: amountStr
|
|
148
|
+
});
|
|
149
|
+
try {
|
|
150
|
+
const {
|
|
151
|
+
data
|
|
152
|
+
} = await _api.default.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
|
|
153
|
+
priceId,
|
|
154
|
+
amount: amountStr
|
|
155
|
+
});
|
|
156
|
+
setState({
|
|
157
|
+
checkoutSession: data
|
|
158
|
+
});
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error(err);
|
|
161
|
+
_Toast.default.error((0, _util2.formatError)(err));
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const handlePaid = result => {
|
|
165
|
+
setState({
|
|
166
|
+
checkoutSession: result.checkoutSession
|
|
167
|
+
});
|
|
168
|
+
onPaid(result);
|
|
169
|
+
};
|
|
170
|
+
const renderBenefits = () => {
|
|
171
|
+
if (!benefits) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
if (benefits.length === 1) {
|
|
175
|
+
return t("payment.checkout.donation.benefits.one", {
|
|
176
|
+
name: benefits[0].name
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return t("payment.checkout.donation.benefits.multiple", {
|
|
180
|
+
count: benefits.length
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.FormProvider, {
|
|
184
|
+
...methods,
|
|
185
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
186
|
+
className: "cko-container",
|
|
187
|
+
sx: {
|
|
188
|
+
gap: {
|
|
189
|
+
sm: mode === "standalone" ? 0 : mode === "inline" ? 4 : 8
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
children: [completed ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
193
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_success.default, {
|
|
194
|
+
mode,
|
|
195
|
+
payee: (0, _util2.getStatementDescriptor)(state.checkoutSession.line_items),
|
|
196
|
+
action: state.checkoutSession.mode,
|
|
197
|
+
invoiceId: state.checkoutSession.invoice_id,
|
|
198
|
+
subscriptionId: state.checkoutSession.subscription_id,
|
|
199
|
+
message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t("payment.checkout.completed.donate")
|
|
200
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {
|
|
201
|
+
sx: {
|
|
202
|
+
mt: {
|
|
203
|
+
xs: "16px",
|
|
204
|
+
md: "-24px"
|
|
205
|
+
},
|
|
206
|
+
mb: {
|
|
207
|
+
xs: "16px",
|
|
208
|
+
md: "16px"
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
212
|
+
direction: "row",
|
|
213
|
+
justifyContent: "flex-end",
|
|
214
|
+
alignItems: "center",
|
|
215
|
+
flexWrap: "wrap",
|
|
216
|
+
gap: 1,
|
|
217
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
218
|
+
variant: "outlined",
|
|
219
|
+
size: "large",
|
|
220
|
+
onClick: formRender?.onCancel,
|
|
221
|
+
sx: {
|
|
222
|
+
width: "fit-content",
|
|
223
|
+
minWidth: 120
|
|
224
|
+
},
|
|
225
|
+
children: t("common.close")
|
|
226
|
+
})
|
|
227
|
+
})]
|
|
228
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
229
|
+
children: [benefitsState.open && /* @__PURE__ */(0, _jsxRuntime.jsx)(_paymentBeneficiaries.default, {
|
|
230
|
+
data: benefits,
|
|
231
|
+
currency,
|
|
232
|
+
totalAmount: benefitsState.amount
|
|
233
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
234
|
+
sx: {
|
|
235
|
+
display: benefitsState.open ? "none" : "block"
|
|
236
|
+
},
|
|
237
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
238
|
+
title: t("payment.checkout.orderSummary"),
|
|
239
|
+
sx: {
|
|
240
|
+
color: "text.primary",
|
|
241
|
+
fontSize: "18px",
|
|
242
|
+
fontWeight: "500",
|
|
243
|
+
lineHeight: "24px",
|
|
244
|
+
mb: 2
|
|
245
|
+
},
|
|
246
|
+
children: t("payment.checkout.donation.tipAmount")
|
|
247
|
+
}), items.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_productDonation.default, {
|
|
248
|
+
item: x,
|
|
249
|
+
settings: donationSettings,
|
|
250
|
+
onChange: onChangeAmount,
|
|
251
|
+
currency
|
|
252
|
+
}, `${x.price_id}-${currency.id}`))]
|
|
253
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {
|
|
254
|
+
sx: {
|
|
255
|
+
mt: {
|
|
256
|
+
xs: "32px",
|
|
257
|
+
md: "0"
|
|
258
|
+
},
|
|
259
|
+
mb: {
|
|
260
|
+
xs: "16px",
|
|
261
|
+
md: "-8px"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
265
|
+
direction: "row",
|
|
266
|
+
justifyContent: "space-between",
|
|
267
|
+
alignItems: "center",
|
|
268
|
+
flexWrap: "wrap",
|
|
269
|
+
gap: 1,
|
|
270
|
+
children: [benefits && benefits.length > 0 && (benefitsState.open ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
271
|
+
onClick: () => setBenefitsState({
|
|
272
|
+
open: false
|
|
273
|
+
}),
|
|
274
|
+
sx: {
|
|
275
|
+
cursor: "pointer",
|
|
276
|
+
color: "text.secondary",
|
|
277
|
+
"&:hover": {
|
|
278
|
+
color: "text.primary"
|
|
279
|
+
},
|
|
280
|
+
display: "flex",
|
|
281
|
+
alignItems: "center"
|
|
282
|
+
},
|
|
283
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ArrowBackOutlined, {
|
|
284
|
+
className: "benefits-arrow",
|
|
285
|
+
sx: {
|
|
286
|
+
fontSize: "18px",
|
|
287
|
+
mr: 0.5
|
|
288
|
+
}
|
|
289
|
+
}), t("common.back")]
|
|
290
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
291
|
+
display: "flex",
|
|
292
|
+
gap: 0.5,
|
|
293
|
+
alignItems: "center",
|
|
294
|
+
onClick: () => setBenefitsState({
|
|
295
|
+
open: true
|
|
296
|
+
}),
|
|
297
|
+
sx: {
|
|
298
|
+
color: "text.secondary",
|
|
299
|
+
cursor: "pointer",
|
|
300
|
+
"& .benefits-arrow": {
|
|
301
|
+
opacity: 0,
|
|
302
|
+
transform: "translateX(-4px)",
|
|
303
|
+
transition: "all 0.2s"
|
|
304
|
+
},
|
|
305
|
+
"&:hover": {
|
|
306
|
+
color: "text.primary",
|
|
307
|
+
"& .benefits-arrow": {
|
|
308
|
+
opacity: 1,
|
|
309
|
+
transform: "translateX(0)"
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.HelpOutlineOutlined, {
|
|
314
|
+
sx: {
|
|
315
|
+
fontSize: "18px"
|
|
316
|
+
}
|
|
317
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
318
|
+
children: renderBenefits()
|
|
319
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ArrowForwardOutlined, {
|
|
320
|
+
className: "benefits-arrow",
|
|
321
|
+
sx: {
|
|
322
|
+
fontSize: "18px"
|
|
323
|
+
}
|
|
324
|
+
})]
|
|
325
|
+
})), benefitsState.open ? null : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
326
|
+
display: "flex",
|
|
327
|
+
gap: 2,
|
|
328
|
+
sx: {
|
|
329
|
+
flex: {
|
|
330
|
+
xs: 1,
|
|
331
|
+
md: "auto"
|
|
332
|
+
},
|
|
333
|
+
justifyContent: "flex-end",
|
|
334
|
+
whiteSpace: "nowrap"
|
|
335
|
+
},
|
|
336
|
+
children: [formRender?.cancel, /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
|
|
337
|
+
currencyId,
|
|
338
|
+
checkoutSession: state.checkoutSession,
|
|
339
|
+
paymentMethods,
|
|
340
|
+
paymentIntent,
|
|
341
|
+
paymentLink,
|
|
342
|
+
customer,
|
|
343
|
+
onPaid: handlePaid,
|
|
344
|
+
onError,
|
|
345
|
+
mode,
|
|
346
|
+
action,
|
|
347
|
+
onlyShowBtn: true
|
|
348
|
+
})]
|
|
349
|
+
})]
|
|
350
|
+
})]
|
|
351
|
+
}), state.customerLimited && /* @__PURE__ */(0, _jsxRuntime.jsx)(_confirm.default, {
|
|
352
|
+
onConfirm: () => window.open((0, _ufo.joinURL)((0, _util2.getPrefix)(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`), "_self"),
|
|
353
|
+
onCancel: () => setState({
|
|
354
|
+
customerLimited: false
|
|
355
|
+
}),
|
|
356
|
+
confirm: t("payment.customer.pastDue.alert.confirm"),
|
|
357
|
+
title: t("payment.customer.pastDue.alert.title"),
|
|
358
|
+
message: t("payment.customer.pastDue.alert.description"),
|
|
359
|
+
color: "primary"
|
|
360
|
+
})]
|
|
361
|
+
})
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
DonationForm.defaultProps = {
|
|
365
|
+
completed: false,
|
|
366
|
+
error: null,
|
|
367
|
+
showCheckoutSummary: true,
|
|
368
|
+
formRender: {}
|
|
369
|
+
};
|
|
370
|
+
function DonationForm({
|
|
371
|
+
checkoutSession,
|
|
372
|
+
paymentMethods,
|
|
373
|
+
paymentIntent,
|
|
374
|
+
paymentLink,
|
|
375
|
+
customer,
|
|
376
|
+
completed,
|
|
377
|
+
error,
|
|
378
|
+
mode,
|
|
379
|
+
onPaid,
|
|
380
|
+
onError,
|
|
381
|
+
onChange,
|
|
382
|
+
goBack,
|
|
383
|
+
action,
|
|
384
|
+
showCheckoutSummary = true,
|
|
385
|
+
formRender,
|
|
386
|
+
id
|
|
387
|
+
}) {
|
|
388
|
+
const {
|
|
389
|
+
t
|
|
390
|
+
} = (0, _context.useLocaleContext)();
|
|
391
|
+
const {
|
|
392
|
+
refresh,
|
|
393
|
+
livemode,
|
|
394
|
+
setLivemode
|
|
395
|
+
} = (0, _payment.usePaymentContext)();
|
|
396
|
+
const {
|
|
397
|
+
isMobile
|
|
398
|
+
} = (0, _mobile.useMobile)();
|
|
399
|
+
const [delay, setDelay] = (0, _react.useState)(false);
|
|
400
|
+
const isMobileSafariEnv = (0, _util2.isMobileSafari)();
|
|
401
|
+
const paymentLinkId = id.startsWith("plink_") ? id : void 0;
|
|
402
|
+
const {
|
|
403
|
+
data: benefits,
|
|
404
|
+
loading: benefitLoading
|
|
405
|
+
} = (0, _ahooks.useRequest)(() => {
|
|
406
|
+
if (paymentLinkId) {
|
|
407
|
+
return getBenefits(paymentLinkId);
|
|
408
|
+
}
|
|
409
|
+
return Promise.resolve([]);
|
|
410
|
+
}, {
|
|
411
|
+
refreshDeps: [paymentLinkId || paymentLink?.id],
|
|
412
|
+
ready: !!paymentLinkId || !!paymentLink?.id
|
|
413
|
+
});
|
|
414
|
+
(0, _ahooks.useMount)(() => {
|
|
415
|
+
setTimeout(() => {
|
|
416
|
+
setDelay(true);
|
|
417
|
+
}, 500);
|
|
418
|
+
});
|
|
419
|
+
(0, _react.useEffect)(() => {
|
|
420
|
+
if (checkoutSession) {
|
|
421
|
+
if (livemode !== checkoutSession.livemode) {
|
|
422
|
+
setLivemode(checkoutSession.livemode);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}, [checkoutSession, livemode, setLivemode, refresh]);
|
|
426
|
+
const renderContent = () => {
|
|
427
|
+
const footer = /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
428
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {
|
|
429
|
+
sx: {
|
|
430
|
+
mt: {
|
|
431
|
+
xs: "16px",
|
|
432
|
+
md: "-24px"
|
|
433
|
+
},
|
|
434
|
+
mb: {
|
|
435
|
+
xs: "16px",
|
|
436
|
+
md: "-16px"
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
440
|
+
direction: "row",
|
|
441
|
+
justifyContent: "flex-end",
|
|
442
|
+
alignItems: "center",
|
|
443
|
+
flexWrap: "wrap",
|
|
444
|
+
gap: 1,
|
|
445
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
446
|
+
variant: "outlined",
|
|
447
|
+
size: "large",
|
|
448
|
+
onClick: formRender?.onCancel,
|
|
449
|
+
children: t("common.cancel")
|
|
450
|
+
})
|
|
451
|
+
})]
|
|
452
|
+
});
|
|
453
|
+
if (error) {
|
|
454
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
455
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
|
|
456
|
+
mode,
|
|
457
|
+
title: "Oops",
|
|
458
|
+
description: (0, _util2.formatError)(error),
|
|
459
|
+
button: null
|
|
460
|
+
}), footer]
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
if (!checkoutSession || !delay || !paymentLink || benefitLoading) {
|
|
464
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_donation.default, {});
|
|
465
|
+
}
|
|
466
|
+
if (checkoutSession?.expires_at <= Math.round(Date.now() / 1e3)) {
|
|
467
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
468
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
|
|
469
|
+
mode,
|
|
470
|
+
title: t("payment.checkout.expired.title"),
|
|
471
|
+
description: t("payment.checkout.expired.description"),
|
|
472
|
+
button: null
|
|
473
|
+
}), footer]
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
if (!checkoutSession.line_items.length) {
|
|
477
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
478
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_error.default, {
|
|
479
|
+
mode,
|
|
480
|
+
title: t("payment.checkout.emptyItems.title"),
|
|
481
|
+
description: t("payment.checkout.emptyItems.description"),
|
|
482
|
+
button: null
|
|
483
|
+
}), footer]
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(PaymentInner, {
|
|
487
|
+
formRender,
|
|
488
|
+
checkoutSession,
|
|
489
|
+
paymentMethods,
|
|
490
|
+
paymentLink,
|
|
491
|
+
paymentIntent,
|
|
492
|
+
completed: completed || checkoutSession.status === "complete",
|
|
493
|
+
customer,
|
|
494
|
+
onPaid,
|
|
495
|
+
onError,
|
|
496
|
+
onChange,
|
|
497
|
+
goBack,
|
|
498
|
+
mode,
|
|
499
|
+
action,
|
|
500
|
+
showCheckoutSummary,
|
|
501
|
+
benefits
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
505
|
+
display: "flex",
|
|
506
|
+
flexDirection: "column",
|
|
507
|
+
sx: {
|
|
508
|
+
height: mode === "standalone" ? "100vh" : "auto",
|
|
509
|
+
overflow: isMobileSafariEnv ? "visible" : "hidden"
|
|
510
|
+
},
|
|
511
|
+
children: [mode === "standalone" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_Header.default, {
|
|
512
|
+
meta: void 0,
|
|
513
|
+
addons: void 0,
|
|
514
|
+
sessionManagerProps: void 0,
|
|
515
|
+
homeLink: void 0,
|
|
516
|
+
theme: void 0,
|
|
517
|
+
hideNavMenu: void 0,
|
|
518
|
+
maxWidth: false,
|
|
519
|
+
sx: {
|
|
520
|
+
borderBottom: "1px solid var(--stroke-border-base, #EFF1F5)"
|
|
521
|
+
}
|
|
522
|
+
}) : null, /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
|
|
523
|
+
mode,
|
|
524
|
+
sx: {
|
|
525
|
+
flex: 1,
|
|
526
|
+
overflow: {
|
|
527
|
+
xs: isMobileSafariEnv ? "visible" : "auto",
|
|
528
|
+
md: "hidden"
|
|
529
|
+
},
|
|
530
|
+
...(isMobile && mode === "standalone" ? {
|
|
531
|
+
".cko-payment-submit-btn": {
|
|
532
|
+
position: "fixed",
|
|
533
|
+
bottom: 20,
|
|
534
|
+
left: 0,
|
|
535
|
+
right: 0,
|
|
536
|
+
zIndex: 999,
|
|
537
|
+
background: "#fff",
|
|
538
|
+
padding: "10px",
|
|
539
|
+
textAlign: "center",
|
|
540
|
+
button: {
|
|
541
|
+
color: "#fff",
|
|
542
|
+
maxWidth: 542
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
} : {})
|
|
546
|
+
},
|
|
547
|
+
children: [goBack && /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.ArrowBackOutlined, {
|
|
548
|
+
sx: {
|
|
549
|
+
mr: 0.5,
|
|
550
|
+
color: "text.secondary",
|
|
551
|
+
alignSelf: "flex-start",
|
|
552
|
+
margin: "16px 0",
|
|
553
|
+
cursor: "pointer"
|
|
554
|
+
},
|
|
555
|
+
onClick: goBack,
|
|
556
|
+
fontSize: "medium"
|
|
557
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
558
|
+
className: "cko-container",
|
|
559
|
+
sx: {
|
|
560
|
+
gap: {
|
|
561
|
+
sm: mode === "standalone" ? 0 : mode === "inline" ? 4 : 8
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
children: renderContent()
|
|
565
|
+
})]
|
|
566
|
+
})]
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
const Root = exports.Root = (0, _system.styled)(_material.Box)`
|
|
570
|
+
box-sizing: border-box;
|
|
571
|
+
display: flex;
|
|
572
|
+
flex-direction: column;
|
|
573
|
+
align-items: center;
|
|
574
|
+
overflow: hidden;
|
|
575
|
+
position: relative;
|
|
576
|
+
|
|
577
|
+
.cko-container {
|
|
578
|
+
overflow: hidden;
|
|
579
|
+
width: 100%;
|
|
580
|
+
display: flex;
|
|
581
|
+
flex-direction: column;
|
|
582
|
+
justify-content: center;
|
|
583
|
+
position: relative;
|
|
584
|
+
flex: 1;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
.cko-overview {
|
|
588
|
+
position: relative;
|
|
589
|
+
flex-direction: column;
|
|
590
|
+
display: ${props => props.mode.endsWith("-minimal") ? "none" : "flex"};
|
|
591
|
+
background: var(--backgrounds-bg-base);
|
|
592
|
+
min-height: 'auto';
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
.cko-footer {
|
|
596
|
+
display: ${props => props.mode.endsWith("-minimal") ? "none" : "block"};
|
|
597
|
+
text-align: center;
|
|
598
|
+
margin-top: 20px;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.cko-payment-form {
|
|
602
|
+
.MuiFormLabel-root {
|
|
603
|
+
color: var(--foregrounds-fg-base, #010714);
|
|
604
|
+
font-weight: 500;
|
|
605
|
+
margin-top: 12px;
|
|
606
|
+
margin-bottom: 4px;
|
|
607
|
+
}
|
|
608
|
+
.MuiBox-root {
|
|
609
|
+
margin: 0;
|
|
610
|
+
}
|
|
611
|
+
.MuiFormHelperText-root {
|
|
612
|
+
margin-left: 14px;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
@media (max-width: ${({
|
|
617
|
+
theme
|
|
618
|
+
}) => theme.breakpoints.values.md}px) {
|
|
619
|
+
padding-top: 0;
|
|
620
|
+
overflow: auto;
|
|
621
|
+
|
|
622
|
+
.cko-container {
|
|
623
|
+
flex-direction: column;
|
|
624
|
+
justify-content: flex-start;
|
|
625
|
+
gap: 0;
|
|
626
|
+
overflow: visible;
|
|
627
|
+
min-width: 200px;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
.cko-overview {
|
|
631
|
+
width: 100%;
|
|
632
|
+
min-height: auto;
|
|
633
|
+
flex: none;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
.cko-footer {
|
|
637
|
+
position: relative;
|
|
638
|
+
margin-bottom: 4px;
|
|
639
|
+
margin-top: 0;
|
|
640
|
+
bottom: 0;
|
|
641
|
+
left: 0;
|
|
642
|
+
transform: translateX(0);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
`;
|
package/lib/payment/error.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ type ModeType = LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal
|
|
|
3
3
|
type Props = {
|
|
4
4
|
title: string;
|
|
5
5
|
description: string;
|
|
6
|
-
button?: string;
|
|
6
|
+
button?: string | React.ReactNode;
|
|
7
7
|
mode?: ModeType;
|
|
8
8
|
};
|
|
9
9
|
declare function PaymentError({ title, description, button, mode }: Props): import("react").JSX.Element;
|
package/lib/payment/error.js
CHANGED
|
@@ -51,7 +51,7 @@ function PaymentError({
|
|
|
51
51
|
textAlign: "center"
|
|
52
52
|
},
|
|
53
53
|
children: description
|
|
54
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
54
|
+
}), typeof button === "string" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
|
|
55
55
|
variant: "text",
|
|
56
56
|
size: "small",
|
|
57
57
|
sx: {
|
|
@@ -60,7 +60,7 @@ function PaymentError({
|
|
|
60
60
|
component: _material.Link,
|
|
61
61
|
href: window.blocklet?.appUrl,
|
|
62
62
|
children: button
|
|
63
|
-
})]
|
|
63
|
+
}) : button]
|
|
64
64
|
})
|
|
65
65
|
});
|
|
66
66
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import 'react-international-phone/style.css';
|
|
2
2
|
import type { CheckoutCallbacks, CheckoutContext } from '../../types';
|
|
3
|
-
|
|
4
|
-
declare
|
|
3
|
+
export declare const waitForCheckoutComplete: (sessionId: string) => Promise<CheckoutContext>;
|
|
4
|
+
export declare const hasDidWallet: (user: any) => any;
|
|
5
|
+
type PageData = CheckoutContext & CheckoutCallbacks & {
|
|
6
|
+
onlyShowBtn?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, currencyId, onlyShowBtn, }: PageData): import("react").JSX.Element;
|
|
5
9
|
declare namespace PaymentForm {
|
|
6
|
-
var defaultProps: {
|
|
10
|
+
var defaultProps: {
|
|
11
|
+
onlyShowBtn: boolean;
|
|
12
|
+
};
|
|
7
13
|
}
|
|
8
14
|
export default PaymentForm;
|