@paykka/card-checkout-ui 0.13.8 → 0.13.13

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 (175) hide show
  1. package/dist/card-checkout-ui.js +20 -20
  2. package/dist/card-checkout-ui.umd.cjs +21 -21
  3. package/dist/es/_commonjsHelpers.js +1 -82
  4. package/dist/es/api/index.js +2 -1
  5. package/dist/es/api/modules/checkout/map.js +1 -0
  6. package/dist/es/api/modules/get-browser-params.js +20 -8
  7. package/dist/es/api/modules/index.js +2 -1
  8. package/dist/es/api/modules/map.js +2 -1
  9. package/dist/es/api/modules/risk/index.js +21 -18
  10. package/dist/es/api/modules/threeDS/index.js +2 -1
  11. package/dist/es/api/modules/vietqr/index.js +2 -1
  12. package/dist/es/api/utils/index.js +4 -1
  13. package/dist/es/components/AccordionItem/AccordionItem.js +0 -1
  14. package/dist/es/components/AccountNameField/index.js +1 -1
  15. package/dist/es/components/AddressField/index.js +1 -2
  16. package/dist/es/components/AliPay/index.js +4 -2
  17. package/dist/es/components/ApplePay/index.js +201 -135
  18. package/dist/es/components/Boost/index.js +4 -2
  19. package/dist/es/components/CPFField/index.js +88 -0
  20. package/dist/es/components/Card/index.js +5 -11
  21. package/dist/es/components/CardBrands/index.js +0 -1
  22. package/dist/es/components/CardExpireDateField/index.js +1 -1
  23. package/dist/es/components/CardHolderNameField/index.js +1 -1
  24. package/dist/es/components/CardIBANField/index.js +1 -1
  25. package/dist/es/components/CardNo/index.js +0 -1
  26. package/dist/es/components/CardNumberField/index.js +1 -1
  27. package/dist/es/components/CardSecurityCodeField/index.js +1 -1
  28. package/dist/es/components/CardSelector/index.js +1 -1
  29. package/dist/es/components/CombinedCardInfo/index.js +1 -1
  30. package/dist/es/components/DropIn/index.js +0 -1
  31. package/dist/es/components/EmailField/EmailField.js +1 -1
  32. package/dist/es/components/EncryptedCard/index.js +12 -11
  33. package/dist/es/components/GooglePay/index.js +1 -0
  34. package/dist/es/components/GrabPay/index.js +4 -2
  35. package/dist/es/components/GuideCard/index.js +1 -1
  36. package/dist/es/components/LinePay/index.js +4 -2
  37. package/dist/es/components/MayBankQRPay/index.js +4 -2
  38. package/dist/es/components/NinePay/index.js +4 -2
  39. package/dist/es/components/RecurringTip/index.js +1 -2
  40. package/dist/es/components/SecuredFieldsProvider/index.js +20 -3
  41. package/dist/es/components/SecuredIframe/index.js +50 -22
  42. package/dist/es/components/Sepa/index.js +4 -2
  43. package/dist/es/components/ShopeePay/index.js +4 -2
  44. package/dist/es/components/SubmitButton/index.js +1 -1
  45. package/dist/es/components/TNGWallet/index.js +4 -2
  46. package/dist/es/components/ThreeDS/index.js +1 -2
  47. package/dist/es/components/Tip/index.js +18 -0
  48. package/dist/es/components/WechatPay/index.js +4 -2
  49. package/dist/es/components/business/QRCodeModal/QRCodeModal.js +1 -1
  50. package/dist/es/components/business/QRCodeModal/index.js +0 -1
  51. package/dist/es/components/business/index.js +0 -1
  52. package/dist/es/components/index.js +0 -1
  53. package/dist/es/components/internal/Accordion/index.js +0 -1
  54. package/dist/es/components/internal/Button/Button.js +0 -1
  55. package/dist/es/components/internal/Button/index.js +0 -1
  56. package/dist/es/components/internal/CheckBox/CheckBox.js +0 -1
  57. package/dist/es/components/internal/CheckBox/index.js +0 -1
  58. package/dist/es/components/internal/Form/type.js +0 -1
  59. package/dist/es/components/internal/Info/Info.js +0 -1
  60. package/dist/es/components/internal/Info/index.js +0 -1
  61. package/dist/es/components/internal/Input/Input.js +1 -1
  62. package/dist/es/components/internal/Input/type.js +0 -1
  63. package/dist/es/components/internal/LoadingCheck/LoadingCheck.js +0 -1
  64. package/dist/es/components/internal/LoadingCheck/index.js +0 -1
  65. package/dist/es/components/internal/Modal/Modal.js +1 -1
  66. package/dist/es/components/internal/QRCode/QRCode.js +0 -1
  67. package/dist/es/components/internal/QRCode/index.js +0 -1
  68. package/dist/es/components/internal/Select/Select.js +14 -17
  69. package/dist/es/components/internal/Select/SelectMenu.js +2 -3
  70. package/dist/es/components/internal/Select/SelectMenuItem.js +0 -1
  71. package/dist/es/components/wallets/GCash/GCash.js +4 -2
  72. package/dist/es/components/wallets/OpayWallet/OpayWallet.js +8 -9
  73. package/dist/es/components/wallets/PagaWallet/PagaWallet.js +8 -9
  74. package/dist/es/components/wallets/Paymaya/Paymaya.js +4 -2
  75. package/dist/es/components/wallets/PicPay/PicPay.js +136 -72
  76. package/dist/es/components/wallets/Pix/Pix.js +136 -72
  77. package/dist/es/components/wallets/Vietqr/Vietqr.js +4 -2
  78. package/dist/es/components/wallets/Zalopay/Zalopay.js +4 -2
  79. package/dist/es/config.js +1 -1
  80. package/dist/es/constant.js +2 -0
  81. package/dist/es/core/checkout.js +15 -3
  82. package/dist/es/core/environment.js +10 -2
  83. package/dist/es/core/index.js +0 -1
  84. package/dist/es/core/query.js +2 -1
  85. package/dist/es/core/session.js +6 -2
  86. package/dist/es/core/theme.js +0 -1
  87. package/dist/es/core.js +585 -4
  88. package/dist/es/hooks/index.js +0 -1
  89. package/dist/es/hooks/useI18n.js +0 -1
  90. package/dist/es/hooks/usePayState.js +13 -6
  91. package/dist/es/i18n/locales/de-DE.js +6 -1
  92. package/dist/es/i18n/locales/en-GB.js +6 -1
  93. package/dist/es/i18n/locales/es-ES.js +6 -1
  94. package/dist/es/i18n/locales/fr-FR.js +7 -2
  95. package/dist/es/i18n/locales/ja-JP.js +6 -1
  96. package/dist/es/i18n/locales/ko-KR.js +6 -1
  97. package/dist/es/i18n/locales/nl-NL.js +6 -1
  98. package/dist/es/i18n/locales/pt-PT.js +6 -1
  99. package/dist/es/i18n/locales/ru-RU.js +6 -1
  100. package/dist/es/i18n/locales/zh-CN.js +6 -1
  101. package/dist/es/i18n/locales/zh-HK.js +7 -2
  102. package/dist/es/i18n/locales/zh-TW.js +7 -2
  103. package/dist/es/index.js +6 -3
  104. package/dist/es/out/base-fraud-detection.js +134 -0
  105. package/dist/es/out/config.js +16 -0
  106. package/dist/es/out/fraud-detection.js +118 -27
  107. package/dist/es/out/paykka-detection.js +63 -0
  108. package/dist/es/out/stripe-radar.js +25 -51
  109. package/dist/es/out/worldpay-ddc.js +52 -99
  110. package/dist/es/out/worldpay-jsc-origin.js +0 -1
  111. package/dist/es/out/worldpay-jsc.js +21 -43
  112. package/dist/es/style.css +1 -1
  113. package/dist/es/types/event.js +33 -13
  114. package/dist/es/types/index.js +14 -0
  115. package/dist/es/utils/cpf.js +48 -0
  116. package/dist/es/utils/encrypt.js +18 -0
  117. package/dist/es/utils/iframe.js +1 -1
  118. package/dist/es/utils/location.js +4 -2
  119. package/dist/es/utils/redirect.js +8 -5
  120. package/dist/es/utils/system-info/index.js +1 -3
  121. package/dist/style.css +1 -1
  122. package/dist/types/api/modules/checkout/type.d.ts +2 -0
  123. package/dist/types/api/modules/get-browser-params.d.ts +25 -1
  124. package/dist/types/api/modules/risk/index.d.ts +28 -12
  125. package/dist/types/api/modules/type.d.ts +5 -0
  126. package/dist/types/api/utils/index.d.ts +3 -0
  127. package/dist/types/components/ApplePay/config.d.ts +9 -0
  128. package/dist/types/components/ApplePay/hooks/useApplePay.d.ts +15 -0
  129. package/dist/types/components/ApplePay/type.d.ts +53 -10
  130. package/dist/types/components/ApplePay/utils.d.ts +8 -2
  131. package/dist/types/components/CPFField/CPFField.d.ts +4 -0
  132. package/dist/types/components/CPFField/index.d.ts +2 -0
  133. package/dist/types/components/CPFField/type.d.ts +21 -0
  134. package/dist/types/components/SecuredFieldsProvider/type.d.ts +8 -3
  135. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +2 -5
  136. package/dist/types/components/ThreeDS/components/ThreeDSIframe/ThreeDSIframe.d.ts +6 -0
  137. package/dist/types/components/Tip/Tip.d.ts +3 -0
  138. package/dist/types/components/Tip/index.d.ts +2 -0
  139. package/dist/types/components/Tip/type.d.ts +12 -0
  140. package/dist/types/constant.d.ts +3 -1
  141. package/dist/types/core/checkout.d.ts +1 -1
  142. package/dist/types/core/environment.d.ts +12 -0
  143. package/dist/types/core/session.d.ts +1 -0
  144. package/dist/types/i18n/locales/de-DE.d.ts +4 -0
  145. package/dist/types/i18n/locales/en-GB.d.ts +4 -0
  146. package/dist/types/i18n/locales/es-ES.d.ts +4 -0
  147. package/dist/types/i18n/locales/fr-FR.d.ts +4 -0
  148. package/dist/types/i18n/locales/ja-JP.d.ts +4 -0
  149. package/dist/types/i18n/locales/ko-KR.d.ts +4 -0
  150. package/dist/types/i18n/locales/nl-NL.d.ts +4 -0
  151. package/dist/types/i18n/locales/pt-PT.d.ts +4 -0
  152. package/dist/types/i18n/locales/ru-RU.d.ts +4 -0
  153. package/dist/types/i18n/locales/zh-CN.d.ts +4 -0
  154. package/dist/types/i18n/locales/zh-HK.d.ts +4 -0
  155. package/dist/types/i18n/locales/zh-TW.d.ts +4 -0
  156. package/dist/types/out/base-fraud-detection.d.ts +53 -0
  157. package/dist/types/out/config.d.ts +11 -0
  158. package/dist/types/out/fraud-detection.d.ts +14 -3
  159. package/dist/types/out/paykka-detection.d.ts +20 -0
  160. package/dist/types/out/stripe-radar.d.ts +7 -9
  161. package/dist/types/out/types.d.ts +8 -2
  162. package/dist/types/out/worldpay-ddc.d.ts +7 -19
  163. package/dist/types/out/worldpay-jsc.d.ts +8 -18
  164. package/dist/types/types/event.d.ts +86 -39
  165. package/dist/types/types/fraud-detection.d.ts +1 -1
  166. package/dist/types/types/index.d.ts +22 -2
  167. package/dist/types/types/message.d.ts +12 -12
  168. package/dist/types/utils/app-payment.d.ts +2 -0
  169. package/dist/types/utils/cpf.d.ts +32 -0
  170. package/dist/types/utils/encrypt.d.ts +9 -0
  171. package/dist/types/utils/location.d.ts +1 -0
  172. package/dist/types/utils/system-info/index.d.ts +0 -1
  173. package/package.json +5 -4
  174. package/dist/types/components/ThreeDS/components/ThreeDSStatus/ThreeDSStatus.d.ts +0 -3
  175. package/dist/types/components/ThreeDS/components/ThreeDSStatus/type.d.ts +0 -6
