@paykka/card-checkout-ui 0.13.8 → 0.13.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/card-checkout-ui.js +20 -20
  2. package/dist/card-checkout-ui.umd.cjs +21 -21
  3. package/dist/es/_commonjsHelpers.js +1 -82
  4. package/dist/es/api/index.js +2 -1
  5. package/dist/es/api/modules/checkout/map.js +1 -0
  6. package/dist/es/api/modules/get-browser-params.js +20 -8
  7. package/dist/es/api/modules/index.js +2 -1
  8. package/dist/es/api/modules/map.js +2 -1
  9. package/dist/es/api/modules/risk/index.js +21 -18
  10. package/dist/es/api/modules/threeDS/index.js +2 -1
  11. package/dist/es/api/modules/vietqr/index.js +2 -1
  12. package/dist/es/api/utils/index.js +4 -1
  13. package/dist/es/components/AccordionItem/AccordionItem.js +0 -1
  14. package/dist/es/components/AccountNameField/index.js +1 -1
  15. package/dist/es/components/AddressField/index.js +1 -2
  16. package/dist/es/components/AliPay/index.js +4 -2
  17. package/dist/es/components/ApplePay/index.js +201 -135
  18. package/dist/es/components/Boost/index.js +4 -2
  19. package/dist/es/components/CPFField/index.js +88 -0
  20. package/dist/es/components/Card/index.js +5 -11
  21. package/dist/es/components/CardBrands/index.js +0 -1
  22. package/dist/es/components/CardExpireDateField/index.js +1 -1
  23. package/dist/es/components/CardHolderNameField/index.js +1 -1
  24. package/dist/es/components/CardIBANField/index.js +1 -1
  25. package/dist/es/components/CardNo/index.js +0 -1
  26. package/dist/es/components/CardNumberField/index.js +1 -1
  27. package/dist/es/components/CardSecurityCodeField/index.js +1 -1
  28. package/dist/es/components/CardSelector/index.js +1 -1
  29. package/dist/es/components/CombinedCardInfo/index.js +1 -1
  30. package/dist/es/components/DropIn/index.js +0 -1
  31. package/dist/es/components/EmailField/EmailField.js +1 -1
  32. package/dist/es/components/EncryptedCard/index.js +12 -11
  33. package/dist/es/components/GooglePay/index.js +1 -0
  34. package/dist/es/components/GrabPay/index.js +4 -2
  35. package/dist/es/components/GuideCard/index.js +1 -1
  36. package/dist/es/components/LinePay/index.js +4 -2
  37. package/dist/es/components/MayBankQRPay/index.js +4 -2
  38. package/dist/es/components/NinePay/index.js +4 -2
  39. package/dist/es/components/RecurringTip/index.js +1 -2
  40. package/dist/es/components/SecuredFieldsProvider/index.js +20 -3
  41. package/dist/es/components/SecuredIframe/index.js +50 -22
  42. package/dist/es/components/Sepa/index.js +4 -2
  43. package/dist/es/components/ShopeePay/index.js +4 -2
  44. package/dist/es/components/SubmitButton/index.js +1 -1
  45. package/dist/es/components/TNGWallet/index.js +4 -2
  46. package/dist/es/components/ThreeDS/index.js +1 -2
  47. package/dist/es/components/Tip/index.js +18 -0
  48. package/dist/es/components/WechatPay/index.js +4 -2
  49. package/dist/es/components/business/QRCodeModal/QRCodeModal.js +1 -1
  50. package/dist/es/components/business/QRCodeModal/index.js +0 -1
  51. package/dist/es/components/business/index.js +0 -1
  52. package/dist/es/components/index.js +0 -1
  53. package/dist/es/components/internal/Accordion/index.js +0 -1
  54. package/dist/es/components/internal/Button/Button.js +0 -1
  55. package/dist/es/components/internal/Button/index.js +0 -1
  56. package/dist/es/components/internal/CheckBox/CheckBox.js +0 -1
  57. package/dist/es/components/internal/CheckBox/index.js +0 -1
  58. package/dist/es/components/internal/Form/type.js +0 -1
  59. package/dist/es/components/internal/Info/Info.js +0 -1
  60. package/dist/es/components/internal/Info/index.js +0 -1
  61. package/dist/es/components/internal/Input/Input.js +1 -1
  62. package/dist/es/components/internal/Input/type.js +0 -1
  63. package/dist/es/components/internal/LoadingCheck/LoadingCheck.js +0 -1
  64. package/dist/es/components/internal/LoadingCheck/index.js +0 -1
  65. package/dist/es/components/internal/Modal/Modal.js +1 -1
  66. package/dist/es/components/internal/QRCode/QRCode.js +0 -1
  67. package/dist/es/components/internal/QRCode/index.js +0 -1
  68. package/dist/es/components/internal/Select/Select.js +14 -17
  69. package/dist/es/components/internal/Select/SelectMenu.js +2 -3
  70. package/dist/es/components/internal/Select/SelectMenuItem.js +0 -1
  71. package/dist/es/components/wallets/GCash/GCash.js +4 -2
  72. package/dist/es/components/wallets/OpayWallet/OpayWallet.js +8 -9
  73. package/dist/es/components/wallets/PagaWallet/PagaWallet.js +8 -9
  74. package/dist/es/components/wallets/Paymaya/Paymaya.js +4 -2
  75. package/dist/es/components/wallets/PicPay/PicPay.js +136 -72
  76. package/dist/es/components/wallets/Pix/Pix.js +136 -72
  77. package/dist/es/components/wallets/Vietqr/Vietqr.js +4 -2
  78. package/dist/es/components/wallets/Zalopay/Zalopay.js +4 -2
  79. package/dist/es/config.js +1 -1
  80. package/dist/es/constant.js +2 -0
  81. package/dist/es/core/checkout.js +15 -3
  82. package/dist/es/core/environment.js +10 -2
  83. package/dist/es/core/index.js +0 -1
  84. package/dist/es/core/query.js +2 -1
  85. package/dist/es/core/session.js +6 -2
  86. package/dist/es/core/theme.js +0 -1
  87. package/dist/es/core.js +585 -4
  88. package/dist/es/hooks/index.js +0 -1
  89. package/dist/es/hooks/useI18n.js +0 -1
  90. package/dist/es/hooks/usePayState.js +13 -6
  91. package/dist/es/i18n/locales/de-DE.js +6 -1
  92. package/dist/es/i18n/locales/en-GB.js +6 -1
  93. package/dist/es/i18n/locales/es-ES.js +6 -1
  94. package/dist/es/i18n/locales/fr-FR.js +7 -2
  95. package/dist/es/i18n/locales/ja-JP.js +6 -1
  96. package/dist/es/i18n/locales/ko-KR.js +6 -1
  97. package/dist/es/i18n/locales/nl-NL.js +6 -1
  98. package/dist/es/i18n/locales/pt-PT.js +6 -1
  99. package/dist/es/i18n/locales/ru-RU.js +6 -1
  100. package/dist/es/i18n/locales/zh-CN.js +6 -1
  101. package/dist/es/i18n/locales/zh-HK.js +7 -2
  102. package/dist/es/i18n/locales/zh-TW.js +7 -2
  103. package/dist/es/index.js +6 -3
  104. package/dist/es/out/base-fraud-detection.js +134 -0
  105. package/dist/es/out/config.js +16 -0
  106. package/dist/es/out/fraud-detection.js +118 -27
  107. package/dist/es/out/paykka-detection.js +63 -0
  108. package/dist/es/out/stripe-radar.js +25 -51
  109. package/dist/es/out/worldpay-ddc.js +52 -99
  110. package/dist/es/out/worldpay-jsc-origin.js +0 -1
  111. package/dist/es/out/worldpay-jsc.js +21 -43
  112. package/dist/es/style.css +1 -1
  113. package/dist/es/types/event.js +33 -13
  114. package/dist/es/types/index.js +14 -0
  115. package/dist/es/utils/cpf.js +48 -0
  116. package/dist/es/utils/encrypt.js +18 -0
  117. package/dist/es/utils/iframe.js +1 -1
  118. package/dist/es/utils/location.js +4 -2
  119. package/dist/es/utils/redirect.js +8 -5
  120. package/dist/es/utils/system-info/index.js +1 -3
  121. package/dist/style.css +1 -1
  122. package/dist/types/api/modules/checkout/type.d.ts +2 -0
  123. package/dist/types/api/modules/get-browser-params.d.ts +25 -1
  124. package/dist/types/api/modules/risk/index.d.ts +28 -12
  125. package/dist/types/api/modules/type.d.ts +5 -0
  126. package/dist/types/api/utils/index.d.ts +3 -0
  127. package/dist/types/components/ApplePay/config.d.ts +9 -0
  128. package/dist/types/components/ApplePay/hooks/useApplePay.d.ts +15 -0
  129. package/dist/types/components/ApplePay/type.d.ts +53 -10
  130. package/dist/types/components/ApplePay/utils.d.ts +8 -2
  131. package/dist/types/components/CPFField/CPFField.d.ts +4 -0
  132. package/dist/types/components/CPFField/index.d.ts +2 -0
  133. package/dist/types/components/CPFField/type.d.ts +21 -0
  134. package/dist/types/components/SecuredFieldsProvider/type.d.ts +8 -3
  135. package/dist/types/components/SecuredIframe/useSecuredInput.d.ts +2 -5
  136. package/dist/types/components/ThreeDS/components/ThreeDSIframe/ThreeDSIframe.d.ts +6 -0
  137. package/dist/types/components/Tip/Tip.d.ts +3 -0
  138. package/dist/types/components/Tip/index.d.ts +2 -0
  139. package/dist/types/components/Tip/type.d.ts +12 -0
  140. package/dist/types/constant.d.ts +3 -1
  141. package/dist/types/core/checkout.d.ts +1 -1
  142. package/dist/types/core/environment.d.ts +12 -0
  143. package/dist/types/core/session.d.ts +1 -0
  144. package/dist/types/i18n/locales/de-DE.d.ts +4 -0
  145. package/dist/types/i18n/locales/en-GB.d.ts +4 -0
  146. package/dist/types/i18n/locales/es-ES.d.ts +4 -0
  147. package/dist/types/i18n/locales/fr-FR.d.ts +4 -0
  148. package/dist/types/i18n/locales/ja-JP.d.ts +4 -0
  149. package/dist/types/i18n/locales/ko-KR.d.ts +4 -0
  150. package/dist/types/i18n/locales/nl-NL.d.ts +4 -0
  151. package/dist/types/i18n/locales/pt-PT.d.ts +4 -0
  152. package/dist/types/i18n/locales/ru-RU.d.ts +4 -0
  153. package/dist/types/i18n/locales/zh-CN.d.ts +4 -0
  154. package/dist/types/i18n/locales/zh-HK.d.ts +4 -0
  155. package/dist/types/i18n/locales/zh-TW.d.ts +4 -0
  156. package/dist/types/out/base-fraud-detection.d.ts +53 -0
  157. package/dist/types/out/config.d.ts +11 -0
  158. package/dist/types/out/fraud-detection.d.ts +14 -3
  159. package/dist/types/out/paykka-detection.d.ts +20 -0
  160. package/dist/types/out/stripe-radar.d.ts +7 -9
  161. package/dist/types/out/types.d.ts +8 -2
  162. package/dist/types/out/worldpay-ddc.d.ts +7 -19
  163. package/dist/types/out/worldpay-jsc.d.ts +8 -18
  164. package/dist/types/types/event.d.ts +86 -39
  165. package/dist/types/types/fraud-detection.d.ts +1 -1
  166. package/dist/types/types/index.d.ts +22 -2
  167. package/dist/types/types/message.d.ts +12 -12
  168. package/dist/types/utils/app-payment.d.ts +2 -0
  169. package/dist/types/utils/cpf.d.ts +32 -0
  170. package/dist/types/utils/encrypt.d.ts +9 -0
  171. package/dist/types/utils/location.d.ts +1 -0
  172. package/dist/types/utils/system-info/index.d.ts +0 -1
  173. package/package.json +5 -4
  174. package/dist/types/components/ThreeDS/components/ThreeDSStatus/ThreeDSStatus.d.ts +0 -3
  175. package/dist/types/components/ThreeDS/components/ThreeDSStatus/type.d.ts +0 -6
