@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 { getTNGWalletPayInfo, tngWalletPay } from "../../api/modules/tng-wallet/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("tng-wallet");
27
+ const fieldClassNames = bem("field");
28
+ const TNGWallet = 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.TNG_WALLET)) {
107
+ return;
108
+ }
109
+ initFieldStatus();
110
+ setIsCheckoutEnabled(true);
111
+ form.email = bill.email ?? "";
112
+ if (autoQuery && core.processingPaymentMethod === PaymentMethod.TNG_WALLET) {
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.TNG_WALLET
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 getTNGWalletPayInfo(
158
+ { sessionId: session.sessionId, clientKey: session.clientKey },
159
+ requestOptions
160
+ ) : await tngWalletPay(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.TNG_WALLET }),
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
+ TNGWallet
322
+ };
@@ -1,7 +1,6 @@
1
- import { w, A, F, h, y, q, u, b } from "../../core.js";
1
+ import { w, A, F, h, y, q, u } from "../../core.js";
2
2
  import { isTimeoutError } from "../../api/http.js";
3
3
  import { COMMON_CLASS_NAME, PaymentType } from "../../constant.js";
4
- import { isUndefined } from "../../utils/is.js";
5
4
  import "../../utils/card-brand/brands.js";
6
5
  import "../../utils/system-info/get-browser-info.js";
7
6
  import { cssVarPrefix, normalizedClass, formatAmount } from "../../utils/format.js";
