@paykka/card-checkout-ui 0.5.15 → 0.6.0

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.
Files changed (108) hide show
  1. package/dist/card-checkout-ui.js +22 -0
  2. package/dist/card-checkout-ui.umd.cjs +19 -5
  3. package/dist/es/api/index.js +3 -0
  4. package/dist/es/api/modules/checkout/map.js +2 -1
  5. package/dist/es/api/modules/encrypted-card/index.js +54 -0
  6. package/dist/es/api/modules/get-browser-params.js +2 -2
  7. package/dist/es/api/modules/index.js +3 -0
  8. package/dist/es/components/AccountNameField/index.js +4 -0
  9. package/dist/es/components/AddressField/index.js +4 -0
  10. package/dist/es/components/AliPay/index.js +8 -8
  11. package/dist/es/components/ApplePay/index.js +71 -14
  12. package/dist/es/components/Card/index.js +56 -40
  13. package/dist/es/components/CardExpireDateField/index.js +8 -3
  14. package/dist/es/components/CardHolderNameField/index.js +4 -0
  15. package/dist/es/components/CardIBANField/index.js +4 -0
  16. package/dist/es/components/CardNumberField/index.js +34 -17
  17. package/dist/es/components/CardSecurityCodeField/index.js +8 -3
  18. package/dist/es/components/CardSelector/index.js +3 -0
  19. package/dist/es/components/CombinedEncryptedField/index.js +75 -0
  20. package/dist/es/components/EmailField/EmailField.js +4 -0
  21. package/dist/es/components/EncryptedCard/index.js +448 -0
  22. package/dist/es/components/GooglePay/index.js +57 -19
  23. package/dist/es/components/RecurringTip/index.js +1 -1
  24. package/dist/es/components/SecuredFieldsProvider/SecuredFieldsProvider.js +70 -25
  25. package/dist/es/components/SecuredIframe/index.js +190 -22
  26. package/dist/es/components/Sepa/index.js +16 -6
  27. package/dist/es/components/WechatPay/index.js +8 -8
  28. package/dist/es/components/index.js +4 -0
  29. package/dist/es/components/internal/CheckBox/CheckBox.js +1 -1
  30. package/dist/es/components/internal/Form/FormItem.js +28 -24
  31. package/dist/es/components/internal/Form/index.js +1 -0
  32. package/dist/es/components/internal/Form/type.js +15 -1
  33. package/dist/es/components/internal/Input/Input.js +9 -11
  34. package/dist/es/components/internal/Input/index.js +1 -0
  35. package/dist/es/components/internal/Input/type.js +13 -1
  36. package/dist/es/components/internal/Select/Select.js +2 -0
  37. package/dist/es/config.js +23 -6
  38. package/dist/es/constant.js +10 -0
  39. package/dist/es/core/PayKKaCheckout.js +62 -0
  40. package/dist/es/core/Session.js +3 -0
  41. package/dist/es/core/index.js +2 -0
  42. package/dist/es/core/query.js +4 -6
  43. package/dist/es/core.js +30 -30
  44. package/dist/es/hooks/useI18n.js +2 -2
  45. package/dist/es/hooks/usePayState.js +14 -25
  46. package/dist/es/i18n/I18n.js +11 -8
  47. package/dist/es/index.js +16 -3
  48. package/dist/es/out/fraud-detection.js +99 -0
  49. package/dist/es/style.css +8 -0
  50. package/dist/es/types/{radar.js → fraud-detection.js} +1 -1
  51. package/dist/es/types/index.js +49 -1
  52. package/dist/es/utils/card-brand/brands.js +16 -42
  53. package/dist/es/utils/index.js +11 -0
  54. package/dist/es/utils/load.js +14 -0
  55. package/dist/es/utils/style.js +37 -0
  56. package/dist/style.css +1 -1
  57. package/dist/types/api/modules/checkout/map.d.ts +1 -0
  58. package/dist/types/api/modules/encrypted-card/index.d.ts +6 -0
  59. package/dist/types/api/modules/encrypted-card/type.d.ts +31 -0
  60. package/dist/types/api/modules/get-browser-params.d.ts +2 -2
  61. package/dist/types/components/AliPay/type.d.ts +0 -4
  62. package/dist/types/components/ApplePay/type.d.ts +16 -7
  63. package/dist/types/components/ApplePay/utils.d.ts +3 -0
  64. package/dist/types/components/Card/type.d.ts +15 -5
  65. package/dist/types/components/CardExpireDateField/type.d.ts +1 -0
  66. package/dist/types/components/CardNumberField/type.d.ts +3 -0
  67. package/dist/types/components/CardSecurityCodeField/type.d.ts +1 -0
  68. package/dist/types/components/CombinedEncryptedField/CombinedEncryptedField.d.ts +4 -0
  69. package/dist/types/components/CombinedEncryptedField/index.d.ts +2 -0
  70. package/dist/types/components/CombinedEncryptedField/type.d.ts +15 -0
  71. package/dist/types/components/EncryptedCard/EncryptedCard.d.ts +4 -0
  72. package/dist/types/components/EncryptedCard/index.d.ts +4 -0
  73. package/dist/types/components/EncryptedCard/output.d.ts +9 -0
  74. package/dist/types/components/EncryptedCard/type.d.ts +85 -0
  75. package/dist/types/components/GooglePay/type.d.ts +17 -8
  76. package/dist/types/components/GooglePay/utils.d.ts +2 -0
  77. package/dist/types/components/SecuredFieldsProvider/type.d.ts +103 -22
  78. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +6 -2
  79. package/dist/types/components/Sepa/type.d.ts +0 -4
  80. package/dist/types/components/WechatPay/type.d.ts +0 -4
  81. package/dist/types/components/index.d.ts +2 -0
  82. package/dist/types/components/internal/Form/FormItem.d.ts +1 -1
  83. package/dist/types/components/internal/Form/type.d.ts +7 -0
  84. package/dist/types/components/internal/Input/Input.d.ts +1 -1
  85. package/dist/types/components/internal/Input/type.d.ts +6 -0
  86. package/dist/types/config.d.ts +10 -3
  87. package/dist/types/constant.d.ts +1 -0
  88. package/dist/types/core/PayKKaCheckout.d.ts +12 -0
  89. package/dist/types/core/index.d.ts +1 -0
  90. package/dist/types/core/query.d.ts +2 -2
  91. package/dist/types/hooks/useI18n.d.ts +2 -2
  92. package/dist/types/hooks/usePayState.d.ts +4 -22
  93. package/dist/types/i18n/I18n.d.ts +6 -5
  94. package/dist/types/i18n/locales/index.d.ts +1 -0
  95. package/dist/types/index.d.ts +3 -3
  96. package/dist/types/out/fraud-detection.d.ts +9 -0
  97. package/dist/types/types/{radar.d.ts → fraud-detection.d.ts} +3 -2
  98. package/dist/types/types/index.d.ts +69 -1
  99. package/dist/types/utils/card-brand/brands.d.ts +3 -10
  100. package/dist/types/utils/card-brand/index.d.ts +10 -9
  101. package/dist/types/utils/format.d.ts +2 -3
  102. package/dist/types/utils/index.d.ts +3 -0
  103. package/dist/types/utils/load.d.ts +7 -0
  104. package/dist/types/utils/style.d.ts +17 -0
  105. package/package.json +2 -2
  106. package/dist/card-checkout-ui.iife.js +0 -8
  107. package/dist/es/out/radar.js +0 -123
  108. package/dist/types/out/radar.d.ts +0 -14
