@paykka/card-checkout-ui 0.11.6 → 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 (187) 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 +11 -9
  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 +0 -4
  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/style.css +1 -1
  90. package/dist/types/api/modules/address/index.d.ts +15 -6
  91. package/dist/types/api/modules/ali-pay/index.d.ts +3 -19
  92. package/dist/types/api/modules/apple-pay/index.d.ts +4 -14
  93. package/dist/types/api/modules/boost/index.d.ts +3 -23
  94. package/dist/types/api/modules/card/index.d.ts +3 -30
  95. package/dist/types/api/modules/checkout/index.d.ts +3 -3
  96. package/dist/types/api/modules/checkout/map.d.ts +3 -3
  97. package/dist/types/api/modules/checkout/type.d.ts +33 -4
  98. package/dist/types/api/modules/gcash/index.d.ts +3 -23
  99. package/dist/types/api/modules/google-pay/index.d.ts +3 -13
  100. package/dist/types/api/modules/grab-pay/index.d.ts +3 -23
  101. package/dist/types/api/modules/index.d.ts +1 -0
  102. package/dist/types/api/modules/line-pay/index.d.ts +3 -23
  103. package/dist/types/api/modules/map.d.ts +2 -2
  104. package/dist/types/api/modules/may-bank-qr-pay/index.d.ts +3 -23
  105. package/dist/types/api/modules/nine-pay/index.d.ts +3 -23
  106. package/dist/types/api/modules/paymaya/index.d.ts +3 -23
  107. package/dist/types/api/modules/sepa/index.d.ts +3 -24
  108. package/dist/types/api/modules/shopee-pay/index.d.ts +3 -23
  109. package/dist/types/api/modules/tng-wallet/index.d.ts +3 -23
  110. package/dist/types/api/modules/type.d.ts +74 -21
  111. package/dist/types/api/modules/wechat-pay/index.d.ts +3 -20
  112. package/dist/types/api/modules/zalopay/index.d.ts +4 -0
  113. package/dist/types/api/utils/index.d.ts +48 -0
  114. package/dist/types/components/AddressField/type.d.ts +3 -9
  115. package/dist/types/components/AliPay/AliPay.d.ts +6 -2
  116. package/dist/types/components/AliPay/type.d.ts +15 -2
  117. package/dist/types/components/ApplePay/ApplePay.d.ts +6 -2
  118. package/dist/types/components/ApplePay/type.d.ts +10 -14
  119. package/dist/types/components/ApplePay/utils.d.ts +1 -1
  120. package/dist/types/components/Boost/Boost.d.ts +6 -2
  121. package/dist/types/components/Boost/type.d.ts +2 -24
  122. package/dist/types/components/Card/Card.d.ts +6 -2
  123. package/dist/types/components/Card/type.d.ts +3 -43
  124. package/dist/types/components/DropIn/DropIn.d.ts +6 -2
  125. package/dist/types/components/DropIn/type.d.ts +4 -10
  126. package/dist/types/components/GooglePay/GooglePay.d.ts +6 -2
  127. package/dist/types/components/GooglePay/createGooglePay.d.ts +2 -1
  128. package/dist/types/components/GooglePay/type.d.ts +10 -26
  129. package/dist/types/components/GrabPay/GrabPay.d.ts +6 -2
  130. package/dist/types/components/GrabPay/type.d.ts +3 -25
  131. package/dist/types/components/LinePay/LinePay.d.ts +6 -2
  132. package/dist/types/components/LinePay/type.d.ts +3 -25
  133. package/dist/types/components/MayBankQRPay/MayBankQRPay.d.ts +6 -2
  134. package/dist/types/components/MayBankQRPay/type.d.ts +3 -25
  135. package/dist/types/components/NinePay/NinePay.d.ts +6 -2
  136. package/dist/types/components/NinePay/type.d.ts +3 -25
  137. package/dist/types/components/Sepa/Sepa.d.ts +6 -2
  138. package/dist/types/components/Sepa/type.d.ts +3 -2
  139. package/dist/types/components/ShopeePay/ShopeePay.d.ts +6 -2
  140. package/dist/types/components/ShopeePay/type.d.ts +3 -25
  141. package/dist/types/components/TNGWallet/TNGWallet.d.ts +6 -2
  142. package/dist/types/components/TNGWallet/type.d.ts +3 -25
  143. package/dist/types/components/WechatPay/WechatPay.d.ts +6 -2
  144. package/dist/types/components/WechatPay/type.d.ts +15 -2
  145. package/dist/types/components/business/QRCodeModal/type.d.ts +2 -0
  146. package/dist/types/components/index.d.ts +1 -0
  147. package/dist/types/components/internal/icons/IconZalopay.d.ts +2 -0
  148. package/dist/types/components/internal/icons/IconZalopayComplete.d.ts +2 -0
  149. package/dist/types/components/internal/icons/index.d.ts +3 -0
  150. package/dist/types/components/wallets/GCash/GCash.d.ts +6 -2
  151. package/dist/types/components/wallets/GCash/type.d.ts +3 -35
  152. package/dist/types/components/wallets/Paymaya/Paymaya.d.ts +6 -2
  153. package/dist/types/components/wallets/Paymaya/type.d.ts +3 -25
  154. package/dist/types/components/wallets/Zalopay/Zalopay.d.ts +10 -0
  155. package/dist/types/components/wallets/Zalopay/index.d.ts +2 -0
  156. package/dist/types/components/wallets/Zalopay/type.d.ts +39 -0
  157. package/dist/types/config.d.ts +2 -4
  158. package/dist/types/constant.d.ts +3 -1
  159. package/dist/types/core/{Address.d.ts → address.d.ts} +23 -24
  160. package/dist/types/core/{PayKKaCheckout.d.ts → checkout.d.ts} +5 -3
  161. package/dist/types/core/context.d.ts +3 -2
  162. package/dist/types/core/index.d.ts +2 -2
  163. package/dist/types/core/query.d.ts +2 -2
  164. package/dist/types/core/session.d.ts +33 -0
  165. package/dist/types/hooks/index.d.ts +1 -0
  166. package/dist/types/hooks/usePayment.d.ts +8 -0
  167. package/dist/types/i18n/locales/de-DE.d.ts +2 -0
  168. package/dist/types/i18n/locales/en-GB.d.ts +2 -0
  169. package/dist/types/i18n/locales/es-ES.d.ts +2 -0
  170. package/dist/types/i18n/locales/fr-FR.d.ts +2 -0
  171. package/dist/types/i18n/locales/ja-JP.d.ts +2 -0
  172. package/dist/types/i18n/locales/ko-KR.d.ts +2 -0
  173. package/dist/types/i18n/locales/nl-NL.d.ts +2 -0
  174. package/dist/types/i18n/locales/pt-PT.d.ts +2 -0
  175. package/dist/types/i18n/locales/ru-RU.d.ts +2 -0
  176. package/dist/types/i18n/locales/zh-CN.d.ts +2 -0
  177. package/dist/types/i18n/locales/zh-HK.d.ts +2 -0
  178. package/dist/types/i18n/locales/zh-TW.d.ts +2 -0
  179. package/dist/types/index.d.ts +2 -1
  180. package/dist/types/types/index.d.ts +70 -32
  181. package/dist/types/types/message.d.ts +1 -0
  182. package/dist/types/utils/card-brand/index.d.ts +3 -3
  183. package/dist/types/utils/colors.d.ts +1 -0
  184. package/dist/types/utils/index.d.ts +1 -0
  185. package/dist/types/utils/payment.d.ts +37 -0
  186. package/package.json +3 -3
  187. package/dist/types/core/Session.d.ts +0 -16
