@paykka/card-checkout-ui 0.6.0 → 0.8.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 (177) hide show
  1. package/dist/card-checkout-ui.js +19 -19
  2. package/dist/card-checkout-ui.umd.cjs +19 -19
  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 +31 -3
  6. package/dist/es/api/modules/index.js +0 -2
  7. package/dist/es/components/AccountNameField/index.js +0 -3
  8. package/dist/es/components/AddressField/index.js +2 -7
  9. package/dist/es/components/AliPay/index.js +45 -34
  10. package/dist/es/components/ApplePay/index.js +19 -13
  11. package/dist/es/components/Card/index.js +334 -155
  12. package/dist/es/components/CardBrands/index.js +0 -2
  13. package/dist/es/components/CardExpireDateField/index.js +1 -4
  14. package/dist/es/components/CardHolderNameField/index.js +3 -5
  15. package/dist/es/components/CardIBANField/index.js +0 -3
  16. package/dist/es/components/CardNo/index.js +0 -2
  17. package/dist/es/components/CardNumberField/index.js +1 -4
  18. package/dist/es/components/CardSecurityCodeField/index.js +1 -4
  19. package/dist/es/components/CardSelector/index.js +0 -3
  20. package/dist/es/components/CombinedCardInfo/index.js +99 -0
  21. package/dist/es/components/DropIn/index.js +210 -0
  22. package/dist/es/components/EmailField/EmailField.js +0 -3
  23. package/dist/es/components/EncryptedCard/index.js +35 -75
  24. package/dist/es/components/GooglePay/index.js +69 -28
  25. package/dist/es/components/RecurringTip/index.js +0 -2
  26. package/dist/es/components/SecuredFieldsProvider/index.js +230 -1
  27. package/dist/es/components/SecuredIframe/index.js +3 -1
  28. package/dist/es/components/Sepa/index.js +26 -30
  29. package/dist/es/components/SubmitButton/index.js +0 -2
  30. package/dist/es/components/ThreeDS/index.js +94 -0
  31. package/dist/es/components/WechatPay/index.js +48 -38
  32. package/dist/es/components/index.js +2 -3
  33. package/dist/es/components/internal/Button/Button.js +0 -2
  34. package/dist/es/components/internal/Button/index.js +0 -2
  35. package/dist/es/components/internal/CheckBox/CheckBox.js +0 -2
  36. package/dist/es/components/internal/CheckBox/index.js +0 -2
  37. package/dist/es/components/internal/Form/type.js +0 -2
  38. package/dist/es/components/internal/Info/Info.js +0 -2
  39. package/dist/es/components/internal/Info/index.js +0 -2
  40. package/dist/es/components/internal/Input/Input.js +2 -2
  41. package/dist/es/components/internal/Input/type.js +0 -2
  42. package/dist/es/components/internal/LoadingCheck/LoadingCheck.js +0 -2
  43. package/dist/es/components/internal/LoadingCheck/index.js +0 -2
  44. package/dist/es/components/internal/Modal/Modal.js +40 -0
  45. package/dist/es/components/internal/Modal/modal2.js +1 -0
  46. package/dist/es/components/internal/Select/Select.js +0 -2
  47. package/dist/es/components/internal/Select/SelectMenu.js +0 -2
  48. package/dist/es/components/internal/Select/SelectMenuItem.js +0 -2
  49. package/dist/es/components/internal/icons/Icon3DSFail.js +3 -0
  50. package/dist/es/components/internal/icons/Icon3DSInfo.js +62 -0
  51. package/dist/es/components/internal/icons/Icon3DSSuccess.js +3 -0
  52. package/dist/es/components/internal/icons/IconCard.js +42 -0
  53. package/dist/es/config.js +0 -2
  54. package/dist/es/constant.js +13 -2
  55. package/dist/es/core/PayKKaCheckout.js +106 -42
  56. package/dist/es/core/Session.js +7 -6
  57. package/dist/es/core/environment.js +26 -0
  58. package/dist/es/core/error.js +21 -0
  59. package/dist/es/core/index.js +0 -2
  60. package/dist/es/core/query.js +0 -2
  61. package/dist/es/core.js +34 -34
  62. package/dist/es/hooks/index.js +0 -2
  63. package/dist/es/hooks/useBreakpoints.js +57 -0
  64. package/dist/es/hooks/useI18n.js +1 -2
  65. package/dist/es/hooks/usePayState.js +20 -24
  66. package/dist/es/i18n/index.js +0 -2
  67. package/dist/es/i18n/locales/de-DE.js +14 -1
  68. package/dist/es/i18n/locales/en-GB.js +14 -1
  69. package/dist/es/i18n/locales/es-ES.js +14 -1
  70. package/dist/es/i18n/locales/fr-FR.js +14 -1
  71. package/dist/es/i18n/locales/index.js +8 -6
  72. package/dist/es/i18n/locales/ja-JP.js +14 -1
  73. package/dist/es/i18n/locales/ko-KR.js +14 -1
  74. package/dist/es/i18n/locales/pt-PT.js +14 -1
  75. package/dist/es/i18n/locales/ru-RU.js +14 -1
  76. package/dist/es/i18n/locales/zh-CN.js +14 -1
  77. package/dist/es/i18n/locales/zh-HK.js +14 -1
  78. package/dist/es/i18n/locales/zh-TW.js +14 -1
  79. package/dist/es/i18n/util.js +22 -8
  80. package/dist/es/index.js +8 -2
  81. package/dist/es/style.css +289 -11
  82. package/dist/es/types/message.js +28 -0
  83. package/dist/es/utils/card-brand/brands.js +12 -10
  84. package/dist/es/utils/card-brand/index.js +3 -2
  85. package/dist/es/utils/iframe.js +23 -0
  86. package/dist/es/utils/index.js +0 -1
  87. package/dist/es/utils/style.js +47 -0
  88. package/dist/style.css +1 -1
  89. package/dist/types/api/modules/checkout/map.d.ts +2 -1
  90. package/dist/types/api/modules/checkout/type.d.ts +24 -2
  91. package/dist/types/api/modules/get-browser-params.d.ts +1 -1
  92. package/dist/types/components/AddressField/type.d.ts +1 -0
  93. package/dist/types/components/AliPay/AliPay.d.ts +2 -1
  94. package/dist/types/components/AliPay/type.d.ts +2 -1
  95. package/dist/types/components/ApplePay/ApplePay.d.ts +2 -1
  96. package/dist/types/components/ApplePay/type.d.ts +9 -5
  97. package/dist/types/components/Card/Card.d.ts +2 -1
  98. package/dist/types/components/Card/type.d.ts +55 -9
  99. package/dist/types/components/CardHolderNameField/type.d.ts +1 -1
  100. package/dist/types/components/CombinedCardInfo/CombinedCardInfo.d.ts +5 -0
  101. package/dist/types/components/CombinedCardInfo/index.d.ts +2 -0
  102. package/dist/types/components/{CombinedEncryptedField → CombinedCardInfo}/type.d.ts +3 -2
  103. package/dist/types/components/DropIn/DropIn.d.ts +6 -0
  104. package/dist/types/components/DropIn/components/PaymentTabs/PaymentTabs.d.ts +3 -0
  105. package/dist/types/components/DropIn/components/PaymentTabs/index.d.ts +2 -0
  106. package/dist/types/components/DropIn/components/PaymentTabs/type.d.ts +11 -0
  107. package/dist/types/components/DropIn/index.d.ts +2 -0
  108. package/dist/types/components/DropIn/type.d.ts +49 -0
  109. package/dist/types/components/GooglePay/GooglePay.d.ts +2 -1
  110. package/dist/types/components/GooglePay/type.d.ts +20 -8
  111. package/dist/types/components/SecuredFieldsProvider/index.d.ts +1 -0
  112. package/dist/types/components/SecuredFieldsProvider/type.d.ts +1 -153
  113. package/dist/types/components/SecuredFieldsProvider/utils/index.d.ts +1 -1
  114. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +2 -1
  115. package/dist/types/components/Sepa/Sepa.d.ts +2 -1
  116. package/dist/types/components/Sepa/type.d.ts +2 -1
  117. package/dist/types/components/ThreeDS/components/ThreeDSAuth/ThreeDSAuth.d.ts +3 -0
  118. package/dist/types/components/ThreeDS/components/ThreeDSAuth/index.d.ts +2 -0
  119. package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +17 -0
  120. package/dist/types/components/ThreeDS/components/ThreeDSIframe/ThreeDSIframe.d.ts +2 -0
  121. package/dist/types/components/ThreeDS/components/ThreeDSIframe/index.d.ts +1 -0
  122. package/dist/types/components/ThreeDS/components/ThreeDSIframe/output.d.ts +1 -0
  123. package/dist/types/components/ThreeDS/components/ThreeDSIframe/type.d.ts +5 -0
  124. package/dist/types/components/ThreeDS/components/ThreeDSStatus/ThreeDSStatus.d.ts +3 -0
  125. package/dist/types/components/ThreeDS/components/ThreeDSStatus/output.d.ts +1 -0
  126. package/dist/types/components/ThreeDS/components/ThreeDSStatus/type.d.ts +6 -0
  127. package/dist/types/components/ThreeDS/index.d.ts +1 -0
  128. package/dist/types/components/WechatPay/WechatPay.d.ts +2 -1
  129. package/dist/types/components/WechatPay/type.d.ts +2 -1
  130. package/dist/types/components/index.d.ts +2 -1
  131. package/dist/types/components/internal/Input/type.d.ts +1 -0
  132. package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
  133. package/dist/types/components/internal/Loading/index.d.ts +1 -0
  134. package/dist/types/components/internal/Modal/Modal.d.ts +5 -0
  135. package/dist/types/components/internal/Modal/index.d.ts +2 -0
  136. package/dist/types/components/internal/Modal/type.d.ts +20 -0
  137. package/dist/types/components/internal/icons/Icon3DSFail.d.ts +2 -0
  138. package/dist/types/components/internal/icons/Icon3DSInfo.d.ts +2 -0
  139. package/dist/types/components/internal/icons/Icon3DSSuccess.d.ts +2 -0
  140. package/dist/types/components/internal/icons/IconCard.d.ts +2 -0
  141. package/dist/types/components/internal/icons/index.d.ts +4 -0
  142. package/dist/types/constant.d.ts +17 -2
  143. package/dist/types/core/PayKKaCheckout.d.ts +23 -6
  144. package/dist/types/core/Session.d.ts +1 -1
  145. package/dist/types/core/context.d.ts +1 -0
  146. package/dist/types/core/environment.d.ts +4 -0
  147. package/dist/types/core/error.d.ts +16 -0
  148. package/dist/types/core/index.d.ts +1 -0
  149. package/dist/types/hooks/index.d.ts +1 -0
  150. package/dist/types/hooks/useBreakpoints.d.ts +15 -0
  151. package/dist/types/hooks/usePayState.d.ts +3 -6
  152. package/dist/types/i18n/locales/de-DE.d.ts +10 -0
  153. package/dist/types/i18n/locales/en-GB.d.ts +10 -0
  154. package/dist/types/i18n/locales/es-ES.d.ts +10 -0
  155. package/dist/types/i18n/locales/fr-FR.d.ts +10 -0
  156. package/dist/types/i18n/locales/index.d.ts +2 -2
  157. package/dist/types/i18n/locales/ja-JP.d.ts +10 -0
  158. package/dist/types/i18n/locales/ko-KR.d.ts +10 -0
  159. package/dist/types/i18n/locales/pt-PT.d.ts +10 -0
  160. package/dist/types/i18n/locales/ru-RU.d.ts +10 -0
  161. package/dist/types/i18n/locales/zh-CN.d.ts +10 -0
  162. package/dist/types/i18n/locales/zh-HK.d.ts +10 -0
  163. package/dist/types/i18n/locales/zh-TW.d.ts +10 -0
  164. package/dist/types/i18n/util.d.ts +5 -0
  165. package/dist/types/index.d.ts +1 -1
  166. package/dist/types/types/index.d.ts +59 -8
  167. package/dist/types/types/message.d.ts +170 -0
  168. package/dist/types/utils/card-brand/brands.d.ts +1 -8
  169. package/dist/types/utils/card-brand/index.d.ts +2 -2
  170. package/dist/types/utils/index.d.ts +1 -0
  171. package/dist/types/utils/style.d.ts +12 -0
  172. package/package.json +2 -2
  173. package/dist/es/components/CombinedEncryptedField/index.js +0 -75
  174. package/dist/es/components/SecuredFieldsProvider/SecuredFieldsProvider.js +0 -268
  175. package/dist/types/components/CombinedEncryptedField/CombinedEncryptedField.d.ts +0 -4
  176. package/dist/types/components/CombinedEncryptedField/index.d.ts +0 -2
  177. /package/dist/types/{components/SecuredFieldsProvider/utils → utils}/iframe.d.ts +0 -0
