@paykka/card-checkout-ui 0.5.17 → 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 (98) 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/modules/checkout/map.js +2 -1
  4. package/dist/es/api/modules/encrypted-card/index.js +54 -0
  5. package/dist/es/api/modules/get-browser-params.js +2 -2
  6. package/dist/es/components/AccountNameField/index.js +2 -0
  7. package/dist/es/components/AddressField/index.js +2 -0
  8. package/dist/es/components/AliPay/index.js +8 -8
  9. package/dist/es/components/ApplePay/index.js +71 -14
  10. package/dist/es/components/Card/index.js +56 -40
  11. package/dist/es/components/CardExpireDateField/index.js +6 -3
  12. package/dist/es/components/CardHolderNameField/index.js +2 -0
  13. package/dist/es/components/CardIBANField/index.js +2 -0
  14. package/dist/es/components/CardNumberField/index.js +32 -17
  15. package/dist/es/components/CardSecurityCodeField/index.js +6 -3
  16. package/dist/es/components/CardSelector/index.js +1 -0
  17. package/dist/es/components/CombinedEncryptedField/index.js +75 -0
  18. package/dist/es/components/EmailField/EmailField.js +2 -0
  19. package/dist/es/components/EncryptedCard/index.js +448 -0
  20. package/dist/es/components/GooglePay/index.js +57 -19
  21. package/dist/es/components/SecuredFieldsProvider/SecuredFieldsProvider.js +70 -24
  22. package/dist/es/components/SecuredIframe/index.js +190 -22
  23. package/dist/es/components/Sepa/index.js +16 -6
  24. package/dist/es/components/WechatPay/index.js +8 -8
  25. package/dist/es/components/index.js +4 -0
  26. package/dist/es/components/internal/Form/FormItem.js +28 -24
  27. package/dist/es/components/internal/Form/index.js +1 -0
  28. package/dist/es/components/internal/Form/type.js +15 -1
  29. package/dist/es/components/internal/Input/Input.js +9 -11
  30. package/dist/es/components/internal/Input/index.js +1 -0
  31. package/dist/es/components/internal/Input/type.js +13 -1
  32. package/dist/es/components/internal/Select/Select.js +2 -0
  33. package/dist/es/config.js +12 -6
  34. package/dist/es/constant.js +10 -0
  35. package/dist/es/core/PayKKaCheckout.js +62 -0
  36. package/dist/es/core/query.js +1 -6
  37. package/dist/es/core.js +34 -34
  38. package/dist/es/hooks/useI18n.js +1 -1
  39. package/dist/es/hooks/usePayState.js +11 -18
  40. package/dist/es/index.js +13 -2
  41. package/dist/es/out/fraud-detection.js +99 -0
  42. package/dist/es/style.css +8 -0
  43. package/dist/es/types/{radar.js → fraud-detection.js} +1 -1
  44. package/dist/es/types/index.js +49 -1
  45. package/dist/es/utils/card-brand/brands.js +16 -42
  46. package/dist/es/utils/index.js +11 -0
  47. package/dist/es/utils/load.js +14 -0
  48. package/dist/es/utils/style.js +37 -0
  49. package/dist/style.css +1 -1
  50. package/dist/types/api/modules/checkout/map.d.ts +1 -0
  51. package/dist/types/api/modules/encrypted-card/index.d.ts +6 -0
  52. package/dist/types/api/modules/encrypted-card/type.d.ts +31 -0
  53. package/dist/types/api/modules/get-browser-params.d.ts +2 -2
  54. package/dist/types/components/AliPay/type.d.ts +0 -2
  55. package/dist/types/components/ApplePay/type.d.ts +16 -5
  56. package/dist/types/components/ApplePay/utils.d.ts +3 -0
  57. package/dist/types/components/Card/type.d.ts +15 -3
  58. package/dist/types/components/CardExpireDateField/type.d.ts +1 -0
  59. package/dist/types/components/CardNumberField/type.d.ts +3 -0
  60. package/dist/types/components/CardSecurityCodeField/type.d.ts +1 -0
  61. package/dist/types/components/CombinedEncryptedField/CombinedEncryptedField.d.ts +4 -0
  62. package/dist/types/components/CombinedEncryptedField/index.d.ts +2 -0
  63. package/dist/types/components/CombinedEncryptedField/type.d.ts +15 -0
  64. package/dist/types/components/EncryptedCard/EncryptedCard.d.ts +4 -0
  65. package/dist/types/components/EncryptedCard/index.d.ts +4 -0
  66. package/dist/types/components/EncryptedCard/output.d.ts +9 -0
  67. package/dist/types/components/EncryptedCard/type.d.ts +85 -0
  68. package/dist/types/components/GooglePay/type.d.ts +17 -6
  69. package/dist/types/components/GooglePay/utils.d.ts +2 -0
  70. package/dist/types/components/SecuredFieldsProvider/type.d.ts +103 -22
  71. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +6 -2
  72. package/dist/types/components/Sepa/type.d.ts +0 -2
  73. package/dist/types/components/WechatPay/type.d.ts +0 -2
  74. package/dist/types/components/index.d.ts +2 -0
  75. package/dist/types/components/internal/Form/FormItem.d.ts +1 -1
  76. package/dist/types/components/internal/Form/type.d.ts +7 -0
  77. package/dist/types/components/internal/Input/Input.d.ts +1 -1
  78. package/dist/types/components/internal/Input/type.d.ts +6 -0
  79. package/dist/types/config.d.ts +7 -3
  80. package/dist/types/constant.d.ts +1 -0
  81. package/dist/types/core/PayKKaCheckout.d.ts +12 -0
  82. package/dist/types/core/index.d.ts +1 -0
  83. package/dist/types/core/query.d.ts +2 -2
  84. package/dist/types/hooks/usePayState.d.ts +4 -20
  85. package/dist/types/index.d.ts +2 -2
  86. package/dist/types/out/fraud-detection.d.ts +9 -0
  87. package/dist/types/types/{radar.d.ts → fraud-detection.d.ts} +3 -2
  88. package/dist/types/types/index.d.ts +69 -1
  89. package/dist/types/utils/card-brand/brands.d.ts +3 -10
  90. package/dist/types/utils/card-brand/index.d.ts +10 -9
  91. package/dist/types/utils/format.d.ts +0 -1
  92. package/dist/types/utils/index.d.ts +3 -0
  93. package/dist/types/utils/load.d.ts +7 -0
  94. package/dist/types/utils/style.d.ts +17 -0
  95. package/package.json +2 -2
  96. package/dist/card-checkout-ui.iife.js +0 -8
  97. package/dist/es/out/radar.js +0 -123
  98. package/dist/types/out/radar.d.ts +0 -14