@@ -9,10 +9,12 @@ import "../core/context.js";
9
9
  import "../i18n/util.js";
10
10
  import "../i18n/locales/index.js";
11
11
  import "./CardExpireDateField/index.js";
12
+ import "./internal/Form/type.js";
12
13
  import "./internal/Form/context.js";
13
14
  import "./internal/Form/FormItem.js";
14
15
  import "./internal/Form/Form.js";
15
16
  import "./internal/Input/Input.js";
17
+ import "./internal/Input/type.js";
16
18
  import "./CardNumberField/index.js";
17
19
  import "./CardSecurityCodeField/index.js";
18
20
  import "./CardSelector/index.js";
@@ -25,3 +27,5 @@ import "./WechatPay/index.js";
25
27
  import "./ApplePay/index.js";
26
28
  import "./GooglePay/index.js";
27
29
  import "./Sepa/index.js";
30
+ import "./EncryptedCard/index.js";
31
+ import "./CombinedEncryptedField/index.js";
@@ -5,9 +5,9 @@ import "../../../core/context.js";
5
5
  import "../../../utils/card-brand/brands.js";
6
6
  import "../../../utils/system-info/get-browser-info.js";
7
7
  import { normalizedClass } from "../../../utils/format.js";
8
- import { COMMON_CLASS_NAME } from "../../../constant.js";
9
8
  import "../../../i18n/util.js";
10
9
  import "../../../i18n/locales/index.js";
