@paykka/card-checkout-ui 0.5.17 → 0.6.0
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 +22 -0
- package/dist/card-checkout-ui.umd.cjs +19 -5
- package/dist/es/api/modules/checkout/map.js +2 -1
- package/dist/es/api/modules/encrypted-card/index.js +54 -0
- package/dist/es/api/modules/get-browser-params.js +2 -2
- package/dist/es/components/AccountNameField/index.js +2 -0
- package/dist/es/components/AddressField/index.js +2 -0
- package/dist/es/components/AliPay/index.js +8 -8
- package/dist/es/components/ApplePay/index.js +71 -14
- package/dist/es/components/Card/index.js +56 -40
- package/dist/es/components/CardExpireDateField/index.js +6 -3
- package/dist/es/components/CardHolderNameField/index.js +2 -0
- package/dist/es/components/CardIBANField/index.js +2 -0
- package/dist/es/components/CardNumberField/index.js +32 -17
- package/dist/es/components/CardSecurityCodeField/index.js +6 -3
- package/dist/es/components/CardSelector/index.js +1 -0
- package/dist/es/components/CombinedEncryptedField/index.js +75 -0
- package/dist/es/components/EmailField/EmailField.js +2 -0
- package/dist/es/components/EncryptedCard/index.js +448 -0
- package/dist/es/components/GooglePay/index.js +57 -19
- package/dist/es/components/SecuredFieldsProvider/SecuredFieldsProvider.js +70 -24
- package/dist/es/components/SecuredIframe/index.js +190 -22
- package/dist/es/components/Sepa/index.js +16 -6
- package/dist/es/components/WechatPay/index.js +8 -8
- package/dist/es/components/index.js +4 -0
- package/dist/es/components/internal/Form/FormItem.js +28 -24
- package/dist/es/components/internal/Form/index.js +1 -0
- package/dist/es/components/internal/Form/type.js +15 -1
- package/dist/es/components/internal/Input/Input.js +9 -11
- package/dist/es/components/internal/Input/index.js +1 -0
- package/dist/es/components/internal/Input/type.js +13 -1
- package/dist/es/components/internal/Select/Select.js +2 -0
- package/dist/es/config.js +12 -6
- package/dist/es/constant.js +10 -0
- package/dist/es/core/PayKKaCheckout.js +62 -0
- package/dist/es/core/query.js +1 -6
- package/dist/es/core.js +34 -34
- package/dist/es/hooks/useI18n.js +1 -1
- package/dist/es/hooks/usePayState.js +11 -18
- package/dist/es/index.js +13 -2
- package/dist/es/out/fraud-detection.js +99 -0
- package/dist/es/style.css +8 -0
- package/dist/es/types/{radar.js → fraud-detection.js} +1 -1
- package/dist/es/types/index.js +49 -1
- package/dist/es/utils/card-brand/brands.js +16 -42
- package/dist/es/utils/index.js +11 -0
- package/dist/es/utils/load.js +14 -0
- package/dist/es/utils/style.js +37 -0
- package/dist/style.css +1 -1
- package/dist/types/api/modules/checkout/map.d.ts +1 -0
- package/dist/types/api/modules/encrypted-card/index.d.ts +6 -0
- package/dist/types/api/modules/encrypted-card/type.d.ts +31 -0
- package/dist/types/api/modules/get-browser-params.d.ts +2 -2
- package/dist/types/components/AliPay/type.d.ts +0 -2
- package/dist/types/components/ApplePay/type.d.ts +16 -5
- package/dist/types/components/ApplePay/utils.d.ts +3 -0
- package/dist/types/components/Card/type.d.ts +15 -3
- package/dist/types/components/CardExpireDateField/type.d.ts +1 -0
- package/dist/types/components/CardNumberField/type.d.ts +3 -0
- package/dist/types/components/CardSecurityCodeField/type.d.ts +1 -0
- package/dist/types/components/CombinedEncryptedField/CombinedEncryptedField.d.ts +4 -0
- package/dist/types/components/CombinedEncryptedField/index.d.ts +2 -0
- package/dist/types/components/CombinedEncryptedField/type.d.ts +15 -0
- package/dist/types/components/EncryptedCard/EncryptedCard.d.ts +4 -0
- package/dist/types/components/EncryptedCard/index.d.ts +4 -0
- package/dist/types/components/EncryptedCard/output.d.ts +9 -0
- package/dist/types/components/EncryptedCard/type.d.ts +85 -0
- package/dist/types/components/GooglePay/type.d.ts +17 -6
- package/dist/types/components/GooglePay/utils.d.ts +2 -0
- package/dist/types/components/SecuredFieldsProvider/type.d.ts +103 -22
- package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +6 -2
- package/dist/types/components/Sepa/type.d.ts +0 -2
- package/dist/types/components/WechatPay/type.d.ts +0 -2
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/components/internal/Form/FormItem.d.ts +1 -1
- package/dist/types/components/internal/Form/type.d.ts +7 -0
- package/dist/types/components/internal/Input/Input.d.ts +1 -1
- package/dist/types/components/internal/Input/type.d.ts +6 -0
- package/dist/types/config.d.ts +7 -3
- package/dist/types/constant.d.ts +1 -0
- package/dist/types/core/PayKKaCheckout.d.ts +12 -0
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/query.d.ts +2 -2
- package/dist/types/hooks/usePayState.d.ts +4 -20
- package/dist/types/index.d.ts +2 -2
- package/dist/types/out/fraud-detection.d.ts +9 -0
- package/dist/types/types/{radar.d.ts → fraud-detection.d.ts} +3 -2
- package/dist/types/types/index.d.ts +69 -1
- package/dist/types/utils/card-brand/brands.d.ts +3 -10
- package/dist/types/utils/card-brand/index.d.ts +10 -9
- package/dist/types/utils/format.d.ts +0 -1
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/load.d.ts +7 -0
- package/dist/types/utils/style.d.ts +17 -0
- package/package.json +2 -2
- package/dist/card-checkout-ui.iife.js +0 -8
- package/dist/es/out/radar.js +0 -123
- package/dist/types/out/radar.d.ts +0 -14
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { intersection } from "../../../utils/index.js";
|
|
2
|
+
import { http } from "../../http.js";
|
|
3
|
+
import { formatPaymentMethodInfo } from "../checkout/map.js";
|
|
4
|
+
import { cardBrandCodes } from "../../../utils/card-brand/brands.js";
|
|
5
|
+
const verifyClientKey = async (clientKey, merchantId, options) => {
|
|
6
|
+
return http.post(
|
|
7
|
+
"/frames/info",
|
|
8
|
+
{
|
|
9
|
+
merchant_id: merchantId,
|
|
10
|
+
client_key: clientKey
|
|
11
|
+
},
|
|
12
|
+
options
|
|
13
|
+
).then((res) => {
|
|
14
|
+
var _a;
|
|
15
|
+
const { paymentMethod } = formatPaymentMethodInfo(((_a = res.support_methods) == null ? void 0 : _a.payment_methods) || []);
|
|
16
|
+
const brands = intersection(cardBrandCodes, paymentMethod);
|
|
17
|
+
return {
|
|
18
|
+
brands
|
|
19
|
+
};
|
|
20
|
+
}).catch(() => {
|
|
21
|
+
return null;
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const encryptCard = async (card, options) => {
|
|
25
|
+
return http.post(
|
|
26
|
+
"/frames/card/encrypt",
|
|
27
|
+
{
|
|
28
|
+
type: "BANKCARD",
|
|
29
|
+
merchant_id: card.merchantId,
|
|
30
|
+
client_key: card.clientKey,
|
|
31
|
+
card_no: card.cardNo,
|
|
32
|
+
cvv: card.cvv,
|
|
33
|
+
exp_year: card.expYear,
|
|
34
|
+
exp_month: card.expMonth
|
|
35
|
+
},
|
|
36
|
+
options
|
|
37
|
+
).then((res) => {
|
|
38
|
+
return {
|
|
39
|
+
encryptedCardNumber: res.encrypted_card_no,
|
|
40
|
+
encryptedCVV: res.encrypted_cvv,
|
|
41
|
+
encryptedExpireYear: res.encrypted_exp_year,
|
|
42
|
+
encryptedExpireMonth: res.encrypted_exp_month,
|
|
43
|
+
cardInfo: {
|
|
44
|
+
bin: res.card_info.bin,
|
|
45
|
+
brand: res.card_info.card_brand,
|
|
46
|
+
last4: res.card_info.last4
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
encryptCard,
|
|
53
|
+
verifyClientKey
|
|
54
|
+
};
|
|
@@ -2,7 +2,7 @@ import "../../utils/card-brand/brands.js";
|
|
|
2
2
|
import { getBrowser } from "../../utils/system-info/index.js";
|
|
3
3
|
import { isUaWebview } from "../../utils/system-info/is-ua-webview.js";
|
|
4
4
|
async function getBrowserParams(params = {}) {
|
|
5
|
-
const {
|
|
5
|
+
const { fraudDetectionId } = params;
|
|
6
6
|
const browser = await getBrowser();
|
|
7
7
|
let terminalType = "WEB";
|
|
8
8
|
const userAgent = window.navigator.userAgent.toLowerCase();
|
|
@@ -30,7 +30,7 @@ async function getBrowserParams(params = {}) {
|
|
|
30
30
|
device_os: browser.osName,
|
|
31
31
|
device_finger_print_id: browser.deviceFingerprintId,
|
|
32
32
|
terminal_type: terminalType,
|
|
33
|
-
|
|
33
|
+
fraud_detection_id: fraudDetectionId
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
export {
|
|
@@ -5,10 +5,12 @@ import { useI18n } from "../../hooks/useI18n.js";
|
|
|
5
5
|
import "../../core/context.js";
|
|
6
6
|
import "../../i18n/util.js";
|
|
7
7
|
import "../../i18n/locales/index.js";
|
|
8
|
+
import "../internal/Form/type.js";
|
|
8
9
|
import "../internal/Form/context.js";
|
|
9
10
|
import { FormItem } from "../internal/Form/FormItem.js";
|
|
10
11
|
import "../internal/Form/Form.js";
|
|
11
12
|
import { Input } from "../internal/Input/Input.js";
|
|
13
|
+
import "../internal/Input/type.js";
|
|
12
14
|
function AccountNameField(props) {
|
|
13
15
|
const { className, style } = props;
|
|
14
16
|
const { i18n } = useI18n();
|
|
@@ -10,10 +10,12 @@ import "../../utils/card-brand/brands.js";
|
|
|
10
10
|
import "../../utils/system-info/get-browser-info.js";
|
|
11
11
|
import "../../i18n/util.js";
|
|
12
12
|
import "../../i18n/locales/index.js";
|
|
13
|
+
import "../internal/Form/type.js";
|
|
13
14
|
import "../internal/Form/context.js";
|
|
14
15
|
import { FormItem } from "../internal/Form/FormItem.js";
|
|
15
16
|
import "../internal/Form/Form.js";
|
|
16
17
|
import { Input } from "../internal/Input/Input.js";
|
|
18
|
+
import "../internal/Input/type.js";
|
|
17
19
|
import { Select } from "../internal/Select/Select.js";
|
|
18
20
|
const { bem } = useBEM("address-field");
|
|
19
21
|
const defaultAddress = {
|
|
@@ -7,14 +7,15 @@ import "../../utils/system-info/get-browser-info.js";
|
|
|
7
7
|
import { formatAmount } from "../../utils/format.js";
|
|
8
8
|
import { PaymentType } from "../../constant.js";
|
|
9
9
|
import { CoreContext } from "../../core/context.js";
|
|
10
|
-
import { createAddressCore } from "../../core/Address.js";
|
|
11
|
-
import { useBEM } from "../../hooks/useBEM.js";
|
|
12
10
|
import "../../i18n/util.js";
|
|
13
11
|
import "../../i18n/locales/index.js";
|
|
12
|
+
import { createAddressCore } from "../../core/Address.js";
|
|
13
|
+
import { useBEM } from "../../hooks/useBEM.js";
|
|
14
14
|
import { usePayState } from "../../hooks/usePayState.js";
|
|
15
15
|
import { useRetry } from "../../hooks/useRetry.js";
|
|
16
16
|
import { AddressField } from "../AddressField/index.js";
|
|
17
17
|
import { EmailField, createEmailCore } from "../EmailField/EmailField.js";
|
|
18
|
+
import "../internal/Form/type.js";
|
|
18
19
|
import "../internal/Form/context.js";
|
|
19
20
|
import "../internal/Form/FormItem.js";
|
|
20
21
|
import { Form } from "../internal/Form/Form.js";
|
|
@@ -23,10 +24,9 @@ import { RecurringTip } from "../RecurringTip/index.js";
|
|
|
23
24
|
import { SubmitButton } from "../SubmitButton/index.js";
|
|
24
25
|
const { bem } = useBEM("ali-pay");
|
|
25
26
|
const AliPay = w((props, ref) => {
|
|
26
|
-
const { sessionId, clientKey } = props;
|
|
27
27
|
let addressState = createAddressCore();
|
|
28
28
|
let emailState = createEmailCore();
|
|
29
|
-
const { setErrorMsg, i18n, session, errorMsg, sessionReady } = usePayState(
|
|
29
|
+
const { setErrorMsg, i18n, session, errorMsg, sessionReady } = usePayState();
|
|
30
30
|
const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
|
|
31
31
|
const formRef = A(null);
|
|
32
32
|
const [form, setForm] = h({
|
|
@@ -109,14 +109,14 @@ const AliPay = w((props, ref) => {
|
|
|
109
109
|
try {
|
|
110
110
|
const res = search ? await getAliPayInfo(
|
|
111
111
|
{
|
|
112
|
-
sessionId,
|
|
113
|
-
clientKey
|
|
112
|
+
sessionId: session.sessionId,
|
|
113
|
+
clientKey: session.clientKey
|
|
114
114
|
},
|
|
115
115
|
{ locale: i18n.locale, timeout }
|
|
116
116
|
) : await aliPay(
|
|
117
117
|
{
|
|
118
|
-
sessionId,
|
|
119
|
-
clientKey,
|
|
118
|
+
sessionId: session.sessionId,
|
|
119
|
+
clientKey: session.clientKey,
|
|
120
120
|
bill: requiredBill ? {
|
|
121
121
|
email: form.email,
|
|
122
122
|
...form.address,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { w, h, y, q, u, b } from "../../core.js";
|
|
2
2
|
import { isTimeoutError } from "../../api/http.js";
|
|
3
|
+
import { PaymentMethod } from "../../constant.js";
|
|
3
4
|
import { getBrowserParams } from "../../api/modules/get-browser-params.js";
|
|
4
5
|
import { getApplePayInfo, applePay, getMerchantSession } from "../../api/modules/apple-pay/index.js";
|
|
5
6
|
import { useBEM } from "../../hooks/useBEM.js";
|
|
@@ -12,18 +13,74 @@ import "../../i18n/locales/index.js";
|
|
|
12
13
|
import { usePayState } from "../../hooks/usePayState.js";
|
|
13
14
|
import { useRetry } from "../../hooks/useRetry.js";
|
|
14
15
|
import { Info } from "../internal/Info/Info.js";
|
|
16
|
+
import { loadScript } from "../../utils/load.js";
|
|
17
|
+
const loadApplePayJS = (onload, onerror) => {
|
|
18
|
+
loadScript({
|
|
19
|
+
src: "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js",
|
|
20
|
+
onload,
|
|
21
|
+
onerror,
|
|
22
|
+
extraOptions: {
|
|
23
|
+
async: true,
|
|
24
|
+
crossOrigin: ""
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
async function applePayEnv(id) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
if (!id || !ApplePaySession)
|
|
31
|
+
return false;
|
|
32
|
+
if (!((_a = ApplePaySession.canMakePayments) == null ? void 0 : _a.call(ApplePaySession))) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const capabilities = await ((_b = ApplePaySession.applePayCapabilities) == null ? void 0 : _b.call(ApplePaySession, id));
|
|
36
|
+
if ([
|
|
37
|
+
"paymentCredentialsAvailable",
|
|
38
|
+
"paymentCredentialStatusUnknown",
|
|
39
|
+
"paymentCredentialsUnavailable"
|
|
40
|
+
].includes(capabilities.paymentCredentialStatus)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
15
45
|
const { bem } = useBEM("apple-pay");
|
|
16
46
|
const ApplePay = w((props) => {
|
|
17
|
-
const { sessionId, clientKey } = props;
|
|
18
47
|
let applePaySession;
|
|
19
|
-
const { i18n, session, sessionReady,
|
|
48
|
+
const { i18n, session, sessionReady, fraudDetection } = usePayState();
|
|
20
49
|
const [errorMsg, setErrorMsg] = h("");
|
|
50
|
+
const [showApplePay, setShowApplePay] = h(false);
|
|
51
|
+
const getPaymentSuccessData = () => ({
|
|
52
|
+
returnUrl: session == null ? void 0 : session.checkout.returnUrl
|
|
53
|
+
});
|
|
21
54
|
y(() => {
|
|
22
55
|
var _a;
|
|
23
|
-
if (sessionReady) {
|
|
24
|
-
|
|
25
|
-
|
|
56
|
+
if (!sessionReady) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const { status, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
|
|
60
|
+
if (!paymentMethod.includes(PaymentMethod.APPLE_PAY)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
loadApplePayJS(
|
|
64
|
+
async () => {
|
|
65
|
+
var _a2, _b, _c, _d, _e;
|
|
66
|
+
const envSupported = await applePayEnv(
|
|
67
|
+
(_c = (_b = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.channelParams) == null ? void 0 : _b.applePay) == null ? void 0 : _c.merchantIdentifier
|
|
68
|
+
);
|
|
69
|
+
if (!envSupported) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
setShowApplePay(true);
|
|
73
|
+
(_d = props.onLoad) == null ? void 0 : _d.call(props, true);
|
|
74
|
+
console.log((_e = ApplePaySession.canMakePayments) == null ? void 0 : _e.call(ApplePaySession));
|
|
75
|
+
},
|
|
76
|
+
() => {
|
|
77
|
+
var _a2;
|
|
78
|
+
setShowApplePay(false);
|
|
79
|
+
(_a2 = props.onLoad) == null ? void 0 : _a2.call(props, false);
|
|
26
80
|
}
|
|
81
|
+
);
|
|
82
|
+
if (status === "SUCCESS") {
|
|
83
|
+
(_a = props.onSuccess) == null ? void 0 : _a.call(props, getPaymentSuccessData());
|
|
27
84
|
}
|
|
28
85
|
}, [sessionReady]);
|
|
29
86
|
const onTimeout = q(
|
|
@@ -48,8 +105,8 @@ const ApplePay = w((props) => {
|
|
|
48
105
|
try {
|
|
49
106
|
const res = await (search ? getApplePayInfo(
|
|
50
107
|
{
|
|
51
|
-
sessionId,
|
|
52
|
-
clientKey
|
|
108
|
+
sessionId: session.sessionId,
|
|
109
|
+
clientKey: session.clientKey
|
|
53
110
|
},
|
|
54
111
|
{ locale: i18n.locale, timeout }
|
|
55
112
|
) : async function() {
|
|
@@ -57,8 +114,8 @@ const ApplePay = w((props) => {
|
|
|
57
114
|
const phone = parseE164(billingContact == null ? void 0 : billingContact.phoneNumber);
|
|
58
115
|
return applePay(
|
|
59
116
|
{
|
|
60
|
-
sessionId,
|
|
61
|
-
clientKey,
|
|
117
|
+
sessionId: session.sessionId,
|
|
118
|
+
clientKey: session.clientKey,
|
|
62
119
|
token: JSON.stringify({
|
|
63
120
|
token
|
|
64
121
|
}),
|
|
@@ -76,7 +133,7 @@ const ApplePay = w((props) => {
|
|
|
76
133
|
country: billingContact == null ? void 0 : billingContact.countryCode
|
|
77
134
|
},
|
|
78
135
|
browser: await getBrowserParams({
|
|
79
|
-
|
|
136
|
+
fraudDetectionId: fraudDetection == null ? void 0 : fraudDetection.fraudDetectionID
|
|
80
137
|
})
|
|
81
138
|
},
|
|
82
139
|
{ locale: i18n.locale }
|
|
@@ -88,7 +145,7 @@ const ApplePay = w((props) => {
|
|
|
88
145
|
applePaySession.completePayment({
|
|
89
146
|
status: 0
|
|
90
147
|
});
|
|
91
|
-
(_a = props.onSuccess) == null ? void 0 : _a.call(props);
|
|
148
|
+
(_a = props.onSuccess) == null ? void 0 : _a.call(props, getPaymentSuccessData());
|
|
92
149
|
return {
|
|
93
150
|
end: true
|
|
94
151
|
};
|
|
@@ -125,7 +182,7 @@ const ApplePay = w((props) => {
|
|
|
125
182
|
};
|
|
126
183
|
}
|
|
127
184
|
} else if (status === "SUCCESS") {
|
|
128
|
-
(_d = props.onSuccess) == null ? void 0 : _d.call(props);
|
|
185
|
+
(_d = props.onSuccess) == null ? void 0 : _d.call(props, getPaymentSuccessData());
|
|
129
186
|
applePaySession.completePayment({
|
|
130
187
|
status: 0
|
|
131
188
|
});
|
|
@@ -139,7 +196,7 @@ const ApplePay = w((props) => {
|
|
|
139
196
|
end: true
|
|
140
197
|
};
|
|
141
198
|
}
|
|
142
|
-
(_f = props.onSuccess) == null ? void 0 : _f.call(props);
|
|
199
|
+
(_f = props.onSuccess) == null ? void 0 : _f.call(props, getPaymentSuccessData());
|
|
143
200
|
return {
|
|
144
201
|
end: true
|
|
145
202
|
};
|
|
@@ -232,7 +289,7 @@ const ApplePay = w((props) => {
|
|
|
232
289
|
}
|
|
233
290
|
) });
|
|
234
291
|
};
|
|
235
|
-
return /* @__PURE__ */ u("div", { children: i18n.ready.value && /* @__PURE__ */ u(b, { children: [
|
|
292
|
+
return /* @__PURE__ */ u("div", { children: sessionReady && showApplePay && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
|
|
236
293
|
!!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
|
|
237
294
|
Button()
|
|
238
295
|
] }) });
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { w, A, h, F, y, q, T, u } from "../../core.js";
|
|
2
2
|
import { isTimeoutError } from "../../api/http.js";
|
|
3
|
-
import { PaymentType, SessionMode, COMMON_CLASS_NAME, PaymentMethod } from "../../constant.js";
|
|
3
|
+
import { PaymentType, SessionMode, COMMON_CLASS_NAME, CardPaymentMethods, PaymentMethod } from "../../constant.js";
|
|
4
4
|
import { getBrowserParams } from "../../api/modules/get-browser-params.js";
|
|
5
5
|
import { getCardPayInfo, cardPay } from "../../api/modules/card/index.js";
|
|
6
6
|
import { CoreContext } from "../../core/context.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import "../../utils/system-info/get-browser-info.js";
|
|
10
|
-
import { cssVarPrefix, normalizedClass, trimAll, formatAmount } from "../../utils/format.js";
|
|
7
|
+
import { intersection } from "../../utils/index.js";
|
|
8
|
+
import { hidePaymentButton } from "../../config.js";
|
|
11
9
|
import { createAddressCore } from "../../core/Address.js";
|
|
12
10
|
import { useBEM } from "../../hooks/useBEM.js";
|
|
13
11
|
import "../../i18n/util.js";
|
|
@@ -23,23 +21,28 @@ import { CardSecurityCodeField } from "../CardSecurityCodeField/index.js";
|
|
|
23
21
|
import { CardSelector } from "../CardSelector/index.js";
|
|
24
22
|
import { createEmailCore, EmailField } from "../EmailField/EmailField.js";
|
|
25
23
|
import { CheckBox } from "../internal/CheckBox/CheckBox.js";
|
|
24
|
+
import "../internal/Form/type.js";
|
|
26
25
|
import "../internal/Form/context.js";
|
|
27
26
|
import "../internal/Form/FormItem.js";
|
|
28
27
|
import { Form } from "../internal/Form/Form.js";
|
|
29
28
|
import { IconSwitch } from "../internal/icons/IconSwitch.js";
|
|
30
29
|
import { Info } from "../internal/Info/Info.js";
|
|
31
30
|
import { RecurringTip } from "../RecurringTip/index.js";
|
|
32
|
-
import {
|
|
31
|
+
import { EFieldType, SecuredFieldsProvider } from "../SecuredFieldsProvider/SecuredFieldsProvider.js";
|
|
33
32
|
import { SubmitButton } from "../SubmitButton/index.js";
|
|
33
|
+
import { defaultInputStyleConfig } from "../../types/index.js";
|
|
34
|
+
import { cssVarPrefix, normalizedClass, trimAll, formatAmount } from "../../utils/format.js";
|
|
35
|
+
import { isEmptyObject, isUndefined } from "../../utils/is.js";
|
|
34
36
|
import { cardBrandCodes } from "../../utils/card-brand/brands.js";
|
|
37
|
+
import { findCardBrand } from "../../utils/card-brand/index.js";
|
|
35
38
|
const { bem } = useBEM("card");
|
|
36
39
|
const fieldClassNames = bem("field");
|
|
37
40
|
const Card = w((props, ref) => {
|
|
38
41
|
var _a, _b, _c, _d, _e, _f;
|
|
39
|
-
const {
|
|
42
|
+
const { showCardBrands = true } = props;
|
|
40
43
|
let addressState = createAddressCore();
|
|
41
44
|
let emailState = createEmailCore();
|
|
42
|
-
const { i18n, session, sessionReady,
|
|
45
|
+
const { i18n, session, sessionReady, fraudDetection } = usePayState();
|
|
43
46
|
const addressFieldRef = A(null);
|
|
44
47
|
const emailFieldRef = A(null);
|
|
45
48
|
const formRef = A(null);
|
|
@@ -81,31 +84,40 @@ const Card = w((props, ref) => {
|
|
|
81
84
|
var _a2;
|
|
82
85
|
setForm(Object.assign(form, { email: emailState.email }));
|
|
83
86
|
(_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
|
|
87
|
+
},
|
|
88
|
+
payment: () => {
|
|
89
|
+
!hidePaymentButton && onSubmit();
|
|
84
90
|
}
|
|
85
91
|
}));
|
|
92
|
+
const getPaymentSuccessData = () => ({
|
|
93
|
+
returnUrl: session == null ? void 0 : session.checkout.returnUrl
|
|
94
|
+
});
|
|
86
95
|
y(() => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const { bill, status } = session.checkout;
|
|
96
|
-
form.email = bill.email ?? "";
|
|
97
|
-
disabledEmail.current = !!bill.email;
|
|
98
|
-
setRequiredBill(bill.billingAddressCollection === "REQUIRED");
|
|
99
|
-
setSupportedCardBrands(
|
|
100
|
-
cardBrandCodes.filter((code) => session == null ? void 0 : session.checkout.paymentMethod.includes(code))
|
|
101
|
-
);
|
|
102
|
-
if (status === "SUCCESS") {
|
|
103
|
-
setSubmitButtonStatus("success");
|
|
104
|
-
processOnSuccess();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
96
|
+
var _a2;
|
|
97
|
+
if (!sessionReady) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const { status, paymentMethod = [], bill = {} } = (session == null ? void 0 : session.checkout) || {};
|
|
101
|
+
console.log(intersection(paymentMethod, CardPaymentMethods));
|
|
102
|
+
if (!intersection(paymentMethod, CardPaymentMethods).length) {
|
|
103
|
+
return;
|
|
107
104
|
}
|
|
108
|
-
|
|
105
|
+
if (isEmptyObject(session == null ? void 0 : session.checkout)) {
|
|
106
|
+
(_a2 = props.onError) == null ? void 0 : _a2.call(props, "FAILURE");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
setIsCheckoutEnabled(true);
|
|
110
|
+
form.email = bill.email ?? "";
|
|
111
|
+
disabledEmail.current = !!bill.email;
|
|
112
|
+
setRequiredBill(bill.billingAddressCollection === "REQUIRED");
|
|
113
|
+
setSupportedCardBrands(
|
|
114
|
+
cardBrandCodes.filter((code) => session == null ? void 0 : session.checkout.paymentMethod.includes(code))
|
|
115
|
+
);
|
|
116
|
+
if (status === "SUCCESS") {
|
|
117
|
+
setSubmitButtonStatus("success");
|
|
118
|
+
processOnSuccess();
|
|
119
|
+
}
|
|
120
|
+
}, [sessionReady]);
|
|
109
121
|
const onTimeout = q(
|
|
110
122
|
(message) => {
|
|
111
123
|
var _a2;
|
|
@@ -116,8 +128,8 @@ const Card = w((props, ref) => {
|
|
|
116
128
|
[i18n, props.onTimeout]
|
|
117
129
|
);
|
|
118
130
|
const processOnSuccess = () => {
|
|
119
|
-
var _a2
|
|
120
|
-
(
|
|
131
|
+
var _a2;
|
|
132
|
+
(_a2 = props.onSuccess) == null ? void 0 : _a2.call(props, getPaymentSuccessData());
|
|
121
133
|
};
|
|
122
134
|
const { start: startReFetchPayInfo } = useRetry((timeout) => pay(true, timeout), {
|
|
123
135
|
onTimeout: () => onTimeout(i18n.get("common.queryTimeout"))
|
|
@@ -146,8 +158,8 @@ const Card = w((props, ref) => {
|
|
|
146
158
|
const isFastPaymentForm = isFastPayment && !isEditOtherCard;
|
|
147
159
|
const paymentMethod = isFastPayment ? PaymentMethod.BANKCARD : ((_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.sessionMode) === SessionMode.EMBEDDED ? (_b2 = cardNumberFieldRef.current) == null ? void 0 : _b2.getCardBrand().code : cardBrand.code;
|
|
148
160
|
return {
|
|
149
|
-
sessionId,
|
|
150
|
-
clientKey,
|
|
161
|
+
sessionId: session.sessionId,
|
|
162
|
+
clientKey: session.clientKey,
|
|
151
163
|
payment: {
|
|
152
164
|
paymentMethod,
|
|
153
165
|
cvv: form.securityCode,
|
|
@@ -170,7 +182,7 @@ const Card = w((props, ref) => {
|
|
|
170
182
|
email: form.email
|
|
171
183
|
},
|
|
172
184
|
browser: await getBrowserParams({
|
|
173
|
-
|
|
185
|
+
fraudDetectionId: fraudDetection == null ? void 0 : fraudDetection.fraudDetectionID
|
|
174
186
|
})
|
|
175
187
|
};
|
|
176
188
|
};
|
|
@@ -183,7 +195,10 @@ const Card = w((props, ref) => {
|
|
|
183
195
|
return { end: true };
|
|
184
196
|
}
|
|
185
197
|
const options = { locale: i18n.locale, timeout };
|
|
186
|
-
const res = search ? await getCardPayInfo(
|
|
198
|
+
const res = search ? await getCardPayInfo(
|
|
199
|
+
{ sessionId: session.sessionId, clientKey: session.clientKey },
|
|
200
|
+
options
|
|
201
|
+
) : await cardPay(paymentParams, options);
|
|
187
202
|
return processAfterPayment(res, search);
|
|
188
203
|
} catch (error) {
|
|
189
204
|
if (isTimeoutError(error)) {
|
|
@@ -432,9 +447,9 @@ const Card = w((props, ref) => {
|
|
|
432
447
|
(_a2 = SFPRef.current) == null ? void 0 : _a2.reload();
|
|
433
448
|
}, [showFastPaymentForm]);
|
|
434
449
|
const fieldRefMap = {
|
|
435
|
-
[
|
|
436
|
-
[
|
|
437
|
-
[
|
|
450
|
+
[EFieldType.CARD_NUMBER]: cardNumberFieldRef,
|
|
451
|
+
[EFieldType.CVV]: cardSecurityCodeFieldRef,
|
|
452
|
+
[EFieldType.EXPIRE_DATE]: cardExpireDateFieldRef
|
|
438
453
|
};
|
|
439
454
|
const onFieldsFocus = (data) => {
|
|
440
455
|
var _a2, _b2;
|
|
@@ -518,7 +533,7 @@ const Card = w((props, ref) => {
|
|
|
518
533
|
(session == null ? void 0 : session.checkout.paymentType) === PaymentType.RECURRING && RecurringTip(),
|
|
519
534
|
isShowStoreCheckBox && storeCheckBox(),
|
|
520
535
|
!!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg, style: { marginTop: "12px" } }),
|
|
521
|
-
Button()
|
|
536
|
+
!hidePaymentButton && Button()
|
|
522
537
|
] }) });
|
|
523
538
|
};
|
|
524
539
|
const fastPaymentCardForm = () => {
|
|
@@ -558,7 +573,7 @@ const Card = w((props, ref) => {
|
|
|
558
573
|
}
|
|
559
574
|
) }),
|
|
560
575
|
!!errorMsg && /* @__PURE__ */ u(Info, { content: errorMsg, style: { marginTop: "12px" } }),
|
|
561
|
-
Button()
|
|
576
|
+
!hidePaymentButton && Button()
|
|
562
577
|
] });
|
|
563
578
|
};
|
|
564
579
|
return /* @__PURE__ */ u(
|
|
@@ -575,6 +590,7 @@ const Card = w((props, ref) => {
|
|
|
575
590
|
i18n,
|
|
576
591
|
sessionMode: session.checkout.sessionMode,
|
|
577
592
|
supportedCardBrands,
|
|
593
|
+
style: defaultInputStyleConfig,
|
|
578
594
|
onFocus: onFieldsFocus,
|
|
579
595
|
onBinValue: onBinValueChanged,
|
|
580
596
|
onAfterPayment,
|
|
@@ -4,15 +4,17 @@ import { useI18n } from "../../hooks/useI18n.js";
|
|
|
4
4
|
import "../../core/context.js";
|
|
5
5
|
import "../../i18n/util.js";
|
|
6
6
|
import "../../i18n/locales/index.js";
|
|
7
|
+
import "../internal/Form/type.js";
|
|
7
8
|
import "../internal/Form/context.js";
|
|
8
9
|
import { FormItem } from "../internal/Form/FormItem.js";
|
|
9
10
|
import "../internal/Form/Form.js";
|
|
10
11
|
import { Input } from "../internal/Input/Input.js";
|
|
11
|
-
import
|
|
12
|
+
import "../internal/Input/type.js";
|
|
13
|
+
import { EFieldType } from "../SecuredFieldsProvider/SecuredFieldsProvider.js";
|
|
12
14
|
import { limitedToNumber } from "../../utils/format.js";
|
|
13
15
|
import { isUndefined } from "../../utils/is.js";
|
|
14
16
|
const CardExpireDateField = w((props, ref) => {
|
|
15
|
-
const { className, style, security } = props;
|
|
17
|
+
const { className, style, security, showLabel } = props;
|
|
16
18
|
const inputRef = A(null);
|
|
17
19
|
const formItemRef = A(null);
|
|
18
20
|
F(ref, () => ({
|
|
@@ -117,6 +119,7 @@ const CardExpireDateField = w((props, ref) => {
|
|
|
117
119
|
FormItem,
|
|
118
120
|
{
|
|
119
121
|
label: i18n.get("card.cardExpireDate.label"),
|
|
122
|
+
showLabel,
|
|
120
123
|
path: "expireDate",
|
|
121
124
|
ref: formItemRef,
|
|
122
125
|
rule,
|
|
@@ -132,7 +135,7 @@ const CardExpireDateField = w((props, ref) => {
|
|
|
132
135
|
value,
|
|
133
136
|
onInput,
|
|
134
137
|
placeholder: i18n.get("card.cardExpireDate.placeholder"),
|
|
135
|
-
children: security && /* @__PURE__ */ u("div", { style: "width:100%;height:100%", "data-sf":
|
|
138
|
+
children: security && /* @__PURE__ */ u("div", { style: "width:100%;height:100%", "data-sf": EFieldType.EXPIRE_DATE })
|
|
136
139
|
}
|
|
137
140
|
)
|
|
138
141
|
}
|
|
@@ -5,10 +5,12 @@ import { useI18n } from "../../hooks/useI18n.js";
|
|
|
5
5
|
import "../../core/context.js";
|
|
6
6
|
import "../../i18n/util.js";
|
|
7
7
|
import "../../i18n/locales/index.js";
|
|
8
|
+
import "../internal/Form/type.js";
|
|
8
9
|
import "../internal/Form/context.js";
|
|
9
10
|
import { FormItem } from "../internal/Form/FormItem.js";
|
|
10
11
|
import "../internal/Form/Form.js";
|
|
11
12
|
import { Input } from "../internal/Input/Input.js";
|
|
13
|
+
import "../internal/Input/type.js";
|
|
12
14
|
function CardHolderNameField(props) {
|
|
13
15
|
const { className, style } = props;
|
|
14
16
|
const { i18n } = useI18n();
|
|
@@ -4,10 +4,12 @@ import { useI18n } from "../../hooks/useI18n.js";
|
|
|
4
4
|
import "../../core/context.js";
|
|
5
5
|
import "../../i18n/util.js";
|
|
6
6
|
import "../../i18n/locales/index.js";
|
|
7
|
+
import "../internal/Form/type.js";
|
|
7
8
|
import "../internal/Form/context.js";
|
|
8
9
|
import { FormItem } from "../internal/Form/FormItem.js";
|
|
9
10
|
import "../internal/Form/Form.js";
|
|
10
11
|
import { Input } from "../internal/Input/Input.js";
|
|
12
|
+
import "../internal/Input/type.js";
|
|
11
13
|
import { validateIBAN } from "../../utils/iban.js";
|
|
12
14
|
import { trimAll, limitedToNumber } from "../../utils/format.js";
|
|
13
15
|
function IBANField(props) {
|