@paykka/card-checkout-ui 0.11.5 → 0.13.1

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 (189) hide show
  1. package/dist/card-checkout-ui.js +17 -17
  2. package/dist/card-checkout-ui.umd.cjs +17 -17
  3. package/dist/es/api/index.js +1 -0
  4. package/dist/es/api/modules/address/index.js +9 -9
  5. package/dist/es/api/modules/ali-pay/index.js +10 -49
  6. package/dist/es/api/modules/apple-pay/index.js +13 -59
  7. package/dist/es/api/modules/boost/index.js +8 -48
  8. package/dist/es/api/modules/card/index.js +10 -54
  9. package/dist/es/api/modules/checkout/index.js +14 -14
  10. package/dist/es/api/modules/checkout/map.js +25 -18
  11. package/dist/es/api/modules/encrypted-card/index.js +3 -2
  12. package/dist/es/api/modules/gcash/index.js +8 -48
  13. package/dist/es/api/modules/google-pay/index.js +10 -56
  14. package/dist/es/api/modules/grab-pay/index.js +8 -48
  15. package/dist/es/api/modules/index.js +1 -0
  16. package/dist/es/api/modules/line-pay/index.js +8 -48
  17. package/dist/es/api/modules/map.js +17 -11
  18. package/dist/es/api/modules/may-bank-qr-pay/index.js +8 -48
  19. package/dist/es/api/modules/nine-pay/index.js +8 -48
  20. package/dist/es/api/modules/paymaya/index.js +8 -48
  21. package/dist/es/api/modules/risk/index.js +2 -1
  22. package/dist/es/api/modules/sepa/index.js +10 -51
  23. package/dist/es/api/modules/shopee-pay/index.js +8 -48
  24. package/dist/es/api/modules/threeDS/index.js +3 -0
  25. package/dist/es/api/modules/tng-wallet/index.js +8 -48
  26. package/dist/es/api/modules/wechat-pay/index.js +10 -51
  27. package/dist/es/api/modules/zalopay/index.js +16 -0
  28. package/dist/es/api/utils/index.js +59 -0
  29. package/dist/es/components/AddressField/index.js +37 -37
  30. package/dist/es/components/AliPay/index.js +143 -90
  31. package/dist/es/components/ApplePay/index.js +99 -67
  32. package/dist/es/components/Boost/index.js +66 -39
  33. package/dist/es/components/Card/index.js +90 -79
  34. package/dist/es/components/CardSelector/index.js +1 -1
  35. package/dist/es/components/DropIn/index.js +12 -4
  36. package/dist/es/components/EncryptedCard/index.js +1 -1
  37. package/dist/es/components/GooglePay/index.js +93 -60
  38. package/dist/es/components/GrabPay/index.js +66 -39
  39. package/dist/es/components/GuideCard/index.js +10 -7
  40. package/dist/es/components/LinePay/index.js +66 -39
  41. package/dist/es/components/MayBankQRPay/index.js +306 -273
  42. package/dist/es/components/NinePay/index.js +66 -39
  43. package/dist/es/components/SecuredFieldsProvider/index.js +3 -2
  44. package/dist/es/components/SecuredIframe/index.js +4 -2
  45. package/dist/es/components/Sepa/index.js +62 -39
  46. package/dist/es/components/ShopeePay/index.js +66 -39
  47. package/dist/es/components/SubmitButton/index.js +8 -7
  48. package/dist/es/components/TNGWallet/index.js +66 -39
  49. package/dist/es/components/WechatPay/index.js +146 -92
  50. package/dist/es/components/business/QRCodeModal/QRCodeModal.js +26 -6
  51. package/dist/es/components/index.js +1 -0
  52. package/dist/es/components/internal/Modal/Modal.js +1 -1
  53. package/dist/es/components/internal/Select/Select.js +19 -8
  54. package/dist/es/components/internal/Select/SelectMenuItem.js +12 -4
  55. package/dist/es/components/internal/icons/IconZalopay.js +47 -0
  56. package/dist/es/components/internal/icons/IconZalopayComplete.js +48 -0
  57. package/dist/es/components/wallets/GCash/GCash.js +68 -39
  58. package/dist/es/components/wallets/Paymaya/Paymaya.js +66 -39
  59. package/dist/es/components/wallets/Zalopay/Zalopay.js +386 -0
  60. package/dist/es/components/wallets/Zalopay/index.js +1 -0
  61. package/dist/es/components/wallets/Zalopay/type.js +1 -0
  62. package/dist/es/components/wallets/Zalopay/zalopay2.js +1 -0
  63. package/dist/es/config.js +5 -5
  64. package/dist/es/constant.js +8 -2
  65. package/dist/es/core/{Address.js → address.js} +8 -16
  66. package/dist/es/core/{PayKKaCheckout.js → checkout.js} +78 -27
  67. package/dist/es/core/query.js +3 -2
  68. package/dist/es/core/{Session.js → session.js} +37 -20
  69. package/dist/es/core.js +34 -38
  70. package/dist/es/hooks/usePayment.js +14 -0
  71. package/dist/es/i18n/locales/de-DE.js +3 -1
  72. package/dist/es/i18n/locales/en-GB.js +3 -1
  73. package/dist/es/i18n/locales/es-ES.js +3 -1
  74. package/dist/es/i18n/locales/fr-FR.js +3 -1
  75. package/dist/es/i18n/locales/ja-JP.js +3 -1
  76. package/dist/es/i18n/locales/ko-KR.js +3 -1
  77. package/dist/es/i18n/locales/nl-NL.js +3 -1
  78. package/dist/es/i18n/locales/pt-PT.js +3 -1
  79. package/dist/es/i18n/locales/ru-RU.js +3 -1
  80. package/dist/es/i18n/locales/zh-CN.js +3 -1
  81. package/dist/es/i18n/locales/zh-HK.js +3 -1
  82. package/dist/es/i18n/locales/zh-TW.js +3 -1
  83. package/dist/es/index.js +16 -4
  84. package/dist/es/style.css +1 -1
  85. package/dist/es/types/index.js +7 -0
  86. package/dist/es/utils/colors.js +5 -1
  87. package/dist/es/utils/payment.js +82 -0
  88. package/dist/es/utils/redirect.js +4 -4
  89. package/dist/es/utils/request-cache-manager.js +32 -0
  90. package/dist/style.css +1 -1
  91. package/dist/types/api/modules/address/index.d.ts +15 -6
  92. package/dist/types/api/modules/ali-pay/index.d.ts +3 -19
  93. package/dist/types/api/modules/apple-pay/index.d.ts +4 -14
  94. package/dist/types/api/modules/boost/index.d.ts +3 -23
  95. package/dist/types/api/modules/card/index.d.ts +3 -30
  96. package/dist/types/api/modules/checkout/index.d.ts +3 -3
  97. package/dist/types/api/modules/checkout/map.d.ts +3 -3
  98. package/dist/types/api/modules/checkout/type.d.ts +33 -4
  99. package/dist/types/api/modules/gcash/index.d.ts +3 -23
  100. package/dist/types/api/modules/google-pay/index.d.ts +3 -13
  101. package/dist/types/api/modules/grab-pay/index.d.ts +3 -23
  102. package/dist/types/api/modules/index.d.ts +1 -0
  103. package/dist/types/api/modules/line-pay/index.d.ts +3 -23
  104. package/dist/types/api/modules/map.d.ts +2 -2
  105. package/dist/types/api/modules/may-bank-qr-pay/index.d.ts +3 -23
  106. package/dist/types/api/modules/nine-pay/index.d.ts +3 -23
  107. package/dist/types/api/modules/paymaya/index.d.ts +3 -23
  108. package/dist/types/api/modules/sepa/index.d.ts +3 -24
  109. package/dist/types/api/modules/shopee-pay/index.d.ts +3 -23
  110. package/dist/types/api/modules/tng-wallet/index.d.ts +3 -23
  111. package/dist/types/api/modules/type.d.ts +74 -21
  112. package/dist/types/api/modules/wechat-pay/index.d.ts +3 -20
  113. package/dist/types/api/modules/zalopay/index.d.ts +4 -0
  114. package/dist/types/api/utils/index.d.ts +48 -0
  115. package/dist/types/components/AddressField/type.d.ts +3 -9
  116. package/dist/types/components/AliPay/AliPay.d.ts +6 -2
  117. package/dist/types/components/AliPay/type.d.ts +15 -2
  118. package/dist/types/components/ApplePay/ApplePay.d.ts +6 -2
  119. package/dist/types/components/ApplePay/type.d.ts +10 -14
  120. package/dist/types/components/ApplePay/utils.d.ts +1 -1
  121. package/dist/types/components/Boost/Boost.d.ts +6 -2
  122. package/dist/types/components/Boost/type.d.ts +2 -24
  123. package/dist/types/components/Card/Card.d.ts +6 -2
  124. package/dist/types/components/Card/type.d.ts +3 -43
  125. package/dist/types/components/DropIn/DropIn.d.ts +6 -2
  126. package/dist/types/components/DropIn/type.d.ts +4 -10
  127. package/dist/types/components/GooglePay/GooglePay.d.ts +6 -2
  128. package/dist/types/components/GooglePay/createGooglePay.d.ts +2 -1
  129. package/dist/types/components/GooglePay/type.d.ts +10 -26
  130. package/dist/types/components/GrabPay/GrabPay.d.ts +6 -2
  131. package/dist/types/components/GrabPay/type.d.ts +3 -25
  132. package/dist/types/components/LinePay/LinePay.d.ts +6 -2
  133. package/dist/types/components/LinePay/type.d.ts +3 -25
  134. package/dist/types/components/MayBankQRPay/MayBankQRPay.d.ts +6 -2
  135. package/dist/types/components/MayBankQRPay/type.d.ts +3 -25
  136. package/dist/types/components/NinePay/NinePay.d.ts +6 -2
  137. package/dist/types/components/NinePay/type.d.ts +3 -25
  138. package/dist/types/components/Sepa/Sepa.d.ts +6 -2
  139. package/dist/types/components/Sepa/type.d.ts +3 -2
  140. package/dist/types/components/ShopeePay/ShopeePay.d.ts +6 -2
  141. package/dist/types/components/ShopeePay/type.d.ts +3 -25
  142. package/dist/types/components/TNGWallet/TNGWallet.d.ts +6 -2
  143. package/dist/types/components/TNGWallet/type.d.ts +3 -25
  144. package/dist/types/components/WechatPay/WechatPay.d.ts +6 -2
  145. package/dist/types/components/WechatPay/type.d.ts +15 -2
  146. package/dist/types/components/business/QRCodeModal/type.d.ts +2 -0
  147. package/dist/types/components/index.d.ts +1 -0
  148. package/dist/types/components/internal/icons/IconZalopay.d.ts +2 -0
  149. package/dist/types/components/internal/icons/IconZalopayComplete.d.ts +2 -0
  150. package/dist/types/components/internal/icons/index.d.ts +3 -0
  151. package/dist/types/components/wallets/GCash/GCash.d.ts +6 -2
  152. package/dist/types/components/wallets/GCash/type.d.ts +3 -35
  153. package/dist/types/components/wallets/Paymaya/Paymaya.d.ts +6 -2
  154. package/dist/types/components/wallets/Paymaya/type.d.ts +3 -25
  155. package/dist/types/components/wallets/Zalopay/Zalopay.d.ts +10 -0
  156. package/dist/types/components/wallets/Zalopay/index.d.ts +2 -0
  157. package/dist/types/components/wallets/Zalopay/type.d.ts +39 -0
  158. package/dist/types/config.d.ts +2 -4
  159. package/dist/types/constant.d.ts +3 -1
  160. package/dist/types/core/{Address.d.ts → address.d.ts} +23 -24
  161. package/dist/types/core/{PayKKaCheckout.d.ts → checkout.d.ts} +5 -3
  162. package/dist/types/core/context.d.ts +3 -2
  163. package/dist/types/core/index.d.ts +2 -2
  164. package/dist/types/core/query.d.ts +2 -2
  165. package/dist/types/core/session.d.ts +33 -0
  166. package/dist/types/hooks/index.d.ts +1 -0
  167. package/dist/types/hooks/usePayment.d.ts +8 -0
  168. package/dist/types/i18n/locales/de-DE.d.ts +2 -0
  169. package/dist/types/i18n/locales/en-GB.d.ts +2 -0
  170. package/dist/types/i18n/locales/es-ES.d.ts +2 -0
  171. package/dist/types/i18n/locales/fr-FR.d.ts +2 -0
  172. package/dist/types/i18n/locales/ja-JP.d.ts +2 -0
  173. package/dist/types/i18n/locales/ko-KR.d.ts +2 -0
  174. package/dist/types/i18n/locales/nl-NL.d.ts +2 -0
  175. package/dist/types/i18n/locales/pt-PT.d.ts +2 -0
  176. package/dist/types/i18n/locales/ru-RU.d.ts +2 -0
  177. package/dist/types/i18n/locales/zh-CN.d.ts +2 -0
  178. package/dist/types/i18n/locales/zh-HK.d.ts +2 -0
  179. package/dist/types/i18n/locales/zh-TW.d.ts +2 -0
  180. package/dist/types/index.d.ts +2 -1
  181. package/dist/types/types/index.d.ts +70 -32
  182. package/dist/types/types/message.d.ts +1 -0
  183. package/dist/types/utils/card-brand/index.d.ts +3 -3
  184. package/dist/types/utils/colors.d.ts +1 -0
  185. package/dist/types/utils/index.d.ts +1 -0
  186. package/dist/types/utils/payment.d.ts +37 -0
  187. package/dist/types/utils/request-cache-manager.d.ts +12 -0
  188. package/package.json +67 -67
  189. package/dist/types/core/Session.d.ts +0 -16
