@blocklet/payment-react 1.13.113
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/LICENSE +13 -0
- package/README.md +29 -0
- package/babel.config.es.js +8 -0
- package/build.config.ts +29 -0
- package/es/api.d.ts +2 -0
- package/es/api.js +18 -0
- package/es/checkout/index.d.ts +15 -0
- package/es/checkout/index.js +61 -0
- package/es/components/input.d.ts +23 -0
- package/es/components/input.js +44 -0
- package/es/components/livemode.d.ts +2 -0
- package/es/components/livemode.js +24 -0
- package/es/components/pricing-table.d.ts +18 -0
- package/es/components/pricing-table.js +175 -0
- package/es/components/status.d.ts +3 -0
- package/es/components/status.js +20 -0
- package/es/components/switch.d.ts +6 -0
- package/es/components/switch.js +42 -0
- package/es/contexts/payment.d.ts +29 -0
- package/es/contexts/payment.js +45 -0
- package/es/dayjs.d.ts +2 -0
- package/es/dayjs.js +14 -0
- package/es/index.d.ts +16 -0
- package/es/index.js +29 -0
- package/es/locales/en.d.ts +2 -0
- package/es/locales/en.js +213 -0
- package/es/locales/index.d.ts +10 -0
- package/es/locales/index.js +20 -0
- package/es/locales/zh.d.ts +2 -0
- package/es/locales/zh.js +213 -0
- package/es/payment/amount.d.ts +12 -0
- package/es/payment/amount.js +22 -0
- package/es/payment/error.d.ts +13 -0
- package/es/payment/error.js +12 -0
- package/es/payment/footer.d.ts +4 -0
- package/es/payment/footer.js +9 -0
- package/es/payment/form/addon.d.ts +2 -0
- package/es/payment/form/addon.js +14 -0
- package/es/payment/form/address.d.ts +7 -0
- package/es/payment/form/address.js +119 -0
- package/es/payment/form/index.d.ts +9 -0
- package/es/payment/form/index.js +337 -0
- package/es/payment/form/phone.d.ts +4 -0
- package/es/payment/form/phone.js +97 -0
- package/es/payment/form/stripe.d.ts +13 -0
- package/es/payment/form/stripe.js +158 -0
- package/es/payment/header.d.ts +7 -0
- package/es/payment/header.js +29 -0
- package/es/payment/index.d.ts +28 -0
- package/es/payment/index.js +327 -0
- package/es/payment/product-card.d.ts +21 -0
- package/es/payment/product-card.js +34 -0
- package/es/payment/product-item.d.ts +19 -0
- package/es/payment/product-item.js +107 -0
- package/es/payment/product-skeleton.d.ts +4 -0
- package/es/payment/product-skeleton.js +34 -0
- package/es/payment/skeleton/overview.d.ts +2 -0
- package/es/payment/skeleton/overview.js +13 -0
- package/es/payment/skeleton/payment.d.ts +2 -0
- package/es/payment/skeleton/payment.js +19 -0
- package/es/payment/success.d.ts +8 -0
- package/es/payment/success.js +164 -0
- package/es/payment/summary.d.ts +12 -0
- package/es/payment/summary.js +178 -0
- package/es/theme.d.ts +1 -0
- package/es/theme.js +17 -0
- package/es/types/index.d.ts +19 -0
- package/es/types/index.js +0 -0
- package/es/types/shims.d.ts +18 -0
- package/es/util.d.ts +52 -0
- package/es/util.js +390 -0
- package/lib/api.d.ts +2 -0
- package/lib/api.js +26 -0
- package/lib/checkout/index.d.ts +15 -0
- package/lib/checkout/index.js +83 -0
- package/lib/components/input.d.ts +23 -0
- package/lib/components/input.js +72 -0
- package/lib/components/livemode.d.ts +2 -0
- package/lib/components/livemode.js +29 -0
- package/lib/components/pricing-table.d.ts +18 -0
- package/lib/components/pricing-table.js +232 -0
- package/lib/components/status.d.ts +3 -0
- package/lib/components/status.js +23 -0
- package/lib/components/switch.d.ts +6 -0
- package/lib/components/switch.js +51 -0
- package/lib/contexts/payment.d.ts +29 -0
- package/lib/contexts/payment.js +73 -0
- package/lib/dayjs.d.ts +2 -0
- package/lib/dayjs.js +21 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +143 -0
- package/lib/locales/en.d.ts +2 -0
- package/lib/locales/en.js +220 -0
- package/lib/locales/index.d.ts +10 -0
- package/lib/locales/index.js +33 -0
- package/lib/locales/zh.d.ts +2 -0
- package/lib/locales/zh.js +220 -0
- package/lib/payment/amount.d.ts +12 -0
- package/lib/payment/amount.js +28 -0
- package/lib/payment/error.d.ts +13 -0
- package/lib/payment/error.js +52 -0
- package/lib/payment/footer.d.ts +4 -0
- package/lib/payment/footer.js +25 -0
- package/lib/payment/form/addon.d.ts +2 -0
- package/lib/payment/form/addon.js +37 -0
- package/lib/payment/form/address.d.ts +7 -0
- package/lib/payment/form/address.js +152 -0
- package/lib/payment/form/index.d.ts +9 -0
- package/lib/payment/form/index.js +464 -0
- package/lib/payment/form/phone.d.ts +4 -0
- package/lib/payment/form/phone.js +133 -0
- package/lib/payment/form/stripe.d.ts +13 -0
- package/lib/payment/form/stripe.js +213 -0
- package/lib/payment/header.d.ts +7 -0
- package/lib/payment/header.js +58 -0
- package/lib/payment/index.d.ts +28 -0
- package/lib/payment/index.js +382 -0
- package/lib/payment/product-card.d.ts +21 -0
- package/lib/payment/product-card.js +81 -0
- package/lib/payment/product-item.d.ts +19 -0
- package/lib/payment/product-item.js +160 -0
- package/lib/payment/product-skeleton.d.ts +4 -0
- package/lib/payment/product-skeleton.js +71 -0
- package/lib/payment/skeleton/overview.d.ts +2 -0
- package/lib/payment/skeleton/overview.js +48 -0
- package/lib/payment/skeleton/payment.d.ts +2 -0
- package/lib/payment/skeleton/payment.js +54 -0
- package/lib/payment/success.d.ts +8 -0
- package/lib/payment/success.js +215 -0
- package/lib/payment/summary.d.ts +12 -0
- package/lib/payment/summary.js +225 -0
- package/lib/theme.d.ts +1 -0
- package/lib/theme.js +19 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/index.js +1 -0
- package/lib/types/shims.d.ts +18 -0
- package/lib/util.d.ts +52 -0
- package/lib/util.js +487 -0
- package/package.json +104 -0
- package/src/api.ts +24 -0
- package/src/checkout/index.tsx +74 -0
- package/src/components/input.tsx +58 -0
- package/src/components/livemode.tsx +23 -0
- package/src/components/pricing-table.tsx +207 -0
- package/src/components/status.tsx +19 -0
- package/src/components/switch.tsx +48 -0
- package/src/contexts/payment.tsx +74 -0
- package/src/dayjs.ts +17 -0
- package/src/index.ts +32 -0
- package/src/locales/en.tsx +218 -0
- package/src/locales/index.tsx +30 -0
- package/src/locales/zh.tsx +214 -0
- package/src/payment/amount.tsx +24 -0
- package/src/payment/error.tsx +29 -0
- package/src/payment/footer.tsx +12 -0
- package/src/payment/form/addon.tsx +24 -0
- package/src/payment/form/address.tsx +119 -0
- package/src/payment/form/index.tsx +401 -0
- package/src/payment/form/phone.tsx +103 -0
- package/src/payment/form/stripe.tsx +195 -0
- package/src/payment/header.tsx +40 -0
- package/src/payment/index.tsx +367 -0
- package/src/payment/product-card.tsx +55 -0
- package/src/payment/product-item.tsx +121 -0
- package/src/payment/product-skeleton.tsx +39 -0
- package/src/payment/skeleton/overview.tsx +21 -0
- package/src/payment/skeleton/payment.tsx +35 -0
- package/src/payment/success.tsx +186 -0
- package/src/payment/summary.tsx +198 -0
- package/src/theme.ts +18 -0
- package/src/types/index.ts +29 -0
- package/src/types/shims.d.ts +18 -0
- package/src/util.ts +543 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = PhoneInput;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _material = require("@mui/material");
|
|
9
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _reactHookForm = require("react-hook-form");
|
|
12
|
+
var _reactInternationalPhone = require("react-international-phone");
|
|
13
|
+
var _input = _interopRequireDefault(require("../../components/input"));
|
|
14
|
+
var _util = require("../../util");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function PhoneInput({
|
|
17
|
+
...props
|
|
18
|
+
}) {
|
|
19
|
+
const countryFieldName = props.countryFieldName || "billing_address.country";
|
|
20
|
+
const {
|
|
21
|
+
control,
|
|
22
|
+
getValues,
|
|
23
|
+
setValue
|
|
24
|
+
} = (0, _reactHookForm.useFormContext)();
|
|
25
|
+
const values = getValues();
|
|
26
|
+
const {
|
|
27
|
+
phone,
|
|
28
|
+
handlePhoneValueChange,
|
|
29
|
+
inputRef,
|
|
30
|
+
country,
|
|
31
|
+
setCountry
|
|
32
|
+
} = (0, _reactInternationalPhone.usePhoneInput)({
|
|
33
|
+
defaultCountry: (0, _util.isValidCountry)(values[countryFieldName]) ? values[countryFieldName] : "us",
|
|
34
|
+
value: values[props.name] || "",
|
|
35
|
+
countries: _reactInternationalPhone.defaultCountries,
|
|
36
|
+
onChange: data => {
|
|
37
|
+
setValue(props.name, data.phone);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const userCountry = (0, _reactHookForm.useWatch)({
|
|
41
|
+
control,
|
|
42
|
+
name: countryFieldName
|
|
43
|
+
});
|
|
44
|
+
(0, _react.useEffect)(() => {
|
|
45
|
+
if (userCountry !== country) {
|
|
46
|
+
setCountry(userCountry);
|
|
47
|
+
}
|
|
48
|
+
}, [userCountry]);
|
|
49
|
+
const onCountryChange = e => {
|
|
50
|
+
setCountry(e.target.value);
|
|
51
|
+
setValue(countryFieldName, e.target.value);
|
|
52
|
+
};
|
|
53
|
+
return (
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
/* @__PURE__ */
|
|
56
|
+
(0, _jsxRuntime.jsx)(_input.default, {
|
|
57
|
+
value: phone,
|
|
58
|
+
onChange: handlePhoneValueChange,
|
|
59
|
+
type: "tel",
|
|
60
|
+
inputRef,
|
|
61
|
+
InputProps: {
|
|
62
|
+
startAdornment: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.InputAdornment, {
|
|
63
|
+
position: "start",
|
|
64
|
+
style: {
|
|
65
|
+
marginRight: "2px",
|
|
66
|
+
marginLeft: "-8px"
|
|
67
|
+
},
|
|
68
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Select, {
|
|
69
|
+
MenuProps: {
|
|
70
|
+
style: {
|
|
71
|
+
height: "300px",
|
|
72
|
+
width: "360px",
|
|
73
|
+
top: "10px",
|
|
74
|
+
left: "-34px"
|
|
75
|
+
},
|
|
76
|
+
transformOrigin: {
|
|
77
|
+
vertical: "top",
|
|
78
|
+
horizontal: "left"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
sx: {
|
|
82
|
+
width: "max-content",
|
|
83
|
+
// Remove default outline (display only on focus)
|
|
84
|
+
fieldset: {
|
|
85
|
+
display: "none"
|
|
86
|
+
},
|
|
87
|
+
'&.Mui-focused:has(div[aria-expanded="false"])': {
|
|
88
|
+
fieldset: {
|
|
89
|
+
display: "block"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
// Update default spacing
|
|
93
|
+
".MuiSelect-select": {
|
|
94
|
+
padding: "8px",
|
|
95
|
+
paddingRight: "24px !important"
|
|
96
|
+
},
|
|
97
|
+
svg: {
|
|
98
|
+
right: 0
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
value: country,
|
|
102
|
+
onChange: onCountryChange,
|
|
103
|
+
renderValue: code => /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
|
|
104
|
+
iso2: code,
|
|
105
|
+
style: {
|
|
106
|
+
display: "flex"
|
|
107
|
+
}
|
|
108
|
+
}),
|
|
109
|
+
children: _reactInternationalPhone.defaultCountries.map(c => {
|
|
110
|
+
const parsed = (0, _reactInternationalPhone.parseCountry)(c);
|
|
111
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
|
112
|
+
value: parsed.iso2,
|
|
113
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactInternationalPhone.FlagEmoji, {
|
|
114
|
+
iso2: parsed.iso2,
|
|
115
|
+
style: {
|
|
116
|
+
marginRight: "8px"
|
|
117
|
+
}
|
|
118
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
119
|
+
marginRight: "8px",
|
|
120
|
+
children: parsed.name
|
|
121
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
122
|
+
color: "gray",
|
|
123
|
+
children: ["+", parsed.dialCode]
|
|
124
|
+
})]
|
|
125
|
+
}, parsed.iso2);
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
...(0, _omit.default)(props, ["countryFieldName"])
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TCustomer } from '@blocklet/payment-types';
|
|
3
|
+
type StripeCheckoutProps = {
|
|
4
|
+
clientSecret: string;
|
|
5
|
+
intentType: string;
|
|
6
|
+
publicKey: string;
|
|
7
|
+
mode: string;
|
|
8
|
+
customer: TCustomer;
|
|
9
|
+
onConfirm: Function;
|
|
10
|
+
onCancel: Function;
|
|
11
|
+
};
|
|
12
|
+
export default function StripeCheckout({ clientSecret, intentType, publicKey, mode, customer, onConfirm, onCancel, }: StripeCheckoutProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = StripeCheckout;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _Center = _interopRequireDefault(require("@arcblock/ux/lib/Center"));
|
|
9
|
+
var _Dialog = _interopRequireDefault(require("@arcblock/ux/lib/Dialog"));
|
|
10
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
11
|
+
var _lab = require("@mui/lab");
|
|
12
|
+
var _material = require("@mui/material");
|
|
13
|
+
var _system = require("@mui/system");
|
|
14
|
+
var _reactStripeJs = require("@stripe/react-stripe-js");
|
|
15
|
+
var _stripeJs = require("@stripe/stripe-js");
|
|
16
|
+
var _ahooks = require("ahooks");
|
|
17
|
+
var _react = require("react");
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
function StripeCheckoutForm({
|
|
20
|
+
clientSecret,
|
|
21
|
+
intentType,
|
|
22
|
+
customer,
|
|
23
|
+
mode,
|
|
24
|
+
onConfirm
|
|
25
|
+
}) {
|
|
26
|
+
const stripe = (0, _reactStripeJs.useStripe)();
|
|
27
|
+
const elements = (0, _reactStripeJs.useElements)();
|
|
28
|
+
const {
|
|
29
|
+
t
|
|
30
|
+
} = (0, _context.useLocaleContext)();
|
|
31
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
32
|
+
message: "",
|
|
33
|
+
confirming: false,
|
|
34
|
+
loaded: false
|
|
35
|
+
});
|
|
36
|
+
(0, _react.useEffect)(() => {
|
|
37
|
+
if (!stripe) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!clientSecret) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const method = intentType === "payment_intent" ? "retrievePaymentIntent" : "retrieveSetupIntent";
|
|
44
|
+
stripe[method](clientSecret).then(({
|
|
45
|
+
paymentIntent,
|
|
46
|
+
setupIntent
|
|
47
|
+
}) => {
|
|
48
|
+
const intent = paymentIntent || setupIntent;
|
|
49
|
+
switch (intent?.status) {
|
|
50
|
+
case "succeeded":
|
|
51
|
+
setState({
|
|
52
|
+
message: t("paymentCredit.preparePayMessage.succeeded")
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
case "processing":
|
|
56
|
+
setState({
|
|
57
|
+
message: t("paymentCredit.preparePayMessage.processing")
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
case "requires_payment_method":
|
|
61
|
+
default:
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}, [stripe, clientSecret]);
|
|
66
|
+
const handleSubmit = async e => {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
if (!stripe || !elements) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
setState({
|
|
73
|
+
confirming: true
|
|
74
|
+
});
|
|
75
|
+
const method = intentType === "payment_intent" ? "confirmPayment" : "confirmSetup";
|
|
76
|
+
const {
|
|
77
|
+
error
|
|
78
|
+
} = await stripe[method]({
|
|
79
|
+
elements,
|
|
80
|
+
redirect: "if_required",
|
|
81
|
+
confirmParams: {
|
|
82
|
+
payment_method_data: {
|
|
83
|
+
billing_details: {
|
|
84
|
+
name: customer.name,
|
|
85
|
+
phone: customer.phone,
|
|
86
|
+
email: customer.email,
|
|
87
|
+
address: customer.address
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
setState({
|
|
93
|
+
confirming: false
|
|
94
|
+
});
|
|
95
|
+
if (error) {
|
|
96
|
+
if (error.type === "validation_error") {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
setState({
|
|
100
|
+
message: error.message
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
onConfirm();
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.error(err);
|
|
107
|
+
setState({
|
|
108
|
+
confirming: false,
|
|
109
|
+
message: err.message
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Content, {
|
|
114
|
+
onSubmit: handleSubmit,
|
|
115
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactStripeJs.PaymentElement, {
|
|
116
|
+
options: {
|
|
117
|
+
layout: "auto",
|
|
118
|
+
fields: {
|
|
119
|
+
billingDetails: "never"
|
|
120
|
+
},
|
|
121
|
+
readOnly: state.confirming
|
|
122
|
+
},
|
|
123
|
+
onReady: () => setState({
|
|
124
|
+
loaded: true
|
|
125
|
+
})
|
|
126
|
+
}), (!stripe || !elements || !state.loaded) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_Center.default, {
|
|
127
|
+
relative: "parent",
|
|
128
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {})
|
|
129
|
+
}), stripe && elements && state.loaded && /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
|
|
130
|
+
fullWidth: true,
|
|
131
|
+
sx: {
|
|
132
|
+
mt: 2,
|
|
133
|
+
mb: 1,
|
|
134
|
+
borderRadius: 0,
|
|
135
|
+
fontSize: "1.1rem"
|
|
136
|
+
},
|
|
137
|
+
type: "submit",
|
|
138
|
+
disabled: state.confirming || !state.loaded,
|
|
139
|
+
loading: state.confirming,
|
|
140
|
+
loadingPosition: "end",
|
|
141
|
+
variant: "contained",
|
|
142
|
+
color: "primary",
|
|
143
|
+
size: "large",
|
|
144
|
+
children: t("payment.checkout.continue", {
|
|
145
|
+
action: mode
|
|
146
|
+
})
|
|
147
|
+
}), state.message && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
148
|
+
sx: {
|
|
149
|
+
mt: 1,
|
|
150
|
+
color: "error.main"
|
|
151
|
+
},
|
|
152
|
+
children: state.message
|
|
153
|
+
})]
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const Content = (0, _system.styled)("form")`
|
|
157
|
+
display: flex;
|
|
158
|
+
flex-direction: column;
|
|
159
|
+
justify-content: center;
|
|
160
|
+
align-items: center;
|
|
161
|
+
width: 100%;
|
|
162
|
+
height: 100%;
|
|
163
|
+
min-height: 320px;
|
|
164
|
+
`;
|
|
165
|
+
function StripeCheckout({
|
|
166
|
+
clientSecret,
|
|
167
|
+
intentType,
|
|
168
|
+
publicKey,
|
|
169
|
+
mode,
|
|
170
|
+
customer,
|
|
171
|
+
onConfirm,
|
|
172
|
+
onCancel
|
|
173
|
+
}) {
|
|
174
|
+
const stripePromise = (0, _stripeJs.loadStripe)(publicKey);
|
|
175
|
+
const {
|
|
176
|
+
t
|
|
177
|
+
} = (0, _context.useLocaleContext)();
|
|
178
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
179
|
+
open: true,
|
|
180
|
+
closable: true
|
|
181
|
+
});
|
|
182
|
+
const handleClose = (_, reason) => {
|
|
183
|
+
if (reason === "backdropClick") {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
setState({
|
|
187
|
+
open: false
|
|
188
|
+
});
|
|
189
|
+
onCancel();
|
|
190
|
+
};
|
|
191
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_Dialog.default, {
|
|
192
|
+
title: t("payment.checkout.cardPay", {
|
|
193
|
+
action: t(`payment.checkout.${mode}`)
|
|
194
|
+
}),
|
|
195
|
+
showCloseButton: state.closable,
|
|
196
|
+
open: state.open,
|
|
197
|
+
onClose: handleClose,
|
|
198
|
+
disableEscapeKeyDown: true,
|
|
199
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactStripeJs.Elements, {
|
|
200
|
+
options: {
|
|
201
|
+
clientSecret
|
|
202
|
+
},
|
|
203
|
+
stripe: stripePromise,
|
|
204
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(StripeCheckoutForm, {
|
|
205
|
+
clientSecret,
|
|
206
|
+
intentType,
|
|
207
|
+
mode,
|
|
208
|
+
customer,
|
|
209
|
+
onConfirm
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TCheckoutSessionExpanded } from '@blocklet/payment-types';
|
|
3
|
+
type Props = {
|
|
4
|
+
checkoutSession: TCheckoutSessionExpanded;
|
|
5
|
+
};
|
|
6
|
+
export default function PaymentHeader({ checkoutSession }: Props): import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = PaymentHeader;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _Theme = require("@arcblock/ux/lib/Theme");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _ahooks = require("ahooks");
|
|
11
|
+
var _livemode = _interopRequireDefault(require("../components/livemode"));
|
|
12
|
+
var _util = require("../util");
|
|
13
|
+
var _addon = _interopRequireDefault(require("./form/addon"));
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function PaymentHeader({
|
|
16
|
+
checkoutSession
|
|
17
|
+
}) {
|
|
18
|
+
const [livemode] = (0, _ahooks.useLocalStorageState)("livemode", {
|
|
19
|
+
defaultValue: true
|
|
20
|
+
});
|
|
21
|
+
const brand = (0, _util.getStatementDescriptor)(checkoutSession.line_items);
|
|
22
|
+
const theme = (0, _Theme.useTheme)();
|
|
23
|
+
const domSize = (0, _ahooks.useSize)(document.body);
|
|
24
|
+
const isColumnLayout = (0, _ahooks.useCreation)(() => {
|
|
25
|
+
if (domSize) {
|
|
26
|
+
if (domSize?.width <= theme.breakpoints.values.md) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}, [domSize, theme]);
|
|
32
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
33
|
+
className: "cko-header",
|
|
34
|
+
direction: "row",
|
|
35
|
+
spacing: 1,
|
|
36
|
+
alignItems: "center",
|
|
37
|
+
justifyContent: "space-between",
|
|
38
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
39
|
+
direction: "row",
|
|
40
|
+
spacing: 1,
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
|
|
43
|
+
variant: "square",
|
|
44
|
+
src: window.blocklet.appLogo,
|
|
45
|
+
sx: {
|
|
46
|
+
width: 32,
|
|
47
|
+
height: 32
|
|
48
|
+
}
|
|
49
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
50
|
+
sx: {
|
|
51
|
+
color: "text.primary",
|
|
52
|
+
fontWeight: 600
|
|
53
|
+
},
|
|
54
|
+
children: brand
|
|
55
|
+
}), !livemode && /* @__PURE__ */(0, _jsxRuntime.jsx)(_livemode.default, {})]
|
|
56
|
+
}), isColumnLayout ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_addon.default, {}) : null]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CheckoutCallbacks, CheckoutContext } from '../types';
|
|
3
|
+
type Props = CheckoutContext & CheckoutCallbacks & {
|
|
4
|
+
completed?: boolean;
|
|
5
|
+
error?: any;
|
|
6
|
+
};
|
|
7
|
+
declare function Payment({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, completed, error, mode, onPaid, onError, }: Props): import("react").JSX.Element;
|
|
8
|
+
declare namespace Payment {
|
|
9
|
+
var defaultProps: {
|
|
10
|
+
completed: boolean;
|
|
11
|
+
error: null;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export default Payment;
|
|
15
|
+
type MainProps = CheckoutContext & CheckoutCallbacks & {
|
|
16
|
+
completed?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function PaymentInner({ checkoutSession, paymentMethods, paymentLink, paymentIntent, customer, completed, mode, onPaid, onError, }: MainProps): import("react").JSX.Element;
|
|
19
|
+
export declare namespace PaymentInner {
|
|
20
|
+
var defaultProps: {
|
|
21
|
+
completed: boolean;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare const Root: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
25
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
26
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/system").Theme> & {
|
|
27
|
+
mode: string;
|
|
28
|
+
}, {}, {}>;
|