Skip to content

Commit fec0a0a

Browse files
geroplroboquat
authored andcommitted
[db, payment] Remove DBPaymentSource
1 parent 55549e8 commit fec0a0a

File tree

6 files changed

+4
-163
lines changed

6 files changed

+4
-163
lines changed

components/ee/payment-endpoint/src/chargebee/payment-source-handler.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.

components/ee/payment-endpoint/src/container-module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { AccountServiceImpl } from "./accounting/account-service-impl";
2222
import { GithubEndpointController } from "./github/endpoint-controller";
2323
import { GithubSubscriptionMapper } from "./github/subscription-mapper";
2424
import { GithubSubscriptionReconciler } from "./github/subscription-reconciler";
25-
import { PaymentSourceHandler } from "./chargebee/payment-source-handler";
2625

2726

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

4947
bind(SubscriptionService).toSelf().inSingletonScope();
5048
bind(TeamSubscriptionService).toSelf().inSingletonScope();

components/gitpod-db/src/accounting-db.spec.db.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DBAccountEntry } from './typeorm/entity/db-account-entry';
1414
import { TransactionalAccountingDBImpl } from './typeorm/accounting-db-impl';
1515
import { DBWorkspace } from './typeorm/entity/db-workspace';
1616
import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
17-
import { DBPaymentSourceInfo, DBSubscription } from './typeorm/entity/db-subscription';
17+
import { DBSubscription } from './typeorm/entity/db-subscription';
1818
import { testContainer } from './test-container';
1919
import { TypeORM } from './typeorm/typeorm';
2020
const expect = chai.expect;
@@ -136,28 +136,6 @@ export class AccountingDBSpec {
136136
expectExactlyOne(await this.db.findActiveSubscriptionsForUser(subscription.userId, rightBefore(later)), dbSubscription);
137137
expect(await this.db.findActiveSubscriptionsForUser(subscription.userId, later)).to.be.an('array').and.empty;
138138
}
139-
140-
// see https://github.com/gitpod-io/gitpod/issues/7171
141-
@test public async bug7171() {
142-
const paymentSourceInfo : DBPaymentSourceInfo = {
143-
id: "bar",
144-
resourceVersion: 1,
145-
userId: "foo",
146-
status: "valid",
147-
cardExpiryMonth: 12,
148-
cardExpiryYear: 2021
149-
};
150-
await this.db.storePaymentSourceInfo(paymentSourceInfo);
151-
const paymentSourceInfo2 : DBPaymentSourceInfo = {
152-
id: "bar",
153-
resourceVersion: 1,
154-
userId: "foo",
155-
status: "expiring",
156-
cardExpiryMonth: 12,
157-
cardExpiryYear: 2021
158-
};
159-
await this.db.storePaymentSourceInfo(paymentSourceInfo2);
160-
}
161139
}
162140

163141
const expectExactlyOne = <T>(result: T[], expectation: T) => {

components/gitpod-db/src/accounting-db.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

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

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

4343
storeSubscriptionAdditionalData(subscriptionData: DBSubscriptionAdditionalData): Promise<DBSubscriptionAdditionalData>;
44-
storePaymentSourceInfo(cardInfo: DBPaymentSourceInfo): Promise<DBPaymentSourceInfo>;
4544
}
46-
47-
export type DBPaymentSourceInfoPartial = DeepPartial<DBPaymentSourceInfo> & Pick<DBPaymentSourceInfo, "id">;

components/gitpod-db/src/typeorm/accounting-db-impl.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DBAccountEntry } from "./entity/db-account-entry";
99
import { User } from "@gitpod/gitpod-protocol";
1010
import { AccountEntry, Subscription, Credit, SubscriptionAndUser } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
1111
import { EntityManager, Repository } from "typeorm";
12-
import { DBSubscription, DBSubscriptionAdditionalData, DBPaymentSourceInfo } from "./entity/db-subscription";
12+
import { DBSubscription, DBSubscriptionAdditionalData } from "./entity/db-subscription";
1313
import { injectable, inject } from "inversify";
1414
import { v4 as uuidv4 } from 'uuid';
1515
import { DBUser } from "../typeorm/entity/db-user";
@@ -101,10 +101,6 @@ export class TypeORMAccountingDBImpl implements AccountingDB {
101101
return (await this.getEntityManager()).getRepository(DBSubscriptionAdditionalData);
102102
}
103103

104-
protected async getPaymentSourceRepo(): Promise<Repository<DBPaymentSourceInfo>> {
105-
return (await this.getEntityManager()).getRepository(DBPaymentSourceInfo);
106-
}
107-
108104
async newSubscription(subscription: Omit<Subscription, 'uid'>): Promise<Subscription> {
109105
const newSubscription = new DBSubscription();
110106
Subscription.create(newSubscription);
@@ -257,23 +253,6 @@ export class TypeORMAccountingDBImpl implements AccountingDB {
257253
const repo = await this.getSubscriptionAdditionalDataRepo();
258254
return repo.save(subscriptionData);
259255
}
260-
261-
async storePaymentSourceInfo(info: DBPaymentSourceInfo): Promise<DBPaymentSourceInfo> {
262-
const repo = await this.getPaymentSourceRepo();
263-
// see https://github.com/gitpod-io/gitpod/issues/7171
264-
// TypeORM seems to have problems with number type primary columns
265-
const existing = await repo.findOne({ id: info.id, resourceVersion: info.resourceVersion });
266-
if (existing) {
267-
for (const prop in info) {
268-
if (prop != "resourceVersion") {
269-
(existing as any)[prop] = (info as any)[prop];
270-
}
271-
}
272-
return repo.save(existing);
273-
} else {
274-
return repo.save(info);
275-
}
276-
}
277256
}
278257

279258
export class TransactionalAccountingDBImpl extends TypeORMAccountingDBImpl {

components/gitpod-db/src/typeorm/entity/db-subscription.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -129,38 +129,3 @@ export interface CouponData {
129129
*/
130130
coupon_code?: string;
131131
}
132-
133-
@Entity()
134-
// on DB but not Typeorm: @Index("ind_lastModified", ["_lastModified"]) // DBSync
135-
@Index("ind_userId_softDeletedTime", ["userId", "softDeletedTime"])
136-
export class DBPaymentSourceInfo {
137-
@PrimaryColumn()
138-
id: string;
139-
140-
@PrimaryColumn({
141-
type: "bigint"
142-
})
143-
@Index("ind_resourceVersion") // Necessary for certain operations: https://dev.mysql.com/doc/refman/8.0/en/order-by-optimization.html
144-
resourceVersion: number;
145-
146-
@Column(TypeORM.UUID_COLUMN_TYPE)
147-
userId: string;
148-
149-
@Column()
150-
status: PaymentSourceStatus;
151-
152-
@Column()
153-
cardExpiryMonth: number;
154-
155-
@Column()
156-
cardExpiryYear: number;
157-
158-
@Column({
159-
type: "varchar",
160-
length: 30,
161-
default: '',
162-
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED
163-
})
164-
softDeletedTime?: string;
165-
}
166-
export type PaymentSourceStatus = "valid" | "expiring" | "expired" | "invalid" | "pending_verification";

0 commit comments

Comments
 (0)