@@ -3,9 +3,10 @@ import { useBEM } from "../../../hooks/useBEM.js";
3
3
  import { CoreContext } from "../../../core/context.js";
4
4
  import "../../../utils/card-brand/brands.js";
5
5
  import "../../../utils/system-info/get-browser-info.js";
6
- import { normalizedClass, formatAmount } from "../../../utils/format.js";
6
+ import { normalizedClass, formatAmount, limitedToNumber } from "../../../utils/format.js";
7
+ import { defaultInputStyleConfig } from "../../../types/index.js";
7
8
  import { redirectToPayment } from "../../../utils/redirect.js";
8
- import { formatPaymentResult } from "../../../utils/payment.js";
9
+ import { processPaymentStatus, formatPaymentResult } from "../../../utils/payment.js";
9
10
  import { isTimeoutError } from "../../../api/http.js";
10
11
  import { getBrowserParams } from "../../../api/modules/get-browser-params.js";
11
12
  import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../../constant.js";
@@ -24,9 +25,13 @@ import "../../internal/Form/context.js";
24
25
  import "../../internal/Form/FormItem.js";
25
26
  import { Form } from "../../internal/Form/Form.js";
26
27
  import "./pix2.js";
28
+ import { SecuredFieldsProvider } from "../../SecuredFieldsProvider/index.js";
29
+ import { CPFField } from "../../CPFField/index.js";
30
+ import { Tip } from "../../Tip/index.js";
27
31
  const { bem } = useBEM("pix");
