@solvapay/server 1.2.1 → 1.3.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/dist/edge.d.ts +98 -1
- package/dist/edge.js +120 -12
- package/dist/fetch/index.cjs +45 -2
- package/dist/fetch/index.d.cts +8 -0
- package/dist/fetch/index.d.ts +8 -0
- package/dist/fetch/index.js +45 -2
- package/dist/index.cjs +129 -12
- package/dist/index.d.cts +107 -1
- package/dist/index.d.ts +107 -1
- package/dist/index.js +123 -12
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -452,7 +452,8 @@ function createSolvaPayClient(opts) {
|
|
|
452
452
|
purpose: "credit_topup",
|
|
453
453
|
amount: params.amount,
|
|
454
454
|
currency: params.currency,
|
|
455
|
-
description: params.description
|
|
455
|
+
description: params.description,
|
|
456
|
+
...params.autoRecharge ? { autoRecharge: params.autoRecharge } : {}
|
|
456
457
|
})
|
|
457
458
|
});
|
|
458
459
|
if (!res.ok) {
|
|
@@ -690,6 +691,47 @@ function createSolvaPayClient(opts) {
|
|
|
690
691
|
});
|
|
691
692
|
}
|
|
692
693
|
return await res.json();
|
|
694
|
+
},
|
|
695
|
+
async getAutoRecharge(params) {
|
|
696
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
697
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
698
|
+
const res = await fetch(url.toString(), { method: "GET", headers });
|
|
699
|
+
if (!res.ok) {
|
|
700
|
+
const error = await res.text();
|
|
701
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
702
|
+
throw new SolvaPayError(`Get auto-recharge failed (${res.status}): ${error}`, {
|
|
703
|
+
status: res.status
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
return await res.json();
|
|
707
|
+
},
|
|
708
|
+
async saveAutoRecharge(params) {
|
|
709
|
+
const res = await fetch(`${base}/v1/sdk/auto-recharge`, {
|
|
710
|
+
method: "PUT",
|
|
711
|
+
headers,
|
|
712
|
+
body: JSON.stringify(params)
|
|
713
|
+
});
|
|
714
|
+
if (!res.ok) {
|
|
715
|
+
const error = await res.text();
|
|
716
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
717
|
+
throw new SolvaPayError(`Save auto-recharge failed (${res.status}): ${error}`, {
|
|
718
|
+
status: res.status
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
return await res.json();
|
|
722
|
+
},
|
|
723
|
+
async disableAutoRecharge(params) {
|
|
724
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
725
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
726
|
+
const res = await fetch(url.toString(), { method: "DELETE", headers });
|
|
727
|
+
if (!res.ok) {
|
|
728
|
+
const error = await res.text();
|
|
729
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
730
|
+
throw new SolvaPayError(`Disable auto-recharge failed (${res.status}): ${error}`, {
|
|
731
|
+
status: res.status
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
return await res.json();
|
|
693
735
|
}
|
|
694
736
|
};
|
|
695
737
|
}
|
|
@@ -2372,6 +2414,23 @@ async function getCustomerBalanceCore(request, options = {}) {
|
|
|
2372
2414
|
}
|
|
2373
2415
|
}
|
|
2374
2416
|
|
|
2417
|
+
// src/helpers/balance-poll.ts
|
|
2418
|
+
var TOPUP_BALANCE_POLL_DELAYS_MS = [500, 1e3, 2e3, 4e3];
|
|
2419
|
+
var BALANCE_RECONCILE_DELAYS_MS = [500, 1e3, 2e3, 4e3, 8e3, 16e3];
|
|
2420
|
+
async function pollBalanceUntilIncreased(getBalance, baseline, delays = BALANCE_RECONCILE_DELAYS_MS) {
|
|
2421
|
+
for (const delay of delays) {
|
|
2422
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2423
|
+
try {
|
|
2424
|
+
const post = await getBalance();
|
|
2425
|
+
if (post.credits > baseline) {
|
|
2426
|
+
return { creditsAdded: post.credits - baseline };
|
|
2427
|
+
}
|
|
2428
|
+
} catch {
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return null;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2375
2434
|
// src/helpers/payment.ts
|
|
2376
2435
|
async function createPaymentIntentCore(request, body, options = {}) {
|
|
2377
2436
|
try {
|
|
@@ -2442,7 +2501,8 @@ async function createTopupPaymentIntentCore(request, body, options = {}) {
|
|
|
2442
2501
|
customerRef,
|
|
2443
2502
|
amount: body.amount,
|
|
2444
2503
|
currency: body.currency,
|
|
2445
|
-
description: body.description
|
|
2504
|
+
description: body.description,
|
|
2505
|
+
...body.autoRecharge ? { autoRecharge: body.autoRecharge } : {}
|
|
2446
2506
|
});
|
|
2447
2507
|
return {
|
|
2448
2508
|
processorPaymentId: paymentIntent.processorPaymentId,
|
|
@@ -2486,7 +2546,6 @@ async function processPaymentIntentCore(request, body, options = {}) {
|
|
|
2486
2546
|
return handleRouteError(error, "Process payment intent", "Payment processing failed");
|
|
2487
2547
|
}
|
|
2488
2548
|
}
|
|
2489
|
-
var TOPUP_BALANCE_POLL_DELAYS_MS = [500, 1e3, 2e3, 4e3];
|
|
2490
2549
|
async function processTopupPaymentIntentCore(request, body, options = {}) {
|
|
2491
2550
|
try {
|
|
2492
2551
|
if (!body.paymentIntentId) {
|
|
@@ -2529,15 +2588,13 @@ async function processTopupPaymentIntentCore(request, body, options = {}) {
|
|
|
2529
2588
|
if (preCredits === null || typeof solvaPay.getCustomerBalance !== "function") {
|
|
2530
2589
|
return { status: "succeeded" };
|
|
2531
2590
|
}
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
} catch {
|
|
2540
|
-
}
|
|
2591
|
+
const pollResult = await pollBalanceUntilIncreased(
|
|
2592
|
+
() => solvaPay.getCustomerBalance({ customerRef }),
|
|
2593
|
+
preCredits,
|
|
2594
|
+
TOPUP_BALANCE_POLL_DELAYS_MS
|
|
2595
|
+
);
|
|
2596
|
+
if (pollResult) {
|
|
2597
|
+
return { status: "succeeded", creditsAdded: pollResult.creditsAdded };
|
|
2541
2598
|
}
|
|
2542
2599
|
return { status: "succeeded" };
|
|
2543
2600
|
} catch (error) {
|
|
@@ -2806,6 +2863,54 @@ async function getPaymentMethodCore(request, options = {}) {
|
|
|
2806
2863
|
}
|
|
2807
2864
|
}
|
|
2808
2865
|
|
|
2866
|
+
// src/helpers/auto-recharge.ts
|
|
2867
|
+
async function resolveCustomerRef(request, options) {
|
|
2868
|
+
return syncCustomerCore(request, {
|
|
2869
|
+
solvaPay: options.solvaPay,
|
|
2870
|
+
includeEmail: options.includeEmail,
|
|
2871
|
+
includeName: options.includeName
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
async function getAutoRechargeCore(request, options = {}) {
|
|
2875
|
+
try {
|
|
2876
|
+
const customerRef = await resolveCustomerRef(request, options);
|
|
2877
|
+
if (isErrorResult(customerRef)) return customerRef;
|
|
2878
|
+
const solvaPay = options.solvaPay ?? createSolvaPay();
|
|
2879
|
+
if (!solvaPay.apiClient.getAutoRecharge) {
|
|
2880
|
+
return { error: "getAutoRecharge is not implemented on this API client", status: 500 };
|
|
2881
|
+
}
|
|
2882
|
+
return solvaPay.apiClient.getAutoRecharge({ customerRef });
|
|
2883
|
+
} catch (error) {
|
|
2884
|
+
return handleRouteError(error, "Get auto-recharge", "Failed to load auto-recharge");
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
async function saveAutoRechargeCore(request, input, options = {}) {
|
|
2888
|
+
try {
|
|
2889
|
+
const customerRef = await resolveCustomerRef(request, options);
|
|
2890
|
+
if (isErrorResult(customerRef)) return customerRef;
|
|
2891
|
+
const solvaPay = options.solvaPay ?? createSolvaPay();
|
|
2892
|
+
if (!solvaPay.apiClient.saveAutoRecharge) {
|
|
2893
|
+
return { error: "saveAutoRecharge is not implemented on this API client", status: 500 };
|
|
2894
|
+
}
|
|
2895
|
+
return solvaPay.apiClient.saveAutoRecharge({ customerRef, ...input });
|
|
2896
|
+
} catch (error) {
|
|
2897
|
+
return handleRouteError(error, "Save auto-recharge", "Failed to save auto-recharge");
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
async function disableAutoRechargeCore(request, options = {}) {
|
|
2901
|
+
try {
|
|
2902
|
+
const customerRef = await resolveCustomerRef(request, options);
|
|
2903
|
+
if (isErrorResult(customerRef)) return customerRef;
|
|
2904
|
+
const solvaPay = options.solvaPay ?? createSolvaPay();
|
|
2905
|
+
if (!solvaPay.apiClient.disableAutoRecharge) {
|
|
2906
|
+
return { error: "disableAutoRecharge is not implemented on this API client", status: 500 };
|
|
2907
|
+
}
|
|
2908
|
+
return solvaPay.apiClient.disableAutoRecharge({ customerRef });
|
|
2909
|
+
} catch (error) {
|
|
2910
|
+
return handleRouteError(error, "Disable auto-recharge", "Failed to disable auto-recharge");
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2809
2914
|
// src/helpers/plans.ts
|
|
2810
2915
|
import { getSolvaPayConfig as getSolvaPayConfig2 } from "@solvapay/core";
|
|
2811
2916
|
async function listPlansCore(request, options = {}) {
|
|
@@ -3104,7 +3209,9 @@ function verifyWebhook({
|
|
|
3104
3209
|
}
|
|
3105
3210
|
}
|
|
3106
3211
|
export {
|
|
3212
|
+
BALANCE_RECONCILE_DELAYS_MS,
|
|
3107
3213
|
PaywallError,
|
|
3214
|
+
TOPUP_BALANCE_POLL_DELAYS_MS,
|
|
3108
3215
|
VIRTUAL_TOOL_DEFINITIONS,
|
|
3109
3216
|
activatePlanCore,
|
|
3110
3217
|
buildGateMessage,
|
|
@@ -3121,7 +3228,9 @@ export {
|
|
|
3121
3228
|
createSolvaPayClient,
|
|
3122
3229
|
createTopupPaymentIntentCore,
|
|
3123
3230
|
createVirtualTools,
|
|
3231
|
+
disableAutoRechargeCore,
|
|
3124
3232
|
getAuthenticatedUserCore,
|
|
3233
|
+
getAutoRechargeCore,
|
|
3125
3234
|
getCustomerBalanceCore,
|
|
3126
3235
|
getMerchantCore,
|
|
3127
3236
|
getPaymentMethodCore,
|
|
@@ -3133,10 +3242,12 @@ export {
|
|
|
3133
3242
|
jsonSchemaToZodRawShape,
|
|
3134
3243
|
listPlansCore,
|
|
3135
3244
|
paywallErrorToClientPayload,
|
|
3245
|
+
pollBalanceUntilIncreased,
|
|
3136
3246
|
processPaymentIntentCore,
|
|
3137
3247
|
processTopupPaymentIntentCore,
|
|
3138
3248
|
reactivatePurchaseCore,
|
|
3139
3249
|
registerVirtualToolsMcpImpl,
|
|
3250
|
+
saveAutoRechargeCore,
|
|
3140
3251
|
syncCustomerCore,
|
|
3141
3252
|
trackUsageCore,
|
|
3142
3253
|
verifyWebhook,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solvapay/server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-preview-ecd61384a4e849717e13d47ab2daa086cdcd91c5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"sideEffects": false,
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@solvapay/core": "1.1.
|
|
45
|
+
"@solvapay/core": "1.1.1-preview-ecd61384a4e849717e13d47ab2daa086cdcd91c5"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"zod": "^3.25.0 || ^4.0.0",
|