@@ -0,0 +1,448 @@
1
+ import { setApiUrl, setCDNUrl } from "../../config.js";
2
+ import { CoreContext } from "../../core/context.js";
3
+ import { create } from "../../core/create.js";
4
+ import "../../utils/card-brand/brands.js";
5
+ import { getBrowserInfo } from "../../utils/system-info/get-browser-info.js";
6
+ import { w, F, h, A, y, u } from "../../core.js";
7
+ import { useBEM } from "../../hooks/useBEM.js";
8
+ import { useI18n } from "../../hooks/useI18n.js";
9
+ import { intersection } from "../../utils/index.js";
10
+ import { defaultInputStyleConfig, inputStyleAttrs } from "../../types/index.js";
11
+ import { EFieldType, SecuredFieldsProvider } from "../SecuredFieldsProvider/SecuredFieldsProvider.js";
12
+ import { CardNumberField } from "../CardNumberField/index.js";
13
+ import { CardExpireDateField } from "../CardExpireDateField/index.js";
14
+ import { CardSecurityCodeField } from "../CardSecurityCodeField/index.js";
15
+ import { verifyClientKey } from "../../api/modules/encrypted-card/index.js";
16
+ import { formItemErrorMessageClassName, formItemLabelClassName } from "../internal/Form/type.js";
17
+ import "../internal/Form/context.js";
18
+ import "../internal/Form/FormItem.js";
19
+ import "../internal/Form/Form.js";
20
+ import { CombinedEncryptedField } from "../CombinedEncryptedField/index.js";
21
+ import "../internal/Input/Input.js";
22
+ import { inputWrapperClassName } from "../internal/Input/type.js";
23
+ import { style2String, loadStyle } from "../../utils/style.js";
24
+ import { createPromise } from "../../utils/create-promise.js";
25
+ const ENCRYPTED_CARD_WRAPPER_ID = "encryptedCardWrapper";
26
+ const ENCRYPTED_CARD_ITEM_ATTR = "data-eci";
27
+ var EEncryptedCardType = /* @__PURE__ */ ((EEncryptedCardType2) => {
28
+ EEncryptedCardType2["CARD"] = "card";
29
+ EEncryptedCardType2["CARD_NUMBER"] = "cardNumber";
30
+ EEncryptedCardType2["CVV"] = "securityCode";
31
+ EEncryptedCardType2["EXPIRE_DATE"] = "expiryDate";
32
+ return EEncryptedCardType2;
33
+ })(EEncryptedCardType || {});
34
+ const { bem } = useBEM("encrypted");
35
+ const cvvClassName = bem("cvv");
36
+ const cardNumberClassName = bem("card-number");
37
+ const expireDateClassName = bem("expire-date");
38
+ const combinedEncryptedFieldClassName = bem("combined-encrypted-field");
39
+ const encryptedCardStyleId = "encryptedCardStyle";
40
+ const EncryptedCard = w((props, ref) => {
41
+ const { brands, locale, clientKey, merchantId, sandbox, styles, showLabel = true } = props;
42
+ F(ref, () => ({
43
+ encrypt: () => {
44
+ var _a;
45
+ validatePromise.current = createPromise();
46
+ Object.keys(fieldValidStatusMap.current).forEach((key) => {
47
+ fieldValidStatusMap.current[key] = null;
48
+ });
49
+ (_a = SFPRef.current) == null ? void 0 : _a.validate();
50
+ validatePromise.current.then(() => {
51
+ var _a2;
52
+ console.log("校验通过");
53
+ (_a2 = SFPRef.current) == null ? void 0 : _a2.encryptCard({
54
+ merchantId,
55
+ clientKey
56
+ });
57
+ }).catch(() => {
58
+ console.log("校验失败");
59
+ });
60
+ }
61
+ }));
62
+ const { i18n } = useI18n(locale || getBrowserInfo().language);
63
+ const [single, setSingle] = h(false);
64
+ const [showEncryptedCard, setShowEncryptedCard] = h(false);
65
+ const [isReady, setIsReady] = h(false);
66
+ const [supportedBrands, setSupportedBrands] = h([]);
67
+ const [targetElement, setTargetElement] = h(null);
68
+ const [inputStyle, setInputStyle] = h({});
69
+ const wrapperDomMap = A({
70
+ [EEncryptedCardType.CARD]: null,
71
+ [EEncryptedCardType.CARD_NUMBER]: null,
72
+ [EEncryptedCardType.CVV]: null,
73
+ [EEncryptedCardType.EXPIRE_DATE]: null
74
+ });
75
+ const SFPRef = A(null);
76
+ const combinedEncryptedFieldComp = A(null);
77
+ const cardNumberFieldComp = A(null);
78
+ const cardExpireDateFieldComp = A(null);
79
+ const cardSecurityCodeFieldComp = A(null);
80
+ const combinedEncryptedFieldRef = A(null);
81
+ const cardNumberFieldRef = A(null);
82
+ const cardExpireDateFieldRef = A(null);
83
+ const cardSecurityCodeFieldRef = A(null);
84
+ const fieldRefMap = {
85
+ [EFieldType.CARD_NUMBER]: cardNumberFieldRef,
86
+ [EFieldType.CVV]: cardSecurityCodeFieldRef,
87
+ [EFieldType.EXPIRE_DATE]: cardExpireDateFieldRef
88
+ };
89
+ const processStyles = () => {
90
+ if (!styles) {
91
+ return;
92
+ }
93
+ const { input, label, errorMessage } = styles;
94
+ let inputWrapper = {};
95
+ if (input) {
96
+ inputWrapper = JSON.parse(JSON.stringify(input));
97
+ Reflect.deleteProperty(inputWrapper, "placeholder");
98
+ const inputStyle2 = {
99
+ placeholder: input == null ? void 0 : input.placeholder
100
+ };
101
+ const statusList = Object.keys(inputWrapper);
102
+ statusList.forEach((key) => {
103
+ if (key === "placeholder") {
104
+ return;
105
+ }
106
+ const style = inputWrapper[key];
107
+ if (!style) {
108
+ return;
109
+ }
110
+ inputStyleAttrs.forEach((attr) => {
111
+ if (!inputStyle2[key]) {
112
+ inputStyle2[key] = {};
113
+ }
114
+ if (style[attr]) {
115
+ inputStyle2[key][attr] = style[attr];
116
+ Reflect.deleteProperty(style, attr);
117
+ }
118
+ });
119
+ });
120
+ setInputStyle(inputStyle2);
121
+ }
122
+ if (!document.querySelector(`style#${encryptedCardStyleId}`)) {
123
+ const style = [];
124
+ const parentId = ENCRYPTED_CARD_WRAPPER_ID;
125
+ const inputWrapperStyle = `#${parentId} .${inputWrapperClassName} { ${style2String(
126
+ inputWrapper.base
127
+ )} }`;
128
+ const inputWrapperFocusStyle = `#${parentId} .${inputWrapperClassName}--focus { ${style2String(
129
+ inputWrapper.focus
130
+ )} }`;
131
+ const inputWrapperValidStyle = `#${parentId} .${inputWrapperClassName}--success { ${style2String(
132
+ inputWrapper.valid
133
+ )} }`;
134
+ const inputWrapperInvalidStyle = `#${parentId} .${inputWrapperClassName}--error { ${style2String(
135
+ inputWrapper.invalid
136
+ )} }`;
137
+ const labelClassName = formItemLabelClassName;
138
+ const labelStyle = `#${parentId} .${labelClassName} { ${style2String(label == null ? void 0 : label.base)} }`;
139
+ const labelFocusStyle = `#${parentId} .${labelClassName}--focus { ${style2String(
140
+ label == null ? void 0 : label.focus
141
+ )} }`;
142
+ const labelValidStyle = `#${parentId} .${labelClassName}--success { ${style2String(
143
+ label == null ? void 0 : label.valid
144
+ )} }`;
145
+ const labelInvalidStyle = `#${parentId} .${labelClassName}--error { ${style2String(
146
+ label == null ? void 0 : label.invalid
147
+ )} }`;
148
+ const errorMessageStyle = `#${parentId} .${formItemErrorMessageClassName} { ${style2String(
149
+ errorMessage
150
+ )} }`;
151
+ style.push(
152
+ ...[
153
+ inputWrapperStyle,
154
+ inputWrapperFocusStyle,
155
+ inputWrapperValidStyle,
156
+ inputWrapperInvalidStyle,
157
+ labelStyle,
158
+ labelFocusStyle,
159
+ labelValidStyle,
160
+ labelInvalidStyle,
161
+ errorMessageStyle
162
+ ]
163
+ );
164
+ loadStyle(style.join("\n"));
165
+ }
166
+ };
167
+ const classNameMap = {
168
+ [EFieldType.CARD_NUMBER]: cardNumberClassName,
169
+ [EFieldType.CVV]: cvvClassName,
170
+ [EFieldType.EXPIRE_DATE]: expireDateClassName
171
+ };
172
+ const updateFieldStyles = (fieldType, type) => {
173
+ var _a, _b;
174
+ const className = single ? combinedEncryptedFieldClassName : classNameMap[fieldType];
175
+ const parent = document.querySelector(`#${ENCRYPTED_CARD_WRAPPER_ID}`);
176
+ if (!parent) {
177
+ return;
178
+ }
179
+ const inputWrapper = (_a = parent.querySelector(`.${className}`)) == null ? void 0 : _a.querySelector(`.${inputWrapperClassName}`);
180
+ const label = (_b = parent.querySelector(`.${className}`)) == null ? void 0 : _b.querySelector(`.${formItemLabelClassName}`);
181
+ if (type === "focus") {
182
+ inputWrapper == null ? void 0 : inputWrapper.classList.add(`${inputWrapperClassName}--focus`);
183
+ label == null ? void 0 : label.classList.add(`.${formItemLabelClassName}--focus`);
184
+ } else if (type === "blur") {
185
+ inputWrapper == null ? void 0 : inputWrapper.classList.remove(`${inputWrapperClassName}--focus`);
186
+ label == null ? void 0 : label.classList.remove(`.${formItemLabelClassName}--focus`);
187
+ } else if (type === "valid") {
188
+ inputWrapper == null ? void 0 : inputWrapper.classList.add(`${inputWrapperClassName}--success`);
189
+ label == null ? void 0 : label.classList.add(`.${formItemLabelClassName}--success`);
190
+ } else if (type === "invalid") {
191
+ inputWrapper == null ? void 0 : inputWrapper.classList.add(`${inputWrapperClassName}--error`);
192
+ label == null ? void 0 : label.classList.add(`.${formItemLabelClassName}--error`);
193
+ } else {
194
+ inputWrapper == null ? void 0 : inputWrapper.classList.remove(`${inputWrapperClassName}--success`);
195
+ inputWrapper == null ? void 0 : inputWrapper.classList.remove(`${inputWrapperClassName}--error`);
196
+ label == null ? void 0 : label.classList.remove(`.${formItemLabelClassName}--success`);
197
+ label == null ? void 0 : label.classList.remove(`.${formItemLabelClassName}--error`);
198
+ }
199
+ };
200
+ y(() => {
201
+ initEncryptedCard();
202
+ }, []);
203
+ const authorize = async () => {
204
+ if (!clientKey) {
205
+ throw new Error("clientKey is required");
206
+ }
207
+ return verifyClientKey(clientKey, merchantId);
208
+ };
209
+ const getBrands = (realBrands) => {
210
+ if (!(brands == null ? void 0 : brands.length)) {
211
+ return realBrands;
212
+ }
213
+ const bothBrands = intersection(brands, realBrands || []);
214
+ if (!bothBrands.length) {
215
+ throw new Error("No available card brands");
216
+ }
217
+ return bothBrands;
218
+ };
219
+ const initEncryptedCard = async () => {
220
+ var _a, _b;
221
+ if (sandbox) {
222
+ setApiUrl("https://checkout-sandbox.aq.paykka.com");
223
+ setCDNUrl("https://checkout-sandbox.aq.paykka.com/cp");
224
+ }
225
+ let authRes = await authorize();
226
+ if (authRes) {
227
+ const supportedBrands2 = getBrands(authRes.brands);
228
+ setSupportedBrands(supportedBrands2);
229
+ (_a = props.onReady) == null ? void 0 : _a.call(props, true, { brands: supportedBrands2 });
230
+ } else {
231
+ (_b = props.onReady) == null ? void 0 : _b.call(props, false);
232
+ return;
233
+ }
234
+ const encryptedCardWrapper = document.getElementById(ENCRYPTED_CARD_WRAPPER_ID);
235
+ setTargetElement(encryptedCardWrapper);
236
+ if (!encryptedCardWrapper) {
237
+ return;
238
+ }
239
+ const getEncryptedCardItems = (attr) => {
240
+ return encryptedCardWrapper.querySelector(
241
+ `[${ENCRYPTED_CARD_ITEM_ATTR}="${attr}"]`
242
+ );
243
+ };
244
+ const cardElement = getEncryptedCardItems(EEncryptedCardType.CARD);
245
+ if (cardElement) {
246
+ setSingle(true);
247
+ setShowEncryptedCard(true);
248
+ wrapperDomMap.current[EEncryptedCardType.CARD] = cardElement;
249
+ } else {
250
+ const cardNumberElement = getEncryptedCardItems(EEncryptedCardType.CARD_NUMBER);
251
+ const cvvElement = getEncryptedCardItems(EEncryptedCardType.CVV);
252
+ const expireDateElement = getEncryptedCardItems(EEncryptedCardType.EXPIRE_DATE);
253
+ if (cardNumberElement && cvvElement && expireDateElement) {
254
+ setSingle(false);
255
+ setShowEncryptedCard(true);
256
+ wrapperDomMap.current[EEncryptedCardType.CARD_NUMBER] = cardNumberElement;
257
+ wrapperDomMap.current[EEncryptedCardType.CVV] = cvvElement;
258
+ wrapperDomMap.current[EEncryptedCardType.EXPIRE_DATE] = expireDateElement;
259
+ }
260
+ }
261
+ processStyles();
262
+ };
263
+ y(() => {
264
+ showEncryptedCard && embedEncryptedCard();
265
+ }, [showEncryptedCard]);
266
+ const embedEncryptedCard = () => {
267
+ if (single) {
268
+ const cardWrapper = wrapperDomMap.current[EEncryptedCardType.CARD];
269
+ const combinedEncryptedField = create(CombinedEncryptedField, {
270
+ supportedCardBrands: supportedBrands,
271
+ security: true,
272
+ className: combinedEncryptedFieldClassName
273
+ });
274
+ combinedEncryptedFieldComp.current = combinedEncryptedField;
275
+ combinedEncryptedFieldRef.current = combinedEncryptedField.ref;
276
+ combinedEncryptedField.mount(cardWrapper);
277
+ } else {
278
+ const cardNumberWrapper = wrapperDomMap.current[EEncryptedCardType.CARD_NUMBER];
279
+ const cardNumberField = create(CardNumberField, {
280
+ supportedCardBrands: supportedBrands,
281
+ security: true,
282
+ showLabel,
283
+ className: cardNumberClassName
284
+ });
285
+ cardNumberFieldComp.current = cardNumberField;
286
+ cardNumberFieldRef.current = cardNumberField.ref;
287
+ cardNumberField.mount(cardNumberWrapper);
288
+ const cvvWrapper = wrapperDomMap.current[EEncryptedCardType.CVV];
289
+ const cvvField = create(CardSecurityCodeField, {
290
+ security: true,
291
+ showLabel,
292
+ className: cvvClassName
293
+ });
294
+ cardSecurityCodeFieldComp.current = cvvField;
295
+ cardSecurityCodeFieldRef.current = cvvField.ref;
296
+ cvvField.mount(cvvWrapper);
297
+ const expireDateWrapper = wrapperDomMap.current[EEncryptedCardType.EXPIRE_DATE];
298
+ const expireDateField = create(CardExpireDateField, {
299
+ security: true,
300
+ showLabel,
301
+ className: expireDateClassName
302
+ });
303
+ cardExpireDateFieldComp.current = expireDateField;
304
+ cardExpireDateFieldRef.current = expireDateField.ref;
305
+ expireDateField.mount(expireDateWrapper);
306
+ }
307
+ setIsReady(true);
308
+ };
309
+ const onFieldsFocus = (data) => {
310
+ var _a, _b, _c, _d;
311
+ const fieldRef = single ? combinedEncryptedFieldRef : fieldRefMap[data.fieldType];
312
+ if (data.focus) {
313
+ (_a = fieldRef.current) == null ? void 0 : _a.focus();
314
+ (_b = props.onFocus) == null ? void 0 : _b.call(props, data.fieldType);
315
+ updateFieldStyles(data.fieldType, "focus");
316
+ } else {
317
+ (_c = fieldRef.current) == null ? void 0 : _c.blur();
318
+ (_d = props.onBlur) == null ? void 0 : _d.call(props, data.fieldType);
319
+ updateFieldStyles(data.fieldType, "blur");
320
+ }
321
+ };
322
+ const onBinValueChanged = (data) => {
323
+ var _a, _b;
324
+ const field = single ? combinedEncryptedFieldRef : cardNumberFieldRef;
325
+ (_a = field.current) == null ? void 0 : _a.binValueChanged(data.binValue);
326
+ (_b = props.onBinChanged) == null ? void 0 : _b.call(props, {
327
+ binValue: data.binValue,
328
+ brand: data.brand
329
+ });
330
+ };
331
+ const onAuthorized = (data) => {
332
+ var _a;
333
+ (_a = props.onReady) == null ? void 0 : _a.call(props, data.success);
334
+ };
335
+ const validatePromise = A(createPromise());
336
+ const validateOrder = [EFieldType.CARD_NUMBER, EFieldType.EXPIRE_DATE, EFieldType.CVV];
337
+ const fieldValidStatusMap = A({
338
+ [EFieldType.CARD_NUMBER]: null,
339
+ [EFieldType.EXPIRE_DATE]: null,
340
+ [EFieldType.CVV]: null
341
+ });
342
+ const onValidated = (data) => {
343
+ fieldValidStatusMap.current[data.fieldType].status = data.status;
344
+ const results = Object.values(fieldValidStatusMap.current);
345
+ if (results.includes(null)) {
346
+ return;
347
+ } else {
348
+ const validateResult = results.every((result) => result.status === "success");
349
+ if (validateResult) {
350
+ validatePromise.current.resolve(true);
351
+ } else {
352
+ validatePromise.current.reject(false);
353
+ }
354
+ }
355
+ };
356
+ const onFieldValidStatusChanged = (data) => {
357
+ var _a, _b, _c, _d, _e;
358
+ const fieldRef = single ? combinedEncryptedFieldRef : fieldRefMap[data.fieldType];
359
+ const error = data.errorTip && i18n.get(data.errorTip);
360
+ (_a = props.onValidationChanged) == null ? void 0 : _a.call(props, {
361
+ fieldType: data.fieldType,
362
+ status: data.status
363
+ });
364
+ fieldValidStatusMap.current[data.fieldType] = {
365
+ status: data.status,
366
+ errorTip: error
367
+ };
368
+ if (single) {
369
+ for (const key of validateOrder) {
370
+ const currResult = fieldValidStatusMap.current[key];
371
+ if ((currResult == null ? void 0 : currResult.status) === "error") {
372
+ (_b = fieldRef.current) == null ? void 0 : _b.resetValidation(currResult.status, currResult.errorTip);
373
+ return;
374
+ }
375
+ }
376
+ const isSuccess = Object.values(fieldValidStatusMap.current).every(
377
+ (result) => (result == null ? void 0 : result.status) === "success"
378
+ );
379
+ if (isSuccess) {
380
+ (_c = fieldRef.current) == null ? void 0 : _c.resetValidation("success");
381
+ } else {
382
+ (_d = fieldRef.current) == null ? void 0 : _d.resetValidation("unValidate");
383
+ }
384
+ } else {
385
+ (_e = fieldRef.current) == null ? void 0 : _e.resetValidation(data.status, error);
386
+ const type = data.status === "success" ? "valid" : data.status === "error" ? "invalid" : "base";
387
+ updateFieldStyles(data.fieldType, type);
388
+ }
389
+ };
390
+ const onFrameActivated = (data) => {
391
+ var _a;
392
+ (_a = props.onActivated) == null ? void 0 : _a.call(props, data.fieldType);
393
+ };
394
+ const onCardEncrypted = (data) => {
395
+ var _a;
396
+ (_a = props.onCardEncrypted) == null ? void 0 : _a.call(props, data.encryptedInfo);
397
+ };
398
+ const onCardEncryptionFailed = () => {
399
+ var _a;
400
+ (_a = props.onCardEncryptionFailed) == null ? void 0 : _a.call(props);
401
+ };
402
+ const onBrand = (data) => {
403
+ var _a, _b;
404
+ const field = single ? combinedEncryptedFieldRef : cardNumberFieldRef;
405
+ (_a = field.current) == null ? void 0 : _a.brandChanged(data.brand);
406
+ (_b = props.onBrand) == null ? void 0 : _b.call(props, data.brand);
407
+ };
408
+ return /* @__PURE__ */ u(CoreContext.Provider, { value: { i18n }, children: isReady && i18n.ready.value && /* @__PURE__ */ u(
409
+ SecuredFieldsProvider,
410
+ {
411
+ ref: SFPRef,
412
+ targetElement,
413
+ i18n,
414
+ style: inputStyle || defaultInputStyleConfig,
415
+ supportedCardBrands: supportedBrands,
416
+ onFocus: onFieldsFocus,
417
+ onBinValue: onBinValueChanged,
418
+ onBrand,
419
+ onAuthorized,
420
+ onValidStatusChanged: onFieldValidStatusChanged,
421
+ onActivated: onFrameActivated,
422
+ onCardEncrypted,
423
+ onCardEncryptionFailed,
424
+ onValidated
425
+ }
426
+ ) });
427
+ });
428
+ class PayKKaEncryptedCard {
429
+ constructor() {
430
+ }
431
+ static init(props) {
432
+ const container = document.querySelector("body");
433
+ const encryptedCard = create(EncryptedCard, props);
434
+ encryptedCard.mount(container);
435
+ return encryptedCard.ref;
436
+ }
437
+ static setEnv(env) {
438
+ setApiUrl(env.apiUrl);
439
+ setCDNUrl(env.cdnUrl);
440
+ }
441
+ }
442
+ export {
443
+ EEncryptedCardType,
444
+ ENCRYPTED_CARD_ITEM_ATTR,
445
+ ENCRYPTED_CARD_WRAPPER_ID,
446
+ EncryptedCard,
447
+ PayKKaEncryptedCard
448
+ };
@@ -1,5 +1,6 @@
1
1
  import { w, F, h, q, y, A, u, b } from "../../core.js";
