@paykka/card-checkout-ui 0.7.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 (72) 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/modules/checkout/map.js +11 -0
  4. package/dist/es/components/AliPay/index.js +39 -29
  5. package/dist/es/components/ApplePay/index.js +14 -7
  6. package/dist/es/components/Card/index.js +42 -39
  7. package/dist/es/components/DropIn/index.js +210 -0
  8. package/dist/es/components/GooglePay/index.js +11 -4
  9. package/dist/es/components/Sepa/index.js +5 -3
  10. package/dist/es/components/WechatPay/index.js +26 -17
  11. package/dist/es/components/index.js +1 -0
  12. package/dist/es/components/internal/Modal/Modal.js +1 -1
  13. package/dist/es/components/internal/icons/IconCard.js +42 -0
  14. package/dist/es/constant.js +10 -0
  15. package/dist/es/core/PayKKaCheckout.js +10 -0
  16. package/dist/es/hooks/usePayState.js +3 -1
  17. package/dist/es/i18n/locales/de-DE.js +3 -0
  18. package/dist/es/i18n/locales/en-GB.js +3 -0
  19. package/dist/es/i18n/locales/es-ES.js +3 -0
  20. package/dist/es/i18n/locales/fr-FR.js +3 -0
  21. package/dist/es/i18n/locales/ja-JP.js +3 -0
  22. package/dist/es/i18n/locales/ko-KR.js +3 -0
  23. package/dist/es/i18n/locales/pt-PT.js +3 -0
  24. package/dist/es/i18n/locales/ru-RU.js +3 -0
  25. package/dist/es/i18n/locales/zh-CN.js +3 -0
  26. package/dist/es/i18n/locales/zh-HK.js +3 -0
  27. package/dist/es/i18n/locales/zh-TW.js +3 -0
  28. package/dist/es/i18n/util.js +11 -0
  29. package/dist/es/index.js +4 -0
  30. package/dist/es/style.css +103 -7
  31. package/dist/style.css +1 -1
  32. package/dist/types/api/modules/checkout/map.d.ts +2 -1
  33. package/dist/types/api/modules/checkout/type.d.ts +11 -2
  34. package/dist/types/components/AliPay/AliPay.d.ts +2 -1
  35. package/dist/types/components/AliPay/type.d.ts +1 -2
  36. package/dist/types/components/ApplePay/ApplePay.d.ts +2 -1
  37. package/dist/types/components/ApplePay/type.d.ts +9 -6
  38. package/dist/types/components/Card/Card.d.ts +2 -1
  39. package/dist/types/components/Card/type.d.ts +2 -2
  40. package/dist/types/components/DropIn/DropIn.d.ts +6 -0
  41. package/dist/types/components/DropIn/components/PaymentTabs/PaymentTabs.d.ts +3 -0
  42. package/dist/types/components/DropIn/components/PaymentTabs/index.d.ts +2 -0
  43. package/dist/types/components/DropIn/components/PaymentTabs/type.d.ts +11 -0
  44. package/dist/types/components/DropIn/index.d.ts +2 -0
  45. package/dist/types/components/DropIn/type.d.ts +49 -0
  46. package/dist/types/components/GooglePay/GooglePay.d.ts +2 -1
  47. package/dist/types/components/GooglePay/type.d.ts +20 -9
  48. package/dist/types/components/Sepa/Sepa.d.ts +2 -1
  49. package/dist/types/components/Sepa/type.d.ts +1 -2
  50. package/dist/types/components/WechatPay/WechatPay.d.ts +2 -1
  51. package/dist/types/components/WechatPay/type.d.ts +1 -2
  52. package/dist/types/components/index.d.ts +1 -0
  53. package/dist/types/components/internal/Modal/index.d.ts +2 -0
  54. package/dist/types/components/internal/Modal/type.d.ts +1 -1
  55. package/dist/types/components/internal/icons/IconCard.d.ts +2 -0
  56. package/dist/types/components/internal/icons/index.d.ts +1 -0
  57. package/dist/types/constant.d.ts +11 -0
  58. package/dist/types/core/PayKKaCheckout.d.ts +1 -0
  59. package/dist/types/i18n/locales/de-DE.d.ts +2 -0
  60. package/dist/types/i18n/locales/en-GB.d.ts +2 -0
  61. package/dist/types/i18n/locales/es-ES.d.ts +2 -0
  62. package/dist/types/i18n/locales/fr-FR.d.ts +2 -0
  63. package/dist/types/i18n/locales/ja-JP.d.ts +2 -0
  64. package/dist/types/i18n/locales/ko-KR.d.ts +2 -0
  65. package/dist/types/i18n/locales/pt-PT.d.ts +2 -0
  66. package/dist/types/i18n/locales/ru-RU.d.ts +2 -0
  67. package/dist/types/i18n/locales/zh-CN.d.ts +2 -0
  68. package/dist/types/i18n/locales/zh-HK.d.ts +2 -0
  69. package/dist/types/i18n/locales/zh-TW.d.ts +2 -0
  70. package/dist/types/i18n/util.d.ts +5 -0
  71. package/dist/types/types/index.d.ts +24 -4
  72. package/package.json +63 -63
