114 lines
2.5 KiB
TypeScript
114 lines
2.5 KiB
TypeScript
/**
|
|
* Stripe Port
|
|
*
|
|
* Interface for Stripe payment integration.
|
|
*/
|
|
|
|
import { SubscriptionPlanType } from '../../value-objects/subscription-plan.vo';
|
|
|
|
export const STRIPE_PORT = 'STRIPE_PORT';
|
|
|
|
export interface CreateCheckoutSessionInput {
|
|
organizationId: string;
|
|
organizationName: string;
|
|
email: string;
|
|
plan: SubscriptionPlanType;
|
|
billingInterval: 'monthly' | 'yearly';
|
|
successUrl: string;
|
|
cancelUrl: string;
|
|
customerId?: string;
|
|
}
|
|
|
|
export interface CreateCheckoutSessionOutput {
|
|
sessionId: string;
|
|
sessionUrl: string;
|
|
}
|
|
|
|
export interface CreatePortalSessionInput {
|
|
customerId: string;
|
|
returnUrl: string;
|
|
}
|
|
|
|
export interface CreatePortalSessionOutput {
|
|
sessionUrl: string;
|
|
}
|
|
|
|
export interface StripeSubscriptionData {
|
|
subscriptionId: string;
|
|
customerId: string;
|
|
status: string;
|
|
planId: string;
|
|
currentPeriodStart: Date;
|
|
currentPeriodEnd: Date;
|
|
cancelAtPeriodEnd: boolean;
|
|
}
|
|
|
|
export interface StripeCheckoutSessionData {
|
|
sessionId: string;
|
|
customerId: string | null;
|
|
subscriptionId: string | null;
|
|
status: string;
|
|
metadata: Record<string, string>;
|
|
}
|
|
|
|
export interface StripeWebhookEvent {
|
|
type: string;
|
|
data: {
|
|
object: Record<string, unknown>;
|
|
};
|
|
}
|
|
|
|
export interface StripePort {
|
|
/**
|
|
* Create a Stripe Checkout session for subscription purchase
|
|
*/
|
|
createCheckoutSession(
|
|
input: CreateCheckoutSessionInput,
|
|
): Promise<CreateCheckoutSessionOutput>;
|
|
|
|
/**
|
|
* Create a Stripe Customer Portal session for subscription management
|
|
*/
|
|
createPortalSession(
|
|
input: CreatePortalSessionInput,
|
|
): Promise<CreatePortalSessionOutput>;
|
|
|
|
/**
|
|
* Retrieve subscription details from Stripe
|
|
*/
|
|
getSubscription(subscriptionId: string): Promise<StripeSubscriptionData | null>;
|
|
|
|
/**
|
|
* Retrieve checkout session details from Stripe
|
|
*/
|
|
getCheckoutSession(sessionId: string): Promise<StripeCheckoutSessionData | null>;
|
|
|
|
/**
|
|
* Cancel a subscription at period end
|
|
*/
|
|
cancelSubscriptionAtPeriodEnd(subscriptionId: string): Promise<void>;
|
|
|
|
/**
|
|
* Cancel a subscription immediately
|
|
*/
|
|
cancelSubscriptionImmediately(subscriptionId: string): Promise<void>;
|
|
|
|
/**
|
|
* Resume a canceled subscription
|
|
*/
|
|
resumeSubscription(subscriptionId: string): Promise<void>;
|
|
|
|
/**
|
|
* Verify and parse a Stripe webhook event
|
|
*/
|
|
constructWebhookEvent(
|
|
payload: string | Buffer,
|
|
signature: string,
|
|
): Promise<StripeWebhookEvent>;
|
|
|
|
/**
|
|
* Map a Stripe price ID to a subscription plan
|
|
*/
|
|
mapPriceIdToPlan(priceId: string): SubscriptionPlanType | null;
|
|
}
|