@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
@@ -22,10 +22,14 @@ var __privateSet = (obj, member, value, setter) => {
22
22
  setter ? setter.call(obj, value) : member.set(obj, value);
23
23
  return value;
24
24
  };
25
- var _config, _envConfig, _session, _componentInsts;
25
+ var __privateMethod = (obj, member, method) => {
26
+ __accessCheck(obj, member, "access private method");
27
+ return method;
28
+ };
29
+ var _id, _config, _envConfig, _session, _theme, _componentInsts, _addressCore, _initPromise, _doInit, doInit_fn;
26
30
  import { create } from "./create.js";
27
- import { Session } from "./Session.js";
28
- import { setApiUrl, setCDNUrl, setFraudDetectionEnv, setCheckoutConfig, setCustomLocale } from "../config.js";
31
+ import { Session } from "./session.js";
32
+ import { setApiPrefix, setApiUrl, setCDNUrl, setFraudDetectionEnv, setCustomLocale } from "../config.js";
29
33
  import { PayKKaError } from "./error.js";
30
34
  import { apiEnv, cdnEnv, fraudDetectionEnv } from "./environment.js";
31
35
  import "../api/http.js";
@@ -33,14 +37,37 @@ import { isEmptyObject } from "../utils/is.js";
33
37
  import "../utils/card-brand/brands.js";
34
38
  import "../utils/system-info/get-browser-info.js";
35
39
  import { getUrlParam } from "../utils/location.js";
40
+ import { deepMerge } from "../utils/object.js";
41
+ import { genShortId } from "../utils/string.js";
36
42
  import { d } from "../core.js";
43
+ import { AddressCore } from "./address.js";
44
+ import { PayKKaTheme } from "./theme.js";
37
45
  const PROCESSING_PARAM_NAME = "m";
