Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-15198] Make trial banner work with Stripe Sources API deprecation flag #12146

12 changes: 7 additions & 5 deletions apps/web/src/app/vault/individual-vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
} from "rxjs/operators";

import {
Unassigned,
CollectionService,
CollectionData,
CollectionDetailsResponse,
CollectionService,
CollectionView,
Unassigned,
} from "@bitwarden/admin-console/common";
import { SearchPipe } from "@bitwarden/angular/pipes/search.pipe";
import { ModalService } from "@bitwarden/angular/services/modal.service";
Expand All @@ -47,6 +47,7 @@
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { OrganizationBillingServiceAbstraction } from "@bitwarden/common/billing/abstractions";

Check warning on line 50 in apps/web/src/app/vault/individual-vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/individual-vault/vault.component.ts#L50

Added line #L50 was not covered by tests
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions/billing-api.service.abstraction";
import { EventType } from "@bitwarden/common/enums";
Expand Down Expand Up @@ -241,6 +242,7 @@
private organizationApiService: OrganizationApiServiceAbstraction,
protected billingApiService: BillingApiServiceAbstraction,
private trialFlowService: TrialFlowService,
private organizationBillingService: OrganizationBillingServiceAbstraction,

Check warning on line 245 in apps/web/src/app/vault/individual-vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/individual-vault/vault.component.ts#L245

Added line #L245 was not covered by tests
) {}

