@paykka/card-checkout-ui 0.6.0 → 0.7.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 (160) hide show
  1. package/dist/card-checkout-ui.js +12 -12
  2. package/dist/card-checkout-ui.umd.cjs +12 -12
  3. package/dist/es/api/index.js +0 -2
  4. package/dist/es/api/modules/checkout/index.js +1 -15
  5. package/dist/es/api/modules/checkout/map.js +20 -3
  6. package/dist/es/api/modules/index.js +0 -2
  7. package/dist/es/components/AccountNameField/index.js +0 -3
  8. package/dist/es/components/AddressField/index.js +2 -7
  9. package/dist/es/components/AliPay/index.js +8 -7
  10. package/dist/es/components/ApplePay/index.js +7 -8
  11. package/dist/es/components/Card/index.js +301 -125
  12. package/dist/es/components/CardBrands/index.js +0 -2
  13. package/dist/es/components/CardExpireDateField/index.js +1 -4
  14. package/dist/es/components/CardHolderNameField/index.js +3 -5
  15. package/dist/es/components/CardIBANField/index.js +0 -3
  16. package/dist/es/components/CardNo/index.js +0 -2
  17. package/dist/es/components/CardNumberField/index.js +1 -4
  18. package/dist/es/components/CardSecurityCodeField/index.js +1 -4
  19. package/dist/es/components/CardSelector/index.js +0 -3
  20. package/dist/es/components/CombinedCardInfo/index.js +99 -0
  21. package/dist/es/components/EmailField/EmailField.js +0 -3
  22. package/dist/es/components/EncryptedCard/index.js +35 -75
  23. package/dist/es/components/GooglePay/index.js +62 -28
  24. package/dist/es/components/RecurringTip/index.js +0 -2
  25. package/dist/es/components/SecuredFieldsProvider/index.js +230 -1
  26. package/dist/es/components/SecuredIframe/index.js +3 -1
  27. package/dist/es/components/Sepa/index.js +21 -27
  28. package/dist/es/components/SubmitButton/index.js +0 -2
  29. package/dist/es/components/ThreeDS/index.js +94 -0
  30. package/dist/es/components/WechatPay/index.js +26 -25
  31. package/dist/es/components/index.js +1 -3
  32. package/dist/es/components/internal/Button/Button.js +0 -2
  33. package/dist/es/components/internal/Button/index.js +0 -2
  34. package/dist/es/components/internal/CheckBox/CheckBox.js +0 -2
  35. package/dist/es/components/internal/CheckBox/index.js +0 -2
  36. package/dist/es/components/internal/Form/type.js +0 -2
  37. package/dist/es/components/internal/Info/Info.js +0 -2
  38. package/dist/es/components/internal/Info/index.js +0 -2
  39. package/dist/es/components/internal/Input/Input.js +2 -2
  40. package/dist/es/components/internal/Input/type.js +0 -2
  41. package/dist/es/components/internal/LoadingCheck/LoadingCheck.js +0 -2
  42. package/dist/es/components/internal/LoadingCheck/index.js +0 -2
  43. package/dist/es/components/internal/Modal/Modal.js +40 -0
  44. package/dist/es/components/internal/Modal/modal2.js +1 -0
  45. package/dist/es/components/internal/Select/Select.js +0 -2
  46. package/dist/es/components/internal/Select/SelectMenu.js +0 -2
  47. package/dist/es/components/internal/Select/SelectMenuItem.js +0 -2
  48. package/dist/es/components/internal/icons/Icon3DSFail.js +3 -0
  49. package/dist/es/components/internal/icons/Icon3DSInfo.js +62 -0
  50. package/dist/es/components/internal/icons/Icon3DSSuccess.js +3 -0
  51. package/dist/es/config.js +0 -2
  52. package/dist/es/constant.js +3 -2
  53. package/dist/es/core/PayKKaCheckout.js +96 -42
  54. package/dist/es/core/Session.js +7 -6
  55. package/dist/es/core/environment.js +26 -0
  56. package/dist/es/core/error.js +21 -0
  57. package/dist/es/core/index.js +0 -2
  58. package/dist/es/core/query.js +0 -2
  59. package/dist/es/core.js +34 -34
  60. package/dist/es/hooks/index.js +0 -2
  61. package/dist/es/hooks/useBreakpoints.js +57 -0
  62. package/dist/es/hooks/useI18n.js +1 -2
  63. package/dist/es/hooks/usePayState.js +18 -24
  64. package/dist/es/i18n/index.js +0 -2
  65. package/dist/es/i18n/locales/de-DE.js +11 -1
  66. package/dist/es/i18n/locales/en-GB.js +11 -1
  67. package/dist/es/i18n/locales/es-ES.js +11 -1
  68. package/dist/es/i18n/locales/fr-FR.js +11 -1
  69. package/dist/es/i18n/locales/index.js +8 -6
  70. package/dist/es/i18n/locales/ja-JP.js +11 -1
  71. package/dist/es/i18n/locales/ko-KR.js +11 -1
  72. package/dist/es/i18n/locales/pt-PT.js +11 -1
  73. package/dist/es/i18n/locales/ru-RU.js +11 -1
  74. package/dist/es/i18n/locales/zh-CN.js +11 -1
  75. package/dist/es/i18n/locales/zh-HK.js +11 -1
  76. package/dist/es/i18n/locales/zh-TW.js +11 -1
  77. package/dist/es/i18n/util.js +11 -8
  78. package/dist/es/index.js +4 -2
  79. package/dist/es/style.css +186 -4
  80. package/dist/es/types/message.js +28 -0
  81. package/dist/es/utils/card-brand/brands.js +12 -10
  82. package/dist/es/utils/card-brand/index.js +3 -2
  83. package/dist/es/utils/iframe.js +23 -0
  84. package/dist/es/utils/index.js +0 -1
  85. package/dist/es/utils/style.js +47 -0
  86. package/dist/style.css +1 -1
  87. package/dist/types/api/modules/checkout/type.d.ts +14 -1
  88. package/dist/types/api/modules/get-browser-params.d.ts +1 -1
  89. package/dist/types/components/AddressField/type.d.ts +1 -0
  90. package/dist/types/components/AliPay/type.d.ts +4 -2
  91. package/dist/types/components/ApplePay/type.d.ts +4 -3
  92. package/dist/types/components/Card/type.d.ts +56 -10
  93. package/dist/types/components/CardHolderNameField/type.d.ts +1 -1
  94. package/dist/types/components/CombinedCardInfo/CombinedCardInfo.d.ts +5 -0
  95. package/dist/types/components/CombinedCardInfo/index.d.ts +2 -0
  96. package/dist/types/components/{CombinedEncryptedField → CombinedCardInfo}/type.d.ts +3 -2
  97. package/dist/types/components/GooglePay/type.d.ts +4 -3
  98. package/dist/types/components/SecuredFieldsProvider/index.d.ts +1 -0
  99. package/dist/types/components/SecuredFieldsProvider/type.d.ts +1 -153
  100. package/dist/types/components/SecuredFieldsProvider/utils/index.d.ts +1 -1
  101. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +2 -1
  102. package/dist/types/components/Sepa/type.d.ts +4 -2
  103. package/dist/types/components/ThreeDS/components/ThreeDSAuth/ThreeDSAuth.d.ts +3 -0
  104. package/dist/types/components/ThreeDS/components/ThreeDSAuth/index.d.ts +2 -0
  105. package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +17 -0
  106. package/dist/types/components/ThreeDS/components/ThreeDSIframe/ThreeDSIframe.d.ts +2 -0
  107. package/dist/types/components/ThreeDS/components/ThreeDSIframe/index.d.ts +1 -0
  108. package/dist/types/components/ThreeDS/components/ThreeDSIframe/output.d.ts +1 -0
  109. package/dist/types/components/ThreeDS/components/ThreeDSIframe/type.d.ts +5 -0
  110. package/dist/types/components/ThreeDS/components/ThreeDSStatus/ThreeDSStatus.d.ts +3 -0
  111. package/dist/types/components/ThreeDS/components/ThreeDSStatus/output.d.ts +1 -0
  112. package/dist/types/components/ThreeDS/components/ThreeDSStatus/type.d.ts +6 -0
  113. package/dist/types/components/ThreeDS/index.d.ts +1 -0
  114. package/dist/types/components/WechatPay/type.d.ts +4 -2
  115. package/dist/types/components/index.d.ts +1 -1
  116. package/dist/types/components/internal/Input/type.d.ts +1 -0
  117. package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
  118. package/dist/types/components/internal/Loading/index.d.ts +1 -0
  119. package/dist/types/components/internal/Modal/Modal.d.ts +5 -0
  120. package/dist/types/components/internal/Modal/index.d.ts +0 -0
  121. package/dist/types/components/internal/Modal/type.d.ts +20 -0
  122. package/dist/types/components/internal/icons/Icon3DSFail.d.ts +2 -0
  123. package/dist/types/components/internal/icons/Icon3DSInfo.d.ts +2 -0
  124. package/dist/types/components/internal/icons/Icon3DSSuccess.d.ts +2 -0
  125. package/dist/types/components/internal/icons/index.d.ts +3 -0
  126. package/dist/types/constant.d.ts +6 -2
  127. package/dist/types/core/PayKKaCheckout.d.ts +22 -6
  128. package/dist/types/core/Session.d.ts +1 -1
  129. package/dist/types/core/context.d.ts +1 -0
  130. package/dist/types/core/environment.d.ts +4 -0
  131. package/dist/types/core/error.d.ts +16 -0
  132. package/dist/types/core/index.d.ts +1 -0
  133. package/dist/types/hooks/index.d.ts +1 -0
  134. package/dist/types/hooks/useBreakpoints.d.ts +15 -0
  135. package/dist/types/hooks/usePayState.d.ts +3 -6
  136. package/dist/types/i18n/locales/de-DE.d.ts +8 -0
  137. package/dist/types/i18n/locales/en-GB.d.ts +8 -0
  138. package/dist/types/i18n/locales/es-ES.d.ts +8 -0
  139. package/dist/types/i18n/locales/fr-FR.d.ts +8 -0
  140. package/dist/types/i18n/locales/index.d.ts +2 -2
  141. package/dist/types/i18n/locales/ja-JP.d.ts +8 -0
  142. package/dist/types/i18n/locales/ko-KR.d.ts +8 -0
  143. package/dist/types/i18n/locales/pt-PT.d.ts +8 -0
  144. package/dist/types/i18n/locales/ru-RU.d.ts +8 -0
  145. package/dist/types/i18n/locales/zh-CN.d.ts +8 -0
  146. package/dist/types/i18n/locales/zh-HK.d.ts +8 -0
  147. package/dist/types/i18n/locales/zh-TW.d.ts +8 -0
  148. package/dist/types/index.d.ts +1 -1
  149. package/dist/types/types/index.d.ts +39 -8
  150. package/dist/types/types/message.d.ts +170 -0
  151. package/dist/types/utils/card-brand/brands.d.ts +1 -8
  152. package/dist/types/utils/card-brand/index.d.ts +2 -2
  153. package/dist/types/utils/index.d.ts +1 -0
  154. package/dist/types/utils/style.d.ts +12 -0
  155. package/package.json +63 -63
  156. package/dist/es/components/CombinedEncryptedField/index.js +0 -75
  157. package/dist/es/components/SecuredFieldsProvider/SecuredFieldsProvider.js +0 -268
  158. package/dist/types/components/CombinedEncryptedField/CombinedEncryptedField.d.ts +0 -4
  159. package/dist/types/components/CombinedEncryptedField/index.d.ts +0 -2
  160. /package/dist/types/{components/SecuredFieldsProvider/utils → utils}/iframe.d.ts +0 -0
