@blocklet/payment-react 1.22.13 → 1.22.15
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.
|
@@ -93,48 +93,45 @@ function OverdueInvoicePayment({
|
|
|
93
93
|
}
|
|
94
94
|
return Object.values(data.summary);
|
|
95
95
|
}, [data?.summary]);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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:
|
|
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
|
|
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
|
-
}
|
|
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:
|
|
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.
|
|
3
|
+
"version": "1.22.15",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -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.
|
|
99
|
+
"@blocklet/payment-types": "1.22.15",
|
|
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": "
|
|
130
|
+
"gitHead": "4d8543567eb8958c55a8cf06d9031f3f64c57e27"
|
|
131
131
|
}
|
|
@@ -161,56 +161,53 @@ function OverdueInvoicePayment({
|
|
|
161
161
|
return Object.values(data.summary);
|
|
162
162
|
}, [data?.summary]);
|
|
163
163
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
{
|
|
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
|
};
|