@paykka/card-checkout-ui 0.5.17 → 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 (189) 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 +0 -2
  4. package/dist/es/api/modules/checkout/index.js +1 -15
  5. package/dist/es/api/modules/checkout/map.js +22 -4
  6. package/dist/es/api/modules/encrypted-card/index.js +54 -0
  7. package/dist/es/api/modules/get-browser-params.js +2 -2
  8. package/dist/es/api/modules/index.js +0 -2
  9. package/dist/es/components/AccountNameField/index.js +2 -3
  10. package/dist/es/components/AddressField/index.js +4 -7
  11. package/dist/es/components/AliPay/index.js +13 -12
  12. package/dist/es/components/ApplePay/index.js +75 -19
  13. package/dist/es/components/Card/index.js +335 -143
  14. package/dist/es/components/CardBrands/index.js +0 -2
  15. package/dist/es/components/CardExpireDateField/index.js +6 -6
  16. package/dist/es/components/CardHolderNameField/index.js +5 -5
  17. package/dist/es/components/CardIBANField/index.js +2 -3
  18. package/dist/es/components/CardNo/index.js +0 -2
  19. package/dist/es/components/CardNumberField/index.js +32 -20
  20. package/dist/es/components/CardSecurityCodeField/index.js +6 -6
  21. package/dist/es/components/CardSelector/index.js +1 -3
  22. package/dist/es/components/CombinedCardInfo/index.js +99 -0
  23. package/dist/es/components/EmailField/EmailField.js +2 -3
  24. package/dist/es/components/EncryptedCard/index.js +408 -0
  25. package/dist/es/components/GooglePay/index.js +108 -36
  26. package/dist/es/components/RecurringTip/index.js +0 -2
  27. package/dist/es/components/SecuredFieldsProvider/index.js +230 -1
  28. package/dist/es/components/SecuredIframe/index.js +192 -22
  29. package/dist/es/components/Sepa/index.js +36 -32
  30. package/dist/es/components/SubmitButton/index.js +0 -2
  31. package/dist/es/components/ThreeDS/index.js +94 -0
  32. package/dist/es/components/WechatPay/index.js +31 -30
  33. package/dist/es/components/index.js +4 -2
  34. package/dist/es/components/internal/Button/Button.js +0 -2
  35. package/dist/es/components/internal/Button/index.js +0 -2
  36. package/dist/es/components/internal/CheckBox/CheckBox.js +0 -2
  37. package/dist/es/components/internal/CheckBox/index.js +0 -2
  38. package/dist/es/components/internal/Form/FormItem.js +28 -24
  39. package/dist/es/components/internal/Form/index.js +1 -0
  40. package/dist/es/components/internal/Form/type.js +13 -1
  41. package/dist/es/components/internal/Info/Info.js +0 -2
  42. package/dist/es/components/internal/Info/index.js +0 -2
  43. package/dist/es/components/internal/Input/Input.js +11 -13
  44. package/dist/es/components/internal/Input/index.js +1 -0
  45. package/dist/es/components/internal/Input/type.js +11 -1
  46. package/dist/es/components/internal/LoadingCheck/LoadingCheck.js +0 -2
  47. package/dist/es/components/internal/LoadingCheck/index.js +0 -2
  48. package/dist/es/components/internal/Modal/Modal.js +40 -0
  49. package/dist/es/components/internal/Modal/modal2.js +1 -0
  50. package/dist/es/components/internal/Select/Select.js +2 -2
  51. package/dist/es/components/internal/Select/SelectMenu.js +0 -2
  52. package/dist/es/components/internal/Select/SelectMenuItem.js +0 -2
  53. package/dist/es/components/internal/icons/Icon3DSFail.js +3 -0
  54. package/dist/es/components/internal/icons/Icon3DSInfo.js +62 -0
  55. package/dist/es/components/internal/icons/Icon3DSSuccess.js +3 -0
  56. package/dist/es/config.js +12 -8
  57. package/dist/es/constant.js +13 -2
  58. package/dist/es/core/PayKKaCheckout.js +116 -0
  59. package/dist/es/core/Session.js +7 -6
  60. package/dist/es/core/environment.js +26 -0
  61. package/dist/es/core/error.js +21 -0
  62. package/dist/es/core/index.js +0 -2
  63. package/dist/es/core/query.js +1 -8
  64. package/dist/es/hooks/index.js +0 -2
  65. package/dist/es/hooks/useBreakpoints.js +57 -0
  66. package/dist/es/hooks/useI18n.js +0 -1
  67. package/dist/es/hooks/usePayState.js +20 -33
  68. package/dist/es/i18n/index.js +0 -2
  69. package/dist/es/i18n/locales/de-DE.js +11 -1
  70. package/dist/es/i18n/locales/en-GB.js +11 -1
  71. package/dist/es/i18n/locales/es-ES.js +11 -1
  72. package/dist/es/i18n/locales/fr-FR.js +11 -1
  73. package/dist/es/i18n/locales/index.js +8 -6
  74. package/dist/es/i18n/locales/ja-JP.js +11 -1
  75. package/dist/es/i18n/locales/ko-KR.js +11 -1
  76. package/dist/es/i18n/locales/pt-PT.js +11 -1
  77. package/dist/es/i18n/locales/ru-RU.js +11 -1
  78. package/dist/es/i18n/locales/zh-CN.js +11 -1
  79. package/dist/es/i18n/locales/zh-HK.js +11 -1
  80. package/dist/es/i18n/locales/zh-TW.js +11 -1
  81. package/dist/es/i18n/util.js +11 -8
  82. package/dist/es/index.js +15 -2
  83. package/dist/es/out/fraud-detection.js +99 -0
  84. package/dist/es/style.css +194 -4
  85. package/dist/es/types/{radar.js → fraud-detection.js} +1 -1
  86. package/dist/es/types/index.js +49 -1
  87. package/dist/es/types/message.js +28 -0
  88. package/dist/es/utils/card-brand/brands.js +21 -45
  89. package/dist/es/utils/card-brand/index.js +3 -2
  90. package/dist/es/utils/iframe.js +23 -0
  91. package/dist/es/utils/index.js +11 -1
  92. package/dist/es/utils/load.js +14 -0
  93. package/dist/es/utils/style.js +84 -0
  94. package/dist/style.css +1 -1
  95. package/dist/types/api/modules/checkout/map.d.ts +1 -0
  96. package/dist/types/api/modules/checkout/type.d.ts +14 -1
  97. package/dist/types/api/modules/encrypted-card/index.d.ts +6 -0
  98. package/dist/types/api/modules/encrypted-card/type.d.ts +31 -0
  99. package/dist/types/api/modules/get-browser-params.d.ts +3 -3
  100. package/dist/types/components/AddressField/type.d.ts +1 -0
  101. package/dist/types/components/AliPay/type.d.ts +4 -4
  102. package/dist/types/components/ApplePay/type.d.ts +19 -7
  103. package/dist/types/components/ApplePay/utils.d.ts +3 -0
  104. package/dist/types/components/Card/type.d.ts +64 -6
  105. package/dist/types/components/CardExpireDateField/type.d.ts +1 -0
  106. package/dist/types/components/CardHolderNameField/type.d.ts +1 -1
  107. package/dist/types/components/CardNumberField/type.d.ts +3 -0
  108. package/dist/types/components/CardSecurityCodeField/type.d.ts +1 -0
  109. package/dist/types/components/CombinedCardInfo/CombinedCardInfo.d.ts +5 -0
  110. package/dist/types/components/CombinedCardInfo/index.d.ts +2 -0
  111. package/dist/types/components/CombinedCardInfo/type.d.ts +16 -0
  112. package/dist/types/components/EncryptedCard/EncryptedCard.d.ts +4 -0
  113. package/dist/types/components/EncryptedCard/index.d.ts +4 -0
  114. package/dist/types/components/EncryptedCard/output.d.ts +9 -0
  115. package/dist/types/components/EncryptedCard/type.d.ts +85 -0
  116. package/dist/types/components/GooglePay/type.d.ts +20 -8
  117. package/dist/types/components/GooglePay/utils.d.ts +2 -0
  118. package/dist/types/components/SecuredFieldsProvider/index.d.ts +1 -0
  119. package/dist/types/components/SecuredFieldsProvider/type.d.ts +29 -100
  120. package/dist/types/components/SecuredFieldsProvider/utils/index.d.ts +1 -1
  121. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +7 -2
  122. package/dist/types/components/Sepa/type.d.ts +4 -4
  123. package/dist/types/components/ThreeDS/components/ThreeDSAuth/ThreeDSAuth.d.ts +3 -0
  124. package/dist/types/components/ThreeDS/components/ThreeDSAuth/index.d.ts +2 -0
  125. package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +17 -0
  126. package/dist/types/components/ThreeDS/components/ThreeDSIframe/ThreeDSIframe.d.ts +2 -0
  127. package/dist/types/components/ThreeDS/components/ThreeDSIframe/index.d.ts +1 -0
  128. package/dist/types/components/ThreeDS/components/ThreeDSIframe/output.d.ts +1 -0
  129. package/dist/types/components/ThreeDS/components/ThreeDSIframe/type.d.ts +5 -0
  130. package/dist/types/components/ThreeDS/components/ThreeDSStatus/ThreeDSStatus.d.ts +3 -0
  131. package/dist/types/components/ThreeDS/components/ThreeDSStatus/output.d.ts +1 -0
  132. package/dist/types/components/ThreeDS/components/ThreeDSStatus/type.d.ts +6 -0
  133. package/dist/types/components/ThreeDS/index.d.ts +1 -0
  134. package/dist/types/components/WechatPay/type.d.ts +4 -4
  135. package/dist/types/components/index.d.ts +2 -0
  136. package/dist/types/components/internal/Form/FormItem.d.ts +1 -1
  137. package/dist/types/components/internal/Form/type.d.ts +7 -0
  138. package/dist/types/components/internal/Input/Input.d.ts +1 -1
  139. package/dist/types/components/internal/Input/type.d.ts +7 -0
  140. package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
  141. package/dist/types/components/internal/Loading/index.d.ts +1 -0
  142. package/dist/types/components/internal/Modal/Modal.d.ts +5 -0
  143. package/dist/types/components/internal/Modal/index.d.ts +0 -0
  144. package/dist/types/components/internal/Modal/type.d.ts +20 -0
  145. package/dist/types/components/internal/icons/Icon3DSFail.d.ts +2 -0
  146. package/dist/types/components/internal/icons/Icon3DSInfo.d.ts +2 -0
  147. package/dist/types/components/internal/icons/Icon3DSSuccess.d.ts +2 -0
  148. package/dist/types/components/internal/icons/index.d.ts +3 -0
  149. package/dist/types/config.d.ts +7 -3
  150. package/dist/types/constant.d.ts +7 -2
  151. package/dist/types/core/PayKKaCheckout.d.ts +28 -0
  152. package/dist/types/core/Session.d.ts +1 -1
  153. package/dist/types/core/context.d.ts +1 -0
  154. package/dist/types/core/environment.d.ts +4 -0
  155. package/dist/types/core/error.d.ts +16 -0
  156. package/dist/types/core/index.d.ts +2 -0
  157. package/dist/types/core/query.d.ts +2 -2
  158. package/dist/types/hooks/index.d.ts +1 -0
  159. package/dist/types/hooks/useBreakpoints.d.ts +15 -0
  160. package/dist/types/hooks/usePayState.d.ts +6 -25
  161. package/dist/types/i18n/locales/de-DE.d.ts +8 -0
  162. package/dist/types/i18n/locales/en-GB.d.ts +8 -0
  163. package/dist/types/i18n/locales/es-ES.d.ts +8 -0
  164. package/dist/types/i18n/locales/fr-FR.d.ts +8 -0
  165. package/dist/types/i18n/locales/index.d.ts +2 -2
  166. package/dist/types/i18n/locales/ja-JP.d.ts +8 -0
  167. package/dist/types/i18n/locales/ko-KR.d.ts +8 -0
  168. package/dist/types/i18n/locales/pt-PT.d.ts +8 -0
  169. package/dist/types/i18n/locales/ru-RU.d.ts +8 -0
  170. package/dist/types/i18n/locales/zh-CN.d.ts +8 -0
  171. package/dist/types/i18n/locales/zh-HK.d.ts +8 -0
  172. package/dist/types/i18n/locales/zh-TW.d.ts +8 -0
  173. package/dist/types/index.d.ts +2 -2
  174. package/dist/types/out/fraud-detection.d.ts +9 -0
  175. package/dist/types/types/{radar.d.ts → fraud-detection.d.ts} +3 -2
  176. package/dist/types/types/index.d.ts +100 -1
  177. package/dist/types/types/message.d.ts +170 -0
  178. package/dist/types/utils/card-brand/brands.d.ts +4 -18
  179. package/dist/types/utils/card-brand/index.d.ts +10 -9
  180. package/dist/types/utils/format.d.ts +0 -1
  181. package/dist/types/utils/index.d.ts +4 -0
  182. package/dist/types/utils/load.d.ts +7 -0
  183. package/dist/types/utils/style.d.ts +29 -0
  184. package/package.json +63 -63
  185. package/dist/card-checkout-ui.iife.js +0 -8
  186. package/dist/es/components/SecuredFieldsProvider/SecuredFieldsProvider.js +0 -222
  187. package/dist/es/out/radar.js +0 -123
  188. package/dist/types/out/radar.d.ts +0 -14
  189. /package/dist/types/{components/SecuredFieldsProvider/utils → utils}/iframe.d.ts +0 -0
