@internetarchive/donation-form 0.5.14 → 0.5.15-a2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/demo/demo-analytics-handler.d.ts +16 -3
  2. package/dist/demo/demo-analytics-handler.js +12 -3
  3. package/dist/demo/demo-analytics-handler.js.map +1 -1
  4. package/dist/src/donation-form-controller.d.ts +10 -3
  5. package/dist/src/donation-form-controller.js +21 -3
  6. package/dist/src/donation-form-controller.js.map +1 -1
  7. package/dist/src/payment-flow-handlers/donation-flow-modal-manager.d.ts +3 -0
  8. package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js +15 -0
  9. package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js.map +1 -1
  10. package/dist/src/payment-flow-handlers/payment-flow-handlers.d.ts +7 -0
  11. package/dist/src/payment-flow-handlers/payment-flow-handlers.js +2 -0
  12. package/dist/src/payment-flow-handlers/payment-flow-handlers.js.map +1 -1
  13. package/dist/test/mocks/mock-analytics-handler.d.ts +1 -0
  14. package/dist/test/mocks/mock-analytics-handler.js +7 -0
  15. package/dist/test/mocks/mock-analytics-handler.js.map +1 -1
  16. package/dist/test/tests/donation-form-controller.test.js +30 -27
  17. package/dist/test/tests/donation-form-controller.test.js.map +1 -1
  18. package/dist/test/tests/flow-handlers/donation-flow-modal-manager.test.js +47 -0
  19. package/dist/test/tests/flow-handlers/donation-flow-modal-manager.test.js.map +1 -1
  20. package/package.json +2 -1
  21. package/src/@types/analytics-handler/index.d.ts +6 -19
  22. package/src/donation-form-controller.ts +24 -5
  23. package/src/payment-flow-handlers/donation-flow-modal-manager.ts +23 -0
  24. package/src/payment-flow-handlers/payment-flow-handlers.ts +15 -1
