@blocklet/payment-react 1.26.1 → 1.26.3

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 (73) hide show
  1. package/es/checkout-v2/components/dialogs/checkout-dialogs.js +2 -0
  2. package/es/checkout-v2/components/left/cross-sell-card.js +3 -3
  3. package/es/checkout-v2/components/left/product-item-card.js +9 -3
  4. package/es/checkout-v2/components/left/promotion-input.d.ts +4 -1
  5. package/es/checkout-v2/components/left/promotion-input.js +8 -13
  6. package/es/checkout-v2/components/right/customer-info-card.d.ts +2 -0
  7. package/es/checkout-v2/components/right/customer-info-card.js +22 -14
  8. package/es/checkout-v2/components/right/status-feedback.js +1 -1
  9. package/es/checkout-v2/components/right/submit-button.js +3 -1
  10. package/es/checkout-v2/layouts/checkout-layout.js +13 -3
  11. package/es/checkout-v2/panels/left/composite-panel.js +27 -6
  12. package/es/checkout-v2/panels/right/payment-panel.js +40 -9
  13. package/es/checkout-v2/utils/format.d.ts +1 -1
  14. package/es/checkout-v2/utils/format.js +1 -0
  15. package/es/checkout-v2/views/error-view.d.ts +1 -1
  16. package/es/checkout-v2/views/error-view.js +9 -0
  17. package/es/checkout-v2/views/success-view.js +3 -1
  18. package/es/components/over-due-invoice-payment.js +5 -3
  19. package/es/components/service-suspended-dialog.d.ts +4 -0
  20. package/es/components/service-suspended-dialog.js +61 -0
  21. package/es/libs/util.d.ts +8 -0
  22. package/es/libs/util.js +3 -0
  23. package/es/locales/en.js +4 -0
  24. package/es/locales/zh.js +4 -0
  25. package/es/payment/form/index.js +17 -0
  26. package/es/payment/index.js +15 -4
  27. package/lib/checkout-v2/components/dialogs/checkout-dialogs.js +4 -0
  28. package/lib/checkout-v2/components/left/cross-sell-card.js +2 -2
  29. package/lib/checkout-v2/components/left/product-item-card.js +9 -2
  30. package/lib/checkout-v2/components/left/promotion-input.d.ts +4 -1
  31. package/lib/checkout-v2/components/left/promotion-input.js +12 -19
  32. package/lib/checkout-v2/components/right/customer-info-card.d.ts +2 -0
  33. package/lib/checkout-v2/components/right/customer-info-card.js +19 -13
  34. package/lib/checkout-v2/components/right/status-feedback.js +1 -1
  35. package/lib/checkout-v2/components/right/submit-button.js +3 -1
  36. package/lib/checkout-v2/layouts/checkout-layout.js +28 -5
  37. package/lib/checkout-v2/panels/left/composite-panel.js +20 -5
  38. package/lib/checkout-v2/panels/right/payment-panel.js +46 -7
  39. package/lib/checkout-v2/utils/format.d.ts +1 -1
  40. package/lib/checkout-v2/utils/format.js +7 -0
  41. package/lib/checkout-v2/views/error-view.d.ts +1 -1
  42. package/lib/checkout-v2/views/error-view.js +9 -0
  43. package/lib/checkout-v2/views/success-view.js +2 -0
  44. package/lib/components/over-due-invoice-payment.js +12 -2
  45. package/lib/components/service-suspended-dialog.d.ts +4 -0
  46. package/lib/components/service-suspended-dialog.js +97 -0
  47. package/lib/libs/util.d.ts +8 -0
  48. package/lib/libs/util.js +4 -0
  49. package/lib/locales/en.js +4 -0
  50. package/lib/locales/zh.js +4 -0
  51. package/lib/payment/form/index.js +23 -0
  52. package/lib/payment/index.js +15 -4
  53. package/package.json +4 -4
  54. package/src/checkout-v2/components/dialogs/checkout-dialogs.tsx +4 -0
  55. package/src/checkout-v2/components/left/cross-sell-card.tsx +3 -3
  56. package/src/checkout-v2/components/left/product-item-card.tsx +18 -8
  57. package/src/checkout-v2/components/left/promotion-input.tsx +17 -17
  58. package/src/checkout-v2/components/right/customer-info-card.tsx +29 -16
  59. package/src/checkout-v2/components/right/status-feedback.tsx +2 -2
  60. package/src/checkout-v2/components/right/submit-button.tsx +2 -0
  61. package/src/checkout-v2/layouts/checkout-layout.tsx +25 -10
  62. package/src/checkout-v2/panels/left/composite-panel.tsx +28 -6
  63. package/src/checkout-v2/panels/right/payment-panel.tsx +32 -5
  64. package/src/checkout-v2/utils/format.ts +2 -0
  65. package/src/checkout-v2/views/error-view.tsx +11 -1
  66. package/src/checkout-v2/views/success-view.tsx +3 -1
  67. package/src/components/over-due-invoice-payment.tsx +6 -3
  68. package/src/components/service-suspended-dialog.tsx +64 -0
  69. package/src/libs/util.ts +7 -0
  70. package/src/locales/en.tsx +4 -0
  71. package/src/locales/zh.tsx +4 -0
  72. package/src/payment/form/index.tsx +20 -0
  73. package/src/payment/index.tsx +26 -4