@@ -32,6 +32,15 @@ function formatPaymentMethodInfo(paymentMethods = []) {
32
32
  channelParams
33
33
  };
34
34
  }
35
+ function formatAmountBreakdown(info = {}) {
36
+ return {
37
+ goodsTax: info.goods_tax,
38
+ shippingAmount: info.shipping_amount,
39
+ shippingTax: info.shipping_tax,
40
+ discount: info.discount,
41
+ other: info.other
42
+ };
43
+ }
35
44
  function checkoutMap(res = {}) {
36
45
  var _a, _b, _c;
37
46
  const { theme, bill, payment_methods, field } = res;
@@ -47,6 +56,7 @@ function checkoutMap(res = {}) {
47
56
  sessionMode,
48
57
  merchantName: (_a = res.theme) == null ? void 0 : _a.merchant_name,
49
58
  returnUrl: res.return_url,
59
+ cancelUrl: res.cancel_url,
50
60
  locale: res.locale,
51
61
  paymentType: res.payment_type,
52
62
  goods: res.goods ? res.goods : [],
@@ -86,6 +96,7 @@ function checkoutMap(res = {}) {
86
96
  required: !!(field == null ? void 0 : field.bill_address_required)
87
97
  }
88
98
  },
99
+ amountBreakdown: formatAmountBreakdown(res.amount_breakdown),
89
100
  ...paymentMethodsInfo
90
101
  };
91
102
  }
@@ -4,8 +4,8 @@ import { getAliPayInfo, aliPay } from "../../api/modules/ali-pay/index.js";
4
4
  import { isUndefined } from "../../utils/is.js";
5
5
  import "../../utils/card-brand/brands.js";
6
6
  import "../../utils/system-info/get-browser-info.js";
7
- import { formatAmount } from "../../utils/format.js";
8
- import { PaymentType } from "../../constant.js";
7
+ import { cssVarPrefix, normalizedClass, formatAmount } from "../../utils/format.js";
8
+ import { COMMON_CLASS_NAME, PaymentType } from "../../constant.js";
9
9
  import { CoreContext } from "../../core/context.js";
10
10
  import { PayKKaError } from "../../core/error.js";
11
11
  import { createAddressCore } from "../../core/Address.js";
@@ -23,6 +23,7 @@ import { RecurringTip } from "../RecurringTip/index.js";
23
23
  import { SubmitButton } from "../SubmitButton/index.js";
24
24
  const { bem } = useBEM("ali-pay");