@@ -0,0 +1,59 @@
1
+ import "../../utils/card-brand/brands.js";
2
+ import "../../utils/system-info/get-browser-info.js";
3
+ import { deepMerge } from "../../utils/object.js";
4
+ const buildPaymentParams = (params, extraParams = {}) => {
5
+ const { bill, payment } = params;
6
+ const mergedParams = deepMerge(
7
+ {
8
+ bill: {
9
+ first_name: bill == null ? void 0 : bill.firstName,
10
+ middle_name: bill == null ? void 0 : bill.middleName,
11
+ last_name: bill == null ? void 0 : bill.lastName,
12
+ email: bill == null ? void 0 : bill.email,
13
+ country: bill == null ? void 0 : bill.country,
14
+ state: bill == null ? void 0 : bill.state,
15
+ city: bill == null ? void 0 : bill.city,
16
+ postal_code: bill == null ? void 0 : bill.postalCode,
17
+ address_line1: bill == null ? void 0 : bill.addressLine1,
18
+ address_line2: bill == null ? void 0 : bill.addressLine2,
19
+ district: bill == null ? void 0 : bill.district,
20
+ area_code: bill == null ? void 0 : bill.areaCode,
21
+ phone_number: bill == null ? void 0 : bill.phoneNumber
22
+ }
23
+ },
24
+ extraParams || {}
25
+ );
26
+ return {
27
+ ...mergedParams,
28
+ session_id: params.sessionId,
29
+ client_key: params.clientKey,
30
+ channel_user_id: params.channelUserId,
31
+ payment: {
32
+ payment_method: payment.paymentMethod,
33
+ store_payment_method: payment.storePaymentMethod,
34
+ token_data: payment.tokenData,
35
+ iban: payment.iban,
36
+ token: payment.token,
37
+ card_no: payment.cardNo,
38
+ exp_year: payment.expYear,
39
+ exp_month: payment.expMonth,
40
+ cvv: payment.cvv,
41
+ holder_name: payment.holderName
42
+ },
43
+ browser: params.browser
44
+ };
45
+ };
46
+ const buildQueryParams = (params, extraParams = {}) => {
47
+ const { sessionId, clientKey, paymentMethod, browser } = params;
48
+ return {
49
+ ...extraParams,
50
+ session_id: sessionId,
51
+ client_key: clientKey,
52
+ payment_method: paymentMethod,
53
+ browser
54
+ };
55
+ };
56
+ export {
57
+ buildPaymentParams,
58
+ buildQueryParams
59
+ };
@@ -1,13 +1,12 @@
1
- import { w, h, A, T, F, u } from "../../core.js";
1
+ import { w, x, h, A, T, F, u } from "../../core.js";
2
2
  import { mergedGetAddressFormat, getCity } from "../../api/modules/address/index.js";