@@ -1,6 +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
+ import { SessionMode, PaymentMethod } from "../../constant.js";
4
4
  import { getBrowserParams } from "../../api/modules/get-browser-params.js";
5
5
  import { getGooglePayInfo, googlePay } from "../../api/modules/google-pay/index.js";
6
6
  import { useBEM } from "../../hooks/useBEM.js";
@@ -8,12 +8,12 @@ import "../../core/context.js";
8
8
  import "../../utils/card-brand/brands.js";
9
9
  import "../../utils/system-info/get-browser-info.js";
10
10
  import { extractAreaCodeAndPhoneNumber } from "../../utils/format.js";
11
- import "../../i18n/util.js";
12
- import "../../i18n/locales/index.js";
11
+ import { PayKKaError } from "../../core/error.js";
13
12
  import { usePayState } from "../../hooks/usePayState.js";
14
13
  import { useRetry } from "../../hooks/useRetry.js";
15
14
  import { Info } from "../internal/Info/Info.js";
16
15
  import { loadScript } from "../../utils/load.js";
16
+ import { ThreeDSAuth } from "../ThreeDS/index.js";
17
17
  function createGooglePay(checkout, pay, onClick, onCanUse) {
18
18
  const {
19
19
  transAmount,
@@ -175,17 +175,22 @@ const loadGooglePayJS = (onload, onerror) => {
175
175
  };
176
176
  const { bem } = useBEM("google-pay");
177
177
  const GooglePay = w((props, ref) => {
178
+ var _a;
179
+ const { session, threeDSFrame, isDropIn } = props;
178
180
  F(ref, () => ({
179
181
  checkThreeDS
180
182
  }));
181
- const { sessionReady, session, i18n, fraudDetection } = usePayState();
183
+ const { sessionReady, i18n, fraudDetection } = usePayState(session);
182
184
  const [errorMsg, setErrorMsg] = h("");
183
185
  const [showGooglePay, setShowGooglePay] = h(false);
186
+ const [showThreeDSModal, setShowThreeDSModal] = h(false);
187
+ const [threeDSInfo, setThreeDSInfo] = h();
188
+ const [hosted, setHosted] = h(true);
184
189
  const onTimeout = q(
185
190
  (message) => {
186
- var _a;
191
+ var _a2;
187
192
  setErrorMsg(message || i18n.get("common.payTimeout"));
188
- (_a = props.onTimeout) == null ? void 0 : _a.call(props, "retry");
193
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
189
194
  },
190
195
  [i18n, props.onTimeout]
191
196
  );
@@ -193,30 +198,57 @@ const GooglePay = w((props, ref) => {
193
198
  returnUrl: session == null ? void 0 : session.checkout.returnUrl
194
199
  });
195
200
  y(() => {
196
- var _a;
201
+ var _a2, _b, _c;
197
202
  if (!sessionReady) {
198
203
  return;
199
204
  }
200
- const { status, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
205
+ const { status, paymentMethod = [], sessionMode } = (session == null ? void 0 : session.checkout) || {};
206
+ if (sessionMode === SessionMode.DROP_IN && !isDropIn) {
207
+ (_b = (_a2 = props.core.config).onInitError) == null ? void 0 : _b.call(
208
+ _a2,
209
+ new PayKKaError("ERROR", "Please send the correct mode when creating the checkout")
210
+ );
211
+ return;
212
+ }
201
213
  if (!paymentMethod.includes(PaymentMethod.GOOGLE_PAY)) {
202
214
  return;
203
215
  }
204
216
  loadGooglePayJS(
205
217
  () => {
206
- var _a2;
218
+ var _a3;
207
219
  setShowGooglePay(true);
208
- (_a2 = props.onLoad) == null ? void 0 : _a2.call(props, true);
220
+ (_a3 = props.onLoad) == null ? void 0 : _a3.call(props, true);
209
221
  },
210
222
  () => {
211
- var _a2;
223
+ var _a3;
212
224
  setShowGooglePay(false);
213
- (_a2 = props.onLoad) == null ? void 0 : _a2.call(props, false);
225
+ (_a3 = props.onLoad) == null ? void 0 : _a3.call(props, false);
214
226
  }
215
227
  );
228
+ setHosted(sessionMode === SessionMode.HOSTED);
216
229
  if (status === "SUCCESS") {
217
- (_a = props.onSuccess) == null ? void 0 : _a.call(props, getPaymentSuccessData());
230
+ (_c = props.onSuccess) == null ? void 0 : _c.call(props, getPaymentSuccessData());
218
231
  }
219
232
  }, [sessionReady]);
233
+ const processThreeDS = (threeDSUrl, incomplete) => {
234
+ var _a2;
235
+ if (hosted) {
236
+ (_a2 = props.onThreeDS) == null ? void 0 : _a2.call(props, threeDSUrl, incomplete);
237
+ } else {
238
+ setShowThreeDSModal(true);
239
+ setThreeDSInfo({
240
+ url: threeDSUrl,
241
+ incomplete,
242
+ width: threeDSFrame == null ? void 0 : threeDSFrame.modalWidth,
243
+ height: threeDSFrame == null ? void 0 : threeDSFrame.modalHeight
244
+ });
245
+ }
246
+ };
247
+ const handleCloseThreeDSModal = () => {
248
+ setShowThreeDSModal(false);
249
+ setThreeDSInfo(void 0);
250
+ checkThreeDS();
251
+ };
220
252
  const { start: startReFetchPayInfo } = useRetry(
221
253
  async (timeout) => {
222
254
  return await pay(void 0, void 0, true, timeout);
@@ -226,10 +258,10 @@ const GooglePay = w((props, ref) => {
226
258
  }
227
259
  );
228
260
  async function pay(token, billAddress, search = false, timeout) {
229
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
261
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
230
262
  setErrorMsg("");
231
263
  if (!search) {
232
- (_a = props.onSubmit) == null ? void 0 : _a.call(props);
264
+ (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props);
233
265
  }
234
266
  try {
235
267
  const res = await (search ? getGooglePayInfo(
@@ -264,7 +296,7 @@ const GooglePay = w((props, ref) => {
264
296
  { locale: i18n.locale }
265
297
  );
266
298
  }());
267
- const { status, orderStatus, errorMessage, threeDSUrl } = res;
299
+ const { status, orderStatus, errorMessage, threeDSUrl, errorCode } = res;
268
300
  if (status === "PROCESSING") {
269
301
  if (orderStatus === "SUCCESS") {
270
302
  (_b = props.onSuccess) == null ? void 0 : _b.call(props, getPaymentSuccessData());
@@ -280,7 +312,7 @@ const GooglePay = w((props, ref) => {
280
312
  } : await startReFetchPayInfo();
281
313
  } else if (orderStatus === "FAILURE") {
282
314
  setErrorMsg(errorMessage);
283
- (_c = props.onError) == null ? void 0 : _c.call(props, "FAILURE");
315
+ (_c = props.onError) == null ? void 0 : _c.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
284
316
  return {
285
317
  end: true,
286
318
  res: {
@@ -299,13 +331,13 @@ const GooglePay = w((props, ref) => {
299
331
  res: { transactionState: "SUCCESS" }
300
332
  };
301
333
  } else if (orderStatus === "IN_THREED") {
302
- (_e = props.onThreeDS) == null ? void 0 : _e.call(props, threeDSUrl, false);
334
+ processThreeDS(threeDSUrl, false);
303
335
  return {
304
336
  end: true,
305
337
  res: { transactionState: "SUCCESS" }
306
338
  };
307
339
  } else if (orderStatus === "IN_PREVIOUS_THREED") {
308
- (_f = props.onThreeDS) == null ? void 0 : _f.call(props, threeDSUrl, true);
340
+ processThreeDS(threeDSUrl, true);
309
341
  return {
310
342
  end: true,
311
343
  res: { transactionState: "SUCCESS" }
@@ -317,19 +349,19 @@ const GooglePay = w((props, ref) => {
317
349
  };
318
350
  }
319
351
  } else if (status === "SUCCESS") {
320
- (_g = props.onSuccess) == null ? void 0 : _g.call(props, getPaymentSuccessData());
352
+ (_e = props.onSuccess) == null ? void 0 : _e.call(props, getPaymentSuccessData());
321
353
  return {
322
354
  end: true,
323
355
  res: { transactionState: "SUCCESS" }
324
356
  };
325
357
  } else if (status === "EXPIRED") {
326
- (_h = props.onExpired) == null ? void 0 : _h.call(props);
358
+ (_f = props.onExpired) == null ? void 0 : _f.call(props);
327
359
  return {
328
360
  end: true,
329
361
  res: { transactionState: "SUCCESS" }
330
362
  };
331
363
  }
332
- (_i = props.onSuccess) == null ? void 0 : _i.call(props, getPaymentSuccessData());
364
+ (_g = props.onSuccess) == null ? void 0 : _g.call(props, getPaymentSuccessData());
333
365
  return {
334
366
  end: false,
335
367
  res: { transactionState: "SUCCESS" }
@@ -354,8 +386,8 @@ const GooglePay = w((props, ref) => {
354
386
  }
355
387
  } else {
356
388
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
357
- setErrorMsg(error.i18nKey ? i18n.get(error.i18nKey) : error.message);
358
- (_j = props.onError) == null ? void 0 : _j.call(props, error);
389
+ setErrorMsg(message);
390
+ (_h = props.onError) == null ? void 0 : _h.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
359
391
  return {
360
392
  end: true,
361
393
  res: {
@@ -378,7 +410,7 @@ const GooglePay = w((props, ref) => {
378
410
  }
379
411
  );
380
412
  async function checkThreeDS(search = false) {
381
- var _a, _b, _c, _d, _e;
413
+ var _a2, _b, _c, _d, _e;
382
414
  if (!session)
383
415
  return { end: true };
384
416
  try {
@@ -398,7 +430,7 @@ const GooglePay = w((props, ref) => {
398
430
  } else if (orderStatus === "FAILURE") {
399
431
  setErrorMsg(errorMessage);
400
432
  } else if (orderStatus === "AUTHORIZED") {
401
- (_a = props.onAuthorized) == null ? void 0 : _a.call(props);
433
+ (_a2 = props.onAuthorized) == null ? void 0 : _a2.call(props);
402
434
  } else if (orderStatus === "IN_THREED") {
403
435
  !search && startReFetchCardPay3DSInfo();
404
436
  return { end: false };
@@ -431,7 +463,7 @@ const GooglePay = w((props, ref) => {
431
463
  } else {
432
464
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
433
465
  setErrorMsg(message);
434
- (_e = props.onError) == null ? void 0 : _e.call(props, error);
466
+ (_e = props.onError) == null ? void 0 : _e.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
435
467
  return { end: true };
436
468
  }
437
469
  }
@@ -453,7 +485,16 @@ const GooglePay = w((props, ref) => {
453
485
  };
454
486
  return /* @__PURE__ */ u("div", { children: sessionReady && showGooglePay && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
455
487
  !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
456
- Button()
488
+ Button(),
489
+ /* @__PURE__ */ u(
490
+ ThreeDSAuth,
491
+ {
492
+ show: showThreeDSModal,
493
+ theme: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.theme,
494
+ ...threeDSInfo,
495
+ onClose: handleCloseThreeDSModal
496
+ }
497
+ )
457
498
  ] }) });
458
499
  });
459
500
  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
  };
@@ -1,11 +1,13 @@
1
1
  import { A, h, y, u, b } from "../../core.js";
2
2
  import { clamp, isExpired, safeParse } from "../../utils/index.js";
3
- import { EFieldType, MessageAction, postMessageToIframe } from "../SecuredFieldsProvider/SecuredFieldsProvider.js";
3
+ import { EFieldType } from "../SecuredFieldsProvider/index.js";
4
4
  import { getSupportedCardBrands, getSupportedCardBrandsLengths, findCardBrand } from "../../utils/card-brand/index.js";
5
5
  import { limitedToNumber, trimAll } from "../../utils/format.js";
6
6
  import { isUndefined, isNil } from "../../utils/is.js";
7
7
  import { cdnOrigin, setApiUrl, setCDNUrl } from "../../config.js";
8
+ import { MessageAction } from "../../types/message.js";
8
9
  import { generateClassNameMap, style2String, createPlaceholderStyle, loadStyle } from "../../utils/style.js";
10
+ import { postMessageToIframe } from "../../utils/iframe.js";
9
11
  import { isTimeoutError } from "../../api/http.js";
10
12
  import { cardPay } from "../../api/modules/card/index.js";
11
13
  import { encryptCard } from "../../api/modules/encrypted-card/index.js";
@@ -2,7 +2,7 @@ import { w, A, h, F, y, q, u } from "../../core.js";
2
2
  import { createAddressCore } from "../../core/Address.js";
3
3
  import { useBEM } from "../../hooks/useBEM.js";
4
4
  import { CoreContext } from "../../core/context.js";
5
- import { isEmptyObject, isUndefined } from "../../utils/is.js";
5
+ import { isUndefined } from "../../utils/is.js";
6
6
  import "../../utils/card-brand/brands.js";
7
7
  import "../../utils/system-info/get-browser-info.js";
8
8
  import { cssVarPrefix, normalizedClass, formatAmount, trimAll } from "../../utils/format.js";
@@ -10,8 +10,7 @@ import { isTimeoutError } from "../../api/http.js";
10
10
  import { COMMON_CLASS_NAME } from "../../constant.js";
11
11
  import { getBrowserParams } from "../../api/modules/get-browser-params.js";
12
12
  import { getSepaPayInfo, sepaPay } from "../../api/modules/sepa/index.js";
13
- import "../../i18n/util.js";
14
- import "../../i18n/locales/index.js";
13
+ import { PayKKaError } from "../../core/error.js";
15
14
  import { usePayState } from "../../hooks/usePayState.js";
16
15
  import { useRetry } from "../../hooks/useRetry.js";
17
16
  import { AddressField } from "../AddressField/index.js";
@@ -27,10 +26,11 @@ import { AccountNameField } from "../AccountNameField/index.js";
27
26
  const { bem } = useBEM("sepa");
28
27
  const fieldClassNames = bem("field");
29
28
  const Sepa = w((props, ref) => {
30
- var _a, _b, _c, _d, _e, _f;
29
+ var _a, _b, _c, _d, _e, _f, _g, _h;
30
+ const { session } = props;
31
31
  let addressState = createAddressCore();
32
32
  let emailState = createEmailCore();
33
- const { i18n, session, sessionReady } = usePayState();
33
+ const { i18n, sessionReady } = usePayState(session);
34
34
  const addressFieldRef = A(null);
35
35
  const emailFieldRef = A(null);
36
36
  const formRef = A(null);
@@ -76,31 +76,25 @@ 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 ?? {};
94
+ let amountStr = "";
101
95
  if (amount && !isUndefined(digits))
102
- amount = formatAmount(+amount, digits);
103
- const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amount}` : "");
96
+ amountStr = formatAmount(+amount, digits);
97
+ const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amountStr}` : "");
104
98
  return /* @__PURE__ */ u(
105
99
  SubmitButton,
106
100
  {
@@ -196,8 +190,9 @@ const Sepa = w((props, ref) => {
196
190
  return { end: true };
197
191
  }
198
192
  } else {
199
- setErrorMsg(error.i18nKey ? i18n.get(error.i18nKey) : error.message);
200
- (_a2 = props.onError) == null ? void 0 : _a2.call(props, error);
193
+ const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
194
+ setErrorMsg(message);
195
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
201
196
  setSubmitButtonStatus("unSubmit");
202
197
  return { end: true };
203
198
  }
@@ -205,7 +200,7 @@ const Sepa = w((props, ref) => {
205
200
  }
206
201
  const processAfterPayment = (res, search = false) => {
207
202
  var _a2, _b2, _c2;
208
- const { status, orderStatus, errorMessage } = res;
203
+ const { status, orderStatus, errorMessage, errorCode } = res;
209
204
  if (status === "PROCESSING") {
210
205
  if (!orderStatus) {
211
206
  setSubmitButtonStatus("unSubmit");
@@ -222,7 +217,7 @@ const Sepa = w((props, ref) => {
222
217
  } else if (orderStatus === "FAILURE") {
223
218
  setErrorMsg(errorMessage);
224
219
  setSubmitButtonStatus("unSubmit");
225
- (_a2 = props.onError) == null ? void 0 : _a2.call(props, "FAILURE");
220
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
226
221
  } else if (orderStatus === "AUTHORIZED") {
227
222
  setSubmitButtonStatus("unSubmit");
228
223
  (_b2 = props.onAuthorized) == null ? void 0 : _b2.call(props);
@@ -268,6 +263,7 @@ const Sepa = w((props, ref) => {
268
263
  {
269
264
  ref: addressFieldRef,
270
265
  value: form.address,
266
+ country: ((_g = session == null ? void 0 : session.checkout) == null ? void 0 : _g.country) || ((_h = session == null ? void 0 : session.checkout) == null ? void 0 : _h.bill.country),
271
267
  onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
272
268
  }
273
269
  ) }),
@@ -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";