@paykka/card-checkout-ui 0.11.6 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/dist/card-checkout-ui.js +19 -19
  2. package/dist/card-checkout-ui.umd.cjs +19 -19
  3. package/dist/es/_commonjsHelpers.js +82 -1
  4. package/dist/es/api/index.js +1 -0
  5. package/dist/es/api/modules/address/index.js +9 -9
  6. package/dist/es/api/modules/ali-pay/index.js +10 -49
  7. package/dist/es/api/modules/apple-pay/index.js +13 -59
  8. package/dist/es/api/modules/boost/index.js +8 -48
  9. package/dist/es/api/modules/card/index.js +10 -54
  10. package/dist/es/api/modules/checkout/index.js +11 -9
  11. package/dist/es/api/modules/checkout/map.js +25 -18
  12. package/dist/es/api/modules/encrypted-card/index.js +3 -2
  13. package/dist/es/api/modules/gcash/index.js +8 -48
  14. package/dist/es/api/modules/get-browser-params.js +4 -1
  15. package/dist/es/api/modules/google-pay/index.js +10 -56
  16. package/dist/es/api/modules/grab-pay/index.js +8 -48
  17. package/dist/es/api/modules/index.js +1 -0
  18. package/dist/es/api/modules/line-pay/index.js +8 -48
  19. package/dist/es/api/modules/map.js +17 -11
  20. package/dist/es/api/modules/may-bank-qr-pay/index.js +8 -48
  21. package/dist/es/api/modules/nine-pay/index.js +8 -48
  22. package/dist/es/api/modules/paymaya/index.js +8 -48
  23. package/dist/es/api/modules/risk/index.js +2 -1
  24. package/dist/es/api/modules/sepa/index.js +10 -51
  25. package/dist/es/api/modules/shopee-pay/index.js +8 -48
  26. package/dist/es/api/modules/threeDS/index.js +3 -0
  27. package/dist/es/api/modules/tng-wallet/index.js +8 -48
  28. package/dist/es/api/modules/wechat-pay/index.js +10 -51
  29. package/dist/es/api/modules/zalopay/index.js +16 -0
  30. package/dist/es/api/utils/index.js +59 -0
  31. package/dist/es/components/AddressField/index.js +37 -37
  32. package/dist/es/components/AliPay/index.js +158 -111
  33. package/dist/es/components/ApplePay/index.js +99 -67
  34. package/dist/es/components/Boost/index.js +91 -70
  35. package/dist/es/components/Card/index.js +114 -107
  36. package/dist/es/components/CardSelector/index.js +1 -1
  37. package/dist/es/components/DropIn/index.js +12 -4
  38. package/dist/es/components/EncryptedCard/index.js +6 -2
  39. package/dist/es/components/GooglePay/index.js +94 -60
  40. package/dist/es/components/GrabPay/index.js +91 -70
  41. package/dist/es/components/GuideCard/index.js +10 -7
  42. package/dist/es/components/LinePay/index.js +91 -70
  43. package/dist/es/components/MayBankQRPay/index.js +302 -275
  44. package/dist/es/components/NinePay/index.js +91 -70
  45. package/dist/es/components/SecuredFieldsProvider/index.js +26 -9
  46. package/dist/es/components/SecuredIframe/index.js +40 -61
  47. package/dist/es/components/Sepa/index.js +72 -53
  48. package/dist/es/components/ShopeePay/index.js +91 -70
  49. package/dist/es/components/SubmitButton/index.js +8 -7
  50. package/dist/es/components/TNGWallet/index.js +91 -70
  51. package/dist/es/components/ThreeDS/index.js +32 -7
  52. package/dist/es/components/WechatPay/index.js +151 -102
  53. package/dist/es/components/business/QRCodeModal/QRCodeModal.js +26 -6
  54. package/dist/es/components/index.js +1 -0
  55. package/dist/es/components/internal/Form/FormItem.js +1 -1
  56. package/dist/es/components/internal/Form/util.js +1 -1
  57. package/dist/es/components/internal/Modal/Modal.js +1 -1
  58. package/dist/es/components/internal/Select/Select.js +19 -8
  59. package/dist/es/components/internal/Select/SelectMenu.js +2 -2
  60. package/dist/es/components/internal/Select/SelectMenuItem.js +12 -4
  61. package/dist/es/components/internal/icons/IconError.js +7 -4
  62. package/dist/es/components/internal/icons/IconZalopay.js +47 -0
  63. package/dist/es/components/internal/icons/IconZalopayComplete.js +48 -0
  64. package/dist/es/components/wallets/GCash/GCash.js +80 -56
  65. package/dist/es/components/wallets/Paymaya/Paymaya.js +91 -70
  66. package/dist/es/components/wallets/Zalopay/Zalopay.js +381 -0
  67. package/dist/es/components/wallets/Zalopay/index.js +1 -0
  68. package/dist/es/components/wallets/Zalopay/type.js +1 -0
  69. package/dist/es/components/wallets/Zalopay/zalopay2.js +1 -0
  70. package/dist/es/config.js +5 -5
  71. package/dist/es/constant.js +8 -2
  72. package/dist/es/core/{Address.js → address.js} +8 -16
  73. package/dist/es/core/{PayKKaCheckout.js → checkout.js} +101 -27
  74. package/dist/es/core/create.js +1 -1
  75. package/dist/es/core/query.js +3 -2
  76. package/dist/es/core/{Session.js → session.js} +28 -32
  77. package/dist/es/core/theme.js +65 -0
  78. package/dist/es/core.js +0 -4
  79. package/dist/es/hooks/usePayment.js +14 -0
  80. package/dist/es/i18n/locales/de-DE.js +3 -1
  81. package/dist/es/i18n/locales/en-GB.js +3 -1
  82. package/dist/es/i18n/locales/es-ES.js +3 -1
  83. package/dist/es/i18n/locales/fr-FR.js +3 -1
  84. package/dist/es/i18n/locales/ja-JP.js +3 -1
  85. package/dist/es/i18n/locales/ko-KR.js +3 -1
  86. package/dist/es/i18n/locales/nl-NL.js +3 -1
  87. package/dist/es/i18n/locales/pt-PT.js +3 -1
  88. package/dist/es/i18n/locales/ru-RU.js +3 -1
  89. package/dist/es/i18n/locales/zh-CN.js +3 -1
  90. package/dist/es/i18n/locales/zh-HK.js +3 -1
  91. package/dist/es/i18n/locales/zh-TW.js +3 -1
  92. package/dist/es/index.js +21 -7
  93. package/dist/es/style.css +1 -1
  94. package/dist/es/types/index.js +7 -0
  95. package/dist/es/utils/colors.js +5 -1
  96. package/dist/es/utils/format.js +0 -5
  97. package/dist/es/utils/object.js +31 -1
  98. package/dist/es/utils/payment.js +82 -0
  99. package/dist/es/utils/redirect.js +4 -4
  100. package/dist/es/utils/string.js +10 -0
  101. package/dist/es/utils/system-info/is-ua-webview.js +14 -12
  102. package/dist/es/utils/theme.js +7 -0
  103. package/dist/style.css +1 -1
  104. package/dist/types/api/modules/address/index.d.ts +15 -6
  105. package/dist/types/api/modules/ali-pay/index.d.ts +3 -19
  106. package/dist/types/api/modules/apple-pay/index.d.ts +4 -14
  107. package/dist/types/api/modules/boost/index.d.ts +3 -23
  108. package/dist/types/api/modules/card/index.d.ts +3 -30
  109. package/dist/types/api/modules/checkout/index.d.ts +3 -3
  110. package/dist/types/api/modules/checkout/map.d.ts +3 -3
  111. package/dist/types/api/modules/checkout/type.d.ts +33 -4
  112. package/dist/types/api/modules/gcash/index.d.ts +3 -23
  113. package/dist/types/api/modules/get-browser-params.d.ts +1 -0
  114. package/dist/types/api/modules/google-pay/index.d.ts +3 -13
  115. package/dist/types/api/modules/grab-pay/index.d.ts +3 -23
  116. package/dist/types/api/modules/index.d.ts +1 -0
  117. package/dist/types/api/modules/line-pay/index.d.ts +3 -23
  118. package/dist/types/api/modules/map.d.ts +2 -2
  119. package/dist/types/api/modules/may-bank-qr-pay/index.d.ts +3 -23
  120. package/dist/types/api/modules/nine-pay/index.d.ts +3 -23
  121. package/dist/types/api/modules/paymaya/index.d.ts +3 -23
  122. package/dist/types/api/modules/sepa/index.d.ts +3 -24
  123. package/dist/types/api/modules/shopee-pay/index.d.ts +3 -23
  124. package/dist/types/api/modules/tng-wallet/index.d.ts +3 -23
  125. package/dist/types/api/modules/type.d.ts +74 -21
  126. package/dist/types/api/modules/wechat-pay/index.d.ts +3 -20
  127. package/dist/types/api/modules/zalopay/index.d.ts +4 -0
  128. package/dist/types/api/utils/index.d.ts +48 -0
  129. package/dist/types/components/AddressField/type.d.ts +3 -9
  130. package/dist/types/components/AliPay/AliPay.d.ts +6 -2
  131. package/dist/types/components/AliPay/type.d.ts +15 -2
  132. package/dist/types/components/ApplePay/ApplePay.d.ts +6 -2
  133. package/dist/types/components/ApplePay/type.d.ts +10 -14
  134. package/dist/types/components/ApplePay/utils.d.ts +1 -1
  135. package/dist/types/components/Boost/Boost.d.ts +6 -2
  136. package/dist/types/components/Boost/type.d.ts +2 -24
  137. package/dist/types/components/Card/Card.d.ts +6 -2
  138. package/dist/types/components/Card/type.d.ts +3 -43
  139. package/dist/types/components/DropIn/DropIn.d.ts +6 -2
  140. package/dist/types/components/DropIn/type.d.ts +4 -10
  141. package/dist/types/components/GooglePay/GooglePay.d.ts +6 -2
  142. package/dist/types/components/GooglePay/createGooglePay.d.ts +2 -1
  143. package/dist/types/components/GooglePay/type.d.ts +10 -26
  144. package/dist/types/components/GrabPay/GrabPay.d.ts +6 -2
  145. package/dist/types/components/GrabPay/type.d.ts +3 -25
  146. package/dist/types/components/LinePay/LinePay.d.ts +6 -2
  147. package/dist/types/components/LinePay/type.d.ts +3 -25
  148. package/dist/types/components/MayBankQRPay/MayBankQRPay.d.ts +6 -2
  149. package/dist/types/components/MayBankQRPay/type.d.ts +3 -25
  150. package/dist/types/components/NinePay/NinePay.d.ts +6 -2
  151. package/dist/types/components/NinePay/type.d.ts +3 -25
  152. package/dist/types/components/SecuredFieldsProvider/type.d.ts +5 -0
  153. package/dist/types/components/SecuredIframe/HiddenIframe.d.ts +3 -1
  154. package/dist/types/components/Sepa/Sepa.d.ts +6 -2
  155. package/dist/types/components/Sepa/type.d.ts +3 -2
  156. package/dist/types/components/ShopeePay/ShopeePay.d.ts +6 -2
  157. package/dist/types/components/ShopeePay/type.d.ts +3 -25
  158. package/dist/types/components/TNGWallet/TNGWallet.d.ts +6 -2
  159. package/dist/types/components/TNGWallet/type.d.ts +3 -25
  160. package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +2 -0
  161. package/dist/types/components/WechatPay/WechatPay.d.ts +6 -2
  162. package/dist/types/components/WechatPay/type.d.ts +15 -2
  163. package/dist/types/components/business/QRCodeModal/type.d.ts +2 -0
  164. package/dist/types/components/index.d.ts +1 -0
  165. package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
  166. package/dist/types/components/internal/Select/SelectMenu.d.ts +1 -1
  167. package/dist/types/components/internal/icons/IconZalopay.d.ts +2 -0
  168. package/dist/types/components/internal/icons/IconZalopayComplete.d.ts +2 -0
  169. package/dist/types/components/internal/icons/index.d.ts +3 -0
  170. package/dist/types/components/wallets/GCash/GCash.d.ts +6 -2
  171. package/dist/types/components/wallets/GCash/type.d.ts +3 -35
  172. package/dist/types/components/wallets/Paymaya/Paymaya.d.ts +6 -2
  173. package/dist/types/components/wallets/Paymaya/type.d.ts +3 -25
  174. package/dist/types/components/wallets/Zalopay/Zalopay.d.ts +10 -0
  175. package/dist/types/components/wallets/Zalopay/index.d.ts +2 -0
  176. package/dist/types/components/wallets/Zalopay/type.d.ts +39 -0
  177. package/dist/types/config.d.ts +2 -4
  178. package/dist/types/constant.d.ts +3 -1
  179. package/dist/types/core/{Address.d.ts → address.d.ts} +23 -24
  180. package/dist/types/core/{PayKKaCheckout.d.ts → checkout.d.ts} +9 -3
  181. package/dist/types/core/context.d.ts +3 -2
  182. package/dist/types/core/index.d.ts +3 -2
  183. package/dist/types/core/query.d.ts +2 -2
  184. package/dist/types/core/session.d.ts +23 -0
  185. package/dist/types/core/theme.d.ts +7 -0
  186. package/dist/types/hooks/index.d.ts +1 -0
  187. package/dist/types/hooks/usePayment.d.ts +8 -0
  188. package/dist/types/i18n/locales/de-DE.d.ts +2 -0
  189. package/dist/types/i18n/locales/en-GB.d.ts +2 -0
  190. package/dist/types/i18n/locales/es-ES.d.ts +2 -0
  191. package/dist/types/i18n/locales/fr-FR.d.ts +2 -0
  192. package/dist/types/i18n/locales/ja-JP.d.ts +2 -0
  193. package/dist/types/i18n/locales/ko-KR.d.ts +2 -0
  194. package/dist/types/i18n/locales/nl-NL.d.ts +2 -0
  195. package/dist/types/i18n/locales/pt-PT.d.ts +2 -0
  196. package/dist/types/i18n/locales/ru-RU.d.ts +2 -0
  197. package/dist/types/i18n/locales/zh-CN.d.ts +2 -0
  198. package/dist/types/i18n/locales/zh-HK.d.ts +2 -0
  199. package/dist/types/i18n/locales/zh-TW.d.ts +2 -0
  200. package/dist/types/index.d.ts +2 -1
  201. package/dist/types/types/index.d.ts +70 -32
  202. package/dist/types/types/message.d.ts +30 -25
  203. package/dist/types/utils/card-brand/index.d.ts +3 -3
  204. package/dist/types/utils/colors.d.ts +1 -0
  205. package/dist/types/utils/index.d.ts +4 -2
  206. package/dist/types/utils/object.d.ts +7 -0
  207. package/dist/types/utils/payment.d.ts +37 -0
  208. package/dist/types/utils/string.d.ts +1 -0
  209. package/dist/types/utils/style.d.ts +1 -1
  210. package/dist/types/utils/system-info/is-ua-webview.d.ts +1 -1
  211. package/dist/types/utils/theme.d.ts +4 -0
  212. package/package.json +3 -3
  213. package/dist/es/utils/deep-freeze.js +0 -13
  214. package/dist/es/utils/obj.js +0 -22
  215. package/dist/types/core/Session.d.ts +0 -16
  216. package/dist/types/utils/deep-freeze.d.ts +0 -1
  217. package/dist/types/utils/obj.d.ts +0 -6
