This commit introduces the updateSubscription method to the BillingStrategyProviderService, ensuring that subscriptions can be updated within the billing core. Additionally, a refactor has been applied to the BillingGatewayFactoryService and stripe-billing-strategy.service to improve error handling and the robustness of subscription updates. Logging in the webhook route has been adjusted for clarity and the data model has been enhanced.
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
const MAILER_PROVIDER = z
|
|
.enum(['nodemailer', 'cloudflare'])
|
|
.default('nodemailer')
|
|
.parse(process.env.MAILER_PROVIDER);
|
|
|
|
/**
|
|
* @description A mailer interface that can be implemented by any mailer.
|
|
* We export a single mailer implementation using Nodemailer. You can add more mailers or replace the existing one.
|
|
* @example
|
|
* ```ts
|
|
* import { Mailer } from '@kit/mailers';
|
|
*
|
|
* const mailer = new Mailer();
|
|
*
|
|
* mailer.sendEmail({
|
|
* from: '',
|
|
* to: '',
|
|
* subject: 'Hello',
|
|
* text: 'Hello, World!'
|
|
* });
|
|
*/
|
|
export const Mailer = await getMailer();
|
|
|
|
/**
|
|
* @description Get the mailer based on the environment variable.
|
|
*/
|
|
async function getMailer() {
|
|
switch (MAILER_PROVIDER) {
|
|
case 'nodemailer': {
|
|
const { Nodemailer } = await import('./impl/nodemailer');
|
|
|
|
return new Nodemailer();
|
|
}
|
|
|
|
case 'cloudflare': {
|
|
const { CloudflareMailer } = await import('./impl/cloudflare');
|
|
|
|
return new CloudflareMailer();
|
|
}
|
|
|
|
default:
|
|
throw new Error(`Invalid mailer: ${MAILER_PROVIDER as string}`);
|
|
}
|
|
}
|