@paykka/card-checkout-ui 0.6.0 → 0.8.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 +19 -19
- package/dist/card-checkout-ui.umd.cjs +19 -19
- package/dist/es/api/index.js +0 -2
- package/dist/es/api/modules/checkout/index.js +1 -15
- package/dist/es/api/modules/checkout/map.js +31 -3
- package/dist/es/api/modules/index.js +0 -2
- package/dist/es/components/AccountNameField/index.js +0 -3
- package/dist/es/components/AddressField/index.js +2 -7
- package/dist/es/components/AliPay/index.js +45 -34
- package/dist/es/components/ApplePay/index.js +19 -13
- package/dist/es/components/Card/index.js +334 -155
- package/dist/es/components/CardBrands/index.js +0 -2
- package/dist/es/components/CardExpireDateField/index.js +1 -4
- package/dist/es/components/CardHolderNameField/index.js +3 -5
- package/dist/es/components/CardIBANField/index.js +0 -3
- package/dist/es/components/CardNo/index.js +0 -2
- package/dist/es/components/CardNumberField/index.js +1 -4
- package/dist/es/components/CardSecurityCodeField/index.js +1 -4
- package/dist/es/components/CardSelector/index.js +0 -3
- package/dist/es/components/CombinedCardInfo/index.js +99 -0
- package/dist/es/components/DropIn/index.js +210 -0
- package/dist/es/components/EmailField/EmailField.js +0 -3
- package/dist/es/components/EncryptedCard/index.js +35 -75
- package/dist/es/components/GooglePay/index.js +69 -28
- package/dist/es/components/RecurringTip/index.js +0 -2
- package/dist/es/components/SecuredFieldsProvider/index.js +230 -1
- package/dist/es/components/SecuredIframe/index.js +3 -1
- package/dist/es/components/Sepa/index.js +26 -30
- package/dist/es/components/SubmitButton/index.js +0 -2
- package/dist/es/components/ThreeDS/index.js +94 -0
- package/dist/es/components/WechatPay/index.js +48 -38
- package/dist/es/components/index.js +2 -3
- package/dist/es/components/internal/Button/Button.js +0 -2
- package/dist/es/components/internal/Button/index.js +0 -2
- package/dist/es/components/internal/CheckBox/CheckBox.js +0 -2
- package/dist/es/components/internal/CheckBox/index.js +0 -2
- package/dist/es/components/internal/Form/type.js +0 -2
- package/dist/es/components/internal/Info/Info.js +0 -2
- package/dist/es/components/internal/Info/index.js +0 -2
- package/dist/es/components/internal/Input/Input.js +2 -2
- package/dist/es/components/internal/Input/type.js +0 -2
- package/dist/es/components/internal/LoadingCheck/LoadingCheck.js +0 -2
- package/dist/es/components/internal/LoadingCheck/index.js +0 -2
- package/dist/es/components/internal/Modal/Modal.js +40 -0
- package/dist/es/components/internal/Modal/modal2.js +1 -0
- package/dist/es/components/internal/Select/Select.js +0 -2
- package/dist/es/components/internal/Select/SelectMenu.js +0 -2
- package/dist/es/components/internal/Select/SelectMenuItem.js +0 -2
- package/dist/es/components/internal/icons/Icon3DSFail.js +3 -0
- package/dist/es/components/internal/icons/Icon3DSInfo.js +62 -0
- package/dist/es/components/internal/icons/Icon3DSSuccess.js +3 -0
- package/dist/es/components/internal/icons/IconCard.js +42 -0
- package/dist/es/config.js +0 -2
- package/dist/es/constant.js +13 -2
- package/dist/es/core/PayKKaCheckout.js +106 -42
- package/dist/es/core/Session.js +7 -6
- package/dist/es/core/environment.js +26 -0
- package/dist/es/core/error.js +21 -0
- package/dist/es/core/index.js +0 -2
- package/dist/es/core/query.js +0 -2
- package/dist/es/core.js +34 -34
- package/dist/es/hooks/index.js +0 -2
- package/dist/es/hooks/useBreakpoints.js +57 -0
- package/dist/es/hooks/useI18n.js +1 -2
- package/dist/es/hooks/usePayState.js +20 -24
- package/dist/es/i18n/index.js +0 -2
- package/dist/es/i18n/locales/de-DE.js +14 -1
- package/dist/es/i18n/locales/en-GB.js +14 -1
- package/dist/es/i18n/locales/es-ES.js +14 -1
- package/dist/es/i18n/locales/fr-FR.js +14 -1
- package/dist/es/i18n/locales/index.js +8 -6
- package/dist/es/i18n/locales/ja-JP.js +14 -1
- package/dist/es/i18n/locales/ko-KR.js +14 -1
- package/dist/es/i18n/locales/pt-PT.js +14 -1
- package/dist/es/i18n/locales/ru-RU.js +14 -1
- package/dist/es/i18n/locales/zh-CN.js +14 -1
- package/dist/es/i18n/locales/zh-HK.js +14 -1
- package/dist/es/i18n/locales/zh-TW.js +14 -1
- package/dist/es/i18n/util.js +22 -8
- package/dist/es/index.js +8 -2
- package/dist/es/style.css +289 -11
- package/dist/es/types/message.js +28 -0
- package/dist/es/utils/card-brand/brands.js +12 -10
- package/dist/es/utils/card-brand/index.js +3 -2
- package/dist/es/utils/iframe.js +23 -0
- package/dist/es/utils/index.js +0 -1
- package/dist/es/utils/style.js +47 -0
- package/dist/style.css +1 -1
- package/dist/types/api/modules/checkout/map.d.ts +2 -1
- package/dist/types/api/modules/checkout/type.d.ts +24 -2
- package/dist/types/api/modules/get-browser-params.d.ts +1 -1
- package/dist/types/components/AddressField/type.d.ts +1 -0
- package/dist/types/components/AliPay/AliPay.d.ts +2 -1
- package/dist/types/components/AliPay/type.d.ts +2 -1
- package/dist/types/components/ApplePay/ApplePay.d.ts +2 -1
- package/dist/types/components/ApplePay/type.d.ts +9 -5
- package/dist/types/components/Card/Card.d.ts +2 -1
- package/dist/types/components/Card/type.d.ts +55 -9
- package/dist/types/components/CardHolderNameField/type.d.ts +1 -1
- package/dist/types/components/CombinedCardInfo/CombinedCardInfo.d.ts +5 -0
- package/dist/types/components/CombinedCardInfo/index.d.ts +2 -0
- package/dist/types/components/{CombinedEncryptedField → CombinedCardInfo}/type.d.ts +3 -2
- package/dist/types/components/DropIn/DropIn.d.ts +6 -0
- package/dist/types/components/DropIn/components/PaymentTabs/PaymentTabs.d.ts +3 -0
- package/dist/types/components/DropIn/components/PaymentTabs/index.d.ts +2 -0
- package/dist/types/components/DropIn/components/PaymentTabs/type.d.ts +11 -0
- package/dist/types/components/DropIn/index.d.ts +2 -0
- package/dist/types/components/DropIn/type.d.ts +49 -0
- package/dist/types/components/GooglePay/GooglePay.d.ts +2 -1
- package/dist/types/components/GooglePay/type.d.ts +20 -8
- package/dist/types/components/SecuredFieldsProvider/index.d.ts +1 -0
- package/dist/types/components/SecuredFieldsProvider/type.d.ts +1 -153
- package/dist/types/components/SecuredFieldsProvider/utils/index.d.ts +1 -1
- package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +2 -1
- package/dist/types/components/Sepa/Sepa.d.ts +2 -1
- package/dist/types/components/Sepa/type.d.ts +2 -1
- package/dist/types/components/ThreeDS/components/ThreeDSAuth/ThreeDSAuth.d.ts +3 -0
- package/dist/types/components/ThreeDS/components/ThreeDSAuth/index.d.ts +2 -0
- package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +17 -0
- package/dist/types/components/ThreeDS/components/ThreeDSIframe/ThreeDSIframe.d.ts +2 -0
- package/dist/types/components/ThreeDS/components/ThreeDSIframe/index.d.ts +1 -0
- package/dist/types/components/ThreeDS/components/ThreeDSIframe/output.d.ts +1 -0
- package/dist/types/components/ThreeDS/components/ThreeDSIframe/type.d.ts +5 -0
- package/dist/types/components/ThreeDS/components/ThreeDSStatus/ThreeDSStatus.d.ts +3 -0
- package/dist/types/components/ThreeDS/components/ThreeDSStatus/output.d.ts +1 -0
- package/dist/types/components/ThreeDS/components/ThreeDSStatus/type.d.ts +6 -0
- package/dist/types/components/ThreeDS/index.d.ts +1 -0
- package/dist/types/components/WechatPay/WechatPay.d.ts +2 -1
- package/dist/types/components/WechatPay/type.d.ts +2 -1
- package/dist/types/components/index.d.ts +2 -1
- package/dist/types/components/internal/Input/type.d.ts +1 -0
- package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
- package/dist/types/components/internal/Loading/index.d.ts +1 -0
- package/dist/types/components/internal/Modal/Modal.d.ts +5 -0
- package/dist/types/components/internal/Modal/index.d.ts +2 -0
- package/dist/types/components/internal/Modal/type.d.ts +20 -0
- package/dist/types/components/internal/icons/Icon3DSFail.d.ts +2 -0
- package/dist/types/components/internal/icons/Icon3DSInfo.d.ts +2 -0
- package/dist/types/components/internal/icons/Icon3DSSuccess.d.ts +2 -0
- package/dist/types/components/internal/icons/IconCard.d.ts +2 -0
- package/dist/types/components/internal/icons/index.d.ts +4 -0
- package/dist/types/constant.d.ts +17 -2
- package/dist/types/core/PayKKaCheckout.d.ts +23 -6
- package/dist/types/core/Session.d.ts +1 -1
- package/dist/types/core/context.d.ts +1 -0
- package/dist/types/core/environment.d.ts +4 -0
- package/dist/types/core/error.d.ts +16 -0
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useBreakpoints.d.ts +15 -0
- package/dist/types/hooks/usePayState.d.ts +3 -6
- package/dist/types/i18n/locales/de-DE.d.ts +10 -0
- package/dist/types/i18n/locales/en-GB.d.ts +10 -0
- package/dist/types/i18n/locales/es-ES.d.ts +10 -0
- package/dist/types/i18n/locales/fr-FR.d.ts +10 -0
- package/dist/types/i18n/locales/index.d.ts +2 -2
- package/dist/types/i18n/locales/ja-JP.d.ts +10 -0
- package/dist/types/i18n/locales/ko-KR.d.ts +10 -0
- package/dist/types/i18n/locales/pt-PT.d.ts +10 -0
- package/dist/types/i18n/locales/ru-RU.d.ts +10 -0
- package/dist/types/i18n/locales/zh-CN.d.ts +10 -0
- package/dist/types/i18n/locales/zh-HK.d.ts +10 -0
- package/dist/types/i18n/locales/zh-TW.d.ts +10 -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 +59 -8
- package/dist/types/types/message.d.ts +170 -0
- package/dist/types/utils/card-brand/brands.d.ts +1 -8
- package/dist/types/utils/card-brand/index.d.ts +2 -2
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/style.d.ts +12 -0
- package/package.json +2 -2
- package/dist/es/components/CombinedEncryptedField/index.js +0 -75
- package/dist/es/components/SecuredFieldsProvider/SecuredFieldsProvider.js +0 -268
- package/dist/types/components/CombinedEncryptedField/CombinedEncryptedField.d.ts +0 -4
- package/dist/types/components/CombinedEncryptedField/index.d.ts +0 -2
- /package/dist/types/{components/SecuredFieldsProvider/utils → utils}/iframe.d.ts +0 -0
package/dist/es/api/index.js
CHANGED
|
@@ -12,23 +12,9 @@ async function queryCheckout({ sessionId, clientKey }, options) {
|
|
|
12
12
|
options
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
|
-
function getPaymentMethods({ sessionId, clientKey }, options) {
|
|
16
|
-
return http.post(
|
|
17
|
-
"/session/payment-methods",
|
|
18
|
-
{
|
|
19
|
-
session_id: sessionId,
|
|
20
|
-
client_key: clientKey
|
|
21
|
-
},
|
|
22
|
-
options
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
15
|
async function getCheckoutInfo({ sessionId, clientKey }, options) {
|
|
26
16
|
const checkoutInfo = await queryCheckout({ sessionId, clientKey }, options);
|
|
27
|
-
|
|
28
|
-
if (checkoutInfo) {
|
|
29
|
-
paymentMethods = await getPaymentMethods({ sessionId, clientKey }, options);
|
|
30
|
-
}
|
|
31
|
-
return checkoutMap({ ...checkoutInfo, ...paymentMethods });
|
|
17
|
+
return checkoutMap({ ...checkoutInfo, ...checkoutInfo == null ? void 0 : checkoutInfo.support_methods });
|
|
32
18
|
}
|
|
33
19
|
let getCheckoutInfoIns;
|
|
34
20
|
async function onceGetCheckoutInfo({ sessionId, clientKey }, options) {
|
|
@@ -32,19 +32,31 @@ function formatPaymentMethodInfo(paymentMethods = []) {
|
|
|
32
32
|
channelParams
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
+
function formatAmountBreakdown(info = {}) {
|
|
36
|
+
return {
|
|
37
|
+
goodsTax: info.goods_tax,
|
|
38
|
+
shippingAmount: info.shipping_amount,
|
|
39
|
+
shippingTax: info.shipping_tax,
|
|
40
|
+
discount: info.discount,
|
|
41
|
+
other: info.other
|
|
42
|
+
};
|
|
43
|
+
}
|
|
35
44
|
function checkoutMap(res = {}) {
|
|
36
45
|
var _a, _b, _c;
|
|
37
|
-
const { theme, bill, payment_methods } = res;
|
|
46
|
+
const { theme, bill, payment_methods, field } = res;
|
|
38
47
|
const paymentMethodsInfo = formatPaymentMethodInfo(payment_methods);
|
|
48
|
+
const sessionMode = res.session_mode === "HOST" ? "HOSTED" : res.session_mode;
|
|
39
49
|
return {
|
|
50
|
+
country: res.country,
|
|
40
51
|
merchantId: res.merchant_id,
|
|
41
52
|
sessionId: res.session_id,
|
|
42
53
|
status: res.status,
|
|
43
54
|
transAmount: amountMap(res.trans_amount),
|
|
44
55
|
expireTime: res.expire_time,
|
|
45
|
-
sessionMode
|
|
56
|
+
sessionMode,
|
|
46
57
|
merchantName: (_a = res.theme) == null ? void 0 : _a.merchant_name,
|
|
47
58
|
returnUrl: res.return_url,
|
|
59
|
+
cancelUrl: res.cancel_url,
|
|
48
60
|
locale: res.locale,
|
|
49
61
|
paymentType: res.payment_type,
|
|
50
62
|
goods: res.goods ? res.goods : [],
|
|
@@ -60,7 +72,8 @@ function checkoutMap(res = {}) {
|
|
|
60
72
|
addressLine1: bill == null ? void 0 : bill.address_line1,
|
|
61
73
|
addressLine2: bill == null ? void 0 : bill.address_line2,
|
|
62
74
|
email: bill == null ? void 0 : bill.email,
|
|
63
|
-
descriptor: bill == null ? void 0 : bill.descriptor
|
|
75
|
+
descriptor: bill == null ? void 0 : bill.descriptor,
|
|
76
|
+
country: bill == null ? void 0 : bill.country
|
|
64
77
|
},
|
|
65
78
|
tokens: (_b = res.tokens) == null ? void 0 : _b.map((card) => ({
|
|
66
79
|
token: card.token,
|
|
@@ -69,6 +82,21 @@ function checkoutMap(res = {}) {
|
|
|
69
82
|
billingAddressFilled: card.billing_address_filled
|
|
70
83
|
})),
|
|
71
84
|
storePaymentMethod: (_c = res.payment) == null ? void 0 : _c.store_payment_method,
|
|
85
|
+
field: {
|
|
86
|
+
holderName: {
|
|
87
|
+
show: !!(field == null ? void 0 : field.holder_name_display),
|
|
88
|
+
required: !!(field == null ? void 0 : field.holder_name_required)
|
|
89
|
+
},
|
|
90
|
+
email: {
|
|
91
|
+
show: !!(field == null ? void 0 : field.bill_email_display),
|
|
92
|
+
required: !!(field == null ? void 0 : field.bill_email_required)
|
|
93
|
+
},
|
|
94
|
+
address: {
|
|
95
|
+
show: !!(field == null ? void 0 : field.bill_address_display),
|
|
96
|
+
required: !!(field == null ? void 0 : field.bill_address_required)
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
amountBreakdown: formatAmountBreakdown(res.amount_breakdown),
|
|
72
100
|
...paymentMethodsInfo
|
|
73
101
|
};
|
|
74
102
|
}
|
|
@@ -2,9 +2,6 @@ import { u } from "../../core.js";
|
|
|
2
2
|
import "../../utils/card-brand/brands.js";
|
|
3
3
|
import "../../utils/system-info/get-browser-info.js";
|
|
4
4
|
import { useI18n } from "../../hooks/useI18n.js";
|
|
5
|
-
import "../../core/context.js";
|
|
6
|
-
import "../../i18n/util.js";
|
|
7
|
-
import "../../i18n/locales/index.js";
|
|
8
5
|
import "../internal/Form/type.js";
|
|
9
6
|
import "../internal/Form/context.js";
|
|
10
7
|
import { FormItem } from "../internal/Form/FormItem.js";
|
|
@@ -4,12 +4,9 @@ import { EAddressType } from "../../constant.js";
|
|
|
4
4
|
import { createAddressCore } from "../../core/Address.js";
|
|
5
5
|
import { useBEM } from "../../hooks/useBEM.js";
|
|
6
6
|
import { useI18n } from "../../hooks/useI18n.js";
|
|
7
|
-
import "../../core/context.js";
|
|
8
7
|
import { isArray, isNil } from "../../utils/is.js";
|
|
9
8
|
import "../../utils/card-brand/brands.js";
|
|
10
9
|
import "../../utils/system-info/get-browser-info.js";
|
|
11
|
-
import "../../i18n/util.js";
|
|
12
|
-
import "../../i18n/locales/index.js";
|
|
13
10
|
import "../internal/Form/type.js";
|
|
14
11
|
import "../internal/Form/context.js";
|
|
15
12
|
import { FormItem } from "../internal/Form/FormItem.js";
|
|
@@ -107,10 +104,8 @@ const AddressField = w((props, ref) => {
|
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
106
|
async function getDefaultCountry() {
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
const countryCode = (areaCode == null ? void 0 : areaCode[1]) ?? "US";
|
|
113
|
-
onSelectCountry(countryCode);
|
|
107
|
+
const countryCode = props.country;
|
|
108
|
+
onSelectCountry(countryCode || "");
|
|
114
109
|
onAddressChange({
|
|
115
110
|
country: addressState.country ?? "",
|
|
116
111
|
province: addressState.province ?? "",
|
|
@@ -4,11 +4,10 @@ import { getAliPayInfo, aliPay } from "../../api/modules/ali-pay/index.js";
|
|
|
4
4
|
import { isUndefined } from "../../utils/is.js";
|
|
5
5
|
import "../../utils/card-brand/brands.js";
|
|
6
6
|
import "../../utils/system-info/get-browser-info.js";
|
|
7
|
-
import { formatAmount } from "../../utils/format.js";
|
|
8
|
-
import { PaymentType } from "../../constant.js";
|
|
7
|
+
import { cssVarPrefix, normalizedClass, formatAmount } from "../../utils/format.js";
|
|
8
|
+
import { COMMON_CLASS_NAME, PaymentType } from "../../constant.js";
|
|
9
9
|
import { CoreContext } from "../../core/context.js";
|
|
10
|
-
import "../../
|
|
11
|
-
import "../../i18n/locales/index.js";
|
|
10
|
+
import { PayKKaError } from "../../core/error.js";
|
|
12
11
|
import { createAddressCore } from "../../core/Address.js";
|
|
13
12
|
import { useBEM } from "../../hooks/useBEM.js";
|
|
14
13
|
import { usePayState } from "../../hooks/usePayState.js";
|
|
@@ -24,9 +23,11 @@ import { RecurringTip } from "../RecurringTip/index.js";
|
|
|
24
23
|
import { SubmitButton } from "../SubmitButton/index.js";
|
|
25
24
|
const { bem } = useBEM("ali-pay");
|
|
26
25
|
const AliPay = w((props, ref) => {
|
|
26
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
27
|
+
const { session } = props;
|
|
27
28
|
let addressState = createAddressCore();
|
|
28
29
|
let emailState = createEmailCore();
|
|
29
|
-
const { setErrorMsg, i18n,
|
|
30
|
+
const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session);
|
|
30
31
|
const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
|
|
31
32
|
const formRef = A(null);
|
|
32
33
|
const [form, setForm] = h({
|
|
@@ -56,19 +57,19 @@ const AliPay = w((props, ref) => {
|
|
|
56
57
|
startReFetchPayInfo({ timeout });
|
|
57
58
|
},
|
|
58
59
|
updateAddress: () => {
|
|
59
|
-
var
|
|
60
|
+
var _a2;
|
|
60
61
|
setForm(Object.assign(form, { address: addressState.getAddressState() }));
|
|
61
|
-
(
|
|
62
|
+
(_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
|
|
62
63
|
},
|
|
63
64
|
updateEmail: () => {
|
|
64
|
-
var
|
|
65
|
+
var _a2;
|
|
65
66
|
setForm(Object.assign(form, { email: emailState.email }));
|
|
66
|
-
(
|
|
67
|
+
(_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
|
|
67
68
|
}
|
|
68
69
|
}));
|
|
69
70
|
function validateForm() {
|
|
70
|
-
var
|
|
71
|
-
(
|
|
71
|
+
var _a2;
|
|
72
|
+
(_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
|
|
72
73
|
setValidated(true);
|
|
73
74
|
}).catch(() => {
|
|
74
75
|
setValidated(false);
|
|
@@ -78,11 +79,11 @@ const AliPay = w((props, ref) => {
|
|
|
78
79
|
validateForm();
|
|
79
80
|
}, [form]);
|
|
80
81
|
y(() => {
|
|
81
|
-
var
|
|
82
|
+
var _a2;
|
|
82
83
|
if (sessionReady) {
|
|
83
84
|
if ((session == null ? void 0 : session.checkout.status) === "SUCCESS") {
|
|
84
85
|
setSubmitButtonStatus("success");
|
|
85
|
-
(
|
|
86
|
+
(_a2 = props.onSuccess) == null ? void 0 : _a2.call(props);
|
|
86
87
|
}
|
|
87
88
|
form.email = (session == null ? void 0 : session.checkout.bill.email) ?? "";
|
|
88
89
|
disabledEmail.current = !!(session == null ? void 0 : session.checkout.bill.email);
|
|
@@ -93,10 +94,10 @@ const AliPay = w((props, ref) => {
|
|
|
93
94
|
}
|
|
94
95
|
}, [sessionReady]);
|
|
95
96
|
const onTimeout = q((message) => {
|
|
96
|
-
var
|
|
97
|
+
var _a2;
|
|
97
98
|
setErrorMsg(message || i18n.get("common.payTimeout"));
|
|
98
99
|
setSubmitButtonStatus("unSubmit");
|
|
99
|
-
(
|
|
100
|
+
(_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
|
|
100
101
|
}, [i18n, props.onTimeout]);
|
|
101
102
|
const { start: startReFetchPayInfo, stop: stopReFetchPayInfo } = useRetry(
|
|
102
103
|
(timeout) => pay(true, timeout),
|
|
@@ -105,7 +106,7 @@ const AliPay = w((props, ref) => {
|
|
|
105
106
|
}
|
|
106
107
|
);
|
|
107
108
|
async function pay(search = false, timeout) {
|
|
108
|
-
var
|
|
109
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
109
110
|
try {
|
|
110
111
|
const res = search ? await getAliPayInfo(
|
|
111
112
|
{
|
|
@@ -131,21 +132,21 @@ const AliPay = w((props, ref) => {
|
|
|
131
132
|
},
|
|
132
133
|
{ locale: i18n.locale, timeout }
|
|
133
134
|
);
|
|
134
|
-
const { status, orderStatus, errorMessage } = res;
|
|
135
|
-
!search && ((
|
|
135
|
+
const { status, orderStatus, errorMessage, errorCode } = res;
|
|
136
|
+
!search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
|
|
136
137
|
if (status === "PROCESSING") {
|
|
137
138
|
if (!orderStatus) {
|
|
138
139
|
setSubmitButtonStatus("unSubmit");
|
|
139
140
|
} else if (orderStatus === "SUCCESS") {
|
|
140
141
|
setSubmitButtonStatus("success");
|
|
141
|
-
(
|
|
142
|
+
(_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
|
|
142
143
|
return {
|
|
143
144
|
end: true
|
|
144
145
|
};
|
|
145
146
|
} else if (orderStatus === "FAILURE") {
|
|
146
147
|
setErrorMsg(errorMessage);
|
|
147
148
|
setSubmitButtonStatus("unSubmit");
|
|
148
|
-
(
|
|
149
|
+
(_c2 = props.onError) == null ? void 0 : _c2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
|
|
149
150
|
return {
|
|
150
151
|
end: true
|
|
151
152
|
};
|
|
@@ -156,26 +157,26 @@ const AliPay = w((props, ref) => {
|
|
|
156
157
|
};
|
|
157
158
|
} else if (orderStatus === "CANCELED") {
|
|
158
159
|
setSubmitButtonStatus("unSubmit");
|
|
159
|
-
(
|
|
160
|
+
(_d2 = props.onTimeout) == null ? void 0 : _d2.call(props, "channel");
|
|
160
161
|
return {
|
|
161
162
|
end: true
|
|
162
163
|
};
|
|
163
164
|
}
|
|
164
165
|
} else if (status === "SUCCESS") {
|
|
165
166
|
setSubmitButtonStatus("success");
|
|
166
|
-
(
|
|
167
|
+
(_e2 = props.onSuccess) == null ? void 0 : _e2.call(props);
|
|
167
168
|
return {
|
|
168
169
|
end: true
|
|
169
170
|
};
|
|
170
171
|
} else if (status === "EXPIRED") {
|
|
171
172
|
setSubmitButtonStatus("unSubmit");
|
|
172
|
-
(
|
|
173
|
+
(_f2 = props.onExpired) == null ? void 0 : _f2.call(props);
|
|
173
174
|
return {
|
|
174
175
|
end: true
|
|
175
176
|
};
|
|
176
177
|
}
|
|
177
178
|
setSubmitButtonStatus("unSubmit");
|
|
178
|
-
(
|
|
179
|
+
(_g2 = props.onSuccess) == null ? void 0 : _g2.call(props);
|
|
179
180
|
return {
|
|
180
181
|
end: true
|
|
181
182
|
};
|
|
@@ -188,20 +189,21 @@ const AliPay = w((props, ref) => {
|
|
|
188
189
|
return { end: true };
|
|
189
190
|
}
|
|
190
191
|
} else {
|
|
191
|
-
|
|
192
|
-
(
|
|
192
|
+
const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
|
|
193
|
+
setErrorMsg(message);
|
|
194
|
+
(_h2 = props.onError) == null ? void 0 : _h2.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
|
|
193
195
|
setSubmitButtonStatus("unSubmit");
|
|
194
196
|
return { end: true };
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
}
|
|
198
200
|
async function onSubmit() {
|
|
199
|
-
var
|
|
201
|
+
var _a2;
|
|
200
202
|
setErrorMsg("");
|
|
201
|
-
(
|
|
202
|
-
var
|
|
203
|
+
(_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
|
|
204
|
+
var _a3;
|
|
203
205
|
requiredBill && addressState.setValidateAllFields(true);
|
|
204
|
-
(
|
|
206
|
+
(_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
|
|
205
207
|
if (errors) {
|
|
206
208
|
setSubmitButtonStatus("unSubmit");
|
|
207
209
|
return;
|
|
@@ -214,9 +216,10 @@ const AliPay = w((props, ref) => {
|
|
|
214
216
|
const Button = () => {
|
|
215
217
|
const { transAmount } = (session == null ? void 0 : session.checkout) ?? {};
|
|
216
218
|
let { symbol = "", amount = "", digits } = transAmount ?? {};
|
|
219
|
+
let amountStr = "";
|
|
217
220
|
if (amount && !isUndefined(digits))
|
|
218
|
-
|
|
219
|
-
const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${
|
|
221
|
+
amountStr = formatAmount(+amount, digits);
|
|
222
|
+
const text = i18n.get("common.pay") + (Number(amount) ? ` ${symbol}${amountStr}` : "");
|
|
220
223
|
return /* @__PURE__ */ u(
|
|
221
224
|
SubmitButton,
|
|
222
225
|
{
|
|
@@ -234,6 +237,13 @@ const AliPay = w((props, ref) => {
|
|
|
234
237
|
formRef.current = dom;
|
|
235
238
|
dom && validateForm();
|
|
236
239
|
};
|
|
240
|
+
const formStyle = {
|
|
241
|
+
[cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
|
|
242
|
+
[cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
|
|
243
|
+
[cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
|
|
244
|
+
[cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
|
|
245
|
+
[cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
|
|
246
|
+
};
|
|
237
247
|
return /* @__PURE__ */ u(
|
|
238
248
|
CoreContext.Provider,
|
|
239
249
|
{
|
|
@@ -241,7 +251,7 @@ const AliPay = w((props, ref) => {
|
|
|
241
251
|
i18n,
|
|
242
252
|
session
|
|
243
253
|
},
|
|
244
|
-
children: sessionReady && i18n.ready.value && /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: [
|
|
254
|
+
children: sessionReady && i18n.ready.value && /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), style: formStyle, children: [
|
|
245
255
|
/* @__PURE__ */ u(
|
|
246
256
|
EmailField,
|
|
247
257
|
{
|
|
@@ -256,13 +266,14 @@ const AliPay = w((props, ref) => {
|
|
|
256
266
|
{
|
|
257
267
|
ref: addressFieldRef,
|
|
258
268
|
value: form.address,
|
|
269
|
+
country: ((_g = session == null ? void 0 : session.checkout) == null ? void 0 : _g.country) || ((_h = session == null ? void 0 : session.checkout) == null ? void 0 : _h.bill.country),
|
|
259
270
|
onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
|
|
260
271
|
}
|
|
261
272
|
),
|
|
262
273
|
(session == null ? void 0 : session.checkout.paymentType) === PaymentType.RECURRING && RecurringTip(),
|
|
263
274
|
!!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
|
|
264
275
|
Button()
|
|
265
|
-
] })
|
|
276
|
+
] }) })
|
|
266
277
|
}
|
|
267
278
|
);
|
|
268
279
|
});
|
|
@@ -1,6 +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
|
+
import { SessionMode, PaymentMethod } from "../../constant.js";
|
|
4
4
|
import { getBrowserParams } from "../../api/modules/get-browser-params.js";
|
|
5
5
|
import { getApplePayInfo, applePay, getMerchantSession } from "../../api/modules/apple-pay/index.js";
|
|
6
6
|
import { useBEM } from "../../hooks/useBEM.js";
|
|
@@ -8,8 +8,7 @@ import "../../core/context.js";
|
|
|
8
8
|
import "../../utils/card-brand/brands.js";
|
|
9
9
|
import "../../utils/system-info/get-browser-info.js";
|
|
10
10
|
import { parseE164, underscoreToUpperCamelCase } from "../../utils/format.js";
|
|
11
|
-
import "../../
|
|
12
|
-
import "../../i18n/locales/index.js";
|
|
11
|
+
import { PayKKaError } from "../../core/error.js";
|
|
13
12
|
import { usePayState } from "../../hooks/usePayState.js";
|
|
14
13
|
import { useRetry } from "../../hooks/useRetry.js";
|
|
15
14
|
import { Info } from "../internal/Info/Info.js";
|
|
@@ -44,34 +43,41 @@ async function applePayEnv(id) {
|
|
|
44
43
|
}
|
|
45
44
|
const { bem } = useBEM("apple-pay");
|
|
46
45
|
const ApplePay = w((props) => {
|
|
46
|
+
const { session, isDropIn } = props;
|
|
47
47
|
let applePaySession;
|
|
48
|
-
const { i18n,
|
|
48
|
+
const { i18n, sessionReady, fraudDetection } = usePayState(session);
|
|
49
49
|
const [errorMsg, setErrorMsg] = h("");
|
|
50
50
|
const [showApplePay, setShowApplePay] = h(false);
|
|
51
51
|
const getPaymentSuccessData = () => ({
|
|
52
52
|
returnUrl: session == null ? void 0 : session.checkout.returnUrl
|
|
53
53
|
});
|
|
54
54
|
y(() => {
|
|
55
|
-
var _a;
|
|
55
|
+
var _a, _b, _c;
|
|
56
56
|
if (!sessionReady) {
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
-
const { status, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
|
|
59
|
+
const { status, paymentMethod = [], sessionMode } = (session == null ? void 0 : session.checkout) || {};
|
|
60
|
+
if (sessionMode === SessionMode.DROP_IN && !isDropIn) {
|
|
61
|
+
(_b = (_a = props.core.config).onInitError) == null ? void 0 : _b.call(
|
|
62
|
+
_a,
|
|
63
|
+
new PayKKaError("ERROR", "Please send the correct mode when creating the checkout")
|
|
64
|
+
);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
60
67
|
if (!paymentMethod.includes(PaymentMethod.APPLE_PAY)) {
|
|
61
68
|
return;
|
|
62
69
|
}
|
|
63
70
|
loadApplePayJS(
|
|
64
71
|
async () => {
|
|
65
|
-
var _a2,
|
|
72
|
+
var _a2, _b2, _c2, _d;
|
|
66
73
|
const envSupported = await applePayEnv(
|
|
67
|
-
(
|
|
74
|
+
(_c2 = (_b2 = (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.channelParams) == null ? void 0 : _b2.applePay) == null ? void 0 : _c2.merchantIdentifier
|
|
68
75
|
);
|
|
69
76
|
if (!envSupported) {
|
|
70
77
|
return;
|
|
71
78
|
}
|
|
72
79
|
setShowApplePay(true);
|
|
73
80
|
(_d = props.onLoad) == null ? void 0 : _d.call(props, true);
|
|
74
|
-
console.log((_e = ApplePaySession.canMakePayments) == null ? void 0 : _e.call(ApplePaySession));
|
|
75
81
|
},
|
|
76
82
|
() => {
|
|
77
83
|
var _a2;
|
|
@@ -80,7 +86,7 @@ const ApplePay = w((props) => {
|
|
|
80
86
|
}
|
|
81
87
|
);
|
|
82
88
|
if (status === "SUCCESS") {
|
|
83
|
-
(
|
|
89
|
+
(_c = props.onSuccess) == null ? void 0 : _c.call(props, getPaymentSuccessData());
|
|
84
90
|
}
|
|
85
91
|
}, [sessionReady]);
|
|
86
92
|
const onTimeout = q(
|
|
@@ -139,7 +145,7 @@ const ApplePay = w((props) => {
|
|
|
139
145
|
{ locale: i18n.locale }
|
|
140
146
|
);
|
|
141
147
|
}());
|
|
142
|
-
const { status, orderStatus, errorMessage } = res;
|
|
148
|
+
const { status, orderStatus, errorMessage, errorCode } = res;
|
|
143
149
|
if (status === "PROCESSING") {
|
|
144
150
|
if (orderStatus === "SUCCESS") {
|
|
145
151
|
applePaySession.completePayment({
|
|
@@ -156,7 +162,7 @@ const ApplePay = w((props) => {
|
|
|
156
162
|
};
|
|
157
163
|
} else if (orderStatus === "FAILURE") {
|
|
158
164
|
setErrorMsg(errorMessage);
|
|
159
|
-
(_b = props.onError) == null ? void 0 : _b.call(props, "
|
|
165
|
+
(_b = props.onError) == null ? void 0 : _b.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
|
|
160
166
|
applePaySession.completePayment({
|
|
161
167
|
status: 1,
|
|
162
168
|
errors: [new ApplePayError("unknown", void 0, errorMessage)]
|
|
@@ -211,7 +217,7 @@ const ApplePay = w((props) => {
|
|
|
211
217
|
} else {
|
|
212
218
|
const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
|
|
213
219
|
setErrorMsg(message);
|
|
214
|
-
(_g = props.onError) == null ? void 0 : _g.call(props, error);
|
|
220
|
+
(_g = props.onError) == null ? void 0 : _g.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
|
|
215
221
|
applePaySession.completePayment({
|
|
216
222
|
status: 1,
|
|
217
223
|
errors: [new ApplePayError("unknown", void 0, message)]
|