@@ -1,8 +1,9 @@
1
- import { w, h, y, q, u, b } from "../../core.js";
1
+ import { A, w, h, y, q, u, b } from "../../core.js";
2
2
  import { isTimeoutError } from "../../api/http.js";
3
3
  import "../../utils/card-brand/brands.js";
4
4
  import "../../utils/system-info/get-browser-info.js";
5
5
  import { parseE164, underscoreToUpperCamelCase } from "../../utils/format.js";
6
+ import { PaymentStatus } from "../../types/index.js";
6
7
  import { deepMerge } from "../../utils/object.js";
7
8
  import { formatPaymentResult } from "../../utils/payment.js";
8
9
  import { getBrowserParams } from "../../api/modules/get-browser-params.js";
@@ -11,40 +12,12 @@ import { getApplePayInfo, applePay, getMerchantSession } from "../../api/modules
11
12
  import { useBEM } from "../../hooks/useBEM.js";
12
13
  import "../../core/context.js";
13
14
  import { PayKKaError } from "../../core/error.js";
15
+ import { ApplePayEventType } from "../../types/event.js";
14
16
  import "../../out/worldpay-jsc-origin.js";
15
17
  import { usePayState } from "../../hooks/usePayState.js";
16
18
  import { useRetry } from "../../hooks/useRetry.js";
