@paykka/card-checkout-ui 0.13.1 → 0.13.5
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 +21 -21
- package/dist/card-checkout-ui.umd.cjs +21 -21
- package/dist/es/_commonjsHelpers.js +82 -1
- package/dist/es/api/modules/get-browser-params.js +4 -1
- package/dist/es/api/modules/opay-wallet/index.js +16 -0
- package/dist/es/api/modules/paga-wallet/index.js +16 -0
- package/dist/es/api/modules/pic-pay/index.js +16 -0
- package/dist/es/api/modules/pix/index.js +16 -0
- package/dist/es/api/modules/vietqr/index.js +4 -0
- package/dist/es/components/AliPay/index.js +29 -35
- package/dist/es/components/Boost/index.js +34 -40
- package/dist/es/components/Card/index.js +35 -39
- package/dist/es/components/DropIn/index.js +42 -2
- package/dist/es/components/EncryptedCard/index.js +5 -1
- package/dist/es/components/GooglePay/index.js +1 -0
- package/dist/es/components/GrabPay/index.js +34 -40
- package/dist/es/components/GuideCard/index.js +6 -1
- package/dist/es/components/LinePay/index.js +34 -40
- package/dist/es/components/MayBankQRPay/index.js +35 -41
- package/dist/es/components/NinePay/index.js +34 -40
- package/dist/es/components/SecuredFieldsProvider/index.js +23 -7
- package/dist/es/components/SecuredIframe/index.js +36 -59
- package/dist/es/components/Sepa/index.js +17 -21
- package/dist/es/components/ShopeePay/index.js +34 -40
- package/dist/es/components/TNGWallet/index.js +34 -40
- package/dist/es/components/ThreeDS/index.js +32 -7
- package/dist/es/components/WechatPay/index.js +19 -24
- package/dist/es/components/business/QRCodeModal/QRCodeModal.js +6 -6
- package/dist/es/components/index.js +5 -0
- package/dist/es/components/internal/Form/FormItem.js +1 -1
- package/dist/es/components/internal/Form/util.js +1 -1
- package/dist/es/components/internal/Select/SelectMenu.js +2 -2
- package/dist/es/components/internal/icons/IconError.js +7 -4
- package/dist/es/components/internal/icons/IconOpayWallet.js +71 -0
- package/dist/es/components/internal/icons/IconPagaWallet.js +141 -0
- package/dist/es/components/internal/icons/IconPaymaya.js +42 -86
- package/dist/es/components/internal/icons/IconPicPay.js +49 -0
- package/dist/es/components/internal/icons/IconPix.js +75 -0
- package/dist/es/components/internal/icons/IconVietqr.js +45 -0
- package/dist/es/components/internal/icons/IconVietqrComplete.js +49 -0
- package/dist/es/components/wallets/GCash/GCash.js +20 -25
- package/dist/es/components/wallets/OpayWallet/OpayWallet.js +346 -0
- package/dist/es/components/wallets/OpayWallet/index.js +1 -0
- package/dist/es/components/wallets/OpayWallet/opay-wallet.js +1 -0
- package/dist/es/components/wallets/OpayWallet/type.js +1 -0
- package/dist/es/components/wallets/PagaWallet/PagaWallet.js +346 -0
- package/dist/es/components/wallets/PagaWallet/index.js +1 -0
- package/dist/es/components/wallets/PagaWallet/paga-wallet.js +1 -0
- package/dist/es/components/wallets/PagaWallet/type.js +1 -0
- package/dist/es/components/wallets/Paymaya/Paymaya.js +34 -40
- package/dist/es/components/wallets/PicPay/PicPay.js +346 -0
- package/dist/es/components/wallets/PicPay/index.js +1 -0
- package/dist/es/components/wallets/PicPay/pic-pay.js +1 -0
- package/dist/es/components/wallets/PicPay/type.js +1 -0
- package/dist/es/components/wallets/Pix/Pix.js +346 -0
- package/dist/es/components/wallets/Pix/index.js +1 -0
- package/dist/es/components/wallets/Pix/pix2.js +1 -0
- package/dist/es/components/wallets/Pix/type.js +1 -0
- package/dist/es/components/wallets/Vietqr/Vietqr.js +380 -0
- package/dist/es/components/wallets/Vietqr/index.js +1 -0
- package/dist/es/components/wallets/Vietqr/type.js +1 -0
- package/dist/es/components/wallets/Vietqr/vietqr2.js +1 -0
- package/dist/es/components/wallets/Zalopay/Zalopay.js +17 -21
- package/dist/es/components/wallets/index.js +8 -0
- package/dist/es/constant.js +32 -2
- package/dist/es/core/checkout.js +24 -1
- package/dist/es/core/create.js +1 -1
- package/dist/es/core/session.js +2 -23
- package/dist/es/core/theme.js +65 -0
- package/dist/es/core.js +34 -34
- package/dist/es/i18n/locales/de-DE.js +8 -2
- package/dist/es/i18n/locales/en-GB.js +8 -2
- package/dist/es/i18n/locales/es-ES.js +8 -2
- package/dist/es/i18n/locales/fr-FR.js +8 -2
- package/dist/es/i18n/locales/ja-JP.js +8 -2
- package/dist/es/i18n/locales/ko-KR.js +8 -2
- package/dist/es/i18n/locales/nl-NL.js +8 -2
- package/dist/es/i18n/locales/pt-PT.js +8 -2
- package/dist/es/i18n/locales/ru-RU.js +8 -2
- package/dist/es/i18n/locales/zh-CN.js +10 -4
- package/dist/es/i18n/locales/zh-HK.js +10 -4
- package/dist/es/i18n/locales/zh-TW.js +10 -4
- package/dist/es/index.js +17 -5
- package/dist/es/style.css +1 -1
- package/dist/es/utils/format.js +0 -5
- package/dist/es/utils/object.js +31 -1
- package/dist/es/utils/string.js +10 -0
- package/dist/es/utils/system-info/is-ua-webview.js +14 -12
- package/dist/es/utils/theme.js +7 -0
- package/dist/style.css +1 -1
- package/dist/types/api/modules/get-browser-params.d.ts +1 -0
- package/dist/types/api/modules/index.d.ts +5 -0
- package/dist/types/api/modules/opay-wallet/index.d.ts +4 -0
- package/dist/types/api/modules/paga-wallet/index.d.ts +4 -0
- package/dist/types/api/modules/pic-pay/index.d.ts +4 -0
- package/dist/types/api/modules/pix/index.d.ts +4 -0
- package/dist/types/api/modules/vietqr/index.d.ts +4 -0
- package/dist/types/components/DropIn/type.d.ts +3 -2
- package/dist/types/components/SecuredFieldsProvider/type.d.ts +5 -0
- package/dist/types/components/SecuredIframe/HiddenIframe.d.ts +3 -1
- package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +2 -0
- package/dist/types/components/business/QRCodeModal/type.d.ts +2 -0
- package/dist/types/components/index.d.ts +1 -3
- package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
- package/dist/types/components/internal/Select/SelectMenu.d.ts +1 -1
- package/dist/types/components/internal/icons/IconOpayWallet.d.ts +2 -0
- package/dist/types/components/internal/icons/IconPagaWallet.d.ts +2 -0
- package/dist/types/components/internal/icons/IconPicPay.d.ts +2 -0
- package/dist/types/components/internal/icons/IconPix.d.ts +2 -0
- package/dist/types/components/internal/icons/IconVietqr.d.ts +2 -0
- package/dist/types/components/internal/icons/IconVietqrComplete.d.ts +2 -0
- package/dist/types/components/internal/icons/index.d.ts +6 -0
- package/dist/types/components/wallets/OpayWallet/OpayWallet.d.ts +10 -0
- package/dist/types/components/wallets/OpayWallet/index.d.ts +2 -0
- package/dist/types/components/wallets/OpayWallet/type.d.ts +40 -0
- package/dist/types/components/wallets/PagaWallet/PagaWallet.d.ts +10 -0
- package/dist/types/components/wallets/PagaWallet/index.d.ts +2 -0
- package/dist/types/components/wallets/PagaWallet/type.d.ts +40 -0
- package/dist/types/components/wallets/PicPay/PicPay.d.ts +10 -0
- package/dist/types/components/wallets/PicPay/index.d.ts +2 -0
- package/dist/types/components/wallets/PicPay/type.d.ts +40 -0
- package/dist/types/components/wallets/Pix/Pix.d.ts +10 -0
- package/dist/types/components/wallets/Pix/index.d.ts +2 -0
- package/dist/types/components/wallets/Pix/type.d.ts +40 -0
- package/dist/types/components/wallets/Vietqr/Vietqr.d.ts +10 -0
- package/dist/types/components/wallets/Vietqr/index.d.ts +2 -0
- package/dist/types/components/wallets/Vietqr/type.d.ts +39 -0
- package/dist/types/components/wallets/index.d.ts +8 -0
- package/dist/types/components/wallets/type.d.ts +9 -0
- package/dist/types/constant.d.ts +11 -1
- package/dist/types/core/checkout.d.ts +4 -0
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/session.d.ts +1 -11
- package/dist/types/core/theme.d.ts +7 -0
- package/dist/types/i18n/locales/de-DE.d.ts +6 -0
- package/dist/types/i18n/locales/en-GB.d.ts +6 -0
- package/dist/types/i18n/locales/es-ES.d.ts +6 -0
- package/dist/types/i18n/locales/fr-FR.d.ts +6 -0
- package/dist/types/i18n/locales/ja-JP.d.ts +6 -0
- package/dist/types/i18n/locales/ko-KR.d.ts +6 -0
- package/dist/types/i18n/locales/nl-NL.d.ts +6 -0
- package/dist/types/i18n/locales/pt-PT.d.ts +6 -0
- package/dist/types/i18n/locales/ru-RU.d.ts +6 -0
- package/dist/types/i18n/locales/zh-CN.d.ts +6 -0
- package/dist/types/i18n/locales/zh-HK.d.ts +6 -0
- package/dist/types/i18n/locales/zh-TW.d.ts +6 -0
- package/dist/types/types/message.d.ts +29 -25
- package/dist/types/utils/index.d.ts +3 -2
- package/dist/types/utils/object.d.ts +7 -0
- package/dist/types/utils/string.d.ts +1 -0
- package/dist/types/utils/style.d.ts +1 -1
- package/dist/types/utils/system-info/is-ua-webview.d.ts +1 -1
- package/dist/types/utils/theme.d.ts +4 -0
- package/package.json +67 -67
- package/dist/es/utils/deep-freeze.js +0 -13
- package/dist/es/utils/obj.js +0 -22
- package/dist/types/utils/deep-freeze.d.ts +0 -1
- package/dist/types/utils/obj.d.ts +0 -6
|
@@ -0,0 +1,346 @@
|
|
|
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 { normalizedClass, formatAmount } from "../../../utils/format.js";
|
|
7
|
+
import { redirectToPayment } from "../../../utils/redirect.js";
|
|
8
|
+
import { formatPaymentResult } from "../../../utils/payment.js";
|
|
9
|
+
import { isTimeoutError } from "../../../api/http.js";
|
|
10
|
+
import { getBrowserParams } from "../../../api/modules/get-browser-params.js";
|
|
11
|
+
import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../../constant.js";
|
|
12
|
+
import { getPagaWalletPayInfo, pagaWalletPay } from "../../../api/modules/paga-wallet/index.js";
|
|
13
|
+
import { PayKKaError } from "../../../core/error.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 { SubmitButton } from "../../SubmitButton/index.js";
|
|
18
|
+
import { GuideCard } from "../../GuideCard/index.js";
|
|
19
|
+
import { AddressField } from "../../AddressField/index.js";
|
|
20
|
+
import { Info } from "../../internal/Info/Info.js";
|
|
21
|
+
import "../../internal/Form/type.js";
|
|
22
|
+
import "../../internal/Form/context.js";
|
|
23
|
+
import "../../internal/Form/FormItem.js";
|
|
24
|
+
import { Form } from "../../internal/Form/Form.js";
|
|
25
|
+
import "./paga-wallet.js";
|
|
26
|
+
const { bem } = useBEM("paga-wallet");
|
|
27
|
+
const fieldClassNames = bem("field");
|
|
28
|
+
const PagaWallet = w((props, ref) => {
|
|
29
|
+
const {
|
|
30
|
+
session,
|
|
31
|
+
showEmail = false,
|
|
32
|
+
showAddress = false,
|
|
33
|
+
core,
|
|
34
|
+
redirectMode = "auto",
|
|
35
|
+
autoQuery = true,
|
|
36
|
+
showGuideCard = true,
|
|
37
|
+
hidePaymentButton = false
|
|
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 _a;
|
|
50
|
+
if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
|
|
51
|
+
return;
|
|
52
|
+
const newForm = Object.assign(form, { address: addressCore.getAddressState() });
|
|
53
|
+
setForm(newForm);
|
|
54
|
+
(_a = addressFieldRef.current) == null ? void 0 : _a.update(addressCore.getAddressState());
|
|
55
|
+
validateForm();
|
|
56
|
+
},
|
|
57
|
+
updateEmail: () => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
|
|
60
|
+
return;
|
|
61
|
+
const newForm = Object.assign(form, { email: emailState.email });
|
|
62
|
+
setForm(newForm);
|
|
63
|
+
(_a = emailFieldRef.current) == null ? void 0 : _a.update(emailState.email);
|
|
64
|
+
validateForm();
|
|
65
|
+
},
|
|
66
|
+
payment: () => {
|
|
67
|
+
hidePaymentButton && onSubmit();
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
const addressCore = core.getAddressCore();
|
|
71
|
+
const emailState = createEmailCore();
|
|
72
|
+
const addressFieldRef = A(null);
|
|
73
|
+
const emailFieldRef = A(null);
|
|
74
|
+
const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
|
|
75
|
+
const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session, props.core);
|
|
76
|
+
const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
|
|
77
|
+
const formRef = A(null);
|
|
78
|
+
const [form, setForm] = h({
|
|
79
|
+
email: "",
|
|
80
|
+
address: {
|
|
81
|
+
country: void 0,
|
|
82
|
+
province: void 0,
|
|
83
|
+
city: void 0,
|
|
84
|
+
area: void 0,
|
|
85
|
+
postCode: void 0,
|
|
86
|
+
address1: void 0,
|
|
87
|
+
address2: void 0
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const [validated, setValidated] = h(false);
|
|
91
|
+
const [fieldStatus, setFieldStatus] = h();
|
|
92
|
+
const initFieldStatus = () => {
|
|
93
|
+
const { field, sessionMode } = session.checkout;
|
|
94
|
+
const { email, address } = field;
|
|
95
|
+
if (sessionMode === SessionMode.COMPONENT) {
|
|
96
|
+
if (email.disabled) {
|
|
97
|
+
email.show = showEmail;
|
|
98
|
+
}
|
|
99
|
+
if (showAddress && !(address == null ? void 0 : address.show)) {
|
|
100
|
+
address.show = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
setFieldStatus({ ...field });
|
|
104
|
+
};
|
|
105
|
+
const processOnSuccess = (res) => {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
setSubmitButtonStatus("success");
|
|
108
|
+
(_b = props.onSuccess) == null ? void 0 : _b.call(props, formatPaymentResult({
|
|
109
|
+
...res,
|
|
110
|
+
returnUrl: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.returnUrl
|
|
111
|
+
}));
|
|
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.PAGA_WALLET)) {
|
|
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.PAGA_WALLET) {
|
|
127
|
+
setSubmitButtonStatus("loading");
|
|
128
|
+
startReFetchPayInfo();
|
|
129
|
+
}
|
|
130
|
+
}, [sessionReady]);
|
|
131
|
+
const processOnError = (error) => {
|
|
132
|
+
var _a;
|
|
133
|
+
(_a = props.onError) == null ? void 0 : _a.call(props, error);
|
|
134
|
+
core.resetEnablePaymentMethod();
|
|
135
|
+
};
|
|
136
|
+
const onTimeout = q(
|
|
137
|
+
(message) => {
|
|
138
|
+
var _a;
|
|
139
|
+
setErrorMsg(message || i18n.get("common.payTimeout"));
|
|
140
|
+
setSubmitButtonStatus("unSubmit");
|
|
141
|
+
(_a = props.onTimeout) == null ? void 0 : _a.call(props);
|
|
142
|
+
core.resetEnablePaymentMethod();
|
|
143
|
+
},
|
|
144
|
+
[i18n, props.onTimeout]
|
|
145
|
+
);
|
|
146
|
+
const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
|
|
147
|
+
(timeout) => pay(true, timeout),
|
|
148
|
+
{ onTimeout: () => onTimeout(i18n.get("common.queryTimeout")) }
|
|
149
|
+
);
|
|
150
|
+
const getPaymentParams = async () => {
|
|
151
|
+
return {
|
|
152
|
+
sessionId: session.sessionId,
|
|
153
|
+
clientKey: session.clientKey,
|
|
154
|
+
payment: {
|
|
155
|
+
paymentMethod: PaymentMethod.PAGA_WALLET
|
|
156
|
+
},
|
|
157
|
+
bill: {
|
|
158
|
+
email: form.email,
|
|
159
|
+
addressLine1: form.address.address1,
|
|
160
|
+
addressLine2: form.address.address2,
|
|
161
|
+
postalCode: form.address.postCode,
|
|
162
|
+
country: form.address.country,
|
|
163
|
+
district: form.address.area,
|
|
164
|
+
state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
|
|
165
|
+
city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
|
|
166
|
+
},
|
|
167
|
+
browser: await getBrowserParams()
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const pay = async (search = false, timeout) => {
|
|
171
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
172
|
+
try {
|
|
173
|
+
const requestOptions = { locale: i18n.locale, timeout };
|
|
174
|
+
let res = null;
|
|
175
|
+
if (search) {
|
|
176
|
+
const extraParams = (_b = (_a = core.config)._getExtraParams) == null ? void 0 : _b.call(_a, "query", PaymentMethod.PAGA_WALLET);
|
|
177
|
+
res = await getPagaWalletPayInfo(
|
|
178
|
+
{
|
|
179
|
+
sessionId: session.sessionId,
|
|
180
|
+
clientKey: session.clientKey,
|
|
181
|
+
paymentMethod: PaymentMethod.PAGA_WALLET
|
|
182
|
+
},
|
|
183
|
+
extraParams,
|
|
184
|
+
requestOptions
|
|
185
|
+
);
|
|
186
|
+
} else {
|
|
187
|
+
const extraParams = (_d = (_c = core.config)._getExtraParams) == null ? void 0 : _d.call(_c, "payment", PaymentMethod.PAGA_WALLET);
|
|
188
|
+
res = await pagaWalletPay(await getPaymentParams(), extraParams, requestOptions);
|
|
189
|
+
}
|
|
190
|
+
!search && ((_e = props.onSubmitResponse) == null ? void 0 : _e.call(props, res));
|
|
191
|
+
const { status, orderStatus, errorMessage, errorCode, payInfo, sessionId } = res;
|
|
192
|
+
sessionId && (session.sessionId = sessionId);
|
|
193
|
+
if (status === "PROCESSING") {
|
|
194
|
+
if (!orderStatus) {
|
|
195
|
+
setSubmitButtonStatus("unSubmit");
|
|
196
|
+
return { end: true };
|
|
197
|
+
} else if (orderStatus === "SUCCESS") {
|
|
198
|
+
processOnSuccess(res);
|
|
199
|
+
return { end: true };
|
|
200
|
+
} else if (orderStatus === "FAILURE") {
|
|
201
|
+
errorMessage && setErrorMsg(errorMessage);
|
|
202
|
+
setSubmitButtonStatus("unSubmit");
|
|
203
|
+
processOnError(new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
|
|
204
|
+
return { end: true };
|
|
205
|
+
} else if (orderStatus === "PROCESSING") {
|
|
206
|
+
if (!search) {
|
|
207
|
+
if (redirectMode === "auto" && payInfo) {
|
|
208
|
+
redirectToPayment(payInfo);
|
|
209
|
+
return { end: true };
|
|
210
|
+
} else {
|
|
211
|
+
startReFetchPayInfo();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { end: false };
|
|
215
|
+
} else if (orderStatus === "CANCELED") {
|
|
216
|
+
setSubmitButtonStatus("unSubmit");
|
|
217
|
+
(_f = props.onTimeout) == null ? void 0 : _f.call(props);
|
|
218
|
+
core.resetEnablePaymentMethod();
|
|
219
|
+
return { end: true };
|
|
220
|
+
}
|
|
221
|
+
} else if (status === "SUCCESS") {
|
|
222
|
+
processOnSuccess(res);
|
|
223
|
+
return { end: true };
|
|
224
|
+
} else if (status === "EXPIRED") {
|
|
225
|
+
setSubmitButtonStatus("unSubmit");
|
|
226
|
+
(_g = props.onExpired) == null ? void 0 : _g.call(props);
|
|
227
|
+
return { end: true };
|
|
228
|
+
}
|
|
229
|
+
setSubmitButtonStatus("unSubmit");
|
|
230
|
+
return { end: true };
|
|
231
|
+
} catch (error) {
|
|
232
|
+
if (isTimeoutError(error)) {
|
|
233
|
+
if (search) {
|
|
234
|
+
return { end: false };
|
|
235
|
+
} else {
|
|
236
|
+
onTimeout();
|
|
237
|
+
return { end: true };
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
|
|
241
|
+
message && setErrorMsg(message);
|
|
242
|
+
processOnError(new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
|
|
243
|
+
setSubmitButtonStatus("unSubmit");
|
|
244
|
+
return { end: true };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const validateForm = () => {
|
|
249
|
+
var _a;
|
|
250
|
+
(_a = formRef.current) == null ? void 0 : _a.validate(void 0, false).then(() => {
|
|
251
|
+
setValidated(true);
|
|
252
|
+
}).catch(() => {
|
|
253
|
+
setValidated(false);
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
y(() => {
|
|
257
|
+
validateForm();
|
|
258
|
+
}, [form]);
|
|
259
|
+
const onSubmit = async () => {
|
|
260
|
+
var _a;
|
|
261
|
+
setErrorMsg("");
|
|
262
|
+
(_a = formRef.current) == null ? void 0 : _a.validate(async (errors) => {
|
|
263
|
+
var _a2;
|
|
264
|
+
(fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
|
|
265
|
+
(_a2 = props.onSubmit) == null ? void 0 : _a2.call(props, errors);
|
|
266
|
+
if (errors) {
|
|
267
|
+
setSubmitButtonStatus("unSubmit");
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
setErrorMsg("");
|
|
271
|
+
setSubmitButtonStatus("loading");
|
|
272
|
+
await pay();
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
const setFormRef = (dom) => {
|
|
276
|
+
formRef.current = dom;
|
|
277
|
+
dom && validateForm();
|
|
278
|
+
};
|
|
279
|
+
const Button = () => {
|
|
280
|
+
var _a;
|
|
281
|
+
const transAmount = (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.transAmount;
|
|
282
|
+
const amountText = (transAmount == null ? void 0 : transAmount.amount) ? formatAmount(transAmount).jointSymbol() : "";
|
|
283
|
+
const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
|
|
284
|
+
return /* @__PURE__ */ u(
|
|
285
|
+
SubmitButton,
|
|
286
|
+
{
|
|
287
|
+
className: bem("button"),
|
|
288
|
+
status: submitButtonStatus,
|
|
289
|
+
text,
|
|
290
|
+
loadingText: i18n.get("common.payProcessing"),
|
|
291
|
+
successText: i18n.get("common.paySuccess"),
|
|
292
|
+
onClick: onSubmit,
|
|
293
|
+
verified: validated
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
};
|
|
297
|
+
const Email = () => {
|
|
298
|
+
return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.email.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
|
|
299
|
+
EmailField,
|
|
300
|
+
{
|
|
301
|
+
ref: emailFieldRef,
|
|
302
|
+
value: form.email,
|
|
303
|
+
disabled: fieldStatus == null ? void 0 : fieldStatus.email.disabled
|
|
304
|
+
}
|
|
305
|
+
) }) });
|
|
306
|
+
};
|
|
307
|
+
const ErrorMessage = () => {
|
|
308
|
+
return /* @__PURE__ */ u(b, { children: !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg }) });
|
|
309
|
+
};
|
|
310
|
+
const Address = () => {
|
|
311
|
+
var _a, _b;
|
|
312
|
+
return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
|
|
313
|
+
AddressField,
|
|
314
|
+
{
|
|
315
|
+
ref: addressFieldRef,
|
|
316
|
+
value: form.address,
|
|
317
|
+
country: ((_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.country) || ((_b = session == null ? void 0 : session.checkout) == null ? void 0 : _b.bill.country),
|
|
318
|
+
onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
|
|
319
|
+
}
|
|
320
|
+
) }) });
|
|
321
|
+
};
|
|
322
|
+
return /* @__PURE__ */ u(
|
|
323
|
+
CoreContext.Provider,
|
|
324
|
+
{
|
|
325
|
+
value: {
|
|
326
|
+
i18n,
|
|
327
|
+
session,
|
|
328
|
+
core
|
|
329
|
+
},
|
|
330
|
+
children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u("div", { className: core.theme.className, children: [
|
|
331
|
+
showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.PAGA_WALLET }),
|
|
332
|
+
/* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), children: [
|
|
333
|
+
Email(),
|
|
334
|
+
Address(),
|
|
335
|
+
/* @__PURE__ */ u("div", { className: bem("footer-wrapper"), children: [
|
|
336
|
+
ErrorMessage(),
|
|
337
|
+
!hidePaymentButton && Button()
|
|
338
|
+
] })
|
|
339
|
+
] }) })
|
|
340
|
+
] })
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
});
|
|
344
|
+
export {
|
|
345
|
+
PagaWallet
|
|
346
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./PagaWallet.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -3,7 +3,7 @@ import { useBEM } from "../../../hooks/useBEM.js";
|
|
|
3
3
|
import { CoreContext } from "../../../core/context.js";
|
|
4
4
|
import "../../../utils/card-brand/brands.js";
|
|
5
5
|
import "../../../utils/system-info/get-browser-info.js";
|
|
6
|
-
import {
|
|
6
|
+
import { normalizedClass, formatAmount } from "../../../utils/format.js";
|
|
7
7
|
import { redirectToPayment } from "../../../utils/redirect.js";
|
|
8
8
|
import { formatPaymentResult } from "../../../utils/payment.js";
|
|
9
9
|
import { isTimeoutError } from "../../../api/http.js";
|
|
@@ -26,7 +26,6 @@ import "./paymaya2.js";
|
|
|
26
26
|
const { bem } = useBEM("paymaya");
|
|
27
27
|
const fieldClassNames = bem("field");
|
|
28
28
|
const Paymaya = w((props, ref) => {
|
|
29
|
-
var _a, _b, _c, _d, _e, _f;
|
|
30
29
|
const {
|
|
31
30
|
session,
|
|
32
31
|
showEmail = false,
|
|
@@ -47,21 +46,21 @@ const Paymaya = w((props, ref) => {
|
|
|
47
46
|
startReFetchPayInfo({ timeout });
|
|
48
47
|
},
|
|
49
48
|
updateAddress: () => {
|
|
50
|
-
var
|
|
49
|
+
var _a;
|
|
51
50
|
if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
|
|
52
51
|
return;
|
|
53
52
|
const newForm = Object.assign(form, { address: addressCore.getAddressState() });
|
|
54
53
|
setForm(newForm);
|
|
55
|
-
(
|
|
54
|
+
(_a = addressFieldRef.current) == null ? void 0 : _a.update(addressCore.getAddressState());
|
|
56
55
|
validateForm();
|
|
57
56
|
},
|
|
58
57
|
updateEmail: () => {
|
|
59
|
-
var
|
|
58
|
+
var _a;
|
|
60
59
|
if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
|
|
61
60
|
return;
|
|
62
61
|
const newForm = Object.assign(form, { email: emailState.email });
|
|
63
62
|
setForm(newForm);
|
|
64
|
-
(
|
|
63
|
+
(_a = emailFieldRef.current) == null ? void 0 : _a.update(emailState.email);
|
|
65
64
|
validateForm();
|
|
66
65
|
},
|
|
67
66
|
payment: () => {
|
|
@@ -104,11 +103,11 @@ const Paymaya = w((props, ref) => {
|
|
|
104
103
|
setFieldStatus({ ...field });
|
|
105
104
|
};
|
|
106
105
|
const processOnSuccess = (res) => {
|
|
107
|
-
var
|
|
106
|
+
var _a, _b;
|
|
108
107
|
setSubmitButtonStatus("success");
|
|
109
|
-
(
|
|
108
|
+
(_b = props.onSuccess) == null ? void 0 : _b.call(props, formatPaymentResult({
|
|
110
109
|
...res,
|
|
111
|
-
returnUrl: (
|
|
110
|
+
returnUrl: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.returnUrl
|
|
112
111
|
}));
|
|
113
112
|
};
|
|
114
113
|
y(() => {
|
|
@@ -130,16 +129,16 @@ const Paymaya = w((props, ref) => {
|
|
|
130
129
|
}
|
|
131
130
|
}, [sessionReady]);
|
|
132
131
|
const processOnError = (error) => {
|
|
133
|
-
var
|
|
134
|
-
(
|
|
132
|
+
var _a;
|
|
133
|
+
(_a = props.onError) == null ? void 0 : _a.call(props, error);
|
|
135
134
|
core.resetEnablePaymentMethod();
|
|
136
135
|
};
|
|
137
136
|
const onTimeout = q(
|
|
138
137
|
(message) => {
|
|
139
|
-
var
|
|
138
|
+
var _a;
|
|
140
139
|
setErrorMsg(message || i18n.get("common.payTimeout"));
|
|
141
140
|
setSubmitButtonStatus("unSubmit");
|
|
142
|
-
(
|
|
141
|
+
(_a = props.onTimeout) == null ? void 0 : _a.call(props);
|
|
143
142
|
core.resetEnablePaymentMethod();
|
|
144
143
|
},
|
|
145
144
|
[i18n, props.onTimeout]
|
|
@@ -169,12 +168,12 @@ const Paymaya = w((props, ref) => {
|
|
|
169
168
|
};
|
|
170
169
|
};
|
|
171
170
|
const pay = async (search = false, timeout) => {
|
|
172
|
-
var
|
|
171
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
173
172
|
try {
|
|
174
173
|
const requestOptions = { locale: i18n.locale, timeout };
|
|
175
174
|
let res = null;
|
|
176
175
|
if (search) {
|
|
177
|
-
const extraParams = (
|
|
176
|
+
const extraParams = (_b = (_a = core.config)._getExtraParams) == null ? void 0 : _b.call(_a, "query", PaymentMethod.PAYMAYA);
|
|
178
177
|
res = await getPaymayaPayInfo(
|
|
179
178
|
{
|
|
180
179
|
sessionId: session.sessionId,
|
|
@@ -185,10 +184,10 @@ const Paymaya = w((props, ref) => {
|
|
|
185
184
|
requestOptions
|
|
186
185
|
);
|
|
187
186
|
} else {
|
|
188
|
-
const extraParams = (
|
|
187
|
+
const extraParams = (_d = (_c = core.config)._getExtraParams) == null ? void 0 : _d.call(_c, "payment", PaymentMethod.PAYMAYA);
|
|
189
188
|
res = await paymayaPay(await getPaymentParams(), extraParams, requestOptions);
|
|
190
189
|
}
|
|
191
|
-
!search && ((
|
|
190
|
+
!search && ((_e = props.onSubmitResponse) == null ? void 0 : _e.call(props, res));
|
|
192
191
|
const { status, orderStatus, errorMessage, errorCode, payInfo, sessionId } = res;
|
|
193
192
|
sessionId && (session.sessionId = sessionId);
|
|
194
193
|
if (status === "PROCESSING") {
|
|
@@ -215,7 +214,7 @@ const Paymaya = w((props, ref) => {
|
|
|
215
214
|
return { end: false };
|
|
216
215
|
} else if (orderStatus === "CANCELED") {
|
|
217
216
|
setSubmitButtonStatus("unSubmit");
|
|
218
|
-
(
|
|
217
|
+
(_f = props.onTimeout) == null ? void 0 : _f.call(props);
|
|
219
218
|
core.resetEnablePaymentMethod();
|
|
220
219
|
return { end: true };
|
|
221
220
|
}
|
|
@@ -247,8 +246,8 @@ const Paymaya = w((props, ref) => {
|
|
|
247
246
|
}
|
|
248
247
|
};
|
|
249
248
|
const validateForm = () => {
|
|
250
|
-
var
|
|
251
|
-
(
|
|
249
|
+
var _a;
|
|
250
|
+
(_a = formRef.current) == null ? void 0 : _a.validate(void 0, false).then(() => {
|
|
252
251
|
setValidated(true);
|
|
253
252
|
}).catch(() => {
|
|
254
253
|
setValidated(false);
|
|
@@ -258,12 +257,12 @@ const Paymaya = w((props, ref) => {
|
|
|
258
257
|
validateForm();
|
|
259
258
|
}, [form]);
|
|
260
259
|
const onSubmit = async () => {
|
|
261
|
-
var
|
|
260
|
+
var _a;
|
|
262
261
|
setErrorMsg("");
|
|
263
|
-
(
|
|
264
|
-
var
|
|
262
|
+
(_a = formRef.current) == null ? void 0 : _a.validate(async (errors) => {
|
|
263
|
+
var _a2;
|
|
265
264
|
(fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
|
|
266
|
-
(
|
|
265
|
+
(_a2 = props.onSubmit) == null ? void 0 : _a2.call(props, errors);
|
|
267
266
|
if (errors) {
|
|
268
267
|
setSubmitButtonStatus("unSubmit");
|
|
269
268
|
return;
|
|
@@ -278,8 +277,8 @@ const Paymaya = w((props, ref) => {
|
|
|
278
277
|
dom && validateForm();
|
|
279
278
|
};
|
|
280
279
|
const Button = () => {
|
|
281
|
-
var
|
|
282
|
-
const transAmount = (
|
|
280
|
+
var _a;
|
|
281
|
+
const transAmount = (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.transAmount;
|
|
283
282
|
const amountText = (transAmount == null ? void 0 : transAmount.amount) ? formatAmount(transAmount).jointSymbol() : "";
|
|
284
283
|
const text = i18n.get("common.pay") + (amountText ? ` ${amountText}` : "");
|
|
285
284
|
return /* @__PURE__ */ u(
|
|
@@ -305,24 +304,17 @@ const Paymaya = w((props, ref) => {
|
|
|
305
304
|
}
|
|
306
305
|
) }) });
|
|
307
306
|
};
|
|
308
|
-
const formStyle = {
|
|
309
|
-
[cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
|
|
310
|
-
[cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
|
|
311
|
-
[cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
|
|
312
|
-
[cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
|
|
313
|
-
[cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
|
|
314
|
-
};
|
|
315
307
|
const ErrorMessage = () => {
|
|
316
|
-
return /* @__PURE__ */ u(b, { children: !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg
|
|
308
|
+
return /* @__PURE__ */ u(b, { children: !!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg }) });
|
|
317
309
|
};
|
|
318
310
|
const Address = () => {
|
|
319
|
-
var
|
|
311
|
+
var _a, _b;
|
|
320
312
|
return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
|
|
321
313
|
AddressField,
|
|
322
314
|
{
|
|
323
315
|
ref: addressFieldRef,
|
|
324
316
|
value: form.address,
|
|
325
|
-
country: ((
|
|
317
|
+
country: ((_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.country) || ((_b = session == null ? void 0 : session.checkout) == null ? void 0 : _b.bill.country),
|
|
326
318
|
onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
|
|
327
319
|
}
|
|
328
320
|
) }) });
|
|
@@ -335,13 +327,15 @@ const Paymaya = w((props, ref) => {
|
|
|
335
327
|
session,
|
|
336
328
|
core
|
|
337
329
|
},
|
|
338
|
-
children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(
|
|
330
|
+
children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u("div", { className: core.theme.className, children: [
|
|
339
331
|
showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.PAYMAYA }),
|
|
340
|
-
/* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()),
|
|
332
|
+
/* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), children: [
|
|
341
333
|
Email(),
|
|
342
334
|
Address(),
|
|
343
|
-
|
|
344
|
-
|
|
335
|
+
/* @__PURE__ */ u("div", { className: bem("footer-wrapper"), children: [
|
|
336
|
+
ErrorMessage(),
|
|
337
|
+
!hidePaymentButton && Button()
|
|
338
|
+
] })
|
|
345
339
|
] }) })
|
|
346
340
|
] })
|
|
347
341
|
}
|