@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
@@ -6,15 +6,14 @@ import "../../../utils/system-info/get-browser-info.js";
6
6
  import { isMobile } from "../../../utils/system-info/get-system-info.js";
7
7
  import { cssVarPrefix, normalizedClass, formatAmount } from "../../../utils/format.js";
8
8
  import { redirectToPayment } from "../../../utils/redirect.js";
9
+ import { formatPaymentResult } from "../../../utils/payment.js";
9
10
  import { isTimeoutError } from "../../../api/http.js";
10
- import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../../constant.js";
11
11
  import { getBrowserParams } from "../../../api/modules/get-browser-params.js";
12
+ import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../../constant.js";
12
13
  import { getGcashPayInfo, gcashPay } from "../../../api/modules/gcash/index.js";
13
14
  import { PayKKaError } from "../../../core/error.js";
14
- import { hidePaymentButton } from "../../../config.js";
15
15
  import { usePayState } from "../../../hooks/usePayState.js";
16
16
  import { useRetry } from "../../../hooks/useRetry.js";
17
- import { createAddressCore } from "../../../core/Address.js";
18
17
  import { createEmailCore, EmailField } from "../../EmailField/EmailField.js";
19
18
  import { SubmitButton } from "../../SubmitButton/index.js";
20
19
  import { GuideCard } from "../../GuideCard/index.js";