@@ -0,0 +1,381 @@
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 { isMobile } from "../../../utils/system-info/get-system-info.js";
7
+ import { normalizedClass, formatAmount } from "../../../utils/format.js";
8
+ import { redirectToPayment } from "../../../utils/redirect.js";
9
+ import { processPaymentStatus } from "../../../utils/payment.js";
10
+ import { isTimeoutError } from "../../../api/http.js";
11
+ import { getBrowserParams } from "../../../api/modules/get-browser-params.js";
12
+ import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../../constant.js";
13
+ import { getZalopayPayInfo, zalopayPay } from "../../../api/modules/zalopay/index.js";
14
+ import { PayKKaError } from "../../../core/error.js";
15
+ import { usePayState } from "../../../hooks/usePayState.js";
16
+ import { useRetry } from "../../../hooks/useRetry.js";
17
+ import { usePaymentStatus } from "../../../hooks/usePayment.js";
18
+ import { createEmailCore, EmailField } from "../../EmailField/EmailField.js";
19
+ import { SubmitButton } from "../../SubmitButton/index.js";
20
+ import { GuideCard } from "../../GuideCard/index.js";
21
+ import { AddressField } from "../../AddressField/index.js";
22
+ import { Info } from "../../internal/Info/Info.js";
23
+ import "../../internal/Form/type.js";
24
+ import "../../internal/Form/context.js";
25
+ import "../../internal/Form/FormItem.js";
26
+ import { Form } from "../../internal/Form/Form.js";
27
+ import { QRCodeModal } from "../../business/QRCodeModal/QRCodeModal.js";
28
+ import { IconZalopayComplete } from "../../internal/icons/IconZalopayComplete.js";
29
+ import "./zalopay2.js";
30
+ const { bem } = useBEM("zalopay");
31
+ const fieldClassNames = bem("field");
32
+ const Zalopay = w((props, ref) => {
33
+ var _a;
34
+ const {
35
+ session,
36
+ showEmail = false,
37
+ showAddress = false,
38
+ core,
39
+ redirectMode = "auto",
40
+ autoQuery = true,
41
+ showGuideCard = true,
42
+ enableQRCodeModal = true,
43
+ hidePaymentButton = false
44
+ } = props;
45
+ F(ref, () => ({
46
+ stopRetry: () => {
47
+ setPaymentButtonStatus("unSubmit");
48
+ stopReFetchPayInfo();
49
+ },
50
+ startRetry: (timeout) => {
51
+ setPaymentButtonStatus("loading");
52
+ startReFetchPayInfo({ timeout });
53
+ },
54
+ updateAddress: () => {
55
+ var _a2;
56
+ if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
57
+ return;
58
+ const newForm = Object.assign(form, { address: addressCore.getAddressState() });
59
+ setForm(newForm);
60
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressCore.getAddressState());
61
+ validateForm();
62
+ },
63
+ updateEmail: () => {
64
+ var _a2;
65
+ if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
66
+ return;
67
+ const newForm = Object.assign(form, { email: emailState.email });
68
+ setForm(newForm);
69
+ (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
70
+ validateForm();
71
+ },
72
+ payment: () => {
73
+ hidePaymentButton && onSubmit();
74
+ }
75
+ }));
76
+ const addressCore = core.getAddressCore();
77
+ const emailState = createEmailCore();
78
+ const addressFieldRef = A(null);
79
+ const emailFieldRef = A(null);
80
+ const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
81
+ const { i18n, sessionReady } = usePayState(session);
82
+ const { errorMsg, setErrorMsg, paymentButtonStatus, setPaymentButtonStatus } = usePaymentStatus();
83
+ const formRef = A(null);
84
+ const [form, setForm] = h({
85
+ email: "",
86
+ address: {
87
+ country: void 0,
88
+ province: void 0,
89
+ city: void 0,
90
+ area: void 0,
91
+ postCode: void 0,
92
+ address1: void 0,
93
+ address2: void 0
94
+ }
95
+ });
96
+ const [validated, setValidated] = h(false);
97
+ const [fieldStatus, setFieldStatus] = h();
98
+ const [showQRCodeModal, setShowQRCodeModal] = h(false);
99
+ const [qrCodeInfo, setQrCodeInfo] = h();
100
+ const initFieldStatus = () => {
101
+ const { field, sessionMode } = session.checkout;
102
+ const { email, address } = field;
103
+ if (sessionMode === SessionMode.COMPONENT) {
104
+ if (email.disabled) {
105
+ email.show = showEmail;
106
+ }
107
+ if (showAddress && !(address == null ? void 0 : address.show)) {
108
+ address.show = true;
109
+ }
110
+ }
111
+ setFieldStatus({ ...field });
112
+ };
113
+ y(() => {
114
+ if (!sessionReady) {
115
+ return;
116
+ }
117
+ const { bill = {}, supportMethods = [], country } = (session == null ? void 0 : session.checkout) || {};
118
+ if (!supportMethods.includes(PaymentMethod.ZALOPAY)) {
119
+ return;
120
+ }
121
+ initFieldStatus();
122
+ setIsCheckoutEnabled(true);
123
+ country && addressCore.setCountry(country);
124
+ form.email = bill.email ?? "";
125
+ form.address.country = country;
126
+ if (autoQuery && core.processingPaymentMethod === PaymentMethod.ZALOPAY) {
127
+ setPaymentButtonStatus("loading");
128
+ startReFetchPayInfo();
129
+ }
130
+ }, [sessionReady]);
131
+ const processOnError = (error) => {
132
+ var _a2;
133
+ setShowQRCodeModal(false);
134
+ (_a2 = props.onError) == null ? void 0 : _a2.call(props, error);
135
+ core.resetEnablePaymentMethod();
136
+ };
137
+ const onTimeout = q(
138
+ (message) => {
139
+ var _a2;
140
+ setShowQRCodeModal(false);
141
+ setErrorMsg(message || i18n.get("common.payTimeout"));
142
+ setPaymentButtonStatus("unSubmit");
143
+ (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
144
+ core.resetEnablePaymentMethod();
145
+ },
146
+ [i18n, props.onTimeout]
147
+ );
148
+ const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
149
+ (timeout) => pay(true, timeout),
150
+ {
151
+ timeout: 10 * 60 * 1e3,
152
+ onTimeout: () => onTimeout(i18n.get("common.queryTimeout"))
153
+ }
154
+ );
155
+ const getPaymentParams = async () => {
156
+ return {
157
+ sessionId: session.sessionId,
158
+ clientKey: session.clientKey,
159
+ payment: {
160
+ paymentMethod: PaymentMethod.ZALOPAY
161
+ },
162
+ bill: {
163
+ email: form.email,
164
+ addressLine1: form.address.address1,
165
+ addressLine2: form.address.address2,
166
+ postalCode: form.address.postCode,
167
+ country: form.address.country,
168
+ district: form.address.area,
169
+ state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
170
+ city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
171
+ },
172
+ browser: await getBrowserParams()
173
+ };
174
+ };
175
+ const pay = async (search = false, timeout) => {
176
+ var _a2, _b, _c, _d, _e;
177
+ try {
178
+ const requestOptions = { locale: i18n.locale, timeout };
179
+ let res = null;
180
+ if (search) {
181
+ const extraParams = (_b = (_a2 = core.config)._getExtraParams) == null ? void 0 : _b.call(_a2, "query", PaymentMethod.ZALOPAY);
182
+ res = await getZalopayPayInfo(
183
+ {
184
+ sessionId: session.sessionId,
185
+ clientKey: session.clientKey,
186
+ paymentMethod: PaymentMethod.ZALOPAY
187
+ },
188
+ extraParams,
189
+ requestOptions
190
+ );
191
+ } else {
192
+ const extraParams = (_d = (_c = core.config)._getExtraParams) == null ? void 0 : _d.call(_c, "payment", PaymentMethod.ZALOPAY);
193
+ res = await zalopayPay(await getPaymentParams(), extraParams, requestOptions);
194
+ }
195
+ !search && ((_e = props.onSubmitResponse) == null ? void 0 : _e.call(props, res));
196
+ const { errorMessage, errorCode, payInfo = {}, sessionId } = res;
197
+ sessionId && (session.sessionId = sessionId);
198
+ const { paymentExpiredAt } = payInfo;
199
+ let end = true;
200
+ processPaymentStatus(res, {
201
+ onProcessing: () => {
202
+ if (!search && payInfo) {
203
+ if (isMobile()) {
204
+ if (redirectMode === "auto") {
205
+ redirectToPayment(payInfo);
206
+ return;
207
+ }
208
+ } else {
209
+ if (enableQRCodeModal) {
210
+ setShowQRCodeModal(true);
211
+ setQrCodeInfo({
212
+ qrCode: payInfo.qr_code || payInfo.request_url,
213
+ expiredTime: paymentExpiredAt
214
+ });
215
+ }
216
+ startReFetchPayInfo();
217
+ }
218
+ }
219
+ end = false;
220
+ },
221
+ onSuccess: () => {
222
+ var _a3;
223
+ setShowQRCodeModal(false);
224
+ setPaymentButtonStatus("success");
225
+ (_a3 = props.onSuccess) == null ? void 0 : _a3.call(props, res);
226
+ },
227
+ onFailure: () => {
228
+ errorMessage && setErrorMsg(errorMessage);
229
+ setPaymentButtonStatus("unSubmit");
230
+ processOnError(new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
231
+ },
232
+ onCanceled: () => {
233
+ var _a3;
234
+ core.resetEnablePaymentMethod();
235
+ setPaymentButtonStatus("unSubmit");
236
+ (_a3 = props.onTimeout) == null ? void 0 : _a3.call(props, "channel");
237
+ },
238
+ onExpired: () => {
239
+ var _a3;
240
+ setShowQRCodeModal(false);
241
+ setPaymentButtonStatus("unSubmit");
242
+ (_a3 = props.onExpired) == null ? void 0 : _a3.call(props);
243
+ },
244
+ onDefault: () => {
245
+ setPaymentButtonStatus("unSubmit");
246
+ }
247
+ });
248
+ return { end };
249
+ } catch (error) {
250
+ if (isTimeoutError(error)) {
251
+ if (search) {
252
+ return { end: false };
253
+ } else {
254
+ onTimeout();
255
+ return { end: true };
256
+ }
257
+ } else {
258
+ const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
259
+ message && setErrorMsg(message);
260
+ processOnError(new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
261
+ setPaymentButtonStatus("unSubmit");
262
+ return { end: true };
263
+ }
264
+ }
265
+ };
266
+ const validateForm = () => {
267
+ var _a2;
268
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
269
+ setValidated(true);
270
+ }).catch(() => {
271
+ setValidated(false);
272
+ });
273
+ };
274
+ y(() => {
275
+ validateForm();
276
+ }, [form]);
277
+ const onSubmit = async () => {
278
+ var _a2;
279
+ setErrorMsg("");
280
+ (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
281
+ var _a3;
282
+ (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
283
+ (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
284
+ if (errors) {
285
+ setPaymentButtonStatus("unSubmit");
286
+ return;
287
+ }
288
+ setErrorMsg("");
289
+ setPaymentButtonStatus("loading");
290
+ await pay();
291
+ });
292
+ };
293
+ const handleCloseQRCodeModal = () => {
294
+ var _a2;
295
+ setPaymentButtonStatus("unSubmit");
296
+ stopReFetchPayInfo();
297
+ setShowQRCodeModal(false);
298
+ setQrCodeInfo(void 0);
299
+ (_a2 = props.onCloseModal) == null ? void 0 : _a2.call(props);
300
+ };
301
+ const setFormRef = (dom) => {
302
+ formRef.current = dom;
303
+ dom && validateForm();
304
+ };
305
+ const PaymentButton = () => {
306
+ var _a2;
307
+ const transAmount = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.transAmount;
308
+ const amountText = (transAmount == null ? void 0 : transAmount.amount) ? formatAmount(transAmount).jointSymbol() : "";
309
+ const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
310
+ return /* @__PURE__ */ u(
311
+ SubmitButton,
312
+ {
313
+ className: bem("button"),
314
+ status: paymentButtonStatus,
315
+ text,
316
+ onClick: onSubmit,
317
+ verified: validated
318
+ }
319
+ );
320
+ };
321
+ const Email = () => {
322
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.email.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
323
+ EmailField,
324
+ {
325
+ ref: emailFieldRef,
326
+ value: form.email,
327
+ disabled: fieldStatus == null ? void 0 : fieldStatus.email.disabled
328
+ }
329
+ ) }) });
330
+ };
331
+ const ErrorMessage = () => {
332
+ return /* @__PURE__ */ u(b, { children: !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg }) });
333
+ };
334
+ const Address = () => {
335
+ var _a2, _b;
336
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
337
+ AddressField,
338
+ {
339
+ ref: addressFieldRef,
340
+ value: form.address,
341
+ country: ((_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.country) || ((_b = session == null ? void 0 : session.checkout) == null ? void 0 : _b.bill.country),
342
+ onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
343
+ }
344
+ ) }) });
345
+ };
346
+ return /* @__PURE__ */ u(
347
+ CoreContext.Provider,
348
+ {
349
+ value: {
350
+ i18n,
351
+ session,
352
+ core
353
+ },
354
+ children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u("div", { className: core.theme.className, children: [
355
+ showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.ZALOPAY }),
356
+ /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), children: [
357
+ Email(),
358
+ Address(),
359
+ /* @__PURE__ */ u("div", { className: bem("footer-wrapper"), children: [
360
+ ErrorMessage(),
361
+ !hidePaymentButton && PaymentButton()
362
+ ] })
363
+ ] }) }),
364
+ showQRCodeModal && /* @__PURE__ */ u(
365
+ QRCodeModal,
366
+ {
367
+ title: i18n.get("qrCode.scanByZalopay"),
368
+ qrCode: qrCodeInfo.qrCode,
369
+ icon: /* @__PURE__ */ u(IconZalopayComplete, { size: 22 }),
370
+ amount: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.transAmount,
371
+ expiredTime: qrCodeInfo.expiredTime,
372
+ onClose: handleCloseQRCodeModal
373
+ }
374
+ )
375
+ ] })
376
+ }
377
+ );
378
+ });
379
+ export {
380
+ Zalopay
381
+ };
@@ -0,0 +1 @@
1
+ import "./Zalopay.js";
package/dist/es/config.js CHANGED
@@ -8,7 +8,7 @@ let cdnUrl = `${cdnOrigin}${cdnDir}`;
8
8
  let fraudDetectionEnv = void 0;
