@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,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, SessionMode } 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";
@@ -7,11 +8,12 @@ import "../../core/context.js";
7
8
  import "../../utils/card-brand/brands.js";
8
9
  import "../../utils/system-info/get-browser-info.js";
9
10
  import { extractAreaCodeAndPhoneNumber } from "../../utils/format.js";
10
- import "../../i18n/util.js";
11
- import "../../i18n/locales/index.js";
11
+ import { PayKKaError } from "../../core/error.js";
12
12
  import { usePayState } from "../../hooks/usePayState.js";
13
13
  import { useRetry } from "../../hooks/useRetry.js";
14
14
  import { Info } from "../internal/Info/Info.js";
15
+ import { loadScript } from "../../utils/load.js";
16
+ import { ThreeDSAuth } from "../ThreeDS/index.js";
15
17
  function createGooglePay(checkout, pay, onClick, onCanUse) {
16
18
  const {
17
19
  transAmount,
@@ -157,30 +159,89 @@ 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) => {
178
+ var _a;
179
+ const { session, threeDSFrame } = props;
162
180
  F(ref, () => ({
163
181
  checkThreeDS
164
182
  }));
165
- const { sessionId, clientKey } = props;
166
- const { sessionReady, session, i18n, payKKaRadar } = usePayState(props);
183
+ const { sessionReady, i18n, fraudDetection } = usePayState(session);
167
184
  const [errorMsg, setErrorMsg] = h("");
185
+ const [showGooglePay, setShowGooglePay] = h(false);
186
+ const [showThreeDSModal, setShowThreeDSModal] = h(false);
187
+ const [threeDSInfo, setThreeDSInfo] = h();
188
+ const [hosted, setHosted] = h(true);
168
189
  const onTimeout = q(
169
190
  (message) => {
170
- var _a;
191
+ var _a2;
171
192
  setErrorMsg(message || i18n.get("common.payTimeout"));
172
- (_a = props.onTimeout) == null ? void 0 : _a.call(props, "retry");
193
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
173
194
  },
174
195
  [i18n, props.onTimeout]
175
196
  );
197
+ const getPaymentSuccessData = () => ({
198
+ returnUrl: session == null ? void 0 : session.checkout.returnUrl
199
+ });
176
200
  y(() => {
177
- 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);
201
+ var _a2;
202
+ if (!sessionReady) {
203
+ return;
204
+ }
205
+ const { status, paymentMethod = [], sessionMode } = (session == null ? void 0 : session.checkout) || {};
206
+ if (!paymentMethod.includes(PaymentMethod.GOOGLE_PAY)) {
207
+ return;
208
+ }
209
+ loadGooglePayJS(
210
+ () => {
211
+ var _a3;
212
+ setShowGooglePay(true);
213
+ (_a3 = props.onLoad) == null ? void 0 : _a3.call(props, true);
214
+ },
215
+ () => {
216
+ var _a3;
217
+ setShowGooglePay(false);
218
+ (_a3 = props.onLoad) == null ? void 0 : _a3.call(props, false);
181
219
  }
220
+ );
221
+ setHosted(sessionMode === SessionMode.HOSTED);
222
+ if (status === "SUCCESS") {
223
+ (_a2 = props.onSuccess) == null ? void 0 : _a2.call(props, getPaymentSuccessData());
182
224
  }
183
225
  }, [sessionReady]);
226
+ const processThreeDS = (threeDSUrl, incomplete) => {
227
+ var _a2;
228
+ if (hosted) {
229
+ (_a2 = props.onThreeDS) == null ? void 0 : _a2.call(props, threeDSUrl, incomplete);
230
+ } else {
231
+ setShowThreeDSModal(true);
232
+ setThreeDSInfo({
233
+ url: threeDSUrl,
234
+ incomplete,
235
+ width: threeDSFrame == null ? void 0 : threeDSFrame.modalWidth,
236
+ height: threeDSFrame == null ? void 0 : threeDSFrame.modalHeight
237
+ });
238
+ }
239
+ };
240
+ const handleCloseThreeDSModal = () => {
241
+ setShowThreeDSModal(false);
242
+ setThreeDSInfo(void 0);
243
+ checkThreeDS();
244
+ };
184
245
  const { start: startReFetchPayInfo } = useRetry(
185
246
  async (timeout) => {
186
247
  return await pay(void 0, void 0, true, timeout);
@@ -190,22 +251,24 @@ const GooglePay = w((props, ref) => {
190
251
  }
191
252
  );
192
253
  async function pay(token, billAddress, search = false, timeout) {
193
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
254
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
194
255
  setErrorMsg("");
195
- (_a = props.onSubmit) == null ? void 0 : _a.call(props);
256
+ if (!search) {
257
+ (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props);
258
+ }
196
259
  try {
197
260
  const res = await (search ? getGooglePayInfo(
198
261
  {
199
- sessionId,
200
- clientKey
262
+ sessionId: session.sessionId,
263
+ clientKey: session.clientKey
201
264
  },
202
265
  { locale: i18n.locale, timeout }
203
266
  ) : async function() {
204
267
  const phone = extractAreaCodeAndPhoneNumber(billAddress == null ? void 0 : billAddress.phoneNumber);
205
268
  return googlePay(
206
269
  {
207
- sessionId,
208
- clientKey,
270
+ sessionId: session.sessionId,
271
+ clientKey: session.clientKey,
209
272
  token: token ?? "",
210
273
  bill: {
211
274
  firstName: billAddress == null ? void 0 : billAddress.name,
@@ -220,16 +283,16 @@ const GooglePay = w((props, ref) => {
220
283
  areaCode: phone == null ? void 0 : phone.areaCode
221
284
  },
222
285
  browser: await getBrowserParams({
223
- radarId: payKKaRadar == null ? void 0 : payKKaRadar.radarId
286
+ fraudDetectionId: fraudDetection == null ? void 0 : fraudDetection.fraudDetectionID
224
287
  })
225
288
  },
226
289
  { locale: i18n.locale }
227
290
  );
228
291
  }());
229
- const { status, orderStatus, errorMessage, threeDSUrl } = res;
292
+ const { status, orderStatus, errorMessage, threeDSUrl, errorCode } = res;
230
293
  if (status === "PROCESSING") {
231
294
  if (orderStatus === "SUCCESS") {
232
- (_b = props.onSuccess) == null ? void 0 : _b.call(props);
295
+ (_b = props.onSuccess) == null ? void 0 : _b.call(props, getPaymentSuccessData());
233
296
  return {
234
297
  end: true,
235
298
  res: { transactionState: "SUCCESS" }
@@ -242,7 +305,7 @@ const GooglePay = w((props, ref) => {
242
305
  } : await startReFetchPayInfo();
243
306
  } else if (orderStatus === "FAILURE") {
244
307
  setErrorMsg(errorMessage);
245
- (_c = props.onError) == null ? void 0 : _c.call(props, "FAILURE");
308
+ (_c = props.onError) == null ? void 0 : _c.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
246
309
  return {
247
310
  end: true,
248
311
  res: {
@@ -261,13 +324,13 @@ const GooglePay = w((props, ref) => {
261
324
  res: { transactionState: "SUCCESS" }
262
325
  };
263
326
  } else if (orderStatus === "IN_THREED") {
264
- (_e = props.onThreeDS) == null ? void 0 : _e.call(props, threeDSUrl, false);
327
+ processThreeDS(threeDSUrl, false);
265
328
  return {
266
329
  end: true,
267
330
  res: { transactionState: "SUCCESS" }
268
331
  };
269
332
  } else if (orderStatus === "IN_PREVIOUS_THREED") {
270
- (_f = props.onThreeDS) == null ? void 0 : _f.call(props, threeDSUrl, true);
333
+ processThreeDS(threeDSUrl, true);
271
334
  return {
272
335
  end: true,
273
336
  res: { transactionState: "SUCCESS" }
@@ -279,19 +342,19 @@ const GooglePay = w((props, ref) => {
279
342
  };
280
343
  }
281
344
  } else if (status === "SUCCESS") {
282
- (_g = props.onSuccess) == null ? void 0 : _g.call(props);
345
+ (_e = props.onSuccess) == null ? void 0 : _e.call(props, getPaymentSuccessData());
283
346
  return {
284
347
  end: true,
285
348
  res: { transactionState: "SUCCESS" }
286
349
  };
287
350
  } else if (status === "EXPIRED") {
288
- (_h = props.onExpired) == null ? void 0 : _h.call(props);
351
+ (_f = props.onExpired) == null ? void 0 : _f.call(props);
289
352
  return {
290
353
  end: true,
291
354
  res: { transactionState: "SUCCESS" }
292
355
  };
293
356
  }
294
- (_i = props.onSuccess) == null ? void 0 : _i.call(props);
357
+ (_g = props.onSuccess) == null ? void 0 : _g.call(props, getPaymentSuccessData());
295
358
  return {
296
359
  end: false,
297
360
  res: { transactionState: "SUCCESS" }
@@ -316,8 +379,8 @@ const GooglePay = w((props, ref) => {
316
379
  }
317
380
  } else {
318
381
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
319
- setErrorMsg(error.i18nKey ? i18n.get(error.i18nKey) : error.message);
320
- (_j = props.onError) == null ? void 0 : _j.call(props, error);
382
+ setErrorMsg(message);
383
+ (_h = props.onError) == null ? void 0 : _h.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
321
384
  return {
322
385
  end: true,
323
386
  res: {
@@ -340,7 +403,7 @@ const GooglePay = w((props, ref) => {
340
403
  }
341
404
  );
342
405
  async function checkThreeDS(search = false) {
343
- var _a, _b, _c, _d, _e;
406
+ var _a2, _b, _c, _d, _e;
344
407
  if (!session)
345
408
  return { end: true };
346
409
  try {
@@ -360,7 +423,7 @@ const GooglePay = w((props, ref) => {
360
423
  } else if (orderStatus === "FAILURE") {
361
424
  setErrorMsg(errorMessage);
362
425
  } else if (orderStatus === "AUTHORIZED") {
363
- (_a = props.onAuthorized) == null ? void 0 : _a.call(props);
426
+ (_a2 = props.onAuthorized) == null ? void 0 : _a2.call(props);
364
427
  } else if (orderStatus === "IN_THREED") {
365
428
  !search && startReFetchCardPay3DSInfo();
366
429
  return { end: false };
@@ -371,7 +434,7 @@ const GooglePay = w((props, ref) => {
371
434
  stopReFetchCardPay3DSInfo();
372
435
  return { end: true };
373
436
  } else if (status === "SUCCESS") {
374
- (_b = props.onSuccess) == null ? void 0 : _b.call(props);
437
+ (_b = props.onSuccess) == null ? void 0 : _b.call(props, getPaymentSuccessData());
375
438
  stopReFetchCardPay3DSInfo();
376
439
  return { end: true };
377
440
  } else if (status === "EXPIRED") {
@@ -379,7 +442,7 @@ const GooglePay = w((props, ref) => {
379
442
  stopReFetchCardPay3DSInfo();
380
443
  return { end: true };
381
444
  }
382
- (_d = props.onSuccess) == null ? void 0 : _d.call(props);
445
+ (_d = props.onSuccess) == null ? void 0 : _d.call(props, getPaymentSuccessData());
383
446
  stopReFetchCardPay3DSInfo();
384
447
  return { end: true };
385
448
  } catch (error) {
@@ -393,14 +456,14 @@ const GooglePay = w((props, ref) => {
393
456
  } else {
394
457
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
395
458
  setErrorMsg(message);
396
- (_e = props.onError) == null ? void 0 : _e.call(props, error);
459
+ (_e = props.onError) == null ? void 0 : _e.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
397
460
  return { end: true };
398
461
  }
399
462
  }
400
463
  }
401
464
  const containRef = A(null);
402
465
  y(() => {
403
- if (containRef && (session == null ? void 0 : session.checkout)) {
466
+ if (containRef && (session == null ? void 0 : session.checkout) && showGooglePay) {
404
467
  const { onGooglePayLoaded } = createGooglePay(
405
468
  session == null ? void 0 : session.checkout,
406
469
  pay,
@@ -409,13 +472,22 @@ const GooglePay = w((props, ref) => {
409
472
  );
410
473
  onGooglePayLoaded(containRef.current);
411
474
  }
412
- }, [sessionReady, containRef, i18n.ready.value]);
475
+ }, [sessionReady, containRef, i18n.ready.value, showGooglePay]);
413
476
  const Button = () => {
414
477
  return /* @__PURE__ */ u("div", { style: "width: 100%; height: 44px", children: /* @__PURE__ */ u("div", { id: "container", style: "width:100%; height: 44px", ref: containRef }) });
415
478
  };
416
- return /* @__PURE__ */ u("div", { children: sessionReady && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
479
+ return /* @__PURE__ */ u("div", { children: sessionReady && showGooglePay && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
417
480
  !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
418
- Button()
481
+ Button(),
482
+ /* @__PURE__ */ u(
483
+ ThreeDSAuth,
484
+ {
485
+ show: showThreeDSModal,
486
+ theme: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.theme,
487
+ ...threeDSInfo,
488
+ onClose: handleCloseThreeDSModal
489
+ }
490
+ )
419
491
  ] }) });
420
492
  });
421
493
  export {
@@ -2,8 +2,6 @@ import { u } from "../../core.js";
2
2
  import { CoreContext } from "../../core/context.js";
3
3
  import "../../utils/card-brand/brands.js";
4
4
  import "../../utils/system-info/get-browser-info.js";
5
- import "../../i18n/util.js";
6
- import "../../i18n/locales/index.js";
7
5
  import { useBEM } from "../../hooks/useBEM.js";
8
6
  import { IconInfo } from "../internal/icons/IconInfo.js";
9
7
  const { bem } = useBEM("recurring-tip");
@@ -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
  };