@@ -39,7 +38,8 @@ const GCash = w((props, ref) => {
39
38
  redirectMode = "auto",
40
39
  autoQuery = true,
41
40
  showGuideCard = true,
42
- enableQRCodeModal = true
41
+ enableQRCodeModal = true,
42
+ hidePaymentButton = false
43
43
  } = props;
44
44
  F(ref, () => ({
45
45
  stopRetry: () => {
@@ -54,15 +54,17 @@ const GCash = w((props, ref) => {
54
54
  var _a2;
55
55
  if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
56
56
  return;
57
- setForm(Object.assign(form, { address: addressState.getAddressState() }));
58
- (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
57
+ const newForm = Object.assign(form, { address: addressCore.getAddressState() });
58
+ setForm(newForm);
59
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressCore.getAddressState());
60
+ validateForm();
59
61
  },
60
62
  updateEmail: () => {
61
63
  var _a2;
62
64
  if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
63
65
  return;
64
- setForm(Object.assign(form, { email: emailState.email }));
65
- form.email = emailState.email;
66
+ const newForm = Object.assign(form, { email: emailState.email });
67
+ setForm(newForm);
66
68
  (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
67
69
  validateForm();
68
70
  },
@@ -70,7 +72,7 @@ const GCash = w((props, ref) => {
70
72
  hidePaymentButton && onSubmit();
71
73
  }
72
74
  }));
73
- const addressState = createAddressCore();
75
+ const addressCore = core.getAddressCore();
74
76
  const emailState = createEmailCore();
75
77
  const addressFieldRef = A(null);
76
78
  const emailFieldRef = A(null);
@@ -81,13 +83,13 @@ const GCash = w((props, ref) => {
81
83
  const [form, setForm] = h({
82
84
  email: "",
83
85
  address: {
84
- country: "",
85
- province: "",
86
- city: "",
87
- area: "",
88
- postCode: "",
89
- address1: "",
90
- address2: ""
86
+ country: void 0,
87
+ province: void 0,
88
+ city: void 0,
89
+ area: void 0,
90
+ postCode: void 0,
91
+ address1: void 0,
92
+ address2: void 0
91
93
  }
92
94
  });
93
95
  const [validated, setValidated] = h(false);
@@ -107,17 +109,27 @@ const GCash = w((props, ref) => {
107
109
  }
108
110
  setFieldStatus({ ...field });
109
111
  };
112
+ const processOnSuccess = (res) => {
113
+ var _a2, _b2;
114
+ setSubmitButtonStatus("success");
115
+ (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props, formatPaymentResult({
116
+ ...res,
117
+ returnUrl: (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.returnUrl
118
+ }));
119
+ };
110
120
  y(() => {
111
121
  if (!sessionReady) {
112
122
  return;
113
123
  }
114
- const { bill = {}, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
115
- if (!paymentMethod.includes(PaymentMethod.GCASH)) {
124
+ const { bill = {}, supportMethods = [], country } = (session == null ? void 0 : session.checkout) || {};
125
+ if (!supportMethods.includes(PaymentMethod.GCASH)) {
116
126
  return;
117
127
  }
118
128
  initFieldStatus();
119
129
  setIsCheckoutEnabled(true);
130
+ country && addressCore.setCountry(country);
120
131
  form.email = bill.email ?? "";
132
+ form.address.country = country;
121
133
  if (autoQuery && core.processingPaymentMethod === PaymentMethod.GCASH) {
122
134
  setSubmitButtonStatus("loading");
123
135
  startReFetchPayInfo();
@@ -156,35 +168,51 @@ const GCash = w((props, ref) => {
156
168
  },
157
169
  bill: {
158
170
  email: form.email,
159
- ...form.address,
160
- province: addressState.getLabel(form.address.province, addressState.getProvinceOption()) ?? form.address.province,
161
- city: addressState.getLabel(form.address.city, addressState.getCityOptions()) ?? form.address.city
171
+ addressLine1: form.address.address1,
172
+ addressLine2: form.address.address2,
173
+ postalCode: form.address.postCode,
174
+ country: form.address.country,
175
+ district: form.address.area,
176
+ state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
177
+ city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
162
178
  },
163
179
  browser: await getBrowserParams()
164
180
  };
165
181
  };
166
182
  const pay = async (search = false, timeout) => {
167
- var _a2, _b2, _c2, _d2, _e2;
183
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
168
184
  try {
169
- const paymentParams = await getPaymentParams();
170
185
  const requestOptions = { locale: i18n.locale, timeout };
171
- const res = search ? await getGcashPayInfo(
172
- { sessionId: session.sessionId, clientKey: session.clientKey },
173
- requestOptions
174
- ) : await gcashPay(paymentParams, props.core, requestOptions);
175
- !search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
176
- const { status, orderStatus, errorMessage, errorCode, payInfo, paymentExpiredAt } = res;
186
+ let res = null;
187
+ if (search) {
188
+ const extraParams = (_b2 = (_a2 = core.config)._getExtraParams) == null ? void 0 : _b2.call(_a2, "query", PaymentMethod.GCASH);
189
+ res = await getGcashPayInfo(
190
+ {
191
+ sessionId: session.sessionId,
192
+ clientKey: session.clientKey,
193
+ paymentMethod: PaymentMethod.GCASH
194
+ },
195
+ extraParams,
196
+ requestOptions
197
+ );
198
+ } else {
199
+ const extraParams = (_d2 = (_c2 = core.config)._getExtraParams) == null ? void 0 : _d2.call(_c2, "payment", PaymentMethod.GCASH);
200
+ res = await gcashPay(await getPaymentParams(), extraParams, requestOptions);
201
+ }
202
+ !search && ((_e2 = props.onSubmitResponse) == null ? void 0 : _e2.call(props, res));
203
+ const { status, orderStatus, errorMessage, errorCode, payInfo = {}, sessionId } = res;
204
+ const { paymentExpiredAt } = payInfo;
205
+ sessionId && (session.sessionId = sessionId);
177
206
  if (status === "PROCESSING") {
178
207
  if (!orderStatus) {
179
208
  setSubmitButtonStatus("unSubmit");
180
209
  return { end: true };
181
210
  } else if (orderStatus === "SUCCESS") {
182
211
  setShowQRCodeModal(false);
183
- setSubmitButtonStatus("success");
184
- (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
212
+ processOnSuccess(res);
185
213
  return { end: true };
186
214
  } else if (orderStatus === "FAILURE") {
187
- setErrorMsg(errorMessage);
215
+ errorMessage && setErrorMsg(errorMessage);
188
216
  setSubmitButtonStatus("unSubmit");
189
217
  processOnError(new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
190
218
  return { end: true };
@@ -209,19 +237,18 @@ const GCash = w((props, ref) => {
209
237
  return { end: false };
210
238
  } else if (orderStatus === "CANCELED") {
211
239
  setSubmitButtonStatus("unSubmit");
212
- (_c2 = props.onTimeout) == null ? void 0 : _c2.call(props);
240
+ (_f2 = props.onTimeout) == null ? void 0 : _f2.call(props);
213
241
  core.resetEnablePaymentMethod();
214
242
  return { end: true };
215
243
  }
216
244
  } else if (status === "SUCCESS") {
217
245
  setShowQRCodeModal(false);
218
- setSubmitButtonStatus("success");
219
- (_d2 = props.onSuccess) == null ? void 0 : _d2.call(props);
246
+ processOnSuccess(res);
220
247
  return { end: true };
221
248
  } else if (status === "EXPIRED") {
222
249
  setShowQRCodeModal(false);
223
250
  setSubmitButtonStatus("unSubmit");
224
- (_e2 = props.onExpired) == null ? void 0 : _e2.call(props);
251
+ (_g2 = props.onExpired) == null ? void 0 : _g2.call(props);
225
252
  return { end: true };
226
253
  }
227
254
  setSubmitButtonStatus("unSubmit");
@@ -236,7 +263,7 @@ const GCash = w((props, ref) => {
236
263
  }
237
264
  } else {
238
265
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
239
- setErrorMsg(message);
266
+ message && setErrorMsg(message);
240
267
  processOnError(new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
241
268
  setSubmitButtonStatus("unSubmit");
242
269
  return { end: true };
@@ -259,7 +286,7 @@ const GCash = w((props, ref) => {
259
286
  setErrorMsg("");
260
287
  (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
261
288
  var _a3;
262
- (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressState.setValidateAllFields(true);
289
+ (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
263
290
  (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
264
291
  if (errors) {
265
292
  setSubmitButtonStatus("unSubmit");
@@ -337,7 +364,8 @@ const GCash = w((props, ref) => {
337
364
  {
338
365
  value: {
339
366
  i18n,
340
- session
367
+ session,
368
+ core
341
369
  },
342
370
  children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
343
371
  showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.GCASH }),
@@ -352,6 +380,7 @@ const GCash = w((props, ref) => {
352
380
  {
353
381
  title: i18n.get("qrCode.scanByGcash"),
354
382
  bgColor: "#002CB8",
383
+ textColor: "#FFFFFF",
355
384
  qrCode: qrCodeInfo.qrCode,
356
385
  icon: /* @__PURE__ */ u(IconGcashComplete, { size: 22 }),
357
386
  amount: (_g = session == null ? void 0 : session.checkout) == null ? void 0 : _g.transAmount,
@@ -5,15 +5,14 @@ import "../../../utils/card-brand/brands.js";
5
5
  import "../../../utils/system-info/get-browser-info.js";
6
6
  import { cssVarPrefix, normalizedClass, formatAmount } from "../../../utils/format.js";
7
7
  import { redirectToPayment } from "../../../utils/redirect.js";
8
+ import { formatPaymentResult } from "../../../utils/payment.js";
8
9
  import { isTimeoutError } from "../../../api/http.js";
9
- import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../../constant.js";
10
10
  import { getBrowserParams } from "../../../api/modules/get-browser-params.js";
11
+ import { PaymentCategory, COMMON_CLASS_NAME, PaymentMethod, SessionMode } from "../../../constant.js";
11
12
  import { getPaymayaPayInfo, paymayaPay } from "../../../api/modules/paymaya/index.js";
12
13
  import { PayKKaError } from "../../../core/error.js";
13
- import { hidePaymentButton } from "../../../config.js";
14
14
  import { usePayState } from "../../../hooks/usePayState.js";
15
15
  import { useRetry } from "../../../hooks/useRetry.js";
16
- import { createAddressCore } from "../../../core/Address.js";
17
16
  import { createEmailCore, EmailField } from "../../EmailField/EmailField.js";
18
17
  import { SubmitButton } from "../../SubmitButton/index.js";
19
18
  import { GuideCard } from "../../GuideCard/index.js";
@@ -35,7 +34,8 @@ const Paymaya = w((props, ref) => {
35
34
  core,
36
35
  redirectMode = "auto",
37
36
  autoQuery = true,
38
- showGuideCard = true
37
+ showGuideCard = true,
38
+ hidePaymentButton = false
39
39
  } = props;
40
40
  F(ref, () => ({
41
41
  stopRetry: () => {
@@ -50,15 +50,17 @@ const Paymaya = w((props, ref) => {
50
50
  var _a2;
51
51
  if (!(fieldStatus == null ? void 0 : fieldStatus.address.show))
52
52
  return;
53
- setForm(Object.assign(form, { address: addressState.getAddressState() }));
54
- (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressState.getAddressState());
53
+ const newForm = Object.assign(form, { address: addressCore.getAddressState() });
54
+ setForm(newForm);
55
+ (_a2 = addressFieldRef.current) == null ? void 0 : _a2.update(addressCore.getAddressState());
56
+ validateForm();
55
57
  },
56
58
  updateEmail: () => {
57
59
  var _a2;
58
60
  if (!(fieldStatus == null ? void 0 : fieldStatus.email.show))
59
61
  return;
60
- setForm(Object.assign(form, { email: emailState.email }));
61
- form.email = emailState.email;
62
+ const newForm = Object.assign(form, { email: emailState.email });
63
+ setForm(newForm);
62
64
  (_a2 = emailFieldRef.current) == null ? void 0 : _a2.update(emailState.email);
63
65
  validateForm();
64
66
  },
@@ -66,7 +68,7 @@ const Paymaya = w((props, ref) => {
66
68
  hidePaymentButton && onSubmit();
67
69
  }
68
70
  }));
69
- const addressState = createAddressCore();
71
+ const addressCore = core.getAddressCore();
70
72
  const emailState = createEmailCore();
71
73
  const addressFieldRef = A(null);
72
74
  const emailFieldRef = A(null);
@@ -77,13 +79,13 @@ const Paymaya = w((props, ref) => {
77
79
  const [form, setForm] = h({
78
80
  email: "",
79
81
  address: {
80
- country: "",
81
- province: "",
82
- city: "",
83
- area: "",
84
- postCode: "",
85
- address1: "",
86
- address2: ""
82
+ country: void 0,
83
+ province: void 0,
84
+ city: void 0,
85
+ area: void 0,
86
+ postCode: void 0,
87
+ address1: void 0,
88
+ address2: void 0
87
89
  }
88
90
  });
89
91
  const [validated, setValidated] = h(false);
@@ -101,17 +103,27 @@ const Paymaya = w((props, ref) => {
101
103
  }
102
104
  setFieldStatus({ ...field });
103
105
  };
106
+ const processOnSuccess = (res) => {
107
+ var _a2, _b2;
108
+ setSubmitButtonStatus("success");
109
+ (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props, formatPaymentResult({
110
+ ...res,
111
+ returnUrl: (_a2 = session == null ? void 0 : session.checkout) == null ? void 0 : _a2.returnUrl
112
+ }));
113
+ };
104
114
  y(() => {
105
115
  if (!sessionReady) {
106
116
  return;
107
117
  }
108
- const { bill = {}, paymentMethod = [] } = (session == null ? void 0 : session.checkout) || {};
109
- if (!paymentMethod.includes(PaymentMethod.PAYMAYA)) {
118
+ const { bill = {}, supportMethods = [], country } = (session == null ? void 0 : session.checkout) || {};
119
+ if (!supportMethods.includes(PaymentMethod.PAYMAYA)) {
110
120
  return;
111
121
  }
112
122
  initFieldStatus();
113
123
  setIsCheckoutEnabled(true);
124
+ country && addressCore.setCountry(country);
114
125
  form.email = bill.email ?? "";
126
+ form.address.country = country;
115
127
  if (autoQuery && core.processingPaymentMethod === PaymentMethod.PAYMAYA) {
116
128
  setSubmitButtonStatus("loading");
117
129
  startReFetchPayInfo();
@@ -145,34 +157,49 @@ const Paymaya = w((props, ref) => {
145
157
  },
146
158
  bill: {
147
159
  email: form.email,
148
- ...form.address,
149
- province: addressState.getLabel(form.address.province, addressState.getProvinceOption()) ?? form.address.province,
150
- city: addressState.getLabel(form.address.city, addressState.getCityOptions()) ?? form.address.city
160
+ addressLine1: form.address.address1,
161
+ addressLine2: form.address.address2,
162
+ postalCode: form.address.postCode,
163
+ country: form.address.country,
164
+ district: form.address.area,
165
+ state: form.address.province ? addressCore.getLabel(form.address.province, addressCore.getProvinceOption()) ?? form.address.province : void 0,
166
+ city: form.address.city ? addressCore.getLabel(form.address.city, addressCore.getCityOptions()) ?? form.address.city : void 0
151
167
  },
152
168
  browser: await getBrowserParams()
153
169
  };
154
170
  };
155
171
  const pay = async (search = false, timeout) => {
156
- var _a2, _b2, _c2, _d2, _e2;
172
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g;
157
173
  try {
158
- const paymentParams = await getPaymentParams();
159
174
  const requestOptions = { locale: i18n.locale, timeout };
160
- const res = search ? await getPaymayaPayInfo(
161
- { sessionId: session.sessionId, clientKey: session.clientKey },
162
- requestOptions
163
- ) : await paymayaPay(paymentParams, props.core, requestOptions);
164
- !search && ((_a2 = props.onSubmitResponse) == null ? void 0 : _a2.call(props, res));
165
- const { status, orderStatus, errorMessage, errorCode, payInfo } = res;
175
+ let res = null;
176
+ if (search) {
177
+ const extraParams = (_b2 = (_a2 = core.config)._getExtraParams) == null ? void 0 : _b2.call(_a2, "query", PaymentMethod.PAYMAYA);
178
+ res = await getPaymayaPayInfo(
179
+ {
180
+ sessionId: session.sessionId,
181
+ clientKey: session.clientKey,
182
+ paymentMethod: PaymentMethod.PAYMAYA
183
+ },
184
+ extraParams,
185
+ requestOptions
186
+ );
187
+ } else {
188
+ const extraParams = (_d2 = (_c2 = core.config)._getExtraParams) == null ? void 0 : _d2.call(_c2, "payment", PaymentMethod.PAYMAYA);
189
+ res = await paymayaPay(await getPaymentParams(), extraParams, requestOptions);
190
+ }
191
+ !search && ((_e2 = props.onSubmitResponse) == null ? void 0 : _e2.call(props, res));
192
+ const { status, orderStatus, errorMessage, errorCode, payInfo, sessionId } = res;
193
+ sessionId && (session.sessionId = sessionId);
166
194
  if (status === "PROCESSING") {
167
195
  if (!orderStatus) {
168
196
  setSubmitButtonStatus("unSubmit");
169
197
  return { end: true };
170
198
  } else if (orderStatus === "SUCCESS") {
171
- setSubmitButtonStatus("success");
172
- (_b2 = props.onSuccess) == null ? void 0 : _b2.call(props);
199
+ processOnSuccess(res);
173
200
  return { end: true };
174
201
  } else if (orderStatus === "FAILURE") {
175
- setErrorMsg(errorMessage);
202
+ errorMessage && setErrorMsg(errorMessage);
176
203
  setSubmitButtonStatus("unSubmit");
177
204
  processOnError(new PayKKaError("API_ERROR", errorMessage, { code: errorCode }));
178
205
  return { end: true };
@@ -188,17 +215,16 @@ const Paymaya = w((props, ref) => {
188
215
  return { end: false };
189
216
  } else if (orderStatus === "CANCELED") {
190
217
  setSubmitButtonStatus("unSubmit");
191
- (_c2 = props.onTimeout) == null ? void 0 : _c2.call(props);
218
+ (_f2 = props.onTimeout) == null ? void 0 : _f2.call(props);
192
219
  core.resetEnablePaymentMethod();
193
220
  return { end: true };
194
221
  }
195
222
  } else if (status === "SUCCESS") {
196
- setSubmitButtonStatus("success");
197
- (_d2 = props.onSuccess) == null ? void 0 : _d2.call(props);
223
+ processOnSuccess(res);
198
224
  return { end: true };
199
225
  } else if (status === "EXPIRED") {
200
226
  setSubmitButtonStatus("unSubmit");
201
- (_e2 = props.onExpired) == null ? void 0 : _e2.call(props);
227
+ (_g = props.onExpired) == null ? void 0 : _g.call(props);
202
228
  return { end: true };
203
229
  }
204
230
  setSubmitButtonStatus("unSubmit");
@@ -213,7 +239,7 @@ const Paymaya = w((props, ref) => {
213
239
  }
214
240
  } else {
215
241
  const message = error.i18nKey ? i18n.get(error.i18nKey) : error.message;
216
- setErrorMsg(message);
242
+ message && setErrorMsg(message);
217
243
  processOnError(new PayKKaError("API_ERROR", message, { code: error.code, cause: error }));
218
244
  setSubmitButtonStatus("unSubmit");
219
245
  return { end: true };
@@ -236,7 +262,7 @@ const Paymaya = w((props, ref) => {
236
262
  setErrorMsg("");
237
263
  (_a2 = formRef.current) == null ? void 0 : _a2.validate(async (errors) => {
238
264
  var _a3;
239
- (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressState.setValidateAllFields(true);
265
+ (fieldStatus == null ? void 0 : fieldStatus.address.show) && addressCore.setValidateAllFields(true);
240
266
  (_a3 = props.onSubmit) == null ? void 0 : _a3.call(props, errors);
241
267
  if (errors) {
242
268
  setSubmitButtonStatus("unSubmit");
@@ -306,7 +332,8 @@ const Paymaya = w((props, ref) => {
306
332
  {
307
333
  value: {
308
334
  i18n,
309
- session
335
+ session,
336
+ core
310
337
  },
311
338
  children: isCheckoutEnabled && i18n.ready.value && /* @__PURE__ */ u(b, { children: [
312
339
  showGuideCard && /* @__PURE__ */ u(GuideCard, { type: PaymentCategory.PAYMAYA }),