@solvapay/react 1.3.0 → 1.4.0-preview-ecd61384a4e849717e13d47ab2daa086cdcd91c5
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.
- package/CHANGELOG.md +28 -0
- package/dist/adapters/auth.js +1 -0
- package/dist/adapters/auth0.js +1 -0
- package/dist/adapters/session-auth.js +1 -0
- package/dist/{chunk-DW5FJUUG.js → chunk-6RR4J74H.js} +214 -24
- package/dist/chunk-GFWMLRR3.js +3224 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/{chunk-4ISNB3JU.js → chunk-SUHDOG7Q.js} +1 -1
- package/dist/{index-BwwdMBdt.d.ts → index-CDvQcobx.d.cts} +21 -2
- package/dist/{index-kXLvp7EU.d.cts → index-w_VMlKm5.d.ts} +21 -2
- package/dist/index.cjs +2216 -363
- package/dist/index.d.cts +34 -5
- package/dist/index.d.ts +34 -5
- package/dist/index.js +66 -3
- package/dist/mcp/index.cjs +216 -29
- package/dist/mcp/index.d.cts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +3 -2
- package/dist/primitives/index.cjs +2101 -362
- package/dist/primitives/index.d.cts +180 -5
- package/dist/primitives/index.d.ts +180 -5
- package/dist/primitives/index.js +73 -2
- package/dist/{shared-lIhc8DS3.d.ts → shared-D8raw1Nv.d.ts} +143 -12
- package/dist/{shared-BNZAIWkU.d.cts → shared-LcjvX4fD.d.cts} +143 -12
- package/dist/styles.css +513 -0
- package/dist/webapi-K5XBCEO6.js +3775 -0
- package/package.json +5 -5
- package/dist/chunk-K7ZUJI26.js +0 -1527
package/dist/mcp/index.cjs
CHANGED
|
@@ -597,6 +597,29 @@ var import_react7 = require("react");
|
|
|
597
597
|
// src/SolvaPayProvider.tsx
|
|
598
598
|
var import_react6 = require("react");
|
|
599
599
|
|
|
600
|
+
// ../server/src/index.ts
|
|
601
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
602
|
+
var import_core = require("@solvapay/core");
|
|
603
|
+
|
|
604
|
+
// ../server/src/helpers/balance-poll.ts
|
|
605
|
+
var BALANCE_RECONCILE_DELAYS_MS = [500, 1e3, 2e3, 4e3, 8e3, 16e3];
|
|
606
|
+
async function pollBalanceUntilIncreased(getBalance, baseline, delays = BALANCE_RECONCILE_DELAYS_MS) {
|
|
607
|
+
for (const delay of delays) {
|
|
608
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
609
|
+
try {
|
|
610
|
+
const post = await getBalance();
|
|
611
|
+
if (post.credits > baseline) {
|
|
612
|
+
return { creditsAdded: post.credits - baseline };
|
|
613
|
+
}
|
|
614
|
+
} catch {
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/helpers/auto-recharge-cache.ts
|
|
621
|
+
var BALANCE_RECONCILE_GRACE_MS = BALANCE_RECONCILE_DELAYS_MS.reduce((sum, delay) => sum + delay, 0) + 1e3;
|
|
622
|
+
|
|
600
623
|
// src/utils/purchases.ts
|
|
601
624
|
function filterPurchases(purchases) {
|
|
602
625
|
return purchases.filter((purchase) => purchase.status === "active");
|
|
@@ -754,6 +777,7 @@ var DEFAULT_ROUTES = {
|
|
|
754
777
|
getProduct: "/api/get-product",
|
|
755
778
|
listPlans: "/api/list-plans",
|
|
756
779
|
getPaymentMethod: "/api/payment-method",
|
|
780
|
+
autoRecharge: "/api/auto-recharge",
|
|
757
781
|
getUsage: "/api/usage",
|
|
758
782
|
getLimits: "/api/limits"
|
|
759
783
|
};
|
|
@@ -791,7 +815,11 @@ function createHttpTransport(config) {
|
|
|
791
815
|
}),
|
|
792
816
|
createTopupPayment: (params) => request(config, routeFor(config, "createTopupPayment"), {
|
|
793
817
|
method: "POST",
|
|
794
|
-
body: {
|
|
818
|
+
body: {
|
|
819
|
+
amount: params.amount,
|
|
820
|
+
currency: params.currency,
|
|
821
|
+
...params.autoRecharge ? { autoRecharge: params.autoRecharge } : {}
|
|
822
|
+
},
|
|
795
823
|
onErrorContext: "createTopupPayment",
|
|
796
824
|
errorPrefix: "Failed to create topup payment"
|
|
797
825
|
}),
|
|
@@ -840,16 +868,12 @@ function createHttpTransport(config) {
|
|
|
840
868
|
}
|
|
841
869
|
);
|
|
842
870
|
},
|
|
843
|
-
createCustomerSession: () => request(
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
onErrorContext: "createCustomerSession",
|
|
850
|
-
errorPrefix: "Failed to create customer session"
|
|
851
|
-
}
|
|
852
|
-
),
|
|
871
|
+
createCustomerSession: () => request(config, routeFor(config, "createCustomerSession"), {
|
|
872
|
+
method: "POST",
|
|
873
|
+
body: {},
|
|
874
|
+
onErrorContext: "createCustomerSession",
|
|
875
|
+
errorPrefix: "Failed to create customer session"
|
|
876
|
+
}),
|
|
853
877
|
getMerchant: () => request(config, routeFor(config, "getMerchant"), {
|
|
854
878
|
method: "GET",
|
|
855
879
|
onErrorContext: "getMerchant",
|
|
@@ -879,6 +903,22 @@ function createHttpTransport(config) {
|
|
|
879
903
|
onErrorContext: "getPaymentMethod",
|
|
880
904
|
errorPrefix: "Failed to load payment method"
|
|
881
905
|
}),
|
|
906
|
+
getAutoRecharge: () => request(config, routeFor(config, "autoRecharge"), {
|
|
907
|
+
method: "GET",
|
|
908
|
+
onErrorContext: "getAutoRecharge",
|
|
909
|
+
errorPrefix: "Failed to load auto-recharge"
|
|
910
|
+
}),
|
|
911
|
+
saveAutoRecharge: (input) => request(config, routeFor(config, "autoRecharge"), {
|
|
912
|
+
method: "PUT",
|
|
913
|
+
body: input,
|
|
914
|
+
onErrorContext: "saveAutoRecharge",
|
|
915
|
+
errorPrefix: "Failed to save auto-recharge"
|
|
916
|
+
}),
|
|
917
|
+
disableAutoRecharge: () => request(config, routeFor(config, "autoRecharge"), {
|
|
918
|
+
method: "DELETE",
|
|
919
|
+
onErrorContext: "disableAutoRecharge",
|
|
920
|
+
errorPrefix: "Failed to disable auto-recharge"
|
|
921
|
+
}),
|
|
882
922
|
getUsage: () => request(config, routeFor(config, "getUsage"), {
|
|
883
923
|
method: "GET",
|
|
884
924
|
onErrorContext: "getUsage",
|
|
@@ -1017,6 +1057,42 @@ var enCopy = {
|
|
|
1017
1057
|
creditEstimateExact: "= {credits} credits",
|
|
1018
1058
|
creditEstimateApprox: "~ {credits} credits"
|
|
1019
1059
|
},
|
|
1060
|
+
autoRecharge: {
|
|
1061
|
+
heading: "Auto recharge",
|
|
1062
|
+
description: "Automatically top up so you never run out \u2014 recommended for production. You can turn this off anytime.",
|
|
1063
|
+
settingsHeading: "Auto recharge settings",
|
|
1064
|
+
setupTriggerLabel: "Set up auto-recharge",
|
|
1065
|
+
modifyTriggerLabel: "Modify",
|
|
1066
|
+
notConfiguredHint: "Automatic top-ups are off. Set up auto-recharge if you want credits added when your balance runs low.",
|
|
1067
|
+
enableLabel: "Enable auto-recharge",
|
|
1068
|
+
enableQuestion: "Would you like to set up automatic recharge?",
|
|
1069
|
+
enableSentence: "Yes, automatically recharge my card when my credit balance falls below a threshold",
|
|
1070
|
+
thresholdLabel: "When balance falls below",
|
|
1071
|
+
thresholdAriaLabel: "Balance threshold",
|
|
1072
|
+
fixedAmountLabel: "Add this amount",
|
|
1073
|
+
fixedAmountAriaLabel: "Fixed top-up amount",
|
|
1074
|
+
saveButton: "Save settings",
|
|
1075
|
+
cancelButton: "Cancel",
|
|
1076
|
+
disableButton: "Disable automatic top-up",
|
|
1077
|
+
savedMessage: "Automatic top-up settings saved.",
|
|
1078
|
+
disabledMessage: "Automatic top-ups disabled.",
|
|
1079
|
+
setupRequiredMessage: "Confirm your card to activate automatic top-ups.",
|
|
1080
|
+
setupHeading: "Authorize card",
|
|
1081
|
+
setupDescription: "Authorize a card for automatic top-ups. You will not be charged now.",
|
|
1082
|
+
setupSubmit: "Save card for auto-recharge",
|
|
1083
|
+
setupProcessing: "Authorizing...",
|
|
1084
|
+
setupAwaitingConfirmation: "Card authorized. Finishing activation \u2014 this can take a moment.",
|
|
1085
|
+
setupAuthFailed: "Card authentication failed. Please try a different card.",
|
|
1086
|
+
invalidThreshold: "Enter a valid balance threshold.",
|
|
1087
|
+
thresholdTooLow: "Balance threshold must be greater than zero.",
|
|
1088
|
+
minTopupAmount: "Top-up amount must be at least {amount}.",
|
|
1089
|
+
topupBelowThreshold: "Top-up amount must be at least your balance threshold ({amount}).",
|
|
1090
|
+
creditsPerRecharge: "\u2248 {credits} credits per recharge",
|
|
1091
|
+
creditsPerRechargeApprox: "~ {credits} credits per recharge",
|
|
1092
|
+
currencyPerRecharge: "\u2248 {amount} per recharge",
|
|
1093
|
+
currencyPerRechargeApprox: "~ {amount} per recharge",
|
|
1094
|
+
statusFailed: "Payment failed \u2014 update your card to resume"
|
|
1095
|
+
},
|
|
1020
1096
|
activationFlow: {
|
|
1021
1097
|
heading: "Confirm your plan",
|
|
1022
1098
|
activateButton: "Activate",
|
|
@@ -1244,12 +1320,18 @@ var SolvaPayProvider = ({ config, children }) => {
|
|
|
1244
1320
|
const [displayExchangeRateValue, setDisplayExchangeRateValue] = (0, import_react6.useState)(
|
|
1245
1321
|
initial?.balance?.displayExchangeRate ?? null
|
|
1246
1322
|
);
|
|
1323
|
+
const [displayBlockValue, setDisplayBlockValue] = (0, import_react6.useState)(
|
|
1324
|
+
initial?.balance?.display ?? null
|
|
1325
|
+
);
|
|
1247
1326
|
const [balanceLoading, setBalanceLoading] = (0, import_react6.useState)(false);
|
|
1248
1327
|
const balanceInFlightRef = (0, import_react6.useRef)(false);
|
|
1249
1328
|
const balanceLoadedRef = (0, import_react6.useRef)(!!initial?.balance);
|
|
1329
|
+
const creditsValueRef = (0, import_react6.useRef)(initial?.balance?.credits ?? null);
|
|
1250
1330
|
const optimisticUntilRef = (0, import_react6.useRef)(0);
|
|
1251
1331
|
const optimisticTimerRef = (0, import_react6.useRef)(null);
|
|
1252
1332
|
const fetchBalanceRef = (0, import_react6.useRef)(null);
|
|
1333
|
+
const reconcileRunningRef = (0, import_react6.useRef)(false);
|
|
1334
|
+
const reconcilePollRef = (0, import_react6.useRef)(null);
|
|
1253
1335
|
const inFlightRef = (0, import_react6.useRef)(null);
|
|
1254
1336
|
const loadedCacheKeysRef = (0, import_react6.useRef)(
|
|
1255
1337
|
new Set(initial?.customerRef ? [initial.customerRef] : [])
|
|
@@ -1267,10 +1349,12 @@ var SolvaPayProvider = ({ config, children }) => {
|
|
|
1267
1349
|
const fetchBalanceImpl = (0, import_react6.useCallback)(async () => {
|
|
1268
1350
|
if (optimisticUntilRef.current > Date.now()) return;
|
|
1269
1351
|
if (!isAuthenticated && !internalCustomerRef) {
|
|
1352
|
+
creditsValueRef.current = null;
|
|
1270
1353
|
setCreditsValue(null);
|
|
1271
1354
|
setDisplayCurrencyValue(null);
|
|
1272
1355
|
setCreditsPerMinorUnitValue(null);
|
|
1273
1356
|
setDisplayExchangeRateValue(null);
|
|
1357
|
+
setDisplayBlockValue(null);
|
|
1274
1358
|
setBalanceLoading(false);
|
|
1275
1359
|
balanceLoadedRef.current = false;
|
|
1276
1360
|
return;
|
|
@@ -1287,10 +1371,12 @@ var SolvaPayProvider = ({ config, children }) => {
|
|
|
1287
1371
|
return;
|
|
1288
1372
|
}
|
|
1289
1373
|
const data = await transportRef.current.getBalance();
|
|
1374
|
+
creditsValueRef.current = data.credits ?? null;
|
|
1290
1375
|
setCreditsValue(data.credits ?? null);
|
|
1291
1376
|
setDisplayCurrencyValue(data.displayCurrency ?? null);
|
|
1292
1377
|
setCreditsPerMinorUnitValue(data.creditsPerMinorUnit ?? null);
|
|
1293
1378
|
setDisplayExchangeRateValue(data.displayExchangeRate ?? null);
|
|
1379
|
+
setDisplayBlockValue(data.display ?? null);
|
|
1294
1380
|
balanceLoadedRef.current = true;
|
|
1295
1381
|
} catch (error) {
|
|
1296
1382
|
console.error("[SolvaPayProvider] Failed to fetch balance:", error);
|
|
@@ -1305,18 +1391,112 @@ var SolvaPayProvider = ({ config, children }) => {
|
|
|
1305
1391
|
(0, import_react6.useEffect)(() => {
|
|
1306
1392
|
return () => {
|
|
1307
1393
|
if (optimisticTimerRef.current) clearTimeout(optimisticTimerRef.current);
|
|
1394
|
+
reconcilePollRef.current = null;
|
|
1395
|
+
reconcileRunningRef.current = false;
|
|
1308
1396
|
};
|
|
1309
1397
|
}, []);
|
|
1310
1398
|
const OPTIMISTIC_GRACE_MS = 8e3;
|
|
1311
|
-
const
|
|
1312
|
-
|
|
1313
|
-
optimisticUntilRef.current =
|
|
1399
|
+
const DEBIT_GRACE_MS = 2e3;
|
|
1400
|
+
const clearOptimisticGrace = (0, import_react6.useCallback)(() => {
|
|
1401
|
+
optimisticUntilRef.current = 0;
|
|
1402
|
+
if (optimisticTimerRef.current) {
|
|
1403
|
+
clearTimeout(optimisticTimerRef.current);
|
|
1404
|
+
optimisticTimerRef.current = null;
|
|
1405
|
+
}
|
|
1406
|
+
}, []);
|
|
1407
|
+
const applyBalanceSnapshot = (0, import_react6.useCallback)(
|
|
1408
|
+
(data) => {
|
|
1409
|
+
creditsValueRef.current = data.credits ?? null;
|
|
1410
|
+
setCreditsValue(data.credits ?? null);
|
|
1411
|
+
setDisplayCurrencyValue(data.displayCurrency ?? null);
|
|
1412
|
+
setCreditsPerMinorUnitValue(data.creditsPerMinorUnit ?? null);
|
|
1413
|
+
setDisplayExchangeRateValue(data.displayExchangeRate ?? null);
|
|
1414
|
+
setDisplayBlockValue(data.display ?? null);
|
|
1415
|
+
balanceLoadedRef.current = true;
|
|
1416
|
+
},
|
|
1417
|
+
[]
|
|
1418
|
+
);
|
|
1419
|
+
const reconcileBalanceIncreaseImpl = (0, import_react6.useCallback)(async () => {
|
|
1420
|
+
if (!transportRef.current.getBalance) return;
|
|
1421
|
+
const finishReconcilePoll = () => {
|
|
1422
|
+
reconcilePollRef.current = null;
|
|
1423
|
+
clearOptimisticGrace();
|
|
1424
|
+
};
|
|
1425
|
+
reconcileRunningRef.current = true;
|
|
1426
|
+
try {
|
|
1427
|
+
while (reconcilePollRef.current) {
|
|
1428
|
+
const { baseline: activeBaseline, generation: activeGeneration } = reconcilePollRef.current;
|
|
1429
|
+
const pollResult = await pollBalanceUntilIncreased(
|
|
1430
|
+
async () => {
|
|
1431
|
+
const data = await transportRef.current.getBalance();
|
|
1432
|
+
return { credits: data.credits ?? 0 };
|
|
1433
|
+
},
|
|
1434
|
+
activeBaseline,
|
|
1435
|
+
BALANCE_RECONCILE_DELAYS_MS
|
|
1436
|
+
);
|
|
1437
|
+
const pollState = reconcilePollRef.current;
|
|
1438
|
+
if (!pollState || pollState.generation !== activeGeneration) {
|
|
1439
|
+
continue;
|
|
1440
|
+
}
|
|
1441
|
+
if (!pollResult) {
|
|
1442
|
+
finishReconcilePoll();
|
|
1443
|
+
break;
|
|
1444
|
+
}
|
|
1445
|
+
try {
|
|
1446
|
+
const data = await transportRef.current.getBalance();
|
|
1447
|
+
applyBalanceSnapshot(data);
|
|
1448
|
+
pollState.pending -= 1;
|
|
1449
|
+
if (pollState.pending > 0) {
|
|
1450
|
+
pollState.baseline = data.credits ?? 0;
|
|
1451
|
+
continue;
|
|
1452
|
+
}
|
|
1453
|
+
} catch (error) {
|
|
1454
|
+
console.error("[SolvaPayProvider] Failed to reconcile balance after auto-recharge:", error);
|
|
1455
|
+
}
|
|
1456
|
+
finishReconcilePoll();
|
|
1457
|
+
break;
|
|
1458
|
+
}
|
|
1459
|
+
} finally {
|
|
1460
|
+
reconcileRunningRef.current = false;
|
|
1461
|
+
}
|
|
1462
|
+
}, [applyBalanceSnapshot, clearOptimisticGrace]);
|
|
1463
|
+
const scheduleGraceRefetch = (0, import_react6.useCallback)((graceMs) => {
|
|
1464
|
+
optimisticUntilRef.current = Date.now() + graceMs;
|
|
1314
1465
|
if (optimisticTimerRef.current) clearTimeout(optimisticTimerRef.current);
|
|
1315
1466
|
optimisticTimerRef.current = setTimeout(() => {
|
|
1316
1467
|
optimisticUntilRef.current = 0;
|
|
1317
1468
|
fetchBalanceRef.current?.();
|
|
1318
|
-
},
|
|
1469
|
+
}, graceMs);
|
|
1319
1470
|
}, []);
|
|
1471
|
+
const adjustBalanceImpl = (0, import_react6.useCallback)(
|
|
1472
|
+
(credits) => {
|
|
1473
|
+
const nextCredits = (creditsValueRef.current ?? 0) + credits;
|
|
1474
|
+
creditsValueRef.current = nextCredits;
|
|
1475
|
+
setCreditsValue(nextCredits);
|
|
1476
|
+
if (credits >= 0) {
|
|
1477
|
+
scheduleGraceRefetch(OPTIMISTIC_GRACE_MS);
|
|
1478
|
+
} else {
|
|
1479
|
+
scheduleGraceRefetch(DEBIT_GRACE_MS);
|
|
1480
|
+
}
|
|
1481
|
+
},
|
|
1482
|
+
[scheduleGraceRefetch]
|
|
1483
|
+
);
|
|
1484
|
+
const reconcileAfterUsageDebitImpl = (0, import_react6.useCallback)(
|
|
1485
|
+
(opts) => {
|
|
1486
|
+
if (opts?.expectIncrease !== true) {
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
const nextCredits = creditsValueRef.current ?? 0;
|
|
1490
|
+
const generation = (reconcilePollRef.current?.generation ?? 0) + 1;
|
|
1491
|
+
const pending = (reconcilePollRef.current?.pending ?? 0) + 1;
|
|
1492
|
+
reconcilePollRef.current = { baseline: nextCredits, generation, pending };
|
|
1493
|
+
scheduleGraceRefetch(BALANCE_RECONCILE_GRACE_MS);
|
|
1494
|
+
if (!reconcileRunningRef.current) {
|
|
1495
|
+
void reconcileBalanceIncreaseImpl();
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
[reconcileBalanceIncreaseImpl, scheduleGraceRefetch]
|
|
1499
|
+
);
|
|
1320
1500
|
const createPayment = (0, import_react6.useCallback)(
|
|
1321
1501
|
(params) => transportRef.current.createPayment(params),
|
|
1322
1502
|
[]
|
|
@@ -1488,6 +1668,7 @@ var SolvaPayProvider = ({ config, children }) => {
|
|
|
1488
1668
|
setDisplayCurrencyValue(next.balance?.displayCurrency ?? null);
|
|
1489
1669
|
setCreditsPerMinorUnitValue(next.balance?.creditsPerMinorUnit ?? null);
|
|
1490
1670
|
setDisplayExchangeRateValue(next.balance?.displayExchangeRate ?? null);
|
|
1671
|
+
setDisplayBlockValue(next.balance?.display ?? null);
|
|
1491
1672
|
balanceLoadedRef.current = !!next.balance;
|
|
1492
1673
|
}, []);
|
|
1493
1674
|
(0, import_react6.useEffect)(() => {
|
|
@@ -1592,8 +1773,10 @@ var SolvaPayProvider = ({ config, children }) => {
|
|
|
1592
1773
|
displayCurrency: displayCurrencyValue,
|
|
1593
1774
|
creditsPerMinorUnit: creditsPerMinorUnitValue,
|
|
1594
1775
|
displayExchangeRate: displayExchangeRateValue,
|
|
1776
|
+
display: displayBlockValue,
|
|
1595
1777
|
refetch: fetchBalanceImpl,
|
|
1596
|
-
adjustBalance: adjustBalanceImpl
|
|
1778
|
+
adjustBalance: adjustBalanceImpl,
|
|
1779
|
+
reconcileAfterUsageDebit: reconcileAfterUsageDebitImpl
|
|
1597
1780
|
}),
|
|
1598
1781
|
[
|
|
1599
1782
|
balanceLoading,
|
|
@@ -1601,8 +1784,10 @@ var SolvaPayProvider = ({ config, children }) => {
|
|
|
1601
1784
|
displayCurrencyValue,
|
|
1602
1785
|
creditsPerMinorUnitValue,
|
|
1603
1786
|
displayExchangeRateValue,
|
|
1787
|
+
displayBlockValue,
|
|
1604
1788
|
fetchBalanceImpl,
|
|
1605
|
-
adjustBalanceImpl
|
|
1789
|
+
adjustBalanceImpl,
|
|
1790
|
+
reconcileAfterUsageDebitImpl
|
|
1606
1791
|
]
|
|
1607
1792
|
);
|
|
1608
1793
|
const contextValue = (0, import_react6.useMemo)(
|
|
@@ -2460,7 +2645,7 @@ function interpolate(template, vars) {
|
|
|
2460
2645
|
|
|
2461
2646
|
// src/utils/errors.ts
|
|
2462
2647
|
var DOCS_BASE_URL = "https://solvapay.com/docs";
|
|
2463
|
-
var
|
|
2648
|
+
var SolvaPayError2 = class extends Error {
|
|
2464
2649
|
code;
|
|
2465
2650
|
docsUrl;
|
|
2466
2651
|
constructor(code, message, docsUrl) {
|
|
@@ -2470,7 +2655,7 @@ var SolvaPayError = class extends Error {
|
|
|
2470
2655
|
this.docsUrl = docsUrl;
|
|
2471
2656
|
}
|
|
2472
2657
|
};
|
|
2473
|
-
var MissingProviderError = class extends
|
|
2658
|
+
var MissingProviderError = class extends SolvaPayError2 {
|
|
2474
2659
|
constructor(primitiveName) {
|
|
2475
2660
|
const docsUrl = `${DOCS_BASE_URL}/troubleshooting/missing-provider`;
|
|
2476
2661
|
super(
|
|
@@ -2481,7 +2666,7 @@ var MissingProviderError = class extends SolvaPayError {
|
|
|
2481
2666
|
this.name = "MissingProviderError";
|
|
2482
2667
|
}
|
|
2483
2668
|
};
|
|
2484
|
-
var MissingProductRefError = class extends
|
|
2669
|
+
var MissingProductRefError = class extends SolvaPayError2 {
|
|
2485
2670
|
constructor(primitiveName) {
|
|
2486
2671
|
const docsUrl = `${DOCS_BASE_URL}/primitives/product-ref`;
|
|
2487
2672
|
super(
|
|
@@ -2679,7 +2864,7 @@ var CancelledPlanNotice2 = ({
|
|
|
2679
2864
|
|
|
2680
2865
|
// src/primitives/BalanceBadge.tsx
|
|
2681
2866
|
var import_react17 = require("react");
|
|
2682
|
-
var
|
|
2867
|
+
var import_core2 = require("@solvapay/core");
|
|
2683
2868
|
|
|
2684
2869
|
// src/hooks/useBalance.ts
|
|
2685
2870
|
var import_react16 = require("react");
|
|
@@ -2720,14 +2905,14 @@ var BalanceBadge = (0, import_react17.forwardRef)(function BalanceBadge2({ asChi
|
|
|
2720
2905
|
const formattedCredits = new Intl.NumberFormat(locale).format(credits);
|
|
2721
2906
|
let currencyEquivalent = "";
|
|
2722
2907
|
if (!numberOnly && displayCurrency && creditsPerMinorUnit) {
|
|
2723
|
-
const displayMinor = (0,
|
|
2908
|
+
const displayMinor = (0, import_core2.creditsToDisplayMinorUnits)({
|
|
2724
2909
|
credits,
|
|
2725
2910
|
creditsPerMinorUnit,
|
|
2726
2911
|
displayExchangeRate: displayExchangeRate ?? 1,
|
|
2727
2912
|
displayCurrency
|
|
2728
2913
|
});
|
|
2729
2914
|
if (displayMinor !== null) {
|
|
2730
|
-
const minorPerMajor = (0,
|
|
2915
|
+
const minorPerMajor = (0, import_core2.minorUnitsPerMajor)(displayCurrency);
|
|
2731
2916
|
const formatted = new Intl.NumberFormat(locale, {
|
|
2732
2917
|
style: "currency",
|
|
2733
2918
|
currency: displayCurrency,
|
|
@@ -3540,7 +3725,7 @@ var CurrentPlanCard = ({
|
|
|
3540
3725
|
};
|
|
3541
3726
|
|
|
3542
3727
|
// src/mcp/views/detail-cards.tsx
|
|
3543
|
-
var
|
|
3728
|
+
var import_core3 = require("@solvapay/core");
|
|
3544
3729
|
|
|
3545
3730
|
// src/hooks/useCustomer.ts
|
|
3546
3731
|
function useCustomer() {
|
|
@@ -3629,7 +3814,7 @@ function McpCustomerDetailsCard({
|
|
|
3629
3814
|
}
|
|
3630
3815
|
const displayName = name?.trim() || "Customer";
|
|
3631
3816
|
const showBalance = !hideBalance && typeof credits === "number" && credits > 0;
|
|
3632
|
-
const displayMinor = showBalance && typeof creditsPerMinorUnit === "number" && creditsPerMinorUnit > 0 && displayCurrency ? (0,
|
|
3817
|
+
const displayMinor = showBalance && typeof creditsPerMinorUnit === "number" && creditsPerMinorUnit > 0 && displayCurrency ? (0, import_core3.creditsToDisplayMinorUnits)({
|
|
3633
3818
|
credits: credits ?? 0,
|
|
3634
3819
|
creditsPerMinorUnit,
|
|
3635
3820
|
displayExchangeRate: displayExchangeRate ?? 1,
|
|
@@ -5326,7 +5511,7 @@ function getStripeCacheKey(publishableKey, accountId) {
|
|
|
5326
5511
|
return accountId ? `${publishableKey}:${accountId}` : publishableKey;
|
|
5327
5512
|
}
|
|
5328
5513
|
function useTopup(options) {
|
|
5329
|
-
const { amount, currency } = options;
|
|
5514
|
+
const { amount, currency, autoRecharge } = options;
|
|
5330
5515
|
const { createTopupPayment, customerRef, updateCustomerRef } = useSolvaPay();
|
|
5331
5516
|
const [loading, setLoading] = (0, import_react35.useState)(false);
|
|
5332
5517
|
const [error, setError] = (0, import_react35.useState)(null);
|
|
@@ -5345,7 +5530,7 @@ function useTopup(options) {
|
|
|
5345
5530
|
setLoading(true);
|
|
5346
5531
|
setError(null);
|
|
5347
5532
|
try {
|
|
5348
|
-
const result = await createTopupPayment({ amount, currency });
|
|
5533
|
+
const result = await createTopupPayment({ amount, currency, autoRecharge });
|
|
5349
5534
|
if (!result || typeof result !== "object") {
|
|
5350
5535
|
throw new Error("Invalid topup payment intent response from server");
|
|
5351
5536
|
}
|
|
@@ -5377,7 +5562,7 @@ function useTopup(options) {
|
|
|
5377
5562
|
setLoading(false);
|
|
5378
5563
|
isStartingRef.current = false;
|
|
5379
5564
|
}
|
|
5380
|
-
}, [amount, currency, createTopupPayment, customerRef, updateCustomerRef, loading]);
|
|
5565
|
+
}, [amount, currency, autoRecharge, createTopupPayment, customerRef, updateCustomerRef, loading]);
|
|
5381
5566
|
const reset = (0, import_react35.useCallback)(() => {
|
|
5382
5567
|
isStartingRef.current = false;
|
|
5383
5568
|
setLoading(false);
|
|
@@ -5449,6 +5634,7 @@ var Root5 = (0, import_react36.forwardRef)(function TopupFormRoot(props, forward
|
|
|
5449
5634
|
const {
|
|
5450
5635
|
amount,
|
|
5451
5636
|
currency,
|
|
5637
|
+
autoRecharge,
|
|
5452
5638
|
onSuccess,
|
|
5453
5639
|
onError,
|
|
5454
5640
|
returnUrl,
|
|
@@ -5472,7 +5658,8 @@ var Root5 = (0, import_react36.forwardRef)(function TopupFormRoot(props, forward
|
|
|
5472
5658
|
stripePromise
|
|
5473
5659
|
} = useTopup({
|
|
5474
5660
|
amount,
|
|
5475
|
-
currency
|
|
5661
|
+
currency,
|
|
5662
|
+
autoRecharge
|
|
5476
5663
|
});
|
|
5477
5664
|
const hasInitializedRef = (0, import_react36.useRef)(false);
|
|
5478
5665
|
const hasAmount = amount > 0;
|
package/dist/mcp/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as SolvaPayTransport, _ as SolvaPayProviderInitial, z as SolvaPayConfig, D as BootstrapPlanLike, H as Merchant } from '../shared-LcjvX4fD.cjs';
|
|
2
2
|
import { TOOL_FOR_VIEW, SolvaPayMcpViewKind, BootstrapMerchant, BootstrapProduct, BootstrapPlan, BootstrapCustomer } from '@solvapay/mcp-core';
|
|
3
3
|
export { MCP_TOOL_NAMES, McpToolName } from '@solvapay/mcp-core';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as SolvaPayTransport, _ as SolvaPayProviderInitial, z as SolvaPayConfig, D as BootstrapPlanLike, H as Merchant } from '../shared-D8raw1Nv.js';
|
|
2
2
|
import { TOOL_FOR_VIEW, SolvaPayMcpViewKind, BootstrapMerchant, BootstrapProduct, BootstrapPlan, BootstrapCustomer } from '@solvapay/mcp-core';
|
|
3
3
|
export { MCP_TOOL_NAMES, McpToolName } from '@solvapay/mcp-core';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
package/dist/mcp/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ExternalLinkGlyph,
|
|
4
4
|
LaunchCustomerPortalButton,
|
|
5
5
|
paymentMethodCache
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-SUHDOG7Q.js";
|
|
7
7
|
import {
|
|
8
8
|
AmountPicker,
|
|
9
9
|
BalanceBadge,
|
|
@@ -38,8 +38,9 @@ import {
|
|
|
38
38
|
usePurchase,
|
|
39
39
|
usePurchaseStatus,
|
|
40
40
|
useTransport
|
|
41
|
-
} from "../chunk-
|
|
41
|
+
} from "../chunk-6RR4J74H.js";
|
|
42
42
|
import "../chunk-UMXOAUW7.js";
|
|
43
|
+
import "../chunk-MLKGABMK.js";
|
|
43
44
|
|
|
44
45
|
// src/mcp/adapter.ts
|
|
45
46
|
import { MCP_TOOL_NAMES } from "@solvapay/mcp-core";
|