@paykka/card-checkout-ui 0.11.6 → 0.13.2

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 (217) 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/_commonjsHelpers.js +82 -1
  4. package/dist/es/api/index.js +1 -0
  5. package/dist/es/api/modules/address/index.js +9 -9
  6. package/dist/es/api/modules/ali-pay/index.js +10 -49
  7. package/dist/es/api/modules/apple-pay/index.js +13 -59
  8. package/dist/es/api/modules/boost/index.js +8 -48
  9. package/dist/es/api/modules/card/index.js +10 -54
  10. package/dist/es/api/modules/checkout/index.js +11 -9
  11. package/dist/es/api/modules/checkout/map.js +25 -18
  12. package/dist/es/api/modules/encrypted-card/index.js +3 -2
  13. package/dist/es/api/modules/gcash/index.js +8 -48
  14. package/dist/es/api/modules/get-browser-params.js +4 -1
  15. package/dist/es/api/modules/google-pay/index.js +10 -56
  16. package/dist/es/api/modules/grab-pay/index.js +8 -48
  17. package/dist/es/api/modules/index.js +1 -0
  18. package/dist/es/api/modules/line-pay/index.js +8 -48
  19. package/dist/es/api/modules/map.js +17 -11
  20. package/dist/es/api/modules/may-bank-qr-pay/index.js +8 -48
  21. package/dist/es/api/modules/nine-pay/index.js +8 -48
  22. package/dist/es/api/modules/paymaya/index.js +8 -48
  23. package/dist/es/api/modules/risk/index.js +2 -1
  24. package/dist/es/api/modules/sepa/index.js +10 -51
  25. package/dist/es/api/modules/shopee-pay/index.js +8 -48
  26. package/dist/es/api/modules/threeDS/index.js +3 -0
  27. package/dist/es/api/modules/tng-wallet/index.js +8 -48
  28. package/dist/es/api/modules/wechat-pay/index.js +10 -51
  29. package/dist/es/api/modules/zalopay/index.js +16 -0
  30. package/dist/es/api/utils/index.js +59 -0
  31. package/dist/es/components/AddressField/index.js +37 -37
  32. package/dist/es/components/AliPay/index.js +158 -111
  33. package/dist/es/components/ApplePay/index.js +99 -67
  34. package/dist/es/components/Boost/index.js +91 -70
  35. package/dist/es/components/Card/index.js +114 -107
  36. package/dist/es/components/CardSelector/index.js +1 -1
  37. package/dist/es/components/DropIn/index.js +12 -4
  38. package/dist/es/components/EncryptedCard/index.js +6 -2
  39. package/dist/es/components/GooglePay/index.js +94 -60
  40. package/dist/es/components/GrabPay/index.js +91 -70
  41. package/dist/es/components/GuideCard/index.js +10 -7
  42. package/dist/es/components/LinePay/index.js +91 -70
  43. package/dist/es/components/MayBankQRPay/index.js +302 -275
  44. package/dist/es/components/NinePay/index.js +91 -70
  45. package/dist/es/components/SecuredFieldsProvider/index.js +26 -9
  46. package/dist/es/components/SecuredIframe/index.js +40 -61
  47. package/dist/es/components/Sepa/index.js +72 -53
  48. package/dist/es/components/ShopeePay/index.js +91 -70
  49. package/dist/es/components/SubmitButton/index.js +8 -7
  50. package/dist/es/components/TNGWallet/index.js +91 -70
  51. package/dist/es/components/ThreeDS/index.js +32 -7
  52. package/dist/es/components/WechatPay/index.js +151 -102
  53. package/dist/es/components/business/QRCodeModal/QRCodeModal.js +26 -6
  54. package/dist/es/components/index.js +1 -0
  55. package/dist/es/components/internal/Form/FormItem.js +1 -1
  56. package/dist/es/components/internal/Form/util.js +1 -1
  57. package/dist/es/components/internal/Modal/Modal.js +1 -1
  58. package/dist/es/components/internal/Select/Select.js +19 -8
  59. package/dist/es/components/internal/Select/SelectMenu.js +2 -2
  60. package/dist/es/components/internal/Select/SelectMenuItem.js +12 -4
  61. package/dist/es/components/internal/icons/IconError.js +7 -4
  62. package/dist/es/components/internal/icons/IconZalopay.js +47 -0
  63. package/dist/es/components/internal/icons/IconZalopayComplete.js +48 -0
  64. package/dist/es/components/wallets/GCash/GCash.js +80 -56
  65. package/dist/es/components/wallets/Paymaya/Paymaya.js +91 -70
  66. package/dist/es/components/wallets/Zalopay/Zalopay.js +381 -0
  67. package/dist/es/components/wallets/Zalopay/index.js +1 -0
  68. package/dist/es/components/wallets/Zalopay/type.js +1 -0
  69. package/dist/es/components/wallets/Zalopay/zalopay2.js +1 -0
  70. package/dist/es/config.js +5 -5
  71. package/dist/es/constant.js +8 -2
  72. package/dist/es/core/{Address.js → address.js} +8 -16
  73. package/dist/es/core/{PayKKaCheckout.js → checkout.js} +101 -27
  74. package/dist/es/core/create.js +1 -1
  75. package/dist/es/core/query.js +3 -2
  76. package/dist/es/core/{Session.js → session.js} +28 -32
  77. package/dist/es/core/theme.js +65 -0
  78. package/dist/es/core.js +0 -4
  79. package/dist/es/hooks/usePayment.js +14 -0
  80. package/dist/es/i18n/locales/de-DE.js +3 -1
  81. package/dist/es/i18n/locales/en-GB.js +3 -1
  82. package/dist/es/i18n/locales/es-ES.js +3 -1
  83. package/dist/es/i18n/locales/fr-FR.js +3 -1
  84. package/dist/es/i18n/locales/ja-JP.js +3 -1
  85. package/dist/es/i18n/locales/ko-KR.js +3 -1
  86. package/dist/es/i18n/locales/nl-NL.js +3 -1
  87. package/dist/es/i18n/locales/pt-PT.js +3 -1
  88. package/dist/es/i18n/locales/ru-RU.js +3 -1
  89. package/dist/es/i18n/locales/zh-CN.js +3 -1
  90. package/dist/es/i18n/locales/zh-HK.js +3 -1
  91. package/dist/es/i18n/locales/zh-TW.js +3 -1
  92. package/dist/es/index.js +21 -7
  93. package/dist/es/style.css +1 -1
  94. package/dist/es/types/index.js +7 -0
  95. package/dist/es/utils/colors.js +5 -1
  96. package/dist/es/utils/format.js +0 -5
  97. package/dist/es/utils/object.js +31 -1
  98. package/dist/es/utils/payment.js +82 -0
  99. package/dist/es/utils/redirect.js +4 -4
  100. package/dist/es/utils/string.js +10 -0
  101. package/dist/es/utils/system-info/is-ua-webview.js +14 -12
  102. package/dist/es/utils/theme.js +7 -0
  103. package/dist/style.css +1 -1
  104. package/dist/types/api/modules/address/index.d.ts +15 -6
  105. package/dist/types/api/modules/ali-pay/index.d.ts +3 -19
  106. package/dist/types/api/modules/apple-pay/index.d.ts +4 -14
  107. package/dist/types/api/modules/boost/index.d.ts +3 -23
  108. package/dist/types/api/modules/card/index.d.ts +3 -30
  109. package/dist/types/api/modules/checkout/index.d.ts +3 -3
  110. package/dist/types/api/modules/checkout/map.d.ts +3 -3
  111. package/dist/types/api/modules/checkout/type.d.ts +33 -4
  112. package/dist/types/api/modules/gcash/index.d.ts +3 -23
  113. package/dist/types/api/modules/get-browser-params.d.ts +1 -0
  114. package/dist/types/api/modules/google-pay/index.d.ts +3 -13
  115. package/dist/types/api/modules/grab-pay/index.d.ts +3 -23
  116. package/dist/types/api/modules/index.d.ts +1 -0
  117. package/dist/types/api/modules/line-pay/index.d.ts +3 -23
  118. package/dist/types/api/modules/map.d.ts +2 -2
  119. package/dist/types/api/modules/may-bank-qr-pay/index.d.ts +3 -23
  120. package/dist/types/api/modules/nine-pay/index.d.ts +3 -23
  121. package/dist/types/api/modules/paymaya/index.d.ts +3 -23
  122. package/dist/types/api/modules/sepa/index.d.ts +3 -24
  123. package/dist/types/api/modules/shopee-pay/index.d.ts +3 -23
  124. package/dist/types/api/modules/tng-wallet/index.d.ts +3 -23
  125. package/dist/types/api/modules/type.d.ts +74 -21
  126. package/dist/types/api/modules/wechat-pay/index.d.ts +3 -20
  127. package/dist/types/api/modules/zalopay/index.d.ts +4 -0
  128. package/dist/types/api/utils/index.d.ts +48 -0
  129. package/dist/types/components/AddressField/type.d.ts +3 -9
  130. package/dist/types/components/AliPay/AliPay.d.ts +6 -2
  131. package/dist/types/components/AliPay/type.d.ts +15 -2
  132. package/dist/types/components/ApplePay/ApplePay.d.ts +6 -2
  133. package/dist/types/components/ApplePay/type.d.ts +10 -14
  134. package/dist/types/components/ApplePay/utils.d.ts +1 -1
  135. package/dist/types/components/Boost/Boost.d.ts +6 -2
  136. package/dist/types/components/Boost/type.d.ts +2 -24
  137. package/dist/types/components/Card/Card.d.ts +6 -2
  138. package/dist/types/components/Card/type.d.ts +3 -43
  139. package/dist/types/components/DropIn/DropIn.d.ts +6 -2
  140. package/dist/types/components/DropIn/type.d.ts +4 -10
  141. package/dist/types/components/GooglePay/GooglePay.d.ts +6 -2
  142. package/dist/types/components/GooglePay/createGooglePay.d.ts +2 -1
  143. package/dist/types/components/GooglePay/type.d.ts +10 -26
  144. package/dist/types/components/GrabPay/GrabPay.d.ts +6 -2
  145. package/dist/types/components/GrabPay/type.d.ts +3 -25
  146. package/dist/types/components/LinePay/LinePay.d.ts +6 -2
  147. package/dist/types/components/LinePay/type.d.ts +3 -25
  148. package/dist/types/components/MayBankQRPay/MayBankQRPay.d.ts +6 -2
  149. package/dist/types/components/MayBankQRPay/type.d.ts +3 -25
  150. package/dist/types/components/NinePay/NinePay.d.ts +6 -2
  151. package/dist/types/components/NinePay/type.d.ts +3 -25
  152. package/dist/types/components/SecuredFieldsProvider/type.d.ts +5 -0
  153. package/dist/types/components/SecuredIframe/HiddenIframe.d.ts +3 -1
  154. package/dist/types/components/Sepa/Sepa.d.ts +6 -2
  155. package/dist/types/components/Sepa/type.d.ts +3 -2
  156. package/dist/types/components/ShopeePay/ShopeePay.d.ts +6 -2
  157. package/dist/types/components/ShopeePay/type.d.ts +3 -25
  158. package/dist/types/components/TNGWallet/TNGWallet.d.ts +6 -2
  159. package/dist/types/components/TNGWallet/type.d.ts +3 -25
  160. package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +2 -0
  161. package/dist/types/components/WechatPay/WechatPay.d.ts +6 -2
  162. package/dist/types/components/WechatPay/type.d.ts +15 -2
  163. package/dist/types/components/business/QRCodeModal/type.d.ts +2 -0
  164. package/dist/types/components/index.d.ts +1 -0
  165. package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
  166. package/dist/types/components/internal/Select/SelectMenu.d.ts +1 -1
  167. package/dist/types/components/internal/icons/IconZalopay.d.ts +2 -0
  168. package/dist/types/components/internal/icons/IconZalopayComplete.d.ts +2 -0
  169. package/dist/types/components/internal/icons/index.d.ts +3 -0
  170. package/dist/types/components/wallets/GCash/GCash.d.ts +6 -2
  171. package/dist/types/components/wallets/GCash/type.d.ts +3 -35
  172. package/dist/types/components/wallets/Paymaya/Paymaya.d.ts +6 -2
  173. package/dist/types/components/wallets/Paymaya/type.d.ts +3 -25
  174. package/dist/types/components/wallets/Zalopay/Zalopay.d.ts +10 -0
  175. package/dist/types/components/wallets/Zalopay/index.d.ts +2 -0
  176. package/dist/types/components/wallets/Zalopay/type.d.ts +39 -0
  177. package/dist/types/config.d.ts +2 -4
  178. package/dist/types/constant.d.ts +3 -1
  179. package/dist/types/core/{Address.d.ts → address.d.ts} +23 -24
  180. package/dist/types/core/{PayKKaCheckout.d.ts → checkout.d.ts} +9 -3
  181. package/dist/types/core/context.d.ts +3 -2
  182. package/dist/types/core/index.d.ts +3 -2
  183. package/dist/types/core/query.d.ts +2 -2
  184. package/dist/types/core/session.d.ts +23 -0
  185. package/dist/types/core/theme.d.ts +7 -0
  186. package/dist/types/hooks/index.d.ts +1 -0
  187. package/dist/types/hooks/usePayment.d.ts +8 -0
  188. package/dist/types/i18n/locales/de-DE.d.ts +2 -0
  189. package/dist/types/i18n/locales/en-GB.d.ts +2 -0
  190. package/dist/types/i18n/locales/es-ES.d.ts +2 -0
  191. package/dist/types/i18n/locales/fr-FR.d.ts +2 -0
  192. package/dist/types/i18n/locales/ja-JP.d.ts +2 -0
  193. package/dist/types/i18n/locales/ko-KR.d.ts +2 -0
  194. package/dist/types/i18n/locales/nl-NL.d.ts +2 -0
  195. package/dist/types/i18n/locales/pt-PT.d.ts +2 -0
  196. package/dist/types/i18n/locales/ru-RU.d.ts +2 -0
  197. package/dist/types/i18n/locales/zh-CN.d.ts +2 -0
  198. package/dist/types/i18n/locales/zh-HK.d.ts +2 -0
  199. package/dist/types/i18n/locales/zh-TW.d.ts +2 -0
  200. package/dist/types/index.d.ts +2 -1
  201. package/dist/types/types/index.d.ts +70 -32
  202. package/dist/types/types/message.d.ts +30 -25
  203. package/dist/types/utils/card-brand/index.d.ts +3 -3
  204. package/dist/types/utils/colors.d.ts +1 -0
  205. package/dist/types/utils/index.d.ts +4 -2
  206. package/dist/types/utils/object.d.ts +7 -0
  207. package/dist/types/utils/payment.d.ts +37 -0
  208. package/dist/types/utils/string.d.ts +1 -0
  209. package/dist/types/utils/style.d.ts +1 -1
  210. package/dist/types/utils/system-info/is-ua-webview.d.ts +1 -1
  211. package/dist/types/utils/theme.d.ts +4 -0
  212. package/package.json +3 -3
  213. package/dist/es/utils/deep-freeze.js +0 -13
  214. package/dist/es/utils/obj.js +0 -22
  215. package/dist/types/core/Session.d.ts +0 -16
  216. package/dist/types/utils/deep-freeze.d.ts +0 -1
  217. package/dist/types/utils/obj.d.ts +0 -6
