@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/index.cjs CHANGED
@@ -30,7 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ BALANCE_RECONCILE_DELAYS_MS: () => BALANCE_RECONCILE_DELAYS_MS,
33
34
  PaywallError: () => PaywallError,
35
+ TOPUP_BALANCE_POLL_DELAYS_MS: () => TOPUP_BALANCE_POLL_DELAYS_MS,
34
36
  VIRTUAL_TOOL_DEFINITIONS: () => VIRTUAL_TOOL_DEFINITIONS,
35
37
  activatePlanCore: () => activatePlanCore,
36
38
  buildGateMessage: () => buildGateMessage,
@@ -47,7 +49,9 @@ __export(index_exports, {
47
49
  createSolvaPayClient: () => createSolvaPayClient,
48
50
  createTopupPaymentIntentCore: () => createTopupPaymentIntentCore,
49
51
  createVirtualTools: () => createVirtualTools,
52
+ disableAutoRechargeCore: () => disableAutoRechargeCore,
50
53
  getAuthenticatedUserCore: () => getAuthenticatedUserCore,
54
+ getAutoRechargeCore: () => getAutoRechargeCore,
51
55
  getCustomerBalanceCore: () => getCustomerBalanceCore,
52
56
  getMerchantCore: () => getMerchantCore,
53
57
  getPaymentMethodCore: () => getPaymentMethodCore,
@@ -59,10 +63,12 @@ __export(index_exports, {
59
63
  jsonSchemaToZodRawShape: () => jsonSchemaToZodRawShape,
60
64
  listPlansCore: () => listPlansCore,
61
65
  paywallErrorToClientPayload: () => paywallErrorToClientPayload,
66
+ pollBalanceUntilIncreased: () => pollBalanceUntilIncreased,
62
67
  processPaymentIntentCore: () => processPaymentIntentCore,
63
68
  processTopupPaymentIntentCore: () => processTopupPaymentIntentCore,
64
69
  reactivatePurchaseCore: () => reactivatePurchaseCore,
65
70
  registerVirtualToolsMcpImpl: () => registerVirtualToolsMcpImpl,
71
+ saveAutoRechargeCore: () => saveAutoRechargeCore,
66
72
  syncCustomerCore: () => syncCustomerCore,
67
73
  trackUsageCore: () => trackUsageCore,
68
74
  verifyWebhook: () => verifyWebhook,
@@ -522,7 +528,8 @@ function createSolvaPayClient(opts) {
522
528
  purpose: "credit_topup",
523
529
  amount: params.amount,
524
530
  currency: params.currency,
525
- description: params.description
531
+ description: params.description,
532
+ ...params.autoRecharge ? { autoRecharge: params.autoRecharge } : {}
526
533
  })
527
534
  });
528
535
  if (!res.ok) {
@@ -760,6 +767,47 @@ function createSolvaPayClient(opts) {
760
767
  });
761
768
  }
762
769
  return await res.json();
770
+ },
771
+ async getAutoRecharge(params) {
772
+ const url = new URL(`${base}/v1/sdk/auto-recharge`);
773
+ url.searchParams.set("customerRef", params.customerRef);
774
+ const res = await fetch(url.toString(), { method: "GET", headers });
775
+ if (!res.ok) {
776
+ const error = await res.text();
777
+ log(`\u274C API Error: ${res.status} - ${error}`);
778
+ throw new import_core.SolvaPayError(`Get auto-recharge failed (${res.status}): ${error}`, {
779
+ status: res.status
780
+ });
781
+ }
782
+ return await res.json();
783
+ },
784
+ async saveAutoRecharge(params) {
785
+ const res = await fetch(`${base}/v1/sdk/auto-recharge`, {
786
+ method: "PUT",
787
+ headers,
788
+ body: JSON.stringify(params)
789
+ });
790
+ if (!res.ok) {
791
+ const error = await res.text();
792
+ log(`\u274C API Error: ${res.status} - ${error}`);
793
+ throw new import_core.SolvaPayError(`Save auto-recharge failed (${res.status}): ${error}`, {
794
+ status: res.status
795
+ });
796
+ }
797
+ return await res.json();
798
+ },
799
+ async disableAutoRecharge(params) {
800
+ const url = new URL(`${base}/v1/sdk/auto-recharge`);
801
+ url.searchParams.set("customerRef", params.customerRef);
802
+ const res = await fetch(url.toString(), { method: "DELETE", headers });
803
+ if (!res.ok) {
804
+ const error = await res.text();
805
+ log(`\u274C API Error: ${res.status} - ${error}`);
806
+ throw new import_core.SolvaPayError(`Disable auto-recharge failed (${res.status}): ${error}`, {
807
+ status: res.status
808
+ });
809
+ }
810
+ return await res.json();
763
811
  }