46
+ const DEFAULT_CHECKOUT_CONFIG = {
47
+ enableInitValidation: true,
48
+ apiPrefix: "/session",
49
+ addressMode: "address"
50
+ };
38
51
  class PayKKaCheckout {
39
52
  constructor(config) {
53
+ __privateAdd(this, _doInit);
54
+ /**
55
+ * 收银台实例 ID
56
+ * 用于标识收银台实例,防止主题样式、iframe 通信数据等在不同收银台之间相互影响
57
+ */
58
+ __privateAdd(this, _id, void 0);
40
59
  __privateAdd(this, _config, void 0);
41
60
  __privateAdd(this, _envConfig, void 0);
42
61
  __privateAdd(this, _session, void 0);
62
+ __privateAdd(this, _theme, void 0);
43
63
  __privateAdd(this, _componentInsts, []);
64
+ /**
65
+ * 地址处理
66
+ * 与 session 一样,我们要保证 addressCore 在 PayKKaCheckout 实例中保持唯一
67
+ */
68
+ __privateAdd(this, _addressCore, void 0);
69
+ /** 初始化状态标志,防止重复初始化 */
70
+ __privateAdd(this, _initPromise, void 0);
44
71
  // TODO: 这俩属性不应该放在这里,但他们是在 PayKKaCheckout 实例中保持唯一的数据,还没想好放哪里
45
72
  /** 当前正在处理的支付方式,在第三方支付页面跳回收银台时,会通过 url 参数传递过来 */
46
73
  __publicField(this, "processingPaymentMethod", null);
@@ -49,35 +76,55 @@ class PayKKaCheckout {
49
76
  * 在 DropIn 且有正在处理的支付方式时,会设置为当前支付方式,并把其他支付方式设为禁用
50
77
  */
51
78
  __publicField(this, "enablePaymentMethod", d(null));
79
+ __privateSet(this, _id, genShortId(6));
52
80
  __privateSet(this, _config, config);
53
81
  this.init();
54
82
  }
55
- init() {
56
- this.initEnv();
57
- this.initLocale();
58
- this.initExtraParams();
59
- this.initSession();
60
- this.initOtherData();
61
- }
62
- initSession() {
63
- const { sessionId, clientKey, onPaymentMethodsReady, onInitError, onSuccess } = __privateGet(this, _config);
64
- if (!sessionId) {
65
- onInitError == null ? void 0 : onInitError(new PayKKaError("ERROR", "SessionId is required"));
66
- return;
83
+ async init() {
84
+ if (__privateGet(this, _initPromise)) {
85
+ return __privateGet(this, _initPromise);
67
86
  }
68
- __privateSet(this, _session, new Session(sessionId, clientKey));
69
- __privateGet(this, _session).ready().then(() => {
70
- var _a, _b;
71
- if (isEmptyObject((_a = __privateGet(this, _session)) == null ? void 0 : _a.checkout)) {
87
+ __privateSet(this, _initPromise, __privateMethod(this, _doInit, doInit_fn).call(this));
88
+ return __privateGet(this, _initPromise);
89
+ }
90
+ initCheckoutConfig() {
91
+ __privateGet(this, _config)._checkoutConfig = deepMerge(
92
+ DEFAULT_CHECKOUT_CONFIG,
93
+ __privateGet(this, _config)._checkoutConfig || {}
94
+ );
95
+ setApiPrefix(__privateGet(this, _config)._checkoutConfig.apiPrefix);
96
+ }
97
+ async initSession() {
98
+ var _a, _b;
99
+ const {
100
+ sessionId,
101
+ clientKey,
102
+ onPaymentMethodsReady,
103
+ onInitError,
104
+ onSuccess,
105
+ _checkoutConfig = {}
106
+ } = __privateGet(this, _config);
107
+ const { enableInitValidation } = _checkoutConfig;
108
+ if (enableInitValidation) {
109
+ if (!sessionId) {
110
+ onInitError == null ? void 0 : onInitError(new PayKKaError("ERROR", "SessionId is required"));
111
+ return;
112
+ }
113
+ }
114
+ const extraParams = (_b = (_a = __privateGet(this, _config))._getExtraParams) == null ? void 0 : _b.call(_a, "info");
115
+ __privateSet(this, _session, new Session({ sessionId, clientKey }, extraParams));
116
+ return __privateGet(this, _session).ready().then(() => {
117
+ var _a2, _b2;
118
+ if (isEmptyObject((_a2 = __privateGet(this, _session)) == null ? void 0 : _a2.checkout)) {
72
119
  onInitError == null ? void 0 : onInitError(new PayKKaError("ERROR", "Checkout is empty"));
73
120
  return;
74
121
  }
75
- const { paymentMethod = [], status } = ((_b = __privateGet(this, _session)) == null ? void 0 : _b.checkout) || {};
122
+ const { supportMethods = [], status } = ((_b2 = __privateGet(this, _session)) == null ? void 0 : _b2.checkout) || {};
76
123
  if (status === "SUCCESS") {
77
124
  onSuccess == null ? void 0 : onSuccess({});
78
125
  return;
79
126
  }
80
- onPaymentMethodsReady == null ? void 0 : onPaymentMethodsReady(paymentMethod);
127
+ onPaymentMethodsReady == null ? void 0 : onPaymentMethodsReady(supportMethods);
81
128
  }).catch((error) => {
82
129
  onInitError == null ? void 0 : onInitError(error);
83
130
  });
@@ -100,9 +147,10 @@ class PayKKaCheckout {
100
147
  const { locale } = __privateGet(this, _config);
101
148
  locale && setCustomLocale(locale);
102
149
  }
103
- initExtraParams() {
104
- const { hidePaymentButton = false } = __privateGet(this, _config);
105
- setCheckoutConfig({ hidePaymentButton });
150
+ initTheme() {
151
+ var _a;
152
+ __privateSet(this, _theme, new PayKKaTheme(__privateGet(this, _id)));
153
+ __privateGet(this, _theme).init((_a = __privateGet(this, _session).checkout) == null ? void 0 : _a.theme);
106
154
  }
107
155
  initOtherData() {
108
156
  const res = getUrlParam(PROCESSING_PARAM_NAME);
@@ -113,12 +161,18 @@ class PayKKaCheckout {
113
161
  get session() {
114
162
  return __privateGet(this, _session);
115
163
  }
164
+ get theme() {
165
+ return __privateGet(this, _theme);
166
+ }
116
167
  get envConfig() {
117
168
  return __privateGet(this, _envConfig);
118
169
  }
119
170
  get config() {
120
171
  return __privateGet(this, _config);
121
172
  }
173
+ get id() {
174
+ return __privateGet(this, _id);
175
+ }
122
176
  /** 创建组件,把 session 作为组件的 props 传递 */
123
177
  create(component, props) {
124
178
  var _a;
@@ -130,8 +184,8 @@ class PayKKaCheckout {
130
184
  onError,
131
185
  onTimeout,
132
186
  onExpired,
133
- ...props,
134
- ...coreProps
187
+ ...coreProps,
188
+ ...props
135
189
  });
136
190
  (_a = __privateGet(this, _componentInsts)) == null ? void 0 : _a.push(componentInst);
137
191
  return componentInst;
@@ -140,17 +194,37 @@ class PayKKaCheckout {
140
194
  return {
141
195
  session: __privateGet(this, _session),
142
196
  core: this,
143
- threeDSFrame: __privateGet(this, _config).threeDSFrame
197
+ threeDSFrame: __privateGet(this, _config).threeDSFrame,
198
+ hidePaymentButton: __privateGet(this, _config).hidePaymentButton
144
199
  };
145
200
  }
146
201
  resetEnablePaymentMethod() {
147
202
  this.enablePaymentMethod.value = null;
148
203
  }
204
+ getAddressCore() {
205
+ if (!__privateGet(this, _addressCore)) {
206
+ __privateSet(this, _addressCore, new AddressCore());
207
+ }
208
+ return __privateGet(this, _addressCore);
209
+ }
149
210
  }
211
+ _id = new WeakMap();
150
212
  _config = new WeakMap();
151
213
  _envConfig = new WeakMap();
152
214
  _session = new WeakMap();
215
+ _theme = new WeakMap();
153
216
  _componentInsts = new WeakMap();
217
+ _addressCore = new WeakMap();
218
+ _initPromise = new WeakMap();
219
+ _doInit = new WeakSet();
220
+ doInit_fn = async function() {
221
+ this.initCheckoutConfig();
222
+ this.initEnv();
223
+ this.initLocale();
224
+ await this.initSession();
225
+ this.initTheme();
226
+ this.initOtherData();
227
+ };
154
228
  export {
155
229
  PayKKaCheckout
156
230
  };
@@ -2,7 +2,7 @@ import { _, B } from "../core.js";
2
2
  import { isString } from "../utils/is.js";
3
3
  import "../utils/card-brand/brands.js";
4
4
  import "../utils/system-info/get-browser-info.js";
5
- import { deepFreeze } from "../utils/deep-freeze.js";
5
+ import { deepFreeze } from "../utils/object.js";
6
6
  const internalInstMap = /* @__PURE__ */ new WeakMap();
7
7
  const setInternalInst = (inst, internalInst) => {
8
8
  const _internalInst = Object.assign(
@@ -1,9 +1,10 @@
1
1
  import "../api/http.js";
2
2
  import "../utils/card-brand/brands.js";
3
3
  import "../utils/system-info/get-browser-info.js";
4
+ import "../core.js";
4
5
  import { onceGetCheckoutInfo } from "../api/modules/checkout/index.js";
5
- const querySession = async ({ sessionId, clientKey }, options) => {
6
- return onceGetCheckoutInfo({ sessionId, clientKey }, options);
6
+ const querySession = async (params, extraParams = {}, options) => {
7
+ return onceGetCheckoutInfo(params, extraParams, options);
7
8
  };
8
9
  export {
9
10
  querySession
@@ -21,47 +21,29 @@ var __privateMethod = (obj, member, method) => {
21
21
  __accessCheck(obj, member, "access private method");
22
22
  return method;
23
23
  };
24
- var _readyPromise, _init, init_fn;
24
+ var _readyPromise, _init, init_fn, _initCheckout, initCheckout_fn;
25
+ import { d } from "../core.js";
25
26
  import { isTimeoutError } from "../api/http.js";
26
27
  import "../utils/card-brand/brands.js";
27
28
  import "../utils/system-info/get-browser-info.js";
28
- import { generateColors } from "../utils/colors.js";
29
29
  import { createPromise } from "../utils/create-promise.js";
30
30
  import { PayKKaError } from "./error.js";
31
31
  import { querySession } from "./query.js";
32
32
  class Session {
33
- constructor(sessionId, clientKey) {
33
+ constructor(params, extraParams = {}) {
34
34
  __privateAdd(this, _init);
35
+ __privateAdd(this, _initCheckout);
35
36
  __publicField(this, "sessionId");
36
37
  __publicField(this, "clientKey");
37
38
  __publicField(this, "checkout");
38
- __publicField(this, "colors", null);
39
+ __publicField(this, "theme", d({}));
40
+ __publicField(this, "extraParams", {});
39
41
  __privateAdd(this, _readyPromise, createPromise());
42
+ const { sessionId, clientKey } = params;
40
43
  this.sessionId = sessionId;
41
44
  this.clientKey = clientKey;
42
- __privateMethod(this, _init, init_fn).call(this).then(() => __privateGet(this, _readyPromise).resolve(true)).catch((err) => {
43
- if (isTimeoutError(err)) {
44
- __privateGet(this, _readyPromise).reject(err);
45
- } else {
46
- __privateGet(this, _readyPromise).reject(new PayKKaError("API_ERROR", err.message, { code: err.code }));
47
- }
48
- });
49
- }
50
- /** 生成主题色 */
51
- genColors() {
52
- var _a;
53
- const { payButtonBackgroundColor } = ((_a = this.checkout) == null ? void 0 : _a.theme) || {};
54
- if (payButtonBackgroundColor) {
55
- const colors = generateColors(payButtonBackgroundColor, {
56
- theme: "default",
57
- backgroundColor: "#fff"
58
- });
59
- this.colors = {
60
- primary: colors[5],
61
- primaryHover: colors[4],
62
- primaryActive: colors[6]
63
- };
64
- }
45
+ this.extraParams = extraParams;
46
+ __privateMethod(this, _init, init_fn).call(this);
65
47
  }
66
48
  ready() {
67
49
  return __privateGet(this, _readyPromise);
@@ -70,11 +52,25 @@ class Session {
70
52
  _readyPromise = new WeakMap();
71
53
  _init = new WeakSet();
72
54
  init_fn = async function() {
73
- this.checkout = await querySession({
74
- sessionId: this.sessionId,
75
- clientKey: this.clientKey
76
- });
77
- this.genColors();
55
+ try {
56
+ await __privateMethod(this, _initCheckout, initCheckout_fn).call(this);
57
+ __privateGet(this, _readyPromise).resolve(true);
58
+ } catch (err) {
59
+ const error = isTimeoutError(err) ? err : new PayKKaError("API_ERROR", err.message, { code: err.code });
60
+ __privateGet(this, _readyPromise).reject(error);
61
+ }
62
+ };
63
+ _initCheckout = new WeakSet();
64
+ initCheckout_fn = async function() {
65
+ var _a;
66
+ this.checkout = await querySession(
67
+ {
68
+ sessionId: this.sessionId,
69
+ clientKey: this.clientKey
70
+ },
71
+ this.extraParams
72
+ );
73
+ this.sessionId = (_a = this.checkout) == null ? void 0 : _a.sessionId;
78
74
  };
79
75
  export {
80
76
  Session
@@ -0,0 +1,65 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+ var _className, _theme;
20
+ import { useBEM } from "../hooks/useBEM.js";
21
+ import "../core.js";
22
+ import "./context.js";
23
+ import "../utils/card-brand/brands.js";
24
+ import "../utils/system-info/get-browser-info.js";
25
+ import { generateColors } from "../utils/colors.js";
26
+ import { loadStyle } from "../utils/style.js";
27
+ import { getThemeText } from "../utils/theme.js";
28
+ import "../api/http.js";
29
+ class PayKKaTheme {
30
+ constructor(checkoutId) {
31
+ /** 主题类名 */
32
+ __privateAdd(this, _className, void 0);
33
+ __privateAdd(this, _theme, {});
34
+ __privateSet(this, _className, useBEM(`theme-${checkoutId}`).bem());
35
+ }
36
+ init(theme) {
37
+ const { payButtonBackgroundColor, payButtonTextColor } = theme || {};
38
+ __privateSet(this, _theme, {
39
+ ...__privateGet(this, _theme),
40
+ "--paykka-button-font-color": payButtonTextColor
41
+ });
42
+ if (payButtonBackgroundColor) {
43
+ const colors = generateColors(payButtonBackgroundColor);
44
+ __privateSet(this, _theme, {
45
+ ...__privateGet(this, _theme),
46
+ "--paykka-button-bg-color": colors[5],
47
+ // 主色
48
+ "--paykka-button-bg-color-hover": colors[4],
49
+ // 浅一点的色,用于 hover
50
+ "--paykka-button-bg-color-active": colors[6]
51
+ // 深一点的色,用于 active
52
+ });
53
+ }
54
+ const themeStyle = getThemeText(__privateGet(this, _theme));
55
+ loadStyle(`.${__privateGet(this, _className)}{${themeStyle}}`);
56
+ }
57
+ get className() {
58
+ return __privateGet(this, _className);
59
+ }
60
+ }
61
+ _className = new WeakMap();
62
+ _theme = new WeakMap();
63
+ export {
64
+ PayKKaTheme
65
+ };
package/dist/es/core.js CHANGED
@@ -20,9 +20,6 @@ function g$2(n2, t2, i2, o2, r2) {
20
20
  var f2 = { type: n2, props: t2, key: i2, ref: o2, __k: null, __: null, __b: 0, __e: null, __d: void 0, __c: null, constructor: void 0, __v: null == r2 ? ++u$3 : r2, __i: -1, __u: 0 };
21
21
  return null == r2 && null != l$3.vnode && l$3.vnode(f2), f2;
22
22
  }
23
- function m$1() {
24
- return { current: null };
25
- }
26
23
  function b$1(n2) {
27
24
  return n2.children;
28
25
  }
@@ -6447,7 +6444,6 @@ export {
6447
6444
  h$1 as h,
6448
6445
  index,
6449
6446
  inputToRGB,
6450
- m$1 as m,
6451
6447
  q,
6452
6448
  rgbToHex,
6453
6449
  rgbToHsv,
@@ -0,0 +1,14 @@
1
+ import { h } from "../core.js";
2
+ const usePaymentStatus = () => {
3
+ const [paymentButtonStatus, setPaymentButtonStatus] = h("unSubmit");
4
+ const [errorMsg, setErrorMsg] = h("");
5
+ return {
6
+ paymentButtonStatus,
7
+ setPaymentButtonStatus,
8
+ errorMsg,
9
+ setErrorMsg
10
+ };
11
+ };
12
+ export {
13
+ usePaymentStatus
14
+ };
@@ -14,6 +14,7 @@ const deDE = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "Kartennummer",
19
20
  "card.cardNumber.incomplete": "Ihre Kartennummer ist unvollständig",
@@ -81,7 +82,8 @@ const deDE = {
81
82
  "threeDS.returnToCheckout": "Rückkehr erfolgt in Kürze.",
82
83
  // qrCode
83
84
  "qrCode.expired": "Der QR-Code ist abgelaufen.",
84
- "qrCode.scanByGcash": "QR-Code mit GCash scannen"
85
+ "qrCode.scanByGcash": "QR-Code mit GCash scannen",
86
+ "qrCode.scanByZalopay": "QR-Code mit Zalopay scannen"
85
87
  };
86
88
  export {
87
89
  deDE as default
@@ -14,6 +14,7 @@ const enGB = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "Card number",
19
20
  "card.cardNumber.incomplete": "Your card number is incomplete",
@@ -81,7 +82,8 @@ const enGB = {
81
82
  "threeDS.returnToCheckout": "returning shortly.",
82
83
  // qrCode
83
84
  "qrCode.expired": "The QR code has expired.",
84
- "qrCode.scanByGcash": "Scan QR code with GCash"
85
+ "qrCode.scanByGcash": "Scan QR code with GCash",
86
+ "qrCode.scanByZalopay": "Scan QR code with Zalopay"
85
87
  };
86
88
  export {
87
89
  enGB as default
@@ -14,6 +14,7 @@ const esES = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "Número de tarjeta",
19
20
  "card.cardNumber.incomplete": "Tu número de tarjeta está incompleto",
@@ -81,7 +82,8 @@ const esES = {
81
82
  "threeDS.returnToCheckout": "volviendo en breve.",
82
83
  // qrCode
83
84
  "qrCode.expired": "El código QR ha expirado.",
84
- "qrCode.scanByGcash": "Escanear el código QR con GCash"
85
+ "qrCode.scanByGcash": "Escanear el código QR con GCash",
86
+ "qrCode.scanByZalopay": "Escanear el código QR con Zalopay"
85
87
  };
86
88
  export {
87
89
  esES as default
@@ -14,6 +14,7 @@ const frFR = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "Numéro de carte",
19
20
  "card.cardNumber.incomplete": "Votre numéro de carte est incomplet",
@@ -81,7 +82,8 @@ const frFR = {
81
82
  "threeDS.returnToCheckout": "retour imminent.",
82
83
  // qrCode
83
84
  "qrCode.expired": "Le code QR a expiré.",
84
- "qrCode.scanByGcash": "Scanner le code QR avec GCash"
85
+ "qrCode.scanByGcash": "Scanner le code QR avec GCash",
86
+ "qrCode.scanByZalopay": "Scanner le code QR avec Zalopay"
85
87
  };
86
88
  export {
87
89
  frFR as default
@@ -14,6 +14,7 @@ const jaJP = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "カード番号",
19
20
  "card.cardNumber.incomplete": "カード番号が不完全です",
@@ -81,7 +82,8 @@ const jaJP = {
81
82
  "threeDS.returnToCheckout": "まもなく戻ります。",
82
83
  // qrCode
83
84
  "qrCode.expired": "QRコードが期限切れです。",
84
- "qrCode.scanByGcash": "Gcashでスキャン"
85
+ "qrCode.scanByGcash": "Gcashでスキャン",
86
+ "qrCode.scanByZalopay": "Zalopayでスキャン"
85
87
  };
86
88
  export {
87
89
  jaJP as default
@@ -14,6 +14,7 @@ const koKR = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "카드 번호",
19
20
  "card.cardNumber.incomplete": "카드 번호가 불완전합니다",
@@ -81,7 +82,8 @@ const koKR = {
81
82
  "threeDS.returnToCheckout": "곧 돌아갑니다.",
82
83
  // qrCode
83
84
  "qrCode.expired": "QR 코드가 만료되었습니다.",
84
- "qrCode.scanByGcash": "GCash 스캔"
85
+ "qrCode.scanByGcash": "GCash 스캔",
86
+ "qrCode.scanByZalopay": "Zalopay 스캔"
85
87
  };
86
88
  export {
87
89
  koKR as default
@@ -14,6 +14,7 @@ const nlNL = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "Kaartnummer",
19
20
  "card.cardNumber.incomplete": "Uw kaartnummer is onvolledig",
@@ -81,7 +82,8 @@ const nlNL = {
81
82
  "threeDS.returnToCheckout": "binnenkort terugkeren.",
82
83
  // qrCode
83
84
  "qrCode.expired": "De QR-code is verlopen.",
84
- "qrCode.scanByGcash": "Scan QR-code met GCash"
85
+ "qrCode.scanByGcash": "Scan QR-code met GCash",
86
+ "qrCode.scanByZalopay": "Scan QR-code met Zalopay"
85
87
  };
86
88
  export {
87
89
  nlNL as default
@@ -14,6 +14,7 @@ const ptPT = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "Número do cartão",
19
20
  "card.cardNumber.incomplete": "O número do seu cartão está incompleto",
@@ -81,7 +82,8 @@ const ptPT = {
81
82
  "threeDS.returnToCheckout": "a regressar em breve.",
82
83
  // qrCode
83
84
  "qrCode.expired": "O código QR expirou.",
84
- "qrCode.scanByGcash": "Escaneie o código QR com GCash"
85
+ "qrCode.scanByGcash": "Escaneie o código QR com GCash",
86
+ "qrCode.scanByZalopay": "Escaneie o código QR com Zalopay"
85
87
  };
86
88
  export {
87
89
  ptPT as default
@@ -14,6 +14,7 @@ const ruRU = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "Номер карты",
19
20
  "card.cardNumber.incomplete": "Ваш номер карты неполный",
@@ -81,7 +82,8 @@ const ruRU = {
81
82
  "threeDS.returnToCheckout": "скоро возврат.",
82
83
  // qrCode
83
84
  "qrCode.expired": "Срок действия QR-кода истек.",
84
- "qrCode.scanByGcash": "Сканируйте QR-кодом с GCash"
85
+ "qrCode.scanByGcash": "Сканируйте QR-кодом с GCash",
86
+ "qrCode.scanByZalopay": "Сканируйте QR-кодом с Zalopay"
85
87
  };
86
88
  export {
87
89
  ruRU as default
@@ -14,6 +14,7 @@ const zhCN = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "卡号",
19
20
  "card.cardNumber.incomplete": "您的卡号不完整",
@@ -81,7 +82,8 @@ const zhCN = {
81
82
  "threeDS.returnToCheckout": "即将返回",
82
83
  // qrCode
83
84
  "qrCode.expired": "二维码过期",
84
- "qrCode.scanByGcash": "用Gcash扫码"
85
+ "qrCode.scanByGcash": "用Gcash扫码",
86
+ "qrCode.scanByZalopay": "用Zalopay扫码"
85
87
  };
86
88
  export {
87
89
  zhCN as default
@@ -14,6 +14,7 @@ const zhHK = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "卡號",
19
20
  "card.cardNumber.incomplete": "您的卡號不完整",
@@ -81,7 +82,8 @@ const zhHK = {
81
82
  "threeDS.returnToCheckout": "即將返回",
82
83
  // qrCode
83
84
  "qrCode.expired": "二維碼過期",
84
- "qrCode.scanByGcash": "用Gcash掃碼"
85
+ "qrCode.scanByGcash": "用Gcash掃碼",
86
+ "qrCode.scanByZalopay": "用Zalopay掃碼"
85
87
  };
86
88
  export {
87
89
  zhHK as default
@@ -14,6 +14,7 @@ const zhTW = {
14
14
  "dropIn.ninePay.label": "9Pay",
15
15
  "dropIn.gcash.label": "GCash",
16
16
  "dropIn.paymaya.label": "Paymaya",
17
+ "dropIn.zalopay.label": "Zalopay",
17
18
  // card number
18
19
  "card.cardNumber.label": "卡號",
19
20
  "card.cardNumber.incomplete": "您的卡號不完整",
@@ -81,7 +82,8 @@ const zhTW = {
81
82
  "threeDS.returnToCheckout": "即將返回",
82
83
  // qrCode
83
84
  "qrCode.expired": "二維碼過期",
84
- "qrCode.scanByGcash": "用Gcash掃碼"
85
+ "qrCode.scanByGcash": "用Gcash掃碼",
86
+ "qrCode.scanByZalopay": "用Zalopay掃碼"
85
87
  };
86
88
  export {
87
89
  zhTW as default