@@ -4,7 +4,7 @@ import { EFieldType } from "../SecuredFieldsProvider/index.js";
4
4
  import { getSupportedCardBrands, getSupportedCardBrandsLengths, findCardBrand } from "../../utils/card-brand/index.js";
5
5
  import { limitedToNumber, trimAll } from "../../utils/format.js";
6
6
  import { isUndefined, isNil } from "../../utils/is.js";
7
- import { cdnOrigin, setApiUrl, setCDNUrl } from "../../config.js";
7
+ import { cdnOrigin, setApiUrl, setCDNUrl, setApiPrefix } from "../../config.js";
8
8
  import { MessageAction } from "../../types/message.js";
9
9
  import { generateClassNameMap, style2String, createPlaceholderStyle, loadStyle } from "../../utils/style.js";
10
10
  import { postMessageToIframe } from "../../utils/iframe.js";
@@ -192,6 +192,7 @@ const useSecuredInput = () => {
192
192
  };
193
193
  const inputClassNameMap = generateClassNameMap("input");
194
194
  const FieldIframe = (props) => {
195
+ const { checkoutId } = props;
195
196
  const hiddenIframe = window.parent.frames[props.hiddenIframeName];
196
197
  const inputRef = A(null);
197
198
  const { initSecuredInput, getConfigByFieldType, getCurrCardBrand, cardBin, value, brand } = useSecuredInput();
@@ -277,11 +278,15 @@ const FieldIframe = (props) => {
277
278
  }, []);