764
812
  };
765
813
  }
@@ -2442,6 +2490,23 @@ async function getCustomerBalanceCore(request, options = {}) {
2442
2490
  }
2443
2491
  }
2444
2492
 
2493
+ // src/helpers/balance-poll.ts
2494
+ var TOPUP_BALANCE_POLL_DELAYS_MS = [500, 1e3, 2e3, 4e3];
2495
+ var BALANCE_RECONCILE_DELAYS_MS = [500, 1e3, 2e3, 4e3, 8e3, 16e3];
2496
+ async function pollBalanceUntilIncreased(getBalance, baseline, delays = BALANCE_RECONCILE_DELAYS_MS) {
2497
+ for (const delay of delays) {
2498
+ await new Promise((resolve) => setTimeout(resolve, delay));
2499
+ try {
2500
+ const post = await getBalance();
2501
+ if (post.credits > baseline) {
2502
+ return { creditsAdded: post.credits - baseline };
2503
+ }
2504
+ } catch {
2505
+ }
2506
+ }
2507
+ return null;
2508
+ }
2509
+
2445
2510
  // src/helpers/payment.ts
2446
2511
  async function createPaymentIntentCore(request, body, options = {}) {
2447
2512
  try {
@@ -2512,7 +2577,8 @@ async function createTopupPaymentIntentCore(request, body, options = {}) {
2512
2577
  customerRef,
2513
2578
  amount: body.amount,
2514
2579
  currency: body.currency,
2515
- description: body.description
2580
+ description: body.description,
2581
+ ...body.autoRecharge ? { autoRecharge: body.autoRecharge } : {}
2516
2582
  });
2517
2583
  return {
2518
2584
  processorPaymentId: paymentIntent.processorPaymentId,
@@ -2556,7 +2622,6 @@ async function processPaymentIntentCore(request, body, options = {}) {
2556
2622
  return handleRouteError(error, "Process payment intent", "Payment processing failed");
2557
2623
  }
2558
2624
  }
2559
- var TOPUP_BALANCE_POLL_DELAYS_MS = [500, 1e3, 2e3, 4e3];
2560
2625
  async function processTopupPaymentIntentCore(request, body, options = {}) {
2561
2626
  try {
2562
2627
  if (!body.paymentIntentId) {
@@ -2599,15 +2664,13 @@ async function processTopupPaymentIntentCore(request, body, options = {}) {
2599
2664
  if (preCredits === null || typeof solvaPay.getCustomerBalance !== "function") {
2600
2665
  return { status: "succeeded" };
2601
2666
  }
2602
- for (const delay of TOPUP_BALANCE_POLL_DELAYS_MS) {
2603
- await new Promise((resolve) => setTimeout(resolve, delay));
2604
- try {
2605
- const post = await solvaPay.getCustomerBalance({ customerRef });
2606
- if (post.credits > preCredits) {
2607
- return { status: "succeeded", creditsAdded: post.credits - preCredits };
2608
- }
2609
- } catch {
2610
- }
2667
+ const pollResult = await pollBalanceUntilIncreased(
2668
+ () => solvaPay.getCustomerBalance({ customerRef }),
2669
+ preCredits,
2670
+ TOPUP_BALANCE_POLL_DELAYS_MS
2671
+ );
2672
+ if (pollResult) {
2673
+ return { status: "succeeded", creditsAdded: pollResult.creditsAdded };
2611
2674
  }
2612
2675
  return { status: "succeeded" };
2613
2676
  } catch (error) {
@@ -2876,6 +2939,54 @@ async function getPaymentMethodCore(request, options = {}) {
2876
2939
  }
2877
2940
  }
2878
2941
 
2942
+ // src/helpers/auto-recharge.ts
2943
+ async function resolveCustomerRef(request, options) {
2944
+ return syncCustomerCore(request, {
2945
+ solvaPay: options.solvaPay,
2946
+ includeEmail: options.includeEmail,
2947
+ includeName: options.includeName
2948
+ });
2949
+ }
2950
+ async function getAutoRechargeCore(request, options = {}) {
2951
+ try {
2952
+ const customerRef = await resolveCustomerRef(request, options);
2953
+ if (isErrorResult(customerRef)) return customerRef;
2954
+ const solvaPay = options.solvaPay ?? createSolvaPay();
2955
+ if (!solvaPay.apiClient.getAutoRecharge) {
2956
+ return { error: "getAutoRecharge is not implemented on this API client", status: 500 };
2957
+ }
2958
+ return solvaPay.apiClient.getAutoRecharge({ customerRef });
2959
+ } catch (error) {
2960
+ return handleRouteError(error, "Get auto-recharge", "Failed to load auto-recharge");
2961
+ }
2962
+ }
2963
+ async function saveAutoRechargeCore(request, input, options = {}) {
2964
+ try {
2965
+ const customerRef = await resolveCustomerRef(request, options);
2966
+ if (isErrorResult(customerRef)) return customerRef;
2967
+ const solvaPay = options.solvaPay ?? createSolvaPay();
2968
+ if (!solvaPay.apiClient.saveAutoRecharge) {
2969
+ return { error: "saveAutoRecharge is not implemented on this API client", status: 500 };
2970
+ }
2971
+ return solvaPay.apiClient.saveAutoRecharge({ customerRef, ...input });
2972
+ } catch (error) {
2973
+ return handleRouteError(error, "Save auto-recharge", "Failed to save auto-recharge");
2974
+ }
2975
+ }
2976
+ async function disableAutoRechargeCore(request, options = {}) {
2977
+ try {
2978
+ const customerRef = await resolveCustomerRef(request, options);
2979
+ if (isErrorResult(customerRef)) return customerRef;
2980
+ const solvaPay = options.solvaPay ?? createSolvaPay();
2981
+ if (!solvaPay.apiClient.disableAutoRecharge) {
2982
+ return { error: "disableAutoRecharge is not implemented on this API client", status: 500 };
2983
+ }
2984
+ return solvaPay.apiClient.disableAutoRecharge({ customerRef });
2985
+ } catch (error) {
2986
+ return handleRouteError(error, "Disable auto-recharge", "Failed to disable auto-recharge");
2987
+ }
2988
+ }
2989
+
2879
2990
  // src/helpers/plans.ts
2880
2991
  var import_core5 = require("@solvapay/core");
2881
2992
  async function listPlansCore(request, options = {}) {
@@ -3175,7 +3286,9 @@ function verifyWebhook({
3175
3286
  }
3176
3287
  // Annotate the CommonJS export names for ESM import in node:
3177
3288
  0 && (module.exports = {
3289
+ BALANCE_RECONCILE_DELAYS_MS,
3178
3290
  PaywallError,
3291
+ TOPUP_BALANCE_POLL_DELAYS_MS,
3179
3292
  VIRTUAL_TOOL_DEFINITIONS,
3180
3293
  activatePlanCore,
3181
3294
  buildGateMessage,
@@ -3192,7 +3305,9 @@ function verifyWebhook({
3192
3305
  createSolvaPayClient,
3193
3306
  createTopupPaymentIntentCore,
3194
3307
  createVirtualTools,
3308
+ disableAutoRechargeCore,
3195
3309
  getAuthenticatedUserCore,
3310
+ getAutoRechargeCore,
3196
3311
  getCustomerBalanceCore,
3197
3312
  getMerchantCore,
3198
3313
  getPaymentMethodCore,
@@ -3204,10 +3319,12 @@ function verifyWebhook({
3204
3319
  jsonSchemaToZodRawShape,
3205
3320
  listPlansCore,
3206
3321
  paywallErrorToClientPayload,
3322
+ pollBalanceUntilIncreased,
3207
3323
  processPaymentIntentCore,
3208
3324
  processTopupPaymentIntentCore,
3209
3325
  reactivatePurchaseCore,
3210
3326
  registerVirtualToolsMcpImpl,
3327
+ saveAutoRechargeCore,
3211
3328
  syncCustomerCore,
3212
3329
  trackUsageCore,
3213
3330
  verifyWebhook,
package/dist/index.d.cts CHANGED
@@ -838,6 +838,14 @@ interface components {
838
838
  * @example 99
839
839
  */
840
840
  unitsRemaining: number;
841
+ autoRecharge?: components["schemas"]["AutoRechargeTriggeredResponse"];
842
+ };
843
+ AutoRechargeTriggeredResponse: {
844
+ /**
845
+ * Whether the server initiated an auto-recharge charge after this debit
846
+ * @example true
847
+ */
848
+ triggered: boolean;
841
849
  };
842
850
  CreditDebitSkippedResponse: {
843
851
  /** @enum {number} */
@@ -3123,6 +3131,68 @@ type ActivatePlanResult = components['schemas']['ActivatePlanResponseDto'];
3123
3131
  * `{ kind: 'card', ... } | { kind: 'none' }` discriminated union here.
3124
3132
  */
3125
3133
  type PaymentMethodInfo = operations['PaymentMethodSdkController_getPaymentMethod']['responses']['200']['content']['application/json'];
3134
+ type AutoRechargeStatus = 'active' | 'disabled' | 'failed' | 'pending_setup';
3135
+ type AutoRechargeConfig = {
3136
+ enabled: boolean;
3137
+ trigger: {
3138
+ type: 'balance';
3139
+ thresholdAmountMinor: number;
3140
+ };
3141
+ topup: {
3142
+ mode: 'fixed';
3143
+ amountMinor: number;
3144
+ currency: string;
3145
+ };
3146
+ fundingSourceType?: 'saved_card' | 'tokenized_card';
3147
+ paymentMethodId?: string;
3148
+ status: AutoRechargeStatus;
3149
+ failureCount: number;
3150
+ lastChargeAt?: string;
3151
+ updatedAt?: string;
3152
+ /** Backend-computed display values — render verbatim; do not derive from trigger fields. */
3153
+ display?: AutoRechargeDisplayBlock;
3154
+ };
3155
+ type AutoRechargeDisplayBlock = {
3156
+ thresholdAmountMajor: number;
3157
+ topupAmountMajor: number;
3158
+ currency: string;
3159
+ formatted: {
3160
+ threshold: string;
3161
+ topup: string;
3162
+ };
3163
+ exchangeRate: number;
3164
+ rateSource: 'parity' | 'db' | 'fallback';
3165
+ };
3166
+ type CreditDisplayBlock = {
3167
+ amountMajor: number;
3168
+ currency: string;
3169
+ formatted: string;
3170
+ exchangeRate: number;
3171
+ rateSource: 'parity' | 'db' | 'fallback';
3172
+ };
3173
+ type AutoRechargeInput = {
3174
+ enabled: boolean;
3175
+ triggerType: 'balance';
3176
+ thresholdAmountMajor?: number;
3177
+ topupAmountMajor?: number;
3178
+ maxRecharges?: number;
3179
+ currency: string;
3180
+ };
3181
+ /** PUT /sdk/auto-recharge — input plus request-only flags. */
3182
+ type SaveAutoRechargeInput = AutoRechargeInput & {
3183
+ deferSetupIntent?: boolean;
3184
+ };
3185
+ type AutoRechargeResponse = {
3186
+ config: AutoRechargeConfig | null;
3187
+ display?: AutoRechargeDisplayBlock;
3188
+ };
3189
+ type SaveAutoRechargeResponse = {
3190
+ config: AutoRechargeConfig;
3191
+ display?: AutoRechargeDisplayBlock;
3192
+ setupClientSecret?: string;
3193
+ publishableKey?: string;
3194
+ stripeAccountId?: string;
3195
+ };
3126
3196
  /**
3127
3197
  * SDK-facing merchant identity (source: GET /v1/sdk/merchant).
3128
3198
  */
@@ -3286,6 +3356,7 @@ interface SolvaPayClient {
3286
3356
  currency: string;
3287
3357
  description?: string;
3288
3358
  idempotencyKey?: string;
3359
+ autoRecharge?: AutoRechargeInput;
3289
3360
  }): Promise<{
3290
3361
  processorPaymentId: string;
3291
3362
  clientSecret: string;
@@ -3317,6 +3388,7 @@ interface SolvaPayClient {
3317
3388
  displayCurrency: string;
3318
3389
  creditsPerMinorUnit: number;
3319
3390
  displayExchangeRate: number;
3391
+ display?: CreditDisplayBlock;
3320
3392
  }>;
3321
3393
  createCheckoutSession(params: operations['CheckoutSessionSdkController_createCheckoutSession']['requestBody']['content']['application/json']): Promise<components['schemas']['CreateCheckoutSessionResponse']>;
3322
3394
  createCustomerSession(params: components['schemas']['CreateCustomerSessionRequest']): Promise<components['schemas']['CreateCustomerSessionResponse']>;
@@ -3324,6 +3396,17 @@ interface SolvaPayClient {
3324
3396
  getPaymentMethod?(params: {
3325
3397
  customerRef: string;
3326
3398
  }): Promise<PaymentMethodInfo>;
3399
+ getAutoRecharge?(params: {
3400
+ customerRef: string;
3401
+ }): Promise<AutoRechargeResponse>;
3402
+ saveAutoRecharge?(params: SaveAutoRechargeInput & {
3403
+ customerRef: string;
3404
+ }): Promise<SaveAutoRechargeResponse>;
3405
+ disableAutoRecharge?(params: {
3406
+ customerRef: string;
3407
+ }): Promise<{
3408
+ success: true;
3409
+ }>;
3327
3410
  }
3328
3411
 
3329
3412
  /**
@@ -4006,6 +4089,7 @@ interface SolvaPay {
4006
4089
  currency: string;
4007
4090
  description?: string;
4008
4091
  idempotencyKey?: string;
4092
+ autoRecharge?: AutoRechargeInput;
4009
4093
  }): Promise<{
4010
4094
  processorPaymentId: string;
4011
4095
  clientSecret: string;
@@ -4803,6 +4887,7 @@ type CustomerBalanceResult = {
4803
4887
  displayCurrency: string;
4804
4888
  creditsPerMinorUnit: number;
4805
4889
  displayExchangeRate: number;
4890
+ display?: CreditDisplayBlock;
4806
4891
  };
4807
4892
  /**
4808
4893
  * Sync customer with SolvaPay backend (ensure customer exists).
@@ -4933,6 +5018,7 @@ declare function createTopupPaymentIntentCore(request: Request, body: {
4933
5018
  amount: number;
4934
5019
  currency: string;
4935
5020
  description?: string;
5021
+ autoRecharge?: AutoRechargeInput;
4936
5022
  }, options?: {
4937
5023
  solvaPay?: SolvaPay;
4938
5024
  includeEmail?: boolean;
@@ -5171,6 +5257,17 @@ declare function getPaymentMethodCore(request: Request, options?: {
5171
5257
  includeName?: boolean;
5172
5258
  }): Promise<PaymentMethodInfo | ErrorResult>;
5173
5259
 
5260
+ type HelperOptions = {
5261
+ solvaPay?: SolvaPay;
5262
+ includeEmail?: boolean;
5263
+ includeName?: boolean;
5264
+ };
5265
+ declare function getAutoRechargeCore(request: Request, options?: HelperOptions): Promise<AutoRechargeResponse | ErrorResult>;
5266
+ declare function saveAutoRechargeCore(request: Request, input: AutoRechargeInput, options?: HelperOptions): Promise<SaveAutoRechargeResponse | ErrorResult>;
5267
+ declare function disableAutoRechargeCore(request: Request, options?: HelperOptions): Promise<{
5268
+ success: true;
5269
+ } | ErrorResult>;
5270
+
5174
5271
  /**
5175
5272
  * Plans Helper (Core)
5176
5273
  *
@@ -5316,6 +5413,15 @@ declare function trackUsageCore(request: Request, body: {
5316
5413
  solvaPay?: SolvaPay;
5317
5414
  }): Promise<TrackUsageResponse | ErrorResult>;
5318
5415
 
5416
+ declare const TOPUP_BALANCE_POLL_DELAYS_MS: readonly [500, 1000, 2000, 4000];
5417
+ /** Backoff for client-side balance reconciliation after async credit top-ups (e.g. auto-recharge). */
5418
+ declare const BALANCE_RECONCILE_DELAYS_MS: readonly [500, 1000, 2000, 4000, 8000, 16000];
5419
+ declare function pollBalanceUntilIncreased(getBalance: () => Promise<{
5420
+ credits: number;
5421
+ }>, baseline: number, delays?: readonly number[]): Promise<{
5422
+ creditsAdded: number;
5423
+ } | null>;
5424
+
5319
5425
  /**
5320
5426
  * SolvaPay Server SDK
5321
5427
  *
@@ -5371,4 +5477,4 @@ declare function verifyWebhook({ body, signature, secret, }: {
5371
5477
  secret: string;
5372
5478
  }): WebhookEvent;
5373
5479
 
5374
- export { type ActivatePlanResult, type AssignCreditsRequest, type AssignCreditsResponse, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CreditDebitResult, type CreditDebitSkipReason, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type GetUsageResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type LimitResponseWithPlan, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableAllowResult, type PayableFunction, type PayableGateOptions, type PayableGateResult, type PayableOptions, type PayablePaywallResult, type PaymentMethodInfo, type PaywallArgs, type PaywallDecision, PaywallError, type PaywallMetadata, type PaywallState, type PaywallStructuredContent, type ProcessPaymentResult, type ProtectHandlerContext, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, type TrackUsageBulkRequest, type TrackUsageBulkResponse, type TrackUsageRequest, type TrackUsageResponse, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, getAuthenticatedUserCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };
5480
+ export { type ActivatePlanResult, type AssignCreditsRequest, type AssignCreditsResponse, type AuthenticatedUser, type AutoRechargeConfig, type AutoRechargeDisplayBlock, type AutoRechargeInput, type AutoRechargeResponse, BALANCE_RECONCILE_DELAYS_MS, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CreditDebitResult, type CreditDebitSkipReason, type CreditDisplayBlock, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type GetUsageResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type LimitResponseWithPlan, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableAllowResult, type PayableFunction, type PayableGateOptions, type PayableGateResult, type PayableOptions, type PayablePaywallResult, type PaymentMethodInfo, type PaywallArgs, type PaywallDecision, PaywallError, type PaywallMetadata, type PaywallState, type PaywallStructuredContent, type ProcessPaymentResult, type ProtectHandlerContext, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SaveAutoRechargeInput, type SaveAutoRechargeResponse, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, TOPUP_BALANCE_POLL_DELAYS_MS, type ToolPlanMappingInput, type TopupProcessResult, type TrackUsageBulkRequest, type TrackUsageBulkResponse, type TrackUsageRequest, type TrackUsageResponse, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, disableAutoRechargeCore, getAuthenticatedUserCore, getAutoRechargeCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, pollBalanceUntilIncreased, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, saveAutoRechargeCore, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };
package/dist/index.d.ts CHANGED
@@ -838,6 +838,14 @@ interface components {
838
838
  * @example 99
839
839
  */
840
840
  unitsRemaining: number;
841
+ autoRecharge?: components["schemas"]["AutoRechargeTriggeredResponse"];
842
+ };
843
+ AutoRechargeTriggeredResponse: {
844
+ /**
845
+ * Whether the server initiated an auto-recharge charge after this debit
846
+ * @example true
847
+ */
848
+ triggered: boolean;
841
849
  };
842
850
  CreditDebitSkippedResponse: {
843
851
  /** @enum {number} */
@@ -3123,6 +3131,68 @@ type ActivatePlanResult = components['schemas']['ActivatePlanResponseDto'];
3123
3131
  * `{ kind: 'card', ... } | { kind: 'none' }` discriminated union here.
3124
3132
  */
3125
3133
  type PaymentMethodInfo = operations['PaymentMethodSdkController_getPaymentMethod']['responses']['200']['content']['application/json'];
3134
+ type AutoRechargeStatus = 'active' | 'disabled' | 'failed' | 'pending_setup';
3135
+ type AutoRechargeConfig = {
3136
+ enabled: boolean;
3137
+ trigger: {
3138
+ type: 'balance';
3139
+ thresholdAmountMinor: number;
3140
+ };
3141
+ topup: {
3142
+ mode: 'fixed';
3143
+ amountMinor: number;
3144
+ currency: string;
3145
+ };
3146
+ fundingSourceType?: 'saved_card' | 'tokenized_card';
3147
+ paymentMethodId?: string;
3148
+ status: AutoRechargeStatus;
3149
+ failureCount: number;
3150
+ lastChargeAt?: string;
3151
+ updatedAt?: string;
3152
+ /** Backend-computed display values — render verbatim; do not derive from trigger fields. */
3153
+ display?: AutoRechargeDisplayBlock;
3154
+ };
3155
+ type AutoRechargeDisplayBlock = {
3156
+ thresholdAmountMajor: number;
3157
+ topupAmountMajor: number;
3158
+ currency: string;
3159
+ formatted: {
3160
+ threshold: string;
3161
+ topup: string;
3162
+ };
3163
+ exchangeRate: number;
3164
+ rateSource: 'parity' | 'db' | 'fallback';
3165
+ };
3166
+ type CreditDisplayBlock = {
3167
+ amountMajor: number;
3168
+ currency: string;
3169
+ formatted: string;
3170
+ exchangeRate: number;
3171
+ rateSource: 'parity' | 'db' | 'fallback';
3172
+ };
3173
+ type AutoRechargeInput = {
3174
+ enabled: boolean;
3175
+ triggerType: 'balance';
3176
+ thresholdAmountMajor?: number;
3177
+ topupAmountMajor?: number;
3178
+ maxRecharges?: number;
3179
+ currency: string;
3180
+ };
3181
+ /** PUT /sdk/auto-recharge — input plus request-only flags. */
3182
+ type SaveAutoRechargeInput = AutoRechargeInput & {
3183
+ deferSetupIntent?: boolean;
3184
+ };
3185
+ type AutoRechargeResponse = {
3186
+ config: AutoRechargeConfig | null;
3187
+ display?: AutoRechargeDisplayBlock;
3188
+ };
3189
+ type SaveAutoRechargeResponse = {
3190
+ config: AutoRechargeConfig;
3191
+ display?: AutoRechargeDisplayBlock;
3192
+ setupClientSecret?: string;
3193
+ publishableKey?: string;
3194
+ stripeAccountId?: string;
3195
+ };
3126
3196
  /**
3127
3197
  * SDK-facing merchant identity (source: GET /v1/sdk/merchant).
3128
3198
  */
@@ -3286,6 +3356,7 @@ interface SolvaPayClient {
3286
3356
  currency: string;
3287
3357
  description?: string;
3288
3358
  idempotencyKey?: string;
3359
+ autoRecharge?: AutoRechargeInput;
3289
3360
  }): Promise<{
3290
3361
  processorPaymentId: string;
3291
3362
  clientSecret: string;
@@ -3317,6 +3388,7 @@ interface SolvaPayClient {
3317
3388
  displayCurrency: string;
3318
3389
  creditsPerMinorUnit: number;
3319
3390
  displayExchangeRate: number;
3391
+ display?: CreditDisplayBlock;
3320
3392
  }>;
3321
3393
  createCheckoutSession(params: operations['CheckoutSessionSdkController_createCheckoutSession']['requestBody']['content']['application/json']): Promise<components['schemas']['CreateCheckoutSessionResponse']>;
3322
3394
  createCustomerSession(params: components['schemas']['CreateCustomerSessionRequest']): Promise<components['schemas']['CreateCustomerSessionResponse']>;
@@ -3324,6 +3396,17 @@ interface SolvaPayClient {
3324
3396
  getPaymentMethod?(params: {
3325
3397
  customerRef: string;
3326
3398
  }): Promise<PaymentMethodInfo>;
3399
+ getAutoRecharge?(params: {
3400
+ customerRef: string;
3401
+ }): Promise<AutoRechargeResponse>;
3402
+ saveAutoRecharge?(params: SaveAutoRechargeInput & {
3403
+ customerRef: string;
3404
+ }): Promise<SaveAutoRechargeResponse>;
3405
+ disableAutoRecharge?(params: {
3406
+ customerRef: string;
3407
+ }): Promise<{
3408
+ success: true;
3409
+ }>;
3327
3410
  }
3328
3411
 
3329
3412
  /**
@@ -4006,6 +4089,7 @@ interface SolvaPay {
4006
4089
  currency: string;
4007
4090
  description?: string;
4008
4091
  idempotencyKey?: string;
4092
+ autoRecharge?: AutoRechargeInput;
4009
4093
  }): Promise<{
4010
4094
  processorPaymentId: string;
4011
4095
  clientSecret: string;
@@ -4803,6 +4887,7 @@ type CustomerBalanceResult = {
4803
4887
  displayCurrency: string;
4804
4888
  creditsPerMinorUnit: number;
4805
4889
  displayExchangeRate: number;
4890
+ display?: CreditDisplayBlock;
4806
4891
  };
4807
4892
  /**
4808
4893
  * Sync customer with SolvaPay backend (ensure customer exists).
@@ -4933,6 +5018,7 @@ declare function createTopupPaymentIntentCore(request: Request, body: {
4933
5018
  amount: number;
4934
5019
  currency: string;
4935
5020
  description?: string;
5021
+ autoRecharge?: AutoRechargeInput;
4936
5022
  }, options?: {
4937
5023
  solvaPay?: SolvaPay;
4938
5024
  includeEmail?: boolean;
@@ -5171,6 +5257,17 @@ declare function getPaymentMethodCore(request: Request, options?: {
5171
5257
  includeName?: boolean;
5172
5258
  }): Promise<PaymentMethodInfo | ErrorResult>;
5173
5259
 
5260
+ type HelperOptions = {
5261
+ solvaPay?: SolvaPay;
5262
+ includeEmail?: boolean;
5263
+ includeName?: boolean;
5264
+ };
5265
+ declare function getAutoRechargeCore(request: Request, options?: HelperOptions): Promise<AutoRechargeResponse | ErrorResult>;
5266
+ declare function saveAutoRechargeCore(request: Request, input: AutoRechargeInput, options?: HelperOptions): Promise<SaveAutoRechargeResponse | ErrorResult>;
5267
+ declare function disableAutoRechargeCore(request: Request, options?: HelperOptions): Promise<{
5268
+ success: true;
5269
+ } | ErrorResult>;
5270
+
5174
5271
  /**
5175
5272
  * Plans Helper (Core)
5176
5273
  *
@@ -5316,6 +5413,15 @@ declare function trackUsageCore(request: Request, body: {
5316
5413
  solvaPay?: SolvaPay;
5317
5414
  }): Promise<TrackUsageResponse | ErrorResult>;
5318
5415
 
5416
+ declare const TOPUP_BALANCE_POLL_DELAYS_MS: readonly [500, 1000, 2000, 4000];
5417
+ /** Backoff for client-side balance reconciliation after async credit top-ups (e.g. auto-recharge). */
5418
+ declare const BALANCE_RECONCILE_DELAYS_MS: readonly [500, 1000, 2000, 4000, 8000, 16000];
5419
+ declare function pollBalanceUntilIncreased(getBalance: () => Promise<{
5420
+ credits: number;
5421
+ }>, baseline: number, delays?: readonly number[]): Promise<{
5422
+ creditsAdded: number;
5423
+ } | null>;
5424
+
5319
5425
  /**
5320
5426
  * SolvaPay Server SDK
5321
5427
  *
@@ -5371,4 +5477,4 @@ declare function verifyWebhook({ body, signature, secret, }: {
5371
5477
  secret: string;
5372
5478
  }): WebhookEvent;
5373
5479
 
5374
- export { type ActivatePlanResult, type AssignCreditsRequest, type AssignCreditsResponse, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CreditDebitResult, type CreditDebitSkipReason, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type GetUsageResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type LimitResponseWithPlan, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableAllowResult, type PayableFunction, type PayableGateOptions, type PayableGateResult, type PayableOptions, type PayablePaywallResult, type PaymentMethodInfo, type PaywallArgs, type PaywallDecision, PaywallError, type PaywallMetadata, type PaywallState, type PaywallStructuredContent, type ProcessPaymentResult, type ProtectHandlerContext, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, type TrackUsageBulkRequest, type TrackUsageBulkResponse, type TrackUsageRequest, type TrackUsageResponse, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, getAuthenticatedUserCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };
5480
+ export { type ActivatePlanResult, type AssignCreditsRequest, type AssignCreditsResponse, type AuthenticatedUser, type AutoRechargeConfig, type AutoRechargeDisplayBlock, type AutoRechargeInput, type AutoRechargeResponse, BALANCE_RECONCILE_DELAYS_MS, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CreditDebitResult, type CreditDebitSkipReason, type CreditDisplayBlock, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type GetUsageResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type LimitResponseWithPlan, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableAllowResult, type PayableFunction, type PayableGateOptions, type PayableGateResult, type PayableOptions, type PayablePaywallResult, type PaymentMethodInfo, type PaywallArgs, type PaywallDecision, PaywallError, type PaywallMetadata, type PaywallState, type PaywallStructuredContent, type ProcessPaymentResult, type ProtectHandlerContext, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SaveAutoRechargeInput, type SaveAutoRechargeResponse, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, TOPUP_BALANCE_POLL_DELAYS_MS, type ToolPlanMappingInput, type TopupProcessResult, type TrackUsageBulkRequest, type TrackUsageBulkResponse, type TrackUsageRequest, type TrackUsageResponse, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildGateMessage, buildNudgeMessage, buildPaywallGate, cancelPurchaseCore, checkLimitsCore, checkPurchaseCore, classifyPaywallState, type components, createCheckoutSessionCore, createCustomerSessionCore, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, disableAutoRechargeCore, getAuthenticatedUserCore, getAutoRechargeCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, pollBalanceUntilIncreased, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, saveAutoRechargeCore, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };