@blocklet/payment-react 1.22.12 → 1.22.14

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.
@@ -118,3 +118,5 @@ translateLanguages:
118
118
  - ja
119
119
  # Checkout ID for document deployment service
120
120
  checkoutId: ""
121
+ # Should sync branding for documentation
122
+ shouldSyncBranding: ""
@@ -7,7 +7,8 @@
7
7
  "sourceIds": [
8
8
  "README.md",
9
9
  "src/index.ts"
10
- ]
10
+ ],
11
+ "icon": "lucide:book-open"
11
12
  },
12
13
  {
13
14
  "title": "Getting Started",
@@ -19,7 +20,8 @@
19
20
  "src/contexts/payment.tsx",
20
21
  "src/checkout/form.tsx",
21
22
  "src/theme/index.tsx"
22
- ]
23
+ ],
24
+ "icon": "lucide:rocket"
23
25
  },
24
26
  {
25
27
  "title": "Providers",
@@ -30,7 +32,8 @@
30
32
  "src/contexts/payment.tsx",
31
33
  "src/contexts/donate.tsx",
32
34
  "README.md"
33
- ]
35
+ ],
36
+ "icon": "lucide:package"
34
37
  },
35
38
  {
36
39
  "title": "PaymentProvider",
@@ -60,7 +63,8 @@
60
63
  "sourceIds": [
61
64
  "src/index.ts",
62
65
  "README.md"
63
- ]
66
+ ],
67
+ "icon": "lucide:blocks"
64
68
  },
65
69
  {
66
70
  "title": "Checkout Components",
@@ -298,7 +302,8 @@
298
302
  "src/theme/index.tsx",
299
303
  "src/libs/util.ts",
300
304
  "README.md"
301
- ]
305
+ ],
306
+ "icon": "lucide:book"
302
307
  },
303
308
  {
304
309
  "title": "Theming",
@@ -336,7 +341,8 @@
336
341
  "src/hooks/subscription.ts",
337
342
  "src/hooks/mobile.ts",
338
343
  "README.md"
339
- ]
344
+ ],
345
+ "icon": "lucide:anchor"
340
346
  },
341
347
  {
342
348
  "title": "useSubscription",
@@ -93,48 +93,45 @@ function OverdueInvoicePayment({
93
93
  }
94
94
  return Object.values(data.summary);
95
95
  }, [data?.summary]);
