Skip to content

Commit

Permalink
[db, payment] Remove DBPaymentSource
Browse files Browse the repository at this point in the history
  • Loading branch information
geropl authored and roboquat committed Dec 20, 2021
1 parent 55549e8 commit fec0a0a
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 163 deletions.

This file was deleted.

2 changes: 0 additions & 2 deletions components/ee/payment-endpoint/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { AccountServiceImpl } from "./accounting/account-service-impl";
import { GithubEndpointController } from "./github/endpoint-controller";
import { GithubSubscriptionMapper } from "./github/subscription-mapper";
import { GithubSubscriptionReconciler } from "./github/subscription-reconciler";
import { PaymentSourceHandler } from "./chargebee/payment-source-handler";


export const productionContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
Expand All @@ -44,7 +43,6 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo
bind(CompositeEventHandler).toSelf().inSingletonScope();
bind(EventHandler).to(SubscriptionHandler).inSingletonScope();
bind(EventHandler).to(TeamSubscriptionHandler).inSingletonScope();
bind(EventHandler).to(PaymentSourceHandler).inSingletonScope();

bind(SubscriptionService).toSelf().inSingletonScope();
bind(TeamSubscriptionService).toSelf().inSingletonScope();
Expand Down
24 changes: 1 addition & 23 deletions components/gitpod-db/src/accounting-db.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DBAccountEntry } from './typeorm/entity/db-account-entry';
import { TransactionalAccountingDBImpl } from './typeorm/accounting-db-impl';
import { DBWorkspace } from './typeorm/entity/db-workspace';
import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
import { DBPaymentSourceInfo, DBSubscription } from './typeorm/entity/db-subscription';
import { DBSubscription } from './typeorm/entity/db-subscription';
import { testContainer } from './test-container';
import { TypeORM } from './typeorm/typeorm';
const expect = chai.expect;
Expand Down Expand Up @@ -136,28 +136,6 @@ export class AccountingDBSpec {
expectExactlyOne(await this.db.findActiveSubscriptionsForUser(subscription.userId, rightBefore(later)), dbSubscription);
expect(await this.db.findActiveSubscriptionsForUser(subscription.userId, later)).to.be.an('array').and.empty;
}

// see https://github.com/gitpod-io/gitpod/issues/7171
@test public async bug7171() {
const paymentSourceInfo : DBPaymentSourceInfo = {
id: "bar",
resourceVersion: 1,
userId: "foo",
status: "valid",
cardExpiryMonth: 12,
cardExpiryYear: 2021
};
await this.db.storePaymentSourceInfo(paymentSourceInfo);
const paymentSourceInfo2 : DBPaymentSourceInfo = {
id: "bar",
resourceVersion: 1,
userId: "foo",
status: "expiring",
cardExpiryMonth: 12,
cardExpiryYear: 2021
};
await this.db.storePaymentSourceInfo(paymentSourceInfo2);
}
}

const expectExactlyOne = <T>(result: T[], expectation: T) => {
Expand Down
7 changes: 2 additions & 5 deletions components/gitpod-db/src/accounting-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { AccountEntry, Subscription, SubscriptionAndUser, Credit } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
import { DBSubscriptionAdditionalData, DBPaymentSourceInfo } from "./typeorm/entity/db-subscription";
import { DeepPartial, EntityManager } from "typeorm";
import { DBSubscriptionAdditionalData } from "./typeorm/entity/db-subscription";
import { EntityManager } from "typeorm";

export const TransactionalAccountingDBFactory = Symbol('TransactionalAccountingDBFactory');
export interface TransactionalAccountingDBFactory {
Expand Down Expand Up @@ -41,7 +41,4 @@ export interface AccountingDB {
transaction<T>(closure: (db: AccountingDB)=>Promise<T>, closures?: ((manager: EntityManager) => Promise<any>)[]): Promise<T>;

storeSubscriptionAdditionalData(subscriptionData: DBSubscriptionAdditionalData): Promise<DBSubscriptionAdditionalData>;
storePaymentSourceInfo(cardInfo: DBPaymentSourceInfo): Promise<DBPaymentSourceInfo>;
}

export type DBPaymentSourceInfoPartial = DeepPartial<DBPaymentSourceInfo> & Pick<DBPaymentSourceInfo, "id">;
23 changes: 1 addition & 22 deletions components/gitpod-db/src/typeorm/accounting-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DBAccountEntry } from "./entity/db-account-entry";
import { User } from "@gitpod/gitpod-protocol";
import { AccountEntry, Subscription, Credit, SubscriptionAndUser } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
import { EntityManager, Repository } from "typeorm";
import { DBSubscription, DBSubscriptionAdditionalData, DBPaymentSourceInfo } from "./entity/db-subscription";
import { DBSubscription, DBSubscriptionAdditionalData } from "./entity/db-subscription";
import { injectable, inject } from "inversify";
import { v4 as uuidv4 } from 'uuid';
import { DBUser } from "../typeorm/entity/db-user";
Expand Down Expand Up @@ -101,10 +101,6 @@ export class TypeORMAccountingDBImpl implements AccountingDB {
return (await this.getEntityManager()).getRepository(DBSubscriptionAdditionalData);
}

protected async getPaymentSourceRepo(): Promise<Repository<DBPaymentSourceInfo>> {
return (await this.getEntityManager()).getRepository(DBPaymentSourceInfo);
}

async newSubscription(subscription: Omit<Subscription, 'uid'>): Promise<Subscription> {
const newSubscription = new DBSubscription();
Subscription.create(newSubscription);
Expand Down Expand Up @@ -257,23 +253,6 @@ export class TypeORMAccountingDBImpl implements AccountingDB {
const repo = await this.getSubscriptionAdditionalDataRepo();
return repo.save(subscriptionData);
}

async storePaymentSourceInfo(info: DBPaymentSourceInfo): Promise<DBPaymentSourceInfo> {
const repo = await this.getPaymentSourceRepo();
// see https://github.com/gitpod-io/gitpod/issues/7171
// TypeORM seems to have problems with number type primary columns
const existing = await repo.findOne({ id: info.id, resourceVersion: info.resourceVersion });
if (existing) {
for (const prop in info) {
if (prop != "resourceVersion") {
(existing as any)[prop] = (info as any)[prop];
}
}
return repo.save(existing);
} else {
return repo.save(info);
}
}
}

export class TransactionalAccountingDBImpl extends TypeORMAccountingDBImpl {
Expand Down
35 changes: 0 additions & 35 deletions components/gitpod-db/src/typeorm/entity/db-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,38 +129,3 @@ export interface CouponData {
*/
coupon_code?: string;
}

@Entity()
// on DB but not Typeorm: @Index("ind_lastModified", ["_lastModified"]) // DBSync
@Index("ind_userId_softDeletedTime", ["userId", "softDeletedTime"])
export class DBPaymentSourceInfo {
@PrimaryColumn()
id: string;

@PrimaryColumn({
type: "bigint"
})
@Index("ind_resourceVersion") // Necessary for certain operations: https://dev.mysql.com/doc/refman/8.0/en/order-by-optimization.html
resourceVersion: number;

@Column(TypeORM.UUID_COLUMN_TYPE)
userId: string;

@Column()
status: PaymentSourceStatus;

@Column()
cardExpiryMonth: number;

@Column()
cardExpiryYear: number;

@Column({
type: "varchar",
length: 30,
default: '',
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED
})
softDeletedTime?: string;
}
export type PaymentSourceStatus = "valid" | "expiring" | "expired" | "invalid" | "pending_verification";

0 comments on commit fec0a0a

Please sign in to comment.