25
25
  const AliPay = w((props, ref) => {
26
+ var _a, _b, _c, _d, _e, _f, _g, _h;
26
27
  const { session } = props;
27
28
  let addressState = createAddressCore();
28
29
  let emailState = createEmailCore();
@@ -56,19 +57,19 @@ const AliPay = w((props, ref) => {
56
57
  startReFetchPayInfo({ timeout });
57
58
  },
58
59
  updateAddress: () => {
59
- var _a;
60
+ var _a2;
60
61
  setForm(Object.assign(form, { address: addressState.getAddressState() }));
61
- (_a = addressFieldRef.current) == null ? void 0 : _a.update(addressState.getAddressState());
62
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
62
63
  },
63
64
  updateEmail: () => {
64
- var _a;
65
+ var _a2;
65
66
  setForm(Object.assign(form, { email: emailState.email }));
66
- (_a = emailFieldRef.current) == null ? void 0 : _a.update(emailState.email);
67
+ (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
67
68
  }
68
69
  }));
69
70
  function validateForm() {
70
- var _a;
71
- (_a = formRef.current) == null ? void 0 : _a.validate(void 0, false).then(() => {
71
+ var _a2;
72
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
72
73
  setValidated(true);
73
74
  }).catch(() => {
74
75
  setValidated(false);
@@ -78,11 +79,11 @@ const AliPay = w((props, ref) => {
78
79
  validateForm();
79
80
  }, [form]);
80
81
  y(() => {
81
- var _a;
82
+ var _a2;
82
83
  if (sessionReady) {
83
84
  if ((session == null ? void 0 : session.checkout.status) === "SUCCESS") {
84
85
  setSubmitButtonStatus("success");
85
- (_a = props.onSuccess) == null ? void 0 : _a.call(props);
86
+ (_a2 = props.onSuccess) == null ? void 0 : _a2.call(props);
86
87
  }
87
88
  form.email = (session == null ? void 0 : session.checkout.bill.email) ?? "";
88
89
  disabledEmail.current = !!(session == null ? void 0 : session.checkout.bill.email);
@@ -93,10 +94,10 @@ const AliPay = w((props, ref) => {
93
94
  }
94
95
  }, [sessionReady]);
95
96
  const onTimeout = q((message) => {
96
- var _a;
97
+ var _a2;
97
98
  setErrorMsg(message || i18n.get("common.payTimeout"));
98
99
  setSubmitButtonStatus("unSubmit");
99
- (_a = props.onTimeout) == null ? void 0 : _a.call(props, "retry");
100
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
100
101
  }, [i18n, props.onTimeout]);
101
102
  const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
102
103
  (timeout) => pay(true, timeout),
@@ -105,7 +106,7 @@ const AliPay = w((props, ref) => {
105
106
  }
106
107
  );
107
108
  async function pay(search = false, timeout) {
108
- var _a, _b, _c, _d, _e, _f, _g, _h;
109
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
109
110
  try {
110
111
  const res = search ? await getAliPayInfo(
111
112
  {
@@ -132,20 +133,20 @@ const AliPay = w((props, ref) => {
132
133
  { locale: i18n.locale, timeout }
133
134
  );
134
135
  const { status, orderStatus, errorMessage, errorCode } = res;
135
- !search && ((_a = props.onSubmitResponse) == null ? void 0 : _a.call(props, res));
136
+ !search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
136
137
  if (status === "PROCESSING") {
137
138
  if (!orderStatus) {
138
139
  setSubmitButtonStatus("unSubmit");
139
140
  } else if (orderStatus === "SUCCESS") {
140
141
  setSubmitButtonStatus("success");
141
- (_b = props.onSuccess) == null ? void 0 : _b.call(props);
142
+ (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
142
143
  return {
143
144
  end: true
144
145
  };
145
146
  } else if (orderStatus === "FAILURE") {
146
147
  setErrorMsg(errorMessage);
147
148
  setSubmitButtonStatus("unSubmit");
148
- (_c = props.onError) == null ? void 0 : _c.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
149
+ (_c2 = props.onError) == null ? void 0 : _c2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
149
150
  return {
150
151
  end: true
151
152
  };
@@ -156,26 +157,26 @@ const AliPay = w((props, ref) => {
156
157
  };
157
158
  } else if (orderStatus === "CANCELED") {
158
159
  setSubmitButtonStatus("unSubmit");
159
- (_d = props.onTimeout) == null ? void 0 : _d.call(props, "channel");
160
+ (_d2 = props.onTimeout) == null ? void 0 : _d2.call(props, "channel");
160
161
  return {
161
162
  end: true
162
163
  };
163
164
  }
164
165
  } else if (status === "SUCCESS") {
165
166
  setSubmitButtonStatus("success");
166
- (_e = props.onSuccess) == null ? void 0 : _e.call(props);
167
+ (_e2 = props.onSuccess) == null ? void 0 : _e2.call(props);
167
168
  return {
168
169
  end: true
169
170
  };
170
171
  } else if (status === "EXPIRED") {
171
172
  setSubmitButtonStatus("unSubmit");
172
- (_f = props.onExpired) == null ? void 0 : _f.call(props);
173
+ (_f2 = props.onExpired) == null ? void 0 : _f2.call(props);
173
174
  return {
174
175
  end: true
175
176
  };
176
177
  }
177
178
  setSubmitButtonStatus("unSubmit");
178
- (_g = props.onSuccess) == null ? void 0 : _g.call(props);
179
+ (_g2 = props.onSuccess) == null ? void 0 : _g2.call(props);
179
180
  return {
180
181
  end: true
181
182
  };
@@ -190,19 +191,19 @@ const AliPay = w((props, ref) => {
190
191
  } else {
191
192
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
192
193
  setErrorMsg(message);
193
- (_h = props.onError) == null ? void 0 : _h.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
194
+ (_h2 = props.onError) == null ? void 0 : _h2.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
194
195
  setSubmitButtonStatus("unSubmit");
195
196
  return { end: true };
196
197
  }
197
198
  }
198
199
  }
199
200
  async function onSubmit() {
200
- var _a;
201
+ var _a2;
201
202
  setErrorMsg("");
202
- (_a = formRef.current) == null ? void 0 : _a.validate(async (errors) => {
203
- var _a2;
203
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
204
+ var _a3;
204
205
  requiredBill && addressState.setValidateAllFields(true);
205
- (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props, errors);
206
+ (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
206
207
  if (errors) {
207
208
  setSubmitButtonStatus("unSubmit");
208
209
  return;
@@ -215,9 +216,10 @@ const AliPay = w((props, ref) => {
215
216
  const Button = () => {
216
217
  const { transAmount } = (session == null ? void 0 : session.checkout) ?? {};
217
218
  let { symbol = "", amount = "", digits } = transAmount ?? {};
219
+ let amountStr = "";
218
220
  if (amount && !isUndefined(digits))
219
- amount = formatAmount(+amount, digits);
220
- const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amount}` : "");
221
+ amountStr = formatAmount(+amount, digits);
222
+ const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amountStr}` : "");
221
223
  return /* @__PURE__ */ u(
222
224
  SubmitButton,
223
225
  {
@@ -235,6 +237,13 @@ const AliPay = w((props, ref) => {
235
237
  formRef.current = dom;
236
238
  dom && validateForm();
237
239
  };
240
+ const formStyle = {
241
+ [cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
242
+ [cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
243
+ [cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
244
+ [cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
245
+ [cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
246
+ };
238
247
  return /* @__PURE__ */ u(
239
248
  CoreContext.Provider,
240
249
  {
@@ -242,7 +251,7 @@ const AliPay = w((props, ref) => {
242
251
  i18n,
243
252
  session
244
253
  },
245
- children: sessionReady && i18n.ready.value && /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: [
254
+ children: sessionReady && 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: [
246
255
  /* @__PURE__ */ u(
247
256
  EmailField,
248
257
  {
@@ -257,13 +266,14 @@ const AliPay = w((props, ref) => {
257
266
  {
258
267
  ref: addressFieldRef,
259
268
  value: form.address,
269
+ 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),
260
270
  onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
261
271
  }
262
272
  ),
263
273
  (session == null ? void 0 : session.checkout.paymentType) === PaymentType.RECURRING && RecurringTip(),
264
274
  !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
265
275
  Button()
266
- ] })
276
+ ] }) })
267
277
  }
268
278
  );
269
279
  });
@@ -1,6 +1,6 @@
1
1
  import { w, h, y, q, 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 { getApplePayInfo, applePay, getMerchantSession } from "../../api/modules/apple-pay/index.js";
6
6
  import { useBEM } from "../../hooks/useBEM.js";
@@ -43,7 +43,7 @@ async function applePayEnv(id) {
43
43
  }
44
44
  const { bem } = useBEM("apple-pay");
45
45
  const ApplePay = w((props) => {
46
- const { session } = props;
46
+ const { session, isDropIn } = props;
47
47
  let applePaySession;
48
48
  const { i18n, sessionReady, fraudDetection } = usePayState(session);
49
49
  const [errorMsg, setErrorMsg] = h("");
@@ -52,19 +52,26 @@ const ApplePay = w((props) => {
52
52
  returnUrl: session == null ? void 0 : session.checkout.returnUrl
53
53
  });
54
54
  y(() => {
55
- var _a;
55
+ var _a, _b, _c;
56
56
  if (!sessionReady) {
57
57
  return;
58
58
  }
59
- const { status, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
59
+ const { status, paymentMethod = [], sessionMode } = (session == null ? void 0 : session.checkout) || {};
60
+ if (sessionMode === SessionMode.DROP_IN && !isDropIn) {
61
+ (_b = (_a = props.core.config).onInitError) == null ? void 0 : _b.call(
62
+ _a,
63
+ new PayKKaError("ERROR", "Please send the correct mode when creating the checkout")
64
+ );
65
+ return;
66
+ }
60
67
  if (!paymentMethod.includes(PaymentMethod.APPLE_PAY)) {
61
68
  return;
62
69
  }
63
70
  loadApplePayJS(
64
71
  async () => {
65
- var _a2, _b, _c, _d;
72
+ var _a2, _b2, _c2, _d;
66
73
  const envSupported = await applePayEnv(
67
- (_c = (_b = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.channelParams) == null ? void 0 : _b.applePay) == null ? void 0 : _c.merchantIdentifier
74
+ (_c2 = (_b2 = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.channelParams) == null ? void 0 : _b2.applePay) == null ? void 0 : _c2.merchantIdentifier
68
75
  );
69
76
  if (!envSupported) {
70
77
  return;
@@ -79,7 +86,7 @@ const ApplePay = w((props) => {
79
86
  }
80
87
  );
81
88
  if (status === "SUCCESS") {
82
- (_a = props.onSuccess) == null ? void 0 : _a.call(props, getPaymentSuccessData());
89
+ (_c = props.onSuccess) == null ? void 0 : _c.call(props, getPaymentSuccessData());
83
90
  }
84
91
  }, [sessionReady]);
85
92
  const onTimeout = q(
@@ -1,6 +1,6 @@
1
1
  import { w, A, h, F, y, q, T, u, b } from "../../core.js";
2
2
  import { isTimeoutError } from "../../api/http.js";
3
- import { PaymentType, SessionMode, COMMON_CLASS_NAME, CardPaymentMethods, PaymentMethod } from "../../constant.js";
3
+ import { PaymentType, SessionMode, CardPaymentMethods, COMMON_CLASS_NAME, PaymentMethod } from "../../constant.js";
4
4
  import { getBrowserParams } from "../../api/modules/get-browser-params.js";
5
5
  import { getCardPayInfo, cardPay } from "../../api/modules/card/index.js";
6
6
  import { CoreContext } from "../../core/context.js";
@@ -32,11 +32,11 @@ import { EFieldType, SecuredFieldsProvider } from "../SecuredFieldsProvider/inde
32
32
  import { SubmitButton } from "../SubmitButton/index.js";
33
33
  import { ThreeDSAuth } from "../ThreeDS/index.js";
34
34
  import { CombinedCardInfo } from "../CombinedCardInfo/index.js";
35
- import { cssVarPrefix, normalizedClass, trimAll, formatAmount } from "../../utils/format.js";
36
35
  import { cardBrandCodes } from "../../utils/card-brand/brands.js";
37
36
  import { findCardBrand } from "../../utils/card-brand/index.js";
38
37
  import { separateInputStyle } from "../../utils/style.js";
39
38
  import { createPromise } from "../../utils/create-promise.js";
39
+ import { cssVarPrefix, normalizedClass, trimAll, formatAmount } from "../../utils/format.js";
40
40
  import { isUndefined } from "../../utils/is.js";
41
41
  const { bem } = useBEM("card");
42
42
  const fieldClassNames = bem("field");
@@ -51,7 +51,8 @@ const Card = w((props, ref) => {
51
51
  showAddress = false,
52
52
  threeDSFrame,
53
53
  styles,
54
- enable3DSModal = true
54
+ enable3DSModal = true,
55
+ isDropIn
55
56
  } = props;
56
57
  let addressState = createAddressCore();
57
58
  let emailState = createEmailCore();
@@ -139,10 +140,18 @@ const Card = w((props, ref) => {
139
140
  input && setInputStyle(input);
140
141
  };
141
142
  y(() => {
143
+ var _a2, _b2;
142
144
  if (!sessionReady) {
143
145
  return;
144
146
  }
145
147
  const { status, paymentMethod = [], bill = {}, sessionMode } = (session == null ? void 0 : session.checkout) || {};
148
+ if (sessionMode === SessionMode.DROP_IN && !isDropIn) {
149
+ (_b2 = (_a2 = props.core.config).onInitError) == null ? void 0 : _b2.call(
150
+ _a2,
151
+ new PayKKaError("ERROR", "Please send the correct mode when creating the checkout")
152
+ );
153
+ return;
154
+ }
146
155
  if (!intersection(paymentMethod, CardPaymentMethods).length) {
147
156
  return;
148
157
  }
@@ -150,12 +159,7 @@ const Card = w((props, ref) => {
150
159
  initElementStyles();
151
160
  setSecurity(sessionMode !== SessionMode.HOSTED);
152
161
  form.email = bill.email ?? "";
153
- setSupportedCardBrands(
154
- cardBrandCodes.filter((code) => {
155
- var _a2;
156
- return (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.paymentMethod.includes(code);
157
- })
158
- );
162
+ setSupportedCardBrands(intersection(cardBrandCodes, paymentMethod || []));
159
163
  setIsCheckoutEnabled(true);
160
164
  if (status === "SUCCESS") {
161
165
  setSubmitButtonStatus("success");
@@ -384,9 +388,10 @@ const Card = w((props, ref) => {
384
388
  const Button = () => {
385
389
  const { transAmount } = (session == null ? void 0 : session.checkout) ?? {};
386
390
  let { symbol = "", amount = "", digits } = transAmount ?? {};
391
+ let amountStr = "";
387
392
  if (amount && !isUndefined(digits))
388
- amount = formatAmount(+amount, digits);
389
- const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amount}` : "");
393
+ amountStr = formatAmount(+amount, digits);
394
+ const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amountStr}` : "");
390
395
  return /* @__PURE__ */ u(
391
396
  SubmitButton,
392
397
  {
@@ -400,7 +405,7 @@ const Card = w((props, ref) => {
400
405
  }
401
406
  );
402
407
  };
403
- const cardStyle = {
408
+ const formStyle = {
404
409
  [cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
405
410
  [cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
406
411
  [cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
@@ -704,7 +709,7 @@ const Card = w((props, ref) => {
704
709
  }, [splitCardInfo, security]);
705
710
  const cardForm = () => {
706
711
  var _a2;
707
- return /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: cardStyle, children: [
712
+ return /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: formStyle, children: [
708
713
  Email(),
709
714
  CardInfo(),
710
715
  (fieldStatus == null ? void 0 : fieldStatus.holderName.show) && /* @__PURE__ */ u("div", { className: bem("holder-name"), children: /* @__PURE__ */ u(CardHolderNameField, { disabled: fieldStatus == null ? void 0 : fieldStatus.holderName.disabled }) }),
@@ -717,36 +722,34 @@ const Card = w((props, ref) => {
717
722
  };
718
723
  const fastPaymentCardForm = () => {
719
724
  var _a2, _b2, _c2, _d2;
720
- return /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: [
721
- /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: cardStyle, children: [
722
- Email(),
723
- /* @__PURE__ */ u("div", { className: bem("card-selector-wrapper"), children: [
724
- /* @__PURE__ */ u(
725
- CardSelector,
726
- {
727
- value: (_c2 = (_b2 = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.tokens) == null ? void 0 : _b2[0]) == null ? void 0 : _c2.token,
728
- cardList: (_d2 = session == null ? void 0 : session.checkout) == null ? void 0 : _d2.tokens,
729
- onClickEdit: onEditOtherCard,
730
- onClickChange: onClickChangeCard,
731
- onCardChange,
732
- style: { flex: 2, marginRight: "12px" }
733
- }
734
- ),
735
- /* @__PURE__ */ u(
736
- CardSecurityCodeField,
737
- {
738
- className: fieldClassNames,
739
- style: { flex: 1, marginLeft: "12px" },
740
- security,
741
- ref: cardSecurityCodeFieldRef
742
- }
743
- )
744
- ] })
725
+ return /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: formStyle, children: [
726
+ Email(),
727
+ /* @__PURE__ */ u("div", { className: bem("card-selector-wrapper"), children: [
728
+ /* @__PURE__ */ u(
729
+ CardSelector,
730
+ {
731
+ value: (_c2 = (_b2 = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.tokens) == null ? void 0 : _b2[0]) == null ? void 0 : _c2.token,
732
+ cardList: (_d2 = session == null ? void 0 : session.checkout) == null ? void 0 : _d2.tokens,
733
+ onClickEdit: onEditOtherCard,
734
+ onClickChange: onClickChangeCard,
735
+ onCardChange,
736
+ style: { flex: 2, marginRight: "12px" }
737
+ }
738
+ ),
739
+ /* @__PURE__ */ u(
740
+ CardSecurityCodeField,
741
+ {
742
+ className: fieldClassNames,
743
+ style: { flex: 1, marginLeft: "12px" },
744
+ security,
745
+ ref: cardSecurityCodeFieldRef
746
+ }
747
+ )
745
748
  ] }),
746
749
  tokenAddressFilled && Address(),
747
750
  ErrorMessage(),
748
751
  !hidePaymentButton && Button()
749
- ] });
752
+ ] }) });
750
753
  };
751
754
  return /* @__PURE__ */ u(CoreContext.Provider, { value: { i18n }, children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
752
755
  /* @__PURE__ */ u(
@@ -0,0 +1,210 @@
1
+ import { u, w, h, A, F, y, b } from "../../core.js";
2
+ import "../../utils/card-brand/brands.js";
3
+ import "../../utils/system-info/get-browser-info.js";
4
+ import { CoreContext } from "../../core/context.js";
5
+ import { CardPaymentMethods, PaymentMethod, PaymentCategory, SessionMode } from "../../constant.js";
6
+ import { Card } from "../Card/index.js";
7
+ import { ApplePay } from "../ApplePay/index.js";
8
+ import { GooglePay } from "../GooglePay/index.js";
9
+ import { useBEM } from "../../hooks/useBEM.js";
10
+ import { intersection } from "../../utils/index.js";
11
+ import { PayKKaError } from "../../core/error.js";
12
+ import { usePayState } from "../../hooks/usePayState.js";
13
+ import { IconCard } from "../internal/icons/IconCard.js";
14
+ const dropInSupportedPaymentMethods = [
15
+ ...CardPaymentMethods,
16
+ PaymentMethod.GOOGLE_PAY,
17
+ PaymentMethod.APPLE_PAY
18
+ ];
19
+ const PaymentComponentMap = {
20
+ [PaymentCategory.CARD]: Card,
21
+ [PaymentCategory.APPLE_PAY]: ApplePay,
22
+ [PaymentCategory.GOOGLE_PAY]: GooglePay
23
+ // [PaymentCategory.WECHAT_PAY]: WechatPay,
24
+ // [PaymentCategory.ALI_PAY]: AliPay,
25
+ // [PaymentCategory.SEPA_DEBIT]: Sepa
26
+ };
27
+ const { bem: bem$1 } = useBEM("payment-tabs");
28
+ const PaymentTabs = (props) => {
29
+ const { value, tabs, themeColor = "#4F43DF" } = props;
30
+ const handleClickTab = (tab) => {
31
+ var _a;
32
+ if (tab.type === value) {
33
+ return;
34
+ }
35
+ (_a = props.onChange) == null ? void 0 : _a.call(props, tab.type);
36
+ };
37
+ return /* @__PURE__ */ u("div", { className: bem$1(), children: tabs.map((tab) => /* @__PURE__ */ u(
38
+ "div",
39
+ {
40
+ className: bem$1("tab"),
41
+ style: tab.type === value ? { borderColor: themeColor } : "",
42
+ onClick: () => handleClickTab(tab),
43
+ children: [
44
+ tab.icon,
45
+ /* @__PURE__ */ u(
46
+ "div",
47
+ {
48
+ className: bem$1("name"),
49
+ style: tab.type === value ? { color: themeColor } : "",
50
+ children: tab.name
51
+ }
52
+ )
53
+ ]
54
+ }
55
+ )) });
56
+ };
57
+ const { bem } = useBEM("drop-in");
58
+ const DropIn = w((props, ref) => {
59
+ const { paymentMethods: paymentMethodsConfig, layout = "tabs", session } = props;
60
+ const { i18n, sessionReady } = usePayState(session);
61
+ const [paymentCategoryOptions, setPaymentCategoryOptions] = h([]);
62
+ const [activePaymentCategory, setActivePaymentCategory] = h(
63
+ null
64
+ );
65
+ const [headerPaymentCategories, setHeaderPaymentCategories] = h(
66
+ []
67
+ );
68
+ const [paymentCategories, setPaymentCategories] = h([]);
69
+ const componentMountRefMap = A({});
70
+ const componentInstMap = A({});
71
+ F(ref, () => ({
72
+ payment: () => {
73
+ var _a, _b;
74
+ if (activePaymentCategory) {
75
+ const instRef = (_a = componentInstMap.current[activePaymentCategory]) == null ? void 0 : _a.ref;
76
+ (_b = instRef == null ? void 0 : instRef.payment) == null ? void 0 : _b.call(instRef);
77
+ }
78
+ }
79
+ }));
80
+ y(() => {
81
+ if (!activePaymentCategory) {
82
+ return;
83
+ }
84
+ if (componentInstMap.current[activePaymentCategory]) {
85
+ return;
86
+ }
87
+ renderComponent(activePaymentCategory);
88
+ }, [activePaymentCategory]);
89
+ y(() => {
90
+ if (headerPaymentCategories == null ? void 0 : headerPaymentCategories.length) {
91
+ renderComponent(PaymentCategory.APPLE_PAY);
92
+ renderComponent(PaymentCategory.GOOGLE_PAY);
93
+ }
94
+ }, [headerPaymentCategories]);
95
+ const createComponent = (category) => {
96
+ const { onError, onSuccess, onTimeout, onExpired, onSubmit } = props;
97
+ return props.core.create(PaymentComponentMap[category], {
98
+ onError,
99
+ onSuccess,
100
+ onTimeout,
101
+ onExpired,
102
+ onSubmit,
103
+ ...paymentMethodsConfig == null ? void 0 : paymentMethodsConfig[category],
104
+ isDropIn: true
105
+ });
106
+ };
107
+ const renderComponent = (category) => {
108
+ const inst = createComponent(category);
109
+ const container = componentMountRefMap.current[category];
110
+ if (container) {
111
+ inst.mount(container);
112
+ componentInstMap.current[category] = inst;
113
+ }
114
+ };
115
+ const initPaymentCategories = (enablePaymentMethods) => {
116
+ const paymentCategoryOptions2 = [];
117
+ const paymentCategories2 = [];
118
+ const headerPaymentCategories2 = [];
119
+ if (enablePaymentMethods.includes(PaymentMethod.APPLE_PAY)) {
120
+ if (layout === "tabs") {
121
+ headerPaymentCategories2.push(PaymentCategory.APPLE_PAY);
122
+ } else {
123
+ paymentCategories2.push(PaymentCategory.APPLE_PAY);
124
+ }
125
+ }
126
+ if (enablePaymentMethods.includes(PaymentMethod.GOOGLE_PAY)) {
127
+ if (layout === "tabs") {
128
+ headerPaymentCategories2.push(PaymentCategory.GOOGLE_PAY);
129
+ } else {
130
+ paymentCategories2.push(PaymentCategory.APPLE_PAY);
131
+ }
132
+ }
133
+ const isCardEnable = !!intersection(enablePaymentMethods, CardPaymentMethods).length;
134
+ if (isCardEnable) {
135
+ paymentCategories2.push(PaymentCategory.CARD);
136
+ paymentCategoryOptions2.push({
137
+ type: PaymentCategory.CARD,
138
+ name: i18n.get("dropIn.card.label"),
139
+ icon: /* @__PURE__ */ u(IconCard, { size: 16 })
140
+ });
141
+ }
142
+ if (paymentCategoryOptions2.length) {
143
+ setPaymentCategoryOptions(paymentCategoryOptions2);
144
+ setActivePaymentCategory(paymentCategoryOptions2[0].type);
145
+ }
146
+ setHeaderPaymentCategories(headerPaymentCategories2);
147
+ setPaymentCategories(paymentCategories2);
148
+ };
149
+ const handlePaymentCategoryChange = (newPaymentCategory) => {
150
+ setActivePaymentCategory(newPaymentCategory);
151
+ };
152
+ y(() => {
153
+ var _a, _b, _c;
154
+ if (!sessionReady || !i18n.ready.value) {
155
+ return;
156
+ }
157
+ if (((_a = session.checkout) == null ? void 0 : _a.sessionMode) === SessionMode.COMPONENT) {
158
+ (_c = (_b = props.core.config).onInitError) == null ? void 0 : _c.call(
159
+ _b,
160
+ new PayKKaError("ERROR", "Please send the correct mode when creating the checkout")
161
+ );
162
+ return;
163
+ }
164
+ const { paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
165
+ const enablePaymentMethods = intersection(
166
+ paymentMethod,
167
+ dropInSupportedPaymentMethods
168
+ );
169
+ if (!enablePaymentMethods.length) {
170
+ return;
171
+ }
172
+ initPaymentCategories(enablePaymentMethods);
173
+ }, [sessionReady, i18n.ready.value]);
174
+ return /* @__PURE__ */ u(CoreContext.Provider, { value: { i18n }, children: i18n.ready.value && /* @__PURE__ */ u("div", { className: bem(), children: layout === "accordion" ? /* @__PURE__ */ u(b, {}) : /* @__PURE__ */ u(b, { children: [
175
+ headerPaymentCategories == null ? void 0 : headerPaymentCategories.map((category) => /* @__PURE__ */ u(
176
+ "div",
177
+ {
178
+ className: bem("header-payment"),
179
+ ref: (el) => componentMountRefMap.current[category] = el
180
+ }
181
+ )),
182
+ !!paymentCategoryOptions.length && activePaymentCategory && /* @__PURE__ */ u(b, { children: [
183
+ !!(headerPaymentCategories == null ? void 0 : headerPaymentCategories.length) && /* @__PURE__ */ u("div", { className: bem("other"), children: [
184
+ /* @__PURE__ */ u("div", { className: bem("other-line") }),
185
+ /* @__PURE__ */ u("div", { className: bem("other-text"), children: i18n.get("dropIn.otherPaymentMethod") }),
186
+ /* @__PURE__ */ u("div", { className: bem("other-line") })
187
+ ] }),
188
+ /* @__PURE__ */ u("div", { className: bem("tabs-wrapper"), children: /* @__PURE__ */ u(
189
+ PaymentTabs,
190
+ {
191
+ value: activePaymentCategory,
192
+ tabs: paymentCategoryOptions,
193
+ onChange: (item) => handlePaymentCategoryChange(item)
194
+ }
195
+ ) }),
196
+ paymentCategories == null ? void 0 : paymentCategories.map((category) => /* @__PURE__ */ u(
197
+ "div",
198
+ {
199
+ style: { display: category === activePaymentCategory ? "block" : "none" },
200
+ ref: (el) => componentMountRefMap.current[category] = el
201
+ }
202
+ ))
203
+ ] })
204
+ ] }) }) });
205
+ });
206
+ export {
207
+ DropIn,
208
+ PaymentComponentMap,
209
+ dropInSupportedPaymentMethods
210
+ };