async ngOnInit() {
Expand Down Expand Up @@ -437,13 +439,13 @@
.map((org) =>
combineLatest([
this.organizationApiService.getSubscription(org.id),
this.organizationApiService.getBilling(org.id),
this.organizationBillingService.getPaymentSource(org.id),
]).pipe(
map(([subscription, billing]) => {
map(([subscription, paymentSource]) => {
return this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
org,
subscription,
billing?.paymentSource,
paymentSource,
);
}),
),
Expand Down
12 changes: 5 additions & 7 deletions apps/web/src/app/vault/org-vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { OrganizationBillingServiceAbstraction } from "@bitwarden/common/billing/abstractions";

Check warning on line 51 in apps/web/src/app/vault/org-vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/org-vault/vault.component.ts#L51

Added line #L51 was not covered by tests
import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions/billing-api.service.abstraction";
import { EventType } from "@bitwarden/common/enums";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
Expand Down Expand Up @@ -252,6 +253,7 @@
private organizationApiService: OrganizationApiServiceAbstraction,
private trialFlowService: TrialFlowService,
protected billingApiService: BillingApiServiceAbstraction,
private organizationBillingService: OrganizationBillingServiceAbstraction,

Check warning on line 256 in apps/web/src/app/vault/org-vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/org-vault/vault.component.ts#L256

Added line #L256 was not covered by tests
) {}

async ngOnInit() {
Expand Down Expand Up @@ -595,15 +597,11 @@
combineLatest([
of(org),
this.organizationApiService.getSubscription(org.id),
this.organizationApiService.getBilling(org.id),
this.organizationBillingService.getPaymentSource(org.id),
]),
),
map(([org, sub, billing]) => {
return this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
org,
sub,
billing?.paymentSource,
);
map(([org, sub, paymentSource]) => {
return this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(org, sub, paymentSource);

Check warning on line 604 in apps/web/src/app/vault/org-vault/vault.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/org-vault/vault.component.ts#L604

Added line #L604 was not covered by tests
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { OrganizationApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization-api.service.abstraction";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { OrganizationBillingServiceAbstraction } from "@bitwarden/common/billing/abstractions";

Check warning on line 23 in bitwarden_license/bit-web/src/app/secrets-manager/overview/overview.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/overview/overview.component.ts#L23

Added line #L23 was not covered by tests
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
Expand Down Expand Up @@ -114,9 +115,9 @@
private smOnboardingTasksService: SMOnboardingTasksService,
private logService: LogService,
private router: Router,

private organizationApiService: OrganizationApiServiceAbstraction,
private trialFlowService: TrialFlowService,
private organizationBillingService: OrganizationBillingServiceAbstraction,

Check warning on line 120 in bitwarden_license/bit-web/src/app/secrets-manager/overview/overview.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/overview/overview.component.ts#L120

Added line #L120 was not covered by tests
) {}

ngOnInit() {
Expand Down Expand Up @@ -144,15 +145,11 @@
combineLatest([
of(org),
this.organizationApiService.getSubscription(org.id),
this.organizationApiService.getBilling(org.id),
this.organizationBillingService.getPaymentSource(org.id),
]),
),
map(([org, sub, billing]) => {
return this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(
org,
sub,
billing?.paymentSource,
);
map(([org, sub, paymentSource]) => {
return this.trialFlowService.checkForOrgsWithUpcomingPaymentIssues(org, sub, paymentSource);

Check warning on line 152 in bitwarden_license/bit-web/src/app/secrets-manager/overview/overview.component.ts

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bit-web/src/app/secrets-manager/overview/overview.component.ts#L152

Added line #L152 was not covered by tests
}),
takeUntil(this.destroy$),
);
Expand Down
2 changes: 2 additions & 0 deletions libs/angular/src/services/jslib-services.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,8 @@ const safeProviders: SafeProvider[] = [
useClass: OrganizationBillingService,
deps: [
ApiServiceAbstraction,
BillingApiServiceAbstraction,
ConfigService,
KeyServiceAbstraction,
EncryptService,
I18nServiceAbstraction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { BillingSourceResponse } from "@bitwarden/common/billing/models/response/billing.response";
import { PaymentSourceResponse } from "@bitwarden/common/billing/models/response/payment-source.response";

import { OrganizationResponse } from "../../admin-console/models/response/organization.response";
import { InitiationPath } from "../../models/request/reference-event.request";
import { PaymentMethodType, PlanType } from "../enums";
Expand Down Expand Up @@ -41,11 +44,15 @@ export type SubscriptionInformation = {
};

export abstract class OrganizationBillingServiceAbstraction {
purchaseSubscription: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
getPaymentSource: (
organizationId: string,
) => Promise<BillingSourceResponse | PaymentSourceResponse>;

startFree: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
purchaseSubscription: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;

purchaseSubscriptionNoPaymentMethod: (
subscription: SubscriptionInformation,
) => Promise<OrganizationResponse>;

startFree: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
}
59 changes: 42 additions & 17 deletions libs/common/src/billing/services/organization-billing.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { KeyService } from "../../../../key-management/src/abstractions/key.service";
import {
BillingApiServiceAbstraction,
OrganizationBillingServiceAbstraction,
OrganizationInformation,
PaymentInformation,
PlanInformation,
SubscriptionInformation,
} from "@bitwarden/common/billing/abstractions";
import { BillingSourceResponse } from "@bitwarden/common/billing/models/response/billing.response";
import { PaymentSourceResponse } from "@bitwarden/common/billing/models/response/payment-source.response";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";

Check warning on line 11 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L11

Added line #L11 was not covered by tests
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { SyncService } from "@bitwarden/common/platform/sync";
import { KeyService } from "@bitwarden/key-management";

import { ApiService } from "../../abstractions/api.service";
import { OrganizationApiServiceAbstraction as OrganizationApiService } from "../../admin-console/abstractions/organization/organization-api.service.abstraction";
import { OrganizationCreateRequest } from "../../admin-console/models/request/organization-create.request";
Expand All @@ -8,14 +22,6 @@
import { I18nService } from "../../platform/abstractions/i18n.service";
import { EncString } from "../../platform/models/domain/enc-string";
import { OrgKey } from "../../types/key";
import { SyncService } from "../../vault/abstractions/sync/sync.service.abstraction";
import {
OrganizationBillingServiceAbstraction,
OrganizationInformation,
PaymentInformation,
PlanInformation,
SubscriptionInformation,
} from "../abstractions/organization-billing.service";
import { PlanType } from "../enums";
import { OrganizationNoPaymentMethodCreateRequest } from "../models/request/organization-no-payment-method-create-request";

Expand All @@ -29,13 +35,32 @@
export class OrganizationBillingService implements OrganizationBillingServiceAbstraction {
constructor(
private apiService: ApiService,
private billingApiService: BillingApiServiceAbstraction,
private configService: ConfigService,

Check warning on line 39 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L38-L39

Added lines #L38 - L39 were not covered by tests
private keyService: KeyService,
private encryptService: EncryptService,
private i18nService: I18nService,
private organizationApiService: OrganizationApiService,
private syncService: SyncService,
) {}

async getPaymentSource(
organizationId: string,
): Promise<BillingSourceResponse | PaymentSourceResponse> {
const deprecateStripeSourcesAPI = await this.configService.getFeatureFlag(

Check warning on line 50 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L50

Added line #L50 was not covered by tests
FeatureFlag.AC2476_DeprecateStripeSourcesAPI,
);

if (deprecateStripeSourcesAPI) {
const paymentMethod =
await this.billingApiService.getOrganizationPaymentMethod(organizationId);
return paymentMethod.paymentSource;

Check warning on line 57 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L56-L57

Added lines #L56 - L57 were not covered by tests
} else {
const billing = await this.organizationApiService.getBilling(organizationId);
return billing.paymentSource;

Check warning on line 60 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L59-L60

Added lines #L59 - L60 were not covered by tests
}
}

async purchaseSubscription(subscription: SubscriptionInformation): Promise<OrganizationResponse> {
const request = new OrganizationCreateRequest();

Expand All @@ -58,8 +83,10 @@
return response;
}

async startFree(subscription: SubscriptionInformation): Promise<OrganizationResponse> {
const request = new OrganizationCreateRequest();
async purchaseSubscriptionNoPaymentMethod(
subscription: SubscriptionInformation,
): Promise<OrganizationResponse> {
const request = new OrganizationNoPaymentMethodCreateRequest();

Check warning on line 89 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L89

Added line #L89 was not covered by tests

const organizationKeys = await this.makeOrganizationKeys();

Expand All @@ -69,7 +96,7 @@

this.setPlanInformation(request, subscription.plan);

const response = await this.organizationApiService.create(request);
const response = await this.organizationApiService.createWithoutPayment(request);

Check warning on line 99 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L99

Added line #L99 was not covered by tests

await this.apiService.refreshIdentityToken();

Expand All @@ -78,10 +105,8 @@
return response;
}

async purchaseSubscriptionNoPaymentMethod(
subscription: SubscriptionInformation,
): Promise<OrganizationResponse> {
const request = new OrganizationNoPaymentMethodCreateRequest();
async startFree(subscription: SubscriptionInformation): Promise<OrganizationResponse> {
const request = new OrganizationCreateRequest();

Check warning on line 109 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L109

Added line #L109 was not covered by tests

const organizationKeys = await this.makeOrganizationKeys();

Expand All @@ -91,7 +116,7 @@

this.setPlanInformation(request, subscription.plan);

const response = await this.organizationApiService.createWithoutPayment(request);
const response = await this.organizationApiService.create(request);

Check warning on line 119 in libs/common/src/billing/services/organization-billing.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/billing/services/organization-billing.service.ts#L119

Added line #L119 was not covered by tests

await this.apiService.refreshIdentityToken();

Expand Down