@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.
- package/dist/card-checkout-ui.js +20 -13
- package/dist/card-checkout-ui.umd.cjs +20 -13
- package/dist/es/_commonjsHelpers.js +1 -0
- package/dist/es/api/http.js +19 -21
- package/dist/es/api/index.js +1 -0
- package/dist/es/api/modules/ali-pay/index.js +19 -11
- package/dist/es/api/modules/apple-pay/index.js +10 -26
- package/dist/es/api/modules/boost/index.js +56 -0
- package/dist/es/api/modules/card/index.js +17 -11
- package/dist/es/api/modules/checkout/index.js +6 -6
- package/dist/es/api/modules/checkout/map.js +23 -6
- package/dist/es/api/modules/gcash/index.js +56 -0
- package/dist/es/api/modules/get-browser-params.js +2 -2
- package/dist/es/api/modules/google-pay/index.js +10 -26
- package/dist/es/api/modules/grab-pay/index.js +56 -0
- package/dist/es/api/modules/index.js +1 -0
- package/dist/es/api/modules/line-pay/index.js +56 -0
- package/dist/es/api/modules/may-bank-qr-pay/index.js +56 -0
- package/dist/es/api/modules/nine-pay/index.js +56 -0
- package/dist/es/api/modules/paymaya/index.js +56 -0
- package/dist/es/api/modules/sepa/index.js +19 -11
- package/dist/es/api/modules/shopee-pay/index.js +56 -0
- package/dist/es/api/modules/tng-wallet/index.js +56 -0
- package/dist/es/api/modules/wechat-pay/index.js +18 -31
- package/dist/es/components/AccordionItem/AccordionItem.js +36 -0
- package/dist/es/components/AliPay/index.js +27 -39
- package/dist/es/components/ApplePay/index.js +16 -37
- package/dist/es/components/Boost/index.js +322 -0
- package/dist/es/components/Card/index.js +52 -41
- package/dist/es/components/CardBrands/index.js +2 -2
- package/dist/es/components/CardNumberField/index.js +113 -106
- package/dist/es/components/DropIn/index.js +204 -49
- package/dist/es/components/GooglePay/index.js +5 -4
- package/dist/es/components/GrabPay/index.js +322 -0
- package/dist/es/components/GuideCard/index.js +43 -0
- package/dist/es/components/LinePay/index.js +322 -0
- package/dist/es/components/MayBankQRPay/index.js +322 -0
- package/dist/es/components/NinePay/index.js +322 -0
- package/dist/es/components/SecuredIframe/index.js +3 -2
- package/dist/es/components/Sepa/index.js +6 -9
- package/dist/es/components/ShopeePay/index.js +322 -0
- package/dist/es/components/SubmitButton/index.js +6 -20
- package/dist/es/components/TNGWallet/index.js +322 -0
- package/dist/es/components/WechatPay/index.js +30 -49
- package/dist/es/components/business/QRCodeModal/QRCodeModal.js +41 -0
- package/dist/es/components/business/QRCodeModal/index.js +6 -0
- package/dist/es/components/business/QRCodeModal/qr-code-modal.js +1 -0
- package/dist/es/components/business/QRCodeModal/type.js +1 -0
- package/dist/es/components/business/index.js +6 -0
- package/dist/es/components/index.js +9 -0
- package/dist/es/components/internal/Accordion/Accordion.js +14 -0
- package/dist/es/components/internal/Accordion/accordion2.js +1 -0
- package/dist/es/components/internal/Accordion/accordionTransition.js +26 -0
- package/dist/es/components/internal/Accordion/index.js +7 -0
- package/dist/es/components/internal/Accordion/type.js +10 -0
- package/dist/es/components/internal/Modal/Modal.js +17 -3
- package/dist/es/components/internal/Modal/index.js +1 -0
- package/dist/es/components/internal/Modal/type.js +1 -0
- package/dist/es/components/internal/QRCode/QRCode.js +31 -0
- package/dist/es/components/internal/QRCode/index.js +4 -0
- package/dist/es/components/internal/QRCode/type.js +1 -0
- package/dist/es/components/internal/icons/IconBoost.js +63 -0
- package/dist/es/components/internal/icons/IconCard.js +1 -40
- package/dist/es/components/internal/icons/IconCard2.js +60 -0
- package/dist/es/components/internal/icons/IconGCash.js +196 -0
- package/dist/es/components/internal/icons/IconGcashComplete.js +184 -0
- package/dist/es/components/internal/icons/IconGrabPay.js +59 -0
- package/dist/es/components/internal/icons/IconLinePay.js +99 -0
- package/dist/es/components/internal/icons/IconMayBankQRPay.js +69 -0
- package/dist/es/components/internal/icons/IconNinePay.js +255 -0
- package/dist/es/components/internal/icons/IconPaymaya.js +114 -0
- package/dist/es/components/internal/icons/IconRedirect.js +58 -0
- package/dist/es/components/internal/icons/IconScan.js +102 -0
- package/dist/es/components/internal/icons/IconShopeePay.js +108 -0
- package/dist/es/components/internal/icons/IconTNGWallet.js +119 -0
- package/dist/es/components/internal/icons/IconUnionPay.js +65 -0
- package/dist/es/components/wallets/GCash/GCash.js +356 -0
- package/dist/es/components/wallets/GCash/g-cash.js +1 -0
- package/dist/es/components/wallets/GCash/index.js +1 -0
- package/dist/es/components/wallets/GCash/type.js +1 -0
- package/dist/es/components/wallets/Paymaya/Paymaya.js +323 -0
- package/dist/es/components/wallets/Paymaya/index.js +1 -0
- package/dist/es/components/wallets/Paymaya/paymaya2.js +1 -0
- package/dist/es/components/wallets/Paymaya/type.js +1 -0
- package/dist/es/config.js +12 -12
- package/dist/es/constant.js +84 -4
- package/dist/es/core/PayKKaCheckout.js +28 -3
- package/dist/es/core/Session.js +24 -23
- package/dist/es/core/error.js +7 -0
- package/dist/es/core/query.js +3 -2
- package/dist/es/core.js +2082 -70
- package/dist/es/hooks/usePayState.js +0 -3
- package/dist/es/i18n/I18n.js +8 -2
- package/dist/es/i18n/locales/de-DE.js +16 -1
- package/dist/es/i18n/locales/en-GB.js +16 -1
- package/dist/es/i18n/locales/es-ES.js +16 -1
- package/dist/es/i18n/locales/fr-FR.js +16 -1
- package/dist/es/i18n/locales/ja-JP.js +16 -1
- package/dist/es/i18n/locales/ko-KR.js +16 -1
- package/dist/es/i18n/locales/pt-PT.js +16 -1
- package/dist/es/i18n/locales/ru-RU.js +16 -1
- package/dist/es/i18n/locales/zh-CN.js +16 -1
- package/dist/es/i18n/locales/zh-HK.js +16 -1
- package/dist/es/i18n/locales/zh-TW.js +16 -1
- package/dist/es/i18n/util.js +12 -3
- package/dist/es/index.js +20 -0
- package/dist/es/style.css +1 -1192
- package/dist/es/types/index.js +1 -0
- package/dist/es/utils/array.js +9 -0
- package/dist/es/utils/card-brand/brands.js +11 -1
- package/dist/es/utils/card-brand/index.js +4 -3
- package/dist/es/utils/card-brand/luhn.js +25 -0
- package/dist/es/utils/date.js +25 -0
- package/dist/es/utils/detect.js +6 -0
- package/dist/es/utils/format.js +28 -12
- package/dist/es/utils/index.js +9 -1
- package/dist/es/utils/location.js +37 -0
- package/dist/es/utils/object.js +14 -0
- package/dist/es/utils/redirect.js +32 -0
- package/dist/es/utils/system-info/get-browser-info.js +4 -4
- package/dist/es/utils/system-info/get-system-info.js +11 -7
- package/dist/es/utils/system-info/index.js +4 -4
- package/dist/style.css +1 -1
- package/dist/types/api/http.d.ts +4 -10
- package/dist/types/api/modules/ali-pay/index.d.ts +2 -1
- package/dist/types/api/modules/apple-pay/index.d.ts +2 -1
- package/dist/types/api/modules/boost/index.d.ts +24 -0
- package/dist/types/api/modules/card/index.d.ts +1 -1
- package/dist/types/api/modules/checkout/index.d.ts +2 -2
- package/dist/types/api/modules/checkout/type.d.ts +9 -0
- package/dist/types/api/modules/gcash/index.d.ts +24 -0
- package/dist/types/api/modules/get-browser-params.d.ts +2 -2
- package/dist/types/api/modules/google-pay/index.d.ts +2 -1
- package/dist/types/api/modules/grab-pay/index.d.ts +24 -0
- package/dist/types/api/modules/index.d.ts +9 -0
- package/dist/types/api/modules/line-pay/index.d.ts +24 -0
- package/dist/types/api/modules/may-bank-qr-pay/index.d.ts +24 -0
- package/dist/types/api/modules/nine-pay/index.d.ts +24 -0
- package/dist/types/api/modules/paymaya/index.d.ts +24 -0
- package/dist/types/api/modules/sepa/index.d.ts +2 -1
- package/dist/types/api/modules/shopee-pay/index.d.ts +24 -0
- package/dist/types/api/modules/tng-wallet/index.d.ts +24 -0
- package/dist/types/api/modules/wechat-pay/index.d.ts +2 -1
- package/dist/types/components/Boost/Boost.d.ts +7 -0
- package/dist/types/components/Boost/index.d.ts +2 -0
- package/dist/types/components/Boost/type.d.ts +61 -0
- package/dist/types/components/DropIn/components/PaymentTabs/type.d.ts +1 -1
- package/dist/types/components/DropIn/config.d.ts +7 -0
- package/dist/types/components/DropIn/type.d.ts +11 -3
- package/dist/types/components/GrabPay/GrabPay.d.ts +7 -0
- package/dist/types/components/GrabPay/index.d.ts +2 -0
- package/dist/types/components/GrabPay/type.d.ts +61 -0
- package/dist/types/components/GuideCard/GuideCard.d.ts +3 -0
- package/dist/types/components/GuideCard/index.d.ts +2 -0
- package/dist/types/components/GuideCard/type.d.ts +4 -0
- package/dist/types/components/LinePay/LinePay.d.ts +7 -0
- package/dist/types/components/LinePay/index.d.ts +2 -0
- package/dist/types/components/LinePay/type.d.ts +61 -0
- package/dist/types/components/MayBankQRPay/MayBankQRPay.d.ts +6 -0
- package/dist/types/components/MayBankQRPay/index.d.ts +2 -0
- package/dist/types/components/MayBankQRPay/type.d.ts +61 -0
- package/dist/types/components/NinePay/NinePay.d.ts +6 -0
- package/dist/types/components/NinePay/index.d.ts +2 -0
- package/dist/types/components/NinePay/type.d.ts +61 -0
- package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +1 -1
- package/dist/types/components/ShopeePay/ShopeePay.d.ts +7 -0
- package/dist/types/components/ShopeePay/index.d.ts +2 -0
- package/dist/types/components/ShopeePay/type.d.ts +61 -0
- package/dist/types/components/SubmitButton/SubmitButton.d.ts +1 -1
- package/dist/types/components/TNGWallet/TNGWallet.d.ts +7 -0
- package/dist/types/components/TNGWallet/index.d.ts +2 -0
- package/dist/types/components/TNGWallet/type.d.ts +61 -0
- package/dist/types/components/business/QRCodeModal/QRCodeModal.d.ts +3 -0
- package/dist/types/components/business/QRCodeModal/index.d.ts +2 -0
- package/dist/types/components/business/QRCodeModal/type.d.ts +18 -0
- package/dist/types/components/business/index.d.ts +1 -0
- package/dist/types/components/index.d.ts +9 -0
- package/dist/types/components/internal/Accordion/Accordion.d.ts +3 -0
- package/dist/types/components/internal/Accordion/accordionTransition.d.ts +8 -0
- package/dist/types/components/internal/Accordion/components/AccordionItem/AccordionItem.d.ts +3 -0
- package/dist/types/components/internal/Accordion/components/AccordionItem/index.d.ts +2 -0
- package/dist/types/components/internal/Accordion/components/AccordionItem/type.d.ts +18 -0
- package/dist/types/components/internal/Accordion/index.d.ts +3 -0
- package/dist/types/components/internal/Accordion/type.d.ts +18 -0
- package/dist/types/components/internal/Modal/type.d.ts +2 -0
- package/dist/types/components/internal/QRCode/QRCode.d.ts +2 -0
- package/dist/types/components/internal/QRCode/index.d.ts +2 -0
- package/dist/types/components/internal/QRCode/type.d.ts +9 -0
- package/dist/types/components/internal/icons/IconBoost.d.ts +2 -0
- package/dist/types/components/internal/icons/IconCard2.d.ts +2 -0
- package/dist/types/components/internal/icons/IconGCash.d.ts +2 -0
- package/dist/types/components/internal/icons/IconGcashComplete.d.ts +2 -0
- package/dist/types/components/internal/icons/IconGrabPay.d.ts +2 -0
- package/dist/types/components/internal/icons/IconLinePay.d.ts +2 -0
- package/dist/types/components/internal/icons/IconMayBankQRPay.d.ts +2 -0
- package/dist/types/components/internal/icons/IconNinePay.d.ts +2 -0
- package/dist/types/components/internal/icons/IconPaymaya.d.ts +2 -0
- package/dist/types/components/internal/icons/IconRedirect.d.ts +2 -0
- package/dist/types/components/internal/icons/IconScan.d.ts +2 -0
- package/dist/types/components/internal/icons/IconShopeePay.d.ts +2 -0
- package/dist/types/components/internal/icons/IconTNGWallet.d.ts +2 -0
- package/dist/types/components/internal/icons/IconUnionPay.d.ts +2 -0
- package/dist/types/components/internal/icons/index.d.ts +13 -0
- package/dist/types/components/wallets/GCash/GCash.d.ts +6 -0
- package/dist/types/components/wallets/GCash/index.d.ts +2 -0
- package/dist/types/components/wallets/GCash/type.d.ts +66 -0
- package/dist/types/components/wallets/Paymaya/Paymaya.d.ts +6 -0
- package/dist/types/components/wallets/Paymaya/index.d.ts +2 -0
- package/dist/types/components/wallets/Paymaya/type.d.ts +61 -0
- package/dist/types/config.d.ts +9 -9
- package/dist/types/constant.d.ts +28 -3
- package/dist/types/core/PayKKaCheckout.d.ts +10 -0
- package/dist/types/core/Session.d.ts +2 -0
- package/dist/types/core/error.d.ts +3 -1
- package/dist/types/core/query.d.ts +2 -2
- package/dist/types/hooks/usePayState.d.ts +0 -3
- package/dist/types/i18n/I18n.d.ts +1 -1
- package/dist/types/i18n/locales/de-DE.d.ts +13 -0
- package/dist/types/i18n/locales/en-GB.d.ts +13 -0
- package/dist/types/i18n/locales/es-ES.d.ts +13 -0
- package/dist/types/i18n/locales/fr-FR.d.ts +13 -0
- package/dist/types/i18n/locales/ja-JP.d.ts +13 -0
- package/dist/types/i18n/locales/ko-KR.d.ts +13 -0
- package/dist/types/i18n/locales/pt-PT.d.ts +13 -0
- package/dist/types/i18n/locales/ru-RU.d.ts +13 -0
- package/dist/types/i18n/locales/zh-CN.d.ts +13 -0
- package/dist/types/i18n/locales/zh-HK.d.ts +13 -0
- package/dist/types/i18n/locales/zh-TW.d.ts +13 -0
- package/dist/types/i18n/util.d.ts +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts +10 -3
- package/dist/types/types/message.d.ts +1 -0
- package/dist/types/utils/array.d.ts +1 -0
- package/dist/types/utils/card-brand/brands.d.ts +4 -3
- package/dist/types/utils/card-brand/index.d.ts +9 -6
- package/dist/types/utils/card-brand/luhn.d.ts +9 -0
- package/dist/types/utils/date.d.ts +9 -0
- package/dist/types/utils/detect.d.ts +1 -0
- package/dist/types/utils/format.d.ts +7 -1
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/types/utils/location.d.ts +7 -0
- package/dist/types/utils/object.d.ts +1 -0
- package/dist/types/utils/redirect.d.ts +5 -0
- package/dist/types/utils/system-info/get-browser-info.d.ts +1 -1
- package/dist/types/utils/system-info/get-system-info.d.ts +3 -2
- package/dist/types/utils/system-info/index.d.ts +3 -3
- package/package.json +4 -2
|
@@ -2,7 +2,6 @@ import { w, A, h, F, y, q, u } from "../../core.js";
|
|
|
2
2
|
import { createAddressCore } from "../../core/Address.js";
|
|
3
3
|
import { useBEM } from "../../hooks/useBEM.js";
|
|
4
4
|
import { CoreContext } from "../../core/context.js";
|
|
5
|
-
import { isUndefined } from "../../utils/is.js";
|
|
6
5
|
import "../../utils/card-brand/brands.js";
|
|
7
6
|
import "../../utils/system-info/get-browser-info.js";
|
|
8
7
|
import { cssVarPrefix, normalizedClass, formatAmount, trimAll } from "../../utils/format.js";
|
|
@@ -89,12 +88,10 @@ const Sepa = w((props, ref) => {
|
|
|
89
88
|
});
|
|
90
89
|
}, []);
|
|
91
90
|
const Button = () => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
amountStr = formatAmount(+amount, digits);
|
|
97
|
-
const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amountStr}` : "");
|
|
91
|
+
var _a2;
|
|
92
|
+
const transAmount = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.transAmount;
|
|
93
|
+
const amountText = (transAmount == null ? void 0 : transAmount.amount) ? formatAmount(transAmount).jointSymbol() : "";
|
|
94
|
+
const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
|
|
98
95
|
return /* @__PURE__ */ u(
|
|
99
96
|
SubmitButton,
|
|
100
97
|
{
|
|
@@ -179,7 +176,7 @@ const Sepa = w((props, ref) => {
|
|
|
179
176
|
const res = search ? await getSepaPayInfo(
|
|
180
177
|
{ sessionId: session.sessionId, clientKey: session.clientKey },
|
|
181
178
|
options
|
|
182
|
-
) : await sepaPay(paymentParams, options);
|
|
179
|
+
) : await sepaPay(paymentParams, props.core, options);
|
|
183
180
|
return processAfterPayment(res, search);
|
|
184
181
|
} catch (error) {
|
|
185
182
|
if (isTimeoutError(error)) {
|
|
@@ -204,6 +201,7 @@ const Sepa = w((props, ref) => {
|
|
|
204
201
|
if (status === "PROCESSING") {
|
|
205
202
|
if (!orderStatus) {
|
|
206
203
|
setSubmitButtonStatus("unSubmit");
|
|
204
|
+
return { end: true };
|
|
207
205
|
} else if (orderStatus === "SUCCESS") {
|
|
208
206
|
setSubmitButtonStatus("success");
|
|
209
207
|
processOnSuccess();
|
|
@@ -233,7 +231,6 @@ const Sepa = w((props, ref) => {
|
|
|
233
231
|
return { end: true };
|
|
234
232
|
}
|
|
235
233
|
setSubmitButtonStatus("unSubmit");
|
|
236
|
-
processOnSuccess();
|
|
237
234
|
return { end: true };
|
|
238
235
|
};
|
|
239
236
|
const processOnSuccess = () => {
|
|
@@ -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 { getShopeePayInfo, shopeePay } from "../../api/modules/shopee-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("shopee-pay");
|
|
27
|
+
const fieldClassNames = bem("field");
|
|
28
|
+
const ShopeePay = 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.SHOPEE_PAY)) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
initFieldStatus();
|
|
110
|
+
setIsCheckoutEnabled(true);
|
|
111
|
+
form.email = bill.email ?? "";
|
|
112
|
+
if (autoQuery && core.processingPaymentMethod === PaymentMethod.SHOPEE_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.SHOPEE_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 getShopeePayInfo(
|
|
158
|
+
{ sessionId: session.sessionId, clientKey: session.clientKey },
|
|
159
|
+
requestOptions
|
|
160
|
+
) : await shopeePay(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.SHOPEE_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
|
+
ShopeePay
|
|
322
|
+
};
|
|
@@ -9,7 +9,7 @@ import { Button } from "../internal/Button/Button.js";
|
|
|
9
9
|
import { IconSafe } from "../internal/icons/IconSafe.js";
|
|
10
10
|
import { LoadingCheck } from "../internal/LoadingCheck/LoadingCheck.js";
|
|
11
11
|
const { bem } = useBEM("submit-button");
|
|
12
|
-
|
|
12
|
+
const SubmitButton = (props) => {
|
|
13
13
|
const {
|
|
14
14
|
text = enGB["common.pay"],
|
|
15
15
|
loadingText = enGB["common.payProcessing"],
|
|
@@ -36,37 +36,23 @@ function SubmitButton(props) {
|
|
|
36
36
|
);
|
|
37
37
|
};
|
|
38
38
|
y(() => {
|
|
39
|
-
if (status === "success")
|
|
39
|
+
if (status === "success")
|
|
40
40
|
return;
|
|
41
|
-
}
|
|
42
41
|
setContent(status === "loading" ? loadingText : text);
|
|
43
|
-
}, [status]);
|
|
42
|
+
}, [status, text]);
|
|
44
43
|
return /* @__PURE__ */ u(
|
|
45
44
|
Button,
|
|
46
45
|
{
|
|
47
46
|
icon: Icon(),
|
|
48
47
|
onClick,
|
|
49
|
-
className: normalizedClass(
|
|
50
|
-
bem({
|
|
51
|
-
success: status === "success"
|
|
52
|
-
}),
|
|
53
|
-
className
|
|
54
|
-
),
|
|
48
|
+
className: normalizedClass(bem({ success: status === "success" }), className),
|
|
55
49
|
style,
|
|
56
50
|
loading: status === "loading",
|
|
57
51
|
disabled: props.disabled || status === "success",
|
|
58
|
-
children: /* @__PURE__ */ u(
|
|
59
|
-
"span",
|
|
60
|
-
{
|
|
61
|
-
class: bem("text", {
|
|
62
|
-
"not-verified": !props.verified
|
|
63
|
-
}),
|
|
64
|
-
children: content
|
|
65
|
-
}
|
|
66
|
-
)
|
|
52
|
+
children: /* @__PURE__ */ u("span", { class: bem("text", { "not-verified": !props.verified }), children: content })
|
|
67
53
|
}
|
|
68
54
|
);
|
|
69
|
-
}
|
|
55
|
+
};
|
|
70
56
|
export {
|
|
71
57
|
SubmitButton
|
|
72
58
|
};
|