From 70fbcf2a10aa9de6ed7a598e157852e2f68665f9 Mon Sep 17 00:00:00 2001 From: Nick Krantz <125900171+nick-livefront@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:37:44 -0500 Subject: [PATCH] [PM-11657] Stripe + Browser Refresh Styling (#10978) * add check for `ExtensionRefresh` in StripeService - Stripe components need new styles to match the new CL components * add global styles for Stripe components - Matches closer to the browser refresh components * add browser refresh component details to Stripe JS initialization * add component to match the display of the new component library that shows only when the `ExtensionRefresh` flag is enabled * update both payment components to use payment label component - This styling of the label is separate from the `AC2476_DeprecateStripeSourcesAPI` flag * update security code copy * change layout of the trial component to account for new CL components * absolutely position label to remove extra spacing around the label * remove unneeded logic --- .../app/billing/services/stripe.service.ts | 41 +++++++++++++++---- .../payment/payment-label-v2.component.html | 22 ++++++++++ .../payment/payment-label-v2.component.ts | 36 ++++++++++++++++ .../shared/payment/payment-v2.component.html | 22 ++++------ .../shared/payment/payment-v2.component.ts | 4 +- .../shared/payment/payment.component.html | 24 ++++++----- .../shared/payment/payment.component.ts | 25 ++++++++--- .../billing/shared/tax-info.component.html | 4 +- apps/web/src/locales/en/messages.json | 3 ++ apps/web/src/scss/forms.scss | 26 +++++++++++- 10 files changed, 166 insertions(+), 41 deletions(-) create mode 100644 apps/web/src/app/billing/shared/payment/payment-label-v2.component.html create mode 100644 apps/web/src/app/billing/shared/payment/payment-label-v2.component.ts diff --git a/apps/web/src/app/billing/services/stripe.service.ts b/apps/web/src/app/billing/services/stripe.service.ts index 0445504d50..d19a7ef9da 100644 --- a/apps/web/src/app/billing/services/stripe.service.ts +++ b/apps/web/src/app/billing/services/stripe.service.ts @@ -1,6 +1,8 @@ import { Injectable } from "@angular/core"; import { BankAccount } from "@bitwarden/common/billing/models/domain"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; +import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { BillingServicesModule } from "./billing-services.module"; @@ -15,7 +17,10 @@ export class StripeService { cardCvc: string; }; - constructor(private logService: LogService) {} + constructor( + private logService: LogService, + private configService: ConfigService, + ) {} /** * Loads [Stripe JS]{@link https://docs.stripe.com/js} in the
element of the current page and mounts @@ -32,15 +37,23 @@ export class StripeService { const script = window.document.createElement("script"); script.id = "stripe-script"; script.src = "https://js.stripe.com/v3?advancedFraudSignals=false"; - script.onload = () => { + script.onload = async () => { const window$ = window as any; this.stripe = window$.Stripe(process.env.STRIPE_KEY); this.elements = this.stripe.elements(); - const options = this.getElementOptions(); + const isExtensionRefresh = await this.configService.getFeatureFlag( + FeatureFlag.ExtensionRefresh, + ); setTimeout(() => { - this.elements.create("cardNumber", options); - this.elements.create("cardExpiry", options); - this.elements.create("cardCvc", options); + this.elements.create( + "cardNumber", + this.getElementOptions("cardNumber", isExtensionRefresh), + ); + this.elements.create( + "cardExpiry", + this.getElementOptions("cardExpiry", isExtensionRefresh), + ); + this.elements.create("cardCvc", this.getElementOptions("cardCvc", isExtensionRefresh)); if (autoMount) { this.mountElements(); } @@ -135,7 +148,10 @@ export class StripeService { }, 500); } - private getElementOptions(): any { + private getElementOptions( + element: "cardNumber" | "cardExpiry" | "cardCvc", + isExtensionRefresh: boolean, + ): any { const options: any = { style: { base: { @@ -160,6 +176,17 @@ export class StripeService { }, }; + // Unique settings that should only be applied when the extension refresh flag is active + if (isExtensionRefresh) { + options.style.base.fontWeight = "500"; + options.classes.base = "v2"; + + // Remove the placeholder for number and CVC fields + if (["cardNumber", "cardCvc"].includes(element)) { + options.placeholder = ""; + } + } + const style = getComputedStyle(document.documentElement); options.style.base.color = `rgb(${style.getPropertyValue("--color-text-main")})`; options.style.base["::placeholder"].color = `rgb(${style.getPropertyValue( diff --git a/apps/web/src/app/billing/shared/payment/payment-label-v2.component.html b/apps/web/src/app/billing/shared/payment/payment-label-v2.component.html new file mode 100644 index 0000000000..a2e1c92a05 --- /dev/null +++ b/apps/web/src/app/billing/shared/payment/payment-label-v2.component.html @@ -0,0 +1,22 @@ +