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