@paykka/card-checkout-ui 0.11.6 → 0.13.2

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 (217) hide show
  1. package/dist/card-checkout-ui.js +19 -19
  2. package/dist/card-checkout-ui.umd.cjs +19 -19
  3. package/dist/es/_commonjsHelpers.js +82 -1
  4. package/dist/es/api/index.js +1 -0
  5. package/dist/es/api/modules/address/index.js +9 -9
  6. package/dist/es/api/modules/ali-pay/index.js +10 -49
  7. package/dist/es/api/modules/apple-pay/index.js +13 -59
  8. package/dist/es/api/modules/boost/index.js +8 -48
  9. package/dist/es/api/modules/card/index.js +10 -54
  10. package/dist/es/api/modules/checkout/index.js +11 -9
  11. package/dist/es/api/modules/checkout/map.js +25 -18
  12. package/dist/es/api/modules/encrypted-card/index.js +3 -2
  13. package/dist/es/api/modules/gcash/index.js +8 -48
  14. package/dist/es/api/modules/get-browser-params.js +4 -1
  15. package/dist/es/api/modules/google-pay/index.js +10 -56
  16. package/dist/es/api/modules/grab-pay/index.js +8 -48
  17. package/dist/es/api/modules/index.js +1 -0
  18. package/dist/es/api/modules/line-pay/index.js +8 -48
  19. package/dist/es/api/modules/map.js +17 -11
  20. package/dist/es/api/modules/may-bank-qr-pay/index.js +8 -48
  21. package/dist/es/api/modules/nine-pay/index.js +8 -48
  22. package/dist/es/api/modules/paymaya/index.js +8 -48
  23. package/dist/es/api/modules/risk/index.js +2 -1
  24. package/dist/es/api/modules/sepa/index.js +10 -51
  25. package/dist/es/api/modules/shopee-pay/index.js +8 -48
  26. package/dist/es/api/modules/threeDS/index.js +3 -0
  27. package/dist/es/api/modules/tng-wallet/index.js +8 -48
  28. package/dist/es/api/modules/wechat-pay/index.js +10 -51
  29. package/dist/es/api/modules/zalopay/index.js +16 -0
  30. package/dist/es/api/utils/index.js +59 -0
  31. package/dist/es/components/AddressField/index.js +37 -37
  32. package/dist/es/components/AliPay/index.js +158 -111
  33. package/dist/es/components/ApplePay/index.js +99 -67
  34. package/dist/es/components/Boost/index.js +91 -70
  35. package/dist/es/components/Card/index.js +114 -107
  36. package/dist/es/components/CardSelector/index.js +1 -1
  37. package/dist/es/components/DropIn/index.js +12 -4
  38. package/dist/es/components/EncryptedCard/index.js +6 -2
  39. package/dist/es/components/GooglePay/index.js +94 -60
  40. package/dist/es/components/GrabPay/index.js +91 -70
  41. package/dist/es/components/GuideCard/index.js +10 -7
  42. package/dist/es/components/LinePay/index.js +91 -70
  43. package/dist/es/components/MayBankQRPay/index.js +302 -275
  44. package/dist/es/components/NinePay/index.js +91 -70
  45. package/dist/es/components/SecuredFieldsProvider/index.js +26 -9
  46. package/dist/es/components/SecuredIframe/index.js +40 -61
  47. package/dist/es/components/Sepa/index.js +72 -53
  48. package/dist/es/components/ShopeePay/index.js +91 -70
  49. package/dist/es/components/SubmitButton/index.js +8 -7
  50. package/dist/es/components/TNGWallet/index.js +91 -70
  51. package/dist/es/components/ThreeDS/index.js +32 -7
  52. package/dist/es/components/WechatPay/index.js +151 -102
  53. package/dist/es/components/business/QRCodeModal/QRCodeModal.js +26 -6
  54. package/dist/es/components/index.js +1 -0
  55. package/dist/es/components/internal/Form/FormItem.js +1 -1
  56. package/dist/es/components/internal/Form/util.js +1 -1
  57. package/dist/es/components/internal/Modal/Modal.js +1 -1
  58. package/dist/es/components/internal/Select/Select.js +19 -8
  59. package/dist/es/components/internal/Select/SelectMenu.js +2 -2
  60. package/dist/es/components/internal/Select/SelectMenuItem.js +12 -4
  61. package/dist/es/components/internal/icons/IconError.js +7 -4
  62. package/dist/es/components/internal/icons/IconZalopay.js +47 -0
  63. package/dist/es/components/internal/icons/IconZalopayComplete.js +48 -0
  64. package/dist/es/components/wallets/GCash/GCash.js +80 -56
  65. package/dist/es/components/wallets/Paymaya/Paymaya.js +91 -70
  66. package/dist/es/components/wallets/Zalopay/Zalopay.js +381 -0
  67. package/dist/es/components/wallets/Zalopay/index.js +1 -0
  68. package/dist/es/components/wallets/Zalopay/type.js +1 -0
  69. package/dist/es/components/wallets/Zalopay/zalopay2.js +1 -0
  70. package/dist/es/config.js +5 -5
  71. package/dist/es/constant.js +8 -2
  72. package/dist/es/core/{Address.js → address.js} +8 -16
  73. package/dist/es/core/{PayKKaCheckout.js → checkout.js} +101 -27
  74. package/dist/es/core/create.js +1 -1
  75. package/dist/es/core/query.js +3 -2
  76. package/dist/es/core/{Session.js → session.js} +28 -32
  77. package/dist/es/core/theme.js +65 -0
  78. package/dist/es/core.js +0 -4
  79. package/dist/es/hooks/usePayment.js +14 -0
  80. package/dist/es/i18n/locales/de-DE.js +3 -1
  81. package/dist/es/i18n/locales/en-GB.js +3 -1
  82. package/dist/es/i18n/locales/es-ES.js +3 -1
  83. package/dist/es/i18n/locales/fr-FR.js +3 -1
  84. package/dist/es/i18n/locales/ja-JP.js +3 -1
  85. package/dist/es/i18n/locales/ko-KR.js +3 -1
  86. package/dist/es/i18n/locales/nl-NL.js +3 -1
  87. package/dist/es/i18n/locales/pt-PT.js +3 -1
  88. package/dist/es/i18n/locales/ru-RU.js +3 -1
  89. package/dist/es/i18n/locales/zh-CN.js +3 -1
  90. package/dist/es/i18n/locales/zh-HK.js +3 -1
  91. package/dist/es/i18n/locales/zh-TW.js +3 -1
  92. package/dist/es/index.js +21 -7
  93. package/dist/es/style.css +1 -1
  94. package/dist/es/types/index.js +7 -0
  95. package/dist/es/utils/colors.js +5 -1
  96. package/dist/es/utils/format.js +0 -5
  97. package/dist/es/utils/object.js +31 -1
  98. package/dist/es/utils/payment.js +82 -0
  99. package/dist/es/utils/redirect.js +4 -4
  100. package/dist/es/utils/string.js +10 -0
  101. package/dist/es/utils/system-info/is-ua-webview.js +14 -12
  102. package/dist/es/utils/theme.js +7 -0
  103. package/dist/style.css +1 -1
  104. package/dist/types/api/modules/address/index.d.ts +15 -6
  105. package/dist/types/api/modules/ali-pay/index.d.ts +3 -19
  106. package/dist/types/api/modules/apple-pay/index.d.ts +4 -14
  107. package/dist/types/api/modules/boost/index.d.ts +3 -23
  108. package/dist/types/api/modules/card/index.d.ts +3 -30
  109. package/dist/types/api/modules/checkout/index.d.ts +3 -3
  110. package/dist/types/api/modules/checkout/map.d.ts +3 -3
  111. package/dist/types/api/modules/checkout/type.d.ts +33 -4
  112. package/dist/types/api/modules/gcash/index.d.ts +3 -23
  113. package/dist/types/api/modules/get-browser-params.d.ts +1 -0
  114. package/dist/types/api/modules/google-pay/index.d.ts +3 -13
  115. package/dist/types/api/modules/grab-pay/index.d.ts +3 -23
  116. package/dist/types/api/modules/index.d.ts +1 -0
  117. package/dist/types/api/modules/line-pay/index.d.ts +3 -23
  118. package/dist/types/api/modules/map.d.ts +2 -2
  119. package/dist/types/api/modules/may-bank-qr-pay/index.d.ts +3 -23
  120. package/dist/types/api/modules/nine-pay/index.d.ts +3 -23
  121. package/dist/types/api/modules/paymaya/index.d.ts +3 -23
  122. package/dist/types/api/modules/sepa/index.d.ts +3 -24
  123. package/dist/types/api/modules/shopee-pay/index.d.ts +3 -23
  124. package/dist/types/api/modules/tng-wallet/index.d.ts +3 -23
  125. package/dist/types/api/modules/type.d.ts +74 -21
  126. package/dist/types/api/modules/wechat-pay/index.d.ts +3 -20
  127. package/dist/types/api/modules/zalopay/index.d.ts +4 -0
  128. package/dist/types/api/utils/index.d.ts +48 -0
  129. package/dist/types/components/AddressField/type.d.ts +3 -9
  130. package/dist/types/components/AliPay/AliPay.d.ts +6 -2
  131. package/dist/types/components/AliPay/type.d.ts +15 -2
  132. package/dist/types/components/ApplePay/ApplePay.d.ts +6 -2
  133. package/dist/types/components/ApplePay/type.d.ts +10 -14
  134. package/dist/types/components/ApplePay/utils.d.ts +1 -1
  135. package/dist/types/components/Boost/Boost.d.ts +6 -2
  136. package/dist/types/components/Boost/type.d.ts +2 -24
  137. package/dist/types/components/Card/Card.d.ts +6 -2
  138. package/dist/types/components/Card/type.d.ts +3 -43
  139. package/dist/types/components/DropIn/DropIn.d.ts +6 -2
  140. package/dist/types/components/DropIn/type.d.ts +4 -10
  141. package/dist/types/components/GooglePay/GooglePay.d.ts +6 -2
  142. package/dist/types/components/GooglePay/createGooglePay.d.ts +2 -1
  143. package/dist/types/components/GooglePay/type.d.ts +10 -26
  144. package/dist/types/components/GrabPay/GrabPay.d.ts +6 -2
  145. package/dist/types/components/GrabPay/type.d.ts +3 -25
  146. package/dist/types/components/LinePay/LinePay.d.ts +6 -2
  147. package/dist/types/components/LinePay/type.d.ts +3 -25
  148. package/dist/types/components/MayBankQRPay/MayBankQRPay.d.ts +6 -2
  149. package/dist/types/components/MayBankQRPay/type.d.ts +3 -25
  150. package/dist/types/components/NinePay/NinePay.d.ts +6 -2
  151. package/dist/types/components/NinePay/type.d.ts +3 -25
  152. package/dist/types/components/SecuredFieldsProvider/type.d.ts +5 -0
  153. package/dist/types/components/SecuredIframe/HiddenIframe.d.ts +3 -1
  154. package/dist/types/components/Sepa/Sepa.d.ts +6 -2
  155. package/dist/types/components/Sepa/type.d.ts +3 -2
  156. package/dist/types/components/ShopeePay/ShopeePay.d.ts +6 -2
  157. package/dist/types/components/ShopeePay/type.d.ts +3 -25
  158. package/dist/types/components/TNGWallet/TNGWallet.d.ts +6 -2
  159. package/dist/types/components/TNGWallet/type.d.ts +3 -25
  160. package/dist/types/components/ThreeDS/components/ThreeDSAuth/type.d.ts +2 -0
  161. package/dist/types/components/WechatPay/WechatPay.d.ts +6 -2
  162. package/dist/types/components/WechatPay/type.d.ts +15 -2
  163. package/dist/types/components/business/QRCodeModal/type.d.ts +2 -0
  164. package/dist/types/components/index.d.ts +1 -0
  165. package/dist/types/components/internal/Loading/Loading.d.ts +1 -0
  166. package/dist/types/components/internal/Select/SelectMenu.d.ts +1 -1
  167. package/dist/types/components/internal/icons/IconZalopay.d.ts +2 -0
  168. package/dist/types/components/internal/icons/IconZalopayComplete.d.ts +2 -0
  169. package/dist/types/components/internal/icons/index.d.ts +3 -0
  170. package/dist/types/components/wallets/GCash/GCash.d.ts +6 -2
  171. package/dist/types/components/wallets/GCash/type.d.ts +3 -35
  172. package/dist/types/components/wallets/Paymaya/Paymaya.d.ts +6 -2
  173. package/dist/types/components/wallets/Paymaya/type.d.ts +3 -25
  174. package/dist/types/components/wallets/Zalopay/Zalopay.d.ts +10 -0
  175. package/dist/types/components/wallets/Zalopay/index.d.ts +2 -0
  176. package/dist/types/components/wallets/Zalopay/type.d.ts +39 -0
  177. package/dist/types/config.d.ts +2 -4
  178. package/dist/types/constant.d.ts +3 -1
  179. package/dist/types/core/{Address.d.ts → address.d.ts} +23 -24
  180. package/dist/types/core/{PayKKaCheckout.d.ts → checkout.d.ts} +9 -3
  181. package/dist/types/core/context.d.ts +3 -2
  182. package/dist/types/core/index.d.ts +3 -2
  183. package/dist/types/core/query.d.ts +2 -2
  184. package/dist/types/core/session.d.ts +23 -0
  185. package/dist/types/core/theme.d.ts +7 -0
  186. package/dist/types/hooks/index.d.ts +1 -0
  187. package/dist/types/hooks/usePayment.d.ts +8 -0
  188. package/dist/types/i18n/locales/de-DE.d.ts +2 -0
  189. package/dist/types/i18n/locales/en-GB.d.ts +2 -0
  190. package/dist/types/i18n/locales/es-ES.d.ts +2 -0
  191. package/dist/types/i18n/locales/fr-FR.d.ts +2 -0
  192. package/dist/types/i18n/locales/ja-JP.d.ts +2 -0
  193. package/dist/types/i18n/locales/ko-KR.d.ts +2 -0
  194. package/dist/types/i18n/locales/nl-NL.d.ts +2 -0
  195. package/dist/types/i18n/locales/pt-PT.d.ts +2 -0
  196. package/dist/types/i18n/locales/ru-RU.d.ts +2 -0
  197. package/dist/types/i18n/locales/zh-CN.d.ts +2 -0
  198. package/dist/types/i18n/locales/zh-HK.d.ts +2 -0
  199. package/dist/types/i18n/locales/zh-TW.d.ts +2 -0
  200. package/dist/types/index.d.ts +2 -1
  201. package/dist/types/types/index.d.ts +70 -32
  202. package/dist/types/types/message.d.ts +30 -25
  203. package/dist/types/utils/card-brand/index.d.ts +3 -3
  204. package/dist/types/utils/colors.d.ts +1 -0
  205. package/dist/types/utils/index.d.ts +4 -2
  206. package/dist/types/utils/object.d.ts +7 -0
  207. package/dist/types/utils/payment.d.ts +37 -0
  208. package/dist/types/utils/string.d.ts +1 -0
  209. package/dist/types/utils/style.d.ts +1 -1
  210. package/dist/types/utils/system-info/is-ua-webview.d.ts +1 -1
  211. package/dist/types/utils/theme.d.ts +4 -0
  212. package/package.json +3 -3
  213. package/dist/es/utils/deep-freeze.js +0 -13
  214. package/dist/es/utils/obj.js +0 -22
  215. package/dist/types/core/Session.d.ts +0 -16
  216. package/dist/types/utils/deep-freeze.d.ts +0 -1
  217. package/dist/types/utils/obj.d.ts +0 -6
