1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-08 05:47:50 +02:00

Fixed free organization upgrade after stripe sources deprecation (#11205)

This commit is contained in:
Alex Morask 2024-09-24 09:26:39 -04:00 committed by GitHub
parent 8507097fe7
commit c8084cc4e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,8 +23,11 @@ import { OrganizationKeysRequest } from "@bitwarden/common/admin-console/models/
import { OrganizationUpgradeRequest } from "@bitwarden/common/admin-console/models/request/organization-upgrade.request"; import { OrganizationUpgradeRequest } from "@bitwarden/common/admin-console/models/request/organization-upgrade.request";
import { ProviderOrganizationCreateRequest } from "@bitwarden/common/admin-console/models/request/provider/provider-organization-create.request"; import { ProviderOrganizationCreateRequest } from "@bitwarden/common/admin-console/models/request/provider/provider-organization-create.request";
import { ProviderResponse } from "@bitwarden/common/admin-console/models/response/provider/provider.response"; import { ProviderResponse } from "@bitwarden/common/admin-console/models/response/provider/provider.response";
import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions";
import { PaymentMethodType, PlanType, ProductTierType } from "@bitwarden/common/billing/enums"; import { PaymentMethodType, PlanType, ProductTierType } from "@bitwarden/common/billing/enums";
import { ExpandedTaxInfoUpdateRequest } from "@bitwarden/common/billing/models/request/expanded-tax-info-update.request";
import { PaymentRequest } from "@bitwarden/common/billing/models/request/payment.request"; import { PaymentRequest } from "@bitwarden/common/billing/models/request/payment.request";
import { UpdatePaymentMethodRequest } from "@bitwarden/common/billing/models/request/update-payment-method.request";
import { BillingResponse } from "@bitwarden/common/billing/models/response/billing.response"; import { BillingResponse } from "@bitwarden/common/billing/models/response/billing.response";
import { OrganizationSubscriptionResponse } from "@bitwarden/common/billing/models/response/organization-subscription.response"; import { OrganizationSubscriptionResponse } from "@bitwarden/common/billing/models/response/organization-subscription.response";
import { PlanResponse } from "@bitwarden/common/billing/models/response/plan.response"; import { PlanResponse } from "@bitwarden/common/billing/models/response/plan.response";
@ -33,7 +36,6 @@ import { ConfigService } from "@bitwarden/common/platform/abstractions/config/co
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service"; import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service"; import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
@ -153,15 +155,15 @@ export class OrganizationPlansComponent implements OnInit, OnDestroy {
private syncService: SyncService, private syncService: SyncService,
private policyService: PolicyService, private policyService: PolicyService,
private organizationService: OrganizationService, private organizationService: OrganizationService,
private logService: LogService,
private messagingService: MessagingService, private messagingService: MessagingService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private organizationApiService: OrganizationApiServiceAbstraction, private organizationApiService: OrganizationApiServiceAbstraction,
private providerApiService: ProviderApiServiceAbstraction, private providerApiService: ProviderApiServiceAbstraction,
private toastService: ToastService, private toastService: ToastService,
private configService: ConfigService, private configService: ConfigService,
private billingApiService: BillingApiServiceAbstraction,
) { ) {
this.selfHosted = platformUtilsService.isSelfHost(); this.selfHosted = this.platformUtilsService.isSelfHost();
} }
async ngOnInit() { async ngOnInit() {
@ -660,22 +662,27 @@ export class OrganizationPlansComponent implements OnInit, OnDestroy {
this.buildSecretsManagerRequest(request); this.buildSecretsManagerRequest(request);
if (this.upgradeRequiresPaymentMethod) { if (this.upgradeRequiresPaymentMethod) {
let type: PaymentMethodType;
let token: string;
if (this.deprecateStripeSourcesAPI) { if (this.deprecateStripeSourcesAPI) {
({ type, token } = await this.paymentV2Component.tokenize()); const updatePaymentMethodRequest = new UpdatePaymentMethodRequest();
updatePaymentMethodRequest.paymentSource = await this.paymentV2Component.tokenize();
const expandedTaxInfoUpdateRequest = new ExpandedTaxInfoUpdateRequest();
expandedTaxInfoUpdateRequest.country = this.taxComponent.country;
expandedTaxInfoUpdateRequest.postalCode = this.taxComponent.postalCode;
updatePaymentMethodRequest.taxInformation = expandedTaxInfoUpdateRequest;
await this.billingApiService.updateOrganizationPaymentMethod(
this.organizationId,
updatePaymentMethodRequest,
);
} else { } else {
[token, type] = await this.paymentComponent.createPaymentToken(); const [paymentToken, paymentMethodType] = await this.paymentComponent.createPaymentToken();
}
const paymentRequest = new PaymentRequest(); const paymentRequest = new PaymentRequest();
paymentRequest.paymentToken = token; paymentRequest.paymentToken = paymentToken;
paymentRequest.paymentMethodType = type; paymentRequest.paymentMethodType = paymentMethodType;
paymentRequest.country = this.taxComponent.taxFormGroup?.value.country; paymentRequest.country = this.taxComponent.taxFormGroup?.value.country;
paymentRequest.postalCode = this.taxComponent.taxFormGroup?.value.postalCode; paymentRequest.postalCode = this.taxComponent.taxFormGroup?.value.postalCode;
await this.organizationApiService.updatePayment(this.organizationId, paymentRequest); await this.organizationApiService.updatePayment(this.organizationId, paymentRequest);
} }
}
// Backfill pub/priv key if necessary // Backfill pub/priv key if necessary
if (!this.organization.hasPublicAndPrivateKeys) { if (!this.organization.hasPublicAndPrivateKeys) {