3
3
  import { EAddressType } from "../../constant.js";
4
- import { createAddressCore } from "../../core/Address.js";
5
- import { useBEM } from "../../hooks/useBEM.js";
6
- import { useI18n } from "../../hooks/useI18n.js";
7
- import "../../api/http.js";
8
4
  import { isArray, isNil } from "../../utils/is.js";
9
5
  import "../../utils/card-brand/brands.js";
10
6
  import "../../utils/system-info/get-browser-info.js";
7
+ import { useBEM } from "../../hooks/useBEM.js";
8
+ import { useI18n } from "../../hooks/useI18n.js";
9
+ import "../../api/http.js";
11
10
  import "../internal/Form/type.js";
12
11
  import "../internal/Form/context.js";
13
12
  import { FormItem } from "../internal/Form/FormItem.js";
@@ -15,20 +14,25 @@ import "../internal/Form/Form.js";
15
14
  import { Input } from "../internal/Input/Input.js";
16
15
  import "../internal/Input/type.js";
17
16
  import { Select } from "../internal/Select/Select.js";
17
+ import { CoreContext } from "../../core/context.js";
18
18
  const { bem } = useBEM("address-field");
19
19
  const defaultAddress = {
20
- country: "",
21
- province: "",
22
- city: "",
23
- area: "",
24
- postCode: "",
25
- address1: "",
26
- address2: ""
20
+ country: void 0,
21
+ province: void 0,
22
+ city: void 0,
23
+ area: void 0,
24
+ postCode: void 0,
25
+ address1: void 0,
26
+ address2: void 0
27
27
  };
