@paykka/card-checkout-ui 0.8.0 → 0.9.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 (247) hide show
  1. package/dist/card-checkout-ui.js +20 -13
  2. package/dist/card-checkout-ui.umd.cjs +20 -13
  3. package/dist/es/_commonjsHelpers.js +1 -0
  4. package/dist/es/api/http.js +19 -21
  5. package/dist/es/api/index.js +1 -0
  6. package/dist/es/api/modules/ali-pay/index.js +19 -11
  7. package/dist/es/api/modules/apple-pay/index.js +10 -26
  8. package/dist/es/api/modules/boost/index.js +56 -0
  9. package/dist/es/api/modules/card/index.js +17 -11
  10. package/dist/es/api/modules/checkout/index.js +6 -6
  11. package/dist/es/api/modules/checkout/map.js +23 -6
  12. package/dist/es/api/modules/gcash/index.js +56 -0
  13. package/dist/es/api/modules/get-browser-params.js +2 -2
  14. package/dist/es/api/modules/google-pay/index.js +10 -26
  15. package/dist/es/api/modules/grab-pay/index.js +56 -0
  16. package/dist/es/api/modules/index.js +1 -0
  17. package/dist/es/api/modules/line-pay/index.js +56 -0
  18. package/dist/es/api/modules/may-bank-qr-pay/index.js +56 -0
  19. package/dist/es/api/modules/nine-pay/index.js +56 -0
  20. package/dist/es/api/modules/paymaya/index.js +56 -0
  21. package/dist/es/api/modules/sepa/index.js +19 -11
  22. package/dist/es/api/modules/shopee-pay/index.js +56 -0
  23. package/dist/es/api/modules/tng-wallet/index.js +56 -0
  24. package/dist/es/api/modules/wechat-pay/index.js +18 -31
  25. package/dist/es/components/AccordionItem/AccordionItem.js +36 -0
  26. package/dist/es/components/AliPay/index.js +27 -39
  27. package/dist/es/components/ApplePay/index.js +16 -37
  28. package/dist/es/components/Boost/index.js +322 -0
  29. package/dist/es/components/Card/index.js +52 -41
  30. package/dist/es/components/CardBrands/index.js +2 -2
  31. package/dist/es/components/CardNumberField/index.js +113 -106
  32. package/dist/es/components/DropIn/index.js +204 -49
  33. package/dist/es/components/GooglePay/index.js +5 -4
  34. package/dist/es/components/GrabPay/index.js +322 -0
  35. package/dist/es/components/GuideCard/index.js +43 -0
  36. package/dist/es/components/LinePay/index.js +322 -0
  37. package/dist/es/components/MayBankQRPay/index.js +322 -0
  38. package/dist/es/components/NinePay/index.js +322 -0
  39. package/dist/es/components/SecuredIframe/index.js +3 -2
  40. package/dist/es/components/Sepa/index.js +6 -9
  41. package/dist/es/components/ShopeePay/index.js +322 -0
  42. package/dist/es/components/SubmitButton/index.js +6 -20
  43. package/dist/es/components/TNGWallet/index.js +322 -0
  44. package/dist/es/components/WechatPay/index.js +30 -49
  45. package/dist/es/components/business/QRCodeModal/QRCodeModal.js +41 -0
  46. package/dist/es/components/business/QRCodeModal/index.js +6 -0
  47. package/dist/es/components/business/QRCodeModal/qr-code-modal.js +1 -0
  48. package/dist/es/components/business/QRCodeModal/type.js +1 -0
  49. package/dist/es/components/business/index.js +6 -0
  50. package/dist/es/components/index.js +9 -0
  51. package/dist/es/components/internal/Accordion/Accordion.js +14 -0
  52. package/dist/es/components/internal/Accordion/accordion2.js +1 -0
  53. package/dist/es/components/internal/Accordion/accordionTransition.js +26 -0
  54. package/dist/es/components/internal/Accordion/index.js +7 -0
  55. package/dist/es/components/internal/Accordion/type.js +10 -0
  56. package/dist/es/components/internal/Modal/Modal.js +17 -3
  57. package/dist/es/components/internal/Modal/index.js +1 -0
  58. package/dist/es/components/internal/Modal/type.js +1 -0
  59. package/dist/es/components/internal/QRCode/QRCode.js +31 -0
  60. package/dist/es/components/internal/QRCode/index.js +4 -0
  61. package/dist/es/components/internal/QRCode/type.js +1 -0
  62. package/dist/es/components/internal/icons/IconBoost.js +63 -0
  63. package/dist/es/components/internal/icons/IconCard.js +1 -40
  64. package/dist/es/components/internal/icons/IconCard2.js +60 -0
  65. package/dist/es/components/internal/icons/IconGCash.js +196 -0
  66. package/dist/es/components/internal/icons/IconGcashComplete.js +184 -0
  67. package/dist/es/components/internal/icons/IconGrabPay.js +59 -0
  68. package/dist/es/components/internal/icons/IconLinePay.js +99 -0
  69. package/dist/es/components/internal/icons/IconMayBankQRPay.js +69 -0
  70. package/dist/es/components/internal/icons/IconNinePay.js +255 -0
  71. package/dist/es/components/internal/icons/IconPaymaya.js +114 -0
  72. package/dist/es/components/internal/icons/IconRedirect.js +58 -0
  73. package/dist/es/components/internal/icons/IconScan.js +102 -0
  74. package/dist/es/components/internal/icons/IconShopeePay.js +108 -0
  75. package/dist/es/components/internal/icons/IconTNGWallet.js +119 -0
  76. package/dist/es/components/internal/icons/IconUnionPay.js +65 -0
  77. package/dist/es/components/wallets/GCash/GCash.js +356 -0
  78. package/dist/es/components/wallets/GCash/g-cash.js +1 -0
  79. package/dist/es/components/wallets/GCash/index.js +1 -0
  80. package/dist/es/components/wallets/GCash/type.js +1 -0
  81. package/dist/es/components/wallets/Paymaya/Paymaya.js +323 -0
  82. package/dist/es/components/wallets/Paymaya/index.js +1 -0
  83. package/dist/es/components/wallets/Paymaya/paymaya2.js +1 -0
  84. package/dist/es/components/wallets/Paymaya/type.js +1 -0
  85. package/dist/es/config.js +12 -12
  86. package/dist/es/constant.js +84 -4
  87. package/dist/es/core/PayKKaCheckout.js +28 -3
  88. package/dist/es/core/Session.js +24 -23
  89. package/dist/es/core/error.js +7 -0
  90. package/dist/es/core/query.js +3 -2
  91. package/dist/es/core.js +2082 -70
  92. package/dist/es/hooks/usePayState.js +0 -3
  93. package/dist/es/i18n/I18n.js +8 -2
  94. package/dist/es/i18n/locales/de-DE.js +16 -1
  95. package/dist/es/i18n/locales/en-GB.js +16 -1
  96. package/dist/es/i18n/locales/es-ES.js +16 -1
  97. package/dist/es/i18n/locales/fr-FR.js +16 -1
  98. package/dist/es/i18n/locales/ja-JP.js +16 -1
  99. package/dist/es/i18n/locales/ko-KR.js +16 -1
  100. package/dist/es/i18n/locales/pt-PT.js +16 -1
  101. package/dist/es/i18n/locales/ru-RU.js +16 -1
  102. package/dist/es/i18n/locales/zh-CN.js +16 -1
  103. package/dist/es/i18n/locales/zh-HK.js +16 -1
  104. package/dist/es/i18n/locales/zh-TW.js +16 -1
  105. package/dist/es/i18n/util.js +12 -3
  106. package/dist/es/index.js +20 -0
  107. package/dist/es/style.css +1 -1192
  108. package/dist/es/types/index.js +1 -0
  109. package/dist/es/utils/array.js +9 -0
  110. package/dist/es/utils/card-brand/brands.js +11 -1
  111. package/dist/es/utils/card-brand/index.js +4 -3
  112. package/dist/es/utils/card-brand/luhn.js +25 -0
  113. package/dist/es/utils/date.js +25 -0
  114. package/dist/es/utils/detect.js +6 -0
  115. package/dist/es/utils/format.js +28 -12
  116. package/dist/es/utils/index.js +9 -1
  117. package/dist/es/utils/location.js +37 -0
  118. package/dist/es/utils/object.js +14 -0
  119. package/dist/es/utils/redirect.js +32 -0
  120. package/dist/es/utils/system-info/get-browser-info.js +4 -4
  121. package/dist/es/utils/system-info/get-system-info.js +11 -7
  122. package/dist/es/utils/system-info/index.js +4 -4
  123. package/dist/style.css +1 -1
  124. package/dist/types/api/http.d.ts +4 -10
  125. package/dist/types/api/modules/ali-pay/index.d.ts +2 -1
  126. package/dist/types/api/modules/apple-pay/index.d.ts +2 -1
  127. package/dist/types/api/modules/boost/index.d.ts +24 -0
  128. package/dist/types/api/modules/card/index.d.ts +1 -1
  129. package/dist/types/api/modules/checkout/index.d.ts +2 -2
  130. package/dist/types/api/modules/checkout/type.d.ts +9 -0
  131. package/dist/types/api/modules/gcash/index.d.ts +24 -0
  132. package/dist/types/api/modules/get-browser-params.d.ts +2 -2
  133. package/dist/types/api/modules/google-pay/index.d.ts +2 -1
  134. package/dist/types/api/modules/grab-pay/index.d.ts +24 -0
  135. package/dist/types/api/modules/index.d.ts +9 -0
  136. package/dist/types/api/modules/line-pay/index.d.ts +24 -0
  137. package/dist/types/api/modules/may-bank-qr-pay/index.d.ts +24 -0
  138. package/dist/types/api/modules/nine-pay/index.d.ts +24 -0
  139. package/dist/types/api/modules/paymaya/index.d.ts +24 -0
  140. package/dist/types/api/modules/sepa/index.d.ts +2 -1
  141. package/dist/types/api/modules/shopee-pay/index.d.ts +24 -0
  142. package/dist/types/api/modules/tng-wallet/index.d.ts +24 -0
  143. package/dist/types/api/modules/wechat-pay/index.d.ts +2 -1
  144. package/dist/types/components/Boost/Boost.d.ts +7 -0
  145. package/dist/types/components/Boost/index.d.ts +2 -0
  146. package/dist/types/components/Boost/type.d.ts +61 -0
  147. package/dist/types/components/DropIn/components/PaymentTabs/type.d.ts +1 -1
  148. package/dist/types/components/DropIn/config.d.ts +7 -0
  149. package/dist/types/components/DropIn/type.d.ts +11 -3
  150. package/dist/types/components/GrabPay/GrabPay.d.ts +7 -0
  151. package/dist/types/components/GrabPay/index.d.ts +2 -0
  152. package/dist/types/components/GrabPay/type.d.ts +61 -0
  153. package/dist/types/components/GuideCard/GuideCard.d.ts +3 -0
  154. package/dist/types/components/GuideCard/index.d.ts +2 -0
  155. package/dist/types/components/GuideCard/type.d.ts +4 -0
  156. package/dist/types/components/LinePay/LinePay.d.ts +7 -0
  157. package/dist/types/components/LinePay/index.d.ts +2 -0
  158. package/dist/types/components/LinePay/type.d.ts +61 -0
  159. package/dist/types/components/MayBankQRPay/MayBankQRPay.d.ts +6 -0
  160. package/dist/types/components/MayBankQRPay/index.d.ts +2 -0
  161. package/dist/types/components/MayBankQRPay/type.d.ts +61 -0
  162. package/dist/types/components/NinePay/NinePay.d.ts +6 -0
  163. package/dist/types/components/NinePay/index.d.ts +2 -0
  164. package/dist/types/components/NinePay/type.d.ts +61 -0
  165. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +1 -1
  166. package/dist/types/components/ShopeePay/ShopeePay.d.ts +7 -0
  167. package/dist/types/components/ShopeePay/index.d.ts +2 -0
  168. package/dist/types/components/ShopeePay/type.d.ts +61 -0
  169. package/dist/types/components/SubmitButton/SubmitButton.d.ts +1 -1
  170. package/dist/types/components/TNGWallet/TNGWallet.d.ts +7 -0
  171. package/dist/types/components/TNGWallet/index.d.ts +2 -0
  172. package/dist/types/components/TNGWallet/type.d.ts +61 -0
  173. package/dist/types/components/business/QRCodeModal/QRCodeModal.d.ts +3 -0
  174. package/dist/types/components/business/QRCodeModal/index.d.ts +2 -0
  175. package/dist/types/components/business/QRCodeModal/type.d.ts +18 -0
  176. package/dist/types/components/business/index.d.ts +1 -0
  177. package/dist/types/components/index.d.ts +9 -0
  178. package/dist/types/components/internal/Accordion/Accordion.d.ts +3 -0
  179. package/dist/types/components/internal/Accordion/accordionTransition.d.ts +8 -0
  180. package/dist/types/components/internal/Accordion/components/AccordionItem/AccordionItem.d.ts +3 -0
  181. package/dist/types/components/internal/Accordion/components/AccordionItem/index.d.ts +2 -0
  182. package/dist/types/components/internal/Accordion/components/AccordionItem/type.d.ts +18 -0
  183. package/dist/types/components/internal/Accordion/index.d.ts +3 -0
  184. package/dist/types/components/internal/Accordion/type.d.ts +18 -0
  185. package/dist/types/components/internal/Modal/type.d.ts +2 -0
  186. package/dist/types/components/internal/QRCode/QRCode.d.ts +2 -0
  187. package/dist/types/components/internal/QRCode/index.d.ts +2 -0
  188. package/dist/types/components/internal/QRCode/type.d.ts +9 -0
  189. package/dist/types/components/internal/icons/IconBoost.d.ts +2 -0
  190. package/dist/types/components/internal/icons/IconCard2.d.ts +2 -0
  191. package/dist/types/components/internal/icons/IconGCash.d.ts +2 -0
  192. package/dist/types/components/internal/icons/IconGcashComplete.d.ts +2 -0
  193. package/dist/types/components/internal/icons/IconGrabPay.d.ts +2 -0
  194. package/dist/types/components/internal/icons/IconLinePay.d.ts +2 -0
  195. package/dist/types/components/internal/icons/IconMayBankQRPay.d.ts +2 -0
  196. package/dist/types/components/internal/icons/IconNinePay.d.ts +2 -0
  197. package/dist/types/components/internal/icons/IconPaymaya.d.ts +2 -0
  198. package/dist/types/components/internal/icons/IconRedirect.d.ts +2 -0
  199. package/dist/types/components/internal/icons/IconScan.d.ts +2 -0
  200. package/dist/types/components/internal/icons/IconShopeePay.d.ts +2 -0
  201. package/dist/types/components/internal/icons/IconTNGWallet.d.ts +2 -0
  202. package/dist/types/components/internal/icons/IconUnionPay.d.ts +2 -0
  203. package/dist/types/components/internal/icons/index.d.ts +13 -0
  204. package/dist/types/components/wallets/GCash/GCash.d.ts +6 -0
  205. package/dist/types/components/wallets/GCash/index.d.ts +2 -0
  206. package/dist/types/components/wallets/GCash/type.d.ts +66 -0
  207. package/dist/types/components/wallets/Paymaya/Paymaya.d.ts +6 -0
  208. package/dist/types/components/wallets/Paymaya/index.d.ts +2 -0
  209. package/dist/types/components/wallets/Paymaya/type.d.ts +61 -0
  210. package/dist/types/config.d.ts +9 -9
  211. package/dist/types/constant.d.ts +28 -3
  212. package/dist/types/core/PayKKaCheckout.d.ts +10 -0
  213. package/dist/types/core/Session.d.ts +2 -0
  214. package/dist/types/core/error.d.ts +3 -1
  215. package/dist/types/core/query.d.ts +2 -2
  216. package/dist/types/hooks/usePayState.d.ts +0 -3
  217. package/dist/types/i18n/I18n.d.ts +1 -1
  218. package/dist/types/i18n/locales/de-DE.d.ts +13 -0
  219. package/dist/types/i18n/locales/en-GB.d.ts +13 -0
  220. package/dist/types/i18n/locales/es-ES.d.ts +13 -0
  221. package/dist/types/i18n/locales/fr-FR.d.ts +13 -0
  222. package/dist/types/i18n/locales/ja-JP.d.ts +13 -0
  223. package/dist/types/i18n/locales/ko-KR.d.ts +13 -0
  224. package/dist/types/i18n/locales/pt-PT.d.ts +13 -0
  225. package/dist/types/i18n/locales/ru-RU.d.ts +13 -0
  226. package/dist/types/i18n/locales/zh-CN.d.ts +13 -0
  227. package/dist/types/i18n/locales/zh-HK.d.ts +13 -0
  228. package/dist/types/i18n/locales/zh-TW.d.ts +13 -0
  229. package/dist/types/i18n/util.d.ts +5 -0
  230. package/dist/types/index.d.ts +1 -1
  231. package/dist/types/types/index.d.ts +10 -3
  232. package/dist/types/types/message.d.ts +1 -0
  233. package/dist/types/utils/array.d.ts +1 -0
  234. package/dist/types/utils/card-brand/brands.d.ts +4 -3
  235. package/dist/types/utils/card-brand/index.d.ts +9 -6
  236. package/dist/types/utils/card-brand/luhn.d.ts +9 -0
  237. package/dist/types/utils/date.d.ts +9 -0
  238. package/dist/types/utils/detect.d.ts +1 -0
  239. package/dist/types/utils/format.d.ts +7 -1
  240. package/dist/types/utils/index.d.ts +7 -0
  241. package/dist/types/utils/location.d.ts +7 -0
  242. package/dist/types/utils/object.d.ts +1 -0
  243. package/dist/types/utils/redirect.d.ts +5 -0
  244. package/dist/types/utils/system-info/get-browser-info.d.ts +1 -1
  245. package/dist/types/utils/system-info/get-system-info.d.ts +3 -2
  246. package/dist/types/utils/system-info/index.d.ts +3 -3
  247. package/package.json +4 -2