96
- const debouncedHandleInvoicePaid = debounce(
97
- async (currencyId) => {
98
- if (stripePaymentInProgressRef.current[currencyId]) {
99
- try {
100
- const checkData = await fetchOverdueInvoices({
101
- subscriptionId,
102
- customerId: effectiveCustomerId,
103
- authToken
104
- });
105
- const hasRemainingInvoices = checkData.invoices?.some((inv) => inv.currency_id === currencyId);
106
- if (hasRemainingInvoices) {
107
- return;
108
- }
109
- setStripePaymentInProgress((prev) => {
110
- const newState = { ...prev };
111
- delete newState[currencyId];
112
- return newState;
113
- });
114
- setPaymentStatus((prev) => ({ ...prev, [currencyId]: "success" }));
115
- } catch (err) {
116
- console.error("Error checking Stripe payment completion:", err);
96
+ const checkAndHandleInvoicePaid = async (currencyId) => {
97
+ if (stripePaymentInProgressRef.current[currencyId]) {
98
+ try {
99
+ const checkData = await fetchOverdueInvoices({
100
+ subscriptionId,
101
+ customerId: effectiveCustomerId,
102
+ authToken
103
+ });
104
+ const hasRemainingInvoices = checkData.invoices?.some((inv) => inv.currency_id === currencyId);
105
+ if (hasRemainingInvoices) {
117
106
  return;
118
107
  }
108
+ setStripePaymentInProgress((prev) => {
109
+ const newState = { ...prev };
110
+ delete newState[currencyId];
111
+ return newState;
112
+ });
113
+ setPaymentStatus((prev) => ({ ...prev, [currencyId]: "success" }));
114
+ } catch (err) {
115
+ console.error("Error checking Stripe payment completion:", err);
116
+ return;
119
117
  }
120
- if (successToast) {
121
- Toast.close();
122
- Toast.success(t("payment.customer.invoice.paySuccess"));
123
- }
124
- setPayLoading(false);
125
- const res = await refresh();
126
- if (res.invoices?.length === 0) {
127
- setDialogOpen(false);
128
- onPaid(sourceId, currencyId, sourceType);
129
- }
130
- },
131
- 1e3,
132
- {
133
- leading: false,
134
- trailing: true,
135
- maxWait: 5e3
136
118
  }
137
- );
119
+ if (successToast) {
120
+ Toast.close();
121
+ Toast.success(t("payment.customer.invoice.paySuccess"));
122
+ }
123
+ setPayLoading(false);
124
+ const res = await refresh();
125
+ if (res.invoices?.length === 0) {
126
+ setDialogOpen(false);
127
+ onPaid(sourceId, currencyId, sourceType);
128
+ }
129
+ };
130
+ const debouncedHandleInvoicePaid = debounce((currencyId) => checkAndHandleInvoicePaid(currencyId), 1e3, {
131
+ leading: false,
132
+ trailing: true,
133
+ maxWait: 5e3
134
+ });
138
135
  const isCrossOriginRequest = isCrossOrigin();
139
136
  const subscription = useSubscription("events");
140
137
  const waitForInvoiceAllPaid = async () => {
@@ -284,6 +281,7 @@ function OverdueInvoicePayment({
284
281
  {
285
282
  variant: options?.variant || "contained",
286
283
  size: "small",
284
+ onClick: () => checkAndHandleInvoicePaid(currency.id),
287
285
  ...primaryButton ? {} : {
288
286
  color: "success",
289
287
  startIcon: /* @__PURE__ */ jsx(CheckCircleIcon, {})
@@ -292,10 +290,13 @@ function OverdueInvoicePayment({
292
290
  }
293
291
  );
294
292
  }
295
- if (status === "error") {
296
- return /* @__PURE__ */ jsx(Button, { variant: options?.variant || "contained", size: "small", onClick: () => handlePay(item), sx: options?.sx, children: t("payment.subscription.overdue.retry") });
297
- }
298
293
  if (item.method.type === "stripe") {
294
+ let buttonText = t("payment.subscription.overdue.payNow");
295
+ if (status === "error") {
296
+ buttonText = t("payment.subscription.overdue.retry");
297
+ } else if (status === "processing") {
298
+ buttonText = t("payment.subscription.overdue.processing");
299
+ }
299
300
  return /* @__PURE__ */ jsx(
300
301
  StripePaymentAction,
301
302
  {
@@ -319,7 +320,7 @@ function OverdueInvoicePayment({
319
320
  loading: paying || status === "processing",
320
321
  onClick: onPay,
321
322
  sx: options?.sx,
322
- children: status === "processing" ? t("payment.subscription.overdue.processing") : t("payment.subscription.overdue.payNow")
323
+ children: buttonText
323
324
  }
324
325
  )
325
326
  }
@@ -334,7 +335,7 @@ function OverdueInvoicePayment({
334
335
  loading: inProcess,
335
336
  onClick: () => handlePay(item),
336
337
  sx: options?.sx,
337
- children: t("payment.subscription.overdue.payNow")
338
+ children: status === "error" ? t("payment.subscription.overdue.retry") : t("payment.subscription.overdue.payNow")
338
339
  }
339
340
  );
340
341
  };
@@ -109,7 +109,7 @@ function OverdueInvoicePayment({
109
109
  }
110
110
  return Object.values(data.summary);
111
111
  }, [data?.summary]);
112
- const debouncedHandleInvoicePaid = (0, _debounce.default)(async currencyId => {
112
+ const checkAndHandleInvoicePaid = async currencyId => {
113
113
  if (stripePaymentInProgressRef.current[currencyId]) {
114
114
  try {
115
115
  const checkData = await fetchOverdueInvoices({
@@ -147,7 +147,8 @@ function OverdueInvoicePayment({
147
147
  setDialogOpen(false);
148
148
  onPaid(sourceId, currencyId, sourceType);
149
149
  }
150
- }, 1e3, {
150
+ };
151
+ const debouncedHandleInvoicePaid = (0, _debounce.default)(currencyId => checkAndHandleInvoicePaid(currencyId), 1e3, {
151
152
  leading: false,
152
153
  trailing: true,
153
154
  maxWait: 5e3
@@ -317,6 +318,7 @@ function OverdueInvoicePayment({
317
318
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
318
319
  variant: options?.variant || "contained",
319
320
  size: "small",
321
+ onClick: () => checkAndHandleInvoicePaid(currency.id),
320
322
  ...(primaryButton ? {} : {
321
323
  color: "success",
322
324
  startIcon: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.CheckCircle, {})
@@ -324,16 +326,13 @@ function OverdueInvoicePayment({
324
326
  children: t("payment.subscription.overdue.paid")
325
327
  });
326
328
  }
327
- if (status === "error") {
328
- return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
329
- variant: options?.variant || "contained",
330
- size: "small",
331
- onClick: () => handlePay(item),
332
- sx: options?.sx,
333
- children: t("payment.subscription.overdue.retry")
334
- });
335
- }
336
329
  if (item.method.type === "stripe") {
330
+ let buttonText = t("payment.subscription.overdue.payNow");
331
+ if (status === "error") {
332
+ buttonText = t("payment.subscription.overdue.retry");
333
+ } else if (status === "processing") {
334
+ buttonText = t("payment.subscription.overdue.processing");
335
+ }
337
336
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_stripePaymentAction.default, {
338
337
  subscriptionId,
339
338
  customerId: !subscriptionId ? effectiveCustomerId : void 0,
@@ -359,7 +358,7 @@ function OverdueInvoicePayment({
359
358
  loading: paying || status === "processing",
360
359
  onClick: onPay,
361
360
  sx: options?.sx,
362
- children: status === "processing" ? t("payment.subscription.overdue.processing") : t("payment.subscription.overdue.payNow")
361
+ children: buttonText
363
362
  })
364
363
  });
365
364
  }
@@ -370,7 +369,7 @@ function OverdueInvoicePayment({
370
369
  loading: inProcess,
371
370
  onClick: () => handlePay(item),
372
371
  sx: options?.sx,
373
- children: t("payment.subscription.overdue.payNow")
372
+ children: status === "error" ? t("payment.subscription.overdue.retry") : t("payment.subscription.overdue.payNow")
374
373
  });
375
374
  };
376
375
  const getMethodText = method => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.22.12",
3
+ "version": "1.22.14",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -54,18 +54,18 @@
54
54
  }
55
55
  },
56
56
  "dependencies": {
57
- "@arcblock/bridge": "^3.2.3",
58
- "@arcblock/did-connect-react": "^3.2.3",
59
- "@arcblock/react-hooks": "^3.2.3",
60
- "@arcblock/ux": "^3.2.3",
61
- "@arcblock/ws": "^1.27.5",
62
- "@blocklet/theme": "^3.2.3",
63
- "@blocklet/ui-react": "^3.2.3",
57
+ "@arcblock/bridge": "^3.2.6",
58
+ "@arcblock/did-connect-react": "^3.2.6",
59
+ "@arcblock/react-hooks": "^3.2.6",
60
+ "@arcblock/ux": "^3.2.6",
61
+ "@arcblock/ws": "^1.27.6",
62
+ "@blocklet/theme": "^3.2.6",
63
+ "@blocklet/ui-react": "^3.2.6",
64
64
  "@mui/icons-material": "^7.1.2",
65
65
  "@mui/lab": "7.0.0-beta.14",
66
66
  "@mui/material": "^7.1.2",
67
67
  "@mui/system": "^7.1.1",
68
- "@ocap/util": "^1.27.5",
68
+ "@ocap/util": "^1.27.6",
69
69
  "@stripe/react-stripe-js": "^2.9.0",
70
70
  "@stripe/stripe-js": "^2.4.0",
71
71
  "@vitejs/plugin-legacy": "^7.0.0",
@@ -96,7 +96,7 @@
96
96
  "@babel/core": "^7.27.4",
97
97
  "@babel/preset-env": "^7.27.2",
98
98
  "@babel/preset-react": "^7.27.1",
99
- "@blocklet/payment-types": "1.22.12",
99
+ "@blocklet/payment-types": "1.22.14",
100
100
  "@storybook/addon-essentials": "^7.6.20",
101
101
  "@storybook/addon-interactions": "^7.6.20",
102
102
  "@storybook/addon-links": "^7.6.20",
@@ -127,5 +127,5 @@
127
127
  "vite-plugin-babel": "^1.3.1",
128
128
  "vite-plugin-node-polyfills": "^0.23.0"
129
129
  },
130
- "gitHead": "0d86273f55b29bf659111090580971143f6d1ab4"
130
+ "gitHead": "fc9395e0eaf4472b42192835fb4933da469939c6"
131
131
  }
@@ -161,56 +161,53 @@ function OverdueInvoicePayment({
161
161
  return Object.values(data.summary);
162
162
  }, [data?.summary]);
163
163
 
164
- const debouncedHandleInvoicePaid = debounce(
165
- async (currencyId: string) => {
166
- // If Stripe payment is in progress, check if it's complete before refreshing
167
- if (stripePaymentInProgressRef.current[currencyId]) {
168
- try {
169
- const checkData = await fetchOverdueInvoices({
170
- subscriptionId,
171
- customerId: effectiveCustomerId,
172
- authToken,
173
- });
174
-
175
- const hasRemainingInvoices = checkData.invoices?.some((inv: Invoice) => inv.currency_id === currencyId);
176
-
177
- // Only refresh UI when all invoices are paid
178
- if (hasRemainingInvoices) {
179
- return;
180
- }
181
-
182
- // Clear Stripe payment state
183
- setStripePaymentInProgress((prev) => {
184
- const newState = { ...prev };
185
- delete newState[currencyId];
186
- return newState;
187
- });
188
- setPaymentStatus((prev) => ({ ...prev, [currencyId]: 'success' }));
189
- } catch (err) {
190
- console.error('Error checking Stripe payment completion:', err);
164
+ const checkAndHandleInvoicePaid = async (currencyId: string) => {
165
+ // If Stripe payment is in progress, check if it's complete before refreshing
166
+ if (stripePaymentInProgressRef.current[currencyId]) {
167
+ try {
168
+ const checkData = await fetchOverdueInvoices({
169
+ subscriptionId,
170
+ customerId: effectiveCustomerId,
171
+ authToken,
172
+ });
173
+
174
+ const hasRemainingInvoices = checkData.invoices?.some((inv: Invoice) => inv.currency_id === currencyId);
175
+
176
+ // Only refresh UI when all invoices are paid
177
+ if (hasRemainingInvoices) {
191
178
  return;
192
179
  }
193
- }
194
180
 
195
- // Now refresh and update UI
196
- if (successToast) {
197
- Toast.close();
198
- Toast.success(t('payment.customer.invoice.paySuccess'));
199
- }
200
- setPayLoading(false);
201
- const res = await refresh();
202
- if (res.invoices?.length === 0) {
203
- setDialogOpen(false);
204
- onPaid(sourceId as string, currencyId, sourceType as 'subscription' | 'customer');
181
+ // Clear Stripe payment state
182
+ setStripePaymentInProgress((prev) => {
183
+ const newState = { ...prev };
184
+ delete newState[currencyId];
185
+ return newState;
186
+ });
187
+ setPaymentStatus((prev) => ({ ...prev, [currencyId]: 'success' }));
188
+ } catch (err) {
189
+ console.error('Error checking Stripe payment completion:', err);
190
+ return;
205
191
  }
206
- },
207
- 1000,
208
- {
209
- leading: false,
210
- trailing: true,
211
- maxWait: 5000,
212
192
  }
213
- );
193
+
194
+ // Now refresh and update UI
195
+ if (successToast) {
196
+ Toast.close();
197
+ Toast.success(t('payment.customer.invoice.paySuccess'));
198
+ }
199
+ setPayLoading(false);
200
+ const res = await refresh();
201
+ if (res.invoices?.length === 0) {
202
+ setDialogOpen(false);
203
+ onPaid(sourceId as string, currencyId, sourceType as 'subscription' | 'customer');
204
+ }
205
+ };
206
+ const debouncedHandleInvoicePaid = debounce((currencyId: string) => checkAndHandleInvoicePaid(currencyId), 1000, {
207
+ leading: false,
208
+ trailing: true,
209
+ maxWait: 5000,
210
+ });
214
211
 
215
212
  const isCrossOriginRequest = isCrossOrigin();
216
213
 
@@ -391,6 +388,7 @@ function OverdueInvoicePayment({
391
388
  <Button
392
389
  variant={options?.variant || 'contained'}
393
390
  size="small"
391
+ onClick={() => checkAndHandleInvoicePaid(currency.id)}
394
392
  {...(primaryButton
395
393
  ? {}
396
394
  : {
@@ -402,15 +400,13 @@ function OverdueInvoicePayment({
402
400
  );
403
401
  }
404
402
 
405
- if (status === 'error') {
406
- return (
407
- <Button variant={options?.variant || 'contained'} size="small" onClick={() => handlePay(item)} sx={options?.sx}>
408
- {t('payment.subscription.overdue.retry')}
409
- </Button>
410
- );
411
- }
412
-
413
403
  if (item.method.type === 'stripe') {
404
+ let buttonText = t('payment.subscription.overdue.payNow');
405
+ if (status === 'error') {
406
+ buttonText = t('payment.subscription.overdue.retry');
407
+ } else if (status === 'processing') {
408
+ buttonText = t('payment.subscription.overdue.processing');
409
+ }
414
410
  return (
415
411
  <StripePaymentAction
416
412
  subscriptionId={subscriptionId}
@@ -432,9 +428,7 @@ function OverdueInvoicePayment({
432
428
  loading={paying || status === 'processing'}
433
429
  onClick={onPay}
434
430
  sx={options?.sx}>
435
- {status === 'processing'
436
- ? t('payment.subscription.overdue.processing')
437
- : t('payment.subscription.overdue.payNow')}
431
+ {buttonText}
438
432
  </LoadingButton>
439
433
  )}
440
434
  </StripePaymentAction>
@@ -448,7 +442,7 @@ function OverdueInvoicePayment({
448
442
  loading={inProcess}
449
443
  onClick={() => handlePay(item)}
450
444
  sx={options?.sx}>
451
- {t('payment.subscription.overdue.payNow')}
445
+ {status === 'error' ? t('payment.subscription.overdue.retry') : t('payment.subscription.overdue.payNow')}
452
446
  </LoadingButton>
453
447
  );
454
448
  };