17
19
  import { Info } from "../internal/Info/Info.js";
18
20
  import { loadScript } from "../../utils/load.js";
19
- const loadApplePayJS = (onload, onerror) => {
20
- loadScript({
21
- src: "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js",
22
- onload,
23
- onerror,
24
- extraOptions: {
25
- async: true,
26
- crossOrigin: ""
27
- }
28
- });
29
- };
30
- async function applePayEnv(id) {
31
- var _a, _b;
32
- if (!id || !ApplePaySession)
33
- return false;
34
- if (!((_a = ApplePaySession.canMakePayments) == null ? void 0 : _a.call(ApplePaySession))) {
35
- return false;
36
- }
37
- const capabilities = await ((_b = ApplePaySession.applePayCapabilities) == null ? void 0 : _b.call(ApplePaySession, id));
38
- if ([
39
- "paymentCredentialsAvailable",
40
- "paymentCredentialStatusUnknown",
41
- "paymentCredentialsUnavailable"
42
- ].includes(capabilities.paymentCredentialStatus)) {
43
- return true;
44
- }
45
- return false;
46
- }
47
- const { bem } = useBEM("apple-pay");
48
21
  const DEFAULT_APPLE_PAY_CONFIG = {
49
22
  request: {
50
23
  requiredBillingContactFields: ["name", "email"],
@@ -55,32 +28,116 @@ const DEFAULT_APPLE_PAY_CONFIG = {
55
28
  buttonType: "plain"
56
29
  }
57
30
  };
31
+ const APPLE_SDK_URL = "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js";
32
+ const APPLE_PAY_CAPABILITIES = [
33
+ /** 付款凭证可用 */
34
+ "paymentCredentialsAvailable",
35
+ /** 付款凭证状态未知 */
36
+ "paymentCredentialStatusUnknown",
37
+ /** 付款凭证不可用 */
38
+ "paymentCredentialsUnavailable"
39
+ ];
40
+ const APPLE_PAY_VERSION = 3;
41
+ const isApplePaySDKAvailable = () => {
42
+ const ua = navigator.userAgent;
43
+ if (/Safari/.test(ua) && !/Chrome|Chromium|Edg|OPR|Android/.test(ua)) {
44
+ const match = ua.match(/Version\/(\d+\.\d+)/);
45
+ if (match) {
46
+ const version = parseFloat(match[1]);
47
+ return version >= 15;
48
+ }
49
+ return false;
50
+ }
51
+ if (/iPhone|iPad|iPod/.test(ua)) {
52
+ const iosMatch = ua.match(/OS (\d+)_(\d+)/);
53
+ if (iosMatch) {
54
+ const major = parseInt(iosMatch[1], 10);
55
+ return major >= 15;
56
+ }
57
+ return false;
58
+ }
59
+ return true;
60
+ };
61
+ const loadApplePayJS = (onload, onerror) => {
62
+ if (isApplePaySDKAvailable()) {
63
+ loadScript({
64
+ src: APPLE_SDK_URL,
65
+ onload,
66
+ onerror,
67
+ extraOptions: {
68
+ async: true,
69
+ crossOrigin: ""
70
+ }
71
+ });
72
+ } else {
73
+ onload == null ? void 0 : onload();
74
+ }
75
+ };
76
+ const getApplePayEnvSupported = async (id) => {
77
+ var _a, _b;
78
+ if (!id || !window.ApplePaySession)
79
+ return false;
80
+ if (!((_a = ApplePaySession.canMakePayments) == null ? void 0 : _a.call(ApplePaySession))) {
81
+ return false;
82
+ }
83
+ if (ApplePaySession.applePayCapabilities) {
84
+ const capabilities = await ((_b = ApplePaySession.applePayCapabilities) == null ? void 0 : _b.call(ApplePaySession, id));
85
+ return APPLE_PAY_CAPABILITIES.includes(capabilities.paymentCredentialStatus);
86
+ } else {
87
+ return !!ApplePaySession.canMakePaymentsWithActiveCard;
88
+ }
89
+ };
90
+ const useApplePaySession = () => {
91
+ const applePaySession = A(null);
92
+ const initApplePaySession = (options) => {
93
+ applePaySession.current = new ApplePaySession(APPLE_PAY_VERSION, options.request);
94
+ applePaySession.current.onvalidatemerchant = options.onValidate;
95
+ applePaySession.current.onpaymentauthorized = options.onAuthorized;
96
+ applePaySession.current.oncancel = options.onCancel;
97
+ };
98
+ const reportSuccess2ApplePay = () => {
99
+ var _a;
100
+ (_a = applePaySession.current) == null ? void 0 : _a.completePayment({ status: ApplePaySession.STATUS_SUCCESS ?? 0 });
101
+ };
102
+ const reportFailure2ApplePay = (errorMessage) => {
103
+ var _a;
104
+ (_a = applePaySession.current) == null ? void 0 : _a.completePayment({
105
+ status: ApplePaySession.STATUS_FAILURE ?? 1,
106
+ errors: [new ApplePayError("unknown", void 0, errorMessage)]
107
+ });
108
+ };
109
+ return {
110
+ applePaySession,
111
+ initApplePaySession,
112
+ reportSuccess2ApplePay,
113
+ reportFailure2ApplePay
114
+ };
115
+ };
116
+ const { bem } = useBEM("apple-pay");
58
117
  const ApplePay = w((props) => {
59
118
  const { session, isDropIn, core, config } = props;
60
- let applePaySession;
119
+ const { applePaySession, initApplePaySession, reportSuccess2ApplePay, reportFailure2ApplePay } = useApplePaySession();
61
120
  const { i18n, sessionReady, fraudDetection } = usePayState(session, props.core);
62
121
  const [errorMsg, setErrorMsg] = h("");
63
122
  const [showApplePay, setShowApplePay] = h(false);
64
123
  const applePayConfig = deepMerge(DEFAULT_APPLE_PAY_CONFIG, config || {});
124
+ const canUseApplePaySDK = isApplePaySDKAvailable();
65
125
  const processOnSuccess = (res) => {
66
126
  var _a, _b;
67
- (_b = props.onSuccess) == null ? void 0 : _b.call(
68
- props,
69
- formatPaymentResult({
70
- ...res,
71
- returnUrl: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.returnUrl
72
- })
73
- );
127
+ const result = formatPaymentResult({
128
+ ...res,
129
+ returnUrl: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.returnUrl
130
+ });
131
+ (_b = props.onSuccess) == null ? void 0 : _b.call(props, result);
74
132
  };
75
133
  y(() => {
76
- var _a, _b;
77
134
  if (!sessionReady) {
78
135
  return;
79
136
  }
80
- const { status, supportMethods = [], sessionMode } = (session == null ? void 0 : session.checkout) || {};
137
+ const { supportMethods = [], sessionMode } = (session == null ? void 0 : session.checkout) || {};
138
+ const { onEvent, onInitError } = props.core.config;
81
139
  if (sessionMode === SessionMode.DROP_IN && !isDropIn) {
82
- (_b = (_a = props.core.config).onInitError) == null ? void 0 : _b.call(
83
- _a,
140
+ onInitError == null ? void 0 : onInitError(
84
141
  new PayKKaError("ERROR", "Please send the correct session when creating the checkout")
85
142
  );
86
143
  return;
@@ -90,32 +147,30 @@ const ApplePay = w((props) => {
90
147
  }
91
148
  loadApplePayJS(
92
149
  async () => {
93
- var _a2, _b2, _c, _d, _e;
94
- (_a2 = props.onLoad) == null ? void 0 : _a2.call(props, true);
95
- const envSupported = await applePayEnv(
96
- (_d = (_c = (_b2 = session == null ? void 0 : session.checkout) == null ? void 0 : _b2.channelParams) == null ? void 0 : _c.applePay) == null ? void 0 : _d.merchantIdentifier
150
+ var _a, _b, _c, _d, _e;
151
+ (_a = props.onLoad) == null ? void 0 : _a.call(props, true);
152
+ const envSupported = await getApplePayEnvSupported(
153
+ (_d = (_c = (_b = session == null ? void 0 : session.checkout) == null ? void 0 : _b.channelParams) == null ? void 0 : _c.applePay) == null ? void 0 : _d.merchantIdentifier
97
154
  );
155
+ if (!envSupported) {
156
+ onEvent == null ? void 0 : onEvent(ApplePayEventType.APPLE_PAY_CAN_NOT_USE);
157
+ }
98
158
  (_e = props.onCanUse) == null ? void 0 : _e.call(props, envSupported);
99
159
  setShowApplePay(envSupported);
100
160
  },
101
161
  () => {
102
- var _a2;
162
+ var _a;
163
+ onEvent == null ? void 0 : onEvent(ApplePayEventType.APPLE_PAY_LOAD_ERROR);
164
+ (_a = props.onLoad) == null ? void 0 : _a.call(props, false);
103
165
  setShowApplePay(false);
104
- (_a2 = props.onLoad) == null ? void 0 : _a2.call(props, false);
105
166
  }
106
167
  );
107
- if (status === "SUCCESS") {
108
- processOnSuccess(session == null ? void 0 : session.checkout);
109
- }
110
168
  }, [sessionReady]);
111
169
  const onTimeout = q(
112
170
  (message) => {
113
171
  var _a;
114
172
  const timeoutMessage = message || i18n.get("common.payTimeout");
115
- applePaySession.completePayment({
116
- status: 1,
117
- errors: [new ApplePayError("unknown", void 0, timeoutMessage)]
118
- });
173
+ reportFailure2ApplePay(timeoutMessage);
119
174
  setErrorMsg(timeoutMessage);
120
175
  (_a = props.onTimeout) == null ? void 0 : _a.call(props, "retry");
121
176
  },
@@ -131,8 +186,8 @@ const ApplePay = w((props) => {
131
186
  sessionId: session.sessionId,
132
187
  clientKey: session.clientKey,
133
188
  bill: {
134
- firstName: billingContact == null ? void 0 : billingContact.familyName,
135
- lastName: billingContact == null ? void 0 : billingContact.givenName,
189
+ firstName: billingContact == null ? void 0 : billingContact.givenName,
190
+ lastName: billingContact == null ? void 0 : billingContact.familyName,
136
191
  addressLine1: (_a = billingContact == null ? void 0 : billingContact.addressLines) == null ? void 0 : _a[0],
137
192
  addressLine2: (_b = billingContact == null ? void 0 : billingContact.addressLines) == null ? void 0 : _b[1],
138
193
  state: billingContact == null ? void 0 : billingContact.administrativeArea,
@@ -153,7 +208,7 @@ const ApplePay = w((props) => {
153
208
  };
154
209
  };
155
210
  async function pay(search = false, timeout, token, billingContact, shippingContact) {
156
- var _a, _b, _c, _d, _e, _f, _g, _h;
211
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
157
212
  setErrorMsg("");
158
213
  try {
159
214
  const requestOptions = { locale: i18n.locale, timeout };
@@ -179,44 +234,39 @@ const ApplePay = w((props) => {
179
234
  }
180
235
  const { status, orderStatus, errorMessage, errorCode, sessionId } = res;
181
236
  sessionId && (session.sessionId = sessionId);
182
- if (status === "PROCESSING") {
183
- if (orderStatus === "SUCCESS") {
184
- applePaySession.completePayment({ status: 0 });
237
+ if (status === PaymentStatus.PROCESSING) {
238
+ if (orderStatus === PaymentStatus.SUCCESS) {
239
+ reportSuccess2ApplePay();
185
240
  processOnSuccess(res);
186
241
  return { end: true };
187
- } else if (orderStatus === "PROCESSING") {
242
+ } else if (orderStatus === PaymentStatus.PROCESSING) {
188
243
  !search && await startReFetchPayInfo();
189
244
  return { end: !search };
190
- } else if (orderStatus === "FAILURE") {
245
+ } else if (orderStatus === PaymentStatus.FAILURE) {
191
246
  errorMessage && setErrorMsg(errorMessage);
192
247
  (_e = props.onError) == null ? void 0 : _e.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
193
- applePaySession.completePayment({
194
- status: 1,
195
- errors: [new ApplePayError("unknown", void 0, errorMessage)]
196
- });
248
+ reportFailure2ApplePay(errorMessage);
197
249
  return { end: true };
198
- } else if (orderStatus === "AUTHORIZED") {
199
- applePaySession.completePayment({ status: 0 });
250
+ } else if (orderStatus === PaymentStatus.AUTHORIZED) {
251
+ reportSuccess2ApplePay();
200
252
  (_f = props.onAuthorized) == null ? void 0 : _f.call(props);
201
253
  return { end: true };
202
- } else if (!orderStatus) {
203
- applePaySession.completePayment({
204
- status: 1,
205
- errors: [new ApplePayError("unknown", void 0, "")]
206
- });
254
+ } else {
255
+ reportFailure2ApplePay();
207
256
  return { end: true };
208
257
  }
209
- } else if (status === "SUCCESS") {
258
+ } else if (status === PaymentStatus.SUCCESS) {
259
+ reportSuccess2ApplePay();
210
260
  processOnSuccess(res);
211
- applePaySession.completePayment({ status: 0 });
212
261
  return { end: true };
213
- } else if (status === "EXPIRED") {
262
+ } else if (status === PaymentStatus.EXPIRED) {
214
263
  (_g = props.onExpired) == null ? void 0 : _g.call(props);
215
- applePaySession.abort();
264
+ (_h = applePaySession.current) == null ? void 0 : _h.abort();
265
+ return { end: true };
266
+ } else {
267
+ reportFailure2ApplePay();
216
268
  return { end: true };
217
269
  }
218
- processOnSuccess(res);
219
- return { end: true };
220
270
  } catch (error) {
221
271
  if (isTimeoutError(error)) {
222
272
  if (search) {
@@ -228,88 +278,104 @@ const ApplePay = w((props) => {
228
278
  } else {
229
279
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
230
280
  message && setErrorMsg(message);
231
- (_h = props.onError) == null ? void 0 : _h.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
232
- applePaySession.completePayment({
233
- status: 1,
234
- errors: [new ApplePayError("unknown", void 0, message)]
235
- });
281
+ (_i = props.onError) == null ? void 0 : _i.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
282
+ reportFailure2ApplePay(message);
236
283
  return { end: true };
237
284
  }
238
285
  }
239
286
  }
240
- function onApplePayButtonClicked() {
241
- var _a, _b, _c, _d, _e, _f;
242
- (_a = props.onBtnClick) == null ? void 0 : _a.call(props);
243
- if (!ApplePaySession) {
244
- return;
245
- }
287
+ const genApplePayRequest = () => {
288
+ var _a, _b, _c, _d, _e;
246
289
  const checkout = session == null ? void 0 : session.checkout;
247
290
  const { applePay: applePay2 } = (checkout == null ? void 0 : checkout.channelParams) ?? {};
248
- const requiredBillingContactFields = ((_b = applePayConfig.request) == null ? void 0 : _b.requiredBillingContactFields) || [];
249
- if (((_c = checkout == null ? void 0 : checkout.bill) == null ? void 0 : _c.billingAddressCollection) === "REQUIRED") {
291
+ const requiredBillingContactFields = [
292
+ ...((_a = applePayConfig.request) == null ? void 0 : _a.requiredBillingContactFields) || []
293
+ ];
294
+ if (((_b = checkout == null ? void 0 : checkout.bill) == null ? void 0 : _b.billingAddressCollection) === "REQUIRED") {
250
295
  requiredBillingContactFields.push("postalAddress");
251
296
  }
252
- const request = {
297
+ return {
253
298
  merchantCapabilities: ["supports3DS"],
254
- // 固定
255
299
  countryCode: (applePay2 == null ? void 0 : applePay2.countryCode) ?? "",
256
- // 接口取:会员注册地址
257
300
  requiredBillingContactFields,
258
- // 接口取:required: "name", "postalAddress", "email"; 否则: "name", "email"
259
- requiredShippingContactFields: (_d = applePayConfig.request) == null ? void 0 : _d.requiredShippingContactFields,
301
+ requiredShippingContactFields: (_c = applePayConfig.request) == null ? void 0 : _c.requiredShippingContactFields,
260
302
  currencyCode: (checkout == null ? void 0 : checkout.transAmount.currency) ?? "",
261
- // 接口取
262
- supportedNetworks: ((_f = (_e = applePay2 == null ? void 0 : applePay2.supportedNetworks) == null ? void 0 : _e.map) == null ? void 0 : _f.call(_e, (item) => underscoreToUpperCamelCase(item))) ?? [],
263
- // 接口获取
303
+ supportedNetworks: ((_e = (_d = applePay2 == null ? void 0 : applePay2.supportedNetworks) == null ? void 0 : _d.map) == null ? void 0 : _e.call(_d, (item) => underscoreToUpperCamelCase(item))) ?? [],
264
304
  total: {
265
305
  label: (checkout == null ? void 0 : checkout.theme.merchantName) ?? "",
266
306
  type: "final",
267
- // 固定
268
307
  amount: String(checkout == null ? void 0 : checkout.transAmount.amount)
269
308
  }
270
309
  };
271
- applePaySession = new ApplePaySession(3, request);
272
- applePaySession.onvalidatemerchant = async () => {
273
- const merchantSession = await getMerchantSession();
274
- console.log("onvalidatemerchant");
275
- applePaySession.completeMerchantValidation(merchantSession);
276
- };
277
- applePaySession.onpaymentauthorized = async (event) => {
278
- var _a2;
279
- (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props);
280
- console.log("onpaymentauthorized");
281
- console.log("apple pay token: ", event.payment.token);
282
- console.log("apple pay shippingContact: ", event.payment.shippingContact);
283
- console.log("apple pay billingContact", event.payment.billingContact);
284
- pay(
285
- false,
286
- void 0,
287
- event.payment.token,
288
- event.payment.billingContact,
289
- event.payment.shippingContact
290
- );
291
- };
292
- applePaySession.oncancel = () => {
293
- var _a2;
294
- (_a2 = props.onCancel) == null ? void 0 : _a2.call(props);
295
- };
296
- applePaySession.begin();
297
- }
298
- const Button = () => {
310
+ };
311
+ const onApplePayButtonClicked = () => {
299
312
  var _a, _b;
300
- return /* @__PURE__ */ u("div", { className: bem("button"), children: /* @__PURE__ */ u(
313
+ const { onEvent } = props.core.config;
314
+ onEvent == null ? void 0 : onEvent(ApplePayEventType.APPLE_PAY_BUTTON_CLICKED);
315
+ (_a = props.onBtnClick) == null ? void 0 : _a.call(props);
316
+ if (!ApplePaySession) {
317
+ return;
318
+ }
319
+ const request = genApplePayRequest();
320
+ console.warn("ApplePay Request", request);
321
+ initApplePaySession({
322
+ request,
323
+ onValidate: async () => {
324
+ var _a2;
325
+ onEvent == null ? void 0 : onEvent(ApplePayEventType.APPLE_PAY_VALIDATE_MERCHANT);
326
+ const merchantSession = await getMerchantSession();
327
+ (_a2 = applePaySession.current) == null ? void 0 : _a2.completeMerchantValidation(merchantSession);
328
+ },
329
+ onAuthorized: async (event) => {
330
+ var _a2;
331
+ onEvent == null ? void 0 : onEvent(ApplePayEventType.APPLE_PAY_AUTHORIZED);
332
+ (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props);
333
+ const { token, billingContact, shippingContact } = (event == null ? void 0 : event.payment) || {};
334
+ console.warn("ApplePay Res", event == null ? void 0 : event.payment);
335
+ pay(false, void 0, token, billingContact, shippingContact);
336
+ },
337
+ onCancel: () => {
338
+ var _a2;
339
+ onEvent == null ? void 0 : onEvent(ApplePayEventType.APPLE_PAY_CANCELLED);
340
+ (_a2 = props.onCancel) == null ? void 0 : _a2.call(props);
341
+ }
342
+ });
343
+ (_b = applePaySession.current) == null ? void 0 : _b.begin();
344
+ };
345
+ const ApplePayButton = () => {
346
+ var _a, _b;
347
+ const buttonStyle = (_a = applePayConfig.button) == null ? void 0 : _a.buttonStyle;
348
+ const buttonType = (_b = applePayConfig.button) == null ? void 0 : _b.buttonType;
349
+ return /* @__PURE__ */ u("div", { className: bem("button"), children: canUseApplePaySDK ? /* @__PURE__ */ u(b, { children: /* @__PURE__ */ u(
301
350
  "apple-pay-button",
302
351
  {
303
- id: "apple-pay-button",
304
- buttonstyle: (_a = applePayConfig.button) == null ? void 0 : _a.buttonStyle,
305
- type: (_b = applePayConfig.button) == null ? void 0 : _b.buttonType,
352
+ buttonstyle: buttonStyle,
353
+ type: buttonType,
306
354
  onClick: onApplePayButtonClicked
307
355
  }
356
+ ) }) : /* @__PURE__ */ u(
357
+ "button",
358
+ {
359
+ onClick: onApplePayButtonClicked,
360
+ style: {
361
+ "-webkit-appearance": "-apple-pay-button",
362
+ // @ts-ignore
363
+ "-apple-pay-button-style": buttonStyle,
364
+ // @ts-ignore
365
+ "-apple-pay-button-type": buttonType,
366
+ width: "100%",
367
+ height: "44px",
368
+ minHeight: "44px",
369
+ border: "none",
370
+ borderRadius: "6px",
371
+ cursor: "pointer"
372
+ }
373
+ }
308
374
  ) });
309
375
  };
310
376
  return /* @__PURE__ */ u("div", { children: sessionReady && showApplePay && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
311
377
  !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
312
- Button()
378
+ /* @__PURE__ */ u(ApplePayButton, {})
313
379
  ] }) });
314
380
  });
315
381
  export {
@@ -72,7 +72,7 @@ const Boost = w((props, ref) => {
72
72
  const addressFieldRef = A(null);
73
73
  const emailFieldRef = A(null);
74
74
  const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
75
- const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session, props.core);
75
+ const { setErrorMsg, fraudDetection, i18n, errorMsg, sessionReady } = usePayState(session, props.core);
76
76
  const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
77
77
  const formRef = A(null);
78
78
  const [form, setForm] = h({
@@ -164,7 +164,9 @@ const Boost = w((props, ref) => {
164
164
  state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
165
165
  city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
166
166
  },
167
- browser: await getBrowserParams()
167
+ browser: await getBrowserParams({
168
+ fraudDetectionId: await (fraudDetection == null ? void 0 : fraudDetection.getFraudDetectionId())
169
+ })
168
170
  };
169
171
  };
170
172
  const pay = async (search = false, timeout) => {
@@ -0,0 +1,88 @@
1
+ import { w, A, h, F, u } from "../../core.js";
2
+ import { isUndefined } from "../../utils/is.js";
3
+ import "../../utils/card-brand/brands.js";
4
+ import "../../utils/system-info/get-browser-info.js";
5
+ import { EInternalFieldType } from "../SecuredFieldsProvider/index.js";
6
+ import { useI18n } from "../../hooks/useI18n.js";
7
+ import "../../core/context.js";
8
+ import "../../out/worldpay-jsc-origin.js";
9
+ import "../internal/Form/type.js";
10
+ import "../internal/Form/context.js";
11
+ import { FormItem } from "../internal/Form/FormItem.js";
12
+ import "../internal/Form/Form.js";
13
+ import { Input } from "../internal/Input/Input.js";
14
+ import "../internal/Input/type.js";
15
+ import { CNPJ_FULL_LENGTH, CPF_FULL_LENGTH, formatCPFOnInsert } from "../../utils/cpf.js";
16
+ const CPFField = w((props, ref) => {
17
+ const { className, style, security } = props;
18
+ const { i18n } = useI18n();
19
+ const inputRef = A(null);
20
+ const formItemRef = A(null);
21
+ const [value, setValue] = h("");
22
+ F(ref, () => ({
23
+ focus: () => {
24
+ var _a;
25
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
26
+ },
27
+ blur: () => {
28
+ var _a;
29
+ (_a = inputRef.current) == null ? void 0 : _a.blur();
30
+ },
31
+ resetValidation: (status, errorTip) => {
32
+ var _a;
33
+ (_a = formItemRef.current) == null ? void 0 : _a.resetValidation(status, [{ message: errorTip }]);
34
+ }
35
+ }));
36
+ const rule = {
37
+ trigger: ["blur", "submit"],
38
+ validator(value2) {
39
+ if (security) {
40
+ const result = formItemRef.current.getValidateResult();
41
+ if (result.status === "error") {
42
+ throw new Error(result.errors[0].message);
43
+ } else if (result.status === "success") {
44
+ return true;
45
+ }
46
+ }
47
+ if (isUndefined(value2) || ![CPF_FULL_LENGTH, CNPJ_FULL_LENGTH].includes(value2.length)) {
48
+ throw new Error(i18n.get("cpf.incomplete"));
49
+ }
50
+ return true;
51
+ }
52
+ };
53
+ const onInput = (event) => {
54
+ var _a;
55
+ const { currentTarget } = event;
56
+ const { value: val, cursorPosition } = formatCPFOnInsert(event);
57
+ setValue(currentTarget.value = val);
58
+ currentTarget.setSelectionRange(cursorPosition, cursorPosition);
59
+ (_a = props.onInput) == null ? void 0 : _a.call(props, event);
60
+ };
61
+ return /* @__PURE__ */ u(
62
+ FormItem,
63
+ {
64
+ label: i18n.get("cpf.label"),
65
+ path: "cpf",
66
+ ref: formItemRef,
67
+ rule,
68
+ className,
69
+ style,
70
+ children: /* @__PURE__ */ u(
71
+ Input,
72
+ {
73
+ type: "text",
74
+ inputmode: "numeric",
75
+ ref: inputRef,
76
+ maxLength: CNPJ_FULL_LENGTH,
77
+ value,
78
+ onInput,
79
+ placeholder: i18n.get("cpf.placeholder"),
80
+ children: security && /* @__PURE__ */ u("div", { style: "width:100%;height:100%", "data-sf": EInternalFieldType.CPF })
81
+ }
82
+ )
83
+ }
84
+ );
85
+ });
86
+ export {
87
+ CPFField
88
+ };
@@ -301,7 +301,7 @@ const Card = w((props, ref) => {
301
301
  };
302
302
  };
303
303
  async function pay(search = false, timeout) {
304
- var _a2, _b2, _c, _d, _e, _f;
304
+ var _a2, _b2, _c, _d, _e;
305
305
  try {
306
306
  const requestOptions = { locale: i18n.locale, timeout };
307
307
  let res = null;
@@ -335,10 +335,7 @@ const Card = w((props, ref) => {
335
335
  return { end: true };
336
336
  }
337
337
  } else {
338
- const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
339
- setErrorMsg(message);
340
- (_f = props.onError) == null ? void 0 : _f.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
341
- setSubmitButtonStatus("unSubmit");
338
+ processPaymentError(error);
342
339
  stopReFetchCardPay3DSInfo();
343
340
  return { end: true };
344
341
  }
@@ -445,7 +442,7 @@ const Card = w((props, ref) => {
445
442
  }
446
443
  );
447
444
  async function checkThreeDS(search = false, timeout = 2e4) {
448
- var _a2, _b2, _c, _d, _e;
445
+ var _a2, _b2, _c, _d;
449
446
  if (!session)
450
447
  return { end: true };
451
448
  try {
@@ -506,10 +503,7 @@ const Card = w((props, ref) => {
506
503
  return { end: true };
507
504
  }
508
505
  } else {
509
- const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
510
- setErrorMsg(message);
511
- (_e = props.onError) == null ? void 0 : _e.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
512
- setSubmitButtonStatus("unSubmit");
506
+ processPaymentError(error);
513
507
  stopReFetchCardPay3DSInfo();
514
508
  return { end: true };
515
509
  }
@@ -655,7 +649,7 @@ const Card = w((props, ref) => {
655
649
  (_a2 = field.current) == null ? void 0 : _a2.binValueChanged(data.binValue);
656
650
  binValue = data.binValue;
657
651
  }
658
- binValue && new WorldpayDDC().getFraudDetectionId(binValue);
652
+ binValue && new WorldpayDDC().init(binValue);
659
653
  };
660
654
  const onAfterPayment = (data) => {
661
655
  processAfterPayment(data.response);
@@ -3,7 +3,6 @@ import { COMMON_CLASS_NAME } from "../../constant.js";
3
3
  import { useBEM } from "../../hooks/useBEM.js";
4
4
  import "../../core/context.js";
5
5
  import { clamp } from "../../utils/index.js";
6
- import "../../api/http.js";
7
6
  import "../../out/worldpay-jsc-origin.js";
8
7
  import { getSupportedCardBrands, getCardBrandInfo } from "../../utils/card-brand/index.js";
9
8
  import { normalizedClass } from "../../utils/format.js";
@@ -1,7 +1,7 @@
1
1
  import { w, A, F, h, u } from "../../core.js";
2
2
  import { isExpired } from "../../utils/index.js";
3
3
  import { useI18n } from "../../hooks/useI18n.js";
4
- import "../../api/http.js";
4
+ import "../../core/context.js";
5
5
  import "../../out/worldpay-jsc-origin.js";
6
6
  import "../internal/Form/type.js";
7
7
  import "../internal/Form/context.js";
@@ -2,7 +2,7 @@ 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 "../../api/http.js";
5
+ import "../../core/context.js";
6
6
  import "../../out/worldpay-jsc-origin.js";
7
7
  import "../internal/Form/type.js";
8
8
  import "../internal/Form/context.js";
@@ -1,7 +1,7 @@
1
1
  import { A, h, u } from "../../core.js";
2
2
  import { clamp } from "../../utils/index.js";
3
3
  import { useI18n } from "../../hooks/useI18n.js";
4
- import "../../api/http.js";
4
+ import "../../core/context.js";
5
5
  import "../../out/worldpay-jsc-origin.js";
6
6
  import "../internal/Form/type.js";
7
7
  import "../internal/Form/context.js";
@@ -5,7 +5,6 @@ import "../../core/context.js";
5
5
  import "../../utils/card-brand/brands.js";
6
6
  import "../../utils/system-info/get-browser-info.js";
7
7
  import { normalizedClass } from "../../utils/format.js";
8
- import "../../api/http.js";
9
8
  import "../../out/worldpay-jsc-origin.js";
10
9
  const { bem } = useBEM("card-no");
11
10
  const CardNo = (props) => {