Skip to content

Commit

Permalink
rename tracker to verification
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparkallas authored Oct 26, 2023
1 parent b343c25 commit 51e3945
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BullModule } from '@nestjs/bullmq';
import { QueueDashboardModule } from './queue-dashboard/queue-dashboard.module';
import { CheckoutSessionModule } from './checkout-session/checkout-session.module';
import { StripeListenerModule } from './stripe-listener/stripe-listener.module';
import { PaymentTrackerModule } from './payment-tracker/payment-tracker.module';
import { PaymentVerificationModule } from './payment-verification/payment-verification.module';
import { SuperTokenAccountingModule } from './super-token-accounting/super-token-accounting.module';
import { StripeToSuperfluidModule } from './stripe-to-superfluid/stripe-to-superfluid.module';
import { HealthModule } from './health/health.module';
Expand Down Expand Up @@ -44,7 +44,7 @@ const registerBullModule = () =>
QueueDashboardModule,
CheckoutSessionModule,
StripeListenerModule,
PaymentTrackerModule,
PaymentVerificationModule,
SuperTokenAccountingModule,
StripeToSuperfluidModule,
HealthModule,
Expand Down
18 changes: 0 additions & 18 deletions apps/backend/src/payment-tracker/payment-tracker.processor.spec.ts

This file was deleted.

18 changes: 0 additions & 18 deletions apps/backend/src/payment-tracker/payment-tracker.service.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { PaymentTrackerProcessor } from './payment-tracker.processor';
import { PaymentTrackerService } from './payment-tracker.service';
import { registerQueueModules } from './payment-tracker.queue';
import { PaymentVerificationProcessor } from './payment-verification.processor';
import { PaymentVerificationService } from './payment-verification.service';
import { registerQueueModules } from './payment-verification.queue';
import { registerStripeModule } from 'src/stripeModuleConfig';
import { SuperTokenAccountingModule } from 'src/super-token-accounting/super-token-accounting.module';
import { StripeToSuperfluidModule } from 'src/stripe-to-superfluid/stripe-to-superfluid.module';
Expand All @@ -13,7 +13,7 @@ import { StripeToSuperfluidModule } from 'src/stripe-to-superfluid/stripe-to-sup
SuperTokenAccountingModule,
StripeToSuperfluidModule,
],
providers: [PaymentTrackerProcessor, PaymentTrackerService],
exports: [PaymentTrackerService],
providers: [PaymentVerificationProcessor, PaymentVerificationService],
exports: [PaymentVerificationService],
})
export class PaymentTrackerModule {}
export class PaymentVerificationModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PaymentVerificationProcessor } from './payment-verification.processor';

describe('InvoicePaymentVerificationService', () => {
let service: PaymentVerificationProcessor;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [PaymentVerificationProcessor],
}).compile();

service = module.get<PaymentVerificationProcessor>(PaymentVerificationProcessor);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InjectFlowProducer, InjectQueue, Processor, WorkerHost } from '@nestjs/bullmq';
import { FlowProducer, Job } from 'bullmq';
import { FLOW_PRODUCER_NAME, QUEUE_NAME } from './payment-tracker.queue';
import { FLOW_PRODUCER_NAME, QUEUE_NAME } from './payment-verification.queue';
import { InjectStripeClient } from '@golevelup/nestjs-stripe';
import Stripe from 'stripe';
import _ from 'lodash';
Expand All @@ -15,14 +15,14 @@ import stringify from 'safe-stable-stringify';
import { currencyDecimalMapping } from 'src/currencies';
import { formatUnits } from 'viem';

export const PAYMENT_TRACKER_JOB_NAME = 'verify-customer-invoice-payments-by-super-token';
export const PAYMENT_VERIFICATION_JOB_NAME = 'verify-customer-invoice-payments-by-super-token';

type PaymentTrackerJob = Job<
type PaymentVerificationJob = Job<
{
stripeCustomerId: string;
},
any,
typeof PAYMENT_TRACKER_JOB_NAME
typeof PAYMENT_VERIFICATION_JOB_NAME
>;