@@ -1,56 +1,15 @@
1
- import { PaymentMethod } from "../../../constant.js";
2
- import "../../../utils/card-brand/brands.js";
3
- import "../../../utils/system-info/get-browser-info.js";
4
- import { deepMerge } from "../../../utils/object.js";
1
+ import { apiPrefix } from "../../../config.js";
5
2
  import { http } from "../../http.js";
6
- import { getBrowserParams } from "../get-browser-params.js";
3
+ import { buildPaymentParams, buildQueryParams } from "../../utils/index.js";
7
4
  import { payResMap } from "../map.js";
8
- async function wechatPay({
9
- sessionId,
10
- clientKey,
11
- bill,
12
- channelUserId
13
- }, core, options) {
14
- const { _getExtraParams } = core.config;
15
- const extraParams = _getExtraParams == null ? void 0 : _getExtraParams("payment", PaymentMethod.WECHAT_PAY);
16
- const params = deepMerge({
17
- bill: {
18
- email: bill.email,
19
- country: bill.country,
20
- state: bill.province,
21
- city: bill.city,
22
- postal_code: bill.postCode,
23
- address_line1: bill.address1,
24
- address_line2: bill.address2,
25
- county: bill.area
26
- }
27
- }, extraParams || {});
28
- return http.post(
29
- "/session/payments",
30
- {
31
- ...params,
32
- session_id: sessionId,
33
- client_key: clientKey,
34
- payment: {
35
- payment_method: PaymentMethod.WECHAT_PAY
36
- },
37
- browser: await getBrowserParams(),
38
- channel_user_id: channelUserId
39
- },
40
- options
41
- ).then(payResMap);
42
- }
43
- async function getWechatPayInfo({ sessionId, clientKey }, options) {
44
- return http.post(
45
- "/session/payments/query",
46
- {
47
- session_id: sessionId,
48
- client_key: clientKey,
49
- payment_method: PaymentMethod.WECHAT_PAY
50
- },
51
- options
52
- ).then(payResMap);
53
- }
5
+ const wechatPay = async (params, extraParams, options) => {
6
+ const paymentParams = buildPaymentParams(params, extraParams);
7
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
8
+ };
9
+ const getWechatPayInfo = async (params, extraParams, options) => {
10
+ const queryParams = buildQueryParams(params, extraParams);
11
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
12
+ };
54
13
  export {
55
14
  getWechatPayInfo,
56
15
  wechatPay
@@ -0,0 +1,16 @@
1
+ import { apiPrefix } from "../../../config.js";
2
+ import { http } from "../../http.js";
3
+ import { payResMap } from "../map.js";
4
+ import { buildPaymentParams, buildQueryParams } from "../../utils/index.js";
5
+ const zalopayPay = async (params, extraParams, options) => {
6
+ const paymentParams = buildPaymentParams(params, extraParams);
7
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
8
+ };
9
+ const getZalopayPayInfo = async (params, extraParams, options) => {
10
+ const queryParams = buildQueryParams(params, extraParams);
11
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
12
+ };
13
+ export {
14
+ getZalopayPayInfo,
15
+ zalopayPay
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
- import { cssVarPrefix, normalizedClass, formatAmount } from "../../utils/format.js";
7
- import { COMMON_CLASS_NAME, PaymentType } from "../../constant.js";
6
+ import { normalizedClass, formatAmount } from "../../utils/format.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,10 @@ 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
+ const { session, core, showEmail = false, showAddress = false } = props;
28
+ const addressCore = core.getAddressCore();
28
29
  const emailState = createEmailCore();
29
30
  const { setErrorMsg, i18n, errorMsg, sessionReady } = usePayState(session, props.core);
30
31
  const [submitButtonStatus, setSubmitButtonStatus] = h("unSubmit");
@@ -32,20 +33,20 @@ const AliPay = w((props, ref) => {
32
33
  const [form, setForm] = h({
33
34
  email: "",
34
35
  address: {
35
- country: "",
36
- province: "",
37
- city: "",
38
- area: "",
39
- postCode: "",
40
- address1: "",
41
- address2: ""
36
+ country: void 0,
37
+ province: void 0,
38
+ city: void 0,
39
+ area: void 0,
40
+ postCode: void 0,
41
+ address1: void 0,
42
+ address2: void 0
42
43
  }
43
44
  });
44
45
  const [validated, setValidated] = h(false);
45
- const disabledEmail = A(false);
46
- const [requiredBill, setRequiredBill] = h(false);
46
+ const [fieldStatus, setFieldStatus] = h();
47
47
  const addressFieldRef = A(null);
48
48
  const emailFieldRef = A(null);
49
+ const [isCheckoutEnabled, setIsCheckoutEnabled] = h(false);
49
50
  F(ref, () => ({
50
51
  stopRetry: () => {
51
52
  stopReFetchPayInfo();
@@ -56,48 +57,79 @@ const AliPay = w((props, ref) => {
56
57
  startReFetchPayInfo({ timeout });
57
58
  },
58
59
  updateAddress: () => {
59
- var _a2;
60
- setForm(Object.assign(form, { address: addressState.getAddressState() }));
61
- (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
60
+ var _a;
61
+ if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
62
+ return;
63
+ const newForm = Object.assign(form, { address: addressCore.getAddressState() });
64
+ setForm(newForm);
65
+ (_a = addressFieldRef.current) == null ? void 0 : _a.update(addressCore.getAddressState());
66
+ validateForm();
62
67
  },
63
68
  updateEmail: () => {
64
- var _a2;
65
- setForm(Object.assign(form, { email: emailState.email }));
66
- (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
69
+ var _a;
70
+ if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
71
+ return;
72
+ const newForm = Object.assign(form, { email: emailState.email });
73
+ setForm(newForm);
74
+ (_a = emailFieldRef.current) == null ? void 0 : _a.update(emailState.email);
75
+ validateForm();
67
76
  }
68
77
  }));
69
78
  function validateForm() {
70
- var _a2;
71
- (_a2 = formRef.current) == null ? void 0 : _a2.validate(void 0, false).then(() => {
79
+ var _a;
80
+ (_a = formRef.current) == null ? void 0 : _a.validate(void 0, false).then(() => {
72
81
  setValidated(true);
73
82
  }).catch(() => {
74
83
  setValidated(false);
75
84
  });
76
85
  }
86
+ const initFieldStatus = () => {
87
+ const { field, sessionMode } = session.checkout;
88
+ const { email, address } = field;
89
+ if (sessionMode === SessionMode.COMPONENT) {
90
+ if (email.disabled) {
91
+ email.show = showEmail;
92
+ }
93
+ if (showAddress && !(address == null ? void 0 : address.show)) {
94
+ address.show = true;
95
+ }
96
+ }
97
+ setFieldStatus({ ...field });
98
+ };
77
99
  y(() => {
78
100
  validateForm();
79
101
  }, [form]);
102
+ const processOnSuccess = (res) => {
103
+ var _a, _b;
104
+ setSubmitButtonStatus("success");
105
+ (_b = props.onSuccess) == null ? void 0 : _b.call(
106
+ props,
107
+ formatPaymentResult({
108
+ ...res,
109
+ returnUrl: (_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.returnUrl
110
+ })
111
+ );
112
+ };
80
113
  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);
114
+ if (!sessionReady) {
115
+ return;
93
116
  }
117
+ const { bill = {}, supportMethods = [], country } = (session == null ? void 0 : session.checkout) || {};
118
+ if (!supportMethods.includes(PaymentMethod.ALI_PAY)) {
119
+ return;
120
+ }
121
+ initFieldStatus();
122
+ setIsCheckoutEnabled(true);
123
+ country && addressCore.setCountry(country);
124
+ form.email = bill.email ?? "";
125
+ form.address.country = country;
94
126
  }, [sessionReady]);
95
127
  const onTimeout = q(
96
128
  (message) => {
97
- var _a2;
129
+ var _a;
98
130
  setErrorMsg(message || i18n.get("common.payTimeout"));
99
131
  setSubmitButtonStatus("unSubmit");
100
- (_a2 = props.onTimeout) == null ? void 0 : _a2.call(props, "retry");
132
+ (_a = props.onTimeout) == null ? void 0 : _a.call(props, "retry");
101
133
  },
102
134
  [i18n, props.onTimeout]
103
135
  );
@@ -107,64 +139,77 @@ const AliPay = w((props, ref) => {
107
139
  onTimeout: () => onTimeout(i18n.get("common.queryTimeout"))
108
140
  }
109
141
  );
142
+ const getPaymentParams = async () => {
143
+ return {
144
+ sessionId: session.sessionId,
145
+ clientKey: session.clientKey,
146
+ bill: (fieldStatus == null ? void 0 : fieldStatus.address.show) ? {
147
+ email: form.email,
148
+ addressLine1: form.address.address1,
149
+ addressLine2: form.address.address2,
150
+ postalCode: form.address.postCode,
151
+ country: form.address.country,
152
+ district: form.address.area,
153
+ state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
154
+ city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
155
+ } : {
156
+ email: form.email
157
+ },
158
+ payment: {
159
+ paymentMethod: PaymentMethod.ALI_PAY
160
+ },
161
+ browser: await getBrowserParams()
162
+ };
163
+ };
110
164
  async function pay(search = false, timeout) {
111
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
165
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
112
166
  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));
167
+ const requestOptions = { locale: i18n.locale, timeout };
168
+ let res = null;
169
+ if (search) {
170
+ const extraParams = (_b = (_a = core.config)._getExtraParams) == null ? void 0 : _b.call(_a, "query", PaymentMethod.ALI_PAY);
171
+ res = await getAliPayInfo(
172
+ {
173
+ sessionId: session.sessionId,
174
+ clientKey: session.clientKey,
175
+ paymentMethod: PaymentMethod.ALI_PAY
176
+ },
177
+ extraParams,
178
+ requestOptions
179
+ );
180
+ } else {
181
+ const extraParams = (_d = (_c = core.config)._getExtraParams) == null ? void 0 : _d.call(_c, "payment", PaymentMethod.ALI_PAY);
182
+ res = await aliPay(await getPaymentParams(), extraParams, requestOptions);
183
+ }
184
+ const { status, orderStatus, errorMessage, errorCode, sessionId } = res;
185
+ sessionId && (session.sessionId = sessionId);
186
+ !search && ((_e = props.onSubmitResponse) == null ? void 0 : _e.call(props, res));
140
187
  if (status === "PROCESSING") {
141
188
  if (!orderStatus) {
142
189
  setSubmitButtonStatus("unSubmit");
143
190
  return { end: true };
144
191
  } else if (orderStatus === "SUCCESS") {
145
- setSubmitButtonStatus("success");
146
- (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
192
+ processOnSuccess(res);
147
193
  return { end: true };
148
194
  } else if (orderStatus === "FAILURE") {
149
- setErrorMsg(errorMessage);
195
+ errorMessage && setErrorMsg(errorMessage);
150
196
  setSubmitButtonStatus("unSubmit");
151
- (_c2 = props.onError) == null ? void 0 : _c2.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
197
+ (_f = props.onError) == null ? void 0 : _f.call(props, new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
152
198
  return { end: true };
153
199
  } else if (orderStatus === "PROCESSING") {
154
200
  !search && startReFetchPayInfo();
155
201
  return { end: false };
156
202
  } else if (orderStatus === "CANCELED") {
157
203
  setSubmitButtonStatus("unSubmit");
158
- (_d2 = props.onTimeout) == null ? void 0 : _d2.call(props, "channel");
204
+ (_g = props.onTimeout) == null ? void 0 : _g.call(props, "channel");
159
205
  return { end: true };
160
206
  }
161
207
  } else if (status === "SUCCESS") {
162
- setSubmitButtonStatus("success");
163
- (_e2 = props.onSuccess) == null ? void 0 : _e2.call(props);
208
+ processOnSuccess(res);
164
209
  return { end: true };
165
210
  } else if (status === "EXPIRED") {
166
211
  setSubmitButtonStatus("unSubmit");
167
- (_f2 = props.onExpired) == null ? void 0 : _f2.call(props);
212
+ (_h = props.onExpired) == null ? void 0 : _h.call(props);
168
213
  return { end: true };
169
214
  }
170
215
  setSubmitButtonStatus("unSubmit");
@@ -179,20 +224,20 @@ const AliPay = w((props, ref) => {
179
224
  }
180
225
  } else {
181
226
  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 }));
227
+ message && setErrorMsg(message);
228
+ (_i = props.onError) == null ? void 0 : _i.call(props, new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
184
229
  setSubmitButtonStatus("unSubmit");
185
230
  return { end: true };
186
231
  }
187
232
  }
188
233
  }
189
234
  async function onSubmit() {
190
- var _a2;
235
+ var _a;
191
236
  setErrorMsg("");
192
- (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
193
- var _a3;
194
- requiredBill && addressState.setValidateAllFields(true);
195
- (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
237
+ (_a = formRef.current) == null ? void 0 : _a.validate(async (errors) => {
238
+ var _a2;
239
+ (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
240
+ (_a2 = props.onSubmit) == null ? void 0 : _a2.call(props, errors);
196
241
  if (errors) {
197
242
  setSubmitButtonStatus("unSubmit");
198
243
  return;
@@ -225,43 +270,45 @@ const AliPay = w((props, ref) => {
225
270
  formRef.current = dom;
226
271
  dom && validateForm();
227
272
  };
228
- const formStyle = {
229
- [cssVarPrefix("button-bg-color")]: (_a = session == null ? void 0 : session.colors) == null ? void 0 : _a.primary,
230
- [cssVarPrefix("button-bg-color-hover")]: (_b = session == null ? void 0 : session.colors) == null ? void 0 : _b.primaryHover,
231
- [cssVarPrefix("button-bg-color-active")]: (_c = session == null ? void 0 : session.colors) == null ? void 0 : _c.primaryActive,
232
- [cssVarPrefix("button-text-color")]: (_e = (_d = session == null ? void 0 : session.checkout) == null ? void 0 : _d.theme) == null ? void 0 : _e.payButtonTextColor,
233
- [cssVarPrefix("input-color")]: (_f = session == null ? void 0 : session.colors) == null ? void 0 : _f.primary
273
+ const Email = () => {
274
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.email.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
275
+ EmailField,
276
+ {
277
+ ref: emailFieldRef,
278
+ value: form.email,
279
+ disabled: fieldStatus == null ? void 0 : fieldStatus.email.disabled
280
+ }
281
+ ) }) });
282
+ };
283
+ const Address = () => {
284
+ var _a, _b;
285
+ return /* @__PURE__ */ u(b, { children: (fieldStatus == null ? void 0 : fieldStatus.address.show) && /* @__PURE__ */ u("div", { className: fieldClassNames, children: /* @__PURE__ */ u(
286
+ AddressField,
287
+ {
288
+ ref: addressFieldRef,
289
+ value: form.address,
290
+ country: ((_a = session == null ? void 0 : session.checkout) == null ? void 0 : _a.country) || ((_b = session == null ? void 0 : session.checkout) == null ? void 0 : _b.bill.country),
291
+ onAddressChange: (value) => setForm(Object.assign(form, { address: value }))
292
+ }
293
+ ) }) });
234
294
  };
235
295
  return /* @__PURE__ */ u(
236
296
  CoreContext.Provider,
237
297
  {
238
298
  value: {
239
299
  i18n,
240
- session
300
+ session,
301
+ core
241
302
  },
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
- ),
303
+ children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u("div", { className: core.theme.className, children: /* @__PURE__ */ u(Form, { form, ref: setFormRef, onFormChange: (form2) => setForm(form2), children: /* @__PURE__ */ u("div", { className: normalizedClass(COMMON_CLASS_NAME, bem()), children: [
304
+ Email(),
305
+ Address(),
261
306
  (session == null ? void 0 : session.checkout.paymentType) === PaymentType.RECURRING && RecurringTip(),
262
- !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
263
- Button()
264
- ] }) })
307
+ /* @__PURE__ */ u("div", { className: bem("footer-wrapper"), children: [
308
+ !!errorMsg && /* @__PURE__ */ u(Info, { className: bem("error"), content: errorMsg }),
309
+ Button()
310
+ ] })
311
+ ] }) }) })
265
312
  }
266
313
  );
267
314
  });