28
32
  const fieldClassNames = bem("field");
29
33
  const Pix = w((props, ref) => {
34
+ var _a;
30
35
  const {
31
36
  session,
32
37
  showEmail = false,
@@ -47,21 +52,21 @@ const Pix = w((props, ref) => {
47
52
  startReFetchPayInfo({ timeout });
48
53
  },
49
54
  updateAddress: () => {
50
- var _a;
55
+ var _a2;
51
56
  if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
52
57
  return;
53
58
  const newForm = Object.assign(form, { address: addressCore.getAddressState() });
54
59
  setForm(newForm);
55
- (_a = addressFieldRef.current) == null ? void 0 : _a.update(addressCore.getAddressState());
60
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressCore.getAddressState());
56
61
  validateForm();
57
62
  },
58
63
  updateEmail: () => {
59
- var _a;
64
+ var _a2;
60
65
  if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
61
66
  return;
62
67
  const newForm = Object.assign(form, { email: emailState.email });
63
68
  setForm(newForm);
64
- (_a = emailFieldRef.current) == null ? void 0 : _a.update(emailState.email);
69
+ (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
65
70
  validateForm();
66
71
  },
67
72
  payment: () => {
@@ -72,9 +77,12 @@ const Pix = w((props, ref) => {
72
77
  const emailState = createEmailCore();
73
78
  const addressFieldRef = A(null);
74
79
  const emailFieldRef = A(null);
80
+ const SFPRef = A(null);
81
+ const cpfFieldRef = A(null);
75
82
  const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
76
- const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session, props.core);
83
+ const { setErrorMsg, fraudDetection, i18n, errorMsg, sessionReady } = usePayState(session, props.core);
77
84
  const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
85
+ const [security, setSecurity] = h(false);
78
86
  const formRef = A(null);
79
87
  const [form, setForm] = h({
80
88
  email: "",
@@ -86,7 +94,8 @@ const Pix = w((props, ref) => {
86
94
  postCode: void 0,
87
95
  address1: void 0,
88
96
  address2: void 0
89
- }
97
+ },
98
+ cpf: ""
90
99
  });
91
100
  const [validated, setValidated] = h(false);
92
101
  const [fieldStatus, setFieldStatus] = h();
@@ -104,22 +113,25 @@ const Pix = w((props, ref) => {
104
113
  setFieldStatus({ ...field });
105
114
  };
106
115
  const processOnSuccess = (res) => {
107
- var _a, _b;
116
+ var _a2, _b;
108
117
  setSubmitButtonStatus("success");
109
118
  (_b = props.onSuccess) == null ? void 0 : _b.call(props, formatPaymentResult({
110
119
  ...res,
111
- returnUrl: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.returnUrl
120
+ returnUrl: (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.returnUrl
112
121
  }));
113
122
  };
114
123
  y(() => {
124
+ var _a2;
115
125
  if (!sessionReady) {
116
126
  return;
117
127
  }
118
- const { bill = {}, supportMethods = [], country } = (session == null ? void 0 : session.checkout) || {};
128
+ const { bill = {}, supportMethods = [], country, sessionMode } = (session == null ? void 0 : session.checkout) || {};
119
129
  if (!supportMethods.includes(PaymentMethod.PIX)) {
120
130
  return;
121
131
  }
122
132
  initFieldStatus();
133
+ setSecurity(sessionMode !== SessionMode.HOSTED);
134
+ (_a2 = SFPRef.current) == null ? void 0 : _a2.reload();
123
135
  setIsCheckoutEnabled(true);
124
136
  country && addressCore.setCountry(country);
125
137
  form.email = bill.email ?? "";
@@ -130,16 +142,16 @@ const Pix = w((props, ref) => {
130
142
  }
131
143
  }, [sessionReady]);
132
144
  const processOnError = (error) => {
133
- var _a;
134
- (_a = props.onError) == null ? void 0 : _a.call(props, error);
145
+ var _a2;
146
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, error);
135
147
  core.resetEnablePaymentMethod();
136
148
  };
137
149
  const onTimeout = q(
138
150
  (message) => {
139
- var _a;
151
+ var _a2;
140
152
  setErrorMsg(message || i18n.get("common.payTimeout"));
141
153
  setSubmitButtonStatus("unSubmit");
142
- (_a = props.onTimeout) == null ? void 0 : _a.call(props);
154
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props);
143
155
  core.resetEnablePaymentMethod();
144
156
  },
145
157
  [i18n, props.onTimeout]
@@ -155,6 +167,9 @@ const Pix = w((props, ref) => {
155
167
  payment: {
156
168
  paymentMethod: PaymentMethod.PIX
157
169
  },
170
+ customer: {
171
+ document: limitedToNumber(form.cpf)
172
+ },
158
173
  bill: {
159
174
  email: form.email,
160
175
  addressLine1: form.address.address1,
@@ -165,16 +180,18 @@ const Pix = w((props, ref) => {
165
180
  state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
166
181
  city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
167
182
  },
168
- browser: await getBrowserParams()
183
+ browser: await getBrowserParams({
184
+ fraudDetectionId: await (fraudDetection == null ? void 0 : fraudDetection.getFraudDetectionId())
185
+ })
169
186
  };
170
187
  };
171
188
  const pay = async (search = false, timeout) => {
172
- var _a, _b, _c, _d, _e, _f, _g;
189
+ var _a2, _b, _c, _d, _e;
173
190
  try {
174
191
  const requestOptions = { locale: i18n.locale, timeout };
175
192
  let res = null;
176
193
  if (search) {
177
- const extraParams = (_b = (_a = core.config)._getExtraParams) == null ? void 0 : _b.call(_a, "query", PaymentMethod.PIX);
194
+ const extraParams = (_b = (_a2 = core.config)._getExtraParams) == null ? void 0 : _b.call(_a2, "query", PaymentMethod.PIX);
178
195
  res = await getPixPayInfo(
179
196
  {
180
197
  sessionId: session.sessionId,
@@ -185,50 +202,16 @@ const Pix = w((props, ref) => {
185
202
  requestOptions
186
203
  );
187
204
  } else {
205
+ const paymentParams = await getPaymentParams();
188
206
  const extraParams = (_d = (_c = core.config)._getExtraParams) == null ? void 0 : _d.call(_c, "payment", PaymentMethod.PIX);
189
- res = await pixPay(await getPaymentParams(), extraParams, requestOptions);
190
- }
191
- !search && ((_e = props.onSubmitResponse) == null ? void 0 : _e.call(props, res));
192
- const { status, orderStatus, errorMessage, errorCode, payInfo, sessionId } = res;
193
- sessionId && (session.sessionId = sessionId);
194
- if (status === "PROCESSING") {
195
- if (!orderStatus) {
196
- setSubmitButtonStatus("unSubmit");
197
- return { end: true };
198
- } else if (orderStatus === "SUCCESS") {
199
- processOnSuccess(res);
200
- return { end: true };
201
- } else if (orderStatus === "FAILURE") {
202
- errorMessage && setErrorMsg(errorMessage);
203
- setSubmitButtonStatus("unSubmit");
204
- processOnError(new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
205
- return { end: true };
206
- } else if (orderStatus === "PROCESSING") {
207
- if (!search) {
208
- if (redirectMode === "auto" && payInfo) {
209
- redirectToPayment(payInfo);
210
- return { end: true };
211
- } else {
212
- startReFetchPayInfo();
213
- }
214
- }
215
- return { end: false };
216
- } else if (orderStatus === "CANCELED") {
217
- setSubmitButtonStatus("unSubmit");
218
- (_f = props.onTimeout) == null ? void 0 : _f.call(props);
219
- core.resetEnablePaymentMethod();
207
+ if (security) {
208
+ (_e = SFPRef.current) == null ? void 0 : _e.payment(paymentParams, extraParams);
220
209
  return { end: true };
210
+ } else {
211
+ res = await pixPay(paymentParams, extraParams, requestOptions);
221
212
  }
222
- } else if (status === "SUCCESS") {
223
- processOnSuccess(res);
224
- return { end: true };
225
- } else if (status === "EXPIRED") {
226
- setSubmitButtonStatus("unSubmit");
227
- (_g = props.onExpired) == null ? void 0 : _g.call(props);
228
- return { end: true };
229
213
  }
230
- setSubmitButtonStatus("unSubmit");
231
- return { end: true };
214
+ return processAfterPayment(res, search);
232
215
  } catch (error) {
233
216
  if (isTimeoutError(error)) {
234
217
  if (search) {
@@ -238,17 +221,14 @@ const Pix = w((props, ref) => {
238
221
  return { end: true };
239
222
  }
240
223
  } else {
241
- const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
242
- message && setErrorMsg(message);
243
- processOnError(new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
244
- setSubmitButtonStatus("unSubmit");
224
+ processPaymentError(error);
245
225
  return { end: true };
246
226
  }
247
227
  }
248
228
  };
249
229
  const validateForm = () => {
250
- var _a;
251
- (_a = formRef.current) == null ? void 0 : _a.validate(void 0, false).then(() => {
230
+ var _a2;
231
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
252
232
  setValidated(true);
253
233
  }).catch(() => {
254
234
  setValidated(false);
@@ -258,12 +238,12 @@ const Pix = w((props, ref) => {
258
238
  validateForm();
259
239
  }, [form]);
260
240
  const onSubmit = async () => {
261
- var _a;
241
+ var _a2;
262
242
  setErrorMsg("");
263
- (_a = formRef.current) == null ? void 0 : _a.validate(async (errors) => {
264
- var _a2;
243
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
244
+ var _a3;
265
245
  (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
266
- (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props, errors);
246
+ (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
267
247
  if (errors) {
268
248
  setSubmitButtonStatus("unSubmit");
269
249
  return;
@@ -273,13 +253,80 @@ const Pix = w((props, ref) => {
273
253
  await pay();
274
254
  });
275
255
  };
256
+ const processAfterPayment = (res, search = false) => {
257
+ var _a2;
258
+ !search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
259
+ const { errorMessage, errorCode, payInfo, sessionId } = res;
260
+ sessionId && (session.sessionId = sessionId);
261
+ let end = true;
262
+ processPaymentStatus(res, {
263
+ onProcessing: () => {
264
+ if (redirectMode === "auto" && (payInfo == null ? void 0 : payInfo.targetUrl)) {
265
+ redirectToPayment(payInfo);
266
+ return;
267
+ }
268
+ !search && startReFetchPayInfo();
269
+ end = false;
270
+ },
271
+ onSuccess: () => {
272
+ processOnSuccess(res);
273
+ },
274
+ onFailure: () => {
275
+ processPaymentError({ message: errorMessage, code: errorCode });
276
+ },
277
+ onCanceled: () => {
278
+ var _a3;
279
+ setSubmitButtonStatus("unSubmit");
280
+ (_a3 = props.onTimeout) == null ? void 0 : _a3.call(props);
281
+ core.resetEnablePaymentMethod();
282
+ },
283
+ onExpired: () => {
284
+ var _a3;
285
+ setSubmitButtonStatus("unSubmit");
286
+ (_a3 = props.onExpired) == null ? void 0 : _a3.call(props);
287
+ },
288
+ onDefault: () => {
289
+ setSubmitButtonStatus("unSubmit");
290
+ }
291
+ });
292
+ return { end };
293
+ };
294
+ const processPaymentError = (error) => {
295
+ const message = (error == null ? void 0 : error.i18nKey) ? i18n.get(error.i18nKey) : error.message;
296
+ message && setErrorMsg(message);
297
+ processOnError(new PayKKaError("API_ERROR", message, { code: error == null ? void 0 : error.code, cause: error }));
298
+ setSubmitButtonStatus("unSubmit");
299
+ };
300
+ const onFieldsFocus = (data) => {
301
+ var _a2, _b;
302
+ const fieldRef = cpfFieldRef;
303
+ if (data.focus) {
304
+ (_a2 = fieldRef.current) == null ? void 0 : _a2.focus();
305
+ } else {
306
+ (_b = fieldRef.current) == null ? void 0 : _b.blur();
307
+ }
308
+ };
309
+ const onAfterPayment = (data) => {
310
+ processAfterPayment(data.response);
311
+ };
312
+ const onPaymentError = (data) => {
313
+ processPaymentError(data.error);
314
+ };
315
+ const onFieldValidStatusChanged = (data) => {
316
+ var _a2;
317
+ const error = data.errorTip && i18n.get(data.errorTip);
318
+ (_a2 = cpfFieldRef.current) == null ? void 0 : _a2.resetValidation(data.status, error);
319
+ setTimeout(() => {
320
+ validateForm();
321
+ }, 100);
322
+ };
276
323
  const setFormRef = (dom) => {
277
324
  formRef.current = dom;
278
325
  dom && validateForm();
279
326
  };
280
327
  const Button = () => {
281
- var _a;
282
- const transAmount = (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.transAmount;
328
+ var _a2;
329
+ const transAmount = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.transAmount;
283
330
  const amountText = (transAmount == null ? void 0 : transAmount.amount) ? formatAmount(transAmount).jointSymbol() : "";
284
331
  const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
285
332
  return /* @__PURE__ */ u(
@@ -309,13 +356,13 @@ const Pix = w((props, ref) => {
309
356
  return /* @__PURE__ */ u(b, { children: !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg }) });
310
357
  };
311
358
  const Address = () => {
312
- var _a, _b;
359
+ var _a2, _b;
313
360
  return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
314
361
  AddressField,
315
362
  {
316
363
  ref: addressFieldRef,
317
364
  value: form.address,
318
- 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),
365
+ country: ((_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.country) || ((_b = session == null ? void 0 : session.checkout) == null ? void 0 : _b.bill.country),
319
366
  onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
320
367
  }
321
368
  ) }) });
@@ -332,7 +379,24 @@ const Pix = w((props, ref) => {
332
379
  showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.PIX }),
333
380
  /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), children: [
334
381
  Email(),
382
+ /* @__PURE__ */ u(
383
+ SecuredFieldsProvider,
384
+ {
385
+ ref: SFPRef,
386
+ i18n,
387
+ checkoutId: core.id,
388
+ style: defaultInputStyleConfig,
389
+ sessionMode: (_a = session.checkout) == null ? void 0 : _a.sessionMode,
390
+ onFocus: onFieldsFocus,
391
+ onAfterPayment,
392
+ onPaymentError,
393
+ onPaymentTimeout: ({ message }) => onTimeout(i18n.get(message)),
394
+ onValidStatusChanged: onFieldValidStatusChanged,
395
+ children: /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(CPFField, { ref: cpfFieldRef, security }) })
396
+ }
397
+ ),
335
398
  Address(),
399
+ /* @__PURE__ */ u(Tip, { text: i18n.get("iofTip") }),
336
400
  /* @__PURE__ */ u("div", { className: bem("footer-wrapper"), children: [
337
401
  ErrorMessage(),
338
402
  !hidePaymentButton && Button()
@@ -79,7 +79,7 @@ const Vietqr = w((props, ref) => {
79
79
  const addressFieldRef = A(null);
80
80
  const emailFieldRef = A(null);
81
81
  const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
82
- const { i18n, sessionReady } = usePayState(session);
82
+ const { i18n, fraudDetection, sessionReady } = usePayState(session);
83
83
  const { errorMsg, setErrorMsg, paymentButtonStatus, setPaymentButtonStatus } = usePaymentStatus();
84
84
  const formRef = A(null);
85
85
  const [form, setForm] = h({
@@ -170,7 +170,9 @@ const Vietqr = w((props, ref) => {
170
170
  state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
171
171
  city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
172
172
  },
173
- browser: await getBrowserParams()
173
+ browser: await getBrowserParams({
174
+ fraudDetectionId: await (fraudDetection == null ? void 0 : fraudDetection.getFraudDetectionId())
175
+ })
174
176
  };
175
177
  };
176
178
  const pay = async (search = false, timeout) => {
@@ -79,7 +79,7 @@ const Zalopay = w((props, ref) => {
79
79
  const addressFieldRef = A(null);
80
80
  const emailFieldRef = A(null);
81
81
  const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
82
- const { i18n, sessionReady } = usePayState(session);
82
+ const { i18n, fraudDetection, sessionReady } = usePayState(session);
83
83
  const { errorMsg, setErrorMsg, paymentButtonStatus, setPaymentButtonStatus } = usePaymentStatus();
84
84
  const formRef = A(null);
85
85
  const [form, setForm] = h({
@@ -170,7 +170,9 @@ const Zalopay = w((props, ref) => {
170
170
  state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
171
171
  city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
172
172
  },
173
- browser: await getBrowserParams()
173
+ browser: await getBrowserParams({
174
+ fraudDetectionId: await (fraudDetection == null ? void 0 : fraudDetection.getFraudDetectionId())
175
+ })
174
176
  };
175
177
  };
176
178
  const pay = async (search = false, timeout) => {
package/dist/es/config.js CHANGED
@@ -8,7 +8,7 @@ let cdnUrl = `${cdnOrigin}${cdnDir}`;
8
8
  let fraudDetectionEnv = void 0;
9
9
  let customReqHeaders = {};
10
10
  let customLocale = void 0;
11
- let apiPrefix = "";
11
+ let apiPrefix = "/session";
12
12
  const setApiUrl = (url) => {
13
13
  apiUrl = url;
14
14
  };
@@ -175,6 +175,8 @@ var SessionMode = /* @__PURE__ */ ((SessionMode2) => {
175
175
  var ChannelCode = /* @__PURE__ */ ((ChannelCode2) => {
176
176
  ChannelCode2["STRIPE"] = "STRIPE";
177
177
  ChannelCode2["WORLDPAY"] = "WORLD_PAY";
178
+ ChannelCode2["WORLDPAY_JSC"] = "WORLDPAY_JSC";
179
+ ChannelCode2["PAYKKA"] = "PAYKKA";
178
180
  return ChannelCode2;
179
181
  })(ChannelCode || {});
180
182
  export {
@@ -27,22 +27,23 @@ var __privateMethod = (obj, member, method) => {
27
27
  return method;
28
28
  };
29
29
  var _id, _config, _envConfig, _session, _theme, _componentInsts, _addressCore, _initPromise, _doInit, doInit_fn;
30
+ import { PaymentEventType } from "../types/event.js";
30
31
  import { create } from "./create.js";
31
32
  import { Session } from "./session.js";
32
33
  import { setApiPrefix, setApiUrl, setCDNUrl, setFraudDetectionEnv, fraudDetectionEnv, setCustomLocale } from "../config.js";
33
34
  import { PayKKaError } from "./error.js";
34
35
  import { apiEnv, cdnEnv } from "./environment.js";
35
- import "../api/http.js";
36
36
  import { isEmptyObject } from "../utils/is.js";
37
37
  import "../utils/card-brand/brands.js";
38
38
  import "../utils/system-info/get-browser-info.js";
39
39
  import { getUrlParam } from "../utils/location.js";
40
40
  import { deepMerge } from "../utils/object.js";
41
41
  import { genShortId } from "../utils/string.js";
42
- import "../out/worldpay-jsc-origin.js";
42
+ import "./context.js";
43
43
  import { d } from "../core.js";
44
44
  import { AddressCore } from "./address.js";
45
45
  import { PayKKaTheme } from "./theme.js";
46
+ import "../out/worldpay-jsc-origin.js";
46
47
  const PROCESSING_PARAM_NAME = "m";
47
48
  const DEFAULT_CHECKOUT_CONFIG = {
48
49
  enableInitValidation: true,
@@ -179,7 +180,7 @@ class PayKKaCheckout {
179
180
  var _a;
180
181
  const { onSubmit, onSuccess, onError, onTimeout, onExpired } = __privateGet(this, _config);
181
182
  const coreProps = this.getCoreProps();
182
- const componentInst = create(component, {
183
+ const combinedProps = {
183
184
  onSubmit,
184
185
  onSuccess,
185
186
  onError,
@@ -187,6 +188,17 @@ class PayKKaCheckout {
187
188
  onExpired,
188
189
  ...coreProps,
189
190
  ...props
191
+ };
192
+ const componentInst = create(component, {
193
+ ...combinedProps,
194
+ onError: (error) => {
195
+ var _a2, _b, _c;
196
+ (_a2 = combinedProps.onError) == null ? void 0 : _a2.call(combinedProps, error);
197
+ (_c = (_b = this.config).onEvent) == null ? void 0 : _c.call(_b, PaymentEventType.PAYMENT_FAILURE, {
198
+ message: error.message,
199
+ code: error.code
200
+ });
201
+ }
190
202
  });
191
203
  (_a = __privateGet(this, _componentInsts)) == null ? void 0 : _a.push(componentInst);
192
204
  return componentInst;
@@ -1,12 +1,20 @@
1
1
  const apiEnv = {
2
2
  eu: "https://checkout.eu.paykka.com",
3
3
  hk: "https://checkout.aq.paykka.com",
4
- sandbox: "https://checkout-sandbox.aq.paykka.com"
4
+ sandbox: "https://checkout-sandbox.aq.paykka.com",
5
+ ...{
6
+ fat: "",
7
+ dev: ""
8
+ }
5
9
  };
6
10
  const cdnEnv = {
7
11
  eu: "https://checkout.eu.paykka.com/cp",
8
12
  hk: "https://checkout.aq.paykka.com/cp",
9
- sandbox: "https://checkout-sandbox.aq.paykka.com/cp"
13
+ sandbox: "https://checkout-sandbox.aq.paykka.com/cp",
14
+ ...{
15
+ fat: "",
16
+ dev: ""
17
+ }
10
18
  };
11
19
  export {
12
20
  apiEnv,
@@ -2,5 +2,4 @@ import "./context.js";
2
2
  import "../core.js";
3
3
  import "../utils/card-brand/brands.js";
4
4
  import "../utils/system-info/get-browser-info.js";
5
- import "../api/http.js";
6
5
  import "../out/worldpay-jsc-origin.js";
@@ -1,7 +1,8 @@
1
- import "../api/http.js";
2
1
  import "../utils/card-brand/brands.js";
3
2
  import "../utils/system-info/get-browser-info.js";
4
3
  import "../core.js";
4
+ import "./context.js";
5
+ import "../out/worldpay-jsc-origin.js";
5
6
  import { onceGetCheckoutInfo } from "../api/modules/checkout/index.js";
6
7
  const querySession = async (params, extraParams = {}, options) => {
7
8
  return onceGetCheckoutInfo(params, extraParams, options);
@@ -35,6 +35,7 @@ class Session {
35
35
  __privateAdd(this, _initCheckout);
36
36
  __publicField(this, "sessionId");
37
37
  __publicField(this, "clientKey");
38
+ __publicField(this, "paykkaDetectionKey");
38
39
  __publicField(this, "checkout");
39
40
  __publicField(this, "theme", d({}));
40
41
  __publicField(this, "extraParams", {});
@@ -62,7 +63,6 @@ init_fn = async function() {
62
63
  };
63
64
  _initCheckout = new WeakSet();
64
65
  initCheckout_fn = async function() {
65
- var _a;
66
66
  this.checkout = await querySession(
67
67
  {
68
68
  sessionId: this.sessionId,
@@ -70,7 +70,11 @@ initCheckout_fn = async function() {
70
70
  },
71
71
  this.extraParams
72
72
  );
73
- this.sessionId = (_a = this.checkout) == null ? void 0 : _a.sessionId;
73
+ const { sessionId, clientKey } = this.checkout || {};
74
+ this.sessionId = sessionId;
75
+ if (clientKey) {
76
+ this.paykkaDetectionKey = clientKey;
77
+ }
74
78
  };
75
79
  export {
76
80
  Session
@@ -25,7 +25,6 @@ import "../utils/system-info/get-browser-info.js";
25
25
  import { generateColors } from "../utils/colors.js";
26
26
  import { loadStyle } from "../utils/style.js";
27
27
  import { getThemeText } from "../utils/theme.js";
28
- import "../api/http.js";
29
28
  import "../out/worldpay-jsc-origin.js";
30
29
  class PayKKaTheme {
31
30
  constructor(checkoutId) {