@@ -1,4 +1,233 @@
1
- import { SecuredFieldsProvider } from "./SecuredFieldsProvider.js";
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 "../../utils/card-brand/brands.js";
8
+ import "../../utils/system-info/get-browser-info.js";
9
+ import { w, A, F, y, q, u } from "../../core.js";
10
+ import { SessionMode } from "../../constant.js";
11
+ import { cdnUrl, cdnOrigin, apiUrl } from "../../config.js";
12
+ import { MessageAction } from "../../types/message.js";
13
+ import { createIframe, postMessageToIframe } from "../../utils/iframe.js";
14
+ import { safeParse } from "../../utils/index.js";
15
+ var EFieldType = /* @__PURE__ */ ((EFieldType2) => {
16
+ EFieldType2["CARD_NUMBER"] = "CARD_NUMBER";
17
+ EFieldType2["CVV"] = "CVV";
18
+ EFieldType2["EXPIRE_DATE"] = "EXPIRE_DATE";
19
+ return EFieldType2;
20
+ })(EFieldType || {});
21
+ const SECURED_FILED_ATTR = "data-sf";
22
+ const SECURED_IFRAME_CLASS_NAME = "secured-iframe";
23
+ const HIDDEN_IFRAME_NAME = "hidden-pay-iframe";
24
+ const getFieldElements = (rootNode) => {
25
+ return rootNode ? Array.prototype.slice.call(rootNode.querySelectorAll(`[${SECURED_FILED_ATTR}]`)) : [];
26
+ };
27
+ class SecuredField {
28
+ constructor(config) {
29
+ __publicField(this, "iframe");
30
+ __publicField(this, "iframeWindow");
31
+ __publicField(this, "hiddenIframe");
32
+ __publicField(this, "config");
33
+ this.config = config;
34
+ this.init();
35
+ }
36
+ /** 初始化表单区域iframe */
37
+ init() {
38
+ const { iframeSrc, iframeClassName, fieldNode } = this.config;
39
+ const iframeEl = createIframe(iframeSrc);
40
+ iframeEl.width = "100%";
41
+ iframeEl.height = "100%";
42
+ iframeEl.style.border = "none";
43
+ fieldNode.appendChild(iframeEl);
44
+ const iframe = fieldNode.querySelector(`.${iframeClassName}`);
45
+ if (!iframe) {
46
+ return;
47
+ }
48
+ this.iframe = iframe;
49
+ iframe.addEventListener("load", () => this.onFieldIframeLoad());
50
+ }
51
+ /** 表单区域iframe加载回调 */
52
+ onFieldIframeLoad() {
53
+ this.iframeWindow = this.iframe.contentWindow;
54
+ const { fieldType, placeholder, style, hiddenIframeName, supportedCardBrands } = this.config;
55
+ const data = {
56
+ action: MessageAction.INIT,
57
+ config: {
58
+ fieldType,
59
+ placeholder,
60
+ style,
61
+ hiddenIframeName,
62
+ supportedCardBrands
63
+ },
64
+ hidden: false,
65
+ cdnUrl
66
+ };
67
+ postMessageToIframe(data, this.iframeWindow, cdnOrigin);
68
+ }
69
+ }
70
+ const SecuredFieldsProvider = w((props, ref) => {
71
+ const { sessionMode, i18n, targetElement } = props;
72
+ const rootNodeRef = A(null);
73
+ const hiddenIframe = A(null);
74
+ const payment = (formData) => {
75
+ const data = {
76
+ action: MessageAction.PAYMENT,
77
+ formData,
78
+ locale: props.i18n.locale
79
+ };
80
+ postMessageToIframe(data, hiddenIframe.current.contentWindow, cdnOrigin);
81
+ };
82
+ F(ref, () => ({
83
+ payment,
84
+ reload: () => {
85
+ if (sessionMode === SessionMode.HOSTED) {
86
+ return;
87
+ }
88
+ window.removeEventListener("message", onReceiveMessage);
89
+ if (hiddenIframe.current) {
90
+ document.body.removeChild(hiddenIframe.current);
91
+ }
92
+ init();
93
+ },
94
+ encryptCard: (encryptedInfo) => {
95
+ const data = {
96
+ action: MessageAction.ENCRYPT_CARD,
97
+ ...encryptedInfo
98
+ };
99
+ postMessageToIframe(data, hiddenIframe.current.contentWindow, cdnOrigin);
100
+ },
101
+ validate: () => {
102
+ Object.values(securedFieldMap.current).forEach((field) => {
103
+ const data = {
104
+ action: MessageAction.VALIDATE
105
+ };
106
+ postMessageToIframe(data, field.iframe.contentWindow, cdnOrigin);
107
+ });
108
+ },
109
+ setConfig: (config) => {
110
+ props.style = config.style;
111
+ }
112
+ }));
113
+ if (!frames && sessionMode === SessionMode.HOSTED) {
114
+ return props.children;
115
+ }
116
+ let fieldNodes = [];
117
+ const securedFieldMap = A({});
118
+ const securedFieldPlaceholderMap = {
119
+ [EFieldType.CARD_NUMBER]: i18n.get("card.cardNumber.placeholder"),
120
+ [EFieldType.CVV]: i18n.get("card.cardSecurityCode.placeholder"),
121
+ [EFieldType.EXPIRE_DATE]: i18n.get("card.cardExpireDate.placeholder")
122
+ };
123
+ y(() => {
124
+ init();
125
+ }, []);
126
+ const init = async () => {
127
+ fieldNodes = getFieldElements(targetElement || rootNodeRef.current);
128
+ if (!fieldNodes.length) {
129
+ return;
130
+ }
131
+ await initHiddenIframe();
132
+ initAllFieldIframe();
133
+ window.addEventListener("message", onReceiveMessage);
134
+ };
135
+ const initHiddenIframe = async () => {
136
+ const iframeEl = createIframe(`${cdnUrl}/secured-iframe.html`);
137
+ iframeEl.name = `${HIDDEN_IFRAME_NAME}-${Date.now()}`;
138
+ iframeEl.width = "0";
139
+ iframeEl.height = "0";
140
+ iframeEl.style.border = "none";
141
+ hiddenIframe.current = iframeEl;
142
+ const data = {
143
+ action: MessageAction.INIT,
144
+ hidden: true,
145
+ apiUrl,
146
+ cdnUrl
147
+ };
148
+ iframeEl.addEventListener("load", () => {
149
+ postMessageToIframe(data, hiddenIframe.current.contentWindow, cdnOrigin);
150
+ });
151
+ window.document.body.appendChild(iframeEl);
152
+ };
153
+ const initAllFieldIframe = () => {
154
+ fieldNodes.forEach((fieldNode) => {
155
+ const fieldType = fieldNode.getAttribute(SECURED_FILED_ATTR);
156
+ securedFieldMap.current[fieldType] = new SecuredField({
157
+ fieldNode,
158
+ hiddenIframe: hiddenIframe.current,
159
+ hiddenIframeName: hiddenIframe.current.name,
160
+ rootNode: rootNodeRef.current,
161
+ iframeSrc: `${cdnUrl}/secured-iframe.html`,
162
+ iframeClassName: SECURED_IFRAME_CLASS_NAME,
163
+ fieldType,
164
+ placeholder: securedFieldPlaceholderMap[fieldType],
165
+ style: props.style,
166
+ supportedCardBrands: props.supportedCardBrands,
167
+ onFocus: props.onFocus,
168
+ onBinValue: props.onBinValue,
169
+ onAfterPayment: props.onAfterPayment,
170
+ onPaymentError: props.onPaymentError,
171
+ onPaymentTimeout: props.onPaymentTimeout,
172
+ onValidStatusChanged: props.onValidStatusChanged
173
+ });
174
+ });
175
+ };
176
+ const onReceiveMessage = q((event) => {
177
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
178
+ const { data, origin } = event;
179
+ if (origin !== cdnOrigin) {
180
+ return;
181
+ }
182
+ const feedbackData = safeParse(data);
183
+ if (!Reflect.has(feedbackData, "action")) {
184
+ return;
185
+ }
186
+ switch (feedbackData.action) {
187
+ case MessageAction.FOCUS:
188
+ (_a = props.onFocus) == null ? void 0 : _a.call(props, feedbackData);
189
+ break;
190
+ case MessageAction.BIN_VALUE:
191
+ (_b = props.onBinValue) == null ? void 0 : _b.call(props, feedbackData);
192
+ break;
193
+ case MessageAction.BRAND:
194
+ (_c = props.onBrand) == null ? void 0 : _c.call(props, feedbackData);
195
+ break;
196
+ case MessageAction.AFTER_PAYMENT:
197
+ (_d = props.onAfterPayment) == null ? void 0 : _d.call(props, feedbackData);
198
+ break;
199
+ case MessageAction.PAYMENT_ERROR:
200
+ (_e = props.onPaymentError) == null ? void 0 : _e.call(props, feedbackData);
201
+ break;
202
+ case MessageAction.PAYMENT_TIMEOUT:
203
+ (_f = props.onPaymentTimeout) == null ? void 0 : _f.call(props, feedbackData);
204
+ break;
205
+ case MessageAction.VALID_STATUS_CHANGED:
206
+ (_g = props.onValidStatusChanged) == null ? void 0 : _g.call(props, feedbackData);
207
+ break;
208
+ case MessageAction.AUTHORIZED:
209
+ (_h = props.onAuthorized) == null ? void 0 : _h.call(props, feedbackData);
210
+ break;
211
+ case MessageAction.ACTIVATED:
212
+ (_i = props.onActivated) == null ? void 0 : _i.call(props, feedbackData);
213
+ break;
214
+ case MessageAction.CARD_ENCRYPTED:
215
+ (_j = props.onCardEncrypted) == null ? void 0 : _j.call(props, feedbackData);
216
+ break;
217
+ case MessageAction.CARD_ENCRYPTION_FAILED:
218
+ (_k = props.onCardEncryptionFailed) == null ? void 0 : _k.call(props, feedbackData);
219
+ break;
220
+ case MessageAction.VALIDATED:
221
+ (_l = props.onValidated) == null ? void 0 : _l.call(props, feedbackData);
222
+ break;
223
+ }
224
+ }, []);
225
+ return /* @__PURE__ */ u("div", { ref: rootNodeRef, children: !targetElement && props.children });
226
+ });
2
227
  export {
228
+ EFieldType,
229
+ HIDDEN_IFRAME_NAME,
230
+ SECURED_FILED_ATTR,
231
+ SECURED_IFRAME_CLASS_NAME,
3
232
  SecuredFieldsProvider
4
233
  };