@@ -1,3 +1,4 @@
1
1
  import "./http.js";
2
2
  import "../utils/card-brand/brands.js";
3
3
  import "../utils/system-info/get-browser-info.js";
4
+ import "../core.js";
@@ -1,7 +1,7 @@
1
1
  import { mergeAsyncFn } from "../../../utils/merge-async-fn.js";
2
2
  import { http } from "../../http.js";
3
3
  import { addressItemMap } from "./map.js";
4
- async function getCountry(options) {
4
+ const getCountry = async (options) => {
5
5
  return http.get("/pub/datadict/get/COUNTRY", void 0, options).then((res) => {
6
6
  var _a;
7
7
  const { values } = res;
@@ -10,12 +10,12 @@ async function getCountry(options) {
10
10
  value: item.value
11
11
  }))) ?? [];
12
12
  });
13
- }
14
- async function getAddressFormat(countryCode, options) {
15
- return http.post(`/address/style/${countryCode}`, void 0, options).then(({ address_style_list }) => {
13
+ };
14
+ const getAddressFormat = async (country, options) => {
15
+ return http.post(`/address/style/${country}`, void 0, options).then(({ address_style_list }) => {
16
16
  return address_style_list.map((item) => addressItemMap(item));
17
17
  });
18
- }
18
+ };
19
19
  const mergedGetAddressFormat = mergeAsyncFn(getAddressFormat, {
20
20
  argsResolver(items) {
21
21
  return items == null ? void 0 : items[0].args;
@@ -24,7 +24,7 @@ const mergedGetAddressFormat = mergeAsyncFn(getAddressFormat, {
24
24
  return result;
25
25
  }
26
26
  });
27
- async function getProvince(country, options) {
27
+ const getProvince = async (country, options) => {
28
28
  return http.post(`/address/province-dict/${country}`, void 0, options).then((res) => {
29
29
  var _a;
30
30
  return (_a = res == null ? void 0 : res.map) == null ? void 0 : _a.call(res, ({ code, description }) => {
@@ -34,7 +34,7 @@ async function getProvince(country, options) {
34
34
  };
35
35
  });
36
36
  });
37
- }
37
+ };
38
38
  const mergedGetProvince = mergeAsyncFn(getProvince, {
39
39
  argsResolver(items) {
40
40
  return items == null ? void 0 : items[0].args;
@@ -43,7 +43,7 @@ const mergedGetProvince = mergeAsyncFn(getProvince, {
43
43
  return result;
44
44
  }
45
45
  });
46
- async function getCity(province) {
46
+ const getCity = async (province) => {
47
47
  return http.post(`/address/city-dict/${province}`).then((res) => {
48
48
  var _a;
49
49
  return (_a = res == null ? void 0 : res.map) == null ? void 0 : _a.call(res, ({ code, description }) => {
@@ -53,7 +53,7 @@ async function getCity(province) {
53
53
  };
54
54
  });
55
55
  });
56
- }
56
+ };
57
57
  export {
58
58
  getCity,
59
59
  getCountry,
@@ -1,54 +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 aliPay({
9
- sessionId,
10
- clientKey,
11
- bill
12
- }, core, options) {
13
- const { _getExtraParams } = core.config;
14
- const extraParams = _getExtraParams == null ? void 0 : _getExtraParams("payment", PaymentMethod.ALI_PAY);
15
- const params = deepMerge({
16
- bill: {
17
- email: bill.email,
18
- country: bill.country,
19
- state: bill.province,
20
- city: bill.city,
21
- postal_code: bill.postCode,
22
- address_line1: bill.address1,
23
- address_line2: bill.address2,
24
- county: bill.area
25
- }
26
- }, extraParams || {});
27
- return http.post(
28
- "/session/payments",
29
- {
30
- ...params,
31
- session_id: sessionId,
32
- client_key: clientKey,
33
- payment: {
34
- payment_method: PaymentMethod.ALI_PAY
35
- },
36
- browser: await getBrowserParams()
37
- },
38
- options
39
- ).then(payResMap);
40
- }
41
- async function getAliPayInfo({ sessionId, clientKey }, options) {
42
- return http.post(
43
- "/session/payments/query",
44
- {
45
- session_id: sessionId,
46
- client_key: clientKey,
47
- payment_method: PaymentMethod.ALI_PAY
48
- },
49
- options
50
- ).then(payResMap);
51
- }
5
+ const aliPay = async (params, extraParams, options) => {
6
+ const paymentParams = buildPaymentParams(params, extraParams);
7
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
8
+ };
9
+ const getAliPayInfo = async (params, extraParams, options) => {
10
+ const queryParams = buildQueryParams(params, extraParams);
11
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
12
+ };
52
13
  export {
53
14
  aliPay,
54
15
  getAliPayInfo
@@ -1,64 +1,18 @@
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";
3
+ import { buildPaymentParams, buildQueryParams } from "../../utils/index.js";
6
4
  import { payResMap } from "../map.js";
7
- async function getMerchantSession(options) {
8
- return http.post(`/session/apple-pay/create-session`, options);
9
- }
10
- async function applePay({
11
- sessionId,
12
- clientKey,
13
- token,
14
- bill,
15
- browser
16
- }, core, options) {
17
- const { _getExtraParams } = core.config;
18
- const extraParams = _getExtraParams == null ? void 0 : _getExtraParams("payment", PaymentMethod.APPLE_PAY);
19
- const params = deepMerge({
20
- bill: {
21
- first_name: bill == null ? void 0 : bill.firstName,
22
- middle_name: bill == null ? void 0 : bill.middleName,
23
- last_name: bill == null ? void 0 : bill.lastName,
24
- address_line1: bill == null ? void 0 : bill.addressLine1,
25
- address_line2: bill == null ? void 0 : bill.addressLine2,
26
- country: bill == null ? void 0 : bill.country,
27
- state: bill == null ? void 0 : bill.state,
28
- city: bill == null ? void 0 : bill.city,
29
- email: bill == null ? void 0 : bill.email,
30
- postal_code: bill == null ? void 0 : bill.postalCode,
31
- area_code: bill == null ? void 0 : bill.areaCode,
32
- phone_number: bill == null ? void 0 : bill.phoneNumber,
33
- descriptor: bill == null ? void 0 : bill.descriptor
34
- }
35
- }, extraParams || {});
36
- return http.post(
37
- "/session/payments",
38
- {
39
- ...params,
40
- session_id: sessionId,
41
- client_key: clientKey,
42
- payment: {
43
- payment_method: PaymentMethod.APPLE_PAY,
44
- token_data: token
45
- },
46
- browser
47
- },
48
- options
49
- ).then(payResMap);
50
- }
51
- async function getApplePayInfo({ sessionId, clientKey }, options) {
52
- return http.post(
53
- "/session/payments/query",
54
- {
55
- session_id: sessionId,
56
- client_key: clientKey,
57
- payment_method: PaymentMethod.APPLE_PAY
58
- },
59
- options
60
- ).then(payResMap);
61
- }
5
+ const getMerchantSession = async (options) => {
6
+ return http.post(`${apiPrefix}/apple-pay/create-session`, options);
7
+ };
8
+ const applePay = async (params, extraParams, options) => {
9
+ const paymentParams = buildPaymentParams(params, extraParams);
10
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
11
+ };
12
+ const getApplePayInfo = async (params, extraParams, options) => {
13
+ const queryParams = buildQueryParams(params, extraParams);
14
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
15
+ };
62
16
  export {
63
17
  applePay,
64
18
  getApplePayInfo,
@@ -1,54 +1,14 @@
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";
5
1
  import { http } from "../../http.js";
6
2
  import { payResMap } from "../map.js";
7
- const boostPay = async ({
8
- sessionId,
9
- clientKey,
10
- payment,
11
- bill,
12
- browser
13
- }, core, options) => {
14
- const { _getExtraParams } = core.config;
15
- const extraParams = _getExtraParams == null ? void 0 : _getExtraParams("payment", payment.paymentMethod);
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: payment.paymentMethod
36
- },
37
- browser
38
- },
39
- options
40
- ).then(payResMap);
3
+ import { apiPrefix } from "../../../config.js";
4
+ import { buildPaymentParams, buildQueryParams } from "../../utils/index.js";
5
+ const boostPay = async (params, extraParams, options) => {
6
+ const paymentParams = buildPaymentParams(params, extraParams);
7
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
41
8
  };
42
- const getBoostPayInfo = async ({ sessionId, clientKey }, options) => {
43
- return http.post(
44
- "/session/payments/query",
45
- {
46
- session_id: sessionId,
47
- client_key: clientKey,
48
- payment_method: PaymentMethod.BOOST
49
- },
50
- options
51
- ).then(payResMap);
9
+ const getBoostPayInfo = async (params, extraParams, options) => {
10
+ const queryParams = buildQueryParams(params, extraParams);
11
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
52
12
  };
53
13
  export {
54
14
  boostPay,
@@ -1,59 +1,15 @@
1
- import "../../../utils/card-brand/brands.js";
2
- import "../../../utils/system-info/get-browser-info.js";
3
- import { deepMerge } from "../../../utils/object.js";
1
+ import { apiPrefix } from "../../../config.js";
4
2
  import { http } from "../../http.js";
3
+ import { buildPaymentParams, buildQueryParams } from "../../utils/index.js";
5
4
  import { payResMap } from "../map.js";
6
- async function cardPay({
7
- sessionId,
8
- clientKey,
9
- payment,
10
- bill,
11
- browser
12
- }, extraParams, options) {
13
- const params = deepMerge({
14
- bill: {
15
- email: bill.email,
16
- country: bill.country,
17
- state: bill.province,
18
- city: bill.city,
19
- postal_code: bill.postCode,
20
- address_line1: bill.address1,
21
- address_line2: bill.address2,
22
- county: bill.area
23
- }
24
- }, extraParams || {});
25
- return http.post(
26
- "/session/payments",
27
- {
28
- ...params,
29
- session_id: sessionId,
30
- client_key: clientKey,
31
- payment: {
32
- payment_method: payment.paymentMethod,
33
- card_no: payment.cardNo,
34
- exp_year: payment.expYear,
35
- exp_month: payment.expMonth,
36
- cvv: payment.cvv,
37
- holder_name: payment.holderName,
38
- store_payment_method: payment.storePaymentMethod,
39
- token_usage: payment.tokenUsage,
40
- token: payment.token
41
- },
42
- browser
43
- },
44
- options
45
- ).then(payResMap);
46
- }
47
- async function getCardPayInfo({ sessionId, clientKey }, options) {
48
- return http.post(
49
- "/session/payments/query",
50
- {
51
- session_id: sessionId,
52
- client_key: clientKey
53
- },
54
- options
55
- ).then(payResMap);
56
- }
5
+ const cardPay = async (params, extraParams, options) => {
6
+ const paymentParams = buildPaymentParams(params, extraParams);
7
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
8
+ };
9
+ const getCardPayInfo = async (params, extraParams, options) => {
10
+ const queryParams = buildQueryParams(params, extraParams);
11
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
12
+ };
57
13
  export {
58
14
  cardPay,
59
15
  getCardPayInfo
@@ -1,25 +1,27 @@
1
1
  import { RequestCacheManager } from "../../../utils/request-cache-manager.js";
2
+ import { apiPrefix } from "../../../config.js";
2
3
  import { http } from "../../http.js";
3
4
  import { getBrowserParams } from "../get-browser-params.js";
4
5
  import { checkoutMap } from "./map.js";
5
- const queryCheckout = async ({ sessionId, clientKey }, options) => {
6
+ const queryCheckout = async (params, extraParams = {}, options) => {
6
7
  return http.post(
7
- "/session/info",
8
+ `${apiPrefix}/info`,
8
9
  {
9
- session_id: sessionId,
10
- client_key: clientKey,
10
+ session_id: params.sessionId,
11
+ client_key: params.clientKey,
12
+ ...extraParams,
11
13
  browser: await getBrowserParams()
12
14
  },
13
15
  options
14
16
  );
15
17
  };
16
- const getCheckoutInfo = async ({ sessionId, clientKey }, options) => {
17
- const checkoutInfo = await queryCheckout({ sessionId, clientKey }, options);
18
- return checkoutMap({ ...checkoutInfo, ...checkoutInfo == null ? void 0 : checkoutInfo.support_methods });
18
+ const getCheckoutInfo = async (params, extraParams = {}, options) => {
19
+ const checkoutInfo = await queryCheckout(params, extraParams, options);
20
+ return checkoutMap(checkoutInfo);
19
21
  };
20
22
  const requestCacheManager = new RequestCacheManager();
21
- const onceGetCheckoutInfo = async (params, options) => {
22
- const request = getCheckoutInfo(params, options);
23
+ const onceGetCheckoutInfo = async (params, extraParams = {}, options) => {
24
+ const request = getCheckoutInfo(params, extraParams, options);
23
25
  return requestCacheManager.cacheRequest(JSON.stringify(params), request);
24
26
  };
25
27
  export {
@@ -1,7 +1,7 @@
1
1
  import { PaymentMethod } from "../../../constant.js";
2
2
  import { amountMap } from "../map.js";
3
- function formatPaymentMethodInfo(paymentMethods = []) {
4
- const paymentMethod = [];
3
+ const formatPaymentMethodInfo = (paymentMethods = []) => {
4
+ const supportMethods = [];
5
5
  const channelParams = {};
6
6
  paymentMethods.forEach(({ value, configuration = {} }) => {
7
7
  if (value === PaymentMethod.APPLE_PAY) {
@@ -38,17 +38,17 @@ function formatPaymentMethodInfo(paymentMethods = []) {
38
38
  };
39
39
  }
40
40
  if (value === PaymentMethod.BANKCARD) {
41
- paymentMethod.push(...configuration.allowed_card_networks || []);
41
+ supportMethods.push(...configuration.allowed_card_networks || []);
42
42
  } else {
43
- paymentMethod.push(value);
43
+ supportMethods.push(value);
44
44
  }
45
45
  });
46
46
  return {
47
- paymentMethod,
47
+ supportMethods,
48
48
  channelParams
49
49
  };
50
- }
51
- function formatAmountBreakdown(info = {}) {
50
+ };
51
+ const formatAmountBreakdown = (info = {}) => {
52
52
  return {
53
53
  goodsTax: amountMap(info.goods_tax),
54
54
  shippingAmount: amountMap(info.shipping_amount),
@@ -56,10 +56,11 @@ function formatAmountBreakdown(info = {}) {
56
56
  discount: amountMap(info.discount),
57
57
  other: amountMap(info.other)
58
58
  };
59
- }
60
- function checkoutMap(res = {}) {
61
- var _a, _b, _c;
62
- const { theme, bill, payment_methods, field } = res;
59
+ };
60
+ const checkoutMap = (res = {}) => {
61
+ var _a, _b;
62
+ const { theme, field, support_methods = {} } = res;
63
+ const { payment_methods, bill, tokens } = support_methods;
63
64
  const paymentMethodsInfo = formatPaymentMethodInfo(payment_methods);
64
65
  const sessionMode = res.session_mode === "HOST" ? "HOSTED" : res.session_mode;
65
66
  return {
@@ -69,13 +70,17 @@ function checkoutMap(res = {}) {
69
70
  status: res.status,
70
71
  transAmount: amountMap(res.trans_amount),
71
72
  expireTime: res.expire_time,
72
- sessionMode,
73
+ paymentMethod: res.payment_method,
74
+ // 兼容其他收银台,没有 session_mode 字段就默认 HOSTED
75
+ sessionMode: sessionMode || "HOSTED",
73
76
  merchantName: (_a = res.theme) == null ? void 0 : _a.merchant_name,
74
77
  returnUrl: res.return_url,
75
78
  cancelUrl: res.cancel_url,
76
79
  locale: res.locale,
77
- paymentType: res.payment_type,
78
- goods: res.goods ? res.goods : [],
80
+ // 兼容其他收银台,没有 payment_type 字段就默认 PURCHASE
81
+ paymentType: res.payment_type || "PURCHASE",
82
+ orderId: res.order_id,
83
+ goods: res.goods || [],
79
84
  theme: {
80
85
  merchantName: theme == null ? void 0 : theme.merchant_name,
81
86
  logo: theme == null ? void 0 : theme.logo,
@@ -91,13 +96,13 @@ function checkoutMap(res = {}) {
91
96
  descriptor: bill == null ? void 0 : bill.descriptor,
92
97
  country: bill == null ? void 0 : bill.country
93
98
  },
94
- tokens: (_b = res.tokens) == null ? void 0 : _b.map((card) => ({
99
+ tokens: tokens == null ? void 0 : tokens.map((card) => ({
95
100
  token: card.token,
96
101
  last4: card.last4,
97
102
  cardBrand: card.card_brand,
98
103
  billingAddressFilled: card.billing_address_filled
99
104
  })),
100
- storePaymentMethod: (_c = res.payment) == null ? void 0 : _c.store_payment_method,
105
+ storePaymentMethod: (_b = res.payment) == null ? void 0 : _b.store_payment_method,
101
106
  field: {
102
107
  holderName: {
103
108
  show: !!(field == null ? void 0 : field.holder_name_display),
@@ -114,9 +119,11 @@ function checkoutMap(res = {}) {
114
119
  }
115
120
  },
116
121
  amountBreakdown: formatAmountBreakdown(res.amount_breakdown),
117
- ...paymentMethodsInfo
122
+ finishTime: res.utc_finish_time,
123
+ ...paymentMethodsInfo,
124
+ rawResponse: res
118
125
  };
119
- }
126
+ };
120
127
  export {
121
128
  checkoutMap,
122
129
  formatPaymentMethodInfo
@@ -1,5 +1,6 @@
1
1
  import { intersection } from "../../../utils/index.js";
2
2
  import { http } from "../../http.js";
3
+ import "../../../core.js";
3
4
  import { formatPaymentMethodInfo } from "../checkout/map.js";
4
5
  import { cardBrandCodes } from "../../../utils/card-brand/brands.js";
5
6
  const verifyClientKey = async (clientKey, merchantId, options) => {
@@ -12,8 +13,8 @@ const verifyClientKey = async (clientKey, merchantId, options) => {
12
13
  options
13
14
  ).then((res) => {
14
15
  var _a;
15
- const { paymentMethod } = formatPaymentMethodInfo(((_a = res.support_methods) == null ? void 0 : _a.payment_methods) || []);
16
- const brands = intersection(cardBrandCodes, paymentMethod);
16
+ const { supportMethods } = formatPaymentMethodInfo(((_a = res.support_methods) == null ? void 0 : _a.payment_methods) || []);
17
+ const brands = intersection(cardBrandCodes, supportMethods);
17
18
  return {
18
19
  brands
19
20
  };
@@ -1,54 +1,14 @@
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";
3
+ import { buildPaymentParams, buildQueryParams } from "../../utils/index.js";
6
4
  import { payResMap } from "../map.js";
7
- const gcashPay = async ({
8
- sessionId,
9
- clientKey,
10
- payment,
11
- bill,
12
- browser
13
- }, core, options) => {
14
- const { _getExtraParams } = core.config;
15
- const extraParams = _getExtraParams == null ? void 0 : _getExtraParams("payment", payment.paymentMethod);
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: payment.paymentMethod
36
- },
37
- browser
38
- },
39
- options
40
- ).then(payResMap);
5
+ const gcashPay = async (params, extraParams, options) => {
6
+ const paymentParams = buildPaymentParams(params, extraParams);
7
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
41
8
  };
42
- const getGcashPayInfo = async ({ sessionId, clientKey }, options) => {
43
- return http.post(
44
- "/session/payments/query",
45
- {
46
- session_id: sessionId,
47
- client_key: clientKey,
48
- payment_method: PaymentMethod.GCASH
49
- },
50
- options
51
- ).then(payResMap);
9
+ const getGcashPayInfo = async (params, extraParams, options) => {
10
+ const queryParams = buildQueryParams(params, extraParams);
11
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
52
12
  };
53
13
  export {
54
14
  gcashPay,
@@ -1,61 +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";
3
+ import { buildPaymentParams, buildQueryParams } from "../../utils/index.js";
6
4
  import { payResMap } from "../map.js";
7
- async function googlePay({
8
- sessionId,
9
- clientKey,
10
- token,
11
- bill,
12
- browser
13
- }, core, options) {
14
- const { _getExtraParams } = core.config;
15
- const extraParams = _getExtraParams == null ? void 0 : _getExtraParams("payment", PaymentMethod.GOOGLE_PAY);
16
- const params = deepMerge({
17
- bill: {
18
- first_name: bill == null ? void 0 : bill.firstName,
19
- middle_name: bill == null ? void 0 : bill.middleName,
20
- last_name: bill == null ? void 0 : bill.lastName,
21
- address_line1: bill == null ? void 0 : bill.addressLine1,
22
- address_line2: bill == null ? void 0 : bill.addressLine2,
23
- country: bill == null ? void 0 : bill.country,
24
- state: bill == null ? void 0 : bill.state,
25
- city: bill == null ? void 0 : bill.city,
26
- email: bill == null ? void 0 : bill.email,
27
- postal_code: bill == null ? void 0 : bill.postalCode,
28
- area_code: bill == null ? void 0 : bill.areaCode,
29
- phone_number: bill == null ? void 0 : bill.phoneNumber,
30
- descriptor: bill == null ? void 0 : bill.descriptor
31
- }
32
- }, extraParams || {});
33
- return http.post(
34
- "/session/payments",
35
- {
36
- ...params,
37
- session_id: sessionId,
38
- client_key: clientKey,
39
- payment: {
40
- payment_method: PaymentMethod.GOOGLE_PAY,
41
- token_data: token
42
- },
43
- browser
44
- },
45
- options
46
- ).then(payResMap);
47
- }
48
- async function getGooglePayInfo({ sessionId, clientKey }, options) {
49
- return http.post(
50
- "/session/payments/query",
51
- {
52
- session_id: sessionId,
53
- client_key: clientKey,
54
- payment_method: PaymentMethod.GOOGLE_PAY
55
- },
56
- options
57
- ).then(payResMap);
58
- }
5
+ const googlePay = async (params, extraParams, options) => {
6
+ const paymentParams = buildPaymentParams(params, extraParams);
7
+ return http.post(`${apiPrefix}/payments`, paymentParams, options).then(payResMap);
8
+ };
9
+ const getGooglePayInfo = async (params, extraParams, options) => {
10
+ const queryParams = buildQueryParams(params, extraParams);
11
+ return http.post(`${apiPrefix}/payments/query`, queryParams, options).then(payResMap);
12
+ };
59
13
  export {
60
14
  getGooglePayInfo,
61
15
  googlePay