@@ -0,0 +1,322 @@
1
+ import { w, F, A, h, y, q, u, b } from "../../core.js";
2
+ import { useBEM } from "../../hooks/useBEM.js";
3
+ import { CoreContext } from "../../core/context.js";
4
+ import "../../utils/card-brand/brands.js";
5
+ import "../../utils/system-info/get-browser-info.js";
6
+ import { cssVarPrefix, normalizedClass, formatAmount } from "../../utils/format.js";
7
+ import { redirectToPayment } from "../../utils/redirect.js";
8
+ import { isTimeoutError } from "../../api/http.js";
9
+ import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../constant.js";
10
+ import { getBrowserParams } from "../../api/modules/get-browser-params.js";
11
+ import { getMayBankQRPayInfo, mayBankQRPay } from "../../api/modules/may-bank-qr-pay/index.js";
12
+ import { PayKKaError } from "../../core/error.js";
13
+ import { hidePaymentButton } from "../../config.js";
14
+ import { usePayState } from "../../hooks/usePayState.js";
15
+ import { useRetry } from "../../hooks/useRetry.js";
16
+ import { createEmailCore, EmailField } from "../EmailField/EmailField.js";
17
+ import { createAddressCore } from "../../core/Address.js";
18
+ import { SubmitButton } from "../SubmitButton/index.js";
19
+ import "../internal/Form/type.js";
20
+ import "../internal/Form/context.js";
21
+ import "../internal/Form/FormItem.js";
22
+ import { Form } from "../internal/Form/Form.js";
23
+ import { AddressField } from "../AddressField/index.js";
24
+ import { Info } from "../internal/Info/Info.js";
25
+ import { GuideCard } from "../GuideCard/index.js";
26
+ const { bem } = useBEM("may-bank-qr-pay");
27
+ const fieldClassNames = bem("field");
28
+ const MayBankQRPay = w((props, ref) => {
29
+ var _a, _b, _c, _d, _e, _f;
30
+ const {
31
+ session,
32
+ showEmail = false,
33
+ showAddress = false,
34
+ redirectMode = "auto",
35
+ core,
36
+ autoQuery = true,
37
+ showGuideCard = true
38
+ } = props;
39
+ F(ref, () => ({
40
+ stopRetry: () => {
41
+ setSubmitButtonStatus("unSubmit");
42
+ stopReFetchPayInfo();
43
+ },
44
+ startRetry: (timeout) => {
45
+ setSubmitButtonStatus("loading");
46
+ startReFetchPayInfo({ timeout });
47
+ },
48
+ updateAddress: () => {
49
+ var _a2;
50
+ if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
51
+ return;
52
+ setForm(Object.assign(form, { address: addressState.getAddressState() }));
53
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
54
+ },
55
+ updateEmail: () => {
56
+ var _a2;
57
+ if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
58
+ return;
59
+ setForm(Object.assign(form, { email: emailState.email }));
60
+ (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
61
+ },
62
+ payment: () => {
63
+ hidePaymentButton && onSubmit();
64
+ }
65
+ }));
66
+ const addressState = createAddressCore();
67
+ const emailState = createEmailCore();
68
+ const addressFieldRef = A(null);
69
+ const emailFieldRef = A(null);
70
+ const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
71
+ const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session);
72
+ const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
73
+ const formRef = A(null);
74
+ const [form, setForm] = h({
75
+ email: "",
76
+ address: {
77
+ country: "",
78
+ province: "",
79
+ city: "",
80
+ area: "",
81
+ postCode: "",
82
+ address1: "",
83
+ address2: ""
84
+ }
85
+ });
86
+ const [validated, setValidated] = h(false);
87
+ const [fieldStatus, setFieldStatus] = h();
88
+ const initFieldStatus = () => {
89
+ const { field, sessionMode } = session.checkout;
90
+ const { email, address } = field;
91
+ if (sessionMode === SessionMode.COMPONENT) {
92
+ if (email.disabled) {
93
+ email.show = showEmail;
94
+ }
95
+ if (showAddress && !(address == null ? void 0 : address.show)) {
96
+ address.show = true;
97
+ }
98
+ }
99
+ setFieldStatus({ ...field });
100
+ };
101
+ y(() => {
102
+ if (!sessionReady) {
103
+ return;
104
+ }
105
+ const { bill = {}, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
106
+ if (!paymentMethod.includes(PaymentMethod.MAY_BANK_QR_PAY)) {
107
+ return;
108
+ }
109
+ initFieldStatus();
110
+ setIsCheckoutEnabled(true);
111
+ form.email = bill.email ?? "";
112
+ if (autoQuery && core.processingPaymentMethod === PaymentMethod.MAY_BANK_QR_PAY) {
113
+ setSubmitButtonStatus("loading");
114
+ startReFetchPayInfo();
115
+ }
116
+ }, [sessionReady]);
117
+ const processOnError = (error) => {
118
+ var _a2;
119
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, error);
120
+ core.resetEnablePaymentMethod();
121
+ };
122
+ const onTimeout = q(
123
+ (message) => {
124
+ var _a2;
125
+ setErrorMsg(message || i18n.get("common.payTimeout"));
126
+ setSubmitButtonStatus("unSubmit");
127
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props);
128
+ core.resetEnablePaymentMethod();
129
+ },
130
+ [i18n, props.onTimeout]
131
+ );
132
+ const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
133
+ (timeout) => pay(true, timeout),
134
+ { onTimeout: () => onTimeout(i18n.get("common.queryTimeout")) }
135
+ );
136
+ const getPaymentParams = async () => {
137
+ return {
138
+ sessionId: session.sessionId,
139
+ clientKey: session.clientKey,
140
+ payment: {
141
+ paymentMethod: PaymentMethod.MAY_BANK_QR_PAY
142
+ },
143
+ bill: {
144
+ email: form.email,
145
+ ...form.address,
146
+ province: addressState.getLabel(form.address.province, addressState.getProvinceOption()) ?? form.address.province,
147
+ city: addressState.getLabel(form.address.city, addressState.getCityOptions()) ?? form.address.city
148
+ },
149
+ browser: await getBrowserParams()
150
+ };
151
+ };
152
+ const pay = async (search = false, timeout) => {
153
+ var _a2, _b2, _c2, _d2, _e2;
154
+ try {
155
+ const paymentParams = await getPaymentParams();
156
+ const requestOptions = { locale: i18n.locale, timeout };
157
+ const res = search ? await getMayBankQRPayInfo(
158
+ { sessionId: session.sessionId, clientKey: session.clientKey },
159
+ requestOptions
160
+ ) : await mayBankQRPay(paymentParams, props.core, requestOptions);
161
+ !search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
162
+ const { status, orderStatus, errorMessage, errorCode, payInfo } = res;
163
+ if (status === "PROCESSING") {
164
+ if (!orderStatus) {
165
+ setSubmitButtonStatus("unSubmit");
166
+ return { end: true };
167
+ } else if (orderStatus === "SUCCESS") {
168
+ setSubmitButtonStatus("success");
169
+ (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
170
+ return { end: true };
171
+ } else if (orderStatus === "FAILURE") {
172
+ setErrorMsg(errorMessage);
173
+ setSubmitButtonStatus("unSubmit");
174
+ processOnError(new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
175
+ return { end: true };
176
+ } else if (orderStatus === "PROCESSING") {
177
+ if (!search) {
178
+ if (redirectMode === "auto" && payInfo) {
179
+ redirectToPayment(payInfo);
180
+ return { end: true };
181
+ } else {
182
+ startReFetchPayInfo();
183
+ }
184
+ }
185
+ return { end: false };
186
+ } else if (orderStatus === "CANCELED") {
187
+ setSubmitButtonStatus("unSubmit");
188
+ (_c2 = props.onTimeout) == null ? void 0 : _c2.call(props);
189
+ core.resetEnablePaymentMethod();
190
+ return { end: true };
191
+ }
192
+ } else if (status === "SUCCESS") {
193
+ setSubmitButtonStatus("success");
194
+ (_d2 = props.onSuccess) == null ? void 0 : _d2.call(props);
195
+ return { end: true };
196
+ } else if (status === "EXPIRED") {
197
+ setSubmitButtonStatus("unSubmit");
198
+ (_e2 = props.onExpired) == null ? void 0 : _e2.call(props);
199
+ return { end: true };
200
+ }
201
+ setSubmitButtonStatus("unSubmit");
202
+ return { end: true };
203
+ } catch (error) {
204
+ if (isTimeoutError(error)) {
205
+ if (search) {
206
+ return { end: false };
207
+ } else {
208
+ onTimeout();
209
+ return { end: true };
210
+ }
211
+ } else {
212
+ const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
213
+ setErrorMsg(message);
214
+ processOnError(new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
215
+ setSubmitButtonStatus("unSubmit");
216
+ return { end: true };
217
+ }
218
+ }
219
+ };
220
+ const validateForm = () => {
221
+ var _a2;
222
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
223
+ setValidated(true);
224
+ }).catch(() => {
225
+ setValidated(false);
226
+ });
227
+ };
228
+ y(() => {
229
+ validateForm();
230
+ }, [form]);
231
+ const onSubmit = async () => {
232
+ var _a2;
233
+ setErrorMsg("");
234
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
235
+ var _a3;
236
+ (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressState.setValidateAllFields(true);
237
+ (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
238
+ if (errors) {
239
+ setSubmitButtonStatus("unSubmit");
240
+ return;
241
+ }
242
+ setErrorMsg("");
243
+ setSubmitButtonStatus("loading");
244
+ await pay();
245
+ });
246
+ };
247
+ const setFormRef = (dom) => {
248
+ formRef.current = dom;
249
+ dom && validateForm();
250
+ };
251
+ const Button = () => {
252
+ var _a2;
253
+ const transAmount = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.transAmount;
254
+ const amountText = (transAmount == null ? void 0 : transAmount.amount) ? formatAmount(transAmount).jointSymbol() : "";
255
+ const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
256
+ return /* @__PURE__ */ u(
257
+ SubmitButton,
258
+ {
259
+ className: bem("button"),
260
+ status: submitButtonStatus,
261
+ text,
262
+ loadingText: i18n.get("common.payProcessing"),
263
+ successText: i18n.get("common.paySuccess"),
264
+ onClick: onSubmit,
265
+ verified: validated
266
+ }
267
+ );
268
+ };
269
+ const Email = () => {
270
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.email.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
271
+ EmailField,
272
+ {
273
+ ref: emailFieldRef,
274
+ value: form.email,
275
+ disabled: fieldStatus == null ? void 0 : fieldStatus.email.disabled
276
+ }
277
+ ) }) });
278
+ };
279
+ const formStyle = {
280
+ [cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
281
+ [cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
282
+ [cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
283
+ [cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
284
+ [cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
285
+ };
286
+ const ErrorMessage = () => {
287
+ return /* @__PURE__ */ u(b, { children: !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg, style: { marginTop: "12px" } }) });
288
+ };
289
+ const Address = () => {
290
+ var _a2, _b2;
291
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
292
+ AddressField,
293
+ {
294
+ ref: addressFieldRef,
295
+ value: form.address,
296
+ country: ((_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.country) || ((_b2 = session == null ? void 0 : session.checkout) == null ? void 0 : _b2.bill.country),
297
+ onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
298
+ }
299
+ ) }) });
300
+ };
301
+ return /* @__PURE__ */ u(
302
+ CoreContext.Provider,
303
+ {
304
+ value: {
305
+ i18n,
306
+ session
307
+ },
308
+ children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
309
+ showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.MAY_BANK_QR_PAY }),
310
+ /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: formStyle, children: [
311
+ Email(),
312
+ Address(),
313
+ ErrorMessage(),
314
+ !hidePaymentButton && Button()
315
+ ] }) })
316
+ ] })
317
+ }
318
+ );
319
+ });
320
+ export {
321
+ MayBankQRPay
322
+ };
@@ -0,0 +1,322 @@
1
+ import { w, F, A, h, y, q, u, b } from "../../core.js";
2
+ import { useBEM } from "../../hooks/useBEM.js";
3
+ import { CoreContext } from "../../core/context.js";
4
+ import "../../utils/card-brand/brands.js";
5
+ import "../../utils/system-info/get-browser-info.js";
6
+ import { cssVarPrefix, normalizedClass, formatAmount } from "../../utils/format.js";
7
+ import { redirectToPayment } from "../../utils/redirect.js";
8
+ import { isTimeoutError } from "../../api/http.js";
9
+ import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../constant.js";
10
+ import { getBrowserParams } from "../../api/modules/get-browser-params.js";
11
+ import { getNinePayInfo, ninePay } from "../../api/modules/nine-pay/index.js";
12
+ import { PayKKaError } from "../../core/error.js";
13
+ import { hidePaymentButton } from "../../config.js";
14
+ import { usePayState } from "../../hooks/usePayState.js";
15
+ import { useRetry } from "../../hooks/useRetry.js";
16
+ import { createEmailCore, EmailField } from "../EmailField/EmailField.js";
17
+ import { createAddressCore } from "../../core/Address.js";
18
+ import { SubmitButton } from "../SubmitButton/index.js";
19
+ import "../internal/Form/type.js";
20
+ import "../internal/Form/context.js";
21
+ import "../internal/Form/FormItem.js";
22
+ import { Form } from "../internal/Form/Form.js";
23
+ import { AddressField } from "../AddressField/index.js";
24
+ import { Info } from "../internal/Info/Info.js";
25
+ import { GuideCard } from "../GuideCard/index.js";
26
+ const { bem } = useBEM("nine-pay");
27
+ const fieldClassNames = bem("field");
28
+ const NinePay = w((props, ref) => {
29
+ var _a, _b, _c, _d, _e, _f;
30
+ const {
31
+ session,
32
+ showEmail = false,
33
+ showAddress = false,
34
+ redirectMode = "auto",
35
+ core,
36
+ autoQuery,
37
+ showGuideCard = true
38
+ } = props;
39
+ F(ref, () => ({
40
+ stopRetry: () => {
41
+ setSubmitButtonStatus("unSubmit");
42
+ stopReFetchPayInfo();
43
+ },
44
+ startRetry: (timeout) => {
45
+ setSubmitButtonStatus("loading");
46
+ startReFetchPayInfo({ timeout });
47
+ },
48
+ updateAddress: () => {
49
+ var _a2;
50
+ if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
51
+ return;
52
+ setForm(Object.assign(form, { address: addressState.getAddressState() }));
53
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
54
+ },
55
+ updateEmail: () => {
56
+ var _a2;
57
+ if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
58
+ return;
59
+ setForm(Object.assign(form, { email: emailState.email }));
60
+ (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
61
+ },
62
+ payment: () => {
63
+ hidePaymentButton && onSubmit();
64
+ }
65
+ }));
66
+ const addressState = createAddressCore();
67
+ const emailState = createEmailCore();
68
+ const addressFieldRef = A(null);
69
+ const emailFieldRef = A(null);
70
+ const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
71
+ const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session);
72
+ const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
73
+ const formRef = A(null);
74
+ const [form, setForm] = h({
75
+ email: "",
76
+ address: {
77
+ country: "",
78
+ province: "",
79
+ city: "",
80
+ area: "",
81
+ postCode: "",
82
+ address1: "",
83
+ address2: ""
84
+ }
85
+ });
86
+ const [validated, setValidated] = h(false);
87
+ const [fieldStatus, setFieldStatus] = h();
88
+ const initFieldStatus = () => {
89
+ const { field, sessionMode } = session.checkout;
90
+ const { email, address } = field;
91
+ if (sessionMode === SessionMode.COMPONENT) {
92
+ if (email.disabled) {
93
+ email.show = showEmail;
94
+ }
95
+ if (showAddress && !(address == null ? void 0 : address.show)) {
96
+ address.show = true;
97
+ }
98
+ }
99
+ setFieldStatus({ ...field });
100
+ };
101
+ y(() => {
102
+ if (!sessionReady) {
103
+ return;
104
+ }
105
+ const { bill = {}, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
106
+ if (!paymentMethod.includes(PaymentMethod.NINE_PAY)) {
107
+ return;
108
+ }
109
+ setIsCheckoutEnabled(true);
110
+ initFieldStatus();
111
+ form.email = bill.email ?? "";
112
+ if (autoQuery && core.processingPaymentMethod === PaymentMethod.NINE_PAY) {
113
+ setSubmitButtonStatus("loading");
114
+ startReFetchPayInfo();
115
+ }
116
+ }, [sessionReady]);
117
+ const processOnError = (error) => {
118
+ var _a2;
119
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, error);
120
+ core.resetEnablePaymentMethod();
121
+ };
122
+ const onTimeout = q(
123
+ (message) => {
124
+ var _a2;
125
+ setErrorMsg(message || i18n.get("common.payTimeout"));
126
+ setSubmitButtonStatus("unSubmit");
127
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props);
128
+ core.resetEnablePaymentMethod();
129
+ },
130
+ [i18n, props.onTimeout]
131
+ );
132
+ const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
133
+ (timeout) => pay(true, timeout),
134
+ { onTimeout: () => onTimeout(i18n.get("common.queryTimeout")) }
135
+ );
136
+ const getPaymentParams = async () => {
137
+ return {
138
+ sessionId: session.sessionId,
139
+ clientKey: session.clientKey,
140
+ payment: {
141
+ paymentMethod: PaymentMethod.NINE_PAY
142
+ },
143
+ bill: {
144
+ email: form.email,
145
+ ...form.address,
146
+ province: addressState.getLabel(form.address.province, addressState.getProvinceOption()) ?? form.address.province,
147
+ city: addressState.getLabel(form.address.city, addressState.getCityOptions()) ?? form.address.city
148
+ },
149
+ browser: await getBrowserParams()
150
+ };
151
+ };
152
+ const pay = async (search = false, timeout) => {
153
+ var _a2, _b2, _c2, _d2, _e2;
154
+ try {
155
+ const paymentParams = await getPaymentParams();
156
+ const requestOptions = { locale: i18n.locale, timeout };
157
+ const res = search ? await getNinePayInfo(
158
+ { sessionId: session.sessionId, clientKey: session.clientKey },
159
+ requestOptions
160
+ ) : await ninePay(paymentParams, props.core, requestOptions);
161
+ !search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
162
+ const { status, orderStatus, errorMessage, errorCode, payInfo } = res;
163
+ if (status === "PROCESSING") {
164
+ if (!orderStatus) {
165
+ setSubmitButtonStatus("unSubmit");
166
+ return { end: true };
167
+ } else if (orderStatus === "SUCCESS") {
168
+ setSubmitButtonStatus("success");
169
+ (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
170
+ return { end: true };
171
+ } else if (orderStatus === "FAILURE") {
172
+ setErrorMsg(errorMessage);
173
+ setSubmitButtonStatus("unSubmit");
174
+ processOnError(new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
175
+ return { end: true };
176
+ } else if (orderStatus === "PROCESSING") {
177
+ if (!search) {
178
+ if (redirectMode === "auto" && payInfo) {
179
+ redirectToPayment(payInfo);
180
+ return { end: true };
181
+ } else {
182
+ startReFetchPayInfo();
183
+ }
184
+ }
185
+ return { end: false };
186
+ } else if (orderStatus === "CANCELED") {
187
+ setSubmitButtonStatus("unSubmit");
188
+ (_c2 = props.onTimeout) == null ? void 0 : _c2.call(props);
189
+ core.resetEnablePaymentMethod();
190
+ return { end: true };
191
+ }
192
+ } else if (status === "SUCCESS") {
193
+ setSubmitButtonStatus("success");
194
+ (_d2 = props.onSuccess) == null ? void 0 : _d2.call(props);
195
+ return { end: true };
196
+ } else if (status === "EXPIRED") {
197
+ setSubmitButtonStatus("unSubmit");
198
+ (_e2 = props.onExpired) == null ? void 0 : _e2.call(props);
199
+ return { end: true };
200
+ }
201
+ setSubmitButtonStatus("unSubmit");
202
+ return { end: true };
203
+ } catch (error) {
204
+ if (isTimeoutError(error)) {
205
+ if (search) {
206
+ return { end: false };
207
+ } else {
208
+ onTimeout();
209
+ return { end: true };
210
+ }
211
+ } else {
212
+ const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
213
+ setErrorMsg(message);
214
+ processOnError(new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
215
+ setSubmitButtonStatus("unSubmit");
216
+ return { end: true };
217
+ }
218
+ }
219
+ };
220
+ const validateForm = () => {
221
+ var _a2;
222
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
223
+ setValidated(true);
224
+ }).catch(() => {
225
+ setValidated(false);
226
+ });
227
+ };
228
+ y(() => {
229
+ validateForm();
230
+ }, [form]);
231
+ const onSubmit = async () => {
232
+ var _a2;
233
+ setErrorMsg("");
234
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
235
+ var _a3;
236
+ (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressState.setValidateAllFields(true);
237
+ (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
238
+ if (errors) {
239
+ setSubmitButtonStatus("unSubmit");
240
+ return;
241
+ }
242
+ setErrorMsg("");
243
+ setSubmitButtonStatus("loading");
244
+ await pay();
245
+ });
246
+ };
247
+ const setFormRef = (dom) => {
248
+ formRef.current = dom;
249
+ dom && validateForm();
250
+ };
251
+ const Button = () => {
252
+ var _a2;
253
+ const transAmount = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.transAmount;
254
+ const amountText = (transAmount == null ? void 0 : transAmount.amount) ? formatAmount(transAmount).jointSymbol() : "";
255
+ const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
256
+ return /* @__PURE__ */ u(
257
+ SubmitButton,
258
+ {
259
+ className: bem("button"),
260
+ status: submitButtonStatus,
261
+ text,
262
+ loadingText: i18n.get("common.payProcessing"),
263
+ successText: i18n.get("common.paySuccess"),
264
+ onClick: onSubmit,
265
+ verified: validated
266
+ }
267
+ );
268
+ };
269
+ const Email = () => {
270
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.email.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
271
+ EmailField,
272
+ {
273
+ ref: emailFieldRef,
274
+ value: form.email,
275
+ disabled: fieldStatus == null ? void 0 : fieldStatus.email.disabled
276
+ }
277
+ ) }) });
278
+ };
279
+ const formStyle = {
280
+ [cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
281
+ [cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
282
+ [cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
283
+ [cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
284
+ [cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
285
+ };
286
+ const ErrorMessage = () => {
287
+ return /* @__PURE__ */ u(b, { children: !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg, style: { marginTop: "12px" } }) });
288
+ };
289
+ const Address = () => {
290
+ var _a2, _b2;
291
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
292
+ AddressField,
293
+ {
294
+ ref: addressFieldRef,
295
+ value: form.address,
296
+ country: ((_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.country) || ((_b2 = session == null ? void 0 : session.checkout) == null ? void 0 : _b2.bill.country),
297
+ onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
298
+ }
299
+ ) }) });
300
+ };
301
+ return /* @__PURE__ */ u(
302
+ CoreContext.Provider,
303
+ {
304
+ value: {
305
+ i18n,
306
+ session
307
+ },
308
+ children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
309
+ showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.NINE_PAY }),
310
+ /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: formStyle, children: [
311
+ Email(),
312
+ Address(),
313
+ ErrorMessage(),
314
+ !hidePaymentButton && Button()
315
+ ] }) })
316
+ ] })
317
+ }
318
+ );
319
+ });
320
+ export {
321
+ NinePay
322
+ };
@@ -432,7 +432,7 @@ const HiddenIframe = () => {
432
432
  }
433
433
  } else if (parsedData.action === MessageAction.PAYMENT) {
434
434
  const feedbackData = parsedData;
435
- pay(feedbackData.formData, feedbackData.locale);
435
+ pay(feedbackData.formData, feedbackData.locale, feedbackData.extraParams);
436
436
  } else if (parsedData.action === MessageAction.ENCRYPT_CARD) {
437
437
  const feedbackData = parsedData;
438
438
  try {
@@ -445,7 +445,7 @@ const HiddenIframe = () => {
445
445
  }
446
446
  };
447
447
  window.addEventListener("message", onReceiveMessage);
448
- const pay = (params, locale) => {
448
+ const pay = (params, locale, extraParams) => {
449
449
  cardPay(
450
450
  {
451
451
  ...params,
@@ -454,6 +454,7 @@ const HiddenIframe = () => {
454
454
  ...formData
455
455
  }
456
456
  },
457
+ extraParams,
457
458
  { locale }
458
459
  ).then(sendAfterPaymentMessage).catch((error) => {
459
460
  if (isTimeoutError(error)) {