@@ -125,6 +125,19 @@ function PaymentInner({
125
125
  }, [paymentMethods]);
126
126
 
127
127
  const defaultCurrencyId = useMemo(() => {
128
+ // Keep session currency stable when a promotion is already applied.
129
+ // Otherwise auto-picking from URL/local preference/no-wallet may switch currency
130
+ // on refresh and trigger a second recalculate-promotion that removes discount
131
+ // with `currency_incompatible`.
132
+ const hasAppliedDiscount = Boolean((state.checkoutSession as any)?.discounts?.length);
133
+ if (
134
+ hasAppliedDiscount &&
135
+ state.checkoutSession.currency_id &&
136
+ availableCurrencyIds.includes(state.checkoutSession.currency_id)
137
+ ) {
138
+ return state.checkoutSession.currency_id;
139
+ }
140
+
128
141
  // 1. first check url currencyId
129
142
  if (query.currencyId && availableCurrencyIds.includes(query.currencyId)) {
130
143
  return query.currencyId;
@@ -151,7 +164,7 @@ function PaymentInner({
151
164
  return state.checkoutSession.currency_id;
152
165
  }
153
166
  return availableCurrencyIds?.[0];
154
- }, [query.currencyId, availableCurrencyIds, session?.user, state.checkoutSession.currency_id, paymentMethods]);
167
+ }, [query.currencyId, availableCurrencyIds, session?.user, state.checkoutSession, paymentMethods]);
155
168
 
156
169
  const defaultMethodId = paymentMethods.find((m) => m.payment_currencies.some((c) => c.id === defaultCurrencyId))?.id;
157
170
  const hideSummaryCard = mode.endsWith('-minimal') || !showCheckoutSummary;
@@ -183,14 +196,23 @@ function PaymentInner({
183
196
  });
184
197
 
185
198
  useEffect(() => {
199
+ const hasAppliedDiscount = Boolean((state.checkoutSession as any)?.discounts?.length);
200
+ const currentCurrency = methods.getValues('payment_currency');
201
+ const currentMethod = methods.getValues('payment_method');
202
+
186
203
  if (defaultCurrencyId) {
187
- methods.setValue('payment_currency', defaultCurrencyId);
204
+ // Avoid overriding current currency on refresh when a promotion is already applied.
205
+ if (!hasAppliedDiscount || !currentCurrency) {
206
+ methods.setValue('payment_currency', defaultCurrencyId);
207
+ }
188
208
  }
189
209
  if (defaultMethodId) {
190
- methods.setValue('payment_method', defaultMethodId);
210
+ if (!hasAppliedDiscount || !currentMethod) {
211
+ methods.setValue('payment_method', defaultMethodId);
212
+ }
191
213
  }
192
214
  // eslint-disable-next-line react-hooks/exhaustive-deps
193
- }, [defaultCurrencyId, defaultMethodId]);
215
+ }, [defaultCurrencyId, defaultMethodId, state.checkoutSession.discounts]);
194
216
 
195
217
  useEffect(() => {
196
218
  if (!isMobileSafari()) {