@@ -1,11 +1,13 @@
1
1
  import { A, h, y, u, b } from "../../core.js";
2
2
  import { clamp, isExpired, safeParse } from "../../utils/index.js";
3
- import { EFieldType, MessageAction, postMessageToIframe } from "../SecuredFieldsProvider/SecuredFieldsProvider.js";
3
+ import { EFieldType } from "../SecuredFieldsProvider/index.js";
4
4
  import { getSupportedCardBrands, getSupportedCardBrandsLengths, findCardBrand } from "../../utils/card-brand/index.js";
5
5
  import { limitedToNumber, trimAll } from "../../utils/format.js";
6
6
  import { isUndefined, isNil } from "../../utils/is.js";
7
7
  import { cdnOrigin, setApiUrl, setCDNUrl } from "../../config.js";
8
+ import { MessageAction } from "../../types/message.js";
8
9
  import { generateClassNameMap, style2String, createPlaceholderStyle, loadStyle } from "../../utils/style.js";
10
+ import { postMessageToIframe } from "../../utils/iframe.js";
9
11
  import { isTimeoutError } from "../../api/http.js";
10
12
  import { cardPay } from "../../api/modules/card/index.js";
11
13
  import { encryptCard } from "../../api/modules/encrypted-card/index.js";
@@ -2,7 +2,7 @@ import { w, A, h, F, y, q, u } from "../../core.js";
2
2
  import { createAddressCore } from "../../core/Address.js";
