@solvapay/server 1.0.8-preview.5 → 1.0.8-preview.7
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/chunk-R5U7XKVJ.js +16 -0
- package/dist/dist-EPVKJAIP.js +94 -0
- package/dist/dist-JBJ4HMP7.js +94 -0
- package/dist/esm-5GYCIXIY.js +3475 -0
- package/dist/esm-UW7WCMEK.js +3475 -0
- package/dist/index.cjs +293 -12
- package/dist/index.d.cts +35 -3
- package/dist/index.d.ts +35 -3
- package/dist/index.js +289 -12
- package/dist/src/adapters/base.d.ts +57 -0
- package/dist/src/adapters/base.d.ts.map +1 -0
- package/dist/src/adapters/base.js +73 -0
- package/dist/src/adapters/base.js.map +1 -0
- package/dist/src/adapters/http.d.ts +25 -0
- package/dist/src/adapters/http.d.ts.map +1 -0
- package/dist/src/adapters/http.js +99 -0
- package/dist/src/adapters/http.js.map +1 -0
- package/dist/src/adapters/index.d.ts +11 -0
- package/dist/src/adapters/index.d.ts.map +1 -0
- package/dist/src/adapters/index.js +10 -0
- package/dist/src/adapters/index.js.map +1 -0
- package/dist/src/adapters/mcp.d.ts +24 -0
- package/dist/src/adapters/mcp.d.ts.map +1 -0
- package/dist/src/adapters/mcp.js +75 -0
- package/dist/src/adapters/mcp.js.map +1 -0
- package/dist/src/adapters/next.d.ts +24 -0
- package/dist/src/adapters/next.d.ts.map +1 -0
- package/dist/src/adapters/next.js +109 -0
- package/dist/src/adapters/next.js.map +1 -0
- package/dist/src/client.d.ts +58 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +495 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/edge.d.ts +22 -0
- package/dist/src/edge.d.ts.map +1 -0
- package/dist/src/edge.js +91 -0
- package/dist/src/edge.js.map +1 -0
- package/dist/src/factory.d.ts +605 -0
- package/dist/src/factory.d.ts.map +1 -0
- package/dist/src/factory.js +215 -0
- package/dist/src/factory.js.map +1 -0
- package/dist/src/helpers/auth.d.ts +47 -0
- package/dist/src/helpers/auth.d.ts.map +1 -0
- package/dist/src/helpers/auth.js +73 -0
- package/dist/src/helpers/auth.js.map +1 -0
- package/dist/src/helpers/checkout.d.ts +45 -0
- package/dist/src/helpers/checkout.d.ts.map +1 -0
- package/dist/src/helpers/checkout.js +89 -0
- package/dist/src/helpers/checkout.js.map +1 -0
- package/dist/src/helpers/customer.d.ts +51 -0
- package/dist/src/helpers/customer.d.ts.map +1 -0
- package/dist/src/helpers/customer.js +77 -0
- package/dist/src/helpers/customer.js.map +1 -0
- package/dist/src/helpers/error.d.ts +15 -0
- package/dist/src/helpers/error.d.ts.map +1 -0
- package/dist/src/helpers/error.js +35 -0
- package/dist/src/helpers/error.js.map +1 -0
- package/dist/src/helpers/index.d.ts +17 -0
- package/dist/src/helpers/index.d.ts.map +1 -0
- package/dist/src/helpers/index.js +23 -0
- package/dist/src/helpers/index.js.map +1 -0
- package/dist/src/helpers/payment.d.ts +107 -0
- package/dist/src/helpers/payment.d.ts.map +1 -0
- package/dist/src/helpers/payment.js +150 -0
- package/dist/src/helpers/payment.js.map +1 -0
- package/dist/src/helpers/plans.d.ts +19 -0
- package/dist/src/helpers/plans.d.ts.map +1 -0
- package/dist/src/helpers/plans.js +53 -0
- package/dist/src/helpers/plans.js.map +1 -0
- package/dist/src/helpers/renewal.d.ts +23 -0
- package/dist/src/helpers/renewal.d.ts.map +1 -0
- package/dist/src/helpers/renewal.js +90 -0
- package/dist/src/helpers/renewal.js.map +1 -0
- package/dist/src/helpers/subscription.d.ts +23 -0
- package/dist/src/helpers/subscription.d.ts.map +1 -0
- package/dist/src/helpers/subscription.js +101 -0
- package/dist/src/helpers/subscription.js.map +1 -0
- package/dist/src/helpers/types.d.ts +22 -0
- package/dist/src/helpers/types.d.ts.map +1 -0
- package/dist/src/helpers/types.js +7 -0
- package/dist/src/helpers/types.js.map +1 -0
- package/dist/src/index.d.ts +73 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +106 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/auth-bridge.d.ts +9 -0
- package/dist/src/mcp/auth-bridge.d.ts.map +1 -0
- package/dist/src/mcp/auth-bridge.js +46 -0
- package/dist/src/mcp/auth-bridge.js.map +1 -0
- package/dist/src/mcp/oauth-bridge.d.ts +48 -0
- package/dist/src/mcp/oauth-bridge.d.ts.map +1 -0
- package/dist/src/mcp/oauth-bridge.js +110 -0
- package/dist/src/mcp/oauth-bridge.js.map +1 -0
- package/dist/src/mcp-auth.d.ts +17 -0
- package/dist/src/mcp-auth.d.ts.map +1 -0
- package/dist/src/mcp-auth.js +57 -0
- package/dist/src/mcp-auth.js.map +1 -0
- package/dist/src/paywall.d.ts +119 -0
- package/dist/src/paywall.d.ts.map +1 -0
- package/dist/src/paywall.js +700 -0
- package/dist/src/paywall.js.map +1 -0
- package/dist/src/register-virtual-tools-mcp.d.ts +23 -0
- package/dist/src/register-virtual-tools-mcp.d.ts.map +1 -0
- package/dist/src/register-virtual-tools-mcp.js +86 -0
- package/dist/src/register-virtual-tools-mcp.js.map +1 -0
- package/dist/src/types/client.d.ts +216 -0
- package/dist/src/types/client.d.ts.map +1 -0
- package/dist/src/types/client.js +7 -0
- package/dist/src/types/client.js.map +1 -0
- package/dist/src/types/generated.d.ts +2834 -0
- package/dist/src/types/generated.d.ts.map +1 -0
- package/dist/src/types/generated.js +6 -0
- package/dist/src/types/generated.js.map +1 -0
- package/dist/src/types/index.d.ts +13 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +8 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/options.d.ts +126 -0
- package/dist/src/types/options.d.ts.map +1 -0
- package/dist/src/types/options.js +8 -0
- package/dist/src/types/options.js.map +1 -0
- package/dist/src/types/paywall.d.ts +64 -0
- package/dist/src/types/paywall.d.ts.map +1 -0
- package/dist/src/types/paywall.js +7 -0
- package/dist/src/types/paywall.js.map +1 -0
- package/dist/src/types/webhook.d.ts +50 -0
- package/dist/src/types/webhook.d.ts.map +1 -0
- package/dist/src/types/webhook.js +2 -0
- package/dist/src/types/webhook.js.map +1 -0
- package/dist/src/utils.d.ts +110 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +217 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/virtual-tools.d.ts +44 -0
- package/dist/src/virtual-tools.d.ts.map +1 -0
- package/dist/src/virtual-tools.js +140 -0
- package/dist/src/virtual-tools.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Handling Helper
|
|
3
|
+
*
|
|
4
|
+
* Generic error handling utilities for route helpers
|
|
5
|
+
*/
|
|
6
|
+
import { SolvaPayError } from '@solvapay/core';
|
|
7
|
+
/**
|
|
8
|
+
* Check if a result is an error result
|
|
9
|
+
*/
|
|
10
|
+
export function isErrorResult(result) {
|
|
11
|
+
return typeof result === 'object' && result !== null && 'error' in result && 'status' in result;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Handle route errors and convert to ErrorResult
|
|
15
|
+
*/
|
|
16
|
+
export function handleRouteError(error, operationName, defaultMessage) {
|
|
17
|
+
console.error(`[${operationName}] Error:`, error);
|
|
18
|
+
// Handle SolvaPay configuration errors
|
|
19
|
+
if (error instanceof SolvaPayError) {
|
|
20
|
+
const errorMessage = error.message;
|
|
21
|
+
return {
|
|
22
|
+
error: errorMessage,
|
|
23
|
+
status: 500,
|
|
24
|
+
details: errorMessage,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
28
|
+
const message = defaultMessage || `${operationName} failed`;
|
|
29
|
+
return {
|
|
30
|
+
error: message,
|
|
31
|
+
status: 500,
|
|
32
|
+
details: errorMessage,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/helpers/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG9C;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IAC3C,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,CAAA;AACjG,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAc,EACd,aAAqB,EACrB,cAAuB;IAEvB,OAAO,CAAC,KAAK,CAAC,IAAI,aAAa,UAAU,EAAE,KAAK,CAAC,CAAA;IAEjD,uCAAuC;IACvC,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;QACnC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAA;QAClC,OAAO;YACL,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,YAAY;SACtB,CAAA;IACH,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAA;IAC7E,MAAM,OAAO,GAAG,cAAc,IAAI,GAAG,aAAa,SAAS,CAAA;IAE3D,OAAO;QACL,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,YAAY;KACtB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Helpers (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic route helpers that work with standard Web API Request.
|
|
5
|
+
* These can be used by Express, Fastify, Next.js, Edge Functions, etc.
|
|
6
|
+
*
|
|
7
|
+
* Framework-specific wrappers (e.g., Next.js) should be in their respective packages.
|
|
8
|
+
*/
|
|
9
|
+
export type { ErrorResult, AuthenticatedUser } from './types';
|
|
10
|
+
export { isErrorResult, handleRouteError } from './error';
|
|
11
|
+
export { getAuthenticatedUserCore } from './auth';
|
|
12
|
+
export { syncCustomerCore } from './customer';
|
|
13
|
+
export { createPaymentIntentCore, processPaymentIntentCore } from './payment';
|
|
14
|
+
export { createCheckoutSessionCore, createCustomerSessionCore } from './checkout';
|
|
15
|
+
export { cancelPurchaseCore } from './renewal';
|
|
16
|
+
export { listPlansCore } from './plans';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAG7D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAGzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAA;AAGjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAG7C,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAG7E,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAGjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAG9C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route Helpers (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic route helpers that work with standard Web API Request.
|
|
5
|
+
* These can be used by Express, Fastify, Next.js, Edge Functions, etc.
|
|
6
|
+
*
|
|
7
|
+
* Framework-specific wrappers (e.g., Next.js) should be in their respective packages.
|
|
8
|
+
*/
|
|
9
|
+
// Export error handling
|
|
10
|
+
export { isErrorResult, handleRouteError } from './error';
|
|
11
|
+
// Export auth helpers
|
|
12
|
+
export { getAuthenticatedUserCore } from './auth';
|
|
13
|
+
// Export customer helpers
|
|
14
|
+
export { syncCustomerCore } from './customer';
|
|
15
|
+
// Export payment helpers
|
|
16
|
+
export { createPaymentIntentCore, processPaymentIntentCore } from './payment';
|
|
17
|
+
// Export checkout helpers
|
|
18
|
+
export { createCheckoutSessionCore, createCustomerSessionCore } from './checkout';
|
|
19
|
+
// Export purchase cancellation helpers
|
|
20
|
+
export { cancelPurchaseCore } from './renewal';
|
|
21
|
+
// Export plans helpers
|
|
22
|
+
export { listPlansCore } from './plans';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,wBAAwB;AACxB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEzD,sBAAsB;AACtB,OAAO,EAAE,wBAAwB,EAAE,MAAM,QAAQ,CAAA;AAEjD,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,yBAAyB;AACzB,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAE7E,0BAA0B;AAC1B,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAEjF,uCAAuC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAE9C,uBAAuB;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment Helpers (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic helpers for payment operations.
|
|
5
|
+
* Works with standard Web API Request (works everywhere).
|
|
6
|
+
*/
|
|
7
|
+
import type { SolvaPay } from '../factory';
|
|
8
|
+
import type { ErrorResult } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Create a Stripe payment intent for a customer to purchase a plan.
|
|
11
|
+
*
|
|
12
|
+
* This is a framework-agnostic helper that:
|
|
13
|
+
* 1. Extracts authenticated user from the request
|
|
14
|
+
* 2. Syncs customer with SolvaPay backend
|
|
15
|
+
* 3. Creates a payment intent for the specified plan
|
|
16
|
+
*
|
|
17
|
+
* The payment intent can then be confirmed on the client side using Stripe.js.
|
|
18
|
+
* After confirmation, use `processPaymentIntentCore()` to complete the purchase.
|
|
19
|
+
*
|
|
20
|
+
* @param request - Standard Web API Request object
|
|
21
|
+
* @param body - Payment intent parameters
|
|
22
|
+
* @param body.planRef - Plan reference to purchase (required)
|
|
23
|
+
* @param body.productRef - Product reference (required)
|
|
24
|
+
* @param options - Configuration options
|
|
25
|
+
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
26
|
+
* @param options.includeEmail - Whether to include email in customer data (default: true)
|
|
27
|
+
* @param options.includeName - Whether to include name in customer data (default: true)
|
|
28
|
+
* @returns Payment intent response with client secret and customer reference, or error result
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // In an API route handler
|
|
33
|
+
* export async function POST(request: Request) {
|
|
34
|
+
* const body = await request.json();
|
|
35
|
+
* const result = await createPaymentIntentCore(request, body);
|
|
36
|
+
*
|
|
37
|
+
* if (isErrorResult(result)) {
|
|
38
|
+
* return Response.json(result, { status: result.status });
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* return Response.json(result);
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @see {@link processPaymentIntentCore} for processing confirmed payments
|
|
46
|
+
* @see {@link ErrorResult} for error handling
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
49
|
+
export declare function createPaymentIntentCore(request: Request, body: {
|
|
50
|
+
planRef: string;
|
|
51
|
+
productRef: string;
|
|
52
|
+
}, options?: {
|
|
53
|
+
solvaPay?: SolvaPay;
|
|
54
|
+
includeEmail?: boolean;
|
|
55
|
+
includeName?: boolean;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
id: string;
|
|
58
|
+
clientSecret: string;
|
|
59
|
+
publishableKey: string;
|
|
60
|
+
accountId?: string;
|
|
61
|
+
customerRef: string;
|
|
62
|
+
} | ErrorResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Process a payment intent after client-side Stripe confirmation.
|
|
65
|
+
*
|
|
66
|
+
* This helper processes a payment intent that has been confirmed on the client
|
|
67
|
+
* side using Stripe.js. It creates the purchase immediately,
|
|
68
|
+
* eliminating webhook delay.
|
|
69
|
+
*
|
|
70
|
+
* Call this after the client has confirmed the payment intent with Stripe.js.
|
|
71
|
+
*
|
|
72
|
+
* @param request - Standard Web API Request object
|
|
73
|
+
* @param body - Payment processing parameters
|
|
74
|
+
* @param body.paymentIntentId - Stripe payment intent ID from client confirmation (required)
|
|
75
|
+
* @param body.productRef - Product reference (required)
|
|
76
|
+
* @param body.planRef - Optional plan reference (if not in payment intent)
|
|
77
|
+
* @param options - Configuration options
|
|
78
|
+
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
79
|
+
* @returns Process payment result with purchase details, or error result
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // In an API route handler
|
|
84
|
+
* export async function POST(request: Request) {
|
|
85
|
+
* const body = await request.json();
|
|
86
|
+
* const result = await processPaymentIntentCore(request, body);
|
|
87
|
+
*
|
|
88
|
+
* if (isErrorResult(result)) {
|
|
89
|
+
* return Response.json(result, { status: result.status });
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* return Response.json(result);
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @see {@link createPaymentIntentCore} for creating payment intents
|
|
97
|
+
* @see {@link ErrorResult} for error handling
|
|
98
|
+
* @since 1.0.0
|
|
99
|
+
*/
|
|
100
|
+
export declare function processPaymentIntentCore(request: Request, body: {
|
|
101
|
+
paymentIntentId: string;
|
|
102
|
+
productRef: string;
|
|
103
|
+
planRef?: string;
|
|
104
|
+
}, options?: {
|
|
105
|
+
solvaPay?: SolvaPay;
|
|
106
|
+
}): Promise<import('../types/client').ProcessPaymentResult | ErrorResult>;
|
|
107
|
+
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/helpers/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IACJ,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;CACnB,EACD,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,WAAW,CAAC,EAAE,OAAO,CAAA;CACjB,GACL,OAAO,CACN;IACE,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;CACpB,GACD,WAAW,CACd,CAuCA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IACJ,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,EACD,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACf,GACL,OAAO,CAAC,OAAO,iBAAiB,EAAE,oBAAoB,GAAG,WAAW,CAAC,CAgCvE"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment Helpers (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic helpers for payment operations.
|
|
5
|
+
* Works with standard Web API Request (works everywhere).
|
|
6
|
+
*/
|
|
7
|
+
import { createSolvaPay } from '../factory';
|
|
8
|
+
import { handleRouteError, isErrorResult } from './error';
|
|
9
|
+
import { syncCustomerCore } from './customer';
|
|
10
|
+
/**
|
|
11
|
+
* Create a Stripe payment intent for a customer to purchase a plan.
|
|
12
|
+
*
|
|
13
|
+
* This is a framework-agnostic helper that:
|
|
14
|
+
* 1. Extracts authenticated user from the request
|
|
15
|
+
* 2. Syncs customer with SolvaPay backend
|
|
16
|
+
* 3. Creates a payment intent for the specified plan
|
|
17
|
+
*
|
|
18
|
+
* The payment intent can then be confirmed on the client side using Stripe.js.
|
|
19
|
+
* After confirmation, use `processPaymentIntentCore()` to complete the purchase.
|
|
20
|
+
*
|
|
21
|
+
* @param request - Standard Web API Request object
|
|
22
|
+
* @param body - Payment intent parameters
|
|
23
|
+
* @param body.planRef - Plan reference to purchase (required)
|
|
24
|
+
* @param body.productRef - Product reference (required)
|
|
25
|
+
* @param options - Configuration options
|
|
26
|
+
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
27
|
+
* @param options.includeEmail - Whether to include email in customer data (default: true)
|
|
28
|
+
* @param options.includeName - Whether to include name in customer data (default: true)
|
|
29
|
+
* @returns Payment intent response with client secret and customer reference, or error result
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // In an API route handler
|
|
34
|
+
* export async function POST(request: Request) {
|
|
35
|
+
* const body = await request.json();
|
|
36
|
+
* const result = await createPaymentIntentCore(request, body);
|
|
37
|
+
*
|
|
38
|
+
* if (isErrorResult(result)) {
|
|
39
|
+
* return Response.json(result, { status: result.status });
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* return Response.json(result);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @see {@link processPaymentIntentCore} for processing confirmed payments
|
|
47
|
+
* @see {@link ErrorResult} for error handling
|
|
48
|
+
* @since 1.0.0
|
|
49
|
+
*/
|
|
50
|
+
export async function createPaymentIntentCore(request, body, options = {}) {
|
|
51
|
+
try {
|
|
52
|
+
if (!body.planRef || !body.productRef) {
|
|
53
|
+
return {
|
|
54
|
+
error: 'Missing required parameters: planRef and productRef are required',
|
|
55
|
+
status: 400,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const customerResult = await syncCustomerCore(request, {
|
|
59
|
+
solvaPay: options.solvaPay,
|
|
60
|
+
includeEmail: options.includeEmail,
|
|
61
|
+
includeName: options.includeName,
|
|
62
|
+
});
|
|
63
|
+
if (isErrorResult(customerResult)) {
|
|
64
|
+
return customerResult;
|
|
65
|
+
}
|
|
66
|
+
const customerRef = customerResult;
|
|
67
|
+
const solvaPay = options.solvaPay || createSolvaPay();
|
|
68
|
+
const paymentIntent = await solvaPay.createPaymentIntent({
|
|
69
|
+
productRef: body.productRef,
|
|
70
|
+
planRef: body.planRef,
|
|
71
|
+
customerRef,
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
id: paymentIntent.id,
|
|
75
|
+
clientSecret: paymentIntent.clientSecret,
|
|
76
|
+
publishableKey: paymentIntent.publishableKey,
|
|
77
|
+
accountId: paymentIntent.accountId,
|
|
78
|
+
customerRef,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return handleRouteError(error, 'Create payment intent', 'Payment intent creation failed');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Process a payment intent after client-side Stripe confirmation.
|
|
87
|
+
*
|
|
88
|
+
* This helper processes a payment intent that has been confirmed on the client
|
|
89
|
+
* side using Stripe.js. It creates the purchase immediately,
|
|
90
|
+
* eliminating webhook delay.
|
|
91
|
+
*
|
|
92
|
+
* Call this after the client has confirmed the payment intent with Stripe.js.
|
|
93
|
+
*
|
|
94
|
+
* @param request - Standard Web API Request object
|
|
95
|
+
* @param body - Payment processing parameters
|
|
96
|
+
* @param body.paymentIntentId - Stripe payment intent ID from client confirmation (required)
|
|
97
|
+
* @param body.productRef - Product reference (required)
|
|
98
|
+
* @param body.planRef - Optional plan reference (if not in payment intent)
|
|
99
|
+
* @param options - Configuration options
|
|
100
|
+
* @param options.solvaPay - Optional SolvaPay instance (creates new one if not provided)
|
|
101
|
+
* @returns Process payment result with purchase details, or error result
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // In an API route handler
|
|
106
|
+
* export async function POST(request: Request) {
|
|
107
|
+
* const body = await request.json();
|
|
108
|
+
* const result = await processPaymentIntentCore(request, body);
|
|
109
|
+
*
|
|
110
|
+
* if (isErrorResult(result)) {
|
|
111
|
+
* return Response.json(result, { status: result.status });
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* return Response.json(result);
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @see {@link createPaymentIntentCore} for creating payment intents
|
|
119
|
+
* @see {@link ErrorResult} for error handling
|
|
120
|
+
* @since 1.0.0
|
|
121
|
+
*/
|
|
122
|
+
export async function processPaymentIntentCore(request, body, options = {}) {
|
|
123
|
+
try {
|
|
124
|
+
if (!body.paymentIntentId || !body.productRef) {
|
|
125
|
+
return {
|
|
126
|
+
error: 'paymentIntentId and productRef are required',
|
|
127
|
+
status: 400,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const customerResult = await syncCustomerCore(request, {
|
|
131
|
+
solvaPay: options.solvaPay,
|
|
132
|
+
});
|
|
133
|
+
if (isErrorResult(customerResult)) {
|
|
134
|
+
return customerResult;
|
|
135
|
+
}
|
|
136
|
+
const customerRef = customerResult;
|
|
137
|
+
const solvaPay = options.solvaPay || createSolvaPay();
|
|
138
|
+
const result = await solvaPay.processPaymentIntent({
|
|
139
|
+
paymentIntentId: body.paymentIntentId,
|
|
140
|
+
productRef: body.productRef,
|
|
141
|
+
customerRef,
|
|
142
|
+
planRef: body.planRef,
|
|
143
|
+
});
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
return handleRouteError(error, 'Process payment intent', 'Payment processing failed');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../src/helpers/payment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAgB,EAChB,IAGC,EACD,UAII,EAAE;IAWN,IAAI,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACtC,OAAO;gBACL,KAAK,EAAE,kEAAkE;gBACzE,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE;YACrD,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,WAAW,EAAE,OAAO,CAAC,WAAW;SACjC,CAAC,CAAA;QAEF,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YAClC,OAAO,cAAc,CAAA;QACvB,CAAC;QAED,MAAM,WAAW,GAAG,cAAc,CAAA;QAElC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,cAAc,EAAE,CAAA;QAErD,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,mBAAmB,CAAC;YACvD,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW;SACZ,CAAC,CAAA;QAEF,OAAO;YACL,EAAE,EAAE,aAAa,CAAC,EAAE;YACpB,YAAY,EAAE,aAAa,CAAC,YAAY;YACxC,cAAc,EAAE,aAAa,CAAC,cAAc;YAC5C,SAAS,EAAE,aAAa,CAAC,SAAS;YAClC,WAAW;SACZ,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,EAAE,gCAAgC,CAAC,CAAA;IAC3F,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,OAAgB,EAChB,IAIC,EACD,UAEI,EAAE;IAEN,IAAI,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAC9C,OAAO;gBACL,KAAK,EAAE,6CAA6C;gBACpD,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE;YACrD,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,CAAA;QAEF,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YAClC,OAAO,cAAc,CAAA;QACvB,CAAC;QAED,MAAM,WAAW,GAAG,cAAc,CAAA;QAElC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,cAAc,EAAE,CAAA;QAErD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,oBAAoB,CAAC;YACjD,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,WAAW;YACX,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,gBAAgB,CAAC,KAAK,EAAE,wBAAwB,EAAE,2BAA2B,CAAC,CAAA;IACvF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plans Helper (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic helper for listing plans.
|
|
5
|
+
* Works with standard Web API Request (works everywhere).
|
|
6
|
+
* This is a public route - no authentication required.
|
|
7
|
+
*/
|
|
8
|
+
import type { ErrorResult } from './types';
|
|
9
|
+
import type { components } from '../types/generated';
|
|
10
|
+
type Plan = components['schemas']['Plan'];
|
|
11
|
+
/**
|
|
12
|
+
* List plans - core implementation
|
|
13
|
+
*/
|
|
14
|
+
export declare function listPlansCore(request: Request): Promise<{
|
|
15
|
+
plans: Plan[];
|
|
16
|
+
productRef: string;
|
|
17
|
+
} | ErrorResult>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../../src/helpers/plans.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAKpD,KAAK,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzC;;GAEG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAC1D;IACE,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;CACnB,GACD,WAAW,CACd,CA4CA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plans Helper (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic helper for listing plans.
|
|
5
|
+
* Works with standard Web API Request (works everywhere).
|
|
6
|
+
* This is a public route - no authentication required.
|
|
7
|
+
*/
|
|
8
|
+
import { createSolvaPayClient } from '../client';
|
|
9
|
+
import { handleRouteError } from './error';
|
|
10
|
+
import { getSolvaPayConfig } from '@solvapay/core';
|
|
11
|
+
/**
|
|
12
|
+
* List plans - core implementation
|
|
13
|
+
*/
|
|
14
|
+
export async function listPlansCore(request) {
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(request.url);
|
|
17
|
+
const productRef = url.searchParams.get('productRef');
|
|
18
|
+
if (!productRef) {
|
|
19
|
+
return {
|
|
20
|
+
error: 'Missing required parameter: productRef',
|
|
21
|
+
status: 400,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const config = getSolvaPayConfig();
|
|
25
|
+
const solvapaySecretKey = config.apiKey;
|
|
26
|
+
const solvapayApiBaseUrl = config.apiBaseUrl;
|
|
27
|
+
if (!solvapaySecretKey) {
|
|
28
|
+
return {
|
|
29
|
+
error: 'Server configuration error: SolvaPay secret key not configured',
|
|
30
|
+
status: 500,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const apiClient = createSolvaPayClient({
|
|
34
|
+
apiKey: solvapaySecretKey,
|
|
35
|
+
apiBaseUrl: solvapayApiBaseUrl,
|
|
36
|
+
});
|
|
37
|
+
if (!apiClient.listPlans) {
|
|
38
|
+
return {
|
|
39
|
+
error: 'List plans method not available',
|
|
40
|
+
status: 500,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const plans = await apiClient.listPlans(productRef);
|
|
44
|
+
return {
|
|
45
|
+
plans: plans || [],
|
|
46
|
+
productRef,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return handleRouteError(error, 'List plans', 'Failed to fetch plans');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=plans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.js","sourceRoot":"","sources":["../../../src/helpers/plans.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAIlD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAgB;IAOlD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAChC,MAAM,UAAU,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAErD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO;gBACL,KAAK,EAAE,wCAAwC;gBAC/C,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAA;QAClC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAA;QACvC,MAAM,kBAAkB,GAAG,MAAM,CAAC,UAAU,CAAA;QAE5C,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,OAAO;gBACL,KAAK,EAAE,gEAAgE;gBACvE,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,SAAS,GAAG,oBAAoB,CAAC;YACrC,MAAM,EAAE,iBAAiB;YACzB,UAAU,EAAE,kBAAkB;SAC/B,CAAC,CAAA;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;YACzB,OAAO;gBACL,KAAK,EAAE,iCAAiC;gBACxC,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QAEnD,OAAO;YACL,KAAK,EAAE,KAAK,IAAI,EAAE;YAClB,UAAU;SACX,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAA;IACvE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Purchase Cancellation Helpers (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic helpers for purchase cancellation operations.
|
|
5
|
+
* Works with standard Web API Request (works everywhere).
|
|
6
|
+
*/
|
|
7
|
+
import type { SolvaPay } from '../factory';
|
|
8
|
+
import type { ErrorResult } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Cancel purchase - core implementation
|
|
11
|
+
*
|
|
12
|
+
* @param request - Standard Web API Request
|
|
13
|
+
* @param body - Cancellation parameters
|
|
14
|
+
* @param options - Configuration options
|
|
15
|
+
* @returns Cancelled purchase response or error result
|
|
16
|
+
*/
|
|
17
|
+
export declare function cancelPurchaseCore(request: Request, body: {
|
|
18
|
+
purchaseRef: string;
|
|
19
|
+
reason?: string;
|
|
20
|
+
}, options?: {
|
|
21
|
+
solvaPay?: SolvaPay;
|
|
22
|
+
}): Promise<Record<string, unknown> | ErrorResult>;
|
|
23
|
+
//# sourceMappingURL=renewal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renewal.d.ts","sourceRoot":"","sources":["../../../src/helpers/renewal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK1C;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IACJ,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,EACD,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACf,GACL,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC,CAuFhD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Purchase Cancellation Helpers (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic helpers for purchase cancellation operations.
|
|
5
|
+
* Works with standard Web API Request (works everywhere).
|
|
6
|
+
*/
|
|
7
|
+
import { createSolvaPay } from '../factory';
|
|
8
|
+
import { SolvaPayError } from '@solvapay/core';
|
|
9
|
+
import { handleRouteError } from './error';
|
|
10
|
+
/**
|
|
11
|
+
* Cancel purchase - core implementation
|
|
12
|
+
*
|
|
13
|
+
* @param request - Standard Web API Request
|
|
14
|
+
* @param body - Cancellation parameters
|
|
15
|
+
* @param options - Configuration options
|
|
16
|
+
* @returns Cancelled purchase response or error result
|
|
17
|
+
*/
|
|
18
|
+
export async function cancelPurchaseCore(request, body, options = {}) {
|
|
19
|
+
try {
|
|
20
|
+
if (!body.purchaseRef) {
|
|
21
|
+
return {
|
|
22
|
+
error: 'Missing required parameter: purchaseRef is required',
|
|
23
|
+
status: 400,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const solvaPay = options.solvaPay || createSolvaPay();
|
|
27
|
+
if (!solvaPay.apiClient.cancelPurchase) {
|
|
28
|
+
return {
|
|
29
|
+
error: 'Cancel purchase method not available on SDK client',
|
|
30
|
+
status: 500,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
let cancelledPurchase = await solvaPay.apiClient.cancelPurchase({
|
|
34
|
+
purchaseRef: body.purchaseRef,
|
|
35
|
+
reason: body.reason,
|
|
36
|
+
});
|
|
37
|
+
if (!cancelledPurchase || typeof cancelledPurchase !== 'object') {
|
|
38
|
+
return {
|
|
39
|
+
error: 'Invalid response from cancel purchase endpoint',
|
|
40
|
+
status: 500,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const responseObj = cancelledPurchase;
|
|
44
|
+
if (responseObj.purchase && typeof responseObj.purchase === 'object') {
|
|
45
|
+
cancelledPurchase = responseObj.purchase;
|
|
46
|
+
}
|
|
47
|
+
if (!cancelledPurchase.reference) {
|
|
48
|
+
return {
|
|
49
|
+
error: 'Cancel purchase response missing required fields',
|
|
50
|
+
status: 500,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const isCancelled = cancelledPurchase.status === 'cancelled' || cancelledPurchase.cancelledAt;
|
|
54
|
+
if (!isCancelled) {
|
|
55
|
+
return {
|
|
56
|
+
error: `Purchase cancellation failed: backend returned status '${cancelledPurchase.status}' without cancelledAt timestamp`,
|
|
57
|
+
status: 500,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
61
|
+
return cancelledPurchase;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof SolvaPayError) {
|
|
65
|
+
const errorMessage = error.message;
|
|
66
|
+
if (errorMessage.includes('not found')) {
|
|
67
|
+
return {
|
|
68
|
+
error: 'Purchase not found',
|
|
69
|
+
status: 404,
|
|
70
|
+
details: errorMessage,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (errorMessage.includes('cannot be cancelled') ||
|
|
74
|
+
errorMessage.includes('does not belong to provider')) {
|
|
75
|
+
return {
|
|
76
|
+
error: 'Purchase cannot be cancelled or does not belong to provider',
|
|
77
|
+
status: 400,
|
|
78
|
+
details: errorMessage,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
error: errorMessage,
|
|
83
|
+
status: 500,
|
|
84
|
+
details: errorMessage,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return handleRouteError(error, 'Cancel purchase', 'Failed to cancel purchase');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=renewal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renewal.js","sourceRoot":"","sources":["../../../src/helpers/renewal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAgB,EAChB,IAGC,EACD,UAEI,EAAE;IAEN,IAAI,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,OAAO;gBACL,KAAK,EAAE,qDAAqD;gBAC5D,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,cAAc,EAAE,CAAA;QAErD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;YACvC,OAAO;gBACL,KAAK,EAAE,oDAAoD;gBAC3D,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,IAAI,iBAAiB,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC;YAC9D,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAA;QAEF,IAAI,CAAC,iBAAiB,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;YAChE,OAAO;gBACL,KAAK,EAAE,gDAAgD;gBACvD,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,WAAW,GAAG,iBAAuD,CAAA;QAC3E,IAAI,WAAW,CAAC,QAAQ,IAAI,OAAO,WAAW,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACrE,iBAAiB,GAAG,WAAW,CAAC,QAAoC,CAAA;QACtE,CAAC;QAED,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,CAAC;YACjC,OAAO;gBACL,KAAK,EAAE,kDAAkD;gBACzD,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,WAAW,GACf,iBAAiB,CAAC,MAAM,KAAK,WAAW,IAAI,iBAAiB,CAAC,WAAW,CAAA;QAE3E,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO;gBACL,KAAK,EAAE,0DAA0D,iBAAiB,CAAC,MAAM,iCAAiC;gBAC1H,MAAM,EAAE,GAAG;aACZ,CAAA;QACH,CAAC;QAED,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;QAEtD,OAAO,iBAAiB,CAAA;IAC1B,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;YACnC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAA;YAElC,IAAI,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBACvC,OAAO;oBACL,KAAK,EAAE,oBAAoB;oBAC3B,MAAM,EAAE,GAAG;oBACX,OAAO,EAAE,YAAY;iBACtB,CAAA;YACH,CAAC;YAED,IACE,YAAY,CAAC,QAAQ,CAAC,qBAAqB,CAAC;gBAC5C,YAAY,CAAC,QAAQ,CAAC,6BAA6B,CAAC,EACpD,CAAC;gBACD,OAAO;oBACL,KAAK,EAAE,6DAA6D;oBACpE,MAAM,EAAE,GAAG;oBACX,OAAO,EAAE,YAAY;iBACtB,CAAA;YACH,CAAC;YAED,OAAO;gBACL,KAAK,EAAE,YAAY;gBACnB,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,YAAY;aACtB,CAAA;QACH,CAAC;QAED,OAAO,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,EAAE,2BAA2B,CAAC,CAAA;IAChF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription Helpers (Core)
|
|
3
|
+
*
|
|
4
|
+
* Generic helpers for subscription operations.
|
|
5
|
+
* Works with standard Web API Request (works everywhere).
|
|
6
|
+
*/
|
|
7
|
+
import type { SolvaPay } from '../factory';
|
|
8
|
+
import type { ErrorResult } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Cancel subscription - core implementation
|
|
11
|
+
*
|
|
12
|
+
* @param request - Standard Web API Request
|
|
13
|
+
* @param body - Cancellation parameters
|
|
14
|
+
* @param options - Configuration options
|
|
15
|
+
* @returns Cancelled subscription response or error result
|
|
16
|
+
*/
|
|
17
|
+
export declare function cancelSubscriptionCore(request: Request, body: {
|
|
18
|
+
subscriptionRef: string;
|
|
19
|
+
reason?: string;
|
|
20
|
+
}, options?: {
|
|
21
|
+
solvaPay?: SolvaPay;
|
|
22
|
+
}): Promise<any | ErrorResult>;
|
|
23
|
+
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../../src/helpers/subscription.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK1C;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE;IACJ,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,EACD,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACf,GACL,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC,CAkG5B"}
|