Skip to content

Commit

Permalink
DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
jankeromnes committed May 23, 2022
1 parent 1646db7 commit cee2dda
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions components/dashboard/src/teams/TeamBilling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ export default function TeamBilling() {
const [pendingTeamPlan, setPendingTeamPlan] = useState<PendingPlan | undefined>();
const [pollTeamSubscriptionTimeout, setPollTeamSubscriptionTimeout] = useState<NodeJS.Timeout | undefined>();

console.log(
"members",
members.length,
"currency",
currency,
"teamSubscription",
teamSubscription,
"pendingTeamPlan",
pendingTeamPlan,
);

useEffect(() => {
if (!team) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TeamSubscription2 } from "@gitpod/gitpod-protocol/lib/team-subscription
import { inject, injectable } from "inversify";
import { SubscriptionModel } from "./subscription-model";
import { SubscriptionService } from "./subscription-service";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";

@injectable()
export class TeamSubscription2Service {
Expand All @@ -19,13 +20,15 @@ export class TeamSubscription2Service {
@inject(SubscriptionService) protected readonly subscriptionService: SubscriptionService;

async addAllTeamMemberSubscriptions(ts2: TeamSubscription2): Promise<void> {
log.info(`addAllTeamMemberSubscriptions: ts2=${JSON.stringify(ts2)}`);
const members = await this.teamDB.findMembersByTeam(ts2.teamId);
for (const member of members) {
await this.addTeamMemberSubscription(ts2, member.userId);
}
}

async addTeamMemberSubscription(ts2: TeamSubscription2, userId: string): Promise<void> {
log.info(`addTeamMemberSubscription: ts2=${JSON.stringify(ts2)} userId=${JSON.stringify(userId)}`);
const membership = await this.teamDB.findTeamMembership(userId, ts2.teamId);
if (!membership) {
throw new Error(`Could not find membership for user '${userId}' in team '${ts2.teamId}'`);
Expand All @@ -39,6 +42,7 @@ export class TeamSubscription2Service {
}

protected async addSubscription(db: AccountingDB, userId: string, planId: string, teamMembershipId: string, startDate: string, amount: number, firstMonthAmount?: number, endDate?: string, cancelationDate?: string) {
log.info(`addSubscription: userId=${userId} planId=${planId} teamMembershipId=${teamMembershipId} startDate=${startDate} amount=${amount}`);
const model = await this.loadSubscriptionModel(db, userId);
const subscription = Subscription.create({
userId,
Expand All @@ -56,6 +60,7 @@ export class TeamSubscription2Service {
}

async cancelAllTeamMemberSubscriptions(ts2: TeamSubscription2, date: Date): Promise<void> {
log.info(`cancelAllTeamMemberSubscriptions: ts2=${JSON.stringify(ts2)} date=${date.toISOString()}`);
const members = await this.teamDB.findMembersByTeam(ts2.teamId);
for (const member of members) {
const membership = await this.teamDB.findTeamMembership(member.userId, ts2.teamId);
Expand All @@ -67,13 +72,15 @@ export class TeamSubscription2Service {
}

async cancelTeamMemberSubscription(ts2: TeamSubscription2, userId: string, teamMemberShipId: string, date: Date): Promise<void> {
log.info(`cancelTeamMemberSubscription: ts2=${JSON.stringify(ts2)} userId=${userId} teamMemberShipId=${teamMemberShipId} date=${date.toISOString()}`);
const { endDate } = Subscription.calculateCurrentPeriod(ts2.startDate, date);
return this.accountingDb.transaction(async (db) => {
await this.cancelSubscription(db, userId, ts2.planId, teamMemberShipId, endDate);
});
}

protected async cancelSubscription(db: AccountingDB, userId: string, planId: string, teamMembershipId: string, cancellationDate: string) {
log.info(`cancelSubscription: userId=${userId} planId=${planId} teamMembershipId=${teamMembershipId} cancellationDate=${cancellationDate}`);
const model = await this.loadSubscriptionModel(db, userId);
const subscription = model.findSubscriptionByTeamMembershipId(teamMembershipId);
if (!subscription) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class EndpointController {
* @param res
*/
private async handleUpdateGitpodSubscription(req: express.Request, res: express.Response) {
log.info('Chargebee handleUpdateGitpodSubscription!');
if (!req.body || !req.body.event_type) {
log.error('Received malformed event request from chargebee!');
return;
Expand All @@ -70,7 +71,7 @@ export class EndpointController {
const handled = await this.eventHandler.handle(req.body);
if (!handled) {
const payload = { chargebeeEventType: req.body.event_type, action: 'ignored' };
log.debug(`Faithfully ignoring chargebee event of type: ${req.body.event_type}`, payload);
log.warn(`Faithfully ignoring chargebee event of type: ${req.body.event_type}`, payload);
}
res.status(200).send();
} catch (err) {
Expand Down
5 changes: 5 additions & 0 deletions components/server/ee/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
const members = await this.teamDB.findMembersByTeam(teamSubscription.teamId);
const oldQuantity = teamSubscription.quantity;
const newQuantity = members.length;
log.info(`updateTeamSubscriptionQuantity: oldQuantity=${oldQuantity}, newQuantity=${newQuantity}`);
try {
if (oldQuantity < newQuantity) {
// Upgrade: Charge for it!
Expand All @@ -1451,6 +1452,9 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
const description = `Pro-rated upgrade from '${oldQuantity}' to '${newQuantity}' team members (${formatDate(
upgradeTimestamp,
)})`;
log.info(
`chargeForUpgrade: paymentReference=${teamSubscription.paymentReference}, currentTermRemainingRatio=${currentTermRemainingRatio}, diffInCents=${diffInCents}`,
);
await this.upgradeHelper.chargeForUpgrade(
"",
teamSubscription.paymentReference,
Expand All @@ -1464,6 +1468,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
end_of_term: false,
});
} catch (err) {
log.error("updateTeamSubscriptionQuantity failed", err);
if (chargebee.ApiError.is(err) && err.type === "payment") {
throw new ResponseError(ErrorCodes.PAYMENT_ERROR, `${err.api_error_code}: ${err.message}`);
}
Expand Down

0 comments on commit cee2dda

Please sign in to comment.