@internetarchive/donation-form 0.5.16-a1 → 0.5.16
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.
- package/dist/src/braintree-manager/braintree-interfaces.d.ts +0 -4
- package/dist/src/braintree-manager/braintree-interfaces.js.map +1 -1
- package/dist/src/braintree-manager/braintree-manager.js.map +1 -1
- package/dist/src/payment-flow-handlers/donation-flow-modal-manager.js.map +1 -1
- package/package.json +2 -2
- package/src/braintree-manager/braintree-interfaces.ts +0 -5
- package/src/braintree-manager/braintree-manager.ts +0 -4
- package/src/payment-flow-handlers/donation-flow-modal-manager.ts +0 -5
|
@@ -140,10 +140,6 @@ export interface BraintreeEndpointManagerInterface {
|
|
|
140
140
|
successResponse: SuccessResponse;
|
|
141
141
|
upsellSuccessResponse?: SuccessResponse;
|
|
142
142
|
}): void;
|
|
143
|
-
/**
|
|
144
|
-
* Optional callback once success is called
|
|
145
|
-
*/
|
|
146
|
-
donationSuccessCallback?: Function;
|
|
147
143
|
}
|
|
148
144
|
export declare enum HostingEnvironment {
|
|
149
145
|
Development = "dev",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"braintree-interfaces.js","sourceRoot":"","sources":["../../../src/braintree-manager/braintree-interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"braintree-interfaces.js","sourceRoot":"","sources":["../../../src/braintree-manager/braintree-interfaces.ts"],"names":[],"mappings":"AAwKA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,yCAAmB,CAAA;AACrB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B","sourcesContent":["import {\n DonationRequest,\n DonationResponse,\n SuccessResponse,\n PaymentProvider,\n DonationPaymentInfo,\n CustomerInfo,\n BillingInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { PromisedSingleton } from '@internetarchive/promised-singleton';\nimport { Unsubscribe } from 'nanoevents';\nimport { PaymentProvidersInterface } from './payment-providers-interface';\n\nexport interface BraintreeManagerEvents {\n paymentProvidersHostedFieldsRetry: (retryNumber: number) => void;\n paymentProvidersHostedFieldsFailed: (error: unknown) => void;\n}\n\n/**\n * The BraintreeManager is the main entrypoint for much of the common braintree functionality.\n *\n * A single instance of it gets created and passed down through all of the components.\n *\n * @export\n * @interface BraintreeManagerInterface\n */\nexport interface BraintreeManagerInterface {\n on<E extends keyof BraintreeManagerEvents>(\n event: E,\n callback: BraintreeManagerEvents[E],\n ): Unsubscribe;\n\n /**\n * The PaymentProviders class contains the IA-specific handlers for each of the\n * different payment providers.\n *\n * They are generally data-focused, as opposed to UI-focused, but there\n * is some cross-polination between PaymentProviders and FlowHandlers.\n *\n * @type {PaymentProvidersInterface}\n * @memberof BraintreeManagerInterface\n */\n paymentProviders: PaymentProvidersInterface;\n\n /**\n * The Braintree Client instance.\n *\n * This gets used to isntantiate clients for all of the payment providers.\n *\n * @type {PromisedSingleton<braintree.Client>}\n * @memberof BraintreeManagerInterface\n */\n instance: PromisedSingleton<braintree.Client>;\n\n /**\n * Set the referrer for later submission\n *\n * @param {string} referrer\n * @memberof BraintreeManagerInterface\n */\n setReferrer(referrer: string): void;\n\n /**\n * Set the origin for later submission\n *\n * @param {string} origin\n * @memberof BraintreeManagerInterface\n */\n setOrigin(origin: string): void;\n\n /**\n * Set the logged-in user for later submission\n *\n * @param {string} loggedInUser\n * @memberof BraintreeManagerInterface\n */\n setLoggedInUser(loggedInUser: string): void;\n\n /**\n * Perform startup tasts like session resuming\n *\n * @memberof BraintreeManagerInterface\n */\n startup(): void;\n\n /**\n * Submit donation to the backend\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>}\n * @memberof BraintreeManagerInterface\n */\n submitDonation(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>;\n\n /**\n * Submit the upsell donation\n *\n * @param {{\n * oneTimeDonationResponse: SuccessResponse;\n * amount: number;\n * }} options\n * @returns {Promise<DonationResponse>}\n * @memberof BraintreeManagerInterface\n */\n submitUpsellDonation(options: {\n oneTimeDonationResponse: SuccessResponse;\n amount: number;\n }): Promise<DonationResponse>;\n\n /**\n * Finish the donation after a successful completion.\n *\n * @param {{\n * successResponse: SuccessResponse;\n * upsellSuccessResponse?: SuccessResponse;\n * }} options\n * @memberof BraintreeManagerInterface\n */\n donationSuccessful(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void;\n}\n\nexport interface BraintreeEndpointManagerInterface {\n /**\n * Responsible for submitting a data object to the backend\n * and returning a Promise of the JSON object response.\n *\n * @param {object} data\n * @returns {Promise<object>}\n * @memberof BraintreeEndpointManagerInterface\n */\n submitData(request: DonationRequest): Promise<DonationResponse>;\n\n /**\n * Once the user is finished with the donation flow, either after\n * a monthly donation or an upsell, we notify the endpoint manager\n * so it can redirect the user to the thank you page.\n */\n donationSuccessful(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void;\n}\n\nexport enum HostingEnvironment {\n Development = 'dev',\n Production = 'prod',\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"braintree-manager.js","sourceRoot":"","sources":["../../../src/braintree-manager/braintree-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,2BAA2B,EAC3B,YAAY,EAGZ,mBAAmB,GAGpB,MA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ClB,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF","sourcesContent":["import {\n DonationResponse,\n DonationRequest,\n DonationRequestCustomFields,\n DonationType,\n CustomerInfo,\n BillingInfo,\n DonationPaymentInfo,\n PaymentProvider,\n SuccessResponse,\n} from '@internetarchive/donation-form-data-models';\n\nimport { PaymentProviders } from './payment-providers';\nimport { PaymentClientsInterface } from './payment-clients';\nimport {\n BraintreeManagerInterface,\n BraintreeEndpointManagerInterface,\n HostingEnvironment,\n BraintreeManagerEvents,\n} from './braintree-interfaces';\nimport { HostedFieldConfiguration } from './payment-providers/credit-card/hosted-field-configuration';\nimport { PromisedSingleton } from '@internetarchive/promised-singleton';\nimport { PaymentProvidersInterface } from './payment-providers-interface';\nimport { createNanoEvents, Unsubscribe } from 'nanoevents';\n\n/** @inheritdoc */\nexport class BraintreeManager implements BraintreeManagerInterface {\n private referrer?: string;\n\n /**\n * The origin is made up of campaign / ABTest information that the user originated from.\n *\n * The field is a freeform string so it can be anything, but make sure it's something\n * identifiable so it can be queried in CiviCRM.\n *\n * For instance, we use this format for the Donation Banner:\n * - `{Source}-{Test Name}-{Variant Name}`, eg:\n * - `DonateBanner-Campaign Start 2020-IADefault`\n * - `DonateBanner-Mid Campaign-IAThermometer`\n *\n * For additional specificity, you could add additional info, ie.\n * - `DonateBanner-MidJuly2020 Campaign-VariantA-Button1`\n *\n * @private\n * @type {string}\n * @memberof BraintreeManager\n */\n private origin?: string;\n\n private loggedInUser?: string;\n\n /**\n * The Device Data token generated by the DataCollector.\n *\n * This gets submitted for several of the payment providers as an anti-fraud mechanism.\n *\n * @private\n * @type {string}\n * @memberof BraintreeManager\n */\n private deviceData?: string;\n\n private emitter = createNanoEvents<BraintreeManagerEvents>();\n\n on<E extends keyof BraintreeManagerEvents>(\n event: E,\n callback: BraintreeManagerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n /** @inheritdoc */\n paymentProviders: PaymentProvidersInterface;\n\n /** @inheritdoc */\n async startup(): Promise<void> {\n return this.collectDeviceData();\n }\n\n /** @inheritdoc */\n instance = new PromisedSingleton<braintree.Client>({\n generator: async (): Promise<braintree.Client> => {\n const client = await this.paymentClients.braintreeClient.get();\n return client?.create({ authorization: this.authorizationToken });\n },\n });\n\n /** @inheritdoc */\n async submitDonation(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> {\n const customFields = new DonationRequestCustomFields();\n // eslint-disable-next-line @typescript-eslint/camelcase\n customFields.fee_amount_covered = options.donationInfo.feeAmountCovered;\n // eslint-disable-next-line @typescript-eslint/camelcase\n customFields.logged_in_user = this.loggedInUser;\n customFields.referrer = this.referrer;\n customFields.origin = this.origin;\n\n // This is interesting and applies only to Venmo, but will work for other providers as well.\n // In Safari, `donationInfo` actually comes through as a DonationPaymentInfo object,\n // but in Chrome, it comes through as a plain object so you can't call `.total()` on it to\n // get the total amount and instead have to calculate the total\n const total = DonationPaymentInfo.calculateTotal(\n options.donationInfo.amount,\n options.donationInfo.coverFees,\n );\n\n const donationRequest = new DonationRequest({\n deviceData: this.deviceData,\n paymentProvider: options.paymentProvider,\n paymentMethodNonce: options.nonce,\n amount: total,\n donationType: options.donationInfo.donationType,\n customer: options.customerInfo,\n billing: options.billingInfo,\n customFields: customFields,\n upsellOnetimeTransactionId: options.upsellOnetimeTransactionId,\n customerId: options.customerId,\n recaptchaToken: options.recaptchaToken,\n bin: options.bin,\n binName: options.binName,\n });\n\n const jsonResponse = await this.endpointManager.submitData(donationRequest);\n const modeledResponse = new DonationResponse(jsonResponse);\n return modeledResponse;\n }\n\n /** @inheritdoc */\n async submitUpsellDonation(options: {\n oneTimeDonationResponse: SuccessResponse;\n amount: number;\n }): Promise<DonationResponse> {\n const response = options.oneTimeDonationResponse;\n\n const donationInfo = new DonationPaymentInfo({\n amount: options.amount,\n donationType: DonationType.Upsell,\n coverFees: false,\n });\n\n return this.submitDonation({\n nonce: response.paymentMethodNonce,\n paymentProvider: response.paymentProvider,\n customerId: response.customer_id,\n donationInfo: donationInfo,\n customerInfo: response.customer,\n billingInfo: response.billing,\n upsellOnetimeTransactionId: response.transaction_id,\n });\n }\n\n /** @inheritdoc */\n donationSuccessful(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void {\n\n\n\n \n this.endpointManager.donationSuccessful(options);\n }\n\n private deviceDataCollectionStarted = false;\n\n /**\n * Collect Braintree device data. This is used to help fraud detection.\n *\n * @private\n * @returns {Promise<void>}\n * @memberof BraintreeManager\n */\n private async collectDeviceData(): Promise<void> {\n if (this.deviceDataCollectionStarted) {\n return;\n }\n this.deviceDataCollectionStarted = true;\n\n const instance = await this.instance.get();\n if (!instance) {\n return;\n }\n\n return this.paymentClients.dataCollector\n .get()\n .then((collector?: braintree.DataCollector) => {\n return collector?.create({ client: instance, kount: false, paypal: true });\n })\n .then(instance => {\n this.deviceData = instance?.deviceData;\n });\n }\n\n /**\n * Braintree Authorization Token\n *\n * @private\n * @type {string}\n * @memberof BraintreeManager\n */\n private authorizationToken: string;\n\n /**\n * The endpoint manager for network communications\n *\n * @private\n * @type {BraintreeEndpointManagerInterface}\n * @memberof BraintreeManager\n */\n private endpointManager: BraintreeEndpointManagerInterface;\n\n /**\n * The payment clients container containing the braintree, paypal, and google clients\n *\n * @private\n * @type {PaymentClientsInterface}\n * @memberof BraintreeManager\n */\n private paymentClients: PaymentClientsInterface;\n\n private hostingEnvironment: HostingEnvironment = HostingEnvironment.Development;\n\n constructor(options: {\n authorizationToken: string;\n paymentClients: PaymentClientsInterface;\n endpointManager: BraintreeEndpointManagerInterface;\n hostedFieldConfig: HostedFieldConfiguration;\n hostingEnvironment: HostingEnvironment;\n venmoProfileId?: string;\n googlePayMerchantId?: string;\n referrer?: string;\n loggedInUser?: string;\n origin?: string;\n }) {\n this.authorizationToken = options.authorizationToken;\n this.endpointManager = options.endpointManager;\n this.hostingEnvironment = options.hostingEnvironment;\n this.paymentClients = options.paymentClients;\n\n this.referrer = options.referrer;\n this.loggedInUser = options.loggedInUser;\n this.origin = options.origin;\n\n this.paymentProviders = new PaymentProviders({\n braintreeManager: this,\n paymentClients: this.paymentClients,\n venmoProfileId: options.venmoProfileId,\n googlePayMerchantId: options.googlePayMerchantId,\n hostingEnvironment: options.hostingEnvironment,\n hostedFieldConfig: options.hostedFieldConfig,\n });\n\n this.paymentProviders.on('hostedFieldsRetry', (retryNumber: number) => {\n this.emitter.emit('paymentProvidersHostedFieldsRetry', retryNumber);\n });\n\n this.paymentProviders.on('hostedFieldsFailed', (error: unknown) => {\n this.emitter.emit('paymentProvidersHostedFieldsFailed', error);\n });\n }\n\n /** @inheritdoc */\n setReferrer(referrer: string): void {\n this.referrer = referrer;\n }\n\n /** @inheritdoc */\n setLoggedInUser(loggedInUser: string): void {\n this.loggedInUser = loggedInUser;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this.origin = origin;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"braintree-manager.js","sourceRoot":"","sources":["../../../src/braintree-manager/braintree-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,2BAA2B,EAC3B,YAAY,EAGZ,mBAAmB,GAGpB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAGL,kBAAkB,GAEnB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAE3D,kBAAkB;AAClB,MAAM,OAAO,gBAAgB;IA2M3B,YAAY,OAWX;QAl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CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAID;;;;;;OAMG;IACW,iBAAiB;;YAC7B,IAAI,IAAI,CAAC,2BAA2B,EAAE;gBACpC,OAAO;aACR;YACD,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC;YAExC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;YAC3C,IAAI,CAAC,QAAQ,EAAE;gBACb,OAAO;aACR;YAED,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa;iBACrC,GAAG,EAAE;iBACL,IAAI,CAAC,CAAC,SAAmC,EAAE,EAAE;gBAC5C,OAAO,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;YAC7E,CAAC,CAAC;iBACD,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACf,IAAI,CAAC,UAAU,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,UAAU,CAAC;YACzC,CAAC,CAAC,CAAC;QACP,CAAC;KAAA;IAsED,kBAAkB;IAClB,WAAW,CAAC,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,kBAAkB;IAClB,eAAe,CAAC,YAAoB;QAClC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,kBAAkB;IAClB,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF","sourcesContent":["import {\n DonationResponse,\n DonationRequest,\n DonationRequestCustomFields,\n DonationType,\n CustomerInfo,\n BillingInfo,\n DonationPaymentInfo,\n PaymentProvider,\n SuccessResponse,\n} from '@internetarchive/donation-form-data-models';\n\nimport { PaymentProviders } from './payment-providers';\nimport { PaymentClientsInterface } from './payment-clients';\nimport {\n BraintreeManagerInterface,\n BraintreeEndpointManagerInterface,\n HostingEnvironment,\n BraintreeManagerEvents,\n} from './braintree-interfaces';\nimport { HostedFieldConfiguration } from './payment-providers/credit-card/hosted-field-configuration';\nimport { PromisedSingleton } from '@internetarchive/promised-singleton';\nimport { PaymentProvidersInterface } from './payment-providers-interface';\nimport { createNanoEvents, Unsubscribe } from 'nanoevents';\n\n/** @inheritdoc */\nexport class BraintreeManager implements BraintreeManagerInterface {\n private referrer?: string;\n\n /**\n * The origin is made up of campaign / ABTest information that the user originated from.\n *\n * The field is a freeform string so it can be anything, but make sure it's something\n * identifiable so it can be queried in CiviCRM.\n *\n * For instance, we use this format for the Donation Banner:\n * - `{Source}-{Test Name}-{Variant Name}`, eg:\n * - `DonateBanner-Campaign Start 2020-IADefault`\n * - `DonateBanner-Mid Campaign-IAThermometer`\n *\n * For additional specificity, you could add additional info, ie.\n * - `DonateBanner-MidJuly2020 Campaign-VariantA-Button1`\n *\n * @private\n * @type {string}\n * @memberof BraintreeManager\n */\n private origin?: string;\n\n private loggedInUser?: string;\n\n /**\n * The Device Data token generated by the DataCollector.\n *\n * This gets submitted for several of the payment providers as an anti-fraud mechanism.\n *\n * @private\n * @type {string}\n * @memberof BraintreeManager\n */\n private deviceData?: string;\n\n private emitter = createNanoEvents<BraintreeManagerEvents>();\n\n on<E extends keyof BraintreeManagerEvents>(\n event: E,\n callback: BraintreeManagerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n /** @inheritdoc */\n paymentProviders: PaymentProvidersInterface;\n\n /** @inheritdoc */\n async startup(): Promise<void> {\n return this.collectDeviceData();\n }\n\n /** @inheritdoc */\n instance = new PromisedSingleton<braintree.Client>({\n generator: async (): Promise<braintree.Client> => {\n const client = await this.paymentClients.braintreeClient.get();\n return client?.create({ authorization: this.authorizationToken });\n },\n });\n\n /** @inheritdoc */\n async submitDonation(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> {\n const customFields = new DonationRequestCustomFields();\n // eslint-disable-next-line @typescript-eslint/camelcase\n customFields.fee_amount_covered = options.donationInfo.feeAmountCovered;\n // eslint-disable-next-line @typescript-eslint/camelcase\n customFields.logged_in_user = this.loggedInUser;\n customFields.referrer = this.referrer;\n customFields.origin = this.origin;\n\n // This is interesting and applies only to Venmo, but will work for other providers as well.\n // In Safari, `donationInfo` actually comes through as a DonationPaymentInfo object,\n // but in Chrome, it comes through as a plain object so you can't call `.total()` on it to\n // get the total amount and instead have to calculate the total\n const total = DonationPaymentInfo.calculateTotal(\n options.donationInfo.amount,\n options.donationInfo.coverFees,\n );\n\n const donationRequest = new DonationRequest({\n deviceData: this.deviceData,\n paymentProvider: options.paymentProvider,\n paymentMethodNonce: options.nonce,\n amount: total,\n donationType: options.donationInfo.donationType,\n customer: options.customerInfo,\n billing: options.billingInfo,\n customFields: customFields,\n upsellOnetimeTransactionId: options.upsellOnetimeTransactionId,\n customerId: options.customerId,\n recaptchaToken: options.recaptchaToken,\n bin: options.bin,\n binName: options.binName,\n });\n\n const jsonResponse = await this.endpointManager.submitData(donationRequest);\n const modeledResponse = new DonationResponse(jsonResponse);\n return modeledResponse;\n }\n\n /** @inheritdoc */\n async submitUpsellDonation(options: {\n oneTimeDonationResponse: SuccessResponse;\n amount: number;\n }): Promise<DonationResponse> {\n const response = options.oneTimeDonationResponse;\n\n const donationInfo = new DonationPaymentInfo({\n amount: options.amount,\n donationType: DonationType.Upsell,\n coverFees: false,\n });\n\n return this.submitDonation({\n nonce: response.paymentMethodNonce,\n paymentProvider: response.paymentProvider,\n customerId: response.customer_id,\n donationInfo: donationInfo,\n customerInfo: response.customer,\n billingInfo: response.billing,\n upsellOnetimeTransactionId: response.transaction_id,\n });\n }\n\n /** @inheritdoc */\n donationSuccessful(options: {\n successResponse: SuccessResponse;\n upsellSuccessResponse?: SuccessResponse;\n }): void {\n this.endpointManager.donationSuccessful(options);\n }\n\n private deviceDataCollectionStarted = false;\n\n /**\n * Collect Braintree device data. This is used to help fraud detection.\n *\n * @private\n * @returns {Promise<void>}\n * @memberof BraintreeManager\n */\n private async collectDeviceData(): Promise<void> {\n if (this.deviceDataCollectionStarted) {\n return;\n }\n this.deviceDataCollectionStarted = true;\n\n const instance = await this.instance.get();\n if (!instance) {\n return;\n }\n\n return this.paymentClients.dataCollector\n .get()\n .then((collector?: braintree.DataCollector) => {\n return collector?.create({ client: instance, kount: false, paypal: true });\n })\n .then(instance => {\n this.deviceData = instance?.deviceData;\n });\n }\n\n /**\n * Braintree Authorization Token\n *\n * @private\n * @type {string}\n * @memberof BraintreeManager\n */\n private authorizationToken: string;\n\n /**\n * The endpoint manager for network communications\n *\n * @private\n * @type {BraintreeEndpointManagerInterface}\n * @memberof BraintreeManager\n */\n private endpointManager: BraintreeEndpointManagerInterface;\n\n /**\n * The payment clients container containing the braintree, paypal, and google clients\n *\n * @private\n * @type {PaymentClientsInterface}\n * @memberof BraintreeManager\n */\n private paymentClients: PaymentClientsInterface;\n\n private hostingEnvironment: HostingEnvironment = HostingEnvironment.Development;\n\n constructor(options: {\n authorizationToken: string;\n paymentClients: PaymentClientsInterface;\n endpointManager: BraintreeEndpointManagerInterface;\n hostedFieldConfig: HostedFieldConfiguration;\n hostingEnvironment: HostingEnvironment;\n venmoProfileId?: string;\n googlePayMerchantId?: string;\n referrer?: string;\n loggedInUser?: string;\n origin?: string;\n }) {\n this.authorizationToken = options.authorizationToken;\n this.endpointManager = options.endpointManager;\n this.hostingEnvironment = options.hostingEnvironment;\n this.paymentClients = options.paymentClients;\n\n this.referrer = options.referrer;\n this.loggedInUser = options.loggedInUser;\n this.origin = options.origin;\n\n this.paymentProviders = new PaymentProviders({\n braintreeManager: this,\n paymentClients: this.paymentClients,\n venmoProfileId: options.venmoProfileId,\n googlePayMerchantId: options.googlePayMerchantId,\n hostingEnvironment: options.hostingEnvironment,\n hostedFieldConfig: options.hostedFieldConfig,\n });\n\n this.paymentProviders.on('hostedFieldsRetry', (retryNumber: number) => {\n this.emitter.emit('paymentProvidersHostedFieldsRetry', retryNumber);\n });\n\n this.paymentProviders.on('hostedFieldsFailed', (error: unknown) => {\n this.emitter.emit('paymentProvidersHostedFieldsFailed', error);\n });\n }\n\n /** @inheritdoc */\n setReferrer(referrer: string): void {\n this.referrer = referrer;\n }\n\n /** @inheritdoc */\n setLoggedInUser(loggedInUser: string): void {\n this.loggedInUser = loggedInUser;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this.origin = origin;\n }\n}\n"]}
|
|
@@ -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;AAGvC,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;IAOnC,YAAY,OAIX;QACC,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;IACrC,CAAC;IAED,kBAAkB;IAClB,UAAU;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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';\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.logDonationFlowEvent(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.logDonationFlowEvent(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\n \n\n\n \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,MAAM,gCAAgC,CAAC;AACpE,OAAO,0CAA0C,CAAC;AAElD,OAAO,EAIL,YAAY,GAKb,MAAM,4CAA4C,CAAC;AACpD,OAAO,+BAA+B,CAAC;AAGvC,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;IAOnC,YAAY,OAIX;QACC,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;IACrC,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,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,kBAAkB;IAClB,iBAAiB,CAAC,OAGjB;QACC,MAA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,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';\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.logDonationFlowEvent(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.logDonationFlowEvent(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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/donation-form",
|
|
3
|
-
"version": "0.5.16
|
|
3
|
+
"version": "0.5.16",
|
|
4
4
|
"description": "The Internet Archive Donation Form",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@internetarchive/analytics-manager": "^0.1.2",
|
|
32
32
|
"@internetarchive/donation-form-currency-validator": "^0.3.0",
|
|
33
|
-
"@internetarchive/donation-form-data-models": "^0.3.
|
|
33
|
+
"@internetarchive/donation-form-data-models": "^0.3.3",
|
|
34
34
|
"@internetarchive/donation-form-edit-donation": "^0.3.13",
|
|
35
35
|
"@internetarchive/donation-form-section": "^0.3.5",
|
|
36
36
|
"@internetarchive/icon-applepay": "^1.3.2",
|
|
@@ -164,11 +164,6 @@ export interface BraintreeEndpointManagerInterface {
|
|
|
164
164
|
successResponse: SuccessResponse;
|
|
165
165
|
upsellSuccessResponse?: SuccessResponse;
|
|
166
166
|
}): void;
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Optional callback once success is called
|
|
170
|
-
*/
|
|
171
|
-
donationSuccessCallback?: Function;
|
|
172
167
|
}
|
|
173
168
|
|
|
174
169
|
export enum HostingEnvironment {
|