@blocklet/payment-react 1.14.14 → 1.14.16

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.
@@ -14,6 +14,12 @@ const fetchData = async (id) => {
14
14
  const { data } = await api.get(`/api/pricing-tables/${id}`);
15
15
  return data;
16
16
  };
17
+ const ensureProtocol = (url) => {
18
+ if (!/^https?:\/\//i.test(url)) {
19
+ return `https://${url}`;
20
+ }
21
+ return url;
22
+ };
17
23
  export default function CheckoutTable({ id, mode, onPaid, onError, onChange, extraParams, goBack }) {
18
24
  if (!id.startsWith("prctbl_")) {
19
25
  throw new Error("A valid pricing table id is required.");
@@ -36,7 +42,7 @@ export default function CheckoutTable({ id, mode, onPaid, onError, onChange, ext
36
42
  if (mode === "standalone") {
37
43
  let { url } = res.data;
38
44
  url = url.indexOf("?") > -1 ? `${url}&currencyId=${currencyId}` : `${url}?currencyId=${currencyId}`;
39
- window.location.replace(url);
45
+ window.location.replace(ensureProtocol(url));
40
46
  } else {
41
47
  window.location.hash = res.data.id;
42
48
  setSessionId(res.data.id);
package/es/libs/util.js CHANGED
@@ -151,6 +151,9 @@ export function formatRecurring(recurring, translate = true, separator = "per",
151
151
  month: "monthly",
152
152
  year: "yearly"
153
153
  };
154
+ if (!recurring) {
155
+ return "";
156
+ }
154
157
  if (+recurring.interval_count === 1) {
155
158
  const interval = t(`common.${recurring.interval}`, locale);
156
159
  return translate ? t(`common.${intervals[recurring.interval]}`, locale) : separator ? t(`common.${separator}`, locale, { interval }) : interval;
@@ -23,6 +23,12 @@ const fetchData = async id => {
23
23
  } = await _api.default.get(`/api/pricing-tables/${id}`);
24
24
  return data;
25
25
  };
26
+ const ensureProtocol = url => {
27
+ if (!/^https?:\/\//i.test(url)) {
28
+ return `https://${url}`;
29
+ }
30
+ return url;
31
+ };
26
32
  function CheckoutTable({
27
33
  id,
28
34
  mode,
@@ -67,7 +73,7 @@ function CheckoutTable({
67
73
  url
68
74
  } = res.data;
69
75
  url = url.indexOf("?") > -1 ? `${url}&currencyId=${currencyId}` : `${url}?currencyId=${currencyId}`;
70
- window.location.replace(url);
76
+ window.location.replace(ensureProtocol(url));
71
77
  } else {
72
78
  window.location.hash = res.data.id;
73
79
  setSessionId(res.data.id);
package/lib/libs/util.js CHANGED
@@ -212,6 +212,9 @@ function formatRecurring(recurring, translate = true, separator = "per", locale
212
212
  month: "monthly",
213
213
  year: "yearly"
214
214
  };
215
+ if (!recurring) {
216
+ return "";
217
+ }
215
218
  if (+recurring.interval_count === 1) {
216
219
  const interval = (0, _locales.t)(`common.${recurring.interval}`, locale);
217
220
  return translate ? (0, _locales.t)(`common.${intervals[recurring.interval]}`, locale) : separator ? (0, _locales.t)(`common.${separator}`, locale, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.14.14",
3
+ "version": "1.14.16",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -91,7 +91,7 @@
91
91
  "@babel/core": "^7.25.2",
92
92
  "@babel/preset-env": "^7.25.2",
93
93
  "@babel/preset-react": "^7.24.7",
94
- "@blocklet/payment-types": "1.14.14",
94
+ "@blocklet/payment-types": "1.14.16",
95
95
  "@storybook/addon-essentials": "^7.6.20",
96
96
  "@storybook/addon-interactions": "^7.6.20",
97
97
  "@storybook/addon-links": "^7.6.20",
@@ -120,5 +120,5 @@
120
120
  "vite-plugin-babel": "^1.2.0",
121
121
  "vite-plugin-node-polyfills": "^0.21.0"
122
122
  },
123
- "gitHead": "3e245cdbcef16f49ce7f2c9afb535212abf58ddf"
123
+ "gitHead": "eb45cb419fe53c4a1bd1c7809a775c0439c210c3"
124
124
  }
@@ -18,6 +18,13 @@ const fetchData = async (id: string): Promise<TPricingTableExpanded> => {
18
18
  return data;
19
19
  };
20
20
 
21
+ const ensureProtocol = (url: string): string => {
22
+ if (!/^https?:\/\//i.test(url)) {
23
+ return `https://${url}`;
24
+ }
25
+ return url;
26
+ };
27
+
21
28
  export default function CheckoutTable({ id, mode, onPaid, onError, onChange, extraParams, goBack }: CheckoutProps) {
22
29
  if (!id.startsWith('prctbl_')) {
23
30
  throw new Error('A valid pricing table id is required.');
@@ -48,7 +55,7 @@ export default function CheckoutTable({ id, mode, onPaid, onError, onChange, ext
48
55
  if (mode === 'standalone') {
49
56
  let { url } = res.data;
50
57
  url = url.indexOf('?') > -1 ? `${url}&currencyId=${currencyId}` : `${url}?currencyId=${currencyId}`;
51
- window.location.replace(url);
58
+ window.location.replace(ensureProtocol(url));
52
59
  } else {
53
60
  window.location.hash = res.data.id;
54
61
  setSessionId(res.data.id);
package/src/libs/util.ts CHANGED
@@ -230,6 +230,10 @@ export function formatRecurring(
230
230
  year: 'yearly',
231
231
  };
232
232
 
233
+ if (!recurring) {
234
+ return '';
235
+ }
236
+
233
237
  if (+recurring.interval_count === 1) {
234
238
  const interval = t(`common.${recurring.interval}`, locale);
235
239
  // @ts-ignore