apps/recallassess/recallassess-api/src/api/shared/stripe/services/stripe-payment.service.ts
Facade for Stripe payment flows. Implementation is split under {@code ./stripe-payment/} (max ~1500 lines per file).
constructor(billing: StripePaymentBillingHelpersService, invoiceWebhooks: StripePaymentInvoiceWebhookService, checkout: StripePaymentCheckoutService, syncRefund: StripePaymentSyncRefundService, subscriptionAdmin: StripePaymentSubscriptionAdminService, customerSubscription: StripePaymentCustomerSubscriptionService)
|
|||||||||||||||||||||
|
Parameters :
|
| Async createCheckoutSession | ||||||
createCheckoutSession(dto: CreateCheckoutSessionDto)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async createPaymentIntent | ||||||
createPaymentIntent(dto: CreatePaymentIntentDto)
|
||||||
|
Parameters :
Returns :
unknown
|
| extractStripePaymentIdsFromInvoice | ||||||
extractStripePaymentIdsFromInvoice(inv: Stripe.Invoice)
|
||||||
|
Parameters :
Returns :
literal type
|
| Async getInvoiceStatus | ||||||
getInvoiceStatus(invoiceId: number)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async handleCheckoutSessionCompleted | ||||||
handleCheckoutSessionCompleted(session: Stripe.Checkout.Session)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async handleCustomerSubscriptionUpdated | ||||||
handleCustomerSubscriptionUpdated(subscription: Stripe.Subscription)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async handleInvoiceCreated | ||||||
handleInvoiceCreated(invoice: Stripe.Invoice)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async handleInvoicePaid | ||||||
handleInvoicePaid(invoice: Stripe.Invoice)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async handleInvoicePaymentFailed | ||||||
handleInvoicePaymentFailed(stripeInvoice: Stripe.Invoice)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async handleInvoicePaymentPaid | ||||||
handleInvoicePaymentPaid(eventObject: unknown)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async handlePaymentFailed | ||||||
handlePaymentFailed(paymentIntent: Stripe.PaymentIntent)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async handlePaymentMethodAttached | ||||||
handlePaymentMethodAttached(paymentMethod: Stripe.PaymentMethod)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async handlePaymentSucceeded | ||||||
handlePaymentSucceeded(paymentIntent: Stripe.PaymentIntent)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async handleRefundCreated | ||||||
handleRefundCreated(refund: Stripe.Refund)
|
||||||
|
Parameters :
Returns :
Promise<boolean>
|
| Async handleSetupIntentSucceeded | ||||||
handleSetupIntentSucceeded(setupIntent: Stripe.SetupIntent)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async previewImmediateExpiredRecoveryCharge |
previewImmediateExpiredRecoveryCharge(companyId: number, fromDate?: string)
|
|
Returns :
unknown
|
| Async refreshPaidSubscriptionLinkedPackageFromCatalog | ||||||
refreshPaidSubscriptionLinkedPackageFromCatalog(companyId: number)
|
||||||
|
Parameters :
Returns :
Promise<void>
|
| Async runAdminCreateStripeSubscription | ||||||
runAdminCreateStripeSubscription(companyId: number)
|
||||||
|
Parameters :
Returns :
Promise<literal type>
|
| Async runBatchStripeSubscriptionSync | ||||||
runBatchStripeSubscriptionSync(options?: literal type)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async runImmediateExpiredRecoveryCharge | |||||||||
runImmediateExpiredRecoveryCharge(companyId: number, options?: literal type)
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async sendBillingSubscriptionResumeEmail | ||||||||||||
sendBillingSubscriptionResumeEmail(companyId: number, subscription: Stripe.Subscription, options?: literal type)
|
||||||||||||
|
Parameters :
Returns :
Promise<void>
|
| Async sendBillingSubscriptionScheduledCancelEmail | ||||||||||||
sendBillingSubscriptionScheduledCancelEmail(companyId: number, subscription: Stripe.Subscription, options?: literal type)
|
||||||||||||
|
Parameters :
Returns :
Promise<void>
|
| Async syncCompanyInvoicesAndRefundsFromStripe | ||||||
syncCompanyInvoicesAndRefundsFromStripe(companyId: number)
|
||||||
|
Parameters :
Returns :
Promise<literal type>
|
| Async updateAdminStripeNextBillingDate |
updateAdminStripeNextBillingDate(companyId: number, nextBillingDate: string)
|
|
Returns :
Promise<literal type>
|
import { Injectable } from "@nestjs/common";
import Stripe from "stripe";
import { CreateCheckoutSessionDto, CreatePaymentIntentDto } from "../dto/payment.dto";
import { StripePaymentBillingHelpersService } from "./stripe-payment/stripe-payment-billing-helpers.service";
import { StripePaymentCheckoutService } from "./stripe-payment/stripe-payment-checkout.service";
import { StripePaymentCustomerSubscriptionService } from "./stripe-payment/stripe-payment-customer-subscription.service";
import { StripePaymentInvoiceWebhookService } from "./stripe-payment/stripe-payment-invoice-webhook.service";
import { StripePaymentSubscriptionAdminService } from "./stripe-payment/stripe-payment-subscription-admin.service";
import { StripePaymentSyncRefundService } from "./stripe-payment/stripe-payment-sync-refund.service";
export type { ImmediateRecoveryQuote } from "./stripe-payment/stripe-payment.types";
/**
* Facade for Stripe payment flows. Implementation is split under {@code ./stripe-payment/} (max ~1500 lines per file).
*/
@Injectable()
export class StripePaymentService {
constructor(
private readonly billing: StripePaymentBillingHelpersService,
private readonly invoiceWebhooks: StripePaymentInvoiceWebhookService,
private readonly checkout: StripePaymentCheckoutService,
private readonly syncRefund: StripePaymentSyncRefundService,
private readonly subscriptionAdmin: StripePaymentSubscriptionAdminService,
private readonly customerSubscription: StripePaymentCustomerSubscriptionService,
) {}
extractStripePaymentIdsFromInvoice(inv: Stripe.Invoice): {
paymentIntentId: string | null;
chargeId: string | null;
checkoutSessionId: string | null;
} {
return this.billing.extractPaymentIntentAndChargeIds(inv);
}
async handleInvoicePaid(invoice: Stripe.Invoice): Promise<void> {
return this.invoiceWebhooks.handleInvoicePaid(invoice);
}
async handleInvoicePaymentFailed(stripeInvoice: Stripe.Invoice): Promise<void> {
return this.invoiceWebhooks.handleInvoicePaymentFailed(stripeInvoice);
}
async handleInvoicePaymentPaid(eventObject: unknown): Promise<void> {
return this.invoiceWebhooks.handleInvoicePaymentPaid(eventObject);
}
async handlePaymentMethodAttached(paymentMethod: Stripe.PaymentMethod): Promise<void> {
return this.invoiceWebhooks.handlePaymentMethodAttached(paymentMethod);
}
async handleSetupIntentSucceeded(setupIntent: Stripe.SetupIntent): Promise<void> {
return this.invoiceWebhooks.handleSetupIntentSucceeded(setupIntent);
}
async handleInvoiceCreated(invoice: Stripe.Invoice): Promise<void> {
return this.invoiceWebhooks.handleInvoiceCreated(invoice);
}
async updateAdminStripeNextBillingDate(
companyId: number,
nextBillingDate: string,
): Promise<{ success: boolean; message: string; next_billing_date: string }> {
return this.syncRefund.updateAdminStripeNextBillingDate(companyId, nextBillingDate);
}
async syncCompanyInvoicesAndRefundsFromStripe(companyId: number): Promise<{
success: boolean;
message: string;
invoices_created: number;
refunds_created: number;
}> {
return this.syncRefund.syncCompanyInvoicesAndRefundsFromStripe(companyId);
}
async handleRefundCreated(refund: Stripe.Refund): Promise<boolean> {
return this.syncRefund.handleRefundCreated(refund);
}
async sendBillingSubscriptionScheduledCancelEmail(
companyId: number,
subscription: Stripe.Subscription,
options?: { triggeredBy?: string; subscriptionRowId?: number },
): Promise<void> {
return this.customerSubscription.sendBillingSubscriptionScheduledCancelEmail(companyId, subscription, options);
}
async sendBillingSubscriptionResumeEmail(
companyId: number,
subscription: Stripe.Subscription,
options?: { triggeredBy?: string; subscriptionRowId?: number },
): Promise<void> {
return this.customerSubscription.sendBillingSubscriptionResumeEmail(companyId, subscription, options);
}
async createCheckoutSession(dto: CreateCheckoutSessionDto) {
return this.checkout.createCheckoutSession(dto);
}
async createPaymentIntent(dto: CreatePaymentIntentDto) {
return this.checkout.createPaymentIntent(dto);
}
async getInvoiceStatus(invoiceId: number) {
return this.checkout.getInvoiceStatus(invoiceId);
}
async handleCheckoutSessionCompleted(session: Stripe.Checkout.Session) {
return this.checkout.handleCheckoutSessionCompleted(session);
}
async handlePaymentSucceeded(paymentIntent: Stripe.PaymentIntent) {
return this.checkout.handlePaymentSucceeded(paymentIntent);
}
async handlePaymentFailed(paymentIntent: Stripe.PaymentIntent) {
return this.checkout.handlePaymentFailed(paymentIntent);
}
async runBatchStripeSubscriptionSync(options?: { dryRun?: boolean; recoverExpiredCompanies?: boolean }) {
return this.subscriptionAdmin.runBatchStripeSubscriptionSync(options);
}
async refreshPaidSubscriptionLinkedPackageFromCatalog(companyId: number): Promise<void> {
return this.subscriptionAdmin.refreshPaidSubscriptionLinkedPackageFromCatalog(companyId);
}
async runAdminCreateStripeSubscription(companyId: number): Promise<{
success: boolean;
message: string;
next_period_end_iso?: string | null;
}> {
return this.subscriptionAdmin.runAdminCreateStripeSubscription(companyId);
}
async runImmediateExpiredRecoveryCharge(
companyId: number,
options?: { forceRecreateStripeSubscription?: boolean; recoveryFromDate?: string },
) {
return this.subscriptionAdmin.runImmediateExpiredRecoveryCharge(companyId, options);
}
async previewImmediateExpiredRecoveryCharge(companyId: number, fromDate?: string) {
return this.subscriptionAdmin.previewImmediateExpiredRecoveryCharge(companyId, fromDate);
}
async handleCustomerSubscriptionCreated(subscription: Stripe.Subscription): Promise<void> {
return this.customerSubscription.handleCustomerSubscriptionCreated(subscription);
}
async handleCustomerSubscriptionUpdated(subscription: Stripe.Subscription): Promise<void> {
return this.customerSubscription.handleCustomerSubscriptionUpdated(subscription);
}
}