197 lines
6.7 KiB
TypeScript
197 lines
6.7 KiB
TypeScript
import { IPlan, PlanFeatures } from "../../Models/Plans/Plans.interface";
|
|
import { IPlanSuscriptionDocument } from "./PlanSubscriptions.Adapter.Mongoose";
|
|
|
|
export type FindPlanSuscripcionsParams = {
|
|
sessionUser: string;
|
|
mpPreferenceId?: string;
|
|
mpStatus?: string;
|
|
};
|
|
|
|
export type CreatePlanSuscriptionParams = {
|
|
userId: string;
|
|
planId: string;
|
|
mpPlanId: string;
|
|
startDate: Date;
|
|
endDate: Date;
|
|
isActive?: boolean;
|
|
autoRenew: boolean;
|
|
mpPayerId?: number;
|
|
mpPayerEmail?: string;
|
|
mpStatus?: string;
|
|
mpDateCreated?: Date;
|
|
mpInitPoint?: string;
|
|
mpPreferenceId?: string;
|
|
billingMonths?: number;
|
|
pendingPaymentInitPoint?: string;
|
|
pendingPaymentPreferenceId?: string;
|
|
pendingPaymentBillingMonths?: number;
|
|
pendingPaymentType?: "extension" | "upgrade";
|
|
pendingPaymentPlanId?: string;
|
|
pendingPaymentCurrentPlanPrice?: number;
|
|
pendingPaymentRequestedPlanPrice?: number;
|
|
pendingPaymentProratedAmount?: number;
|
|
pendingPaymentRemainingDays?: number;
|
|
pendingPaymentPeriodEndDate?: Date;
|
|
lastPaymentStatus?: LastPlanPaymentStatus;
|
|
lastPaymentPreferenceId?: string;
|
|
lastPaymentAt?: Date;
|
|
lastPaymentType?: LastPlanPaymentType;
|
|
downgradedFromPlanId?: string;
|
|
downgradedFromPlanName?: string;
|
|
downgradedFromPlanCode?: string;
|
|
downgradedAt?: Date;
|
|
downgradeReason?: DowngradeReason;
|
|
};
|
|
|
|
export type CancellPlanSuscriptionParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type CreateMPPreApprovalParams = {
|
|
planId: string;
|
|
sessionUser: string;
|
|
months: number;
|
|
};
|
|
|
|
export type CheckFeatureParams = {
|
|
userId: string;
|
|
feature: PlanFeatures;
|
|
};
|
|
|
|
export enum MP_PRE_APPROVAL_STATUS {
|
|
READY_TO_START = "ready_to_start",
|
|
NO_PAYER_EMAIL = "no_payer_email",
|
|
}
|
|
|
|
export type MPPreApprovalResponse = {
|
|
init_point: string;
|
|
status: MP_PRE_APPROVAL_STATUS;
|
|
};
|
|
|
|
export type ToFreePlanParams = {
|
|
sessionUser: string;
|
|
downgradeReason?: DowngradeReason;
|
|
};
|
|
|
|
export type ToMpParams = {
|
|
planId: string;
|
|
sessionUser: string;
|
|
months: number;
|
|
};
|
|
|
|
export type CheckMpStatusParams = {
|
|
mpPreferenceId: string;
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type DeletePlanSuscriptionByUserParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type GetSubscriptionInitPointParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type VerifyPendingPlanPaymentParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type VerifyPendingPlanPaymentResponse = {
|
|
status: "approved" | "pending" | "not_found" | "rejected" | "failed" | "cancelled";
|
|
approved: boolean;
|
|
message: string;
|
|
subscriptionId?: string;
|
|
paymentId?: string;
|
|
paymentType?: "new" | "extension" | "upgrade";
|
|
};
|
|
|
|
export type LastPlanPaymentStatus = "rejected" | "failed" | "cancelled";
|
|
export type LastPlanPaymentType = "new" | "extension" | "upgrade";
|
|
export type DowngradeReason = "expired";
|
|
|
|
export interface GetSuscriptionInitPointResponse {
|
|
init_point: string;
|
|
}
|
|
|
|
export interface IPlanSuscription {
|
|
id?: string;
|
|
userId: string; // Referencia al ID del usuario
|
|
planId: string; // Referencia al ID del plan suscrito
|
|
mpPlanId: string; //Referencia al ultimo plan contratado por mercadopago.
|
|
startDate: Date; // Fecha de inicio de la suscripción
|
|
endDate: Date; // Fecha de finalización de la suscripción
|
|
isActive: boolean; // Estado de la suscripción (activa o no)
|
|
autoRenew: boolean; // Indica si la suscripción se renueva automáticamente
|
|
paymentMethod: string; // Método de pago usado para la suscripción
|
|
mpPayerId: number; // ID del pagador en MercadoPago.
|
|
mpPayerEmail: string; // Email del pagador en MercadoPago.
|
|
mpStatus: string; // Estado de la suscripción en MercadoPago.
|
|
mpDateCreated: Date; // Fecha de creación de la suscripción en MercadoPago.
|
|
mpInitPoint: string; // URL de inicio de la suscripción en MercadoPago.
|
|
mpPreferenceId: string; // ID de la preferencia en MercadoPago.
|
|
billingMonths?: number; // Cantidad de meses comprados para pagos únicos.
|
|
pendingPaymentInitPoint?: string; // URL de pago pendiente para extender el plan actual.
|
|
pendingPaymentPreferenceId?: string; // ID de preferencia pendiente para extender el plan actual.
|
|
pendingPaymentBillingMonths?: number; // Meses pendientes de acreditar al aprobarse la extensión.
|
|
pendingPaymentType?: "extension" | "upgrade";
|
|
pendingPaymentPlanId?: string;
|
|
pendingPaymentCurrentPlanPrice?: number;
|
|
pendingPaymentRequestedPlanPrice?: number;
|
|
pendingPaymentProratedAmount?: number;
|
|
pendingPaymentRemainingDays?: number;
|
|
pendingPaymentPeriodEndDate?: Date;
|
|
lastPaymentStatus?: LastPlanPaymentStatus;
|
|
lastPaymentPreferenceId?: string;
|
|
lastPaymentAt?: Date;
|
|
lastPaymentType?: LastPlanPaymentType;
|
|
downgradedFromPlanId?: string;
|
|
downgradedFromPlanName?: string;
|
|
downgradedFromPlanCode?: string;
|
|
downgradedAt?: Date;
|
|
downgradeReason?: DowngradeReason;
|
|
}
|
|
|
|
export interface ISubscriptionInfo {
|
|
id: string;
|
|
plan: IPlan;
|
|
startDate: Date;
|
|
endDate: Date;
|
|
isActive: boolean;
|
|
autoRenew: boolean;
|
|
mpStatus: string;
|
|
mpDateCreated: Date;
|
|
pendingPaymentInitPoint?: string;
|
|
pendingPaymentPreferenceId?: string;
|
|
pendingPaymentType?: "extension" | "upgrade";
|
|
lastPaymentStatus?: LastPlanPaymentStatus;
|
|
lastPaymentPreferenceId?: string;
|
|
lastPaymentAt?: Date;
|
|
lastPaymentType?: LastPlanPaymentType;
|
|
downgradedFromPlanId?: string;
|
|
downgradedFromPlanName?: string;
|
|
downgradedFromPlanCode?: string;
|
|
downgradedAt?: Date;
|
|
downgradeReason?: DowngradeReason;
|
|
}
|
|
|
|
export interface IPlanSuscriptionsAdapter {
|
|
find(filters: FindPlanSuscripcionsParams): Promise<IPlanSuscription[]>;
|
|
findOne(data: FindPlanSuscripcionsParams): Promise<IPlanSuscriptionDocument | null>;
|
|
create(data: CreatePlanSuscriptionParams): Promise<IPlanSuscriptionDocument>;
|
|
delete(data: CancellPlanSuscriptionParams): Promise<void>;
|
|
}
|
|
|
|
export interface IPlanSuscriptionsManager {
|
|
planSuscriptions: IPlanSuscriptionsAdapter;
|
|
create(data: CreateMPPreApprovalParams): Promise<MPPreApprovalResponse>;
|
|
cancell(data: CancellPlanSuscriptionParams): Promise<void>;
|
|
findOne(data: FindPlanSuscripcionsParams): Promise<IPlanSuscriptionDocument | null>;
|
|
getSubscriptionByUser(data: FindPlanSuscripcionsParams): Promise<ISubscriptionInfo | null>;
|
|
checkFeature(data: CheckFeatureParams): Promise<boolean>;
|
|
isSubscriptionActive(data: FindPlanSuscripcionsParams): Promise<boolean>;
|
|
toFreePlan(data: ToFreePlanParams): Promise<void>;
|
|
toMP(data: ToMpParams): Promise<IPlanSuscriptionDocument>;
|
|
deletePlanSuscriptionByUser(data: DeletePlanSuscriptionByUserParams): Promise<void>;
|
|
getInitPoint(data: GetSubscriptionInitPointParams): Promise<GetSuscriptionInitPointResponse>;
|
|
}
|