@@ -25,8 +24,8 @@ const { bem } = useBEM("wechat-pay");
25
24
  const WechatPay = w((props, ref) => {
26
25
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
27
26
  const { session } = props;
28
- let addressState = createAddressCore();
29
- let emailState = createEmailCore();
27
+ const addressState = createAddressCore();
28
+ const emailState = createEmailCore();
30
29
  const emailFieldRef = A(null);
31
30
  F(ref, () => ({
32
31
  stopRetry: () => {
@@ -50,14 +49,8 @@ const WechatPay = w((props, ref) => {
50
49
  (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
51
50
  }
52
51
  }));
53
- const {
54
- setErrorMsg,
55
- setSubmitButtonStatus,
56
- i18n,
57
- submitButtonStatus,
58
- errorMsg,
59
- sessionReady
60
- } = usePayState(session);
52
+ const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session);
53
+ const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
61
54
  const formRef = A(null);
62
55
  const [form, setForm] = h({
63
56
  email: "",
@@ -101,12 +94,15 @@ const WechatPay = w((props, ref) => {
101
94
  }, 100);
102
95
  }
103
96
  }, [sessionReady]);
104
- const onTimeout = q((message) => {
105
- var _a2;
106
- setErrorMsg(message || i18n.get("common.payTimeout"));
107
- setSubmitButtonStatus("unSubmit");
108
- (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
109
- }, [i18n, props.onTimeout]);
97
+ const onTimeout = q(
98
+ (message) => {
99
+ var _a2;
100
+ setErrorMsg(message || i18n.get("common.payTimeout"));
101
+ setSubmitButtonStatus("unSubmit");
102
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
103
+ },
104
+ [i18n, props.onTimeout]
105
+ );
110
106
  const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
111
107
  (timeout) => pay(true, timeout),
112
108
  {
@@ -115,7 +111,7 @@ const WechatPay = w((props, ref) => {
115
111
  }
116
112
  );
117
113
  async function pay(search = false, timeout) {
118
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j;
114
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
119
115
  try {
120
116
  const res = search ? await getWechatPayInfo(
121
117
  {
@@ -140,6 +136,7 @@ const WechatPay = w((props, ref) => {
140
136
  },
141
137
  channelUserId: await ((_a2 = props.onGetOpenId) == null ? void 0 : _a2.call(props))
142
138
  },
139
+ props.core,
143
140
  { locale: i18n.locale, timeout }
144
141
  );
145
142
  const { status, orderStatus, errorMessage, payInfo, errorCode } = res;
@@ -147,52 +144,38 @@ const WechatPay = w((props, ref) => {
147
144
  if (status === "PROCESSING") {
148
145
  if (!orderStatus) {
149
146
  setSubmitButtonStatus("unSubmit");
147
+ return { end: true };
150
148
  } else if (orderStatus === "SUCCESS") {
151
149
  setSubmitButtonStatus("success");
152
150
  (_c2 = props.onSuccess) == null ? void 0 : _c2.call(props);
153
- return {
154
- end: true
155
- };
151
+ return { end: true };
156
152
  } else if (orderStatus === "FAILURE") {
157
153
  setErrorMsg(errorMessage);
158
154
  setSubmitButtonStatus("unSubmit");
159
155
  (_d2 = props.onError) == null ? void 0 : _d2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
160
- return {
161
- end: true
162
- };
156
+ return { end: true };
163
157
  } else if (orderStatus === "PROCESSING") {
164
158
  if (!search) {
165
159
  await ((_e2 = props.onCallWxPayBox) == null ? void 0 : _e2.call(props, payInfo));
166
160
  startReFetchPayInfo();
167
161
  }
168
- return {
169
- end: false
170
- };
162
+ return { end: false };
171
163
  } else if (orderStatus === "CANCELED") {
172
164
  setSubmitButtonStatus("unSubmit");
173
165
  (_f2 = props.onTimeout) == null ? void 0 : _f2.call(props, "channel");
174
- return {
175
- end: true
176
- };
166
+ return { end: true };
177
167
  }
178
168
  } else if (status === "SUCCESS") {
179
169
  setSubmitButtonStatus("success");
180
170
  (_g2 = props.onSuccess) == null ? void 0 : _g2.call(props);
181
- return {
182
- end: true
183
- };
171
+ return { end: true };
184
172
  } else if (status === "EXPIRED") {
185
173
  setSubmitButtonStatus("unSubmit");
186
174
  (_h2 = props.onExpired) == null ? void 0 : _h2.call(props);
187
- return {
188
- end: true
189
- };
175
+ return { end: true };
190
176
  }
191
177
  setSubmitButtonStatus("unSubmit");
192
- (_i2 = props.onSuccess) == null ? void 0 : _i2.call(props);
193
- return {
194
- end: true
195
- };
178
+ return { end: true };
196
179
  } catch (error) {
197
180
  if (isTimeoutError(error)) {
198
181
  if (search) {
@@ -204,7 +187,7 @@ const WechatPay = w((props, ref) => {
204
187
  } else {
205
188
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
206
189
  setErrorMsg(message);
207
- (_j = props.onError) == null ? void 0 : _j.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
190
+ (_i2 = props.onError) == null ? void 0 : _i2.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
208
191
  setSubmitButtonStatus("unSubmit");
209
192
  return { end: true };
210
193
  }
@@ -227,16 +210,14 @@ const WechatPay = w((props, ref) => {
227
210
  });
228
211
  }
229
212
  const Button = () => {
230
- const { transAmount } = (session == null ? void 0 : session.checkout) ?? {};
231
- let { symbol = "", amount = "", digits } = transAmount ?? {};
232
- let amountStr = "";
233
- if (amount && !isUndefined(digits))
234
- amountStr = formatAmount(+amount, digits);
235
- const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amountStr}` : "");
213
+ const { transAmount, channelParams = {} } = (session == null ? void 0 : session.checkout) ?? {};
214
+ const { totalAmount } = channelParams.wechatPay ?? {};
215
+ const amountObj = ((totalAmount == null ? void 0 : totalAmount.amount) ? totalAmount : transAmount) || {};
216
+ const amountText = (amountObj == null ? void 0 : amountObj.amount) ? formatAmount(amountObj).jointSymbol() : "";
217
+ const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
236
218
  return /* @__PURE__ */ u(
237
219
  SubmitButton,
238
220
  {
239
- icon: () => /* @__PURE__ */ u(b, {}),
240
221
  className: bem("button"),
241
222
  status: submitButtonStatus,
242
223
  text,
@@ -0,0 +1,41 @@
1
+ import { u, b } from "../../../core.js";
2
+ import { useBEM } from "../../../hooks/useBEM.js";
3
+ import { useI18n } from "../../../hooks/useI18n.js";
4
+ import "../../../utils/card-brand/brands.js";
5
+ import "../../../utils/system-info/get-browser-info.js";
6
+ import { formatAmount } from "../../../utils/format.js";
7
+ import { formatTime } from "../../../utils/date.js";
8
+ import { useBreakpoints } from "../../../hooks/useBreakpoints.js";
9
+ import { Modal } from "../../internal/Modal/Modal.js";
10
+ import "./qr-code-modal.js";
11
+ import { QRCode } from "../../internal/QRCode/QRCode.js";
12
+ const { bem } = useBEM("qr-code-modal");
13
+ const QRCodeModal = (props) => {
14
+ const { title, bgColor, expiredTime, amount, icon, qrCode, onClose } = props;
15
+ const { i18n } = useI18n();
16
+ const breakpoints = useBreakpoints();
17
+ return /* @__PURE__ */ u(
18
+ Modal,
19
+ {
20
+ show: true,
21
+ width: breakpoints.smaller("xs") ? "90vw" : "340px",
22
+ appendToBody: true,
23
+ onChange: (status) => !status && (onClose == null ? void 0 : onClose()),
24
+ children: /* @__PURE__ */ u("div", { className: bem(), children: [
25
+ /* @__PURE__ */ u("div", { className: bem("title"), children: title }),
26
+ /* @__PURE__ */ u("div", { className: bem("container"), children: /* @__PURE__ */ u("div", { className: bem("body"), style: { backgroundColor: bgColor }, children: [
27
+ icon && /* @__PURE__ */ u("div", { className: bem("icon"), children: icon }),
28
+ /* @__PURE__ */ u("div", { className: bem("qr-code"), children: /* @__PURE__ */ u(QRCode, { value: qrCode }) }),
29
+ expiredTime && /* @__PURE__ */ u(b, { children: [
30
+ /* @__PURE__ */ u("div", { className: bem("expired-time"), children: formatTime(expiredTime) }),
31
+ /* @__PURE__ */ u("div", { className: bem("expired-time-text"), children: i18n.get("qrCode.expired") })
32
+ ] })
33
+ ] }) }),
34
+ amount && /* @__PURE__ */ u("div", { className: bem("amount"), children: formatAmount(amount).jointSymbolAndCurrency() })
35
+ ] })
36
+ }
37
+ );
38
+ };
39
+ export {
40
+ QRCodeModal
41
+ };
@@ -0,0 +1,6 @@
1
+ import "../../../core.js";
2
+ import "../../../utils/card-brand/brands.js";
3
+ import "../../../utils/system-info/get-browser-info.js";
4
+ import "../../../core/context.js";
5
+ import "../../internal/Modal/Modal.js";
6
+ import "./qr-code-modal.js";
@@ -0,0 +1,6 @@
1
+ import "../../core.js";
2
+ import "../../utils/card-brand/brands.js";
3
+ import "../../utils/system-info/get-browser-info.js";
4
+ import "../../core/context.js";
5
+ import "../internal/Modal/Modal.js";
6
+ import "./QRCodeModal/qr-code-modal.js";
@@ -28,3 +28,12 @@ import "./Sepa/index.js";
28
28
  import "./EncryptedCard/index.js";
29
29
  import "./CombinedCardInfo/index.js";
30
30
  import "./DropIn/index.js";
31
+ import "./Boost/index.js";
32
+ import "./LinePay/index.js";
33
+ import "./MayBankQRPay/index.js";
34
+ import "./NinePay/index.js";
35
+ import "./GrabPay/index.js";
36
+ import "./TNGWallet/index.js";
37
+ import "./ShopeePay/index.js";
38
+ import "./wallets/GCash/GCash.js";
39
+ import "./wallets/Paymaya/Paymaya.js";
@@ -0,0 +1,14 @@
1
+ import { h, u } from "../../../core.js";
2
+ import { AccordionContext } from "./type.js";
3
+ import "./accordion2.js";
4
+ const Accordion = ({ value, onChange, children, enableTransition }) => {
5
+ const [activeName, setActiveName] = h(value);
6
+ const onSelect = (newValue) => {
7
+ setActiveName(newValue);
8
+ onChange == null ? void 0 : onChange(newValue);
9
+ };
10
+ return /* @__PURE__ */ u(AccordionContext.Provider, { value: { onSelect, activeName, enableTransition }, children: /* @__PURE__ */ u("div", { children }) });
11
+ };
12
+ export {
13
+ Accordion
14
+ };
@@ -0,0 +1,26 @@
1
+ import "../../../utils/card-brand/brands.js";
2
+ import "../../../utils/system-info/get-browser-info.js";
3
+ import { isEventSupported } from "../../../utils/detect.js";
4
+ const accordionTransition = (item, unfold, enable = true) => {
5
+ const paddingBottom = 16;
6
+ const child = item.firstElementChild;
7
+ if (!child)
8
+ return;
9
+ const childHeight = child.scrollHeight;
10
+ if (enable && isEventSupported("transitionend")) {
11
+ item.style.transition = "max-height 0.3s ease";
12
+ item.style.maxHeight = unfold ? `${childHeight + paddingBottom}px` : "0px";
13
+ setTimeout(() => {
14
+ if (unfold) {
15
+ item.style.maxHeight = "none";
16
+ }
17
+ item.style.overflow = unfold ? "visible" : "hidden";
18
+ }, 300);
19
+ } else {
20
+ item.style.maxHeight = unfold ? `${childHeight + paddingBottom}px` : "0px";
21
+ item.style.overflow = unfold ? "visible" : "hidden";
22
+ }
23
+ };
24
+ export {
25
+ accordionTransition
26
+ };
@@ -0,0 +1,7 @@
1
+ import "../../../core.js";
2
+ import "./type.js";
3
+ import "./accordion2.js";
4
+ import "../../../utils/card-brand/brands.js";
5
+ import "../../../utils/system-info/get-browser-info.js";
6
+ import "../../../core/context.js";
7
+ import "../../AccordionItem/AccordionItem.js";
@@ -0,0 +1,10 @@
1
+ import { G } from "../../../core.js";
2
+ const AccordionContext = G({
3
+ activeName: void 0,
4
+ enableTransition: true,
5
+ onSelect: () => {
6
+ }
7
+ });
8
+ export {
9
+ AccordionContext
10
+ };
@@ -1,4 +1,4 @@
1
- import { w, h, T, u, b } from "../../../core.js";
1
+ import { w, h, T, u, b, P } from "../../../core.js";
2
2
  import { useBEM } from "../../../hooks/useBEM.js";
3
3
  import { useI18n } from "../../../hooks/useI18n.js";
4
4
  import "../../../utils/card-brand/brands.js";
@@ -6,7 +6,17 @@ import "../../../utils/system-info/get-browser-info.js";
6
6
  import "./modal2.js";
7
7
  const { bem } = useBEM("modal");
8
8
  const Modal = w((props) => {
9
- const { show = false, width, height, maskClosable, header, children, onChange, style } = props;
9
+ const {
10
+ show = false,
11
+ width,
12
+ height,
13
+ maskClosable,
14
+ header,
15
+ children,
16
+ onChange,
17
+ style,
18
+ appendToBody = false
19
+ } = props;
10
20
  const [modalWidth, setModalWidth] = h();
11
21
  const [modalHeight, setModalHeight] = h();
12
22
  const { i18n } = useI18n();
@@ -20,7 +30,7 @@ const Modal = w((props) => {
20
30
  const handleClickClose = () => {
21
31
  onChange == null ? void 0 : onChange(false);
22
32
  };
23
- return /* @__PURE__ */ u(b, { children: show && /* @__PURE__ */ u("div", { className: bem(), children: [
33
+ const modalContent = /* @__PURE__ */ u(b, { children: show && /* @__PURE__ */ u("div", { className: bem(), children: [
24
34
  /* @__PURE__ */ u("div", { className: bem("mask"), onClick: handleClickMask }),
25
35
  /* @__PURE__ */ u(
26
36
  "div",
@@ -34,6 +44,10 @@ const Modal = w((props) => {
34
44
  }
35
45
  )
36
46
  ] }) });
47
+ if (appendToBody) {
48
+ return show ? P(modalContent, document.body) : null;
49
+ }
50
+ return modalContent;
37
51
  });
38
52
  export {
39
53
  Modal