type TRACKED_INVOICE_GROUP_KEY = `${number}:${string}:${string}:${string}`;
Expand All @@ -32,7 +32,7 @@ const NOT_TRACKED_INVOICE_GROUP_KEY = null;
*
*/
@Processor(QUEUE_NAME)
export class PaymentTrackerProcessor extends WorkerHost {
export class PaymentVerificationProcessor extends WorkerHost {
constructor(
@InjectQueue(QUEUE_NAME) private readonly queue,
@InjectFlowProducer(FLOW_PRODUCER_NAME)
Expand All @@ -44,7 +44,7 @@ export class PaymentTrackerProcessor extends WorkerHost {
super();
}

async process(job: PaymentTrackerJob, token?: string): Promise<void> {
async process(job: PaymentVerificationJob, token?: string): Promise<void> {
const customer = await this.stripeClient.customers.retrieve(job.data.stripeCustomerId);
// Is stripe already ensuring the customer exists? Should I check for .deleted?
if (!customer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BullModule } from '@nestjs/bullmq';

export const QUEUE_NAME = 'payment-tracker';
export const FLOW_PRODUCER_NAME = 'payment-tracker-flow-producer';
export const QUEUE_NAME = 'payment-verification';
export const FLOW_PRODUCER_NAME = 'payment-verification-flow-producer';

export const registerQueueModules = () => [
BullModule.registerQueue({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PaymentVerificationService as PaymentVerificationService } from './payment-verification.service';

describe('InvoicePaymentVerificationService', () => {
let service: PaymentVerificationService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [PaymentVerificationService],
}).compile();

service = module.get<PaymentVerificationService>(PaymentVerificationService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Injectable, Logger } from '@nestjs/common';
import { Queue } from 'bullmq';
import Stripe from 'stripe';
import { QUEUE_NAME } from './payment-tracker.queue';
import { QUEUE_NAME } from './payment-verification.queue';
import { InjectQueue } from '@nestjs/bullmq';
import { PAYMENT_TRACKER_JOB_NAME } from './payment-tracker.processor';
import { PAYMENT_VERIFICATION_JOB_NAME } from './payment-verification.processor';

/**
* Handles Stripe invoices:
* - invoice aggregation
* - produces payment marking jobs
*/
@Injectable()
export class PaymentTrackerService {
export class PaymentVerificationService {
constructor(@InjectQueue(QUEUE_NAME) private readonly queue: Queue) {}

/**
Expand All @@ -26,7 +26,7 @@ export class PaymentTrackerService {

const jobs = await this.queue.addBulk(
invoices.map((invoice) => ({
name: PAYMENT_TRACKER_JOB_NAME,
name: PAYMENT_VERIFICATION_JOB_NAME,
data: {}, // TODO: Storing the whole invoice seems totally excessive
opts: {
jobId: invoice.customer as string, // TODO(KK): not quite right
Expand All @@ -38,4 +38,4 @@ export class PaymentTrackerService {
}
}

const logger = new Logger(PaymentTrackerService.name);
const logger = new Logger(PaymentVerificationService.name);
10 changes: 5 additions & 5 deletions apps/backend/src/queue-dashboard/queue-dashboard.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { Queue } from 'bullmq';
import { BasicAuthMiddleware } from './basic-auth.middleware';
import * as CheckoutSession from 'src/checkout-session/checkout-session.queue';
import * as PaymentTracker from 'src/payment-tracker/payment-tracker.queue';
import * as PaymentVerification from 'src/payment-verification/payment-verification.queue';
import * as StripeListener from 'src/stripe-listener/stripe-listener.queue';

@Module({
imports: [
CheckoutSession.registerQueueModule(),
...PaymentTracker.registerQueueModules(),
...PaymentVerification.registerQueueModules(),
StripeListener.registerQueueModule(),
],
})
export class QueueDashboardModule implements NestModule {
constructor(
@InjectQueue(CheckoutSession.QUEUE_NAME)
private readonly checkoutSessionQueue: Queue,
@InjectQueue(PaymentTracker.QUEUE_NAME)
private readonly paymentTrackerQueue: Queue,
@InjectQueue(PaymentVerification.QUEUE_NAME)
private readonly paymentVerificationQueue: Queue,
@InjectQueue(StripeListener.QUEUE_NAME)
private readonly stripeListenerQueue: Queue,
) {}
Expand All @@ -34,7 +34,7 @@ export class QueueDashboardModule implements NestModule {
serverAdapter,
queues: [
new BullMQAdapter(this.checkoutSessionQueue),
new BullMQAdapter(this.paymentTrackerQueue),
new BullMQAdapter(this.paymentVerificationQueue),
new BullMQAdapter(this.stripeListenerQueue),
],
});
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/stripe-listener/stripe-listener.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { QUEUE_NAME, registerQueueModule } from './stripe-listener.queue';
import { InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';
import { StripeModule } from '@golevelup/nestjs-stripe';
import { PaymentTrackerModule } from 'src/payment-tracker/payment-tracker.module';
import { PaymentVerificationModule } from 'src/payment-verification/payment-verification.module';
import { registerStripeModule } from 'src/stripeModuleConfig';

@Module({
imports: [registerQueueModule(), registerStripeModule(), PaymentTrackerModule],
imports: [registerQueueModule(), registerStripeModule(), PaymentVerificationModule],
providers: [StripeListenerProcessor],
controllers: [StripeListenerController],
})
Expand Down
8 changes: 4 additions & 4 deletions apps/backend/src/stripe-listener/stripe-listener.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Job, Queue } from 'bullmq';
import { QUEUE_NAME } from './stripe-listener.queue';
import { InjectStripeClient } from '@golevelup/nestjs-stripe';
import Stripe from 'stripe';
import { PAYMENT_TRACKER_JOB_NAME } from 'src/payment-tracker/payment-tracker.processor';
import { PaymentTrackerService } from 'src/payment-tracker/payment-tracker.service';
import { PAYMENT_VERIFICATION_JOB_NAME } from 'src/payment-verification/payment-verification.processor';
import { PaymentVerificationService } from 'src/payment-verification/payment-verification.service';
import { DEFAULT_PAGING } from 'src/stripeModuleConfig';

export const STRIPE_LISTENER_JOB_NAME = 'poll-new-invoices';
Expand All @@ -25,7 +25,7 @@ type StripeListenerJob = Job<
export class StripeListenerProcessor extends WorkerHost {
constructor(
@InjectStripeClient() private readonly stripeClient: Stripe,
private readonly paymentTrackerService: PaymentTrackerService,
private readonly paymentVerificationService: PaymentVerificationService,
) {
super();
}
Expand All @@ -39,7 +39,7 @@ export class StripeListenerProcessor extends WorkerHost {
})
.autoPagingToArray(DEFAULT_PAGING);

await this.paymentTrackerService.handleOpenStripeInvoices(invoices);
await this.paymentVerificationService.handleOpenStripeInvoices(invoices);
}
}

Expand Down

0 comments on commit 51e3945

Please sign in to comment.