10
+ import { COMMON_CLASS_NAME } from "../../../constant.js";
11
11
  import { IconChecked } from "../icons/iconChecked.js";
12
12
  const { bem } = useBEM("check-box");
13
13
  const CheckBox = (props) => {
@@ -1,18 +1,14 @@
1
1
  import { w, F, x, h, y, u } from "../../../core.js";
2
2
  import "./form-item.js";
3
3
  import { COMMON_CLASS_NAME } from "../../../constant.js";
4
- import { useBEM } from "../../../hooks/useBEM.js";
5
- import "../../../core/context.js";
6
4
  import { isNil } from "../../../utils/is.js";
7
5
  import "../../../utils/card-brand/brands.js";
8
6
  import "../../../utils/system-info/get-browser-info.js";
9
7
  import { normalizedClass } from "../../../utils/format.js";
10
8
  import { set } from "../../../utils/obj.js";
11
- import "../../../i18n/util.js";
12
- import "../../../i18n/locales/index.js";
13
9
  import { FormItemContext, FormContext } from "./context.js";
10
+ import { formItemBEM, formItemLabelClassName, formItemErrorMessageClassName } from "./type.js";
14
11
  import { getActiveRules } from "./util.js";
15
- const { bem } = useBEM("form-item");
16
12
  const isEmpty = (value) => isNil(value) || value === "";
17
13
  const FormItem = w((props, ref) => {
18
14
  const {
@@ -23,7 +19,8 @@ const FormItem = w((props, ref) => {
23
19
  onValidationStatusChange,
24
20
  className,
25
21
  style,
26
- showErrorMessage = true
22
+ showErrorMessage = true,
23
+ showLabel = true
27
24
  } = props;
28
25
  F(ref, () => ({
29
26
  validate: internalValidate,
@@ -136,24 +133,31 @@ const FormItem = w((props, ref) => {
136
133
  path && (formContext == null ? void 0 : formContext.setFormItems((prev) => prev.filter((item) => item !== internalRef)));
137
134
  };
138
135
  }, []);
139
- return /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem(), className), style, children: [
140
- !isNil(label) && /* @__PURE__ */ u("div", { className: bem("label"), children: label }),
141
- /* @__PURE__ */ u(
142
- FormItemContext.Provider,
143
- {
144
- value: {
145
- rule: props.rule,
146
- validateBlur,
147
- validateChange,
148
- resetValidation,
149
- validationResult,
150
- setValue
151
- },
152
- children
153
- }
154
- ),
155
- showErrorMessage && validationResult.status === "error" && /* @__PURE__ */ u("div", { className: bem("error-text"), children: getFirstError().message })
156
- ] });
136
+ return /* @__PURE__ */ u(
137
+ "div",
138
+ {
139
+ className: normalizedClass(COMMON_CLASS_NAME, formItemBEM.bem(), className),
140
+ style,
141
+ children: [
142
+ showLabel && !isNil(label) && /* @__PURE__ */ u("div", { className: formItemLabelClassName, children: label }),
143
+ /* @__PURE__ */ u(
144
+ FormItemContext.Provider,
145
+ {
146
+ value: {
147
+ rule: props.rule,
148
+ validateBlur,
149
+ validateChange,
150
+ resetValidation,
151
+ validationResult,
152
+ setValue
153
+ },
154
+ children
155
+ }
156
+ ),
157
+ showErrorMessage && validationResult.status === "error" && /* @__PURE__ */ u("div", { className: formItemErrorMessageClassName, children: getFirstError().message })
158
+ ]
159
+ }
160
+ );
157
161
  });
158
162
  export {
159
163
  FormItem
@@ -1,3 +1,4 @@
1
+ import "./type.js";
1
2
  import "./context.js";
2
3
  import "./FormItem.js";
3
4
  import "./Form.js";
@@ -1 +1,15 @@
1
-
1
+ import { useBEM } from "../../../hooks/useBEM.js";
2
+ import "../../../core.js";
3
+ import "../../../core/context.js";
4
+ import "../../../utils/card-brand/brands.js";
5
+ import "../../../utils/system-info/get-browser-info.js";
6
+ import "../../../i18n/util.js";
7
+ import "../../../i18n/locales/index.js";
8
+ const formItemBEM = useBEM("form-item");
9
+ const formItemLabelClassName = formItemBEM.bem("label");
10
+ const formItemErrorMessageClassName = formItemBEM.bem("error-text");
11
+ export {
12
+ formItemBEM,
13
+ formItemErrorMessageClassName,
14
+ formItemLabelClassName
15
+ };
@@ -1,19 +1,16 @@
1
1
  import { w, F, x, h, A, w$1, u } from "../../../core.js";
2
2
  import "./input2.js";
3
3
  import { COMMON_CLASS_NAME } from "../../../constant.js";
4
- import { useBEM } from "../../../hooks/useBEM.js";
5
- import "../../../core/context.js";
6
4
  import "../../../utils/card-brand/brands.js";
7
5
  import "../../../utils/system-info/get-browser-info.js";
8
6
  import { normalizedClass } from "../../../utils/format.js";
9
- import "../../../i18n/util.js";
10
- import "../../../i18n/locales/index.js";
7
+ import "../Form/type.js";
11
8
  import { FormItemContext } from "../Form/context.js";
12
9
  import "../Form/FormItem.js";
13
10
  import "../Form/Form.js";
14
11
  import { IconError } from "../icons/IconError.js";
15
12
  import { IconSuccess } from "../icons/IconSuccess.js";
16
- const { bem } = useBEM("input");
13
+ import { inputBEM } from "./type.js";
17
14
  const statusIconMap = {
18
15
  error: IconError,
19
16
  success: IconSuccess
@@ -74,13 +71,13 @@ const Input = w((props, ref) => {
74
71
  formItemContext == null ? void 0 : formItemContext.validateChange(value);
75
72
  }
76
73
  const inputWrapperClass = w$1(() => {
77
- const inputWrapper = bem("input-wrapper", [
74
+ const inputWrapper = inputBEM.bem("input-wrapper", [
78
75
  status,
79
76
  {
80
77
  focus: isFocus
81
78
  }
82
79
  ]);
83
- const inputWrapperDisabled = bem("input-wrapper-disabled");
80
+ const inputWrapperDisabled = inputBEM.bem("input-wrapper-disabled");
84
81
  return disabled ? `${inputWrapper} ${inputWrapperDisabled}` : `${inputWrapper}`;
85
82
  });
86
83
  function onCompositionStart(e) {
@@ -92,16 +89,17 @@ const Input = w((props, ref) => {
92
89
  isComposing = false;
93
90
  onInput(e);
94
91
  }
95
- return /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem(), inputClassName), style, onClick: () => {
92
+ return /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, inputBEM.bem(), inputClassName), onClick: () => {
96
93
  var _a;
97
94
  return (_a = inputRef.current) == null ? void 0 : _a.focus();
98
- }, children: /* @__PURE__ */ u("div", { className: inputWrapperClass, children: [
95
+ }, children: /* @__PURE__ */ u("div", { className: `${inputWrapperClass}`, style, children: [
96
+ !!props.leftIcon && /* @__PURE__ */ u("div", { class: inputBEM.bem("left-icon"), children: props.leftIcon }),
99
97
  children ? children : /* @__PURE__ */ u(
100
98
  "input",
101
99
  {
102
100
  ref: inputRef,
103
101
  ...props,
104
- class: bem("input"),
102
+ class: inputBEM.bem("input"),
105
103
  onFocus,
106
104
  onBlur,
107
105
  onInput,
@@ -110,7 +108,7 @@ const Input = w((props, ref) => {
110
108
  autocomplete: "off"
111
109
  }
112
110
  ),
113
- !!rightIcon && /* @__PURE__ */ u("div", { class: bem("right-icon"), children: rightIcon })
111
+ !!rightIcon && /* @__PURE__ */ u("div", { class: inputBEM.bem("right-icon"), children: rightIcon })
114
112
  ] }) });
115
113
  });
116
114
  export {
@@ -1 +1,2 @@
1
1
  import "./Input.js";
2
+ import "./type.js";
@@ -1 +1,13 @@
1
-
1
+ import { useBEM } from "../../../hooks/useBEM.js";
2
+ import "../../../core.js";
3
+ import "../../../core/context.js";
4
+ import "../../../utils/card-brand/brands.js";
5
+ import "../../../utils/system-info/get-browser-info.js";
6
+ import "../../../i18n/util.js";
7
+ import "../../../i18n/locales/index.js";
8
+ const inputBEM = useBEM("input");
9
+ const inputWrapperClassName = inputBEM.bem("input-wrapper");
10
+ export {
11
+ inputBEM,
12
+ inputWrapperClassName
13
+ };
@@ -6,11 +6,13 @@ import "../../../utils/card-brand/brands.js";
6
6
  import "../../../utils/system-info/get-browser-info.js";
7
7
  import "../../../i18n/util.js";
8
8
  import "../../../i18n/locales/index.js";
9
+ import "../Form/type.js";
9
10
  import { FormItemContext } from "../Form/context.js";
10
11
  import "../Form/FormItem.js";
11
12
  import "../Form/Form.js";
12
13
  import { IconArrowDown } from "../icons/IconArrowDown.js";
13
14
  import { Input } from "../Input/Input.js";
15
+ import "../Input/type.js";
14
16
  import { SelectMenu } from "./SelectMenu.js";
15
17
  import { SelectMenuItem } from "./SelectMenuItem.js";
16
18
  const { bem } = useBEM("select");
package/dist/es/config.js CHANGED
@@ -1,9 +1,16 @@
1
+ import "./utils/card-brand/brands.js";
2
+ import "./utils/system-info/get-browser-info.js";
3
+ import "./i18n/util.js";
4
+ import "./core.js";
5
+ import "./i18n/locales/index.js";
1
6
  let apiUrl = "https://checkout.aq.paykka.com";
2
7
  let cdnOrigin = "https://checkout.aq.paykka.com";
3
8
  let cdnDir = "/cp";
4
9
  let cdnUrl = `${cdnOrigin}${cdnDir}`;
5
- let radarEnv = void 0;
10
+ let fraudDetectionEnv = void 0;
6
11
  let customReqHeaders = {};
12
+ let customLocale = void 0;
13
+ let hidePaymentButton = false;
7
14
  function setApiUrl(url) {
8
15
  apiUrl = url;
9
16
  }
@@ -11,22 +18,32 @@ function setCDNUrl(url) {
11
18
  const urlInfo = new URL(url);
12
19
  cdnOrigin = urlInfo.origin;
13
20
  cdnDir = urlInfo.pathname;
14
- cdnUrl = `${cdnOrigin}${cdnDir}`;
21
+ cdnUrl = `${cdnOrigin}${cdnDir === "/" ? "" : cdnDir}`;
15
22
  }
16
- function setRadarEnv(env) {
17
- radarEnv = env;
23
+ function setFraudDetectionEnv(env) {
24
+ fraudDetectionEnv = env;
18
25
  }
19
26
  function setCustomReqHeaders(headers) {
20
27
  customReqHeaders = headers;
21
28
  }
29
+ function setCustomLocale(locale) {
30
+ customLocale = locale;
31
+ }
32
+ function setCheckoutConfig(params) {
33
+ hidePaymentButton = params.hidePaymentButton || false;
34
+ }
22
35
  export {
23
36
  apiUrl,
24
37
  cdnOrigin,
25
38
  cdnUrl,
39
+ customLocale,
26
40
  customReqHeaders,
27
- radarEnv,
41
+ fraudDetectionEnv,
42
+ hidePaymentButton,
28
43
  setApiUrl,
29
44
  setCDNUrl,
45
+ setCheckoutConfig,
46
+ setCustomLocale,
30
47
  setCustomReqHeaders,
31
- setRadarEnv
48
+ setFraudDetectionEnv
32
49
  };
@@ -17,6 +17,15 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
17
17
  PaymentMethod2["SEPA_DEBIT"] = "SEPA_DEBIT";
18
18
  return PaymentMethod2;
19
19
  })(PaymentMethod || {});
20
+ const CardPaymentMethods = [
21
+ "VISA",
22
+ "MASTER_CARD",
23
+ "JCB",
24
+ "AMEX",
25
+ "DINERS_CLUB",
26
+ "DISCOVER"
27
+ /* DISCOVER */
28
+ ];
20
29
  var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
21
30
  PaymentType2["PURCHASE"] = "PURCHASE";
22
31
  PaymentType2["PREPARE_AUTHORIZE"] = "PREPARE_AUTHORIZE";
@@ -40,6 +49,7 @@ var SessionMode = /* @__PURE__ */ ((SessionMode2) => {
40
49
  })(SessionMode || {});
41
50
  export {
42
51
  COMMON_CLASS_NAME,
52
+ CardPaymentMethods,
43
53
  EAddressType,
44
54
  PREFIX,
45
55
  PaymentMethod,
@@ -0,0 +1,62 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { create } from "./create.js";
8
+ import { Session } from "./Session.js";
9
+ import { setCheckoutConfig, setCDNUrl, setFraudDetectionEnv, setCustomLocale, setApiUrl } from "../config.js";
10
+ const _PayKKaCheckout = class _PayKKaCheckout {
11
+ constructor(config) {
12
+ __publicField(this, "config");
13
+ if (_PayKKaCheckout.instance) {
14
+ return _PayKKaCheckout.instance;
15
+ }
16
+ this.config = config;
17
+ this.init();
18
+ _PayKKaCheckout.instance = this;
19
+ }
20
+ init() {
21
+ const {
22
+ sandbox,
23
+ sessionId,
24
+ clientKey,
25
+ locale,
26
+ fraudDetectionEnv,
27
+ hidePaymentButton,
28
+ onPaymentMethodsReady,
29
+ onInitError
30
+ } = this.config;
31
+ fraudDetectionEnv && setFraudDetectionEnv(fraudDetectionEnv);
32
+ locale && setCustomLocale(locale);
33
+ setCheckoutConfig({
34
+ hidePaymentButton
35
+ });
36
+ if (sandbox) {
37
+ setApiUrl("https://checkout-sandbox.aq.paykka.com");
38
+ setCDNUrl("https://checkout-sandbox.aq.paykka.com/cp");
39
+ }
40
+ _PayKKaCheckout.session = new Session(sessionId, clientKey);
41
+ _PayKKaCheckout.session.ready().then(() => {
42
+ var _a;
43
+ const { paymentMethod = [] } = ((_a = _PayKKaCheckout.session) == null ? void 0 : _a.checkout) || {};
44
+ onPaymentMethodsReady == null ? void 0 : onPaymentMethodsReady(paymentMethod);
45
+ }).catch((error) => {
46
+ onInitError == null ? void 0 : onInitError(error);
47
+ console.log(error);
48
+ });
49
+ }
50
+ static getSession() {
51
+ return _PayKKaCheckout.session;
52
+ }
53
+ create(component, props) {
54
+ return create(component, props);
55
+ }
56
+ };
57
+ __publicField(_PayKKaCheckout, "session");
58
+ __publicField(_PayKKaCheckout, "instance", null);
59
+ let PayKKaCheckout = _PayKKaCheckout;
60
+ export {
61
+ PayKKaCheckout
62
+ };
@@ -26,6 +26,9 @@ import "../utils/card-brand/brands.js";
26
26
  import "../utils/system-info/get-browser-info.js";
27
27
  import { generateColors } from "../utils/colors.js";
28
28
  import { createPromise } from "../utils/create-promise.js";
29
+ import "../i18n/util.js";
30
+ import "../core.js";
31
+ import "../i18n/locales/index.js";
29
32
  import { querySession } from "./query.js";
30
33
  class Session {
31
34
  constructor(sessionId, clientKey) {
@@ -2,3 +2,5 @@ import "./context.js";
2
2
  import "../core.js";
3
3
  import "../utils/card-brand/brands.js";
4
4
  import "../utils/system-info/get-browser-info.js";
5
+ import "../i18n/util.js";
6
+ import "../i18n/locales/index.js";
@@ -1,13 +1,11 @@
1
1
  import "../utils/card-brand/brands.js";
2
2
  import "../utils/system-info/get-browser-info.js";
3
+ import "../i18n/util.js";
4
+ import "../core.js";
5
+ import "../i18n/locales/index.js";
3
6
  import { onceGetCheckoutInfo } from "../api/modules/checkout/index.js";
4
7
  async function querySession({ sessionId, clientKey }, options) {
5
- try {
6
- return await onceGetCheckoutInfo({ sessionId, clientKey }, options);
7
- } catch (error) {
8
- console.log("[PayKKa Checkout UI]:", error);
9
- return {};
10
- }
8
+ return onceGetCheckoutInfo({ sessionId, clientKey }, options);
11
9
  }
12
10
  export {
13
11
  querySession
package/dist/es/core.js CHANGED
@@ -675,6 +675,36 @@ l$3.diffed = function(n2) {
675
675
  var t2 = n2.props, e2 = n2.__e;
676
676
  null != e2 && "textarea" === n2.type && "value" in t2 && t2.value !== e2.value && (e2.value = null == t2.value ? "" : t2.value);
677
677
  };
678
+ function e$1(e2, n2) {
679
+ return n2 = n2 || {}, new Promise(function(t2, r2) {
680
+ var s2 = new XMLHttpRequest(), o2 = [], u2 = {}, a2 = function e3() {
681
+ return { ok: 2 == (s2.status / 100 | 0), statusText: s2.statusText, status: s2.status, url: s2.responseURL, text: function() {
682
+ return Promise.resolve(s2.responseText);
683
+ }, json: function() {
684
+ return Promise.resolve(s2.responseText).then(JSON.parse);
685
+ }, blob: function() {
686
+ return Promise.resolve(new Blob([s2.response]));
687
+ }, clone: e3, headers: { keys: function() {
688
+ return o2;
689
+ }, entries: function() {
690
+ return o2.map(function(e4) {
691
+ return [e4, s2.getResponseHeader(e4)];
692
+ });
693
+ }, get: function(e4) {
694
+ return s2.getResponseHeader(e4);
695
+ }, has: function(e4) {
696
+ return null != s2.getResponseHeader(e4);
697
+ } } };
698
+ };
699
+ for (var i2 in s2.open(n2.method || "get", e2, true), s2.onload = function() {
700
+ s2.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm, function(e3, n3) {
701
+ u2[n3] || o2.push(u2[n3] = n3);
702
+ }), t2(a2());
703
+ }, s2.onerror = r2, s2.withCredentials = "include" == n2.credentials, n2.headers)
704
+ s2.setRequestHeader(i2, n2.headers[i2]);
705
+ s2.send(n2.body || null);
706
+ });
707
+ }
678
708
  var __assign = function() {
679
709
  __assign = Object.assign || function __assign2(t2) {
680
710
  for (var s2, i2 = 1, n2 = arguments.length; i2 < n2; i2++) {
@@ -3854,36 +3884,6 @@ function isValidCSSUnit(color) {
3854
3884
  }
3855
3885
  return matchers.CSS_UNIT.test(color);
3856
3886
  }
3857
- function e$1(e2, n2) {
3858
- return n2 = n2 || {}, new Promise(function(t2, r2) {
3859
- var s2 = new XMLHttpRequest(), o2 = [], u2 = {}, a2 = function e3() {
3860
- return { ok: 2 == (s2.status / 100 | 0), statusText: s2.statusText, status: s2.status, url: s2.responseURL, text: function() {
3861
- return Promise.resolve(s2.responseText);
3862
- }, json: function() {
3863
- return Promise.resolve(s2.responseText).then(JSON.parse);
3864
- }, blob: function() {
3865
- return Promise.resolve(new Blob([s2.response]));
3866
- }, clone: e3, headers: { keys: function() {
3867
- return o2;
3868
- }, entries: function() {
3869
- return o2.map(function(e4) {
3870
- return [e4, s2.getResponseHeader(e4)];
3871
- });
3872
- }, get: function(e4) {
3873
- return s2.getResponseHeader(e4);
3874
- }, has: function(e4) {
3875
- return null != s2.getResponseHeader(e4);
3876
- } } };
3877
- };
3878
- for (var i2 in s2.open(n2.method || "get", e2, true), s2.onload = function() {
3879
- s2.getAllResponseHeaders().toLowerCase().replace(/^(.+?):/gm, function(e3, n3) {
3880
- u2[n3] || o2.push(u2[n3] = n3);
3881
- }), t2(a2());
3882
- }, s2.onerror = r2, s2.withCredentials = "include" == n2.credentials, n2.headers)
3883
- s2.setRequestHeader(i2, n2.headers[i2]);
3884
- s2.send(n2.body || null);
3885
- });
3886
- }
3887
3887
  var i = Symbol.for("preact-signals");
3888
3888
  function t() {
3889
3889
  if (!(s$1 > 1)) {
@@ -6,8 +6,8 @@ import { I18n } from "../i18n/I18n.js";
6
6
  import "../i18n/locales/index.js";
7
7
  function useI18n(locale) {
8
8
  const coreContext = x(CoreContext);
9
- const [_i18n] = h((coreContext == null ? void 0 : coreContext.i18n) ?? new I18n(locale));
10
- locale && _i18n.load(locale);
9
+ const [_i18n] = h((coreContext == null ? void 0 : coreContext.i18n) ?? new I18n());
10
+ _i18n.load(locale);
11
11
  return { i18n: _i18n };
12
12
  }
13
13
  export {
@@ -2,41 +2,30 @@ import { h, y } from "../core.js";
2
2
  import "../core/context.js";
3
3
  import "../utils/card-brand/brands.js";
4
4
  import "../utils/system-info/get-browser-info.js";
5
- import { Session } from "../core/Session.js";
6
- import { radarEnv } from "../config.js";
7
- import { getPayKKaRadarInstance } from "../out/radar.js";
5
+ import { customLocale, fraudDetectionEnv } from "../config.js";
6
+ import { PayKKaCheckout } from "../core/PayKKaCheckout.js";
7
+ import { getFraudDetectionInstance } from "../out/fraud-detection.js";
8
8
  import { useI18n } from "./useI18n.js";
9
- let _session;
10
- function usePayState(props) {
9
+ function usePayState() {
11
10
  const [validated, setValidated] = h(false);
12
11
  const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
13
12
  const [errorMsg, setErrorMsg] = h("");
14
13
  const [session, setSession] = h(null);
15
14
  const [sessionReady, setSessionReady] = h(false);
16
- const [payKKaRadar, setPayKKaRadar] = h(null);
15
+ const [fraudDetection, setFraudDetection] = h(null);
16
+ setSession(PayKKaCheckout.getSession());
17
+ const { i18n } = useI18n(customLocale);
17
18
  y(() => {
18
- setSessionReady(false);
19
- if (!_session) {
20
- _session = new Session(props.sessionId, props.clientKey);
21
- }
22
- setSession(_session);
23
- _session.ready().then(() => setSessionReady(true)).catch(() => setSessionReady(false));
24
- }, [props.sessionId]);
25
- const { i18n } = useI18n(props.i18n);
26
- y(() => {
27
- if (props.i18n) {
28
- i18n.load(props.i18n);
29
- return;
30
- }
31
19
  if (session) {
32
20
  session.ready().then(() => {
33
- i18n.load(session.checkout.locale);
34
- const payKKaRadar2 = getPayKKaRadarInstance(radarEnv);
35
- setPayKKaRadar(payKKaRadar2);
36
- payKKaRadar2 == null ? void 0 : payKKaRadar2.createPayKKaRadar();
21
+ setSessionReady(true);
22
+ i18n.load(session.checkout.locale || customLocale);
23
+ const fraudDetection2 = getFraudDetectionInstance(fraudDetectionEnv);
24
+ setFraudDetection(fraudDetection2);
25
+ fraudDetection2 == null ? void 0 : fraudDetection2.createFraudDetection();
37
26
  });
38
27
  }
39
- }, [props.i18n, session]);
28
+ }, [session]);
40
29
  return {
41
30
  validated,
42
31
  setValidated,
@@ -49,7 +38,7 @@ function usePayState(props) {
49
38
  sessionReady,
50
39
  setSessionReady,
51
40
  i18n,
52
- payKKaRadar
41
+ fraudDetection
53
42
  };
54
43
  }
55
44
  export {
@@ -9,17 +9,16 @@ import { getBrowserInfo } from "../utils/system-info/get-browser-info.js";
9
9
  import { loadTranslation } from "./util.js";
10
10
  import { d } from "../core.js";
11
11
  const _I18n = class _I18n {
12
- constructor(locale = getBrowserInfo().language) {
12
+ constructor() {
13
13
  /** 语言 */
14
14
  __publicField(this, "locale");
15
15
  /** 翻译文案 */
16
16
  __publicField(this, "translation");
17
17
  /** 加载文案完成标识 */
18
- __publicField(this, "ready", d(false));
18
+ __publicField(this, "isReady", d(false));
19
19
  /** 当前正在加载的id标识 */
20
20
  __publicField(this, "currentLoadId", 0);
21
21
  if (!_I18n.instance) {
22
- this.load(locale);
23
22
  _I18n.instance = this;
24
23
  }
25
24
  return _I18n.instance;
@@ -28,6 +27,9 @@ const _I18n = class _I18n {
28
27
  var _a;
29
28
  return ((_a = this.translation) == null ? void 0 : _a[key]) ?? "";
30
29
  }
30
+ get ready() {
31
+ return this.isReady;
32
+ }
31
33
  /** 加载国际化翻译文案 */
32
34
  load(locale = getBrowserInfo().language) {
33
35
  if (locale === this.locale) {
@@ -35,15 +37,16 @@ const _I18n = class _I18n {
35
37
  }
36
38
  this.locale = locale;
37
39
  const loadId = ++this.currentLoadId;
38
- this.ready.value = false;
40
+ this.isReady.value = false;
39
41
  loadTranslation(this.locale).then((res) => {
42
+ if (loadId !== this.currentLoadId) {
43
+ return;
44
+ }
45
+ this.isReady.value = true;
40
46
  this.locale = res.locale;
41
47
  this.translation = res.translation;
42
- if (loadId === this.currentLoadId) {
43
- this.ready.value = true;
44
- }
45
48
  }).catch(() => {
46
- this.ready.value = false;
49
+ this.isReady.value = false;
47
50
  });
48
51
  }
49
52
  };