9
9
  let customReqHeaders = {};
10
10
  let customLocale = void 0;
11
- let hidePaymentButton = false;
11
+ let apiPrefix = "";
12
12
  const setApiUrl = (url) => {
13
13
  apiUrl = url;
14
14
  };
@@ -27,20 +27,20 @@ const setCustomReqHeaders = (headers) => {
27
27
  const setCustomLocale = (locale) => {
28
28
  customLocale = locale;
29
29
  };
30
- const setCheckoutConfig = (params) => {
31
- hidePaymentButton = params.hidePaymentButton || false;
30
+ const setApiPrefix = (prefix) => {
31
+ apiPrefix = prefix;
32
32
  };
33
33
  export {
34
+ apiPrefix,
34
35
  apiUrl,
35
36
  cdnOrigin,
36
37
  cdnUrl,
37
38
  customLocale,
38
39
  customReqHeaders,
39
40
  fraudDetectionEnv,
40
- hidePaymentButton,
41
+ setApiPrefix,
41
42
  setApiUrl,
42
43
  setCDNUrl,
43
- setCheckoutConfig,
44
44
  setCustomLocale,
45
45
  setCustomReqHeaders,
46
46
  setFraudDetectionEnv
@@ -24,6 +24,7 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
24
24
  PaymentMethod2["NINE_PAY"] = "NINE_PAY";
25
25
  PaymentMethod2["GCASH"] = "G_CASH";
26
26
  PaymentMethod2["PAYMAYA"] = "PAYMAYA";
27
+ PaymentMethod2["ZALOPAY"] = "ZALOPAY";
27
28
  PaymentMethod2["SEPA_DEBIT"] = "SEPA_DEBIT";
28
29
  return PaymentMethod2;
29
30
  })(PaymentMethod || {});
@@ -43,6 +44,7 @@ var PaymentCategory = /* @__PURE__ */ ((PaymentCategory2) => {
43
44
  PaymentCategory2["NINE_PAY"] = "ninePay";
44
45
  PaymentCategory2["GCASH"] = "gcash";
45
46
  PaymentCategory2["PAYMAYA"] = "paymaya";
47
+ PaymentCategory2["ZALOPAY"] = "zalopay";
46
48
  return PaymentCategory2;
47
49
  })(PaymentCategory || {});
48
50
  const PaymentMethod2CategoryMap = {
@@ -101,8 +103,12 @@ const PaymentMethod2CategoryMap = {
101
103
  [
102
104
  "PAYMAYA"
103
105
  /* PAYMAYA */
104
- ]: "paymaya"
105
- /* PAYMAYA */
106
+ ]: "paymaya",
107
+ [
108
+ "ZALOPAY"
109
+ /* ZALOPAY */
110
+ ]: "zalopay"
111
+ /* ZALOPAY */
106
112
  };
107
113
  const CardPaymentMethods = [
108
114
  "VISA",
@@ -40,13 +40,13 @@ class AddressCore {
40
40
  __publicField(this, "addressFormat");
41
41
  __publicField(this, "validateAllFields", false);
42
42
  this.addressState = {
43
- country: "",
44
- province: "",
45
- city: "",
46
- area: "",
47
- postCode: "",
48
- address1: "",
49
- address2: ""
43
+ country: void 0,
44
+ province: void 0,
45
+ city: void 0,
46
+ area: void 0,
47
+ postCode: void 0,
48
+ address1: void 0,
49
+ address2: void 0
50
50
  };
51
51
  this.countryOptions = [];
52
52
  }
@@ -185,14 +185,6 @@ class AddressCore {
185
185
  }
186
186
  }
187
187
  _countryOptionsReadyPromise = new WeakMap();
188
- let addressState;
189
- const createAddressCore = () => {
190
- if (addressState) {
191
- return addressState;
192
- } else {
193
- return addressState = new AddressCore();
194
- }
195
- };
196
188
  export {
197
- createAddressCore
189
+ AddressCore
198
190
  };