From 2aa4b07d6851c8d865ba28bd9bfe0694efa092a2 Mon Sep 17 00:00:00 2001 From: Alex Morask <144709477+amorask-bitwarden@users.noreply.github.com> Date: Fri, 6 Sep 2024 09:51:00 -0400 Subject: [PATCH] Move braintree.service and stripe.service from jslib-services.module into web (#10923) --- .../services/billing-services.module.ts | 4 ++ .../billing/services}/braintree.service.ts | 29 ++++++++++-- apps/web/src/app/billing/services/index.ts | 3 ++ .../app/billing/services}/stripe.service.ts | 39 ++++++++++++++-- .../shared/payment/payment-v2.component.ts | 13 +++--- .../src/services/jslib-services.module.ts | 14 ------ libs/common/src/billing/abstractions/index.ts | 2 - .../braintree.service.abstraction.ts | 28 ------------ .../stripe.service.abstraction.ts | 45 ------------------- 9 files changed, 73 insertions(+), 104 deletions(-) create mode 100644 apps/web/src/app/billing/services/billing-services.module.ts rename {libs/common/src/billing/services/payment-processors => apps/web/src/app/billing/services}/braintree.service.ts (64%) create mode 100644 apps/web/src/app/billing/services/index.ts rename {libs/common/src/billing/services/payment-processors => apps/web/src/app/billing/services}/stripe.service.ts (65%) delete mode 100644 libs/common/src/billing/abstractions/payment-processors/braintree.service.abstraction.ts delete mode 100644 libs/common/src/billing/abstractions/payment-processors/stripe.service.abstraction.ts diff --git a/apps/web/src/app/billing/services/billing-services.module.ts b/apps/web/src/app/billing/services/billing-services.module.ts new file mode 100644 index 0000000000..7412d47c79 --- /dev/null +++ b/apps/web/src/app/billing/services/billing-services.module.ts @@ -0,0 +1,4 @@ +import { NgModule } from "@angular/core"; + +@NgModule({}) +export class BillingServicesModule {} diff --git a/libs/common/src/billing/services/payment-processors/braintree.service.ts b/apps/web/src/app/billing/services/braintree.service.ts similarity index 64% rename from libs/common/src/billing/services/payment-processors/braintree.service.ts rename to apps/web/src/app/billing/services/braintree.service.ts index 98533a5434..04b2b7dd44 100644 --- a/libs/common/src/billing/services/payment-processors/braintree.service.ts +++ b/apps/web/src/app/billing/services/braintree.service.ts @@ -1,12 +1,19 @@ -import { LogService } from "../../../platform/abstractions/log.service"; -import { BraintreeServiceAbstraction } from "../../abstractions"; +import { Injectable } from "@angular/core"; -export class BraintreeService implements BraintreeServiceAbstraction { +import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; + +import { BillingServicesModule } from "./billing-services.module"; + +@Injectable({ providedIn: BillingServicesModule }) +export class BraintreeService { private braintree: any; private containerId: string; constructor(private logService: LogService) {} + /** + * Utilizes the Braintree SDK to create a [Braintree drop-in]{@link https://braintree.github.io/braintree-web-drop-in/docs/current/Dropin.html} instance attached to the container ID specified as part of the {@link loadBraintree} method. + */ createDropin() { window.setTimeout(() => { const window$ = window as any; @@ -37,6 +44,12 @@ export class BraintreeService implements BraintreeServiceAbstraction { }, 250); } + /** + * Loads the Bitwarden dropin.js script in the element of the current page. + * This script attaches the Braintree SDK to the window. + * @param containerId - The ID of the HTML element where the Braintree drop-in will be loaded at. + * @param autoCreateDropin - Specifies whether the Braintree drop-in should be created when dropin.js loads. + */ loadBraintree(containerId: string, autoCreateDropin: boolean) { const script = window.document.createElement("script"); script.id = "dropin-script"; @@ -49,6 +62,10 @@ export class BraintreeService implements BraintreeServiceAbstraction { window.document.head.appendChild(script); } + /** + * Invokes the Braintree [requestPaymentMethod]{@link https://braintree.github.io/braintree-web-drop-in/docs/current/Dropin.html#requestPaymentMethod} method + * in order to generate a payment method token using the active Braintree drop-in. + */ requestPaymentMethod(): Promise { return new Promise((resolve, reject) => { this.braintree.requestPaymentMethod((error: any, payload: any) => { @@ -62,6 +79,12 @@ export class BraintreeService implements BraintreeServiceAbstraction { }); } + /** + * Removes the following elements from the of the current page: + * - The Bitwarden dropin.js script + * - Any