@@ -1,14 +1,16 @@
1
1
  import { A, h, y, u, b } from "../../core.js";
2
2
  import { clamp, isExpired, safeParse } from "../../utils/index.js";
3
- import { FieldType, 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
- import "../../utils/card-brand/brands.js";
8
- import "../../utils/system-info/get-browser-info.js";
9
7
  import { cdnOrigin, setApiUrl, setCDNUrl } from "../../config.js";
8
+ import { MessageAction } from "../../types/message.js";
9
+ import { generateClassNameMap, style2String, createPlaceholderStyle, loadStyle } from "../../utils/style.js";
10
+ import { postMessageToIframe } from "../../utils/iframe.js";
10
11
  import { isTimeoutError } from "../../api/http.js";
11
12
  import { cardPay } from "../../api/modules/card/index.js";
13
+ import { encryptCard } from "../../api/modules/encrypted-card/index.js";
12
14
  const useSecuredInput = () => {
13
15
  let fieldType;
14
16
  let supportedCardBrands;
@@ -16,6 +18,7 @@ const useSecuredInput = () => {
16
18
  const [cardBin, setCardBin] = h("");
17
19
  let brands;
18
20
  let brandLengths;
21
+ const [brand, setBrand] = h(void 0);
19
22
  const initSecuredInput = (options) => {
20
23
  fieldType = options.fieldType;
21
24
  supportedCardBrands = options.supportedCardBrands;
@@ -29,25 +32,28 @@ const useSecuredInput = () => {
29
32
  }
30
33
  };
31
34
  switch (fieldType) {
32
- case FieldType.CVV: {
35
+ case EFieldType.CVV: {
33
36
  config = {
34
37
  maxLength: 4,
38
+ inputMode: "numeric",
35
39
  onInput: onInputCVV,
36
40
  validator: cvvValidator
37
41
  };
38
42
  break;
39
43
  }
40
- case FieldType.CARD_NUMBER: {
44
+ case EFieldType.CARD_NUMBER: {
41
45
  config = {
42
46
  maxLength: 23,
47
+ inputMode: "numeric",
43
48
  onInput: onInputCardNumber,
44
49
  validator: cardNumberValidator
45
50
  };
46
51
  break;
47
52
  }
48
- case FieldType.EXPIRE_DATE: {
53
+ case EFieldType.EXPIRE_DATE: {
49
54
  config = {
50
55
  maxLength: 5,
56
+ inputMode: "numeric",
51
57
  onInput: onInputExpireDate,
52
58
  validator: expireDateValidator
53
59
  };
@@ -62,6 +68,7 @@ const useSecuredInput = () => {
62
68
  value.current = currentTarget.value = val;
63
69
  };
64
70
  const onInputCardNumber = (event) => {
71
+ var _a;
65
72
  const { inputType } = event;
66
73
  const currentTarget = event.currentTarget;
67
74
  const selectionStart = currentTarget.selectionStart;
@@ -73,7 +80,9 @@ const useSecuredInput = () => {
73
80
  }
74
81
  value.current = currentTarget.value = val;
75
82
  currentTarget.setSelectionRange(pos, pos);
76
- setCardBin(trimAll(currentTarget.value).substring(0, 6));
83
+ const newBin = trimAll(currentTarget.value).substring(0, 6);
84
+ setCardBin(newBin.length < 6 ? "" : newBin);
85
+ setBrand((_a = getCurrCardBrand(trimAll(currentTarget.value))) == null ? void 0 : _a.code);
77
86
  };
78
87
  const onInputExpireDate = (event) => {
79
88
  const { inputType } = event;
@@ -145,7 +154,7 @@ const useSecuredInput = () => {
145
154
  if (!brandLengths.includes(realValue.length)) {
146
155
  throw new Error("card.cardNumber.incomplete");
147
156
  }
148
- const cardBrand = findCardBrand(realValue, brands);
157
+ const cardBrand = getCurrCardBrand(realValue);
149
158
  if (!cardBrand) {
150
159
  throw new Error("card.cardNumber.invalid");
151
160
  }
@@ -159,18 +168,35 @@ const useSecuredInput = () => {
159
168
  throw new Error("card.cardExpireDate.expired");
160
169
  }
161
170
  };
171
+ const getCurrCardBrand = (realValue) => {
172
+ return findCardBrand(realValue, brands);
173
+ };
174
+ const validate = () => {
175
+ if (fieldType === EFieldType.CARD_NUMBER) {
176
+ return cardNumberValidator();
177
+ } else if (fieldType === EFieldType.CVV) {
178
+ return cvvValidator();
179
+ } else if (fieldType === EFieldType.EXPIRE_DATE) {
180
+ return expireDateValidator();
181
+ }
182
+ };
162
183
  return {
163
184
  value,
164
185
  cardBin,
165
186
  initSecuredInput,
166
- getConfigByFieldType
187
+ getConfigByFieldType,
188
+ getCurrCardBrand,
189
+ brand,
190
+ validate
167
191
  };
168
192
  };
193
+ const inputClassNameMap = generateClassNameMap("input");
169
194
  const FieldIframe = (props) => {
170
195
  const hiddenIframe = window.parent.frames[props.hiddenIframeName];
171
196
  const inputRef = A(null);
172
- const { initSecuredInput, getConfigByFieldType, cardBin, value } = useSecuredInput();
197
+ const { initSecuredInput, getConfigByFieldType, getCurrCardBrand, cardBin, value, brand } = useSecuredInput();
173
198
  const [hasInit, setHasInit] = h(false);
199
+ const inputId = "securedInput";
174
200
  const initInput = () => {
175
201
  initSecuredInput({
176
202
  fieldType: props.fieldType,
@@ -179,47 +205,128 @@ const FieldIframe = (props) => {
179
205
  postMessageToIframe(message, window.parent);
180
206
  }
181
207
  });
208
+ processInputStyleConfig(props.style);
209
+ };
210
+ const processInputStyleConfig = (style = {}) => {
211
+ const { base, hover, focus, valid, invalid, placeholder } = style;
212
+ const baseStyleStr = `input { ${style2String(base)} }`;
213
+ const hoverStyleStr = `input.${inputClassNameMap.hover} { ${style2String(hover)} }`;
214
+ const focusStyleStr = `input.${inputClassNameMap.focus} { ${style2String(focus)} }`;
215
+ const validStyleStr = `input.${inputClassNameMap.valid} { ${style2String(valid)} }`;
216
+ const invalidStyleStr = `input.${inputClassNameMap.invalid} { ${style2String(invalid)} }`;
217
+ const placeholderStyleStr = createPlaceholderStyle("input", placeholder == null ? void 0 : placeholder.base);
218
+ const placeholderFocusStyleStr = createPlaceholderStyle(
219
+ `input.${inputClassNameMap.focus}`,
220
+ placeholder == null ? void 0 : placeholder.focus
221
+ );
222
+ const styleStr = `
223
+ ${baseStyleStr}
224
+ ${hoverStyleStr}
225
+ ${focusStyleStr}
226
+ ${validStyleStr}
227
+ ${invalidStyleStr}
228
+ ${placeholderStyleStr}
229
+ ${placeholderFocusStyleStr}
230
+ `;
231
+ const styleId = "securedInputStyle";
232
+ if (!document.querySelector(`style#${styleId}`)) {
233
+ loadStyle(styleStr, { id: styleId });
234
+ }
182
235
  };
183
236
  y(() => {
237
+ initInput();
184
238
  const inputConfig = getConfigByFieldType();
185
239
  const inputEl = inputRef.current;
186
240
  inputEl.oninput = inputConfig.onInput;
187
241
  inputEl.maxLength = inputConfig.maxLength;
188
- inputEl.onfocus = () => sendFocusMessage(true);
242
+ inputEl.inputMode = inputConfig.inputMode;
243
+ inputEl.onfocus = () => {
244
+ var _a;
245
+ (_a = inputEl == null ? void 0 : inputEl.classList) == null ? void 0 : _a.add(inputClassNameMap.focus);
246
+ sendFocusMessage(true);
247
+ };
189
248
  inputEl.onblur = () => {
190
- sendFocusMessage(false);
249
+ var _a;
191
250
  try {
251
+ (_a = inputEl == null ? void 0 : inputEl.classList) == null ? void 0 : _a.remove(inputClassNameMap.focus);
192
252
  if (isNil(value.current) || value.current === "") {
193
- sendValidStatusChanged("unValidate");
253
+ processValidStatusChanged("unValidate");
254
+ sendFocusMessage(false);
194
255
  return;
195
256
  }
196
257
  inputConfig.validator();
197
- sendValidStatusChanged("success");
258
+ processValidStatusChanged("success");
198
259
  } catch (error) {
199
- sendValidStatusChanged("error", error);
260
+ processValidStatusChanged("error", error);
200
261
  }
262
+ sendFocusMessage(false);
263
+ };
264
+ inputEl.onmouseenter = (e) => {
265
+ var _a;
266
+ const inputEl2 = e.target;
267
+ (_a = inputEl2 == null ? void 0 : inputEl2.classList) == null ? void 0 : _a.add(inputClassNameMap.hover);
268
+ };
269
+ inputEl.onmouseleave = (e) => {
270
+ var _a;
271
+ const inputEl2 = e.target;
272
+ (_a = inputEl2 == null ? void 0 : inputEl2.classList) == null ? void 0 : _a.remove(inputClassNameMap.hover);
201
273
  };
202
274
  setHasInit(true);
275
+ sendActivatedMessage();
276
+ window.addEventListener("message", onReceiveMessage);
203
277
  }, []);
204
- initInput();
278
+ const onReceiveMessage = (event) => {
279
+ const { data } = event;
280
+ const parsedData = safeParse(data);
281
+ if (!Reflect.has(parsedData, "action")) {
282
+ return;
283
+ }
284
+ if (parsedData.action === MessageAction.VALIDATE) {
285
+ try {
286
+ const inputConfig = getConfigByFieldType();
287
+ inputConfig.validator();
288
+ processValidStatusChanged("success");
289
+ sendValidateMessage("success");
290
+ } catch (error) {
291
+ processValidStatusChanged("error", error);
292
+ sendValidateMessage("error");
293
+ }
294
+ }
295
+ };
205
296
  y(() => {
206
297
  if (!hasInit) {
207
298
  return;
208
299
  }
209
300
  sendBinValueMessage(cardBin);
210
301
  }, [cardBin]);
302
+ y(() => {
303
+ if (!hasInit) {
304
+ return;
305
+ }
306
+ sendBrandMessage(brand);
307
+ }, [brand]);
211
308
  y(() => {
212
309
  if (!hasInit) {
213
310
  return;
214
311
  }
215
312
  if (!value) {
216
- sendValidStatusChanged("unValidate");
313
+ processValidStatusChanged("unValidate");
217
314
  }
218
315
  }, [value]);
219
316
  const sendBinValueMessage = (binValue) => {
317
+ var _a;
220
318
  const data = {
221
319
  action: MessageAction.BIN_VALUE,
222
320
  binValue,
321
+ fieldType: props.fieldType,
322
+ brand: (_a = getCurrCardBrand(binValue)) == null ? void 0 : _a.code
323
+ };
324
+ postMessageToIframe(data, window.parent);
325
+ };
326
+ const sendBrandMessage = (brand2) => {
327
+ const data = {
328
+ action: MessageAction.BRAND,
329
+ brand: brand2,
223
330
  fieldType: props.fieldType
224
331
  };
225
332
  postMessageToIframe(data, window.parent);
@@ -232,6 +339,19 @@ const FieldIframe = (props) => {
232
339
  };
233
340
  postMessageToIframe(data, window.parent);
234
341
  };
342
+ const processValidStatusChanged = (status, err) => {
343
+ const inputEl = inputRef.current;
344
+ if (status === "unValidate") {
345
+ inputEl.classList.remove(inputClassNameMap.valid, inputClassNameMap.invalid);
346
+ } else if (status === "success") {
347
+ inputEl.classList.add(inputClassNameMap.valid);
348
+ inputEl.classList.remove(inputClassNameMap.invalid);
349
+ } else {
350
+ inputEl.classList.add(inputClassNameMap.invalid);
351
+ inputEl.classList.remove(inputClassNameMap.valid);
352
+ }
353
+ sendValidStatusChanged(status, err);
354
+ };
235
355
  const sendValidStatusChanged = (status, err) => {
236
356
  const validData = {
237
357
  action: MessageAction.VALID_STATUS_CHANGED,
@@ -243,6 +363,9 @@ const FieldIframe = (props) => {
243
363
  if (status !== "success") {
244
364
  return;
245
365
  }
366
+ sendValidWithValueMessage();
367
+ };
368
+ const sendValidWithValueMessage = () => {
246
369
  const validWithValueData = {
247
370
  action: MessageAction.VALID_WITH_VALUE,
248
371
  value: value.current,
@@ -250,12 +373,27 @@ const FieldIframe = (props) => {
250
373
  };
251
374
  postMessageToIframe(validWithValueData, hiddenIframe, cdnOrigin);
252
375
  };
376
+ const sendActivatedMessage = () => {
377
+ const data = {
378
+ action: MessageAction.ACTIVATED,
379
+ fieldType: props.fieldType
380
+ };
381
+ postMessageToIframe(data, window.parent);
382
+ };
383
+ const sendValidateMessage = (status) => {
384
+ const data = {
385
+ action: MessageAction.VALIDATED,
386
+ fieldType: props.fieldType,
387
+ status
388
+ };
389
+ postMessageToIframe(data, window.parent);
390
+ };
253
391
  return /* @__PURE__ */ u(
254
392
  "input",
255
393
  {
394
+ id: inputId,
256
395
  ref: inputRef,
257
396
  placeholder: props.placeholder,
258
- style: props.style,
259
397
  autocomplete: "off",
260
398
  disabled: !hasInit
261
399
  }
@@ -268,7 +406,7 @@ const HiddenIframe = () => {
268
406
  cardNo: "",
269
407
  cvv: ""
270
408
  };
271
- const onReceiveMessage = (event) => {
409
+ const onReceiveMessage = async (event) => {
272
410
  const { data } = event;
273
411
  const parsedData = safeParse(data);
274
412
  if (!Reflect.has(parsedData, "action")) {
@@ -277,15 +415,15 @@ const HiddenIframe = () => {
277
415
  if (parsedData.action === MessageAction.VALID_WITH_VALUE) {
278
416
  const feedbackData = parsedData;
279
417
  switch (feedbackData.fieldType) {
280
- case FieldType.CVV: {
418
+ case EFieldType.CVV: {
281
419
  formData.cvv = feedbackData.value;
282
420
  break;
283
421
  }
284
- case FieldType.CARD_NUMBER: {
422
+ case EFieldType.CARD_NUMBER: {
285
423
  formData.cardNo = trimAll(feedbackData.value);
286
424
  break;
287
425
  }
288
- case FieldType.EXPIRE_DATE: {
426
+ case EFieldType.EXPIRE_DATE: {
289
427
  const [expMonth, expYear] = feedbackData.value.split("/");
290
428
  formData.expMonth = expMonth;
291
429
  formData.expYear = `20${expYear}`;
@@ -295,6 +433,15 @@ const HiddenIframe = () => {
295
433
  } else if (parsedData.action === MessageAction.PAYMENT) {
296
434
  const feedbackData = parsedData;
297
435
  pay(feedbackData.formData, feedbackData.locale);
436
+ } else if (parsedData.action === MessageAction.ENCRYPT_CARD) {
437
+ const feedbackData = parsedData;
438
+ try {
439
+ const res = await encryptCard({ ...feedbackData, ...formData });
440
+ sendCardEncryptedMessage(res);
441
+ } catch (error) {
442
+ console.log("error", error);
443
+ sendCardEncryptionFailedMessage(error);
444
+ }
298
445
  }
299
446
  };
300
447
  window.addEventListener("message", onReceiveMessage);
@@ -339,6 +486,29 @@ const HiddenIframe = () => {
339
486
  };
340
487
  postMessageToIframe(data, window.parent);
341
488
  };
489
+ const sendHiddenIframeReadyMessage = () => {
490
+ const data = {
491
+ action: MessageAction.HIDDEN_IFRAME_READY
492
+ };
493
+ postMessageToIframe(data, window.parent);
494
+ };
495
+ const sendCardEncryptedMessage = (encryptedInfo) => {
496
+ const data = {
497
+ action: MessageAction.CARD_ENCRYPTED,
498
+ encryptedInfo
499
+ };
500
+ postMessageToIframe(data, window.parent);
501
+ };
502
+ const sendCardEncryptionFailedMessage = (error) => {
503
+ const data = {
504
+ action: MessageAction.CARD_ENCRYPTION_FAILED,
505
+ error
506
+ };
507
+ postMessageToIframe(data, window.parent);
508
+ };
509
+ y(() => {
510
+ sendHiddenIframeReadyMessage();
511
+ }, []);
342
512
  return /* @__PURE__ */ u(b, {});
343
513
  };
344
514
  const SecuredIframe = () => {
@@ -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,13 +10,13 @@ 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";
18
17
  import { EmailField, createEmailCore } from "../EmailField/EmailField.js";
19
18
  import { SubmitButton } from "../SubmitButton/index.js";
19
+ import "../internal/Form/type.js";
20
20
  import "../internal/Form/context.js";
21
21
  import "../internal/Form/FormItem.js";
22
22
  import { Form } from "../internal/Form/Form.js";
@@ -27,10 +27,10 @@ const { bem } = useBEM("sepa");
27
27
  const fieldClassNames = bem("field");
28
28
  const Sepa = w((props, ref) => {
29
29
  var _a, _b, _c, _d, _e, _f;
30
- const { sessionId, clientKey } = props;
30
+ const { session } = props;
31
31
  let addressState = createAddressCore();
32
32
  let emailState = createEmailCore();
33
- const { i18n, session, sessionReady } = usePayState(props);
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 ?? {};
@@ -160,8 +153,8 @@ const Sepa = w((props, ref) => {
160
153
  });
161
154
  const getPaymentParams = async () => {
162
155
  return {
163
- sessionId,
164
- clientKey,
156
+ sessionId: session.sessionId,
157
+ clientKey: session.clientKey,
165
158
  payment: {
166
159
  holderName: form.holderName,
167
160
  iban: trimAll(form.iban)
@@ -182,7 +175,10 @@ const Sepa = w((props, ref) => {
182
175
  try {
183
176
  const paymentParams = await getPaymentParams();
184
177
  const options = { locale: i18n.locale, timeout };
185
- const res = search ? await getSepaPayInfo({ sessionId, clientKey }, options) : await sepaPay(paymentParams, options);
178
+ const res = search ? await getSepaPayInfo(
179
+ { sessionId: session.sessionId, clientKey: session.clientKey },
180
+ options
181
+ ) : await sepaPay(paymentParams, options);
186
182
  return processAfterPayment(res, search);
187
183
  } catch (error) {
188
184
  if (isTimeoutError(error)) {
@@ -193,8 +189,9 @@ const Sepa = w((props, ref) => {
193
189
  return { end: true };
194
190
  }
195
191
  } else {
196
- setErrorMsg(error.i18nKey ? i18n.get(error.i18nKey) : error.message);
197
- (_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 }));
198
195
  setSubmitButtonStatus("unSubmit");
199
196
  return { end: true };
200
197
  }
@@ -202,7 +199,7 @@ const Sepa = w((props, ref) => {
202
199
  }
203
200
  const processAfterPayment = (res, search = false) => {
204
201
  var _a2, _b2, _c2;
205
- const { status, orderStatus, errorMessage } = res;
202
+ const { status, orderStatus, errorMessage, errorCode } = res;
206
203
  if (status === "PROCESSING") {
207
204
  if (!orderStatus) {
208
205
  setSubmitButtonStatus("unSubmit");
@@ -219,7 +216,7 @@ const Sepa = w((props, ref) => {
219
216
  } else if (orderStatus === "FAILURE") {
220
217
  setErrorMsg(errorMessage);
221
218
  setSubmitButtonStatus("unSubmit");
222
- (_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 }));
223
220
  } else if (orderStatus === "AUTHORIZED") {
224
221
  setSubmitButtonStatus("unSubmit");
225
222
  (_b2 = props.onAuthorized) == null ? void 0 : _b2.call(props);
@@ -250,7 +247,14 @@ const Sepa = w((props, ref) => {
250
247
  session
251
248
  },
252
249
  children: sessionReady && isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: formStyle, children: [
253
- /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(EmailField, { ref: emailFieldRef, value: form.email, disabled: !!disabledEmail.current }) }),
250
+ /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
251
+ EmailField,
252
+ {
253
+ ref: emailFieldRef,
254
+ value: form.email,
255
+ disabled: !!disabledEmail.current
256
+ }
257
+ ) }),
254
258
  /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u("div", { className: bem("iban-wrapper"), children: /* @__PURE__ */ u(IBANField, {}) }) }),
255
259
  /* @__PURE__ */ u("div", { className: bem("holder-name"), children: /* @__PURE__ */ u(AccountNameField, {}) }),
256
260
  requiredBill && /* @__PURE__ */ u("div", { className: bem("address"), children: /* @__PURE__ */ u(
@@ -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
+ };