3
3
  import { useBEM } from "../../hooks/useBEM.js";
4
4
  import { CoreContext } from "../../core/context.js";
5
- import { isEmptyObject, isUndefined } from "../../utils/is.js";
5
+ import { isUndefined } from "../../utils/is.js";
6
6
  import "../../utils/card-brand/brands.js";
7
7
  import "../../utils/system-info/get-browser-info.js";
8
8
  import { cssVarPrefix, normalizedClass, formatAmount, trimAll } from "../../utils/format.js";
@@ -10,8 +10,7 @@ import { isTimeoutError } from "../../api/http.js";
10
10
  import { COMMON_CLASS_NAME } from "../../constant.js";
11
11
  import { getBrowserParams } from "../../api/modules/get-browser-params.js";
12
12
  import { getSepaPayInfo, sepaPay } from "../../api/modules/sepa/index.js";
13
- import "../../i18n/util.js";
14
- import "../../i18n/locales/index.js";
13
+ import { PayKKaError } from "../../core/error.js";
15
14
  import { usePayState } from "../../hooks/usePayState.js";
16
15
  import { useRetry } from "../../hooks/useRetry.js";
17
16
  import { AddressField } from "../AddressField/index.js";
@@ -28,9 +27,10 @@ const { bem } = useBEM("sepa");
28
27
  const fieldClassNames = bem("field");