@@ -1,4 +1,17 @@
1
- import { AnalyticsHandlerInterface } from '../src/@types/analytics-handler';
2
- export declare class DemoAnalyticsHandler implements AnalyticsHandlerInterface {
3
- send_event(category: string, action: string, label?: string, additionalEventParams?: object): void;
1
+ import { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
2
+ export declare class DemoAnalyticsHandler implements AnalyticsManagerInterface {
3
+ nodeToUpdate: HTMLElement;
4
+ sendEvent(options: {
5
+ category: string;
6
+ action: string;
7
+ label?: string;
8
+ additionalEventParams?: object;
9
+ }): void;
10
+ sendEventNoSampling(options: {
11
+ category: string;
12
+ action: string;
13
+ label?: string;
14
+ additionalEventParams?: object;
15
+ }): void;
16
+ sendPing(values: Record<string, any>): void;
4
17
  }
@@ -1,7 +1,16 @@
1
1
  export class DemoAnalyticsHandler {
2
- // eslint-disable-next-line @typescript-eslint/camelcase
3
- send_event(category, action, label, additionalEventParams) {
4
- console.debug('DemoAnalyticsHandler', category, action, label, additionalEventParams);
2
+ sendEvent(options) {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ this.nodeToUpdate.innerHTML = `Action: ${options.action} - Label: ${options.label}`;
5
+ console.debug('DemoAnalyticsHandler -- sendEventNoSampling ', Object.assign({}, options), this.nodeToUpdate.innerHTML);
6
+ }
7
+ sendEventNoSampling(options) {
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ this.nodeToUpdate.innerHTML = `Action: ${options.action} - Label: ${options.label}`;
10
+ console.debug('DemoAnalyticsHandler -- sendEventNoSampling ', Object.assign({}, options), this.nodeToUpdate.innerHTML);
11
+ }
12
+ sendPing(values) {
13
+ console.debug('DemoAnalyticsHandler -- sendPing ', Object.assign({}, values));
5
14
  }
6
15
  }
7
16
  //# sourceMappingURL=demo-analytics-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"demo-analytics-handler.js","sourceRoot":"","sources":["../../demo/demo-analytics-handler.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,oBAAoB;IAC/B,wDAAwD;IACxD,UAAU,CACR,QAAgB,EAChB,MAAc,EACd,KAAc,EACd,qBAA8B;QAE9B,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;IACxF,CAAC;CACF","sourcesContent":["import { AnalyticsHandlerInterface } from '../src/@types/analytics-handler';\n\nexport class DemoAnalyticsHandler implements AnalyticsHandlerInterface {\n // eslint-disable-next-line @typescript-eslint/camelcase\n send_event(\n category: string,\n action: string,\n label?: string,\n additionalEventParams?: object,\n ): void {\n console.debug('DemoAnalyticsHandler', category, action, label, additionalEventParams);\n }\n}\n"]}
1
+ {"version":3,"file":"demo-analytics-handler.js","sourceRoot":"","sources":["../../demo/demo-analytics-handler.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,oBAAoB;IAG/B,SAAS,CAAC,OAKT;QACC,8DAA8D;QAC9D,IAAI,CAAC,YAAY,CAAC,SAAS,GAAG,WAAW,OAAO,CAAC,MAAM,aAAa,OAAO,CAAC,KAAK,EAAE,CAAC;QACpF,OAAO,CAAC,KAAK,CAAC,8CAA8C,oBAAO,OAAO,GAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC7G,CAAC;IAED,mBAAmB,CACjB,OAKC;QACC,8DAA8D;QAC9D,IAAI,CAAC,YAAY,CAAC,SAAS,GAAG,WAAW,OAAO,CAAC,MAAM,aAAa,OAAO,CAAC,KAAK,EAAE,CAAC;QACpF,OAAO,CAAC,KAAK,CAAC,8CAA8C,oBAAO,OAAO,GAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC/G,CAAC;IAED,QAAQ,CAAC,MAA2B;QAClC,OAAO,CAAC,KAAK,CAAC,mCAAmC,oBAAO,MAAM,EAAG,CAAC;IACpE,CAAC;CACF","sourcesContent":["import { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';\nexport class DemoAnalyticsHandler implements AnalyticsManagerInterface {\n nodeToUpdate!: HTMLElement;\n\n sendEvent(options: {\n category: string;\n action: string;\n label?: string;\n additionalEventParams?: object;\n }): void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.nodeToUpdate.innerHTML = `Action: ${options.action} - Label: ${options.label}`;\n console.debug('DemoAnalyticsHandler -- sendEventNoSampling ', { ...options }, this.nodeToUpdate.innerHTML);\n }\n\n sendEventNoSampling(\n options: {\n category: string;\n action: string;\n label?: string;\n additionalEventParams?: object;\n }): void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.nodeToUpdate.innerHTML = `Action: ${options.action} - Label: ${options.label}`;\n console.debug('DemoAnalyticsHandler -- sendEventNoSampling ', { ...options }, this.nodeToUpdate.innerHTML);\n }\n\n sendPing(values: Record<string, any>): void {\n console.debug('DemoAnalyticsHandler -- sendPing ', { ...values });\n }\n}\n"]}
@@ -7,7 +7,7 @@ import { PaymentFlowHandlersInterface } from './payment-flow-handlers/payment-fl
7
7
  import { RecaptchaManagerInterface } from './recaptcha-manager/recaptcha-manager';
8
8
  import './form-elements/badged-input';
9
9
  import './form-elements/contact-form/contact-form';
10
- import { AnalyticsHandlerInterface } from './@types/analytics-handler';
10
+ import { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
11
11
  import { EditDonationAmountSelectionLayout, EditDonationFrequencySelectionMode } from '@internetarchive/donation-form-edit-donation';
12
12
  import { DonationPaymentInfo, DonationType } from '@internetarchive/donation-form-data-models';
13
13
  import { UpsellModalCTAMode } from './modals/upsell-modal-content';
@@ -34,7 +34,7 @@ export declare class DonationFormController extends LitElement {
34
34
  loggedInUser?: string;
35
35
  origin?: string;
36
36
  endpointManager?: BraintreeEndpointManagerInterface;
37
- analyticsHandler?: AnalyticsHandlerInterface;
37
+ analyticsHandler?: AnalyticsManagerInterface;
38
38
  modalManager?: ModalManagerInterface;
39
39
  recaptchaElement?: HTMLElement;
40
40
  braintreeManager?: BraintreeManagerInterface;
@@ -88,10 +88,17 @@ export declare class DonationFormController extends LitElement {
88
88
  /**
89
89
  * Log an event
90
90
  *
91
- * @param {string} name Name of event
91
+ * @param {string} action Name of event
92
92
  * @param {string} label Event label, optional
93
93
  */
94
94
  private logEvent;
95
+ /**
96
+ * Log an event in no sample bucket
97
+ *
98
+ * @param {string} action Name of event
99
+ * @param {string} label Event label, optional
100
+ */
101
+ private logEventNoSampling;
95
102
  /**
96
103
  * This is not the normal LitElement styles block.
97
104
  *
@@ -197,6 +197,12 @@ let DonationFormController = class DonationFormController extends LitElement {
197
197
  braintreeManager: this.braintreeManager,
198
198
  modalManager: this.modalManager,
199
199
  recaptchaManager: this.recaptchaManager,
200
+ resources: {
201
+ analytics: {
202
+ logEvent: this.logEvent.bind(this),
203
+ logEventNoSampling: this.logEventNoSampling.bind(this),
204
+ },
205
+ }
200
206
  });
201
207
  this.donationForm.braintreeManager = this.braintreeManager;
202
208
  this.donationForm.paymentFlowHandlers = this.paymentFlowHandlers;
@@ -369,12 +375,24 @@ let DonationFormController = class DonationFormController extends LitElement {
369
375
  /**
370
376
  * Log an event
371
377
  *
372
- * @param {string} name Name of event
378
+ * @param {string} action Name of event
379
+ * @param {string} label Event label, optional
380
+ */
381
+ logEvent(action, label) {
382
+ var _a;
383
+ const analyticEvent = { action, label, category: this.analyticsCategory };
384
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent(analyticEvent);
385
+ }
386
+ /**
387
+ * Log an event in no sample bucket
388
+ *
389
+ * @param {string} action Name of event
373
390
  * @param {string} label Event label, optional
374
391
  */
375
- logEvent(name, label) {
392
+ logEventNoSampling(action, label) {
376
393
  var _a;
377
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.send_event(this.analyticsCategory, name, label);
394
+ const analyticEvent = { action, label, category: this.analyticsCategory };
395
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling(analyticEvent);
378
396
  }
379
397
  /**
380
398
  * This is not the normal LitElement styles block.
@@ -1 +1 @@
1
- {"version":3,"file":"donation-form-controller.js","sourceRoot":"","sources":["../../src/donation-form-controller.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAkC,MAAM,KAAK,CAAC;AACvE,OAAO,EA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;AAEhB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+DAAqD;AAEpD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAA8C;AAE7C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4DAAsC;AAErC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAAgC;AAE/B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAA8C;AAE7C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gEAA8C;AAE7C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;mEAAoD;AAEnD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8DAA0C;AAGrE;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iEAC6C;AAEhD;IAAvB,KAAK,CAAC,eAAe,CAAC;4DAAqC;AAE5B;IAA/B,KAAK,CAAC,uBAAuB,CAAC;oEAA+C;AAErD;IAAxB,KAAK,CAAC,gBAAgB,CAAC;iEAA4C;AAEpC;IAA/B,KAAK,CAAC,uBAAuB,CAAC;4EAAuD;AAEnD;IAAlC,KAAK,CAAC,0BAA0B,CAAC;qEAAgD;AAE3D;IAAtB,KAAK,CAAC,cAAc,CAAC;2DAAmC;AA1D9C,sBAAsB;IADlC,aAAa,CAAC,0BAA0B,CAAC;GAC7B,sBAAsB,CAwhBlC;SAxhBY,sBAAsB","sourcesContent":["import { LitElement, html, PropertyValues, TemplateResult } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\n\nimport currency from 'currency.js';\nimport {\n LazyLoaderService,\n LazyLoaderServiceInterface,\n} from '@internetarchive/lazy-loader-service';\nimport { ModalManagerInterface } from '@internetarchive/modal-manager';\n\nimport { DonationForm } from './donation-form';\nimport { PaymentClients, PaymentClientsInterface } from './braintree-manager/payment-clients';\nimport { BraintreeManager } from './braintree-manager/braintree-manager';\nimport {\n BraintreeEndpointManagerInterface,\n BraintreeManagerInterface,\n HostingEnvironment,\n} from './braintree-manager/braintree-interfaces';\nimport {\n PaymentFlowHandlers,\n PaymentFlowHandlersInterface,\n} from './payment-flow-handlers/payment-flow-handlers';\n\nimport { RecaptchaManager, RecaptchaManagerInterface } from './recaptcha-manager/recaptcha-manager';\nimport { HostedFieldConfiguration } from './braintree-manager/payment-providers/credit-card/hosted-field-configuration';\nimport {\n HostedFieldContainerInterface,\n HostedFieldContainer,\n} from './braintree-manager/payment-providers/credit-card/hosted-field-container';\n\nimport './form-elements/badged-input';\nimport { ContactForm } from './form-elements/contact-form/contact-form';\nimport './form-elements/contact-form/contact-form';\n\nimport creditCardImg from '@internetarchive/icon-credit-card';\nimport calendarImg from '@internetarchive/icon-calendar';\nimport lockImg from '@internetarchive/icon-lock';\nimport { AnalyticsHandlerInterface } from './@types/analytics-handler';\nimport {\n EditDonationAmountSelectionLayout,\n EditDonationFrequencySelectionMode,\n} from '@internetarchive/donation-form-edit-donation';\n\nimport {\n DonationPaymentInfo,\n PaymentProvider,\n DonationType,\n defaultDonationAmounts,\n defaultSelectedDonationInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { UpsellModalCTAMode } from './modals/upsell-modal-content';\n\n/**\n * The DonationFormController orchestrates several of the interactions between\n * the various pieces of the donation form like modals, braintree, paypal, and recaptcha\n *\n * @export\n * @class RadioPlayerController\n * @extends {LitElement}\n */\n@customElement('donation-form-controller')\nexport class DonationFormController extends LitElement {\n @property({ type: String }) environment?: HostingEnvironment;\n\n @property({ type: String }) braintreeAuthToken?: string;\n\n @property({ type: String }) recaptchaSiteKey?: string;\n\n @property({ type: String }) venmoProfileId?: string;\n\n @property({ type: String }) googlePayMerchantId?: string;\n\n @property({ type: String }) analyticsCategory = 'DonationForm';\n\n @property({ type: Array }) amountOptions: number[] = defaultDonationAmounts;\n\n @property({ type: Object }) donationInfo: DonationPaymentInfo = defaultSelectedDonationInfo;\n\n @property({ type: String }) amountSelectionLayout: EditDonationAmountSelectionLayout =\n EditDonationAmountSelectionLayout.MultiLine;\n\n @property({ type: String }) frequencySelectionMode: EditDonationFrequencySelectionMode =\n EditDonationFrequencySelectionMode.Button;\n\n @property({ type: String }) referrer?: string;\n\n @property({ type: String }) loggedInUser?: string;\n\n @property({ type: String }) origin?: string;\n\n @property({ type: Object }) endpointManager?: BraintreeEndpointManagerInterface;\n\n @property({ type: Object }) analyticsHandler?: AnalyticsHandlerInterface;\n\n @property({ type: Object }) modalManager?: ModalManagerInterface;\n\n @property({ type: Object }) recaptchaElement?: HTMLElement;\n\n @property({ type: Object }) braintreeManager?: BraintreeManagerInterface;\n\n @property({ type: Object }) recaptchaManager?: RecaptchaManagerInterface;\n\n @property({ type: Object }) paymentFlowHandlers?: PaymentFlowHandlersInterface;\n\n @property({ type: Object }) paymentClients?: PaymentClientsInterface;\n\n @property({ type: Object })\n lazyLoaderService: LazyLoaderServiceInterface = new LazyLoaderService();\n\n @query('donation-form') private donationForm!: DonationForm;\n\n @query('#braintree-creditcard') private braintreeNumberInput!: HTMLDivElement;\n\n @query('#braintree-cvv') private braintreeCVVInput!: HTMLDivElement;\n\n @query('#braintree-expiration') private braintreeExpirationDateInput!: HTMLDivElement;\n\n @query('#braintree-error-message') private braintreeErrorMessage!: HTMLDivElement;\n\n @query('contact-form') private contactForm?: ContactForm;\n\n /** @inheritdoc */\n updated(changedProperties: PropertyValues): void {\n if (changedProperties.has('referrer') && this.referrer) {\n this.braintreeManager?.setReferrer(this.referrer);\n }\n\n if (changedProperties.has('loggedInUser') && this.loggedInUser) {\n this.braintreeManager?.setLoggedInUser(this.loggedInUser);\n }\n\n if (changedProperties.has('origin') && this.origin) {\n this.braintreeManager?.setOrigin(this.origin);\n }\n\n if (\n changedProperties.has('paymentClients') ||\n changedProperties.has('braintreeAuthToken') ||\n changedProperties.has('endpointManager') ||\n changedProperties.has('environment')\n ) {\n this.setupBraintreeManager();\n this.setupRecaptchaManager();\n }\n\n if (changedProperties.has('recaptchaSiteKey')) {\n this.setupRecaptchaManager();\n }\n\n if (\n changedProperties.has('braintreeManager') ||\n changedProperties.has('recaptchaManager') ||\n changedProperties.has('modalManager') ||\n changedProperties.has('recaptchaElement')\n ) {\n this.setupPaymentFlowHandlers();\n }\n\n if (\n (changedProperties.has('environment') || changedProperties.has('lazyLoaderService')) &&\n this.environment\n ) {\n this.paymentClients = new PaymentClients(this.lazyLoaderService, this.environment);\n }\n }\n\n async showConfirmationStepDev(options: {\n donationType: DonationType;\n amount: number;\n currencyType: string;\n cancelDonationCB: Function;\n confirmDonationCB: Function;\n }): Promise<void> {\n this.donationForm.showConfirmationModalDev(options);\n }\n\n async showUpsellModalDev(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n this.donationForm.showUpsellModalDev(options);\n }\n\n private setupBraintreeManager(): void {\n if (\n this.braintreeManager === undefined &&\n this.braintreeAuthToken &&\n this.endpointManager &&\n this.paymentClients &&\n this.environment\n ) {\n this.braintreeManager = new BraintreeManager({\n paymentClients: this.paymentClients,\n endpointManager: this.endpointManager,\n authorizationToken: this.braintreeAuthToken,\n venmoProfileId: this.venmoProfileId,\n googlePayMerchantId: this.googlePayMerchantId,\n hostedFieldConfig: this.hostedFieldConfig,\n hostingEnvironment: this.environment,\n referrer: this.referrer,\n loggedInUser: this.loggedInUser,\n origin: this.origin,\n });\n\n this.braintreeManager.on('paymentProvidersHostedFieldsRetry', (retryNumber: number) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsRetry', {\n detail: { retryNumber },\n });\n this.dispatchEvent(event);\n });\n\n this.braintreeManager.on('paymentProvidersHostedFieldsFailed', (error: unknown) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsFailed', {\n detail: { error },\n });\n this.dispatchEvent(event);\n });\n }\n }\n\n private recaptchaManagerSetup = false;\n\n private async setupRecaptchaManager(): Promise<void> {\n if (!this.recaptchaSiteKey || !this.paymentClients || this.recaptchaManagerSetup) {\n return;\n }\n this.recaptchaManagerSetup = true;\n const grecaptchaLibrary = await this.paymentClients.recaptchaLibrary.get();\n this.recaptchaManager = new RecaptchaManager({\n grecaptchaLibrary: grecaptchaLibrary,\n siteKey: this.recaptchaSiteKey,\n });\n }\n\n /** @inheritdoc */\n firstUpdated(): void {\n this.configureFromQueryParams();\n this.trackViewedEvent();\n }\n\n private configureFromQueryParams(): void {\n const urlParams = new URLSearchParams(window.location.search);\n\n let amountOptions = this.amountOptions;\n const amountOptionsParam = urlParams.get('dollarAmounts');\n if (amountOptionsParam) {\n const stripBrackets = amountOptionsParam.slice(1, -1);\n const splitValues = stripBrackets.split(',');\n const numberArray = splitValues\n .map(value => parseFloat(value))\n .filter(value => !isNaN(value));\n amountOptions = numberArray;\n }\n\n let coverFees = this.donationInfo.coverFees;\n const coverFeesParam = urlParams.get('coverFees');\n if (coverFeesParam) {\n coverFees = coverFeesParam === 'true';\n }\n\n let frequency = this.donationInfo.donationType;\n const frequencyParam = urlParams.get('contrib_type');\n if (frequencyParam === 'monthly') {\n frequency = DonationType.Monthly;\n }\n\n let amount = this.donationInfo.amount;\n const amountParam = urlParams.get('amt');\n if (amountParam) {\n const parsedAmount = currency(amountParam).value;\n if (parsedAmount > 0) {\n amount = parsedAmount;\n }\n }\n\n const amountLayoutParam = urlParams.get('amountLayout');\n if (amountLayoutParam) {\n const amountLayout = amountLayoutParam as EditDonationAmountSelectionLayout;\n if (Object.values(EditDonationAmountSelectionLayout).includes(amountLayout)) {\n this.amountSelectionLayout = amountLayout;\n }\n }\n\n const frequencyModeParam = urlParams.get('frequencyMode');\n if (frequencyModeParam) {\n const frequencyMode = frequencyModeParam as EditDonationFrequencySelectionMode;\n if (Object.values(EditDonationFrequencySelectionMode).includes(frequencyMode)) {\n this.frequencySelectionMode = frequencyMode;\n }\n }\n\n const donationInfo = new DonationPaymentInfo({\n donationType: frequency,\n amount: amount,\n coverFees: coverFees,\n });\n\n this.amountOptions = amountOptions;\n this.donationInfo = donationInfo;\n }\n\n private setupPaymentFlowHandlers(): void {\n // only set up once\n if (this.paymentFlowHandlers) {\n return;\n }\n\n // verify we have all of the dependencies\n if (\n !this.braintreeManager ||\n !this.recaptchaManager ||\n !this.modalManager ||\n !this.recaptchaElement\n ) {\n return;\n }\n\n this.paymentFlowHandlers = new PaymentFlowHandlers({\n braintreeManager: this.braintreeManager,\n modalManager: this.modalManager,\n recaptchaManager: this.recaptchaManager,\n });\n\n this.donationForm.braintreeManager = this.braintreeManager;\n this.donationForm.paymentFlowHandlers = this.paymentFlowHandlers;\n\n this.braintreeManager.startup();\n this.paymentFlowHandlers?.startup();\n this.recaptchaManager.setup(this.recaptchaElement, 1, 'light', 'image');\n }\n\n private get hostedFieldConfig(): HostedFieldConfiguration {\n const hostedFieldStyle: Record<string, Record<string, string>> = {\n input: {\n 'font-size': '16px',\n 'font-family': '\"Helvetica Neue\", Helvetica, Arial, sans-serif',\n 'font-weight': '700',\n color: '#333',\n },\n ':focus': {\n color: '#333',\n },\n '.valid': {},\n '.invalid': {\n color: '#b00b00',\n },\n };\n\n const hostedFieldFieldOptions: braintree.HostedFieldFieldOptions = {\n number: {\n selector: '#braintree-creditcard',\n placeholder: 'Card number',\n },\n cvv: {\n selector: '#braintree-cvv',\n placeholder: 'CVC',\n },\n expirationDate: {\n selector: '#braintree-expiration',\n placeholder: 'MM / YY',\n },\n };\n\n const hostedFieldContainer: HostedFieldContainerInterface = new HostedFieldContainer({\n number: this.braintreeNumberInput,\n cvv: this.braintreeCVVInput,\n expirationDate: this.braintreeExpirationDateInput,\n errorContainer: this.braintreeErrorMessage,\n });\n\n const config: HostedFieldConfiguration = new HostedFieldConfiguration({\n hostedFieldStyle,\n hostedFieldFieldOptions,\n hostedFieldContainer,\n });\n\n return config;\n }\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <div class=\"donation-form-controller-container\">\n <donation-form\n .environment=${this.environment}\n .braintreeManager=${this.braintreeManager}\n .contactForm=${this.contactForm}\n .amountOptions=${this.amountOptions}\n .donationInfo=${this.donationInfo}\n .amountSelectionLayout=${this.amountSelectionLayout}\n .frequencySelectionMode=${this.frequencySelectionMode}\n @donationInfoChanged=${this.donationInfoChanged}\n @paymentProviderSelected=${this.paymentProviderSelected}\n @paymentFlowStarted=${this.paymentFlowStarted}\n @paymentFlowConfirmed=${this.paymentFlowConfirmed}\n @paymentFlowCancelled=${this.paymentFlowCancelled}\n @paymentFlowError=${this.paymentFlowError}\n >\n <!--\n Why are these slots here?\n\n Due to the way Braintree, PayPal, and Recaptcha work, they cannot exist\n in the shadowDOM so must exist in the clearDOM and get passed\n in through a <slot>.\n\n Braintree / PayPal are working on a solution to this. See:\n - https://github.com/braintree/braintree-web-drop-in/issues/614#issuecomment-616796104\n - https://github.com/braintree/braintree-web-drop-in/issues/296#issuecomment-616749307\n - https://github.com/paypal/paypal-checkout-components/issues/353#issuecomment-595956216\n -->\n <div slot=\"braintree-hosted-fields\">\n <div id=\"braintree-error-message\"></div>\n <div class=\"braintree-row\">\n <badged-input .icon=${creditCardImg} ?required=${true} class=\"creditcard\">\n <div class=\"braintree-input\" id=\"braintree-creditcard\"></div>\n </badged-input>\n </div>\n <div class=\"braintree-row\">\n <badged-input .icon=${calendarImg} ?required=${true} class=\"expiration\">\n <div class=\"braintree-input\" id=\"braintree-expiration\"></div>\n </badged-input>\n <badged-input .icon=${lockImg} ?required=${true} class=\"cvv\">\n <div class=\"braintree-input\" id=\"braintree-cvv\"></div>\n </badged-input>\n </div>\n </div>\n\n <!--\n Form autocompletion does not work in the shadowDOM so\n we slot the contact form in from the lightDOM and pass\n in a reference to it in the <donation-form> tag above\n -->\n <div slot=\"contact-form\">\n <contact-form></contact-form>\n </div>\n\n <div slot=\"paypal-button\">\n <div id=\"paypal-button\"></div>\n </div>\n\n <slot name=\"recaptcha\" slot=\"recaptcha\"> </slot>\n </donation-form>\n </div>\n\n ${this.getStyles}\n `;\n }\n\n /** @inheritdoc */\n createRenderRoot(): this {\n // Render template without shadow DOM. Note that shadow DOM features like\n // encapsulated CSS and slots are unavailable.\n // We have to do this to accomodate the PayPal buttons and HostedFields,\n // which do not work in the shadow DOM\n return this;\n }\n\n private donationInfoChanged(): void {\n this.logEvent('DonationInfoChanged');\n }\n\n private trackViewedEvent(): void {\n this.logEvent('Viewed');\n }\n\n private paymentProviderSelected(e: CustomEvent): void {\n const paymentProvider = e.detail.paymentProvider as PaymentProvider;\n const previousPaymentProvider = e.detail.previousPaymentProvider;\n const providerNoSpaces = this.removeSpaces(paymentProvider);\n let eventName = `ProviderFirstSelected-${providerNoSpaces}`;\n let previousProviderInfo;\n if (previousPaymentProvider !== undefined) {\n eventName = `ProviderChangedTo-${providerNoSpaces}`;\n previousProviderInfo = `ProviderChangedFrom-${this.removeSpaces(previousPaymentProvider)}`;\n }\n this.logEvent(eventName, previousProviderInfo);\n }\n\n private paymentFlowConfirmed(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n this.logEvent('PaymentFlowConfirmed', providerNoSpaces);\n }\n\n private paymentFlowStarted(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n this.logEvent('PaymentFlowStarted', providerNoSpaces);\n }\n\n private paymentFlowCancelled(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n this.logEvent('PaymentFlowCancelled', providerNoSpaces);\n }\n\n private paymentFlowError(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n const error = e.detail.error;\n const detail = `${providerNoSpaces}-${error}`;\n this.logEvent('PaymentFlowError', detail);\n }\n\n private removeSpaces(original: string): string {\n return original.replace(/\\s+/g, '');\n }\n\n /**\n * Log an event\n *\n * @param {string} name Name of event\n * @param {string} label Event label, optional\n */\n private logEvent(name: string, label?: string): void {\n this.analyticsHandler?.send_event(this.analyticsCategory, name, label);\n }\n\n /**\n * This is not the normal LitElement styles block.\n *\n * This element uses the clear DOM instead of the shadow DOM, it can't use\n * the shadowRoot's isolated styling. This is a bit of a workaround to keep all of\n * the styling local by writing out our own <style> tag and just be careful about\n * the selectors since they will leak outside of this component.\n *\n * @readonly\n * @private\n * @type {TemplateResult}\n * @memberof IADonationFormController\n */\n private get getStyles(): TemplateResult {\n return html`\n <style>\n .donation-form-controller-container {\n color: var(--donateFormTextColor, #333);\n background-color: var(--donateFormBgColor, transparent);\n\n --formSectionContentBackgroundColor: var(--donateFormBgColor, transparent);\n\n --editFormBadgeBgColor: var(--donateFormBadgeBgColor, #333);\n --formSectionBadgeBackgroundColor: var(--donateFormBadgeBgColor, #333);\n\n --editFormBadgeFontColor: var(--donateFormBadgeTextColor, #fff);\n --formSectionBadgeFontColor: var(--donateFormBadgeTextColor, #fff);\n\n --paymentButtonFontColor: var(--donateFormPaymentOptionTextColor);\n --paymentButtonColor: var(--donateFormPaymentOptionBgColor);\n\n --paymentButtonSelectedColor: var(--donateFormSelectedOptionBgColor);\n --paymentButtonSelectedFontColor: var(--donateFormSelectedOptionTextColor);\n }\n .donation-form-controller-container donation-form:focus {\n outline: none;\n }\n\n .donation-form-controller-container #paypal-button {\n opacity: 0.001;\n width: 5rem;\n height: 3rem;\n overflow: hidden;\n }\n\n .donation-form-controller-container .braintree-row {\n display: flex;\n margin-top: -1px;\n }\n\n .donation-form-controller-container badged-input {\n width: 100%;\n }\n\n .donation-form-controller-container badged-input.cvv {\n margin-left: -1px;\n }\n\n .donation-form-controller-container .braintree-input {\n width: 100%;\n height: 100%;\n }\n\n .donation-form-controller-container #braintree-error-message {\n color: red;\n font-size: 1.4rem;\n margin-bottom: 0.6rem;\n }\n\n .donation-form-controller-container div[slot=\"braintree-hosted-fields\"] {\n background-color: white;\n }\n </style>\n `;\n }\n}\n"]}
1
+ {"version":3,"file":"donation-form-controller.js","sourceRoot":"","sources":["../../src/donation-form-controller.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAkC,MAAM,KAAK,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,iBAAiB,GAElB,MAAM,sCAAsC,CAAC;AAI9C,OAAO,EAAE,cAAc,EAA2B,MAAM,qCAAqC,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAMzE,OAAO,EACL,mBAAmB,GAEpB,MAAM,+CAA+C,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAA6B,MAAM,uCAAuC,CAAC;AACpG,OAAO,EAAE,wBAAwB,EAAE,MAAM,8EAA8E,CAAC;AACxH,OAAO,EAEL,oBAAoB,GACrB,MAAM,0EAA0E,CAAC;AAElF,OAAO,8BAA8B,CAAC;AAEtC,OAAO,2CAA2C,CAAC;AAEnD,OAAO,aAAa,MAAM,mCAAmC,CAAC;AAC9D,OAAO,WAAW,MAAM,gCAAgC,CAAC;AACzD,OAAO,OAAO,MAAM,4BAA4B,CAAC;AAGjD,OAAO,EACL,iCAAiC,EACjC,kCAAkC,GACnC,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EACL,mBAAmB,EAEnB,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,GAC5B,MAAM,4CAA4C,CAAC;AAGpD;;;;;;;GAOG;AAEH,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,UAAU;IAAtD;;QAW8B,sBAAiB,GAAG,cAAc,CAAC;QAEpC,kBAAa,GAAa,sBAAsB,CAA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,EAAE,MAAM,EAAE,CAAC;mEAAoD;AAEnD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8DAA0C;AAGrE;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iEAC6C;AAEhD;IAAvB,KAAK,CAAC,eAAe,CAAC;4DAAqC;AAE5B;IAA/B,KAAK,CAAC,uBAAuB,CAAC;oEAA+C;AAErD;IAAxB,KAAK,CAAC,gBAAgB,CAAC;iEAA4C;AAEpC;IAA/B,KAAK,CAAC,uBAAuB,CAAC;4EAAuD;AAEnD;IAAlC,KAAK,CAAC,0BAA0B,CAAC;qEAAgD;AAE3D;IAAtB,KAAK,CAAC,cAAc,CAAC;2DAAmC;AA1D9C,sBAAsB;IADlC,aAAa,CAAC,0BAA0B,CAAC;GAC7B,sBAAsB,CA0iBlC;SA1iBY,sBAAsB","sourcesContent":["import { LitElement, html, PropertyValues, TemplateResult } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\n\nimport currency from 'currency.js';\nimport {\n LazyLoaderService,\n LazyLoaderServiceInterface,\n} from '@internetarchive/lazy-loader-service';\nimport { ModalManagerInterface } from '@internetarchive/modal-manager';\n\nimport { DonationForm } from './donation-form';\nimport { PaymentClients, PaymentClientsInterface } from './braintree-manager/payment-clients';\nimport { BraintreeManager } from './braintree-manager/braintree-manager';\nimport {\n BraintreeEndpointManagerInterface,\n BraintreeManagerInterface,\n HostingEnvironment,\n} from './braintree-manager/braintree-interfaces';\nimport {\n PaymentFlowHandlers,\n PaymentFlowHandlersInterface,\n} from './payment-flow-handlers/payment-flow-handlers';\n\nimport { RecaptchaManager, RecaptchaManagerInterface } from './recaptcha-manager/recaptcha-manager';\nimport { HostedFieldConfiguration } from './braintree-manager/payment-providers/credit-card/hosted-field-configuration';\nimport {\n HostedFieldContainerInterface,\n HostedFieldContainer,\n} from './braintree-manager/payment-providers/credit-card/hosted-field-container';\n\nimport './form-elements/badged-input';\nimport { ContactForm } from './form-elements/contact-form/contact-form';\nimport './form-elements/contact-form/contact-form';\n\nimport creditCardImg from '@internetarchive/icon-credit-card';\nimport calendarImg from '@internetarchive/icon-calendar';\nimport lockImg from '@internetarchive/icon-lock';\nimport { DonationControllerEventLoggerInterface } from './@types/analytics-handler';\nimport { AnalyticsManagerInterface, AnalyticsEvent } from '@internetarchive/analytics-manager';\nimport {\n EditDonationAmountSelectionLayout,\n EditDonationFrequencySelectionMode,\n} from '@internetarchive/donation-form-edit-donation';\n\nimport {\n DonationPaymentInfo,\n PaymentProvider,\n DonationType,\n defaultDonationAmounts,\n defaultSelectedDonationInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { UpsellModalCTAMode } from './modals/upsell-modal-content';\n\n/**\n * The DonationFormController orchestrates several of the interactions between\n * the various pieces of the donation form like modals, braintree, paypal, and recaptcha\n *\n * @export\n * @class RadioPlayerController\n * @extends {LitElement}\n */\n@customElement('donation-form-controller')\nexport class DonationFormController extends LitElement {\n @property({ type: String }) environment?: HostingEnvironment;\n\n @property({ type: String }) braintreeAuthToken?: string;\n\n @property({ type: String }) recaptchaSiteKey?: string;\n\n @property({ type: String }) venmoProfileId?: string;\n\n @property({ type: String }) googlePayMerchantId?: string;\n\n @property({ type: String }) analyticsCategory = 'DonationForm';\n\n @property({ type: Array }) amountOptions: number[] = defaultDonationAmounts;\n\n @property({ type: Object }) donationInfo: DonationPaymentInfo = defaultSelectedDonationInfo;\n\n @property({ type: String }) amountSelectionLayout: EditDonationAmountSelectionLayout =\n EditDonationAmountSelectionLayout.MultiLine;\n\n @property({ type: String }) frequencySelectionMode: EditDonationFrequencySelectionMode =\n EditDonationFrequencySelectionMode.Button;\n\n @property({ type: String }) referrer?: string;\n\n @property({ type: String }) loggedInUser?: string;\n\n @property({ type: String }) origin?: string;\n\n @property({ type: Object }) endpointManager?: BraintreeEndpointManagerInterface;\n\n @property({ type: Object }) analyticsHandler?: AnalyticsManagerInterface;\n\n @property({ type: Object }) modalManager?: ModalManagerInterface;\n\n @property({ type: Object }) recaptchaElement?: HTMLElement;\n\n @property({ type: Object }) braintreeManager?: BraintreeManagerInterface;\n\n @property({ type: Object }) recaptchaManager?: RecaptchaManagerInterface;\n\n @property({ type: Object }) paymentFlowHandlers?: PaymentFlowHandlersInterface;\n\n @property({ type: Object }) paymentClients?: PaymentClientsInterface;\n\n @property({ type: Object })\n lazyLoaderService: LazyLoaderServiceInterface = new LazyLoaderService();\n\n @query('donation-form') private donationForm!: DonationForm;\n\n @query('#braintree-creditcard') private braintreeNumberInput!: HTMLDivElement;\n\n @query('#braintree-cvv') private braintreeCVVInput!: HTMLDivElement;\n\n @query('#braintree-expiration') private braintreeExpirationDateInput!: HTMLDivElement;\n\n @query('#braintree-error-message') private braintreeErrorMessage!: HTMLDivElement;\n\n @query('contact-form') private contactForm?: ContactForm;\n\n /** @inheritdoc */\n updated(changedProperties: PropertyValues): void {\n if (changedProperties.has('referrer') && this.referrer) {\n this.braintreeManager?.setReferrer(this.referrer);\n }\n\n if (changedProperties.has('loggedInUser') && this.loggedInUser) {\n this.braintreeManager?.setLoggedInUser(this.loggedInUser);\n }\n\n if (changedProperties.has('origin') && this.origin) {\n this.braintreeManager?.setOrigin(this.origin);\n }\n\n if (\n changedProperties.has('paymentClients') ||\n changedProperties.has('braintreeAuthToken') ||\n changedProperties.has('endpointManager') ||\n changedProperties.has('environment')\n ) {\n this.setupBraintreeManager();\n this.setupRecaptchaManager();\n }\n\n if (changedProperties.has('recaptchaSiteKey')) {\n this.setupRecaptchaManager();\n }\n\n if (\n changedProperties.has('braintreeManager') ||\n changedProperties.has('recaptchaManager') ||\n changedProperties.has('modalManager') ||\n changedProperties.has('recaptchaElement')\n ) {\n this.setupPaymentFlowHandlers();\n }\n\n if (\n (changedProperties.has('environment') || changedProperties.has('lazyLoaderService')) &&\n this.environment\n ) {\n this.paymentClients = new PaymentClients(this.lazyLoaderService, this.environment);\n }\n }\n\n async showConfirmationStepDev(options: {\n donationType: DonationType;\n amount: number;\n currencyType: string;\n cancelDonationCB: Function;\n confirmDonationCB: Function;\n }): Promise<void> {\n this.donationForm.showConfirmationModalDev(options);\n }\n\n async showUpsellModalDev(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n this.donationForm.showUpsellModalDev(options);\n }\n\n private setupBraintreeManager(): void {\n if (\n this.braintreeManager === undefined &&\n this.braintreeAuthToken &&\n this.endpointManager &&\n this.paymentClients &&\n this.environment\n ) {\n this.braintreeManager = new BraintreeManager({\n paymentClients: this.paymentClients,\n endpointManager: this.endpointManager,\n authorizationToken: this.braintreeAuthToken,\n venmoProfileId: this.venmoProfileId,\n googlePayMerchantId: this.googlePayMerchantId,\n hostedFieldConfig: this.hostedFieldConfig,\n hostingEnvironment: this.environment,\n referrer: this.referrer,\n loggedInUser: this.loggedInUser,\n origin: this.origin,\n });\n\n this.braintreeManager.on('paymentProvidersHostedFieldsRetry', (retryNumber: number) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsRetry', {\n detail: { retryNumber },\n });\n this.dispatchEvent(event);\n });\n\n this.braintreeManager.on('paymentProvidersHostedFieldsFailed', (error: unknown) => {\n const event = new CustomEvent('paymentProvidersHostedFieldsFailed', {\n detail: { error },\n });\n this.dispatchEvent(event);\n });\n }\n }\n\n private recaptchaManagerSetup = false;\n\n private async setupRecaptchaManager(): Promise<void> {\n if (!this.recaptchaSiteKey || !this.paymentClients || this.recaptchaManagerSetup) {\n return;\n }\n this.recaptchaManagerSetup = true;\n const grecaptchaLibrary = await this.paymentClients.recaptchaLibrary.get();\n this.recaptchaManager = new RecaptchaManager({\n grecaptchaLibrary: grecaptchaLibrary,\n siteKey: this.recaptchaSiteKey,\n });\n }\n\n /** @inheritdoc */\n firstUpdated(): void {\n this.configureFromQueryParams();\n this.trackViewedEvent();\n }\n\n private configureFromQueryParams(): void {\n const urlParams = new URLSearchParams(window.location.search);\n\n let amountOptions = this.amountOptions;\n const amountOptionsParam = urlParams.get('dollarAmounts');\n if (amountOptionsParam) {\n const stripBrackets = amountOptionsParam.slice(1, -1);\n const splitValues = stripBrackets.split(',');\n const numberArray = splitValues\n .map(value => parseFloat(value))\n .filter(value => !isNaN(value));\n amountOptions = numberArray;\n }\n\n let coverFees = this.donationInfo.coverFees;\n const coverFeesParam = urlParams.get('coverFees');\n if (coverFeesParam) {\n coverFees = coverFeesParam === 'true';\n }\n\n let frequency = this.donationInfo.donationType;\n const frequencyParam = urlParams.get('contrib_type');\n if (frequencyParam === 'monthly') {\n frequency = DonationType.Monthly;\n }\n\n let amount = this.donationInfo.amount;\n const amountParam = urlParams.get('amt');\n if (amountParam) {\n const parsedAmount = currency(amountParam).value;\n if (parsedAmount > 0) {\n amount = parsedAmount;\n }\n }\n\n const amountLayoutParam = urlParams.get('amountLayout');\n if (amountLayoutParam) {\n const amountLayout = amountLayoutParam as EditDonationAmountSelectionLayout;\n if (Object.values(EditDonationAmountSelectionLayout).includes(amountLayout)) {\n this.amountSelectionLayout = amountLayout;\n }\n }\n\n const frequencyModeParam = urlParams.get('frequencyMode');\n if (frequencyModeParam) {\n const frequencyMode = frequencyModeParam as EditDonationFrequencySelectionMode;\n if (Object.values(EditDonationFrequencySelectionMode).includes(frequencyMode)) {\n this.frequencySelectionMode = frequencyMode;\n }\n }\n\n const donationInfo = new DonationPaymentInfo({\n donationType: frequency,\n amount: amount,\n coverFees: coverFees,\n });\n\n this.amountOptions = amountOptions;\n this.donationInfo = donationInfo;\n }\n\n private setupPaymentFlowHandlers(): void {\n // only set up once\n if (this.paymentFlowHandlers) {\n return;\n }\n\n // verify we have all of the dependencies\n if (\n !this.braintreeManager ||\n !this.recaptchaManager ||\n !this.modalManager ||\n !this.recaptchaElement\n ) {\n return;\n }\n\n this.paymentFlowHandlers = new PaymentFlowHandlers({\n braintreeManager: this.braintreeManager,\n modalManager: this.modalManager,\n recaptchaManager: this.recaptchaManager,\n resources: {\n analytics: {\n logEvent: this.logEvent.bind(this),\n logEventNoSampling: this.logEventNoSampling.bind(this),\n } as DonationControllerEventLoggerInterface,\n }\n });\n\n this.donationForm.braintreeManager = this.braintreeManager;\n this.donationForm.paymentFlowHandlers = this.paymentFlowHandlers;\n\n this.braintreeManager.startup();\n this.paymentFlowHandlers?.startup();\n this.recaptchaManager.setup(this.recaptchaElement, 1, 'light', 'image');\n }\n\n private get hostedFieldConfig(): HostedFieldConfiguration {\n const hostedFieldStyle: Record<string, Record<string, string>> = {\n input: {\n 'font-size': '16px',\n 'font-family': '\"Helvetica Neue\", Helvetica, Arial, sans-serif',\n 'font-weight': '700',\n color: '#333',\n },\n ':focus': {\n color: '#333',\n },\n '.valid': {},\n '.invalid': {\n color: '#b00b00',\n },\n };\n\n const hostedFieldFieldOptions: braintree.HostedFieldFieldOptions = {\n number: {\n selector: '#braintree-creditcard',\n placeholder: 'Card number',\n },\n cvv: {\n selector: '#braintree-cvv',\n placeholder: 'CVC',\n },\n expirationDate: {\n selector: '#braintree-expiration',\n placeholder: 'MM / YY',\n },\n };\n\n const hostedFieldContainer: HostedFieldContainerInterface = new HostedFieldContainer({\n number: this.braintreeNumberInput,\n cvv: this.braintreeCVVInput,\n expirationDate: this.braintreeExpirationDateInput,\n errorContainer: this.braintreeErrorMessage,\n });\n\n const config: HostedFieldConfiguration = new HostedFieldConfiguration({\n hostedFieldStyle,\n hostedFieldFieldOptions,\n hostedFieldContainer,\n });\n\n return config;\n }\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <div class=\"donation-form-controller-container\">\n <donation-form\n .environment=${this.environment}\n .braintreeManager=${this.braintreeManager}\n .contactForm=${this.contactForm}\n .amountOptions=${this.amountOptions}\n .donationInfo=${this.donationInfo}\n .amountSelectionLayout=${this.amountSelectionLayout}\n .frequencySelectionMode=${this.frequencySelectionMode}\n @donationInfoChanged=${this.donationInfoChanged}\n @paymentProviderSelected=${this.paymentProviderSelected}\n @paymentFlowStarted=${this.paymentFlowStarted}\n @paymentFlowConfirmed=${this.paymentFlowConfirmed}\n @paymentFlowCancelled=${this.paymentFlowCancelled}\n @paymentFlowError=${this.paymentFlowError}\n >\n <!--\n Why are these slots here?\n\n Due to the way Braintree, PayPal, and Recaptcha work, they cannot exist\n in the shadowDOM so must exist in the clearDOM and get passed\n in through a <slot>.\n\n Braintree / PayPal are working on a solution to this. See:\n - https://github.com/braintree/braintree-web-drop-in/issues/614#issuecomment-616796104\n - https://github.com/braintree/braintree-web-drop-in/issues/296#issuecomment-616749307\n - https://github.com/paypal/paypal-checkout-components/issues/353#issuecomment-595956216\n -->\n <div slot=\"braintree-hosted-fields\">\n <div id=\"braintree-error-message\"></div>\n <div class=\"braintree-row\">\n <badged-input .icon=${creditCardImg} ?required=${true} class=\"creditcard\">\n <div class=\"braintree-input\" id=\"braintree-creditcard\"></div>\n </badged-input>\n </div>\n <div class=\"braintree-row\">\n <badged-input .icon=${calendarImg} ?required=${true} class=\"expiration\">\n <div class=\"braintree-input\" id=\"braintree-expiration\"></div>\n </badged-input>\n <badged-input .icon=${lockImg} ?required=${true} class=\"cvv\">\n <div class=\"braintree-input\" id=\"braintree-cvv\"></div>\n </badged-input>\n </div>\n </div>\n\n <!--\n Form autocompletion does not work in the shadowDOM so\n we slot the contact form in from the lightDOM and pass\n in a reference to it in the <donation-form> tag above\n -->\n <div slot=\"contact-form\">\n <contact-form></contact-form>\n </div>\n\n <div slot=\"paypal-button\">\n <div id=\"paypal-button\"></div>\n </div>\n\n <slot name=\"recaptcha\" slot=\"recaptcha\"> </slot>\n </donation-form>\n </div>\n\n ${this.getStyles}\n `;\n }\n\n /** @inheritdoc */\n createRenderRoot(): this {\n // Render template without shadow DOM. Note that shadow DOM features like\n // encapsulated CSS and slots are unavailable.\n // We have to do this to accomodate the PayPal buttons and HostedFields,\n // which do not work in the shadow DOM\n return this;\n }\n\n private donationInfoChanged(): void {\n this.logEvent('DonationInfoChanged');\n }\n\n private trackViewedEvent(): void {\n this.logEvent('Viewed');\n }\n\n private paymentProviderSelected(e: CustomEvent): void {\n const paymentProvider = e.detail.paymentProvider as PaymentProvider;\n const previousPaymentProvider = e.detail.previousPaymentProvider;\n const providerNoSpaces = this.removeSpaces(paymentProvider);\n let eventName = `ProviderFirstSelected-${providerNoSpaces}`;\n let previousProviderInfo;\n if (previousPaymentProvider !== undefined) {\n eventName = `ProviderChangedTo-${providerNoSpaces}`;\n previousProviderInfo = `ProviderChangedFrom-${this.removeSpaces(previousPaymentProvider)}`;\n }\n this.logEvent(eventName, previousProviderInfo);\n }\n\n private paymentFlowConfirmed(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n this.logEvent('PaymentFlowConfirmed', providerNoSpaces);\n }\n\n private paymentFlowStarted(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n this.logEvent('PaymentFlowStarted', providerNoSpaces);\n }\n\n private paymentFlowCancelled(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n this.logEvent('PaymentFlowCancelled', providerNoSpaces);\n }\n\n private paymentFlowError(e: CustomEvent): void {\n const selectedProvider = e.detail.paymentProvider as PaymentProvider;\n const providerNoSpaces = this.removeSpaces(selectedProvider);\n const error = e.detail.error;\n const detail = `${providerNoSpaces}-${error}`;\n this.logEvent('PaymentFlowError', detail);\n }\n\n private removeSpaces(original: string): string {\n return original.replace(/\\s+/g, '');\n }\n\n /**\n * Log an event\n *\n * @param {string} action Name of event\n * @param {string} label Event label, optional\n */\n private logEvent(action: string, label?: string): void {\n const analyticEvent = { action, label, category: this.analyticsCategory } as AnalyticsEvent;\n this.analyticsHandler?.sendEvent(analyticEvent);\n }\n\n /**\n * Log an event in no sample bucket\n *\n * @param {string} action Name of event\n * @param {string} label Event label, optional\n */\n private logEventNoSampling(action: string, label?: string): void {\n const analyticEvent = { action, label, category: this.analyticsCategory } as AnalyticsEvent;\n this.analyticsHandler?.sendEventNoSampling(analyticEvent);\n }\n\n /**\n * This is not the normal LitElement styles block.\n *\n * This element uses the clear DOM instead of the shadow DOM, it can't use\n * the shadowRoot's isolated styling. This is a bit of a workaround to keep all of\n * the styling local by writing out our own <style> tag and just be careful about\n * the selectors since they will leak outside of this component.\n *\n * @readonly\n * @private\n * @type {TemplateResult}\n * @memberof IADonationFormController\n */\n private get getStyles(): TemplateResult {\n return html`\n <style>\n .donation-form-controller-container {\n color: var(--donateFormTextColor, #333);\n background-color: var(--donateFormBgColor, transparent);\n\n --formSectionContentBackgroundColor: var(--donateFormBgColor, transparent);\n\n --editFormBadgeBgColor: var(--donateFormBadgeBgColor, #333);\n --formSectionBadgeBackgroundColor: var(--donateFormBadgeBgColor, #333);\n\n --editFormBadgeFontColor: var(--donateFormBadgeTextColor, #fff);\n --formSectionBadgeFontColor: var(--donateFormBadgeTextColor, #fff);\n\n --paymentButtonFontColor: var(--donateFormPaymentOptionTextColor);\n --paymentButtonColor: var(--donateFormPaymentOptionBgColor);\n\n --paymentButtonSelectedColor: var(--donateFormSelectedOptionBgColor);\n --paymentButtonSelectedFontColor: var(--donateFormSelectedOptionTextColor);\n }\n .donation-form-controller-container donation-form:focus {\n outline: none;\n }\n\n .donation-form-controller-container #paypal-button {\n opacity: 0.001;\n width: 5rem;\n height: 3rem;\n overflow: hidden;\n }\n\n .donation-form-controller-container .braintree-row {\n display: flex;\n margin-top: -1px;\n }\n\n .donation-form-controller-container badged-input {\n width: 100%;\n }\n\n .donation-form-controller-container badged-input.cvv {\n margin-left: -1px;\n }\n\n .donation-form-controller-container .braintree-input {\n width: 100%;\n height: 100%;\n }\n\n .donation-form-controller-container #braintree-error-message {\n color: red;\n font-size: 1.4rem;\n margin-bottom: 0.6rem;\n }\n\n .donation-form-controller-container div[slot=\"braintree-hosted-fields\"] {\n background-color: white;\n }\n </style>\n `;\n }\n}\n"]}
@@ -4,6 +4,7 @@ import '../modals/confirm-donation-modal-content';
4
4
  import { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';
5
5
  import { SuccessResponse, DonationPaymentInfo, DonationType, PaymentProvider, BillingInfo, CustomerInfo, DonationResponse } from '@internetarchive/donation-form-data-models';
6
6
  import '../modals/error-modal-content';
7
+ import { DonationControllerEventLoggerInterface } from '../@types/analytics-handler';
7
8
  /**
8
9
  * The DonationFlowModalManager is responsible for most of the high-level modal flows.
9
10
  *
@@ -123,9 +124,11 @@ export interface DonationFlowModalManagerInterface {
123
124
  export declare class DonationFlowModalManager implements DonationFlowModalManagerInterface {
124
125
  private braintreeManager;
125
126
  private modalManager;
127
+ private analytics;
126
128
  constructor(options: {
127
129
  braintreeManager: BraintreeManagerInterface;
128
130
  modalManager: ModalManagerInterface;
131
+ analytics: DonationControllerEventLoggerInterface;
129
132
  });
130
133
  /** @inheritdoc */
131
134
  closeModal(): void;
@@ -15,6 +15,7 @@ export class DonationFlowModalManager {
15
15
  constructor(options) {
16
16
  this.modalManager = options.modalManager;
17
17
  this.braintreeManager = options.braintreeManager;
18
+ this.analytics = options.analytics;
18
19
  }
19
20
  /** @inheritdoc */
20
21
  closeModal() {
@@ -47,6 +48,15 @@ export class DonationFlowModalManager {
47
48
  this.modalManager.showModal({
48
49
  config: modalConfig,
49
50
  });
51
+ // post analytic
52
+ const selectedPayment = options.successResponse.paymentProvider.replace(/\s+/g, '');
53
+ let action = `Donated-${selectedPayment}`;
54
+ if (options.upsellSuccessResponse) {
55
+ action += `-upsell`;
56
+ }
57
+ const label = options.successResponse.donationType;
58
+ this.analytics.logEventNoSampling(action, label);
59
+ // post donation
50
60
  this.braintreeManager.donationSuccessful(options);
51
61
  }
52
62
  /** @inheritdoc */
@@ -192,6 +202,11 @@ export class DonationFlowModalManager {
192
202
  }
193
203
  completeUpsell(options) {
194
204
  this.showThankYouModal(options);
205
+ // post analytic
206
+ const selectedPayment = options.successResponse.paymentProvider.replace(/\s+/g, '');
207
+ const action = `Donated-${selectedPayment}-upsell`;
208
+ const label = options.successResponse.donationType;
209
+ this.analytics.logEventNoSampling(action, label);
195
210
  this.braintreeManager.donationSuccessful(options);
196
211
  }
197
212
  static getDefaultUpsellAmount(oneTimeAmount) {
@@ -1 +1 @@
1
- {"version":3,"file":"donation-flow-modal-manager.js","sourceRoot":"","sources":["../../../src/payment-flow-handlers/donation-flow-modal-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAyB,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,0CAA0C,CAAC;AAElD,OAAO,EAIL,YAAY,GAKb,MAAM,4CAA4C,CAAC;AACpD,OAAO,+BAA+B,CAAC;AAEvC,IAAK,gBAIJ;AAJD,WAAK,gBAAgB;IACnB,oCAAgB,CAAA;IAChB,qCAAiB,CAAA;IACjB,mCAAe,CAAA;AACjB,CAAC,EAJI,gBAAgB,KAAhB,gBAAgB,QAIpB;AA6HD,MAAM,OAAO,wBAAwB;IAKnC,YAAY,OAGX;QACC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACnD,CAAC;IAED,kBAAkB;IAClB,UAAU;QACR,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;IACjC,CAAC;IAED,kBAAkB;IAClB,mBAAmB;QACjB,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC;YAClC,WAAW,EAAE,gBAAgB,CAAC,IAAI;YAClC,uBAAuB,EAAE,IAAI;YAC7B,oBAAoB,EAAE,KAAK;YAC3B,eAAe,EAAE,KAAK;YACtB,mBAAmB,EAAE,YAAY;YACjC,KAAK,EAAE,IAAI,CAAA;;OAEV;SACF,CAAC,CAAC;QACH,I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AE,IAAI,aAAa,IAAI,GAAG;YAAE,MAAM,GAAG,EAAE,CAAC;aAC5D,IAAI,aAAa,GAAG,GAAG;YAAE,MAAM,GAAG,EAAE,CAAC;QAE1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,kBAAkB;IAClB,gCAAgC,CAC9B,YAAiC,EACjC,QAAyB;QAEzB,QAAQ,YAAY,CAAC,YAAY,EAAE;YACjC,KAAK,YAAY,CAAC,OAAO;gBACvB,IAAI,CAAC,eAAe,CAAC;oBACnB,aAAa,EAAE,QAAQ,CAAC,MAAM;oBAC9B,WAAW,EAAE,CAAC,MAAc,EAAE,EAAE;wBAC9B,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAChD,CAAC;oBACD,UAAU,EAAE,GAAG,EAAE;wBACf,IAAI,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;oBACxD,CAAC;oBACD,uBAAuB,EAAE,GAAG,EAAE;wBAC5B,IAAI,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;oBACxD,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,YAAY,CAAC,OAAO;gBACvB,IAAI,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACtD,MAAM;YACR,qEAAqE;YACrE,6DAA6D;YAC7D,KAAK,YAAY,CAAC,MAAM;gBACtB,MAAM;YACR;gBACE,MAAM;SACT;IACH,CAAC;CACF","sourcesContent":["import { html } from 'lit';\nimport { ModalConfig, ModalManagerInterface } from '@internetarchive/modal-manager';\nimport { UpsellModalCTAMode } from '../modals/upsell-modal-content';\nimport '../modals/confirm-donation-modal-content';\nimport { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';\nimport {\n SuccessResponse,\n ErrorResponse,\n DonationPaymentInfo,\n DonationType,\n PaymentProvider,\n BillingInfo,\n CustomerInfo,\n DonationResponse,\n} from '@internetarchive/donation-form-data-models';\nimport '../modals/error-modal-content';\n\nenum ModalHeaderColor {\n Blue = '#497fbf',\n Green = '#55A183',\n Red = '#691916',\n}\n\n/**\n * The DonationFlowModalManager is responsible for most of the high-level modal flows.\n *\n * Each of the payment providers has slightly different interactions, ie the PayPal button,\n * ApplePay popup, Venmo launching the app, etc. The modal flow is the same for all of them\n * so this class gets called by the individual payment flow handlers to take the user\n * through the modal flow.\n *\n * @export\n * @interface DonationFlowModalManagerInterface\n */\nexport interface DonationFlowModalManagerInterface {\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void>;\n /**\n * Close the modal\n *\n * @memberof DonationFlowModalManagerInterface\n */\n closeModal(): void;\n\n /**\n * Show the processing modal\n *\n * @memberof DonationFlowModalManagerInterface\n */\n showProcessingModal(): void;\n\n /**\n * Show the Thank You modal\n *\n * @memberof DonationFlowModalManagerInterface\n */\n showThankYouModal(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void;\n\n /**\n * Show the Error modal\n *\n * @param {{\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @memberof DonationFlowModalManagerInterface\n */\n showErrorModal(options: { message: string; userClosedModalCallback?: () => void }): void;\n\n /**\n * Show the upsell modal\n *\n * @param {{\n * ctaMode?: UpsellModalCTAMode;\n * yesSelected?: (amount: number) => void;\n * noSelected?: () => void;\n * amountChanged?: (amount: number) => void;\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @returns {Promise<void>}\n * @memberof DonationFlowModalManagerInterface\n */\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void>;\n\n /**\n * Start the donation submission flow. This kicks off the \"main\" modal flow once the\n * user authorizes the donation through their payment provider, which provides\n * us the with the nonce used to complete the donation.\n *\n * @param {{\n * nonce: string;\n * paymentProvider: PaymentProvider;\n * donationInfo: DonationPaymentInfo;\n * billingInfo: BillingInfo;\n * customerInfo: CustomerInfo;\n * upsellOnetimeTransactionId?: string;\n * customerId?: string;\n * recaptchaToken?: string;\n * bin?: string; // first 6 digits of CC\n * binName?: string; // credit card bank name\n * }} options\n * @returns {(Promise<DonationResponse | undefined>)}\n * @memberof DonationFlowModalManagerInterface\n */\n startDonationSubmissionFlow(options: {\n nonce: string;\n paymentProvider: PaymentProvider;\n donationInfo: DonationPaymentInfo;\n billingInfo: BillingInfo;\n customerInfo: CustomerInfo;\n upsellOnetimeTransactionId?: string;\n customerId?: string;\n recaptchaToken?: string;\n bin?: string; // first 6 digits of CC\n binName?: string; // credit card bank name\n }): Promise<DonationResponse | undefined>;\n\n /**\n * Handle a successful donation response. This encapsulates the logic for the type of\n * donation that was made.\n * ie. If it was a one-time donation, show the upsell, if it was monthly do not.\n *\n * @param {DonationPaymentInfo} donationInfo\n * @param {SuccessResponse} response\n * @memberof DonationFlowModalManagerInterface\n */\n handleSuccessfulDonationResponse(\n donationInfo: DonationPaymentInfo,\n response: SuccessResponse,\n ): void;\n}\n\nexport class DonationFlowModalManager implements DonationFlowModalManagerInterface {\n private braintreeManager: BraintreeManagerInterface;\n\n private modalManager: ModalManagerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n modalManager: ModalManagerInterface;\n }) {\n this.modalManager = options.modalManager;\n this.braintreeManager = options.braintreeManager;\n }\n\n /** @inheritdoc */\n closeModal(): void {\n this.modalManager.closeModal();\n }\n\n /** @inheritdoc */\n showProcessingModal(): void {\n const modalConfig = new ModalConfig({\n headerColor: ModalHeaderColor.Blue,\n showProcessingIndicator: true,\n closeOnBackdropClick: false,\n showCloseButton: false,\n processingImageMode: 'processing',\n title: html`\n Processing...\n `,\n });\n this.modalManager.showModal({ config: modalConfig });\n }\n\n /** @inheritdoc */\n showThankYouModal(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void {\n const modalConfig = new ModalConfig({\n showProcessingIndicator: true,\n processingImageMode: 'complete',\n headerColor: ModalHeaderColor.Green,\n title: html`\n Thank You!\n `,\n });\n this.modalManager.showModal({\n config: modalConfig,\n });\n this.braintreeManager.donationSuccessful(options);\n }\n\n /** @inheritdoc */\n showErrorModal(options: { message: string; userClosedModalCallback?: () => void }): void {\n const modalConfig = new ModalConfig({\n headerColor: ModalHeaderColor.Red,\n title: html`\n Processing error\n `,\n headline: html`\n There's been a problem completing your donation.\n `,\n message: html`\n ${options?.message}\n `,\n });\n\n this.modalManager.showModal({\n config: modalConfig,\n userClosedModalCallback: options?.userClosedModalCallback,\n customModalContent: html`\n <donation-form-error-modal-content></donation-form-error-modal-content>\n `,\n });\n }\n\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void> {\n const confirmDonation = (): void => {\n options?.confirmDonationCB();\n };\n const cancelDonation = (): void => {\n options?.cancelDonationCB();\n };\n const modalTitle = options.donationType === DonationType.Upsell\n ? 'Confirm monthly donation'\n : 'Complete donation';\n\n const modalConfig = new ModalConfig({\n closeOnBackdropClick: false,\n headerColor: ModalHeaderColor.Green,\n title: html`${modalTitle}`,\n message: html`\n <confirm-donation-modal\n .amount=\"${options.amount}\"\n .currencyType=\"${options.currencyType}\"\n .donationType=\"${options.donationType}\"\n .confirmDonation=${confirmDonation}\n .cancelDonation=${cancelDonation}\n ></confirm-donation-modal>\n `,\n });\n return this.modalManager.showModal({\n config: modalConfig,\n userClosedModalCallback: cancelDonation\n });\n }\n\n /** @inheritdoc */\n showUpsellModal(options: {\n oneTimeAmount: number;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n ctaMode?: UpsellModalCTAMode;\n }): Promise<void> {\n const modalConfig = new ModalConfig({\n headerColor: ModalHeaderColor.Green,\n title: html`\n Donation received\n `,\n processingImageMode: 'complete',\n showProcessingIndicator: true,\n });\n\n const upsellAmount = DonationFlowModalManager.getDefaultUpsellAmount(options.oneTimeAmount);\n if (options.amountChanged) {\n options.amountChanged(upsellAmount);\n }\n\n const modalContent = html`\n <upsell-modal-content\n .amount=${upsellAmount}\n .yesButtonMode=${options?.ctaMode ?? UpsellModalCTAMode.YesButton}\n @yesSelected=${(e: CustomEvent): void =>\n options?.yesSelected ? options.yesSelected(e.detail.amount) : undefined}\n @noThanksSelected=${options?.noSelected}\n @amountChanged=${(e: CustomEvent): void =>\n options?.amountChanged ? options.amountChanged(e.detail.amount) : undefined}\n >\n <slot name=\"paypal-upsell-button\"></slot>\n </upsell-modal-content>\n `;\n return this.modalManager.showModal({\n config: modalConfig,\n customModalContent: modalContent,\n userClosedModalCallback: options?.userClosedModalCallback,\n });\n }\n\n /** @inheritdoc */\n async startDonationSubmissionFlow(options: {\n nonce: string;\n paymentProvider: PaymentProvider;\n donationInfo: DonationPaymentInfo;\n billingInfo: BillingInfo;\n customerInfo: CustomerInfo;\n upsellOnetimeTransactionId?: string;\n customerId?: string;\n recaptchaToken?: string;\n bin?: string; // first 6 digits of CC\n binName?: string; // credit card bank name\n }): Promise<DonationResponse | undefined> {\n this.showProcessingModal();\n\n try {\n const response = await this.braintreeManager.submitDonation(options);\n\n if (response.success) {\n this.handleSuccessfulDonationResponse(\n options.donationInfo,\n response.value as SuccessResponse,\n );\n return response;\n } else {\n const error = response.value as ErrorResponse;\n this.showErrorModal({\n message: error.message,\n });\n return response;\n }\n } catch (error) {\n this.showErrorModal({\n message: `${error}`,\n });\n console.error('error getting a response', error);\n return undefined;\n }\n }\n\n private async upsellModalYesSelected(\n oneTimeDonationResponse: SuccessResponse,\n amount: number,\n ): Promise<DonationResponse | undefined> {\n this.showProcessingModal();\n\n try {\n const response = await this.braintreeManager.submitUpsellDonation({\n oneTimeDonationResponse: oneTimeDonationResponse,\n amount: amount,\n });\n\n if (response.success) {\n this.completeUpsell({\n successResponse: oneTimeDonationResponse,\n upsellSuccessResponse: response.value as SuccessResponse,\n });\n } else {\n const error = response.value as ErrorResponse;\n this.showErrorModal({\n message: error.message,\n });\n }\n\n return response;\n } catch (error) {\n this.showErrorModal({\n message: `${error}`,\n });\n console.error('error getting a response', error);\n return undefined;\n }\n }\n\n private completeUpsell(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void {\n this.showThankYouModal(options);\n this.braintreeManager.donationSuccessful(options);\n }\n\n static getDefaultUpsellAmount(oneTimeAmount: number): number {\n let amount = 5;\n\n if (oneTimeAmount <= 10) amount = 5;\n else if (oneTimeAmount > 10 && oneTimeAmount <= 25) amount = 10;\n else if (oneTimeAmount > 25 && oneTimeAmount <= 100) amount = 25;\n else if (oneTimeAmount > 100) amount = 50;\n\n return amount;\n }\n\n /** @inheritdoc */\n handleSuccessfulDonationResponse(\n donationInfo: DonationPaymentInfo,\n response: SuccessResponse,\n ): void {\n switch (donationInfo.donationType) {\n case DonationType.OneTime:\n this.showUpsellModal({\n oneTimeAmount: response.amount,\n yesSelected: (amount: number) => {\n this.upsellModalYesSelected(response, amount);\n },\n noSelected: () => {\n this.showThankYouModal({ successResponse: response });\n },\n userClosedModalCallback: () => {\n this.showThankYouModal({ successResponse: response });\n },\n });\n break;\n case DonationType.Monthly:\n this.showThankYouModal({ successResponse: response });\n break;\n // This case will never be reached, it is only here for completeness.\n // The upsell case gets handled in `modalYesSelected()` below\n case DonationType.Upsell:\n break;\n default:\n break;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"donation-flow-modal-manager.js","sourceRoot":"","sources":["../../../src/payment-flow-handlers/donation-flow-modal-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAyB,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MA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AAC,MAAM;gBACtB,MAAM;YACR;gBACE,MAAM;SACT;IACH,CAAC;CACF","sourcesContent":["import { html } from 'lit';\nimport { ModalConfig, ModalManagerInterface } from '@internetarchive/modal-manager';\nimport { UpsellModalCTAMode } from '../modals/upsell-modal-content';\nimport '../modals/confirm-donation-modal-content';\nimport { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';\nimport {\n SuccessResponse,\n ErrorResponse,\n DonationPaymentInfo,\n DonationType,\n PaymentProvider,\n BillingInfo,\n CustomerInfo,\n DonationResponse,\n} from '@internetarchive/donation-form-data-models';\nimport '../modals/error-modal-content';\nimport { DonationControllerEventLoggerInterface } from '../@types/analytics-handler';\n\nenum ModalHeaderColor {\n Blue = '#497fbf',\n Green = '#55A183',\n Red = '#691916',\n}\n\n/**\n * The DonationFlowModalManager is responsible for most of the high-level modal flows.\n *\n * Each of the payment providers has slightly different interactions, ie the PayPal button,\n * ApplePay popup, Venmo launching the app, etc. The modal flow is the same for all of them\n * so this class gets called by the individual payment flow handlers to take the user\n * through the modal flow.\n *\n * @export\n * @interface DonationFlowModalManagerInterface\n */\nexport interface DonationFlowModalManagerInterface {\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void>;\n /**\n * Close the modal\n *\n * @memberof DonationFlowModalManagerInterface\n */\n closeModal(): void;\n\n /**\n * Show the processing modal\n *\n * @memberof DonationFlowModalManagerInterface\n */\n showProcessingModal(): void;\n\n /**\n * Show the Thank You modal\n *\n * @memberof DonationFlowModalManagerInterface\n */\n showThankYouModal(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void;\n\n /**\n * Show the Error modal\n *\n * @param {{\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @memberof DonationFlowModalManagerInterface\n */\n showErrorModal(options: { message: string; userClosedModalCallback?: () => void }): void;\n\n /**\n * Show the upsell modal\n *\n * @param {{\n * ctaMode?: UpsellModalCTAMode;\n * yesSelected?: (amount: number) => void;\n * noSelected?: () => void;\n * amountChanged?: (amount: number) => void;\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @returns {Promise<void>}\n * @memberof DonationFlowModalManagerInterface\n */\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void>;\n\n /**\n * Start the donation submission flow. This kicks off the \"main\" modal flow once the\n * user authorizes the donation through their payment provider, which provides\n * us the with the nonce used to complete the donation.\n *\n * @param {{\n * nonce: string;\n * paymentProvider: PaymentProvider;\n * donationInfo: DonationPaymentInfo;\n * billingInfo: BillingInfo;\n * customerInfo: CustomerInfo;\n * upsellOnetimeTransactionId?: string;\n * customerId?: string;\n * recaptchaToken?: string;\n * bin?: string; // first 6 digits of CC\n * binName?: string; // credit card bank name\n * }} options\n * @returns {(Promise<DonationResponse | undefined>)}\n * @memberof DonationFlowModalManagerInterface\n */\n startDonationSubmissionFlow(options: {\n nonce: string;\n paymentProvider: PaymentProvider;\n donationInfo: DonationPaymentInfo;\n billingInfo: BillingInfo;\n customerInfo: CustomerInfo;\n upsellOnetimeTransactionId?: string;\n customerId?: string;\n recaptchaToken?: string;\n bin?: string; // first 6 digits of CC\n binName?: string; // credit card bank name\n }): Promise<DonationResponse | undefined>;\n\n /**\n * Handle a successful donation response. This encapsulates the logic for the type of\n * donation that was made.\n * ie. If it was a one-time donation, show the upsell, if it was monthly do not.\n *\n * @param {DonationPaymentInfo} donationInfo\n * @param {SuccessResponse} response\n * @memberof DonationFlowModalManagerInterface\n */\n handleSuccessfulDonationResponse(\n donationInfo: DonationPaymentInfo,\n response: SuccessResponse,\n ): void;\n}\n\nexport class DonationFlowModalManager implements DonationFlowModalManagerInterface {\n private braintreeManager: BraintreeManagerInterface;\n\n private modalManager: ModalManagerInterface;\n\n private analytics: DonationControllerEventLoggerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n modalManager: ModalManagerInterface;\n analytics: DonationControllerEventLoggerInterface;\n }) {\n this.modalManager = options.modalManager;\n this.braintreeManager = options.braintreeManager;\n this.analytics = options.analytics;\n }\n\n /** @inheritdoc */\n closeModal(): void {\n this.modalManager.closeModal();\n }\n\n /** @inheritdoc */\n showProcessingModal(): void {\n const modalConfig = new ModalConfig({\n headerColor: ModalHeaderColor.Blue,\n showProcessingIndicator: true,\n closeOnBackdropClick: false,\n showCloseButton: false,\n processingImageMode: 'processing',\n title: html`\n Processing...\n `,\n });\n this.modalManager.showModal({ config: modalConfig });\n }\n\n /** @inheritdoc */\n showThankYouModal(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void {\n const modalConfig = new ModalConfig({\n showProcessingIndicator: true,\n processingImageMode: 'complete',\n headerColor: ModalHeaderColor.Green,\n title: html`\n Thank You!\n `,\n });\n this.modalManager.showModal({\n config: modalConfig,\n });\n\n // post analytic\n const selectedPayment = options.successResponse.paymentProvider.replace(/\\s+/g, '');\n let action = `Donated-${selectedPayment}`;\n if (options.upsellSuccessResponse) {\n action += `-upsell`;\n }\n const label = options.successResponse.donationType;\n this.analytics.logEventNoSampling(action, label);\n\n // post donation\n this.braintreeManager.donationSuccessful(options);\n }\n\n /** @inheritdoc */\n showErrorModal(options: { message: string; userClosedModalCallback?: () => void }): void {\n const modalConfig = new ModalConfig({\n headerColor: ModalHeaderColor.Red,\n title: html`\n Processing error\n `,\n headline: html`\n There's been a problem completing your donation.\n `,\n message: html`\n ${options?.message}\n `,\n });\n\n this.modalManager.showModal({\n config: modalConfig,\n userClosedModalCallback: options?.userClosedModalCallback,\n customModalContent: html`\n <donation-form-error-modal-content></donation-form-error-modal-content>\n `,\n });\n }\n\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void> {\n const confirmDonation = (): void => {\n options?.confirmDonationCB();\n };\n const cancelDonation = (): void => {\n options?.cancelDonationCB();\n };\n const modalTitle = options.donationType === DonationType.Upsell\n ? 'Confirm monthly donation'\n : 'Complete donation';\n\n const modalConfig = new ModalConfig({\n closeOnBackdropClick: false,\n headerColor: ModalHeaderColor.Green,\n title: html`${modalTitle}`,\n message: html`\n <confirm-donation-modal\n .amount=\"${options.amount}\"\n .currencyType=\"${options.currencyType}\"\n .donationType=\"${options.donationType}\"\n .confirmDonation=${confirmDonation}\n .cancelDonation=${cancelDonation}\n ></confirm-donation-modal>\n `,\n });\n return this.modalManager.showModal({\n config: modalConfig,\n userClosedModalCallback: cancelDonation\n });\n }\n\n /** @inheritdoc */\n showUpsellModal(options: {\n oneTimeAmount: number;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n ctaMode?: UpsellModalCTAMode;\n }): Promise<void> {\n const modalConfig = new ModalConfig({\n headerColor: ModalHeaderColor.Green,\n title: html`\n Donation received\n `,\n processingImageMode: 'complete',\n showProcessingIndicator: true,\n });\n\n const upsellAmount = DonationFlowModalManager.getDefaultUpsellAmount(options.oneTimeAmount);\n if (options.amountChanged) {\n options.amountChanged(upsellAmount);\n }\n\n const modalContent = html`\n <upsell-modal-content\n .amount=${upsellAmount}\n .yesButtonMode=${options?.ctaMode ?? UpsellModalCTAMode.YesButton}\n @yesSelected=${(e: CustomEvent): void =>\n options?.yesSelected ? options.yesSelected(e.detail.amount) : undefined}\n @noThanksSelected=${options?.noSelected}\n @amountChanged=${(e: CustomEvent): void =>\n options?.amountChanged ? options.amountChanged(e.detail.amount) : undefined}\n >\n <slot name=\"paypal-upsell-button\"></slot>\n </upsell-modal-content>\n `;\n return this.modalManager.showModal({\n config: modalConfig,\n customModalContent: modalContent,\n userClosedModalCallback: options?.userClosedModalCallback,\n });\n }\n\n /** @inheritdoc */\n async startDonationSubmissionFlow(options: {\n nonce: string;\n paymentProvider: PaymentProvider;\n donationInfo: DonationPaymentInfo;\n billingInfo: BillingInfo;\n customerInfo: CustomerInfo;\n upsellOnetimeTransactionId?: string;\n customerId?: string;\n recaptchaToken?: string;\n bin?: string; // first 6 digits of CC\n binName?: string; // credit card bank name\n }): Promise<DonationResponse | undefined> {\n this.showProcessingModal();\n\n try {\n const response = await this.braintreeManager.submitDonation(options);\n\n if (response.success) {\n this.handleSuccessfulDonationResponse(\n options.donationInfo,\n response.value as SuccessResponse,\n );\n return response;\n } else {\n const error = response.value as ErrorResponse;\n this.showErrorModal({\n message: error.message,\n });\n return response;\n }\n } catch (error) {\n this.showErrorModal({\n message: `${error}`,\n });\n console.error('error getting a response', error);\n return undefined;\n }\n }\n\n private async upsellModalYesSelected(\n oneTimeDonationResponse: SuccessResponse,\n amount: number,\n ): Promise<DonationResponse | undefined> {\n this.showProcessingModal();\n\n try {\n const response = await this.braintreeManager.submitUpsellDonation({\n oneTimeDonationResponse: oneTimeDonationResponse,\n amount: amount,\n });\n\n if (response.success) {\n this.completeUpsell({\n successResponse: oneTimeDonationResponse,\n upsellSuccessResponse: response.value as SuccessResponse,\n });\n } else {\n const error = response.value as ErrorResponse;\n this.showErrorModal({\n message: error.message,\n });\n }\n\n return response;\n } catch (error) {\n this.showErrorModal({\n message: `${error}`,\n });\n console.error('error getting a response', error);\n return undefined;\n }\n }\n\n private completeUpsell(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void {\n this.showThankYouModal(options);\n\n // post analytic\n const selectedPayment = options.successResponse.paymentProvider.replace(/\\s+/g, '');\n const action = `Donated-${selectedPayment}-upsell`;\n const label = options.successResponse.donationType;\n this.analytics.logEventNoSampling(action, label);\n\n this.braintreeManager.donationSuccessful(options);\n }\n\n static getDefaultUpsellAmount(oneTimeAmount: number): number {\n let amount = 5;\n\n if (oneTimeAmount <= 10) amount = 5;\n else if (oneTimeAmount > 10 && oneTimeAmount <= 25) amount = 10;\n else if (oneTimeAmount > 25 && oneTimeAmount <= 100) amount = 25;\n else if (oneTimeAmount > 100) amount = 50;\n\n return amount;\n }\n\n /** @inheritdoc */\n handleSuccessfulDonationResponse(\n donationInfo: DonationPaymentInfo,\n response: SuccessResponse,\n ): void {\n switch (donationInfo.donationType) {\n case DonationType.OneTime:\n this.showUpsellModal({\n oneTimeAmount: response.amount,\n yesSelected: (amount: number) => {\n this.upsellModalYesSelected(response, amount);\n },\n noSelected: () => {\n this.showThankYouModal({ successResponse: response });\n },\n userClosedModalCallback: () => {\n this.showThankYouModal({ successResponse: response });\n },\n });\n break;\n case DonationType.Monthly:\n this.showThankYouModal({ successResponse: response });\n break;\n // This case will never be reached, it is only here for completeness.\n // The upsell case gets handled in `modalYesSelected()` below\n case DonationType.Upsell:\n break;\n default:\n break;\n }\n }\n}\n"]}
@@ -96,9 +96,16 @@ export declare class PaymentFlowHandlers implements PaymentFlowHandlersInterface
96
96
  braintreeManager: BraintreeManagerInterface;
97
97
  modalManager: ModalManagerInterface;
98
98
  recaptchaManager: RecaptchaManagerInterface;
99
+ resources: {
100
+ analytics: {
101
+ logEvent: (action: string, label: string) => void;
102
+ logEventNoSampling: (action: string, label: string) => void;
103
+ };
104
+ };
99
105
  });
100
106
  private braintreeManager;
101
107
  private modalManager;
102
108
  private recaptchaManager;
103
109
  private donationFlowModalManager;
110
+ private resources;
104
111
  }
@@ -29,9 +29,11 @@ export class PaymentFlowHandlers {
29
29
  this.braintreeManager = options.braintreeManager;
30
30
  this.modalManager = options.modalManager;
31
31
  this.recaptchaManager = options.recaptchaManager;
32
+ this.resources = options.resources;
32
33
  this.donationFlowModalManager = new DonationFlowModalManager({
33
34
  braintreeManager: this.braintreeManager,
34
35
  modalManager: this.modalManager,
36
+ analytics: this.resources.analytics,
35
37
  });
36
38
  }
37
39
  startup() {
@@ -1 +1 @@
1
- {"version":3,"file":"payment-flow-handlers.js","sourceRoot":"","sources":["../../../src/payment-flow-handlers/payment-flow-handlers.ts"],"names":[],"mappings":";AAEA,OAAO,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ED,IAAI,CAAC,qBAAqB,GAAG,IAAI,oBAAoB,CAAC;YACpD,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;SACxD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;CA2BF","sourcesContent":["import { ModalManagerInterface } from '@internetarchive/modal-manager';\n\nimport {\n CreditCardFlowHandlerInterface,\n CreditCardFlowHandler,\n} from './handlers/creditcard-flow-handler';\nimport { PayPalFlowHandlerInterface, PayPalFlowHandler } from './handlers/paypal-flow-handler';\nimport { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';\nimport { RecaptchaManagerInterface } from '../recaptcha-manager/recaptcha-manager';\nimport {\n ApplePayFlowHandlerInterface,\n ApplePayFlowHandler,\n} from './handlers/applepay-flow-handler';\nimport { VenmoFlowHandlerInterface, VenmoFlowHandler } from './handlers/venmo-flow-handler';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from './donation-flow-modal-manager';\nimport {\n GooglePayFlowHandlerInterface,\n GooglePayFlowHandler,\n} from './handlers/googlepay-flow-handler';\nimport { UpsellModalCTAMode } from '../modals/upsell-modal-content';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\nexport interface PaymentFlowHandlersInterface {\n startup(): Promise<void>;\n /**\n * Show the upsell modal\n *\n * @param {{\n * ctaMode?: UpsellModalCTAMode;\n * yesSelected?: (amount: number) => void;\n * noSelected?: () => void;\n * amountChanged?: (amount: number) => void;\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @returns {Promise<void>}\n * @memberof DonationFlowModalManagerInterface\n */\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void>;\n\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void>;\n\n creditCardHandler: CreditCardFlowHandlerInterface | undefined;\n paypalHandler: PayPalFlowHandlerInterface | undefined;\n applePayHandler: ApplePayFlowHandlerInterface | undefined;\n venmoHandler: VenmoFlowHandlerInterface | undefined;\n googlePayHandler: GooglePayFlowHandlerInterface | undefined;\n}\n\n/**\n * This class is a container for all of the individual flow handlers.\n *\n * Flow Handlers are responsible for handling the provider-specific interactions between\n * the UI and the Data.\n *\n * For instance, when the user clicks on the \"Donate\" button for credit cards, we\n * pull in contact info from the form, trigger the recaptcha, tokenize the form,\n * submit, show the upsell, complete. The Credit Card Flow Handler is responsible for\n * managing that series of steps.\n *\n * For PayPal, the user initiates the payment from the PayPal button and once they're\n * done, we show the modal. The PayPal Flow Handler is responsible for handling that\n * series of events.\n *\n * @export\n * @class PaymentFlowHandlers\n * @implements {PaymentFlowHandlersInterface}\n */\nexport class PaymentFlowHandlers implements PaymentFlowHandlersInterface {\n async startup(): Promise<void> {\n this.venmoHandler?.startup();\n this.creditCardHandler?.startup();\n }\n\n /** @inheritdoc */\n async showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n return this.donationFlowModalManager.showUpsellModal(options);\n }\n\n /** @inheritdoc */\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void> {\n return this.donationFlowModalManager.showConfirmationStepModal(options);\n }\n\n get creditCardHandler(): CreditCardFlowHandlerInterface | undefined {\n if (this.creditCardHandlerCache) {\n return this.creditCardHandlerCache;\n }\n\n this.creditCardHandlerCache = new CreditCardFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n recaptchaManager: this.recaptchaManager,\n });\n\n return this.creditCardHandlerCache;\n }\n\n get paypalHandler(): PayPalFlowHandlerInterface | undefined {\n if (this.paypalHandlerCache) {\n return this.paypalHandlerCache;\n }\n\n this.paypalHandlerCache = new PayPalFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.paypalHandlerCache;\n }\n\n get applePayHandler(): ApplePayFlowHandlerInterface | undefined {\n if (this.applePayHandlerCache) {\n return this.applePayHandlerCache;\n }\n\n this.applePayHandlerCache = new ApplePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.applePayHandlerCache;\n }\n\n get venmoHandler(): VenmoFlowHandlerInterface | undefined {\n if (this.venmoHandlerCache) {\n return this.venmoHandlerCache;\n }\n\n this.venmoHandlerCache = new VenmoFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.venmoHandlerCache;\n }\n\n get googlePayHandler(): GooglePayFlowHandlerInterface | undefined {\n if (this.googlePayHandlerCache) {\n return this.googlePayHandlerCache;\n }\n\n this.googlePayHandlerCache = new GooglePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.googlePayHandlerCache;\n }\n\n private creditCardHandlerCache?: CreditCardFlowHandlerInterface;\n private paypalHandlerCache?: PayPalFlowHandlerInterface;\n private applePayHandlerCache?: ApplePayFlowHandlerInterface;\n private venmoHandlerCache?: VenmoFlowHandlerInterface;\n private googlePayHandlerCache?: GooglePayFlowHandlerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n modalManager: ModalManagerInterface;\n recaptchaManager: RecaptchaManagerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.modalManager = options.modalManager;\n this.recaptchaManager = options.recaptchaManager;\n\n this.donationFlowModalManager = new DonationFlowModalManager({\n braintreeManager: this.braintreeManager,\n modalManager: this.modalManager,\n });\n }\n\n private braintreeManager: BraintreeManagerInterface;\n private modalManager: ModalManagerInterface;\n private recaptchaManager: RecaptchaManagerInterface;\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n}\n"]}
1
+ {"version":3,"file":"payment-flow-handlers.js","sourceRoot":"","sources":["../../../src/payment-flow-handlers/payment-flow-handlers.ts"],"names":[],"mappings":";AAEA,OAAO,EAEL,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAA8B,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAG/F,OAAO,EAEL,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAA6B,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAEL,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,oBAAoB,GACrB,MAAM,mCAAmC,CAAC;AA2C3C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,mBAAmB;IAqG9B,YAAY,OAUX;QACC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEnC,IAAI,CAAC,wBAAwB,GAAG,IAAI,wBAAwB,CAAC;YAC3D,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS;SACpC,CAAC,CAAC;IACL,CAAC;IAzHK,OAAO;;;YACX,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,GAAG;YAC7B,MAAA,IAAI,CAAC,iBAAiB,0CAAE,OAAO,GAAG;;KACnC;IAED,kBAAkB;IACZ,eAAe,CAAC,OAOrB;;YACC,OAAO,I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AAiB,CAAC;SAC/B;QAED,IAAI,CAAC,iBAAiB,GAAG,IAAI,gBAAgB,CAAC;YAC5C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;SACxD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED,IAAI,gBAAgB;QAClB,IAAI,IAAI,CAAC,qBAAqB,EAAE;YAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC;SACnC;QAED,IAAI,CAAC,qBAAqB,GAAG,IAAI,oBAAoB,CAAC;YACpD,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;SACxD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;CAyCF","sourcesContent":["import { ModalManagerInterface } from '@internetarchive/modal-manager';\n\nimport {\n CreditCardFlowHandlerInterface,\n CreditCardFlowHandler,\n} from './handlers/creditcard-flow-handler';\nimport { PayPalFlowHandlerInterface, PayPalFlowHandler } from './handlers/paypal-flow-handler';\nimport { BraintreeManagerInterface } from '../braintree-manager/braintree-interfaces';\nimport { RecaptchaManagerInterface } from '../recaptcha-manager/recaptcha-manager';\nimport {\n ApplePayFlowHandlerInterface,\n ApplePayFlowHandler,\n} from './handlers/applepay-flow-handler';\nimport { VenmoFlowHandlerInterface, VenmoFlowHandler } from './handlers/venmo-flow-handler';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from './donation-flow-modal-manager';\nimport {\n GooglePayFlowHandlerInterface,\n GooglePayFlowHandler,\n} from './handlers/googlepay-flow-handler';\nimport { UpsellModalCTAMode } from '../modals/upsell-modal-content';\nimport { DonationType } from '@internetarchive/donation-form-data-models';\n\nexport interface PaymentFlowHandlersInterface {\n startup(): Promise<void>;\n /**\n * Show the upsell modal\n *\n * @param {{\n * ctaMode?: UpsellModalCTAMode;\n * yesSelected?: (amount: number) => void;\n * noSelected?: () => void;\n * amountChanged?: (amount: number) => void;\n * userClosedModalCallback?: () => void;\n * }} [options]\n * @returns {Promise<void>}\n * @memberof DonationFlowModalManagerInterface\n */\n showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void>;\n\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void>;\n\n creditCardHandler: CreditCardFlowHandlerInterface | undefined;\n paypalHandler: PayPalFlowHandlerInterface | undefined;\n applePayHandler: ApplePayFlowHandlerInterface | undefined;\n venmoHandler: VenmoFlowHandlerInterface | undefined;\n googlePayHandler: GooglePayFlowHandlerInterface | undefined;\n}\n\n/**\n * This class is a container for all of the individual flow handlers.\n *\n * Flow Handlers are responsible for handling the provider-specific interactions between\n * the UI and the Data.\n *\n * For instance, when the user clicks on the \"Donate\" button for credit cards, we\n * pull in contact info from the form, trigger the recaptcha, tokenize the form,\n * submit, show the upsell, complete. The Credit Card Flow Handler is responsible for\n * managing that series of steps.\n *\n * For PayPal, the user initiates the payment from the PayPal button and once they're\n * done, we show the modal. The PayPal Flow Handler is responsible for handling that\n * series of events.\n *\n * @export\n * @class PaymentFlowHandlers\n * @implements {PaymentFlowHandlersInterface}\n */\nexport class PaymentFlowHandlers implements PaymentFlowHandlersInterface {\n async startup(): Promise<void> {\n this.venmoHandler?.startup();\n this.creditCardHandler?.startup();\n }\n\n /** @inheritdoc */\n async showUpsellModal(options: {\n oneTimeAmount: number;\n ctaMode?: UpsellModalCTAMode;\n yesSelected?: (amount: number) => void;\n noSelected?: () => void;\n amountChanged?: (amount: number) => void;\n userClosedModalCallback?: () => void;\n }): Promise<void> {\n return this.donationFlowModalManager.showUpsellModal(options);\n }\n\n /** @inheritdoc */\n showConfirmationStepModal(options: {\n amount: number;\n donationType: DonationType;\n currencyType: string;\n confirmDonationCB: Function;\n cancelDonationCB: Function;\n }): Promise<void> {\n return this.donationFlowModalManager.showConfirmationStepModal(options);\n }\n\n get creditCardHandler(): CreditCardFlowHandlerInterface | undefined {\n if (this.creditCardHandlerCache) {\n return this.creditCardHandlerCache;\n }\n\n this.creditCardHandlerCache = new CreditCardFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n recaptchaManager: this.recaptchaManager,\n });\n\n return this.creditCardHandlerCache;\n }\n\n get paypalHandler(): PayPalFlowHandlerInterface | undefined {\n if (this.paypalHandlerCache) {\n return this.paypalHandlerCache;\n }\n\n this.paypalHandlerCache = new PayPalFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.paypalHandlerCache;\n }\n\n get applePayHandler(): ApplePayFlowHandlerInterface | undefined {\n if (this.applePayHandlerCache) {\n return this.applePayHandlerCache;\n }\n\n this.applePayHandlerCache = new ApplePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.applePayHandlerCache;\n }\n\n get venmoHandler(): VenmoFlowHandlerInterface | undefined {\n if (this.venmoHandlerCache) {\n return this.venmoHandlerCache;\n }\n\n this.venmoHandlerCache = new VenmoFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.venmoHandlerCache;\n }\n\n get googlePayHandler(): GooglePayFlowHandlerInterface | undefined {\n if (this.googlePayHandlerCache) {\n return this.googlePayHandlerCache;\n }\n\n this.googlePayHandlerCache = new GooglePayFlowHandler({\n braintreeManager: this.braintreeManager,\n donationFlowModalManager: this.donationFlowModalManager,\n });\n\n return this.googlePayHandlerCache;\n }\n\n private creditCardHandlerCache?: CreditCardFlowHandlerInterface;\n private paypalHandlerCache?: PayPalFlowHandlerInterface;\n private applePayHandlerCache?: ApplePayFlowHandlerInterface;\n private venmoHandlerCache?: VenmoFlowHandlerInterface;\n private googlePayHandlerCache?: GooglePayFlowHandlerInterface;\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n modalManager: ModalManagerInterface;\n recaptchaManager: RecaptchaManagerInterface;\n resources: {\n analytics: {\n logEvent: (action: string, label: string) => void;\n logEventNoSampling: (action: string, label: string) => void;\n };\n };\n }) {\n this.braintreeManager = options.braintreeManager;\n this.modalManager = options.modalManager;\n this.recaptchaManager = options.recaptchaManager;\n this.resources = options.resources;\n\n this.donationFlowModalManager = new DonationFlowModalManager({\n braintreeManager: this.braintreeManager,\n modalManager: this.modalManager,\n analytics: this.resources.analytics,\n });\n }\n\n private braintreeManager: BraintreeManagerInterface;\n private modalManager: ModalManagerInterface;\n private recaptchaManager: RecaptchaManagerInterface;\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n private resources: {\n analytics: {\n logEvent: (action: string, label: string) => void;\n logEventNoSampling: (action: string, label: string) => void;\n };\n };\n}\n"]}
@@ -5,4 +5,5 @@ export declare class MockAnalyticHandler implements AnalyticsHandlerInterface {
5
5
  callLabel?: string;
6
6
  callAdditionalEventParams?: object;
7
7
  send_event(category: string, action: string, label?: string, additionalEventParams?: object): void;
8
+ send_event_no_sampling(category: string, action: string, label?: string, additionalEventParams?: object): void;
8
9
  }
@@ -6,5 +6,12 @@ export class MockAnalyticHandler {
6
6
  this.callLabel = label;
7
7
  this.callAdditionalEventParams = additionalEventParams;
8
8
  }
9
+ // eslint-disable-next-line @typescript-eslint/camelcase
10
+ send_event_no_sampling(category, action, label, additionalEventParams) {
11
+ this.callCategory = category;
12
+ this.callAction = action;
13
+ this.callLabel = label;
14
+ this.callAdditionalEventParams = additionalEventParams;
15
+ }
9
16
  }
10
17
  //# sourceMappingURL=mock-analytics-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mock-analytics-handler.js","sourceRoot":"","sources":["../../../test/mocks/mock-analytics-handler.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAmB;IAM9B,wDAAwD;IACxD,UAAU,CACR,QAAgB,EAChB,MAAc,EACd,KAAc,EACd,qBAA8B;QAE9B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,yBAAyB,GAAG,qBAAqB,CAAC;IACzD,CAAC;CACF","sourcesContent":["import { AnalyticsHandlerInterface } from '../../src/@types/analytics-handler';\n\nexport class MockAnalyticHandler implements AnalyticsHandlerInterface {\n callCategory?: string;\n callAction?: string;\n callLabel?: string;\n callAdditionalEventParams?: object;\n\n // eslint-disable-next-line @typescript-eslint/camelcase\n send_event(\n category: string,\n action: string,\n label?: string,\n additionalEventParams?: object,\n ): void {\n this.callCategory = category;\n this.callAction = action;\n this.callLabel = label;\n this.callAdditionalEventParams = additionalEventParams;\n }\n}\n"]}
1
+ {"version":3,"file":"mock-analytics-handler.js","sourceRoot":"","sources":["../../../test/mocks/mock-analytics-handler.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAmB;IAM9B,wDAAwD;IACxD,UAAU,CACR,QAAgB,EAChB,MAAc,EACd,KAAc,EACd,qBAA8B;QAE9B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,yBAAyB,GAAG,qBAAqB,CAAC;IACzD,CAAC;IAED,wDAAwD;IACxD,sBAAsB,CACpB,QAAgB,EAChB,MAAc,EACd,KAAc,EACd,qBAA8B;QAE9B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,yBAAyB,GAAG,qBAAqB,CAAC;IACzD,CAAC;CACF","sourcesContent":["import { AnalyticsHandlerInterface } from '../../src/@types/analytics-handler';\n\nexport class MockAnalyticHandler implements AnalyticsHandlerInterface {\n callCategory?: string;\n callAction?: string;\n callLabel?: string;\n callAdditionalEventParams?: object;\n\n // eslint-disable-next-line @typescript-eslint/camelcase\n send_event(\n category: string,\n action: string,\n label?: string,\n additionalEventParams?: object,\n ): void {\n this.callCategory = category;\n this.callAction = action;\n this.callLabel = label;\n this.callAdditionalEventParams = additionalEventParams;\n }\n\n // eslint-disable-next-line @typescript-eslint/camelcase\n send_event_no_sampling(\n category: string,\n action: string,\n label?: string,\n additionalEventParams?: object,\n ): void {\n this.callCategory = category;\n this.callAction = action;\n this.callLabel = label;\n this.callAdditionalEventParams = additionalEventParams;\n }\n}\n"]}
@@ -9,8 +9,8 @@ import { MockPaymentClients } from '../mocks/mock-payment-clients';
9
9
  import { fillInContactForm } from '../helpers/fillInContactForm';
10
10
  import { promisedSleep } from '../../src/util/promisedSleep';
11
11
  import { MockModalManager } from '../mocks/mock-modal-manager';
12
- import { MockAnalyticHandler } from '../mocks/mock-analytics-handler';
13
12
  import { MockPaymentFlowHandlers } from '../mocks/flow-handlers/mock-payment-flow-handlers';
13
+ import { MockAnalyticsManager } from '@internetarchive/analytics-manager/dist/test/mock-analytics-manager';
14
14
  describe('Donation Form Controller', () => {
15
15
  beforeEach(() => {
16
16
  window['grecaptcha'] = new MockGrecaptcha(MockGrecaptchaMode.Success);
@@ -25,8 +25,8 @@ describe('Donation Form Controller', () => {
25
25
  expect(el.shadowRoot).to.equal(null);
26
26
  }));
27
27
  it('can submit a donation', () => __awaiter(void 0, void 0, void 0, function* () {
28
- var _a, _b, _c;
29
- const mockAnalytics = new MockAnalyticHandler();
28
+ var _a, _b, _c, _d;
29
+ const mockAnalytics = new MockAnalyticsManager();
30
30
  const controller = (yield fixture(html `
31
31
  <donation-form-controller .analyticsHandler=${mockAnalytics}> </donation-form-controller>
32
32
  `));
@@ -72,12 +72,13 @@ describe('Donation Form Controller', () => {
72
72
  const donateClickEvent = new MouseEvent('click');
73
73
  donateButton === null || donateButton === void 0 ? void 0 : donateButton.dispatchEvent(donateClickEvent);
74
74
  yield promisedSleep(100);
75
- expect(mockAnalytics.callAction).to.equal('PaymentFlowStarted');
75
+ expect((_d = mockAnalytics.sendEventOptions) === null || _d === void 0 ? void 0 : _d.action).to.equal('PaymentFlowStarted');
76
76
  // verify that a payload has been requested to be submitted to the backend
77
77
  expect(endpointManager.requestSubmitted).to.not.equal(undefined);
78
78
  }));
79
79
  it('sends Viewed analytics when it first updates', () => __awaiter(void 0, void 0, void 0, function* () {
80
- const mockAnalytics = new MockAnalyticHandler();
80
+ var _e, _f;
81
+ const mockAnalytics = new MockAnalyticsManager();
81
82
  const analyticsCategory = 'FooCategory';
82
83
  (yield fixture(html `
83
84
  <donation-form-controller
@@ -87,12 +88,12 @@ describe('Donation Form Controller', () => {
87
88
  >
88
89
  </donation-form-controller>
89
90
  `));
90
- expect(mockAnalytics.callCategory).to.equal(analyticsCategory);
91
- expect(mockAnalytics.callAction).to.equal('Viewed');
91
+ expect((_e = mockAnalytics.sendEventOptions) === null || _e === void 0 ? void 0 : _e.category).to.equal(analyticsCategory);
92
+ expect((_f = mockAnalytics.sendEventOptions) === null || _f === void 0 ? void 0 : _f.action).to.equal('Viewed');
92
93
  }));
93
94
  it('sends DonationInfoChanged analytics when donation info changes', () => __awaiter(void 0, void 0, void 0, function* () {
94
- var _d, _e, _f;
95
- const mockAnalytics = new MockAnalyticHandler();
95
+ var _g, _h, _j, _k, _l;
96
+ const mockAnalytics = new MockAnalyticsManager();
96
97
  const analyticsCategory = 'FooCategory';
97
98
  const controller = (yield fixture(html `
98
99
  <donation-form-controller
@@ -103,17 +104,17 @@ describe('Donation Form Controller', () => {
103
104
  </donation-form-controller>
104
105
  `));
105
106
  const donationForm = controller.querySelector('donation-form');
106
- const donationHeader = (_d = donationForm.shadowRoot) === null || _d === void 0 ? void 0 : _d.querySelector('donation-form-header');
107
- const editDonation = (_e = donationHeader === null || donationHeader === void 0 ? void 0 : donationHeader.shadowRoot) === null || _e === void 0 ? void 0 : _e.querySelector('donation-form-edit-donation');
108
- const monthlyOption = (_f = editDonation === null || editDonation === void 0 ? void 0 : editDonation.shadowRoot) === null || _f === void 0 ? void 0 : _f.querySelector('#donationType-monthly-option');
107
+ const donationHeader = (_g = donationForm.shadowRoot) === null || _g === void 0 ? void 0 : _g.querySelector('donation-form-header');
108
+ const editDonation = (_h = donationHeader === null || donationHeader === void 0 ? void 0 : donationHeader.shadowRoot) === null || _h === void 0 ? void 0 : _h.querySelector('donation-form-edit-donation');
109
+ const monthlyOption = (_j = editDonation === null || editDonation === void 0 ? void 0 : editDonation.shadowRoot) === null || _j === void 0 ? void 0 : _j.querySelector('#donationType-monthly-option');
109
110
  const clickEvent = new MouseEvent('click');
110
111
  monthlyOption === null || monthlyOption === void 0 ? void 0 : monthlyOption.dispatchEvent(clickEvent);
111
- expect(mockAnalytics.callCategory).to.equal(analyticsCategory);
112
- expect(mockAnalytics.callAction).to.equal('DonationInfoChanged');
112
+ expect((_k = mockAnalytics.sendEventOptions) === null || _k === void 0 ? void 0 : _k.category).to.equal(analyticsCategory);
113
+ expect((_l = mockAnalytics.sendEventOptions) === null || _l === void 0 ? void 0 : _l.action).to.equal('DonationInfoChanged');
113
114
  }));
114
115
  it('sends ProviderSelected analytics', () => __awaiter(void 0, void 0, void 0, function* () {
115
- var _g, _h, _j;
116
- const mockAnalytics = new MockAnalyticHandler();
116
+ var _m, _o, _p, _q, _r;
117
+ const mockAnalytics = new MockAnalyticsManager();
117
118
  const analyticsCategory = 'FooCategory';
118
119
  const controller = (yield fixture(html `
119
120
  <donation-form-controller
@@ -124,26 +125,27 @@ describe('Donation Form Controller', () => {
124
125
  </donation-form-controller>
125
126
  `));
126
127
  const donationForm = controller.querySelector('donation-form');
127
- const paymentSelector = (_g = donationForm.shadowRoot) === null || _g === void 0 ? void 0 : _g.querySelector('payment-selector');
128
+ const paymentSelector = (_m = donationForm.shadowRoot) === null || _m === void 0 ? void 0 : _m.querySelector('payment-selector');
128
129
  // on the first payment provider chosen, the previousPaymentProvider is undefined
129
- const creditCardButton = (_h = paymentSelector.shadowRoot) === null || _h === void 0 ? void 0 : _h.querySelector('.credit-card-button');
130
+ const creditCardButton = (_o = paymentSelector.shadowRoot) === null || _o === void 0 ? void 0 : _o.querySelector('.credit-card-button');
130
131
  setTimeout(() => {
131
132
  const ccClickEvent = new MouseEvent('click');
132
133
  creditCardButton.dispatchEvent(ccClickEvent);
133
134
  });
134
135
  yield oneEvent(donationForm, 'paymentProviderSelected');
135
- expect(mockAnalytics.callAction).to.equal('ProviderFirstSelected-CreditCard');
136
+ expect((_p = mockAnalytics.sendEventOptions) === null || _p === void 0 ? void 0 : _p.action).to.equal('ProviderFirstSelected-CreditCard');
136
137
  // on subsequent payment provider choices, the previousPaymentProvider is populated
137
- const venmoButton = (_j = paymentSelector.shadowRoot) === null || _j === void 0 ? void 0 : _j.querySelector('.venmo');
138
+ const venmoButton = (_q = paymentSelector.shadowRoot) === null || _q === void 0 ? void 0 : _q.querySelector('.venmo');
138
139
  setTimeout(() => {
139
140
  const venmoClickEvent = new MouseEvent('click');
140
141
  venmoButton.dispatchEvent(venmoClickEvent);
141
142
  });
142
143
  yield oneEvent(donationForm, 'paymentProviderSelected');
143
- expect(mockAnalytics.callAction).to.equal('ProviderChangedTo-Venmo');
144
+ expect((_r = mockAnalytics.sendEventOptions) === null || _r === void 0 ? void 0 : _r.action).to.equal('ProviderChangedTo-Venmo');
144
145
  }));
145
146
  it('sends PaymentFlowCancelled analytics', () => __awaiter(void 0, void 0, void 0, function* () {
146
- const mockAnalytics = new MockAnalyticHandler();
147
+ var _s, _t;
148
+ const mockAnalytics = new MockAnalyticsManager();
147
149
  const analyticsCategory = 'FooCategory';
148
150
  const controller = (yield fixture(html `
149
151
  <donation-form-controller
@@ -159,11 +161,12 @@ describe('Donation Form Controller', () => {
159
161
  yield elementUpdated(donationForm);
160
162
  yield promisedSleep(250);
161
163
  flowHandlers.paypalHandler.emitPaymentCancelledEvent();
162
- expect(mockAnalytics.callAction).to.equal('PaymentFlowCancelled');
163
- expect(mockAnalytics.callLabel).to.equal('PayPal');
164
+ expect((_s = mockAnalytics.sendEventOptions) === null || _s === void 0 ? void 0 : _s.action).to.equal('PaymentFlowCancelled');
165
+ expect((_t = mockAnalytics.sendEventOptions) === null || _t === void 0 ? void 0 : _t.label).to.equal('PayPal');
164
166
  }));
165
167
  it('sends PaymentFlowError analytics', () => __awaiter(void 0, void 0, void 0, function* () {
166
- const mockAnalytics = new MockAnalyticHandler();
168
+ var _u, _v;
169
+ const mockAnalytics = new MockAnalyticsManager();
167
170
  const analyticsCategory = 'FooCategory';
168
171
  const controller = (yield fixture(html `
169
172
  <donation-form-controller
@@ -179,8 +182,8 @@ describe('Donation Form Controller', () => {
179
182
  yield elementUpdated(donationForm);
180
183
  yield promisedSleep(250);
181
184
  flowHandlers.paypalHandler.emitPaymentErrorEvent();
182
- expect(mockAnalytics.callAction).to.equal('PaymentFlowError');
183
- expect(mockAnalytics.callLabel).to.equal('PayPal-foo-error');
185
+ expect((_u = mockAnalytics.sendEventOptions) === null || _u === void 0 ? void 0 : _u.action).to.equal('PaymentFlowError');
186
+ expect((_v = mockAnalytics.sendEventOptions) === null || _v === void 0 ? void 0 : _v.label).to.equal('PayPal-foo-error');
184
187
  }));
185
188
  });
186
189
  //# sourceMappingURL=donation-form-controller.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"donation-form-controller.test.js","sourceRoot":"","sources":["../../../test/tests/donation-form-controller.test.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,oCAAoC,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9F,O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GAAG,IAAI,uBAAuB,EAAE,CAAC;QACnD,YAAY,CAAC,mBAAmB,GAAG,YAAY,CAAC;QAChD,MAAM,cAAc,CAAC,YAAY,CAAC,CAAC;QACnC,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;QACzB,YAAY,CAAC,aAAa,CAAC,qBAAqB,EAAE,CAAC;QACnD,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC9D,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC/D,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { html, fixture, expect, elementUpdated, oneEvent } from '@open-wc/testing';\n\nimport '../../src/donation-form-controller';\nimport { DonationFormController } from '../../src/donation-form-controller';\nimport { MockGrecaptcha, MockGrecaptchaMode } from '../mocks/payment-clients/mock-grecaptcha';\nimport { HostingEnvironment } from '../../src/braintree-manager/braintree-interfaces';\nimport { MockEndpointManager } from '../mocks/mock-endpoint-manager';\nimport { MockPaymentClients } from '../mocks/mock-payment-clients';\nimport { ContactForm } from '../../src/form-elements/contact-form/contact-form';\nimport { fillInContactForm } from '../helpers/fillInContactForm';\nimport { promisedSleep } from '../../src/util/promisedSleep';\nimport { MockModalManager } from '../mocks/mock-modal-manager';\nimport { MockHostedFieldsClient } from '../mocks/payment-clients/mock-hostedfields-client';\nimport { DonationForm } from '../../src/donation-form';\nimport { PaymentSelector } from '../../src/form-elements/payment-selector';\nimport { MockAnalyticHandler } from '../mocks/mock-analytics-handler';\nimport { DonationFormHeader } from '../../src/form-elements/header/donation-form-header';\nimport { DonationFormEditDonation } from '@internetarchive/donation-form-edit-donation';\nimport { MockPaymentFlowHandlers } from '../mocks/flow-handlers/mock-payment-flow-handlers';\n\ndescribe('Donation Form Controller', () => {\n beforeEach(() => {\n (window['grecaptcha' as any] as any) = new MockGrecaptcha(MockGrecaptchaMode.Success);\n });\n\n afterEach(() => {\n delete window['grecaptcha' as any];\n });\n\n it('has no shadowRoot', async () => {\n const el = (await fixture(html`\n <donation-form-controller></donation-form-controller>\n `)) as DonationFormController;\n\n expect(el.shadowRoot).to.equal(null);\n });\n\n it('can submit a donation', async () => {\n const mockAnalytics = new MockAnalyticHandler();\n const controller = (await fixture(html`\n <donation-form-controller .analyticsHandler=${mockAnalytics}> </donation-form-controller>\n `)) as DonationFormController;\n\n // configure the donation-form-controller\n const recaptchaElement = (await fixture(\n html`\n <div></div>\n `,\n )) as HTMLElement;\n const endpointManager = new MockEndpointManager();\n const paymentClients = new MockPaymentClients();\n const modalManager = new MockModalManager();\n controller.paymentClients = paymentClients;\n controller.modalManager = modalManager;\n controller.environment = HostingEnvironment.Development;\n controller.recaptchaElement = recaptchaElement;\n controller.endpointManager = endpointManager;\n controller.braintreeAuthToken = 'foo';\n controller.recaptchaSiteKey = 'bar';\n controller.venmoProfileId = 'baz';\n controller.referrer = 'test-referrer';\n controller.loggedInUser = 'test-user';\n\n // grab some internal elements to interact with\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const paymentSelector: PaymentSelector = donationForm?.shadowRoot?.querySelector(\n 'payment-selector',\n ) as PaymentSelector;\n const creditCardButton = paymentSelector?.shadowRoot?.querySelector('.credit-card-button');\n\n // click on the credit card button\n const ccClickEvent = new MouseEvent('click');\n creditCardButton?.dispatchEvent(ccClickEvent);\n\n // clicking on the credit card button will show the contact form so wait for it to be updated\n await elementUpdated(donationForm);\n await promisedSleep(100);\n const contactForm = document.querySelector('contact-form') as ContactForm;\n await fillInContactForm(contactForm);\n\n // verify the Donate button is still disabled\n const donateButton = donationForm?.shadowRoot?.querySelector(\n '#donate-button',\n ) as HTMLButtonElement;\n\n // simulates after the user has input all of the credit card fields\n const hostedFields = (await paymentClients.hostedFields.get()) as MockHostedFieldsClient;\n hostedFields.emitValidityChangedEvent(true);\n await promisedSleep(100);\n\n // verify that the donate button has become enabled and no request has been submitted\n expect(donateButton.disabled).to.equal(false);\n expect(endpointManager.requestSubmitted).to.equal(undefined);\n\n // click the donate button\n const donateClickEvent = new MouseEvent('click');\n donateButton?.dispatchEvent(donateClickEvent);\n await promisedSleep(100);\n\n expect(mockAnalytics.callAction).to.equal('PaymentFlowStarted');\n\n // verify that a payload has been requested to be submitted to the backend\n expect(endpointManager.requestSubmitted).to.not.equal(undefined);\n });\n\n it('sends Viewed analytics when it first updates', async () => {\n const mockAnalytics = new MockAnalyticHandler();\n const analyticsCategory = 'FooCategory';\n (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n expect(mockAnalytics.callCategory).to.equal(analyticsCategory);\n expect(mockAnalytics.callAction).to.equal('Viewed');\n });\n\n it('sends DonationInfoChanged analytics when donation info changes', async () => {\n const mockAnalytics = new MockAnalyticHandler();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const donationHeader = donationForm.shadowRoot?.querySelector(\n 'donation-form-header',\n ) as DonationFormHeader;\n const editDonation = donationHeader?.shadowRoot?.querySelector(\n 'donation-form-edit-donation',\n ) as DonationFormEditDonation;\n const monthlyOption = editDonation?.shadowRoot?.querySelector('#donationType-monthly-option');\n const clickEvent = new MouseEvent('click');\n monthlyOption?.dispatchEvent(clickEvent);\n\n expect(mockAnalytics.callCategory).to.equal(analyticsCategory);\n expect(mockAnalytics.callAction).to.equal('DonationInfoChanged');\n });\n\n it('sends ProviderSelected analytics', async () => {\n const mockAnalytics = new MockAnalyticHandler();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const paymentSelector = donationForm.shadowRoot?.querySelector(\n 'payment-selector',\n ) as PaymentSelector;\n\n // on the first payment provider chosen, the previousPaymentProvider is undefined\n const creditCardButton = paymentSelector.shadowRoot?.querySelector(\n '.credit-card-button',\n ) as HTMLButtonElement;\n setTimeout(() => {\n const ccClickEvent = new MouseEvent('click');\n creditCardButton.dispatchEvent(ccClickEvent);\n });\n await oneEvent(donationForm, 'paymentProviderSelected');\n expect(mockAnalytics.callAction).to.equal('ProviderFirstSelected-CreditCard');\n\n // on subsequent payment provider choices, the previousPaymentProvider is populated\n const venmoButton = paymentSelector.shadowRoot?.querySelector('.venmo') as HTMLButtonElement;\n setTimeout(() => {\n const venmoClickEvent = new MouseEvent('click');\n venmoButton.dispatchEvent(venmoClickEvent);\n });\n await oneEvent(donationForm, 'paymentProviderSelected');\n expect(mockAnalytics.callAction).to.equal('ProviderChangedTo-Venmo');\n });\n\n it('sends PaymentFlowCancelled analytics', async () => {\n const mockAnalytics = new MockAnalyticHandler();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const flowHandlers = new MockPaymentFlowHandlers();\n donationForm.paymentFlowHandlers = flowHandlers;\n await elementUpdated(donationForm);\n await promisedSleep(250);\n flowHandlers.paypalHandler.emitPaymentCancelledEvent();\n expect(mockAnalytics.callAction).to.equal('PaymentFlowCancelled');\n expect(mockAnalytics.callLabel).to.equal('PayPal');\n });\n\n it('sends PaymentFlowError analytics', async () => {\n const mockAnalytics = new MockAnalyticHandler();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const flowHandlers = new MockPaymentFlowHandlers();\n donationForm.paymentFlowHandlers = flowHandlers;\n await elementUpdated(donationForm);\n await promisedSleep(250);\n flowHandlers.paypalHandler.emitPaymentErrorEvent();\n expect(mockAnalytics.callAction).to.equal('PaymentFlowError');\n expect(mockAnalytics.callLabel).to.equal('PayPal-foo-error');\n });\n});\n"]}
1
+ {"version":3,"file":"donation-form-controller.test.js","sourceRoot":"","sources":["../../../test/tests/donation-form-controller.test.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,oCAAoC,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,kDAAkD,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAM/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,qEAAqE,CAAC;AAE3G,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,UAAU,C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,OAAC,aAAa,CAAC,gBAAgB,0CAAE,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC7E,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { html, fixture, expect, elementUpdated, oneEvent } from '@open-wc/testing';\n\nimport '../../src/donation-form-controller';\nimport { DonationFormController } from '../../src/donation-form-controller';\nimport { MockGrecaptcha, MockGrecaptchaMode } from '../mocks/payment-clients/mock-grecaptcha';\nimport { HostingEnvironment } from '../../src/braintree-manager/braintree-interfaces';\nimport { MockEndpointManager } from '../mocks/mock-endpoint-manager';\nimport { MockPaymentClients } from '../mocks/mock-payment-clients';\nimport { ContactForm } from '../../src/form-elements/contact-form/contact-form';\nimport { fillInContactForm } from '../helpers/fillInContactForm';\nimport { promisedSleep } from '../../src/util/promisedSleep';\nimport { MockModalManager } from '../mocks/mock-modal-manager';\nimport { MockHostedFieldsClient } from '../mocks/payment-clients/mock-hostedfields-client';\nimport { DonationForm } from '../../src/donation-form';\nimport { PaymentSelector } from '../../src/form-elements/payment-selector';\nimport { DonationFormHeader } from '../../src/form-elements/header/donation-form-header';\nimport { DonationFormEditDonation } from '@internetarchive/donation-form-edit-donation';\nimport { MockPaymentFlowHandlers } from '../mocks/flow-handlers/mock-payment-flow-handlers';\nimport { MockAnalyticsManager } from '@internetarchive/analytics-manager/dist/test/mock-analytics-manager';\n\ndescribe('Donation Form Controller', () => {\n beforeEach(() => {\n (window['grecaptcha' as any] as any) = new MockGrecaptcha(MockGrecaptchaMode.Success);\n });\n\n afterEach(() => {\n delete window['grecaptcha' as any];\n });\n\n it('has no shadowRoot', async () => {\n const el = (await fixture(html`\n <donation-form-controller></donation-form-controller>\n `)) as DonationFormController;\n\n expect(el.shadowRoot).to.equal(null);\n });\n\n it('can submit a donation', async () => {\n const mockAnalytics = new MockAnalyticsManager();\n const controller = (await fixture(html`\n <donation-form-controller .analyticsHandler=${mockAnalytics}> </donation-form-controller>\n `)) as DonationFormController;\n\n // configure the donation-form-controller\n const recaptchaElement = (await fixture(\n html`\n <div></div>\n `,\n )) as HTMLElement;\n const endpointManager = new MockEndpointManager();\n const paymentClients = new MockPaymentClients();\n const modalManager = new MockModalManager();\n controller.paymentClients = paymentClients;\n controller.modalManager = modalManager;\n controller.environment = HostingEnvironment.Development;\n controller.recaptchaElement = recaptchaElement;\n controller.endpointManager = endpointManager;\n controller.braintreeAuthToken = 'foo';\n controller.recaptchaSiteKey = 'bar';\n controller.venmoProfileId = 'baz';\n controller.referrer = 'test-referrer';\n controller.loggedInUser = 'test-user';\n\n // grab some internal elements to interact with\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const paymentSelector: PaymentSelector = donationForm?.shadowRoot?.querySelector(\n 'payment-selector',\n ) as PaymentSelector;\n const creditCardButton = paymentSelector?.shadowRoot?.querySelector('.credit-card-button');\n\n // click on the credit card button\n const ccClickEvent = new MouseEvent('click');\n creditCardButton?.dispatchEvent(ccClickEvent);\n\n // clicking on the credit card button will show the contact form so wait for it to be updated\n await elementUpdated(donationForm);\n await promisedSleep(100);\n const contactForm = document.querySelector('contact-form') as ContactForm;\n await fillInContactForm(contactForm);\n\n // verify the Donate button is still disabled\n const donateButton = donationForm?.shadowRoot?.querySelector(\n '#donate-button',\n ) as HTMLButtonElement;\n\n // simulates after the user has input all of the credit card fields\n const hostedFields = (await paymentClients.hostedFields.get()) as MockHostedFieldsClient;\n hostedFields.emitValidityChangedEvent(true);\n await promisedSleep(100);\n\n // verify that the donate button has become enabled and no request has been submitted\n expect(donateButton.disabled).to.equal(false);\n expect(endpointManager.requestSubmitted).to.equal(undefined);\n\n // click the donate button\n const donateClickEvent = new MouseEvent('click');\n donateButton?.dispatchEvent(donateClickEvent);\n await promisedSleep(100);\n\n expect(mockAnalytics.sendEventOptions?.action).to.equal('PaymentFlowStarted');\n\n // verify that a payload has been requested to be submitted to the backend\n expect(endpointManager.requestSubmitted).to.not.equal(undefined);\n });\n\n it('sends Viewed analytics when it first updates', async () => {\n const mockAnalytics = new MockAnalyticsManager();\n const analyticsCategory = 'FooCategory';\n (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n expect(mockAnalytics.sendEventOptions?.category).to.equal(analyticsCategory);\n expect(mockAnalytics.sendEventOptions?.action).to.equal('Viewed');\n });\n\n it('sends DonationInfoChanged analytics when donation info changes', async () => {\n const mockAnalytics = new MockAnalyticsManager();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const donationHeader = donationForm.shadowRoot?.querySelector(\n 'donation-form-header',\n ) as DonationFormHeader;\n const editDonation = donationHeader?.shadowRoot?.querySelector(\n 'donation-form-edit-donation',\n ) as DonationFormEditDonation;\n const monthlyOption = editDonation?.shadowRoot?.querySelector('#donationType-monthly-option');\n const clickEvent = new MouseEvent('click');\n monthlyOption?.dispatchEvent(clickEvent);\n\n expect(mockAnalytics.sendEventOptions?.category).to.equal(analyticsCategory);\n expect(mockAnalytics.sendEventOptions?.action).to.equal('DonationInfoChanged');\n });\n\n it('sends ProviderSelected analytics', async () => {\n const mockAnalytics = new MockAnalyticsManager();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const paymentSelector = donationForm.shadowRoot?.querySelector(\n 'payment-selector',\n ) as PaymentSelector;\n\n // on the first payment provider chosen, the previousPaymentProvider is undefined\n const creditCardButton = paymentSelector.shadowRoot?.querySelector(\n '.credit-card-button',\n ) as HTMLButtonElement;\n setTimeout(() => {\n const ccClickEvent = new MouseEvent('click');\n creditCardButton.dispatchEvent(ccClickEvent);\n });\n await oneEvent(donationForm, 'paymentProviderSelected');\n expect(mockAnalytics.sendEventOptions?.action).to.equal('ProviderFirstSelected-CreditCard');\n\n // on subsequent payment provider choices, the previousPaymentProvider is populated\n const venmoButton = paymentSelector.shadowRoot?.querySelector('.venmo') as HTMLButtonElement;\n setTimeout(() => {\n const venmoClickEvent = new MouseEvent('click');\n venmoButton.dispatchEvent(venmoClickEvent);\n });\n await oneEvent(donationForm, 'paymentProviderSelected');\n expect(mockAnalytics.sendEventOptions?.action).to.equal('ProviderChangedTo-Venmo');\n });\n\n it('sends PaymentFlowCancelled analytics', async () => {\n const mockAnalytics = new MockAnalyticsManager();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const flowHandlers = new MockPaymentFlowHandlers();\n donationForm.paymentFlowHandlers = flowHandlers;\n await elementUpdated(donationForm);\n await promisedSleep(250);\n flowHandlers.paypalHandler.emitPaymentCancelledEvent();\n expect(mockAnalytics.sendEventOptions?.action).to.equal('PaymentFlowCancelled');\n expect(mockAnalytics.sendEventOptions?.label).to.equal('PayPal');\n });\n\n it('sends PaymentFlowError analytics', async () => {\n const mockAnalytics = new MockAnalyticsManager();\n const analyticsCategory = 'FooCategory';\n const controller = (await fixture(html`\n <donation-form-controller\n ?showCreditCardButtonText=${true}\n .analyticsCategory=${analyticsCategory}\n .analyticsHandler=${mockAnalytics}\n >\n </donation-form-controller>\n `)) as DonationFormController;\n\n const donationForm: DonationForm = controller.querySelector('donation-form') as DonationForm;\n const flowHandlers = new MockPaymentFlowHandlers();\n donationForm.paymentFlowHandlers = flowHandlers;\n await elementUpdated(donationForm);\n await promisedSleep(250);\n flowHandlers.paypalHandler.emitPaymentErrorEvent();\n expect(mockAnalytics.sendEventOptions?.action).to.equal('PaymentFlowError');\n expect(mockAnalytics.sendEventOptions?.label).to.equal('PayPal-foo-error');\n });\n});\n"]}
@@ -8,7 +8,18 @@ import { mockSuccessResponse } from '../../mocks/models/mock-success-response';
8
8
  import { PaymentProvider, DonationPaymentInfo, DonationType, } from '@internetarchive/donation-form-data-models';
9
9
  import { mockBillingInfo } from '../../mocks/models/mock-billing-info';
10
10
  import { mockCustomerInfo } from '../../mocks/models/mock-customer-info';
11
+ import sinon from 'sinon';
12
+ let analytics;
11
13
  describe('Donation Flow Modal Manager', () => {
14
+ beforeEach(() => {
15
+ analytics = {
16
+ logEvent: sinon.fake(),
17
+ logEventNoSampling: sinon.fake(),
18
+ };
19
+ });
20
+ afterEach(() => {
21
+ sinon.restore();
22
+ });
12
23
  it('can close the modal', () => __awaiter(void 0, void 0, void 0, function* () {
13
24
  const mockModalManager = (yield fixture(html `
14
25
  <mock-modal-manager></mock-modal-manager>
@@ -17,6 +28,7 @@ describe('Donation Flow Modal Manager', () => {
17
28
  const manager = new DonationFlowModalManager({
18
29
  braintreeManager: mockBraintreeManager,
19
30
  modalManager: mockModalManager,
31
+ analytics
20
32
  });
21
33
  manager.closeModal();
22
34
  expect(mockModalManager.closeCalled).to.be.true;
@@ -46,6 +58,7 @@ describe('Donation Flow Modal Manager', () => {
46
58
  const manager = new DonationFlowModalManager({
47
59
  braintreeManager: mockBraintreeManager,
48
60
  modalManager: mockModalManager,
61
+ analytics
49
62
  });
50
63
  manager.showProcessingModal();
51
64
  const modalOptions = mockModalManager.showModalOptions;
@@ -65,6 +78,7 @@ describe('Donation Flow Modal Manager', () => {
65
78
  const manager = new DonationFlowModalManager({
66
79
  braintreeManager: mockBraintreeManager,
67
80
  modalManager: mockModalManager,
81
+ analytics
68
82
  });
69
83
  manager.showErrorModal({ message: 'foo-error' });
70
84
  const modalOptions = mockModalManager.showModalOptions;
@@ -81,9 +95,15 @@ describe('Donation Flow Modal Manager', () => {
81
95
  <mock-modal-manager></mock-modal-manager>
82
96
  `));
83
97
  const mockBraintreeManager = new MockBraintreeManager();
98
+ const logEvent = sinon.fake();
99
+ const logEventNoSampling = sinon.fake();
84
100
  const manager = new DonationFlowModalManager({
85
101
  braintreeManager: mockBraintreeManager,
86
102
  modalManager: mockModalManager,
103
+ analytics: {
104
+ logEvent,
105
+ logEventNoSampling,
106
+ }
87
107
  });
88
108
  manager.showThankYouModal({
89
109
  successResponse: mockSuccessResponse,
@@ -98,6 +118,31 @@ describe('Donation Flow Modal Manager', () => {
98
118
  const response = (_e = mockBraintreeManager.donationSuccessfulOptions) === null || _e === void 0 ? void 0 : _e.successResponse;
99
119
  expect(response).to.deep.equal(mockSuccessResponse);
100
120
  }));
121
+ it('donation submitted analytics gets sent when drawing thank you modal', () => __awaiter(void 0, void 0, void 0, function* () {
122
+ const mockModalManager = (yield fixture(html `
123
+ <mock-modal-manager></mock-modal-manager>
124
+ `));
125
+ const mockBraintreeManager = new MockBraintreeManager();
126
+ const logEvent = sinon.fake();
127
+ const logEventNoSampling = sinon.fake();
128
+ const manager = new DonationFlowModalManager({
129
+ braintreeManager: mockBraintreeManager,
130
+ modalManager: mockModalManager,
131
+ analytics: {
132
+ logEvent,
133
+ logEventNoSampling,
134
+ }
135
+ });
136
+ const successResponse = mockSuccessResponse;
137
+ successResponse.paymentProvider = PaymentProvider.GooglePay;
138
+ manager.showThankYouModal({
139
+ successResponse: mockSuccessResponse,
140
+ });
141
+ // fires analytics
142
+ expect(logEventNoSampling.callCount).to.equal(1);
143
+ expect(logEventNoSampling.args[0][0]).to.equal(`Donated-GooglePay`);
144
+ expect(logEventNoSampling.args[0][1]).to.equal(DonationType.OneTime);
145
+ }));
101
146
  it('can show the confirmation modal', () => __awaiter(void 0, void 0, void 0, function* () {
102
147
  var _f, _g;
103
148
  const mockModalManager = (yield fixture(html `
@@ -107,6 +152,7 @@ describe('Donation Flow Modal Manager', () => {
107
152
  const manager = new DonationFlowModalManager({
108
153
  braintreeManager: mockBraintreeManager,
109
154
  modalManager: mockModalManager,
155
+ analytics
110
156
  });
111
157
  manager.showConfirmationStepModal({
112
158
  donationType: DonationType.Upsell,
@@ -129,6 +175,7 @@ describe('Donation Flow Modal Manager', () => {
129
175
  const manager = new DonationFlowModalManager({
130
176
  braintreeManager: mockBraintreeManager,
131
177
  modalManager: mockModalManager,
178
+ analytics
132
179
  });
133
180
  const result = yield manager.startDonationSubmissionFlow({
134
181
  nonce: 'foo',
@@ -1 +1 @@
1
- {"version":3,"file":"donation-flow-modal-manager.test.js","sourceRoot":"","sources":["../../../../test/tests/flow-handlers/donation-flow-modal-manager.test.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gEAAgE,CAAC;AAE1G,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAGzE,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,EAAE,CAAC,qBAAqB,EAAE,GAAS,EAAE;QACnC,MAAM,gBAAgB,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAA;;KAE3C,CAAC,CAAqB,CAAC;QACxB,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,E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AAe;oBACzB,UAAU,EAAE,OAAO;oBACnB,MAAM,EAAE,IAAI;oBACZ,aAAa,EAAE,aAAa;iBAC7B;gBACD,QAAQ,EAAE;oBACR,KAAK,EAAE,aAAa;oBACpB,SAAS,EAAE,OAAO;oBAClB,QAAQ,EAAE,YAAY;iBACvB;gBACD,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,UAAU;gBACxB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,aAAa;gBAC9B,cAAc,EAAE,KAAK;aACtB;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/camelcase */\nimport { html, fixture, expect } from '@open-wc/testing';\nimport { DonationFlowModalManager } from '../../../src/payment-flow-handlers/donation-flow-modal-manager';\nimport { MockModalManager } from '../../mocks/mock-modal-manager';\nimport '../../mocks/mock-modal-manager';\nimport { MockBraintreeManager } from '../../mocks/mock-braintree-manager';\nimport { mockSuccessResponse } from '../../mocks/models/mock-success-response';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport { mockBillingInfo } from '../../mocks/models/mock-billing-info';\nimport { mockCustomerInfo } from '../../mocks/models/mock-customer-info';\nimport { ModalConfig } from '@internetarchive/modal-manager';\n\ndescribe('Donation Flow Modal Manager', () => {\n it('can close the modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.closeModal();\n expect(mockModalManager.closeCalled).to.be.true;\n });\n\n it('can calculate the proper default upsell amount', async () => {\n let amount = DonationFlowModalManager.getDefaultUpsellAmount(1);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10.01);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25.01);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100.01);\n expect(amount).to.equal(50);\n });\n\n it('can show the processing modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showProcessingModal();\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#497fbf');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.processingImageMode).to.equal('processing');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.false;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Processing...');\n });\n\n it('can show the error modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showErrorModal({ message: 'foo-error' });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#691916');\n expect(modalOptions?.config.showProcessingIndicator).to.be.false;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.headline?.strings[0]).to.contain(\n \"There's been a problem completing your donation.\",\n );\n expect(modalOptions?.config.message?.values[0]).to.equal('foo-error');\n });\n\n it('shows the thank you modal and calls `donationSuccessful` to take user to thank you page', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.processingImageMode).to.equal('complete');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Thank You!');\n const response = mockBraintreeManager.donationSuccessfulOptions?.successResponse;\n expect(response).to.deep.equal(mockSuccessResponse);\n });\n\n it('can show the confirmation modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n manager.showConfirmationStepModal({\n donationType: DonationType.Upsell,\n amount: 8,\n currencyType: 'USD',\n cancelDonationCB: () => console.log('donation cancelled'),\n confirmDonationCB: () => console.log('donation confirmed'),\n });\n\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config?.title?.values).to.contain('Confirm monthly donation');\n });\n\n it('can start the donation submission flow', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n });\n const result = await manager.startDonationSubmissionFlow({\n nonce: 'foo',\n paymentProvider: PaymentProvider.CreditCard,\n donationInfo: new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 5,\n coverFees: false,\n }),\n billingInfo: mockBillingInfo,\n customerInfo: mockCustomerInfo,\n });\n\n expect(result).to.deep.equal({\n success: true,\n value: {\n amount: 5,\n billing: {\n countryCodeAlpha2: 'US',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n postalCode: '12345',\n region: 'CA',\n streetAddress: '123 Fake St',\n },\n customer: {\n email: 'foo@bar.com',\n firstName: 'Fooey',\n lastName: 'McBarrison',\n },\n customer_id: 'bar',\n donationType: 'one-time',\n paymentMethodNonce: 'foo',\n paymentProvider: 'Credit Card',\n transaction_id: 'foo',\n },\n });\n });\n});\n"]}
1
+ {"version":3,"file":"donation-flow-modal-manager.test.js","sourceRoot":"","sources":["../../../../test/tests/flow-handlers/donation-flow-modal-manager.test.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gEAAgE,CAAC;AAE1G,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAEzE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,IAAI,SAAiD,CAAC;AAEtD,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG;YACV,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE;YACtB,kBAAkB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OAAO;gBAClC,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,KAAK;aACjB,CAAC;YACF,WAAW,EAAE,eAAe;YAC5B,YAAY,EAAE,gBAAgB;SAC/B,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;YAC3B,OAAO,EAAE,IAAI;YACb,KAAK,EAAE;gBACL,MAAM,EAAE,CAAC;gBACT,OAAO,EAAE;oBACP,iBAAiB,EAAE,IAAI;oBACvB,eAAe,EAAE,SAAS;oBAC1B,QAAQ,EAAE,eAAe;oBACzB,UAAU,EAAE,OAAO;oBACnB,MAAM,EAAE,IAAI;oBACZ,aAAa,EAAE,aAAa;iBAC7B;gBACD,QAAQ,EAAE;oBACR,KAAK,EAAE,aAAa;oBACpB,SAAS,EAAE,OAAO;oBAClB,QAAQ,EAAE,YAAY;iBACvB;gBACD,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,UAAU;gBACxB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,aAAa;gBAC9B,cAAc,EAAE,KAAK;aACtB;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/camelcase */\nimport { html, fixture, expect } from '@open-wc/testing';\nimport { DonationFlowModalManager } from '../../../src/payment-flow-handlers/donation-flow-modal-manager';\nimport { MockModalManager } from '../../mocks/mock-modal-manager';\nimport '../../mocks/mock-modal-manager';\nimport { MockBraintreeManager } from '../../mocks/mock-braintree-manager';\nimport { mockSuccessResponse } from '../../mocks/models/mock-success-response';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport { mockBillingInfo } from '../../mocks/models/mock-billing-info';\nimport { mockCustomerInfo } from '../../mocks/models/mock-customer-info';\nimport { DonationControllerEventLoggerInterface } from '../../../src/@types/analytics-handler';\nimport sinon from 'sinon';\n\nlet analytics: DonationControllerEventLoggerInterface;\n\ndescribe('Donation Flow Modal Manager', () => {\n beforeEach(() => {\n analytics = {\n logEvent: sinon.fake(),\n logEventNoSampling: sinon.fake(),\n };\n });\n afterEach(() => {\n sinon.restore();\n });\n it('can close the modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics\n });\n manager.closeModal();\n expect(mockModalManager.closeCalled).to.be.true;\n });\n\n it('can calculate the proper default upsell amount', async () => {\n let amount = DonationFlowModalManager.getDefaultUpsellAmount(1);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10);\n expect(amount).to.equal(5);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10.01);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25.01);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100.01);\n expect(amount).to.equal(50);\n });\n\n it('can show the processing modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics\n });\n manager.showProcessingModal();\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#497fbf');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.processingImageMode).to.equal('processing');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.false;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Processing...');\n });\n\n it('can show the error modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics\n });\n manager.showErrorModal({ message: 'foo-error' });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#691916');\n expect(modalOptions?.config.showProcessingIndicator).to.be.false;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.headline?.strings[0]).to.contain(\n \"There's been a problem completing your donation.\",\n );\n expect(modalOptions?.config.message?.values[0]).to.equal('foo-error');\n });\n\n it('shows the thank you modal and calls `donationSuccessful` to take user to thank you page', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const logEvent = sinon.fake();\n const logEventNoSampling = sinon.fake();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics: {\n logEvent,\n logEventNoSampling,\n }\n });\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.processingImageMode).to.equal('complete');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Thank You!');\n const response = mockBraintreeManager.donationSuccessfulOptions?.successResponse;\n expect(response).to.deep.equal(mockSuccessResponse);\n });\n\n it('donation submitted analytics gets sent when drawing thank you modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const logEvent = sinon.fake();\n const logEventNoSampling = sinon.fake();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics: {\n logEvent,\n logEventNoSampling,\n }\n });\n const successResponse = mockSuccessResponse;\n successResponse.paymentProvider = PaymentProvider.GooglePay;\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n\n // fires analytics\n expect(logEventNoSampling.callCount).to.equal(1);\n expect(logEventNoSampling.args[0][0]).to.equal(`Donated-GooglePay`);\n expect(logEventNoSampling.args[0][1]).to.equal(DonationType.OneTime);\n });\n\n it('can show the confirmation modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics\n });\n manager.showConfirmationStepModal({\n donationType: DonationType.Upsell,\n amount: 8,\n currencyType: 'USD',\n cancelDonationCB: () => console.log('donation cancelled'),\n confirmDonationCB: () => console.log('donation confirmed'),\n });\n\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config?.title?.values).to.contain('Confirm monthly donation');\n });\n\n it('can start the donation submission flow', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics\n });\n const result = await manager.startDonationSubmissionFlow({\n nonce: 'foo',\n paymentProvider: PaymentProvider.CreditCard,\n donationInfo: new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 5,\n coverFees: false,\n }),\n billingInfo: mockBillingInfo,\n customerInfo: mockCustomerInfo,\n });\n\n expect(result).to.deep.equal({\n success: true,\n value: {\n amount: 5,\n billing: {\n countryCodeAlpha2: 'US',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n postalCode: '12345',\n region: 'CA',\n streetAddress: '123 Fake St',\n },\n customer: {\n email: 'foo@bar.com',\n firstName: 'Fooey',\n lastName: 'McBarrison',\n },\n customer_id: 'bar',\n donationType: 'one-time',\n paymentMethodNonce: 'foo',\n paymentProvider: 'Credit Card',\n transaction_id: 'foo',\n },\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/donation-form",
3
- "version": "0.5.14",
3
+ "version": "0.5.15-a2",
4
4
  "description": "The Internet Archive Donation Form",
5
5
  "license": "AGPL-3.0-only",
6
6
  "main": "dist/index.js",
@@ -28,6 +28,7 @@
28
28
  "test:watch": "concurrently --kill-others --names tsc,karma \"yarn run tsc:watch\" \"karma start --auto-watch=true --single-run=false\""
29
29
  },
30
30
  "dependencies": {
31
+ "@internetarchive/analytics-manager": "^0.1.2",
31
32
  "@internetarchive/donation-form-currency-validator": "^0.3.0",
32
33
  "@internetarchive/donation-form-data-models": "^0.3.2",
33
34
  "@internetarchive/donation-form-edit-donation": "^0.3.13",
@@ -1,21 +1,8 @@
1
- /**
2
- * This is an interface for the analytics handler in petabox
3
- * because we don't currently have a declarations file for it.
1
+ /** Analytics functionality from Donation Form Controller
2
+ * this will get passed thru to the children handlers
3
+ * so that they can send analytics events in donation form context
4
4
  */
5
- export interface AnalyticsHandlerInterface {
6
- /**
7
- * Sends a tracking event.
8
- *
9
- * @param {string} category
10
- * @param {string} action
11
- * @param {string} label Defaults to `window.location.pathname`
12
- * @param {Object} additionalEventParams These are internal params, not sent to GA
13
- */
14
- // eslint-disable-next-line @typescript-eslint/camelcase
15
- send_event(
16
- category: string,
17
- action: string,
18
- label?: string,
19
- additionalEventParams?: object,
20
- ): void;
5
+ export interface DonationControllerEventLoggerInterface {
6
+ logEvent(action: string, label: string): void;
7
+ logEventNoSampling(action: string, label: string): void;
21
8
  }
@@ -35,7 +35,8 @@ import './form-elements/contact-form/contact-form';
35
35
  import creditCardImg from '@internetarchive/icon-credit-card';
36
36
  import calendarImg from '@internetarchive/icon-calendar';
37
37
  import lockImg from '@internetarchive/icon-lock';
38
- import { AnalyticsHandlerInterface } from './@types/analytics-handler';
38
+ import { DonationControllerEventLoggerInterface } from './@types/analytics-handler';
39
+ import { AnalyticsManagerInterface, AnalyticsEvent } from '@internetarchive/analytics-manager';
39
40
  import {
40
41
  EditDonationAmountSelectionLayout,
41
42
  EditDonationFrequencySelectionMode,
@@ -90,7 +91,7 @@ export class DonationFormController extends LitElement {
90
91
 
91
92
  @property({ type: Object }) endpointManager?: BraintreeEndpointManagerInterface;
92
93
 
93
- @property({ type: Object }) analyticsHandler?: AnalyticsHandlerInterface;
94
+ @property({ type: Object }) analyticsHandler?: AnalyticsManagerInterface;
94
95
 
95
96
  @property({ type: Object }) modalManager?: ModalManagerInterface;
96
97
 
@@ -323,6 +324,12 @@ export class DonationFormController extends LitElement {
323
324
  braintreeManager: this.braintreeManager,
324
325
  modalManager: this.modalManager,
325
326
  recaptchaManager: this.recaptchaManager,
327
+ resources: {
328
+ analytics: {
329
+ logEvent: this.logEvent.bind(this),
330
+ logEventNoSampling: this.logEventNoSampling.bind(this),
331
+ } as DonationControllerEventLoggerInterface,
332
+ }
326
333
  });
327
334
 
328
335
  this.donationForm.braintreeManager = this.braintreeManager;
@@ -513,13 +520,25 @@ export class DonationFormController extends LitElement {
513
520
  /**
514
521
  * Log an event
515
522
  *
516
- * @param {string} name Name of event
523
+ * @param {string} action Name of event
517
524
  * @param {string} label Event label, optional
518
525
  */
519
- private logEvent(name: string, label?: string): void {
520
- this.analyticsHandler?.send_event(this.analyticsCategory, name, label);
526
+ private logEvent(action: string, label?: string): void {
527
+ const analyticEvent = { action, label, category: this.analyticsCategory } as AnalyticsEvent;
528
+ this.analyticsHandler?.sendEvent(analyticEvent);
521
529
  }
522
530
 
531
+ /**
532
+ * Log an event in no sample bucket
533
+ *
534
+ * @param {string} action Name of event
535
+ * @param {string} label Event label, optional
536
+ */
537
+ private logEventNoSampling(action: string, label?: string): void {
538
+ const analyticEvent = { action, label, category: this.analyticsCategory } as AnalyticsEvent;
539
+ this.analyticsHandler?.sendEventNoSampling(analyticEvent);
540
+ }
541
+
523
542
  /**
524
543
  * This is not the normal LitElement styles block.
525
544
  *
@@ -14,6 +14,7 @@ import {
14
14
  DonationResponse,
15
15
  } from '@internetarchive/donation-form-data-models';
16
16
  import '../modals/error-modal-content';
17
+ import { DonationControllerEventLoggerInterface } from '../@types/analytics-handler';
17
18
 
18
19
  enum ModalHeaderColor {
19
20
  Blue = '#497fbf',
@@ -149,12 +150,16 @@ export class DonationFlowModalManager implements DonationFlowModalManagerInterfa
149
150
 
150
151
  private modalManager: ModalManagerInterface;
151
152
 
153
+ private analytics: DonationControllerEventLoggerInterface;
154
+
152
155
  constructor(options: {
153
156
  braintreeManager: BraintreeManagerInterface;
154
157
  modalManager: ModalManagerInterface;
158
+ analytics: DonationControllerEventLoggerInterface;
155
159
  }) {
156
160
  this.modalManager = options.modalManager;
157
161
  this.braintreeManager = options.braintreeManager;
162
+ this.analytics = options.analytics;
158
163
  }
159
164
 
160
165
  /** @inheritdoc */
@@ -193,6 +198,17 @@ export class DonationFlowModalManager implements DonationFlowModalManagerInterfa
193
198
  this.modalManager.showModal({
194
199
  config: modalConfig,
195
200
  });
201
+
202
+ // post analytic
203
+ const selectedPayment = options.successResponse.paymentProvider.replace(/\s+/g, '');
204
+ let action = `Donated-${selectedPayment}`;
205
+ if (options.upsellSuccessResponse) {
206
+ action += `-upsell`;
207
+ }
208
+ const label = options.successResponse.donationType;
209
+ this.analytics.logEventNoSampling(action, label);
210
+
211
+ // post donation
196
212
  this.braintreeManager.donationSuccessful(options);
197
213
  }
198
214
 
@@ -379,6 +395,13 @@ export class DonationFlowModalManager implements DonationFlowModalManagerInterfa
379
395
  upsellSuccessResponse?: SuccessResponse;
380
396
  }): void {
381
397
  this.showThankYouModal(options);
398
+
399
+ // post analytic
400
+ const selectedPayment = options.successResponse.paymentProvider.replace(/\s+/g, '');
401
+ const action = `Donated-${selectedPayment}-upsell`;
402
+ const label = options.successResponse.donationType;
403
+ this.analytics.logEventNoSampling(action, label);
404
+
382
405
  this.braintreeManager.donationSuccessful(options);
383
406
  }
384
407
 
@@ -99,7 +99,7 @@ export class PaymentFlowHandlers implements PaymentFlowHandlersInterface {
99
99
  return this.donationFlowModalManager.showUpsellModal(options);
100
100
  }
101
101
 
102
- /** @inheritdoc */
102
+ /** @inheritdoc */
103
103
  showConfirmationStepModal(options: {
104
104
  amount: number;
105
105
  donationType: DonationType;
@@ -186,14 +186,22 @@ export class PaymentFlowHandlers implements PaymentFlowHandlersInterface {
186
186
  braintreeManager: BraintreeManagerInterface;
187
187
  modalManager: ModalManagerInterface;
188
188
  recaptchaManager: RecaptchaManagerInterface;
189
+ resources: {
190
+ analytics: {
191
+ logEvent: (action: string, label: string) => void;
192
+ logEventNoSampling: (action: string, label: string) => void;
193
+ };
194
+ };
189
195
  }) {
190
196
  this.braintreeManager = options.braintreeManager;
191
197
  this.modalManager = options.modalManager;
192
198
  this.recaptchaManager = options.recaptchaManager;
199
+ this.resources = options.resources;
193
200
 
194
201
  this.donationFlowModalManager = new DonationFlowModalManager({
195
202
  braintreeManager: this.braintreeManager,
196
203
  modalManager: this.modalManager,
204
+ analytics: this.resources.analytics,
197
205
  });
198
206
  }
199
207
 
@@ -201,4 +209,10 @@ export class PaymentFlowHandlers implements PaymentFlowHandlersInterface {
201
209
  private modalManager: ModalManagerInterface;
202
210
  private recaptchaManager: RecaptchaManagerInterface;
203
211
  private donationFlowModalManager: DonationFlowModalManagerInterface;
212
+ private resources: {
213
+ analytics: {
214
+ logEvent: (action: string, label: string) => void;
215
+ logEventNoSampling: (action: string, label: string) => void;
216
+ };
217
+ };
204
218
  }