278
279
  const onReceiveMessage = (event) => {
279
280
  const { data } = event;
280
- const parsedData = safeParse(data);
281
- if (!Reflect.has(parsedData, "action")) {
281
+ const feedbackData = safeParse(data);
282
+ if (!Reflect.has(feedbackData, "action")) {
282
283
  return;
283
284
  }
284
- if (parsedData.action === MessageAction.VALIDATE) {
285
+ console.log(feedbackData, checkoutId);
286
+ if (feedbackData.checkoutId !== checkoutId) {
287
+ return;
288
+ }
289
+ if (feedbackData.action === MessageAction.VALIDATE) {
285
290
  try {
286
291
  const inputConfig = getConfigByFieldType();
287
292
  inputConfig.validator();
@@ -317,6 +322,7 @@ const FieldIframe = (props) => {
317
322
  var _a;
318
323
  const data = {
319
324
  action: MessageAction.BIN_VALUE,
325
+ checkoutId,
320
326
  binValue,
321
327
  fieldType: props.fieldType,
322
328
  brand: (_a = getCurrCardBrand(binValue)) == null ? void 0 : _a.code
@@ -326,6 +332,7 @@ const FieldIframe = (props) => {
326
332
  const sendBrandMessage = (brand2) => {
327
333
  const data = {
328
334
  action: MessageAction.BRAND,
335
+ checkoutId,
329
336
  brand: brand2,
330
337
  fieldType: props.fieldType
331
338
  };
@@ -334,6 +341,7 @@ const FieldIframe = (props) => {
334
341
  const sendFocusMessage = (focus) => {
335
342
  const data = {
336
343
  action: MessageAction.FOCUS,
344
+ checkoutId,
337
345
  focus,
338
346
  fieldType: props.fieldType
339
347
  };
@@ -357,7 +365,8 @@ const FieldIframe = (props) => {
357
365
  action: MessageAction.VALID_STATUS_CHANGED,
358
366
  status,
359
367
  errorTip: err == null ? void 0 : err.message,
360
- fieldType: props.fieldType
368
+ fieldType: props.fieldType,
369
+ checkoutId
361
370
  };
362
371
  postMessageToIframe(validData, window.parent);
363
372
  if (status !== "success") {
@@ -369,15 +378,16 @@ const FieldIframe = (props) => {
369
378
  const validWithValueData = {
370
379
  action: MessageAction.VALID_WITH_VALUE,
371
380
  value: value.current,
372
- fieldType: props.fieldType
381
+ fieldType: props.fieldType,
382
+ checkoutId
373
383
  };
374
- console.log(hiddenIframe, props.hiddenIframeName);
375
384
  postMessageToIframe(validWithValueData, hiddenIframe, cdnOrigin);
376
385
  };
377
386
  const sendActivatedMessage = () => {
378
387
  const data = {
379
388
  action: MessageAction.ACTIVATED,
380
- fieldType: props.fieldType
389
+ fieldType: props.fieldType,
390
+ checkoutId
381
391
  };
382
392
  postMessageToIframe(data, window.parent);
383
393
  };
@@ -385,6 +395,7 @@ const FieldIframe = (props) => {
385
395
  const data = {
386
396
  action: MessageAction.VALIDATED,
387
397
  fieldType: props.fieldType,
398
+ checkoutId,
388
399
  status
389
400
  };
390
401
  postMessageToIframe(data, window.parent);
@@ -400,7 +411,7 @@ const FieldIframe = (props) => {
400
411
  }
401
412
  );
402
413
  };
403
- const HiddenIframe = () => {
414
+ const HiddenIframe = ({ checkoutId }) => {
404
415
  const formData = {
405
416
  expYear: "",
406
417
  expMonth: "",
@@ -410,59 +421,34 @@ const HiddenIframe = () => {
410
421
  const onReceiveMessage = async (event) => {
411
422
  const { data } = event;
412
423
  const parsedData = safeParse(data);
413
- console.log(parsedData);
414
424
  if (!Reflect.has(parsedData, "action")) {
415
425
  return;
416
426
  }
427
+ console.log(parsedData, checkoutId);
428
+ if (parsedData.checkoutId !== checkoutId) {
429
+ return;
430
+ }
417
431
  if (parsedData.action === MessageAction.VALID_WITH_VALUE) {
418
432
  const feedbackData = parsedData;
419
433
  switch (feedbackData.fieldType) {
420
434
  case EFieldType.CVV: {
421
435
  formData.cvv = feedbackData.value;
422
- setMessageList([
423
- ...messageList,
424
- {
425
- name: "CVV",
426
- label: `收到值:${feedbackData.value}`
427
- }
428
- ]);
429
436
  break;
430
437
  }
431
438
  case EFieldType.CARD_NUMBER: {
432
439
  formData.cardNo = trimAll(feedbackData.value);
433
- setMessageList([
434
- ...messageList,
435
- {
436
- name: "卡号",
437
- label: `收到值:${feedbackData.value}`
438
- }
439
- ]);
440
440
  break;
441
441
  }
442
442
  case EFieldType.EXPIRE_DATE: {
443
443
  const [expMonth, expYear] = feedbackData.value.split("/");
444
444
  formData.expMonth = expMonth;
445
445
  formData.expYear = `20${expYear}`;
446
- setMessageList([
447
- ...messageList,
448
- {
449
- name: "卡有效期",
450
- label: `收到值:${feedbackData.value}`
451
- }
452
- ]);
453
446
  break;
454
447
  }
455
448
  }
456
449
  } else if (parsedData.action === MessageAction.PAYMENT) {
457
450
  const feedbackData = parsedData;
458
451
  pay(feedbackData.formData, feedbackData.locale, feedbackData.extraParams);
459
- setMessageList([
460
- ...messageList,
461
- {
462
- name: "表单组件",
463
- label: `进行支付,${JSON.stringify(formData || {})}`
464
- }
465
- ]);
466
452
  } else if (parsedData.action === MessageAction.ENCRYPT_CARD) {
467
453
  const feedbackData = parsedData;
468
454
  try {
@@ -472,8 +458,6 @@ const HiddenIframe = () => {
472
458
  console.log("error", error);
473
459
  sendCardEncryptionFailedMessage(error);
474
460
  }
475
- } else if (parsedData.action === MessageAction.DEBUG_MODE) {
476
- console.log("hidden iframe 开启测试模式");
477
461
  }
478
462
  };
479
463
  y(() => {
@@ -502,6 +486,7 @@ const HiddenIframe = () => {
502
486
  const sendAfterPaymentMessage = (response) => {
503
487
  const data = {
504
488
  action: MessageAction.AFTER_PAYMENT,
489
+ checkoutId,
505
490
  response
506
491
  };
507
492
  postMessageToIframe(data, window.parent);
@@ -509,6 +494,7 @@ const HiddenIframe = () => {
509
494
  const sendPaymentErrorMessage = (error) => {
510
495
  const data = {
511
496
  action: MessageAction.PAYMENT_ERROR,
497
+ checkoutId,
512
498
  error: {
513
499
  message: error.message,
514
500
  code: error.code
@@ -518,19 +504,22 @@ const HiddenIframe = () => {
518
504
  };
519
505
  const sendPaymentTimeoutMessage = () => {
520
506
  const data = {
521
- action: MessageAction.PAYMENT_TIMEOUT
507
+ action: MessageAction.PAYMENT_TIMEOUT,
508
+ checkoutId
522
509
  };
523
510
  postMessageToIframe(data, window.parent);
524
511
  };
525
512
  const sendHiddenIframeReadyMessage = () => {
526
513
  const data = {
527
- action: MessageAction.HIDDEN_IFRAME_READY
514
+ action: MessageAction.HIDDEN_IFRAME_READY,
515
+ checkoutId
528
516
  };
529
517
  postMessageToIframe(data, window.parent);
530
518
  };
531
519
  const sendCardEncryptedMessage = (encryptedInfo) => {
532
520
  const data = {
533
521
  action: MessageAction.CARD_ENCRYPTED,
522
+ checkoutId,
534
523
  encryptedInfo
535
524
  };
536
525
  postMessageToIframe(data, window.parent);
@@ -538,6 +527,7 @@ const HiddenIframe = () => {
538
527
  const sendCardEncryptionFailedMessage = (error) => {
539
528
  const data = {
540
529
  action: MessageAction.CARD_ENCRYPTION_FAILED,
530
+ checkoutId,
541
531
  error
542
532
  };
543
533
  postMessageToIframe(data, window.parent);
@@ -545,36 +535,22 @@ const HiddenIframe = () => {
545
535
  y(() => {
546
536
  sendHiddenIframeReadyMessage();
547
537
  }, []);
548
- const [messageList, setMessageList] = h([]);
549
- const messageListRef = A(null);
550
- y(() => {
551
- if (messageListRef.current) {
552
- messageListRef.current.scrollTop = messageListRef.current.scrollHeight;
553
- }
554
- }, [messageList]);
555
- return /* @__PURE__ */ u(b, { children: /* @__PURE__ */ u("div", { style: "width: 100%; height: 100%; overflow-y: auto", ref: messageListRef, children: messageList.map((message) => /* @__PURE__ */ u("div", { style: { fontSize: "18px", marginBottom: "4px" }, children: [
556
- /* @__PURE__ */ u("span", { style: { color: "#4f43df" }, children: [
557
- "[",
558
- message.name,
559
- "]"
560
- ] }),
561
- /* @__PURE__ */ u("span", { children: [
562
- ": ",
563
- message.label
564
- ] })
565
- ] })) }) });
538
+ return /* @__PURE__ */ u(b, {});
566
539
  };
567
540
  const SecuredIframe = () => {
568
541
  const [fieldIframeConfig, setFieldIframeConfig] = h();
569
542
  const [hidden, setHidden] = h(false);
570
543
  const [hasInit, setHasInit] = h(false);
544
+ const checkoutId = A("");
571
545
  const onReceiveMessage = (event) => {
572
546
  const { data } = event;
573
547
  const feedbackData = safeParse(data);
574
548
  if (!Reflect.has(feedbackData, "action")) {
575
549
  return;
576
550
  }
551
+ console.log(feedbackData, checkoutId.current);
577
552
  if (feedbackData.action === MessageAction.INIT) {
553
+ checkoutId.current = feedbackData.checkoutId;
578
554
  setHidden(feedbackData.hidden);
579
555
  setFieldIframeConfig(feedbackData.config);
580
556
  if (feedbackData.apiUrl) {
@@ -583,13 +559,16 @@ const SecuredIframe = () => {
583
559
  if (feedbackData.cdnUrl) {
584
560
  setCDNUrl(feedbackData.cdnUrl);
585
561
  }
562
+ if (feedbackData.apiPrefix) {
563
+ setApiPrefix(feedbackData.apiPrefix);
564
+ }
586
565
  window.removeEventListener("message", onReceiveMessage);
587
566
  setHasInit(true);
588
567
  }
589
568
  return;
590
569
  };
591
570
  window.addEventListener("message", onReceiveMessage);
592
- return /* @__PURE__ */ u(b, { children: hasInit && (hidden ? /* @__PURE__ */ u(HiddenIframe, {}) : /* @__PURE__ */ u(FieldIframe, { ...fieldIframeConfig })) });
571
+ return /* @__PURE__ */ u(b, { children: hasInit && (hidden ? /* @__PURE__ */ u(HiddenIframe, { checkoutId: checkoutId.current }) : /* @__PURE__ */ u(FieldIframe, { ...fieldIframeConfig, checkoutId: checkoutId.current })) });
593
572
  };
594
573
  export {
595
574
  SecuredIframe
@@ -1,13 +1,13 @@
1
1
  import { w, A, h, F, y, q, u } from "../../core.js";
2
- import { createAddressCore } from "../../core/Address.js";
3
2
  import { useBEM } from "../../hooks/useBEM.js";
4
3
  import { CoreContext } from "../../core/context.js";
5
4
  import "../../utils/card-brand/brands.js";
6
5
  import "../../utils/system-info/get-browser-info.js";
7
- import { cssVarPrefix, normalizedClass, formatAmount, trimAll } from "../../utils/format.js";
6
+ import { normalizedClass, formatAmount, trimAll } from "../../utils/format.js";
7
+ import { formatPaymentResult } from "../../utils/payment.js";
8
8
  import { isTimeoutError } from "../../api/http.js";
9
- import { COMMON_CLASS_NAME } from "../../constant.js";
10
9
  import { getBrowserParams } from "../../api/modules/get-browser-params.js";
10
+ import { COMMON_CLASS_NAME, PaymentMethod } from "../../constant.js";
11
11
  import { getSepaPayInfo, sepaPay } from "../../api/modules/sepa/index.js";
12
12
  import { PayKKaError } from "../../core/error.js";
13
13
  import { usePayState } from "../../hooks/usePayState.js";
@@ -25,9 +25,9 @@ import { AccountNameField } from "../AccountNameField/index.js";
25
25
  const { bem } = useBEM("sepa");
26
26
  const fieldClassNames = bem("field");
27
27
  const Sepa = w((props, ref) => {
28
- var _a, _b, _c, _d, _e, _f, _g, _h;
29
- const { session } = props;
30
- let addressState = createAddressCore();
28
+ var _a, _b;
29
+ const { session, core } = props;
30
+ const addressCore = core.getAddressCore();
31
31
  let emailState = createEmailCore();
32
32
  const { i18n, sessionReady } = usePayState(session, props.core);
33
33
  const addressFieldRef = A(null);
@@ -38,13 +38,13 @@ const Sepa = w((props, ref) => {
38
38
  iban: "",
39
39
  holderName: "",
40
40
  address: {
41
- country: "",
42
- province: "",
43
- city: "",
44
- area: "",
45
- postCode: "",
46
- address1: "",
47
- address2: ""
41
+ country: void 0,
42
+ province: void 0,
43
+ city: void 0,
44
+ area: void 0,
45
+ postCode: void 0,
46
+ address1: void 0,
47
+ address2: void 0
48
48
  }
49
49
  });
50
50
  const [validated, setValidated] = h(false);
@@ -53,36 +53,43 @@ const Sepa = w((props, ref) => {
53
53
  const disabledEmail = A(false);
54
54
  const [requiredBill, setRequiredBill] = h(false);
55
55
  const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
56
- const formStyle = {
57
- [cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
58
- [cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
59
- [cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
60
- [cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
61
- [cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
62
- };
63
56
  F(ref, () => ({
64
57
  updateAddress: () => {
65
58
  var _a2;
66
59
  if (!requiredBill)
67
60
  return;
68
- setForm(Object.assign(form, { address: addressState.getAddressState() }));
69
- (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
61
+ setForm(Object.assign(form, { address: addressCore.getAddressState() }));
62
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressCore.getAddressState());
70
63
  },
71
64
  updateEmail: () => {
72
65
  var _a2;
73
66
  setForm(Object.assign(form, { email: emailState.email }));
67
+ form.email = emailState.email;
74
68
  (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
69
+ validateForm();
75
70
  }
76
71
  }));
72
+ const processOnSuccess = (res) => {
73
+ var _a2, _b2;
74
+ setSubmitButtonStatus("success");
75
+ (_b2 = props.onSuccess) == null ? void 0 : _b2.call(
76
+ props,
77
+ formatPaymentResult({
78
+ ...res,
79
+ returnUrl: (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.returnUrl
80
+ })
81
+ );
82
+ };
77
83
  y(() => {
78
84
  session.ready().then(() => {
79
85
  setIsCheckoutEnabled(true);
80
- const { bill, status } = session.checkout;
86
+ const { bill, status, country } = session.checkout;
87
+ country && addressCore.setCountry(country);
81
88
  form.email = bill.email ?? "";
89
+ form.address.country = country;
82
90
  disabledEmail.current = !!bill.email;
83
91
  setRequiredBill(bill.billingAddressCollection === "REQUIRED");
84
92
  if (status === "SUCCESS") {
85
- setSubmitButtonStatus("success");
86
93
  processOnSuccess();
87
94
  }
88
95
  });
@@ -125,7 +132,7 @@ const Sepa = w((props, ref) => {
125
132
  setErrorMsg("");
126
133
  (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
127
134
  var _a3;
128
- requiredBill && addressState.setValidateAllFields(true);
135
+ requiredBill && addressCore.setValidateAllFields(true);
129
136
  (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
130
137
  if (errors) {
131
138
  setSubmitButtonStatus("unSubmit");
@@ -154,14 +161,19 @@ const Sepa = w((props, ref) => {
154
161
  sessionId: session.sessionId,
155
162
  clientKey: session.clientKey,
156
163
  payment: {
164
+ paymentMethod: PaymentMethod.SEPA_DEBIT,
157
165
  holderName: form.holderName,
158
166
  iban: trimAll(form.iban)
159
167
  },
160
168
  bill: requiredBill ? {
161
169
  email: form.email,
162
- ...form.address,
163
- province: addressState.getLabel(form.address.province, addressState.getProvinceOption()) ?? form.address.province,
164
- city: addressState.getLabel(form.address.city, addressState.getCityOptions()) ?? form.address.city
170
+ addressLine1: form.address.address1,
171
+ addressLine2: form.address.address2,
172
+ postalCode: form.address.postCode,
173
+ country: form.address.country,
174
+ district: form.address.area,
175
+ state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
176
+ city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
165
177
  } : {
166
178
  email: form.email
167
179
  },
@@ -169,14 +181,25 @@ const Sepa = w((props, ref) => {
169
181
  };
170
182
  };
171
183
  async function pay(search = false, timeout) {
172
- var _a2;
184
+ var _a2, _b2, _c, _d, _e;
173
185
  try {
174
- const paymentParams = await getPaymentParams();
175
- const options = { locale: i18n.locale, timeout };
176
- const res = search ? await getSepaPayInfo(
177
- { sessionId: session.sessionId, clientKey: session.clientKey },
178
- options
179
- ) : await sepaPay(paymentParams, props.core, options);
186
+ const requestOptions = { locale: i18n.locale, timeout };
187
+ let res = null;
188
+ if (search) {
189
+ const extraParams = (_b2 = (_a2 = core.config)._getExtraParams) == null ? void 0 : _b2.call(_a2, "query", PaymentMethod.SEPA_DEBIT);
190
+ res = await getSepaPayInfo(
191
+ {
192
+ sessionId: session.sessionId,
193
+ clientKey: session.clientKey,
194
+ paymentMethod: PaymentMethod.SEPA_DEBIT
195
+ },
196
+ extraParams,
197
+ requestOptions
198
+ );
199
+ } else {
200
+ const extraParams = (_d = (_c = core.config)._getExtraParams) == null ? void 0 : _d.call(_c, "payment", PaymentMethod.SEPA_DEBIT);
201
+ res = await sepaPay(await getPaymentParams(), extraParams, requestOptions);
202
+ }
180
203
  return processAfterPayment(res, search);
181
204
  } catch (error) {
182
205
  if (isTimeoutError(error)) {
@@ -189,31 +212,31 @@ const Sepa = w((props, ref) => {
189
212
  } else {
190
213
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
191
214
  setErrorMsg(message);
192
- (_a2 = props.onError) == null ? void 0 : _a2.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
215
+ (_e = props.onError) == null ? void 0 : _e.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
193
216
  setSubmitButtonStatus("unSubmit");
194
217
  return { end: true };
195
218
  }
196
219
  }
197
220
  }
198
221
  const processAfterPayment = (res, search = false) => {
199
- var _a2, _b2, _c2;
200
- const { status, orderStatus, errorMessage, errorCode } = res;
222
+ var _a2, _b2, _c;
223
+ const { status, orderStatus, errorMessage, errorCode, sessionId } = res;
224
+ sessionId && (session.sessionId = sessionId);
201
225
  if (status === "PROCESSING") {
202
226
  if (!orderStatus) {
203
227
  setSubmitButtonStatus("unSubmit");
204
228
  return { end: true };
205
229
  } else if (orderStatus === "SUCCESS") {
206
- setSubmitButtonStatus("success");
207
- processOnSuccess();
230
+ processOnSuccess(res);
208
231
  } else if (orderStatus === "PROCESSING") {
209
232
  if (search) {
210
- processOnSuccess();
233
+ processOnSuccess(res);
211
234
  } else {
212
235
  startReFetchPayInfo();
213
236
  }
214
237
  return { end: search };
215
238
  } else if (orderStatus === "FAILURE") {
216
- setErrorMsg(errorMessage);
239
+ errorMessage && setErrorMsg(errorMessage);
217
240
  setSubmitButtonStatus("unSubmit");
218
241
  (_a2 = props.onError) == null ? void 0 : _a2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
219
242
  } else if (orderStatus === "AUTHORIZED") {
@@ -222,29 +245,25 @@ const Sepa = w((props, ref) => {
222
245
  }
223
246
  return { end: true };
224
247
  } else if (status === "SUCCESS") {
225
- setSubmitButtonStatus("success");
226
- processOnSuccess();
248
+ processOnSuccess(res);
227
249
  return { end: true };
228
250
  } else if (status === "EXPIRED") {
229
251
  setSubmitButtonStatus("unSubmit");
230
- (_c2 = props.onExpired) == null ? void 0 : _c2.call(props);
252
+ (_c = props.onExpired) == null ? void 0 : _c.call(props);
231
253
  return { end: true };
232
254
  }
233
255
  setSubmitButtonStatus("unSubmit");
234
256
  return { end: true };
235
257
  };
236
- const processOnSuccess = () => {
237
- var _a2, _b2;
238
- (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props, (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.returnUrl);
239
- };
240
258
  return /* @__PURE__ */ u(
241
259
  CoreContext.Provider,
242
260
  {
243
261
  value: {
244
262
  i18n,
245
- session
263
+ session,
264
+ core
246
265
  },
247
- children: sessionReady && isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: formStyle, children: [
266
+ children: sessionReady && isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u("div", { className: core.theme.className, children: /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), children: [
248
267
  /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
249
268
  EmailField,
250
269
  {
@@ -260,13 +279,13 @@ const Sepa = w((props, ref) => {
260
279
  {
261
280
  ref: addressFieldRef,
262
281
  value: form.address,
263
- 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),
282
+ country: ((_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.country) || ((_b = session == null ? void 0 : session.checkout) == null ? void 0 : _b.bill.country),
264
283
  onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
265
284
  }
266
285
  ) }),
267
286
  !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg, style: { marginTop: "12px" } }),
268
287
  Button()
269
- ] }) })
288
+ ] }) }) })
270
289
  }
271
290
  );
272
291
  });