@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/edge.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
|
*/
|
|
@@ -3284,6 +3354,7 @@ interface SolvaPayClient {
|
|
|
3284
3354
|
currency: string;
|
|
3285
3355
|
description?: string;
|
|
3286
3356
|
idempotencyKey?: string;
|
|
3357
|
+
autoRecharge?: AutoRechargeInput;
|
|
3287
3358
|
}): Promise<{
|
|
3288
3359
|
processorPaymentId: string;
|
|
3289
3360
|
clientSecret: string;
|
|
@@ -3315,6 +3386,7 @@ interface SolvaPayClient {
|
|
|
3315
3386
|
displayCurrency: string;
|
|
3316
3387
|
creditsPerMinorUnit: number;
|
|
3317
3388
|
displayExchangeRate: number;
|
|
3389
|
+
display?: CreditDisplayBlock;
|
|
3318
3390
|
}>;
|
|
3319
3391
|
createCheckoutSession(params: operations['CheckoutSessionSdkController_createCheckoutSession']['requestBody']['content']['application/json']): Promise<components['schemas']['CreateCheckoutSessionResponse']>;
|
|
3320
3392
|
createCustomerSession(params: components['schemas']['CreateCustomerSessionRequest']): Promise<components['schemas']['CreateCustomerSessionResponse']>;
|
|
@@ -3322,6 +3394,17 @@ interface SolvaPayClient {
|
|
|
3322
3394
|
getPaymentMethod?(params: {
|
|
3323
3395
|
customerRef: string;
|
|
3324
3396
|
}): Promise<PaymentMethodInfo>;
|
|
3397
|
+
getAutoRecharge?(params: {
|
|
3398
|
+
customerRef: string;
|
|
3399
|
+
}): Promise<AutoRechargeResponse>;
|
|
3400
|
+
saveAutoRecharge?(params: SaveAutoRechargeInput & {
|
|
3401
|
+
customerRef: string;
|
|
3402
|
+
}): Promise<SaveAutoRechargeResponse>;
|
|
3403
|
+
disableAutoRecharge?(params: {
|
|
3404
|
+
customerRef: string;
|
|
3405
|
+
}): Promise<{
|
|
3406
|
+
success: true;
|
|
3407
|
+
}>;
|
|
3325
3408
|
}
|
|
3326
3409
|
|
|
3327
3410
|
/**
|
|
@@ -4043,6 +4126,7 @@ interface SolvaPay {
|
|
|
4043
4126
|
currency: string;
|
|
4044
4127
|
description?: string;
|
|
4045
4128
|
idempotencyKey?: string;
|
|
4129
|
+
autoRecharge?: AutoRechargeInput;
|
|
4046
4130
|
}): Promise<{
|
|
4047
4131
|
processorPaymentId: string;
|
|
4048
4132
|
clientSecret: string;
|
|
@@ -4754,6 +4838,7 @@ type CustomerBalanceResult = {
|
|
|
4754
4838
|
displayCurrency: string;
|
|
4755
4839
|
creditsPerMinorUnit: number;
|
|
4756
4840
|
displayExchangeRate: number;
|
|
4841
|
+
display?: CreditDisplayBlock;
|
|
4757
4842
|
};
|
|
4758
4843
|
/**
|
|
4759
4844
|
* Sync customer with SolvaPay backend (ensure customer exists).
|
|
@@ -4884,6 +4969,7 @@ declare function createTopupPaymentIntentCore(request: Request, body: {
|
|
|
4884
4969
|
amount: number;
|
|
4885
4970
|
currency: string;
|
|
4886
4971
|
description?: string;
|
|
4972
|
+
autoRecharge?: AutoRechargeInput;
|
|
4887
4973
|
}, options?: {
|
|
4888
4974
|
solvaPay?: SolvaPay;
|
|
4889
4975
|
includeEmail?: boolean;
|
|
@@ -5122,6 +5208,17 @@ declare function getPaymentMethodCore(request: Request, options?: {
|
|
|
5122
5208
|
includeName?: boolean;
|
|
5123
5209
|
}): Promise<PaymentMethodInfo | ErrorResult>;
|
|
5124
5210
|
|
|
5211
|
+
type HelperOptions = {
|
|
5212
|
+
solvaPay?: SolvaPay;
|
|
5213
|
+
includeEmail?: boolean;
|
|
5214
|
+
includeName?: boolean;
|
|
5215
|
+
};
|
|
5216
|
+
declare function getAutoRechargeCore(request: Request, options?: HelperOptions): Promise<AutoRechargeResponse | ErrorResult>;
|
|
5217
|
+
declare function saveAutoRechargeCore(request: Request, input: AutoRechargeInput, options?: HelperOptions): Promise<SaveAutoRechargeResponse | ErrorResult>;
|
|
5218
|
+
declare function disableAutoRechargeCore(request: Request, options?: HelperOptions): Promise<{
|
|
5219
|
+
success: true;
|
|
5220
|
+
} | ErrorResult>;
|
|
5221
|
+
|
|
5125
5222
|
/**
|
|
5126
5223
|
* Plans Helper (Core)
|
|
5127
5224
|
*
|
|
@@ -5280,4 +5377,4 @@ declare function verifyWebhook({ body, signature, secret, }: {
|
|
|
5280
5377
|
secret: string;
|
|
5281
5378
|
}): Promise<WebhookEvent>;
|
|
5282
5379
|
|
|
5283
|
-
export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, 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 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 PurchaseCheckResult, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, 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, getAuthenticatedUserCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };
|
|
5380
|
+
export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, 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 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 PurchaseCheckResult, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, type TopupProcessResult, 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, disableAutoRechargeCore, getAuthenticatedUserCore, getAutoRechargeCore, getCustomerBalanceCore, getMerchantCore, getPaymentMethodCore, getProductCore, getUsageCore, handleRouteError, isErrorResult, isPaywallStructuredContent, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, processTopupPaymentIntentCore, reactivatePurchaseCore, saveAutoRechargeCore, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };
|
package/dist/edge.js
CHANGED
|
@@ -451,7 +451,8 @@ function createSolvaPayClient(opts) {
|
|
|
451
451
|
purpose: "credit_topup",
|
|
452
452
|
amount: params.amount,
|
|
453
453
|
currency: params.currency,
|
|
454
|
-
description: params.description
|
|
454
|
+
description: params.description,
|
|
455
|
+
...params.autoRecharge ? { autoRecharge: params.autoRecharge } : {}
|
|
455
456
|
})
|
|
456
457
|
});
|
|
457
458
|
if (!res.ok) {
|
|
@@ -689,6 +690,47 @@ function createSolvaPayClient(opts) {
|
|
|
689
690
|
});
|
|
690
691
|
}
|
|
691
692
|
return await res.json();
|
|
693
|
+
},
|
|
694
|
+
async getAutoRecharge(params) {
|
|
695
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
696
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
697
|
+
const res = await fetch(url.toString(), { method: "GET", headers });
|
|
698
|
+
if (!res.ok) {
|
|
699
|
+
const error = await res.text();
|
|
700
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
701
|
+
throw new SolvaPayError(`Get auto-recharge failed (${res.status}): ${error}`, {
|
|
702
|
+
status: res.status
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
return await res.json();
|
|
706
|
+
},
|
|
707
|
+
async saveAutoRecharge(params) {
|
|
708
|
+
const res = await fetch(`${base}/v1/sdk/auto-recharge`, {
|
|
709
|
+
method: "PUT",
|
|
710
|
+
headers,
|
|
711
|
+
body: JSON.stringify(params)
|
|
712
|
+
});
|
|
713
|
+
if (!res.ok) {
|
|
714
|
+
const error = await res.text();
|
|
715
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
716
|
+
throw new SolvaPayError(`Save auto-recharge failed (${res.status}): ${error}`, {
|
|
717
|
+
status: res.status
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
return await res.json();
|
|
721
|
+
},
|
|
722
|
+
async disableAutoRecharge(params) {
|
|
723
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
724
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
725
|
+
const res = await fetch(url.toString(), { method: "DELETE", headers });
|
|
726
|
+
if (!res.ok) {
|
|
727
|
+
const error = await res.text();
|
|
728
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
729
|
+
throw new SolvaPayError(`Disable auto-recharge failed (${res.status}): ${error}`, {
|
|
730
|
+
status: res.status
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
return await res.json();
|
|
692
734
|
}
|
|
693
735
|
};
|
|
694
736
|
}
|
|
@@ -2370,6 +2412,23 @@ async function getCustomerBalanceCore(request, options = {}) {
|
|
|
2370
2412
|
}
|
|
2371
2413
|
}
|
|
2372
2414
|
|
|
2415
|
+
// src/helpers/balance-poll.ts
|
|
2416
|
+
var TOPUP_BALANCE_POLL_DELAYS_MS = [500, 1e3, 2e3, 4e3];
|
|
2417
|
+
var BALANCE_RECONCILE_DELAYS_MS = [500, 1e3, 2e3, 4e3, 8e3, 16e3];
|
|
2418
|
+
async function pollBalanceUntilIncreased(getBalance, baseline, delays = BALANCE_RECONCILE_DELAYS_MS) {
|
|
2419
|
+
for (const delay of delays) {
|
|
2420
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2421
|
+
try {
|
|
2422
|
+
const post = await getBalance();
|
|
2423
|
+
if (post.credits > baseline) {
|
|
2424
|
+
return { creditsAdded: post.credits - baseline };
|
|
2425
|
+
}
|
|
2426
|
+
} catch {
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
return null;
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2373
2432
|
// src/helpers/payment.ts
|
|
2374
2433
|
async function createPaymentIntentCore(request, body, options = {}) {
|
|
2375
2434
|
try {
|
|
@@ -2440,7 +2499,8 @@ async function createTopupPaymentIntentCore(request, body, options = {}) {
|
|
|
2440
2499
|
customerRef,
|
|
2441
2500
|
amount: body.amount,
|
|
2442
2501
|
currency: body.currency,
|
|
2443
|
-
description: body.description
|
|
2502
|
+
description: body.description,
|
|
2503
|
+
...body.autoRecharge ? { autoRecharge: body.autoRecharge } : {}
|
|
2444
2504
|
});
|
|
2445
2505
|
return {
|
|
2446
2506
|
processorPaymentId: paymentIntent.processorPaymentId,
|
|
@@ -2484,7 +2544,6 @@ async function processPaymentIntentCore(request, body, options = {}) {
|
|
|
2484
2544
|
return handleRouteError(error, "Process payment intent", "Payment processing failed");
|
|
2485
2545
|
}
|
|
2486
2546
|
}
|
|
2487
|
-
var TOPUP_BALANCE_POLL_DELAYS_MS = [500, 1e3, 2e3, 4e3];
|
|
2488
2547
|
async function processTopupPaymentIntentCore(request, body, options = {}) {
|
|
2489
2548
|
try {
|
|
2490
2549
|
if (!body.paymentIntentId) {
|
|
@@ -2527,15 +2586,13 @@ async function processTopupPaymentIntentCore(request, body, options = {}) {
|
|
|
2527
2586
|
if (preCredits === null || typeof solvaPay.getCustomerBalance !== "function") {
|
|
2528
2587
|
return { status: "succeeded" };
|
|
2529
2588
|
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
} catch {
|
|
2538
|
-
}
|
|
2589
|
+
const pollResult = await pollBalanceUntilIncreased(
|
|
2590
|
+
() => solvaPay.getCustomerBalance({ customerRef }),
|
|
2591
|
+
preCredits,
|
|
2592
|
+
TOPUP_BALANCE_POLL_DELAYS_MS
|
|
2593
|
+
);
|
|
2594
|
+
if (pollResult) {
|
|
2595
|
+
return { status: "succeeded", creditsAdded: pollResult.creditsAdded };
|
|
2539
2596
|
}
|
|
2540
2597
|
return { status: "succeeded" };
|
|
2541
2598
|
} catch (error) {
|
|
@@ -2804,6 +2861,54 @@ async function getPaymentMethodCore(request, options = {}) {
|
|
|
2804
2861
|
}
|
|
2805
2862
|
}
|
|
2806
2863
|
|
|
2864
|
+
// src/helpers/auto-recharge.ts
|
|
2865
|
+
async function resolveCustomerRef(request, options) {
|
|
2866
|
+
return syncCustomerCore(request, {
|
|
2867
|
+
solvaPay: options.solvaPay,
|
|
2868
|
+
includeEmail: options.includeEmail,
|
|
2869
|
+
includeName: options.includeName
|
|
2870
|
+
});
|
|
2871
|
+
}
|
|
2872
|
+
async function getAutoRechargeCore(request, options = {}) {
|
|
2873
|
+
try {
|
|
2874
|
+
const customerRef = await resolveCustomerRef(request, options);
|
|
2875
|
+
if (isErrorResult(customerRef)) return customerRef;
|
|
2876
|
+
const solvaPay = options.solvaPay ?? createSolvaPay();
|
|
2877
|
+
if (!solvaPay.apiClient.getAutoRecharge) {
|
|
2878
|
+
return { error: "getAutoRecharge is not implemented on this API client", status: 500 };
|
|
2879
|
+
}
|
|
2880
|
+
return solvaPay.apiClient.getAutoRecharge({ customerRef });
|
|
2881
|
+
} catch (error) {
|
|
2882
|
+
return handleRouteError(error, "Get auto-recharge", "Failed to load auto-recharge");
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
async function saveAutoRechargeCore(request, input, options = {}) {
|
|
2886
|
+
try {
|
|
2887
|
+
const customerRef = await resolveCustomerRef(request, options);
|
|
2888
|
+
if (isErrorResult(customerRef)) return customerRef;
|
|
2889
|
+
const solvaPay = options.solvaPay ?? createSolvaPay();
|
|
2890
|
+
if (!solvaPay.apiClient.saveAutoRecharge) {
|
|
2891
|
+
return { error: "saveAutoRecharge is not implemented on this API client", status: 500 };
|
|
2892
|
+
}
|
|
2893
|
+
return solvaPay.apiClient.saveAutoRecharge({ customerRef, ...input });
|
|
2894
|
+
} catch (error) {
|
|
2895
|
+
return handleRouteError(error, "Save auto-recharge", "Failed to save auto-recharge");
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
async function disableAutoRechargeCore(request, options = {}) {
|
|
2899
|
+
try {
|
|
2900
|
+
const customerRef = await resolveCustomerRef(request, options);
|
|
2901
|
+
if (isErrorResult(customerRef)) return customerRef;
|
|
2902
|
+
const solvaPay = options.solvaPay ?? createSolvaPay();
|
|
2903
|
+
if (!solvaPay.apiClient.disableAutoRecharge) {
|
|
2904
|
+
return { error: "disableAutoRecharge is not implemented on this API client", status: 500 };
|
|
2905
|
+
}
|
|
2906
|
+
return solvaPay.apiClient.disableAutoRecharge({ customerRef });
|
|
2907
|
+
} catch (error) {
|
|
2908
|
+
return handleRouteError(error, "Disable auto-recharge", "Failed to disable auto-recharge");
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2807
2912
|
// src/helpers/plans.ts
|
|
2808
2913
|
import { getSolvaPayConfig as getSolvaPayConfig2 } from "@solvapay/core";
|
|
2809
2914
|
async function listPlansCore(request, options = {}) {
|
|
@@ -3132,7 +3237,9 @@ export {
|
|
|
3132
3237
|
createSolvaPay,
|
|
3133
3238
|
createSolvaPayClient,
|
|
3134
3239
|
createTopupPaymentIntentCore,
|
|
3240
|
+
disableAutoRechargeCore,
|
|
3135
3241
|
getAuthenticatedUserCore,
|
|
3242
|
+
getAutoRechargeCore,
|
|
3136
3243
|
getCustomerBalanceCore,
|
|
3137
3244
|
getMerchantCore,
|
|
3138
3245
|
getPaymentMethodCore,
|
|
@@ -3146,6 +3253,7 @@ export {
|
|
|
3146
3253
|
processPaymentIntentCore,
|
|
3147
3254
|
processTopupPaymentIntentCore,
|
|
3148
3255
|
reactivatePurchaseCore,
|
|
3256
|
+
saveAutoRechargeCore,
|
|
3149
3257
|
syncCustomerCore,
|
|
3150
3258
|
trackUsageCore,
|
|
3151
3259
|
verifyWebhook,
|
package/dist/fetch/index.cjs
CHANGED
|
@@ -655,7 +655,8 @@ function createSolvaPayClient(opts) {
|
|
|
655
655
|
purpose: "credit_topup",
|
|
656
656
|
amount: params.amount,
|
|
657
657
|
currency: params.currency,
|
|
658
|
-
description: params.description
|
|
658
|
+
description: params.description,
|
|
659
|
+
...params.autoRecharge ? { autoRecharge: params.autoRecharge } : {}
|
|
659
660
|
})
|
|
660
661
|
});
|
|
661
662
|
if (!res.ok) {
|
|
@@ -893,6 +894,47 @@ function createSolvaPayClient(opts) {
|
|
|
893
894
|
});
|
|
894
895
|
}
|
|
895
896
|
return await res.json();
|
|
897
|
+
},
|
|
898
|
+
async getAutoRecharge(params) {
|
|
899
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
900
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
901
|
+
const res = await fetch(url.toString(), { method: "GET", headers });
|
|
902
|
+
if (!res.ok) {
|
|
903
|
+
const error = await res.text();
|
|
904
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
905
|
+
throw new import_core2.SolvaPayError(`Get auto-recharge failed (${res.status}): ${error}`, {
|
|
906
|
+
status: res.status
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
return await res.json();
|
|
910
|
+
},
|
|
911
|
+
async saveAutoRecharge(params) {
|
|
912
|
+
const res = await fetch(`${base}/v1/sdk/auto-recharge`, {
|
|
913
|
+
method: "PUT",
|
|
914
|
+
headers,
|
|
915
|
+
body: JSON.stringify(params)
|
|
916
|
+
});
|
|
917
|
+
if (!res.ok) {
|
|
918
|
+
const error = await res.text();
|
|
919
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
920
|
+
throw new import_core2.SolvaPayError(`Save auto-recharge failed (${res.status}): ${error}`, {
|
|
921
|
+
status: res.status
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
return await res.json();
|
|
925
|
+
},
|
|
926
|
+
async disableAutoRecharge(params) {
|
|
927
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
928
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
929
|
+
const res = await fetch(url.toString(), { method: "DELETE", headers });
|
|
930
|
+
if (!res.ok) {
|
|
931
|
+
const error = await res.text();
|
|
932
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
933
|
+
throw new import_core2.SolvaPayError(`Disable auto-recharge failed (${res.status}): ${error}`, {
|
|
934
|
+
status: res.status
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
return await res.json();
|
|
896
938
|
}
|
|
897
939
|
};
|
|
898
940
|
}
|
|
@@ -2467,7 +2509,8 @@ async function createTopupPaymentIntentCore(request, body, options = {}) {
|
|
|
2467
2509
|
customerRef,
|
|
2468
2510
|
amount: body.amount,
|
|
2469
2511
|
currency: body.currency,
|
|
2470
|
-
description: body.description
|
|
2512
|
+
description: body.description,
|
|
2513
|
+
...body.autoRecharge ? { autoRecharge: body.autoRecharge } : {}
|
|
2471
2514
|
});
|
|
2472
2515
|
return {
|
|
2473
2516
|
processorPaymentId: paymentIntent.processorPaymentId,
|
package/dist/fetch/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} */
|
package/dist/fetch/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} */
|
package/dist/fetch/index.js
CHANGED
|
@@ -602,7 +602,8 @@ function createSolvaPayClient(opts) {
|
|
|
602
602
|
purpose: "credit_topup",
|
|
603
603
|
amount: params.amount,
|
|
604
604
|
currency: params.currency,
|
|
605
|
-
description: params.description
|
|
605
|
+
description: params.description,
|
|
606
|
+
...params.autoRecharge ? { autoRecharge: params.autoRecharge } : {}
|
|
606
607
|
})
|
|
607
608
|
});
|
|
608
609
|
if (!res.ok) {
|
|
@@ -840,6 +841,47 @@ function createSolvaPayClient(opts) {
|
|
|
840
841
|
});
|
|
841
842
|
}
|
|
842
843
|
return await res.json();
|
|
844
|
+
},
|
|
845
|
+
async getAutoRecharge(params) {
|
|
846
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
847
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
848
|
+
const res = await fetch(url.toString(), { method: "GET", headers });
|
|
849
|
+
if (!res.ok) {
|
|
850
|
+
const error = await res.text();
|
|
851
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
852
|
+
throw new SolvaPayError2(`Get auto-recharge failed (${res.status}): ${error}`, {
|
|
853
|
+
status: res.status
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
return await res.json();
|
|
857
|
+
},
|
|
858
|
+
async saveAutoRecharge(params) {
|
|
859
|
+
const res = await fetch(`${base}/v1/sdk/auto-recharge`, {
|
|
860
|
+
method: "PUT",
|
|
861
|
+
headers,
|
|
862
|
+
body: JSON.stringify(params)
|
|
863
|
+
});
|
|
864
|
+
if (!res.ok) {
|
|
865
|
+
const error = await res.text();
|
|
866
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
867
|
+
throw new SolvaPayError2(`Save auto-recharge failed (${res.status}): ${error}`, {
|
|
868
|
+
status: res.status
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
return await res.json();
|
|
872
|
+
},
|
|
873
|
+
async disableAutoRecharge(params) {
|
|
874
|
+
const url = new URL(`${base}/v1/sdk/auto-recharge`);
|
|
875
|
+
url.searchParams.set("customerRef", params.customerRef);
|
|
876
|
+
const res = await fetch(url.toString(), { method: "DELETE", headers });
|
|
877
|
+
if (!res.ok) {
|
|
878
|
+
const error = await res.text();
|
|
879
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
880
|
+
throw new SolvaPayError2(`Disable auto-recharge failed (${res.status}): ${error}`, {
|
|
881
|
+
status: res.status
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
return await res.json();
|
|
843
885
|
}
|
|
844
886
|
};
|
|
845
887
|
}
|
|
@@ -2414,7 +2456,8 @@ async function createTopupPaymentIntentCore(request, body, options = {}) {
|
|
|
2414
2456
|
customerRef,
|
|
2415
2457
|
amount: body.amount,
|
|
2416
2458
|
currency: body.currency,
|
|
2417
|
-
description: body.description
|
|
2459
|
+
description: body.description,
|
|
2460
|
+
...body.autoRecharge ? { autoRecharge: body.autoRecharge } : {}
|
|
2418
2461
|
});
|
|
2419
2462
|
return {
|
|
2420
2463
|
processorPaymentId: paymentIntent.processorPaymentId,
|