29
28
  const Sepa = w((props, ref) => {
30
29
  var _a, _b, _c, _d, _e, _f;
30
+ const { session } = props;
31
31
  let addressState = createAddressCore();
32
32
  let emailState = createEmailCore();
33
- const { i18n, session, sessionReady } = usePayState();
33
+ const { i18n, sessionReady } = usePayState(session);
34
34
  const addressFieldRef = A(null);
35
35
  const emailFieldRef = A(null);
36
36
  const formRef = A(null);
@@ -76,25 +76,18 @@ const Sepa = w((props, ref) => {
76
76
  }
77
77
  }));
78
78
  y(() => {
79
- if (session) {
80
- session.ready().then(() => {
81
- var _a2;
82
- if (isEmptyObject(session.checkout)) {
83
- (_a2 = props.onError) == null ? void 0 : _a2.call(props, "FAILURE");
84
- return;
85
- }
86
- setIsCheckoutEnabled(true);
87
- const { bill, status } = session.checkout;
88
- form.email = bill.email ?? "";
89
- disabledEmail.current = !!bill.email;
90
- setRequiredBill(bill.billingAddressCollection === "REQUIRED");
91
- if (status === "SUCCESS") {
92
- setSubmitButtonStatus("success");
93
- processOnSuccess();
94
- }
95
- });
96
- }
97
- }, [session]);
79
+ session.ready().then(() => {
80
+ setIsCheckoutEnabled(true);
81
+ const { bill, status } = session.checkout;
82
+ form.email = bill.email ?? "";
83
+ disabledEmail.current = !!bill.email;
84
+ setRequiredBill(bill.billingAddressCollection === "REQUIRED");
85
+ if (status === "SUCCESS") {
86
+ setSubmitButtonStatus("success");
87
+ processOnSuccess();
88
+ }
89
+ });
90
+ }, []);
98
91
  const Button = () => {
99
92
  const { transAmount } = (session == null ? void 0 : session.checkout) ?? {};
100
93
  let { symbol = "", amount = "", digits } = transAmount ?? {};
@@ -196,8 +189,9 @@ const Sepa = w((props, ref) => {
196
189
  return { end: true };
197
190
  }
198
191
  } else {
199
- setErrorMsg(error.i18nKey ? i18n.get(error.i18nKey) : error.message);
200
- (_a2 = props.onError) == null ? void 0 : _a2.call(props, error);
192
+ const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
193
+ setErrorMsg(message);
194
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
201
195
  setSubmitButtonStatus("unSubmit");
202
196
  return { end: true };
203
197
  }
@@ -205,7 +199,7 @@ const Sepa = w((props, ref) => {
205
199
  }
206
200
  const processAfterPayment = (res, search = false) => {
207
201
  var _a2, _b2, _c2;
208
- const { status, orderStatus, errorMessage } = res;
202
+ const { status, orderStatus, errorMessage, errorCode } = res;
209
203
  if (status === "PROCESSING") {
210
204
  if (!orderStatus) {
211
205
  setSubmitButtonStatus("unSubmit");
@@ -222,7 +216,7 @@ const Sepa = w((props, ref) => {
222
216
  } else if (orderStatus === "FAILURE") {
223
217
  setErrorMsg(errorMessage);
224
218
  setSubmitButtonStatus("unSubmit");
225
- (_a2 = props.onError) == null ? void 0 : _a2.call(props, "FAILURE");
219
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
226
220
  } else if (orderStatus === "AUTHORIZED") {
227
221
  setSubmitButtonStatus("unSubmit");
228
222
  (_b2 = props.onAuthorized) == null ? void 0 : _b2.call(props);
@@ -4,8 +4,6 @@ import "../../core/context.js";
4
4
  import "../../utils/card-brand/brands.js";
5
5
  import "../../utils/system-info/get-browser-info.js";
6
6
  import { normalizedClass } from "../../utils/format.js";
7
- import "../../i18n/util.js";
8
- import "../../i18n/locales/index.js";
9
7
  import enGB from "../../i18n/locales/en-GB.js";
10
8
  import { Button } from "../internal/Button/Button.js";
11
9
  import { IconSafe } from "../internal/icons/IconSafe.js";
@@ -0,0 +1,94 @@
1
+ import { h, A, T, y, u } from "../../core.js";
2
+ import "../../utils/card-brand/brands.js";
3
+ import "../../utils/system-info/get-browser-info.js";
4
+ import "../../core/context.js";
5
+ import { Modal } from "../internal/Modal/Modal.js";
6
+ import "../internal/Button/button2.js";
7
+ import { useBEM } from "../../hooks/useBEM.js";
8
+ import { useI18n } from "../../hooks/useI18n.js";
9
+ import { MessageAction } from "../../types/message.js";
10
+ import { cdnOrigin } from "../../config.js";
11
+ import { safeParse } from "../../utils/index.js";
12
+ import { useBreakpoints } from "../../hooks/useBreakpoints.js";
13
+ import { Icon3DSInfo } from "../internal/icons/Icon3DSInfo.js";
14
+ import { Button } from "../internal/Button/Button.js";
15
+ const { bem } = useBEM("three-ds-auth");
16
+ const ThreeDSAuth = (props) => {
17
+ const { show = false, onClose, url, incomplete = true, width, height = "72vh", theme } = props;
18
+ const breakpoints = useBreakpoints();
19
+ const [continueThreeDs, setContinueThreeDs] = h(false);
20
+ const messageHandler = A();
21
+ const iframeRef = A(null);
22
+ const { i18n } = useI18n();
23
+ const handleLastThreeDs = () => {
24
+ setContinueThreeDs(true);
25
+ };
26
+ const onChange = (status) => {
27
+ !status && (onClose == null ? void 0 : onClose());
28
+ };
29
+ const modalWidth = T(() => {
30
+ if (!show) {
31
+ return "0";
32
+ }
33
+ return width || (breakpoints.smaller("sm") ? "90vw" : "600px");
34
+ }, [show, width, breakpoints.matches]);
35
+ y(() => {
36
+ if (show) {
37
+ if (messageHandler.current) {
38
+ window.removeEventListener("message", messageHandler.current);
39
+ }
40
+ messageHandler.current = (event) => {
41
+ const { data, origin } = event;
42
+ if (origin !== cdnOrigin) {
43
+ return;
44
+ }
45
+ const feedbackData = safeParse(data);
46
+ switch (feedbackData.action) {
47
+ case MessageAction.CHECK_THREE_DS: {
48
+ onChange(false);
49
+ break;
50
+ }
51
+ }
52
+ };
53
+ window.addEventListener("message", messageHandler.current);
54
+ } else {
55
+ messageHandler.current && window.removeEventListener("message", messageHandler.current);
56
+ }
57
+ }, [show]);
58
+ return /* @__PURE__ */ u(
59
+ Modal,
60
+ {
61
+ show,
62
+ onChange,
63
+ width: modalWidth,
64
+ height,
65
+ style: {
66
+ maxWidth: "100vw",
67
+ maxHeight: "100vh",
68
+ minHeight: "500px",
69
+ minWidth: "350px"
70
+ },
71
+ children: /* @__PURE__ */ u("div", { className: bem("content"), children: !incomplete || continueThreeDs ? /* @__PURE__ */ u("iframe", { ref: iframeRef, width: "100%", height: "100%", frameBorder: 0, src: url }) : /* @__PURE__ */ u("div", { className: bem("last-three-ds"), children: [
72
+ /* @__PURE__ */ u(Icon3DSInfo, { size: 60 }),
73
+ /* @__PURE__ */ u("div", { className: bem("last-three-ds-title"), children: [
74
+ /* @__PURE__ */ u("div", { children: i18n.get("threeDS.paymentIncomplete") }),
75
+ /* @__PURE__ */ u("div", { children: i18n.get("threeDS.completeFirst") })
76
+ ] }),
77
+ /* @__PURE__ */ u("div", { children: /* @__PURE__ */ u(
78
+ Button,
79
+ {
80
+ style: {
81
+ backgroundColor: theme == null ? void 0 : theme.payButtonBackgroundColor,
82
+ color: theme == null ? void 0 : theme.payButtonTextColor
83
+ },
84
+ onClick: handleLastThreeDs,
85
+ children: i18n.get("common.confirm")
86
+ }
87
+ ) })
88
+ ] }) })
89
+ }
90
+ );
91
+ };
92
+ export {
93
+ ThreeDSAuth
94
+ };
@@ -7,8 +7,7 @@ import "../../utils/system-info/get-browser-info.js";
7
7
  import { formatAmount } from "../../utils/format.js";
8
8
  import { getWechatPayInfo, wechatPay } from "../../api/modules/wechat-pay/index.js";
9
9
  import { CoreContext } from "../../core/context.js";
10
- import "../../i18n/util.js";
11
- import "../../i18n/locales/index.js";
10
+ import { PayKKaError } from "../../core/error.js";
12
11
  import { createAddressCore } from "../../core/Address.js";
13
12
  import { useBEM } from "../../hooks/useBEM.js";
14
13
  import { usePayState } from "../../hooks/usePayState.js";
@@ -24,6 +23,8 @@ import { RecurringTip } from "../RecurringTip/index.js";
24
23
  import { SubmitButton } from "../SubmitButton/index.js";
25
24
  const { bem } = useBEM("wechat-pay");
26
25
  const WechatPay = w((props, ref) => {
26
+ var _a;
27
+ const { session } = props;
27
28
  let addressState = createAddressCore();
28
29
  let emailState = createEmailCore();
29
30
  const emailFieldRef = A(null);
@@ -39,25 +40,24 @@ const WechatPay = w((props, ref) => {
39
40
  });
40
41
  },
41
42
  updateAddress: () => {
42
- var _a;
43
+ var _a2;
43
44
  setForm(Object.assign(form, { address: addressState.getAddressState() }));
44
- (_a = addressFieldRef.current) == null ? void 0 : _a.update(addressState.getAddressState());
45
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
45
46
  },
46
47
  updateEmail: () => {
47
- var _a;
48
+ var _a2;
48
49
  setForm(Object.assign(form, { email: emailState.email }));
49
- (_a = emailFieldRef.current) == null ? void 0 : _a.update(emailState.email);
50
+ (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
50
51
  }
51
52
  }));
52
53
  const {
53
54
  setErrorMsg,
54
55
  setSubmitButtonStatus,
55
56
  i18n,
56
- session,
57
57
  submitButtonStatus,
58
58
  errorMsg,
59
59
  sessionReady
60
- } = usePayState();
60
+ } = usePayState(session);
61
61
  const formRef = A(null);
62
62
  const [form, setForm] = h({
63
63
  email: "",
@@ -76,8 +76,8 @@ const WechatPay = w((props, ref) => {
76
76
  const [requiredBill, setRequiredBill] = h(false);
77
77
  const addressFieldRef = A(null);
78
78
  function validateForm() {
79
- var _a;
80
- (_a = formRef.current) == null ? void 0 : _a.validate(void 0, false).then(() => {
79
+ var _a2;
80
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
81
81
  setValidated(true);
82
82
  }).catch(() => {
83
83
  setValidated(false);
@@ -87,11 +87,11 @@ const WechatPay = w((props, ref) => {
87
87
  validateForm();
88
88
  }, [form]);
89
89
  y(() => {
90
- var _a;
90
+ var _a2;
91
91
  if (sessionReady) {
92
92
  if ((session == null ? void 0 : session.checkout.status) === "SUCCESS") {
93
93
  setSubmitButtonStatus("success");
94
- (_a = props.onSuccess) == null ? void 0 : _a.call(props);
94
+ (_a2 = props.onSuccess) == null ? void 0 : _a2.call(props);
95
95
  }
96
96
  form.email = (session == null ? void 0 : session.checkout.bill.email) ?? "";
97
97
  disabledEmail.current = !!(session == null ? void 0 : session.checkout.bill.email);
@@ -102,10 +102,10 @@ const WechatPay = w((props, ref) => {
102
102
  }
103
103
  }, [sessionReady]);
104
104
  const onTimeout = q((message) => {
105
- var _a;
105
+ var _a2;
106
106
  setErrorMsg(message || i18n.get("common.payTimeout"));
107
107
  setSubmitButtonStatus("unSubmit");
108
- (_a = props.onTimeout) == null ? void 0 : _a.call(props, "retry");
108
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
109
109
  }, [i18n, props.onTimeout]);
110
110
  const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
111
111
  (timeout) => pay(true, timeout),
@@ -115,7 +115,7 @@ const WechatPay = w((props, ref) => {
115
115
  }
116
116
  );
117
117
  async function pay(search = false, timeout) {
118
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
118
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
119
119
  try {
120
120
  const res = search ? await getWechatPayInfo(
121
121
  {
@@ -138,11 +138,11 @@ const WechatPay = w((props, ref) => {
138
138
  } : {
139
139
  email: form.email
140
140
  },
141
- channelUserId: await ((_a = props.onGetOpenId) == null ? void 0 : _a.call(props))
141
+ channelUserId: await ((_a2 = props.onGetOpenId) == null ? void 0 : _a2.call(props))
142
142
  },
143
143
  { locale: i18n.locale, timeout }
144
144
  );
145
- const { status, orderStatus, errorMessage, payInfo } = res;
145
+ const { status, orderStatus, errorMessage, payInfo, errorCode } = res;
146
146
  !search && ((_b = props.onSubmitResponse) == null ? void 0 : _b.call(props, res));
147
147
  if (status === "PROCESSING") {
148
148
  if (!orderStatus) {
@@ -156,7 +156,7 @@ const WechatPay = w((props, ref) => {
156
156
  } else if (orderStatus === "FAILURE") {
157
157
  setErrorMsg(errorMessage);
158
158
  setSubmitButtonStatus("unSubmit");
159
- (_d = props.onError) == null ? void 0 : _d.call(props, "FAILURE");
159
+ (_d = props.onError) == null ? void 0 : _d.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
160
160
  return {
161
161
  end: true
162
162
  };
@@ -202,20 +202,21 @@ const WechatPay = w((props, ref) => {
202
202
  return { end: true };
203
203
  }
204
204
  } else {
205
- setErrorMsg(error.i18nKey ? i18n.get(error.i18nKey) : error.message);
206
- (_j = props.onError) == null ? void 0 : _j.call(props, error);
205
+ const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
206
+ setErrorMsg(message);
207
+ (_j = props.onError) == null ? void 0 : _j.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
207
208
  setSubmitButtonStatus("unSubmit");
208
209
  return { end: true };
209
210
  }
210
211
  }
211
212
  }
212
213
  async function onSubmit() {
213
- var _a;
214
+ var _a2;
214
215
  setErrorMsg("");
215
- (_a = formRef.current) == null ? void 0 : _a.validate(async (errors) => {
216
- var _a2;
216
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
217
+ var _a3;
217
218
  requiredBill && addressState.setValidateAllFields(true);
218
- (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props, errors);
219
+ (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
219
220
  if (errors) {
220
221
  setSubmitButtonStatus("unSubmit");
221
222
  return;
@@ -274,7 +275,7 @@ const WechatPay = w((props, ref) => {
274
275
  onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
275
276
  }
276
277
  ),
277
- (session == null ? void 0 : session.checkout.paymentType) === PaymentType.RECURRING && RecurringTip(),
278
+ ((_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.paymentType) === PaymentType.RECURRING && RecurringTip(),
278
279
  !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
279
280
  Button()
280
281
  ] })
@@ -6,8 +6,6 @@ import "./CardBrands/index.js";
6
6
  import "../utils/card-brand/brands.js";
7
7
  import "../utils/system-info/get-browser-info.js";
8
8
  import "../core/context.js";
9
- import "../i18n/util.js";
10
- import "../i18n/locales/index.js";
11
9
  import "./CardExpireDateField/index.js";
12
10
  import "./internal/Form/type.js";
13
11
  import "./internal/Form/context.js";
@@ -28,4 +26,4 @@ import "./ApplePay/index.js";
28
26
  import "./GooglePay/index.js";
29
27
  import "./Sepa/index.js";
30
28
  import "./EncryptedCard/index.js";
31
- import "./CombinedEncryptedField/index.js";
29
+ import "./CombinedCardInfo/index.js";
@@ -6,8 +6,6 @@ import "../../../core/context.js";
6
6
  import "../../../utils/card-brand/brands.js";
7
7
  import "../../../utils/system-info/get-browser-info.js";
8
8
  import { normalizedClass } from "../../../utils/format.js";
9
- import "../../../i18n/util.js";
10
- import "../../../i18n/locales/index.js";
11
9
  const { bem } = useBEM("button");
12
10
  function Button(props) {
13
11
  const { style, className, children, icon, loading, disabled, dashed } = props;
@@ -3,5 +3,3 @@ import "./button2.js";
3
3
  import "../../../utils/card-brand/brands.js";
4
4
  import "../../../utils/system-info/get-browser-info.js";
5
5
  import "../../../core/context.js";
6
- import "../../../i18n/util.js";
7
- import "../../../i18n/locales/index.js";
@@ -5,8 +5,6 @@ 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 "../../../i18n/util.js";
9
- import "../../../i18n/locales/index.js";
10
8
  import { COMMON_CLASS_NAME } from "../../../constant.js";
11
9
  import { IconChecked } from "../icons/iconChecked.js";
12
10
  const { bem } = useBEM("check-box");
@@ -3,5 +3,3 @@ import "./check-box.js";
3
3
  import "../../../utils/card-brand/brands.js";
4
4
  import "../../../utils/system-info/get-browser-info.js";
5
5
  import "../../../core/context.js";
6
- import "../../../i18n/util.js";
7
- import "../../../i18n/locales/index.js";
@@ -3,8 +3,6 @@ import "../../../core.js";
3
3
  import "../../../core/context.js";
4
4
  import "../../../utils/card-brand/brands.js";
5
5
  import "../../../utils/system-info/get-browser-info.js";
6
- import "../../../i18n/util.js";
7
- import "../../../i18n/locales/index.js";
8
6
  const formItemBEM = useBEM("form-item");
9
7
  const formItemLabelClassName = formItemBEM.bem("label");
10
8
  const formItemErrorMessageClassName = formItemBEM.bem("error-text");