1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[AC-1562] Added region custom field to PayPal add credits (#5897)

* Added config service func for getting cloud region

* Updated to use `buildServerConfig`
This commit is contained in:
Conner Turnbull
2023-07-25 15:57:29 -04:00
committed by GitHub
parent 4ba9427967
commit ab6085cd88
3 changed files with 10 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { PaymentMethodType } from "@bitwarden/common/billing/enums";
import { BitPayInvoiceRequest } from "@bitwarden/common/billing/models/request/bit-pay-invoice.request";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { PayPalConfig } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
@@ -50,7 +51,8 @@ export class AddCreditComponent implements OnInit {
private apiService: ApiService,
private platformUtilsService: PlatformUtilsService,
private organizationService: OrganizationService,
private logService: LogService
private logService: LogService,
private configService: ConfigServiceAbstraction
) {
const payPalConfig = process.env.PAYPAL_CONFIG as PayPalConfig;
this.ppButtonFormAction = payPalConfig.buttonAction;
@@ -77,7 +79,7 @@ export class AddCreditComponent implements OnInit {
this.email = this.subject;
this.ppButtonCustomField = "user_id:" + this.userId;
}
this.region = await this.stateService.getRegion();
this.region = await this.configService.getCloudRegion();
this.ppButtonCustomField += ",account_credit:1";
this.ppButtonCustomField += `,region:${this.region}`;
this.returnUrl = window.location.href;

View File

@@ -10,4 +10,5 @@ export abstract class ConfigServiceAbstraction {
getFeatureFlagBool: (key: FeatureFlag, defaultValue?: boolean) => Promise<boolean>;
getFeatureFlagString: (key: FeatureFlag, defaultValue?: string) => Promise<string>;
getFeatureFlagNumber: (key: FeatureFlag, defaultValue?: number) => Promise<number>;
getCloudRegion: (defaultValue?: string) => Promise<string>;
}

View File

@@ -63,6 +63,11 @@ export class ConfigService implements ConfigServiceAbstraction {
return await this.getFeatureFlag(key, defaultValue);
}
async getCloudRegion(defaultValue = "US"): Promise<string> {
const serverConfig = await this.buildServerConfig();
return serverConfig.environment?.cloudRegion ?? defaultValue;
}
private async getFeatureFlag<T>(key: FeatureFlag, defaultValue: T): Promise<T> {
const serverConfig = await this.buildServerConfig();
if (