28
28
  const AddressField = w((props, ref) => {
29
29
  const { onAddressChange } = props;
30
30
  const { i18n } = useI18n();
31
- const addressCore = createAddressCore();
31
+ const context = x(CoreContext);
32
+ if (!(context == null ? void 0 : context.core)) {
33
+ throw new Error("CoreContext is not found");
34
+ }
35
+ const addressCore = context.core.getAddressCore();
32
36
  const [addressState, setAddressState] = h({
33
37
  ...addressCore.getAddressState()
34
38
  });
@@ -105,17 +109,11 @@ const AddressField = w((props, ref) => {
105
109
  });
106
110
  }
107
111
  async function getDefaultCountry() {
108
- const countryCode = props.country;
112
+ const language = navigator.language;
113
+ const areaCode = language.split("-");
114
+ const countryCode = addressState.country || ((areaCode == null ? void 0 : areaCode[1]) ?? "US");
109
115
  onSelectCountry(countryCode || "");
110
- onAddressChange({
111
- country: addressState.country ?? "",
112
- province: addressState.province ?? "",
113
- city: addressState.city ?? "",
114
- area: addressState.area ?? "",
115
- postCode: addressState.postCode ?? "",
116
- address1: addressState.address1 ?? "",
117
- address2: addressState.address2 ?? ""
118
- });
116
+ onAddressChange({ ...addressState });
119
117
  }
120
118
  const AddressFormatMap = {
121
119
  [EAddressType.ADDRESS_1]: Address1Item,
@@ -137,8 +135,17 @@ const AddressField = w((props, ref) => {
137
135
  };
138
136
  }
139
137
  async function onSelectCountry(value) {
138
+ var _a, _b;
140
139
  handleAddressFormatChange([]);
141
140
  handleStateChange("COUNTRY", value);
141
+ const addressMode = (_b = (_a = context == null ? void 0 : context.core) == null ? void 0 : _a.config._checkoutConfig) == null ? void 0 : _b.addressMode;
142
+ if (addressMode === "country") {
143
+ onAddressChange({
144
+ ...defaultAddress,
145
+ country: value
146
+ });
147
+ return;
148
+ }
142
149
  const format = await mergedGetAddressFormat(value, { locale: i18n.locale });
143
150
  const addressType = [];
144
151
  const addressArr = format.map(({ addressItem, required, description }) => {
@@ -188,13 +195,9 @@ const AddressField = w((props, ref) => {
188
195
  resetField([EAddressType.CITY]);
189
196
  (_a = cityFormItemRef.current) == null ? void 0 : _a.validateChange("");
190
197
  onAddressChange({
191
- country: addressState.country ?? "",
198
+ ...addressState,
192
199
  province: value,
193
- city: "",
194
- postCode: addressState.postCode,
195
- address1: addressState.address1,
196
- address2: addressState.address2,
197
- area: addressState.area
200
+ city: ""
198
201
  });
199
202
  }
200
203
  async function getCityData(value) {
@@ -208,16 +211,13 @@ const AddressField = w((props, ref) => {
208
211
  function onSelectCity(value) {
209
212
  handleStateChange(EAddressType.CITY, value);
210
213
  onAddressChange({
211
- country: addressState.country ?? "",
212
- province: addressState.province ?? "",
213
- city: value,
214
- postCode: addressState.postCode ?? "",
215
- address1: addressState.address1 ?? "",
216
- address2: addressState.address2 ?? "",
217
- area: addressState.area
214
+ ...addressState,
215
+ city: value
218
216
  });
219
217
  }
220
218
  function CountryItem() {
219
+ var _a, _b;
220
+ const addressMode = (_b = (_a = context == null ? void 0 : context.core) == null ? void 0 : _a.config._checkoutConfig) == null ? void 0 : _b.addressMode;
221
221
  return /* @__PURE__ */ u(
222
222
  FormItem,
223
223
  {
@@ -234,7 +234,7 @@ const AddressField = w((props, ref) => {
234
234
  options: countryOptions,
235
235
  onSelect: (value) => onSelectCountry(value),
236
236
  placeholder: i18n.get("address.country"),
237
- inputClassName: bem("first-item"),
237
+ inputClassName: bem("first-item", { "no-bottom-radius": addressMode === "address" }),
238
238
  noDataTip: i18n.get("common.noData")
239
239
  }
240
240
  )
@@ -1,18 +1,19 @@
1
- import { w, h, A, F, y, q, u } from "../../core.js";
1
+ import { w, h, A, F, y, q, u, b } from "../../core.js";
2
2
  import { isTimeoutError } from "../../api/http.js";
3
3
  import { getAliPayInfo, aliPay } from "../../api/modules/ali-pay/index.js";
4
4
  import "../../utils/card-brand/brands.js";
5
5
  import "../../utils/system-info/get-browser-info.js";
6
6
  import { cssVarPrefix, normalizedClass, formatAmount } from "../../utils/format.js";
7
- import { COMMON_CLASS_NAME, PaymentType } from "../../constant.js";
7
+ import { formatPaymentResult } from "../../utils/payment.js";
8
+ import { getBrowserParams } from "../../api/modules/get-browser-params.js";
9
+ import { COMMON_CLASS_NAME, PaymentType, PaymentMethod, SessionMode } from "../../constant.js";
8
10
  import { CoreContext } from "../../core/context.js";
9
11
  import { PayKKaError } from "../../core/error.js";
10
- import { createAddressCore } from "../../core/Address.js";
11
12
  import { useBEM } from "../../hooks/useBEM.js";
12
13
  import { usePayState } from "../../hooks/usePayState.js";
13
14
  import { useRetry } from "../../hooks/useRetry.js";
14
15
  import { AddressField } from "../AddressField/index.js";
15
- import { EmailField, createEmailCore } from "../EmailField/EmailField.js";
16
+ import { createEmailCore, EmailField } from "../EmailField/EmailField.js";
16
17
  import "../internal/Form/type.js";
17
18
  import "../internal/Form/context.js";
18
19
  import "../internal/Form/FormItem.js";
@@ -21,10 +22,11 @@ import { Info } from "../internal/Info/Info.js";
21
22
  import { RecurringTip } from "../RecurringTip/index.js";
22
23
  import { SubmitButton } from "../SubmitButton/index.js";
23
24
  const { bem } = useBEM("ali-pay");
25
+ const fieldClassNames = bem("field");
24
26
  const AliPay = w((props, ref) => {
25
- var _a, _b, _c, _d, _e, _f, _g, _h;
26
- const { session } = props;
27
- const addressState = createAddressCore();
27
+ var _a, _b, _c, _d, _e, _f;
28
+ const { session, core, showEmail = false, showAddress = false } = props;
29
+ const addressCore = core.getAddressCore();
28
30
  const emailState = createEmailCore();
29
31
  const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session, props.core);
30
32
  const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
@@ -32,20 +34,20 @@ const AliPay = w((props, ref) => {
32
34
  const [form, setForm] = h({
33
35
  email: "",
34
36
  address: {
35
- country: "",
36
- province: "",
37
- city: "",
38
- area: "",
39
- postCode: "",
40
- address1: "",
41
- address2: ""
37
+ country: void 0,
38
+ province: void 0,
39
+ city: void 0,
40
+ area: void 0,
41
+ postCode: void 0,
42
+ address1: void 0,
43
+ address2: void 0
42
44
  }
43
45
  });
44
46
  const [validated, setValidated] = h(false);
45
- const disabledEmail = A(false);
46
- const [requiredBill, setRequiredBill] = h(false);
47
+ const [fieldStatus, setFieldStatus] = h();
47
48
  const addressFieldRef = A(null);
48
49
  const emailFieldRef = A(null);
50
+ const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
49
51
  F(ref, () => ({
50
52
  stopRetry: () => {
51
53
  stopReFetchPayInfo();
@@ -57,13 +59,21 @@ const AliPay = w((props, ref) => {
57
59
  },
58
60
  updateAddress: () => {
59
61
  var _a2;
60
- setForm(Object.assign(form, { address: addressState.getAddressState() }));
61
- (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
62
+ if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
63
+ return;
64
+ const newForm = Object.assign(form, { address: addressCore.getAddressState() });
65
+ setForm(newForm);
66
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressCore.getAddressState());
67
+ validateForm();
62
68
  },
63
69
  updateEmail: () => {
64
70
  var _a2;
65
- setForm(Object.assign(form, { email: emailState.email }));
71
+ if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
72
+ return;
73
+ const newForm = Object.assign(form, { email: emailState.email });
74
+ setForm(newForm);
66
75
  (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
76
+ validateForm();
67
77
  }
68
78
  }));
69
79
  function validateForm() {
@@ -74,23 +84,46 @@ const AliPay = w((props, ref) => {
74
84
  setValidated(false);
75
85
  });
76
86
  }
87
+ const initFieldStatus = () => {
88
+ const { field, sessionMode } = session.checkout;
89
+ const { email, address } = field;
90
+ if (sessionMode === SessionMode.COMPONENT) {
91
+ if (email.disabled) {
92
+ email.show = showEmail;
93
+ }
94
+ if (showAddress && !(address == null ? void 0 : address.show)) {
95
+ address.show = true;
96
+ }
97
+ }
98
+ setFieldStatus({ ...field });
99
+ };
77
100
  y(() => {
78
101
  validateForm();
79
102
  }, [form]);
103
+ const processOnSuccess = (res) => {
104
+ var _a2, _b2;
105
+ setSubmitButtonStatus("success");
106
+ (_b2 = props.onSuccess) == null ? void 0 : _b2.call(
107
+ props,
108
+ formatPaymentResult({
109
+ ...res,
110
+ returnUrl: (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.returnUrl
111
+ })
112
+ );
113
+ };
80
114
  y(() => {
81
- var _a2;
82
- if (sessionReady) {
83
- if ((session == null ? void 0 : session.checkout.status) === "SUCCESS") {
84
- setSubmitButtonStatus("success");
85
- (_a2 = props.onSuccess) == null ? void 0 : _a2.call(props);
86
- }
87
- form.email = (session == null ? void 0 : session.checkout.bill.email) ?? "";
88
- disabledEmail.current = !!(session == null ? void 0 : session.checkout.bill.email);
89
- (session == null ? void 0 : session.checkout.bill.billingAddressCollection) === "REQUIRED" ? setRequiredBill(true) : setRequiredBill(false);
90
- !requiredBill && setTimeout(() => {
91
- validateForm();
92
- }, 100);
115
+ if (!sessionReady) {
116
+ return;
93
117
  }
118
+ const { bill = {}, supportMethods = [], country } = (session == null ? void 0 : session.checkout) || {};
119
+ if (!supportMethods.includes(PaymentMethod.ALI_PAY)) {
120
+ return;
121
+ }
122
+ initFieldStatus();
123
+ setIsCheckoutEnabled(true);
124
+ country && addressCore.setCountry(country);
125
+ form.email = bill.email ?? "";
126
+ form.address.country = country;
94
127
  }, [sessionReady]);
95
128
  const onTimeout = q(
96
129
  (message) => {
@@ -107,64 +140,77 @@ const AliPay = w((props, ref) => {
107
140
  onTimeout: () => onTimeout(i18n.get("common.queryTimeout"))
108
141
  }
109
142
  );
143
+ const getPaymentParams = async () => {
144
+ return {
145
+ sessionId: session.sessionId,
146
+ clientKey: session.clientKey,
147
+ bill: (fieldStatus == null ? void 0 : fieldStatus.address.show) ? {
148
+ email: form.email,
149
+ addressLine1: form.address.address1,
150
+ addressLine2: form.address.address2,
151
+ postalCode: form.address.postCode,
152
+ country: form.address.country,
153
+ district: form.address.area,
154
+ state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
155
+ city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
156
+ } : {
157
+ email: form.email
158
+ },
159
+ payment: {
160
+ paymentMethod: PaymentMethod.ALI_PAY
161
+ },
162
+ browser: await getBrowserParams()
163
+ };
164
+ };
110
165
  async function pay(search = false, timeout) {
111
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
166
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i;
112
167
  try {
113
- const res = search ? await getAliPayInfo(
114
- {
115
- sessionId: session.sessionId,
116
- clientKey: session.clientKey
117
- },
118
- { locale: i18n.locale, timeout }
119
- ) : await aliPay(
120
- {
121
- sessionId: session.sessionId,
122
- clientKey: session.clientKey,
123
- bill: requiredBill ? {
124
- email: form.email,
125
- ...form.address,
126
- province: addressState.getLabel(
127
- form.address.province,
128
- addressState.getProvinceOption()
129
- ) ?? form.address.province,
130
- city: addressState.getLabel(form.address.city, addressState.getCityOptions()) ?? form.address.city
131
- } : {
132
- email: form.email
133
- }
134
- },
135
- props.core,
136
- { locale: i18n.locale, timeout }
137
- );
138
- const { status, orderStatus, errorMessage, errorCode } = res;
139
- !search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
168
+ const requestOptions = { locale: i18n.locale, timeout };
169
+ let res = null;
170
+ if (search) {
171
+ const extraParams = (_b2 = (_a2 = core.config)._getExtraParams) == null ? void 0 : _b2.call(_a2, "query", PaymentMethod.ALI_PAY);
172
+ res = await getAliPayInfo(
173
+ {
174
+ sessionId: session.sessionId,
175
+ clientKey: session.clientKey,
176
+ paymentMethod: PaymentMethod.ALI_PAY
177
+ },
178
+ extraParams,
179
+ requestOptions
180
+ );
181
+ } else {
182
+ const extraParams = (_d2 = (_c2 = core.config)._getExtraParams) == null ? void 0 : _d2.call(_c2, "payment", PaymentMethod.ALI_PAY);
183
+ res = await aliPay(await getPaymentParams(), extraParams, requestOptions);
184
+ }
185
+ const { status, orderStatus, errorMessage, errorCode, sessionId } = res;
186
+ sessionId && (session.sessionId = sessionId);
187
+ !search && ((_e2 = props.onSubmitResponse) == null ? void 0 : _e2.call(props, res));
140
188
  if (status === "PROCESSING") {
141
189
  if (!orderStatus) {
142
190
  setSubmitButtonStatus("unSubmit");
143
191
  return { end: true };
144
192
  } else if (orderStatus === "SUCCESS") {
145
- setSubmitButtonStatus("success");
146
- (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
193
+ processOnSuccess(res);
147
194
  return { end: true };
148
195
  } else if (orderStatus === "FAILURE") {
149
- setErrorMsg(errorMessage);
196
+ errorMessage && setErrorMsg(errorMessage);
150
197
  setSubmitButtonStatus("unSubmit");
151
- (_c2 = props.onError) == null ? void 0 : _c2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
198
+ (_f2 = props.onError) == null ? void 0 : _f2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
152
199
  return { end: true };
153
200
  } else if (orderStatus === "PROCESSING") {
154
201
  !search && startReFetchPayInfo();
155
202
  return { end: false };
156
203
  } else if (orderStatus === "CANCELED") {
157
204
  setSubmitButtonStatus("unSubmit");
158
- (_d2 = props.onTimeout) == null ? void 0 : _d2.call(props, "channel");
205
+ (_g = props.onTimeout) == null ? void 0 : _g.call(props, "channel");
159
206
  return { end: true };
160
207
  }
161
208
  } else if (status === "SUCCESS") {
162
- setSubmitButtonStatus("success");
163
- (_e2 = props.onSuccess) == null ? void 0 : _e2.call(props);
209
+ processOnSuccess(res);
164
210
  return { end: true };
165
211
  } else if (status === "EXPIRED") {
166
212
  setSubmitButtonStatus("unSubmit");
167
- (_f2 = props.onExpired) == null ? void 0 : _f2.call(props);
213
+ (_h = props.onExpired) == null ? void 0 : _h.call(props);
168
214
  return { end: true };
169
215
  }
170
216
  setSubmitButtonStatus("unSubmit");
@@ -179,8 +225,8 @@ const AliPay = w((props, ref) => {
179
225
  }
180
226
  } else {
181
227
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
182
- setErrorMsg(message);
183
- (_g2 = props.onError) == null ? void 0 : _g2.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
228
+ message && setErrorMsg(message);
229
+ (_i = props.onError) == null ? void 0 : _i.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
184
230
  setSubmitButtonStatus("unSubmit");
185
231
  return { end: true };
186
232
  }
@@ -191,7 +237,7 @@ const AliPay = w((props, ref) => {
191
237
  setErrorMsg("");
192
238
  (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
193
239
  var _a3;
194
- requiredBill && addressState.setValidateAllFields(true);
240
+ (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
195
241
  (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
196
242
  if (errors) {
197
243
  setSubmitButtonStatus("unSubmit");
@@ -232,32 +278,39 @@ const AliPay = w((props, ref) => {
232
278
  [cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
233
279
  [cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
234
280
  };
281
+ const Email = () => {
282
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.email.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
283
+ EmailField,
284
+ {
285
+ ref: emailFieldRef,
286
+ value: form.email,
287
+ disabled: fieldStatus == null ? void 0 : fieldStatus.email.disabled
288
+ }
289
+ ) }) });
290
+ };
291
+ const Address = () => {
292
+ var _a2, _b2;
293
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
294
+ AddressField,
295
+ {
296
+ ref: addressFieldRef,
297
+ value: form.address,
298
+ country: ((_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.country) || ((_b2 = session == null ? void 0 : session.checkout) == null ? void 0 : _b2.bill.country),
299
+ onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
300
+ }
301
+ ) }) });
302
+ };
235
303
  return /* @__PURE__ */ u(
236
304
  CoreContext.Provider,
237
305
  {
238
306
  value: {
239
307
  i18n,
240
- session
308
+ session,
309
+ core
241
310
  },
242
- 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: [
243
- /* @__PURE__ */ u(
244
- EmailField,
245
- {
246
- ref: emailFieldRef,
247
- className: bem("email"),
248
- value: form.email,
249
- disabled: !!disabledEmail.current
250
- }
251
- ),
252
- requiredBill && /* @__PURE__ */ u(
253
- AddressField,
254
- {
255
- ref: addressFieldRef,
256
- value: form.address,
257
- 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),
258
- onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
259
- }
260
- ),
311
+ children: isCheckoutEnabled && 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: [
312
+ Email(),
313
+ Address(),
261
314
  (session == null ? void 0 : session.checkout.paymentType) === PaymentType.RECURRING && RecurringTip(),
262
315
  !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
263
316
  Button()