2
2
  import { isTimeoutError } from "../../api/http.js";
3
+ import { PaymentMethod } from "../../constant.js";
3
4
  import { getBrowserParams } from "../../api/modules/get-browser-params.js";
4
5
  import { getGooglePayInfo, googlePay } from "../../api/modules/google-pay/index.js";
5
6
  import { useBEM } from "../../hooks/useBEM.js";
@@ -12,6 +13,7 @@ import "../../i18n/locales/index.js";
12
13
  import { usePayState } from "../../hooks/usePayState.js";
13
14
  import { useRetry } from "../../hooks/useRetry.js";
14
15
  import { Info } from "../internal/Info/Info.js";
16
+ import { loadScript } from "../../utils/load.js";
15
17
  function createGooglePay(checkout, pay, onClick, onCanUse) {
16
18
  const {
17
19
  transAmount,
@@ -157,14 +159,28 @@ function createGooglePay(checkout, pay, onClick, onCanUse) {
157
159
  onGooglePayLoaded
158
160
  };
159
161
  }
162
+ const loadGooglePayJS = (onload, onerror) => {
163
+ var _a;
164
+ if ((_a = window.google) == null ? void 0 : _a.payments) {
165
+ return;
166
+ }
167
+ loadScript({
168
+ src: "https://pay.google.com/gp/p/js/pay.js",
169
+ onload,
170
+ onerror,
171
+ extraOptions: {
172
+ async: true
173
+ }
174
+ });
175
+ };
160
176
  const { bem } = useBEM("google-pay");
161
177
  const GooglePay = w((props, ref) => {
162
178
  F(ref, () => ({
163
179
  checkThreeDS
164
180
  }));
165
- const { sessionId, clientKey } = props;
166
- const { sessionReady, session, i18n, payKKaRadar } = usePayState(props);
181
+ const { sessionReady, session, i18n, fraudDetection } = usePayState();
167
182
  const [errorMsg, setErrorMsg] = h("");
183
+ const [showGooglePay, setShowGooglePay] = h(false);
168
184
  const onTimeout = q(
169
185
  (message) => {
170
186
  var _a;
@@ -173,12 +189,32 @@ const GooglePay = w((props, ref) => {
173
189
  },
174
190
  [i18n, props.onTimeout]
175
191
  );
192
+ const getPaymentSuccessData = () => ({
193
+ returnUrl: session == null ? void 0 : session.checkout.returnUrl
194
+ });
176
195
  y(() => {
177
196
  var _a;
178
- if (sessionReady) {
179
- if ((session == null ? void 0 : session.checkout.status) === "SUCCESS") {
180
- (_a = props.onSuccess) == null ? void 0 : _a.call(props);
197
+ if (!sessionReady) {
198
+ return;
199
+ }
200
+ const { status, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
201
+ if (!paymentMethod.includes(PaymentMethod.GOOGLE_PAY)) {
202
+ return;
203
+ }
204
+ loadGooglePayJS(
205
+ () => {
206
+ var _a2;
207
+ setShowGooglePay(true);
208
+ (_a2 = props.onLoad) == null ? void 0 : _a2.call(props, true);
209
+ },
210
+ () => {
211
+ var _a2;
212
+ setShowGooglePay(false);
213
+ (_a2 = props.onLoad) == null ? void 0 : _a2.call(props, false);
181
214
  }
215
+ );
216
+ if (status === "SUCCESS") {
217
+ (_a = props.onSuccess) == null ? void 0 : _a.call(props, getPaymentSuccessData());
182
218
  }
183
219
  }, [sessionReady]);
184
220
  const { start: startReFetchPayInfo } = useRetry(
@@ -192,20 +228,22 @@ const GooglePay = w((props, ref) => {
192
228
  async function pay(token, billAddress, search = false, timeout) {
193
229
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
194
230
  setErrorMsg("");
195
- (_a = props.onSubmit) == null ? void 0 : _a.call(props);
231
+ if (!search) {
232
+ (_a = props.onSubmit) == null ? void 0 : _a.call(props);
233
+ }
196
234
  try {
197
235
  const res = await (search ? getGooglePayInfo(
198
236
  {
199
- sessionId,
200
- clientKey
237
+ sessionId: session.sessionId,
238
+ clientKey: session.clientKey
201
239
  },
202
240
  { locale: i18n.locale, timeout }
203
241
  ) : async function() {
204
242
  const phone = extractAreaCodeAndPhoneNumber(billAddress == null ? void 0 : billAddress.phoneNumber);
205
243
  return googlePay(
206
244
  {
207
- sessionId,
208
- clientKey,
245
+ sessionId: session.sessionId,
246
+ clientKey: session.clientKey,
209
247
  token: token ?? "",
210
248
  bill: {
211
249
  firstName: billAddress == null ? void 0 : billAddress.name,
@@ -220,7 +258,7 @@ const GooglePay = w((props, ref) => {
220
258
  areaCode: phone == null ? void 0 : phone.areaCode
221
259
  },
222
260
  browser: await getBrowserParams({
223
- radarId: payKKaRadar == null ? void 0 : payKKaRadar.radarId
261
+ fraudDetectionId: fraudDetection == null ? void 0 : fraudDetection.fraudDetectionID
224
262
  })
225
263
  },
226
264
  { locale: i18n.locale }
@@ -229,7 +267,7 @@ const GooglePay = w((props, ref) => {
229
267
  const { status, orderStatus, errorMessage, threeDSUrl } = res;
230
268
  if (status === "PROCESSING") {
231
269
  if (orderStatus === "SUCCESS") {
232
- (_b = props.onSuccess) == null ? void 0 : _b.call(props);
270
+ (_b = props.onSuccess) == null ? void 0 : _b.call(props, getPaymentSuccessData());
233
271
  return {
234
272
  end: true,
235
273
  res: { transactionState: "SUCCESS" }
@@ -279,7 +317,7 @@ const GooglePay = w((props, ref) => {
279
317
  };
280
318
  }
281
319
  } else if (status === "SUCCESS") {
282
- (_g = props.onSuccess) == null ? void 0 : _g.call(props);
320
+ (_g = props.onSuccess) == null ? void 0 : _g.call(props, getPaymentSuccessData());
283
321
  return {
284
322
  end: true,
285
323
  res: { transactionState: "SUCCESS" }
@@ -291,7 +329,7 @@ const GooglePay = w((props, ref) => {
291
329
  res: { transactionState: "SUCCESS" }
292
330
  };
293
331
  }
294
- (_i = props.onSuccess) == null ? void 0 : _i.call(props);
332
+ (_i = props.onSuccess) == null ? void 0 : _i.call(props, getPaymentSuccessData());
295
333
  return {
296
334
  end: false,
297
335
  res: { transactionState: "SUCCESS" }
@@ -371,7 +409,7 @@ const GooglePay = w((props, ref) => {
371
409
  stopReFetchCardPay3DSInfo();
372
410
  return { end: true };
373
411
  } else if (status === "SUCCESS") {
374
- (_b = props.onSuccess) == null ? void 0 : _b.call(props);
412
+ (_b = props.onSuccess) == null ? void 0 : _b.call(props, getPaymentSuccessData());
375
413
  stopReFetchCardPay3DSInfo();
376
414
  return { end: true };
377
415
  } else if (status === "EXPIRED") {
@@ -379,7 +417,7 @@ const GooglePay = w((props, ref) => {
379
417
  stopReFetchCardPay3DSInfo();
380
418
  return { end: true };
381
419
  }
382
- (_d = props.onSuccess) == null ? void 0 : _d.call(props);
420
+ (_d = props.onSuccess) == null ? void 0 : _d.call(props, getPaymentSuccessData());
383
421
  stopReFetchCardPay3DSInfo();
384
422
  return { end: true };
385
423
  } catch (error) {
@@ -400,7 +438,7 @@ const GooglePay = w((props, ref) => {
400
438
  }
401
439
  const containRef = A(null);
402
440
  y(() => {
403
- if (containRef && (session == null ? void 0 : session.checkout)) {
441
+ if (containRef && (session == null ? void 0 : session.checkout) && showGooglePay) {
404
442
  const { onGooglePayLoaded } = createGooglePay(
405
443
  session == null ? void 0 : session.checkout,
406
444
  pay,
@@ -409,11 +447,11 @@ const GooglePay = w((props, ref) => {
409
447
  );
410
448
  onGooglePayLoaded(containRef.current);
411
449
  }
412
- }, [sessionReady, containRef, i18n.ready.value]);
450
+ }, [sessionReady, containRef, i18n.ready.value, showGooglePay]);
413
451
  const Button = () => {
414
452
  return /* @__PURE__ */ u("div", { style: "width: 100%; height: 44px", children: /* @__PURE__ */ u("div", { id: "container", style: "width:100%; height: 44px", ref: containRef }) });
415
453
  };
416
- return /* @__PURE__ */ u("div", { children: sessionReady && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
454
+ return /* @__PURE__ */ u("div", { children: sessionReady && showGooglePay && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
417
455
  !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
418
456
  Button()
419
457
  ] }) });