@internetarchive/donation-form 0.5.16-a1 → 0.5.17-a1

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.
@@ -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":"AA6KA,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 /**\n * Optional callback once success is called\n */\n donationSuccessCallback?: Function;\n}\n\nexport enum HostingEnvironment {\n Development = 'dev',\n Production = 'prod',\n}\n"]}
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,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;A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IAClB,kBAAkB,CAAC,OAGlB;QAKC,IAAI,CAAC,eAAe,CAAC,kBAAkB,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\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;QAlLO,YAAO,GAAG,gBAAgB,EAA0B,CAAC;QAiB7D,kBAAkB;QAClB,aAAQ,GAAG,IAAI,iBAAiB,CAAmB;YACjD,SAAS,EAAE,GAAoC,EAAE;gBAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;gBAC/D,OAAO,MAAM,aAAN,M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C;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"]}
@@ -22,6 +22,8 @@ export declare class ContactForm extends LitElement {
22
22
  countryCodeAlpha2Field: HTMLSelectElement;
23
23
  errorMessage: HTMLDivElement;
24
24
  form: HTMLFormElement;
25
+ /** @keyof countries */
26
+ selectedCountry: string;
25
27
  reportValidity(): boolean;
26
28
  focus(): void;
27
29
  /** @inheritdoc */
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { LitElement, html, css } from 'lit';
3
- import { customElement, query } from 'lit/decorators.js';
3
+ import { customElement, property, query } from 'lit/decorators.js';
4
4
  import { ifDefined } from 'lit/directives/if-defined.js';
5
5
  import { BillingInfo, CustomerInfo, DonorContactInfo, } from '@internetarchive/donation-form-data-models';
6
6
  import { SpacerOption } from '../badged-input';
@@ -10,6 +10,11 @@ import localePinImg from '@internetarchive/icon-locale-pin';
10
10
  import userIcon from '@internetarchive/icon-user';
11
11
  import { countries } from './countries';
12
12
  let ContactForm = class ContactForm extends LitElement {
13
+ constructor() {
14
+ super(...arguments);
15
+ /** @keyof countries */
16
+ this.selectedCountry = 'US';
17
+ }
13
18
  reportValidity() {
14
19
  const fieldBadgedInputs = [
15
20
  [this.emailField, this.emailBadgedInput],
@@ -140,14 +145,27 @@ let ContactForm = class ContactForm extends LitElement {
140
145
  `;
141
146
  }
142
147
  get countrySelectorTemplate() {
143
- const selectedCountry = 'US';
144
148
  return html `
145
149
  <badged-input>
146
- <select id="donation-contact-form-countryCodeAlpha2">
150
+ <select id="donation-contact-form-countryCodeAlpha2"
151
+ @change=${(e) => {
152
+ var _a, _b, _c, _d, _e, _f;
153
+ const currCountry = this.selectedCountry;
154
+ this.selectedCountry = ((_a = e.target) === null || _a === void 0 ? void 0 : _a.value) ? (_b = e.target) === null || _b === void 0 ? void 0 : _b.value : currCountry;
155
+ // update required visual cue on postal code
156
+ if (this.selectedCountry === 'US') {
157
+ (_c = this.postalBadgedInput) === null || _c === void 0 ? void 0 : _c.setAttribute('required', '');
158
+ (_d = this.postalCodeField) === null || _d === void 0 ? void 0 : _d.setAttribute('required', '');
159
+ }
160
+ else {
161
+ (_e = this.postalBadgedInput) === null || _e === void 0 ? void 0 : _e.removeAttribute('required');
162
+ (_f = this.postalCodeField) === null || _f === void 0 ? void 0 : _f.removeAttribute('required');
163
+ }
164
+ }}>
147
165
  ${Object.keys(countries).map(key => {
148
166
  const name = countries[key];
149
167
  return html `
150
- <option value=${key} ?selected=${key === selectedCountry}>${name}</option>
168
+ <option value=${key} ?selected=${key === this.selectedCountry}>${name}</option>
151
169
  `;
152
170
  })}
153
171
  </select>
@@ -397,6 +415,9 @@ __decorate([
397
415
  __decorate([
398
416
  query('form')
399
417
  ], ContactForm.prototype, "form", void 0);
418
+ __decorate([
419
+ property({ type: String })
420
+ ], ContactForm.prototype, "selectedCountry", void 0);
400
421
  ContactForm = __decorate([
401
422
  customElement('contact-form')
402
423
  ], ContactForm);
@@ -1 +1 @@
1
- {"version":3,"file":"contact-form.js","sourceRoot":"","sources":["../../../../src/form-elements/contact-form/contact-form.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAkB,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,gBAAgB,GACjB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,iBAAiB,CAAC;AAEzB,OAAO,QAAQ,MAAM,6BAA6B,CAAC;AACnD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tC,KAAK,CAAC,8BAA8B,CAAC;+CAA+B;AAEb;IAAvD,KAAK,CAAC,+CAA+C,CAAC;yDAAoC;AAC/C;IAA3C,KAAK,CAAC,mCAAmC,CAAC;mDAAmC;AAEvB;IAAtD,KAAK,CAAC,8CAA8C,CAAC;wDAAmC;AAC9C;IAA1C,KAAK,CAAC,kCAAkC,CAAC;kDAAkC;AAEnB;IAAxD,KAAK,CAAC,gDAAgD,CAAC;sDAAiC;AAC5C;IAA5C,KAAK,CAAC,oCAAoC,CAAC;oDAAoC;AAGhF;IADC,KAAK,CAAC,mDAAmD,CAAC;6DACpB;AACS;IAA/C,KAAK,CAAC,uCAAuC,CAAC;uDAAuC;AAGtF;IADC,KAAK,CAAC,qDAAqD,CAAC;+DACpB;AACS;IAAjD,KAAK,CAAC,yCAAyC,CAAC;yDAAyC;AAEpC;IAArD,KAAK,CAAC,6CAA6C,CAAC;wDAAmC;AAC9C;IAAzC,KAAK,CAAC,iCAAiC,CAAC;kDAAkC;AAEvB;IAAnD,KAAK,CAAC,2CAA2C,CAAC;sDAAiC;AAC5C;IAAvC,KAAK,CAAC,+BAA+B,CAAC;gDAAgC;AAEpB;IAAlD,KAAK,CAAC,0CAA0C,CAAC;2DAA4C;AAE/C;IAA9C,KAAK,CAAC,sCAAsC,CAAC;iDAA+B;AAC9D;IAAd,KAAK,CAAC,MAAM,CAAC;yCAAwB;AA9B3B,WAAW;IADvB,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CAoYvB;SApYY,WAAW","sourcesContent":["import { LitElement, html, css, TemplateResult } from 'lit';\nimport { customElement, query } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport {\n BillingInfo,\n CustomerInfo,\n DonorContactInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { AutoCompleteFieldOptions } from './autocomplete-field-options';\nimport { SpacerOption } from '../badged-input';\nimport { BadgedInput } from '../badged-input';\nimport '../badged-input';\n\nimport emailImg from '@internetarchive/icon-email';\nimport localePinImg from '@internetarchive/icon-locale-pin';\nimport userIcon from '@internetarchive/icon-user';\n\nimport { countries } from './countries';\n\n@customElement('contact-form')\nexport class ContactForm extends LitElement {\n @query('badged-input.donation-contact-form-email') emailBadgedInput!: BadgedInput;\n @query('#donation-contact-form-email') emailField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-first-name') firstNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-first-name') firstNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-last-name') lastNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-last-name') lastNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-postal-code') postalBadgedInput!: BadgedInput;\n @query('#donation-contact-form-postal-code') postalCodeField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-street-address')\n streetAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-street-address') streetAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-extended-address')\n extendedAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-extended-address') extendedAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-locality') localityBadgedInput!: BadgedInput;\n @query('#donation-contact-form-locality') localityField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-region') regionBadgedInput!: BadgedInput;\n @query('#donation-contact-form-region') regionField!: HTMLInputElement;\n\n @query('#donation-contact-form-countryCodeAlpha2') countryCodeAlpha2Field!: HTMLSelectElement;\n\n @query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;\n @query('form') form!: HTMLFormElement;\n\n reportValidity(): boolean {\n const fieldBadgedInputs: Array<[HTMLInputElement, BadgedInput]> = [\n [this.emailField, this.emailBadgedInput],\n [this.firstNameField, this.firstNameBadgedInput],\n [this.lastNameField, this.lastNameBadgedInput],\n [this.regionField, this.regionBadgedInput],\n [this.localityField, this.localityBadgedInput],\n [this.streetAddressField, this.streetAddressBadgedInput],\n [this.postalCodeField, this.postalBadgedInput],\n ];\n\n let isValid = true;\n fieldBadgedInputs.forEach(([inputElement, badgedInput]) => {\n const fieldValid = inputElement.checkValidity();\n isValid = isValid && fieldValid;\n if (!fieldValid) {\n badgedInput.error = true;\n }\n });\n\n if (!isValid) {\n this.errorMessage.innerText = 'Please enter any missing contact information below';\n } else {\n this.errorMessage.innerText = '';\n }\n\n return isValid;\n }\n\n focus(): void {\n this.emailField.focus();\n }\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <div id=\"donation-contact-form-error-message\"></div>\n <form>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-email',\n placeholder: 'Email',\n required: true,\n fieldType: 'email',\n name: 'email',\n autocomplete: 'email',\n maxlength: 255,\n icon: emailImg,\n })}\n </div>\n </fieldset>\n\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-first-name',\n placeholder: 'First name',\n name: 'fname',\n required: true,\n maxlength: 255,\n autocomplete: 'given-name',\n icon: userIcon,\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-last-name',\n placeholder: 'Last name',\n name: 'lname',\n autocomplete: 'family-name',\n required: true,\n maxlength: 255,\n })}\n </div>\n </fieldset>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-street-address',\n placeholder: 'Address Line 1',\n required: true,\n autocomplete: 'address-line1',\n icon: localePinImg,\n name: 'street-address',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-extended-address',\n placeholder: 'Address Line 2 (optional)',\n autocomplete: 'address-line2',\n required: false,\n name: 'extended-address',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-locality',\n placeholder: 'City',\n autocomplete: 'address-level2',\n required: true,\n name: 'locality',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-region',\n placeholder: 'State / Province',\n autocomplete: 'address-level1',\n required: true,\n name: 'region',\n })}\n ${this.generateInput({\n id: 'donation-contact-form-postal-code',\n placeholder: 'Zip / Postal',\n autocomplete: 'postal-code',\n required: true,\n name: 'postal',\n maxlength: 9,\n // must start with a character, then may contain spaces\n validationPattern: '[a-zA-Z\\\\-\\\\d]+[a-zA-Z\\\\-\\\\d\\\\s]*',\n iconSpaceOption: SpacerOption.CompressSpace,\n })}\n </div>\n <div class=\"row\">\n ${this.countrySelectorTemplate}\n </div>\n </fieldset>\n </form>\n ${this.getStyles}\n `;\n }\n\n private get countrySelectorTemplate(): TemplateResult {\n const selectedCountry = 'US';\n\n return html`\n <badged-input>\n <select id=\"donation-contact-form-countryCodeAlpha2\">\n ${Object.keys(countries).map(key => {\n const name = countries[key];\n return html`\n <option value=${key} ?selected=${key === selectedCountry}>${name}</option>\n `;\n })}\n </select>\n </badged-input>\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 // Form autofill does not work properly in the shadow DOM\n // so we need our form fields in the light DOM\n return this;\n }\n\n // reset the error state when the user focuses the input\n private inputFocused(e: KeyboardEvent): void {\n this.errorMessage.innerText = '';\n const input = e.target as HTMLInputElement;\n const inputIdentifier = input.id;\n const badgedInput = this.querySelector(`badged-input.${inputIdentifier}`) as BadgedInput;\n badgedInput.error = false;\n }\n\n private generateInput(options: {\n id: string;\n placeholder: string;\n required?: boolean;\n fieldType?: 'text' | 'email';\n autocomplete?: AutoCompleteFieldOptions;\n maxlength?: number;\n name: string;\n icon?: TemplateResult;\n iconSpaceOption?: SpacerOption;\n validationPattern?: string;\n }): TemplateResult {\n const required = options.required ?? true;\n const fieldType = options.fieldType ?? 'text';\n const iconOption = options.iconSpaceOption ?? SpacerOption.LeaveSpace;\n\n return html`\n <badged-input\n class=${options.id}\n .icon=${options.icon}\n .iconSpaceOption=${iconOption}\n ?required=${options.required}\n >\n <label for=${options.id}>${options.placeholder}</label>\n <input\n type=${fieldType}\n id=${options.id}\n class=\"donation-contact-form-input\"\n name=${options.name}\n aria-label=${options.placeholder}\n placeholder=${options.placeholder}\n maxlength=${ifDefined(options.maxlength)}\n autocomplete=${options.autocomplete ?? 'on'}\n pattern=${ifDefined(options.validationPattern)}\n @focus=${this.inputFocused}\n ?required=${required}\n />\n </badged-input>\n `;\n }\n\n get donorContactInfo(): DonorContactInfo {\n return new DonorContactInfo({\n billing: this.billingInfo,\n customer: this.contactInfo,\n });\n }\n\n get billingInfo(): BillingInfo {\n const billingInfo = new BillingInfo({\n streetAddress: this.streetAddressField.value,\n extendedAddress: this.extendedAddressField.value,\n locality: this.localityField.value,\n region: this.regionField.value,\n postalCode: this.postalCodeField.value,\n countryCodeAlpha2: this.countryCodeAlpha2Field.value,\n });\n return billingInfo;\n }\n\n get contactInfo(): CustomerInfo {\n return new CustomerInfo({\n email: this.emailField.value,\n firstName: this.firstNameField.value,\n lastName: this.lastNameField.value,\n });\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 so 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 ContactForm\n */\n private get getStyles(): TemplateResult {\n const noIconSpacerWidth = css`var(--badgedInputNoIconSpacerWidth, 3rem)`;\n const iconSpacerWidth = css`var(--badgedInputIconSpacerWidth, 5rem)`;\n\n const fieldSetSpacing = css`var(--fieldSetSpacing, 1rem)`;\n const fieldFontFamily = css`var(--fontFamily, \"Helvetica Neue\", Helvetica, Arial, sans-serif)`;\n const fieldFontSize = css`var(--contactFieldFontSize, 1.6rem)`;\n const fieldFontColor = css`var(--inputFieldFontColor, #333)`;\n\n const iconFieldWidth = css`calc(100% - ${iconSpacerWidth})`;\n const noIconFieldWidth = css`calc(100% - ${noIconSpacerWidth})`;\n\n return html`\n <style>\n /*\n **NOTE**\n This element is in the lightDOM so be sure to prefix all styles\n with \"contact-form\" so styles don't leak.\n */\n contact-form fieldset {\n border: 0;\n padding: 0;\n margin: 0;\n margin-bottom: ${fieldSetSpacing};\n background-color: white;\n }\n\n /* These 1px and 0 margins in the next few selectors are to account for the\n double outlines caused by the fields being right next to each other */\n contact-form .row {\n display: flex;\n margin: -1px 0 0 0;\n }\n\n contact-form fieldset .row:first-child {\n margin-top: 0;\n }\n\n contact-form badged-input.donation-contact-form-region {\n width: 60%;\n }\n\n contact-form badged-input.donation-contact-form-postal-code {\n width: 40%;\n }\n\n contact-form #donation-contact-form-region {\n width: ${iconFieldWidth};\n }\n\n contact-form #donation-contact-form-postal-code {\n width: ${noIconFieldWidth};\n }\n\n contact-form #donation-contact-form-error-message {\n color: red;\n font-size: 1.4rem;\n margin-bottom: 0.6rem;\n }\n\n contact-form #donation-contact-form-last-name {\n width: ${noIconFieldWidth};\n }\n\n /* only show for screen readers */\n contact-form label {\n position: absolute;\n left: -10000px;\n top: auto;\n width: 1px;\n height: 1px;\n overflow: hidden;\n }\n\n contact-form .donation-contact-form-input {\n width: ${iconFieldWidth};\n border: 0;\n outline: 0;\n background: transparent;\n font-weight: bold;\n color: ${fieldFontColor};\n font-size: ${fieldFontSize};\n padding: 0;\n font-family: ${fieldFontFamily};\n }\n\n contact-form .donation-contact-form-input::placeholder {\n color: revert;\n }\n\n contact-form #donation-contact-form-countryCodeAlpha2 {\n width: ${iconFieldWidth};\n height: 100%;\n box-sizing: border-box;\n font-weight: bold;\n font-size: ${fieldFontSize};\n font-family: ${fieldFontFamily};\n border: 0;\n background: #fff;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n }\n </style>\n `;\n }\n}\n"]}
1
+ {"version":3,"file":"contact-form.js","sourceRoot":"","sources":["../../../../src/form-elements/contact-form/contact-form.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAkB,MAAM,KAAK,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,K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KAAK,CAAC,oCAAoC,CAAC;oDAAoC;AAGhF;IADC,KAAK,CAAC,mDAAmD,CAAC;6DACpB;AACS;IAA/C,KAAK,CAAC,uCAAuC,CAAC;uDAAuC;AAGtF;IADC,KAAK,CAAC,qDAAqD,CAAC;+DACpB;AACS;IAAjD,KAAK,CAAC,yCAAyC,CAAC;yDAAyC;AAEpC;IAArD,KAAK,CAAC,6CAA6C,CAAC;wDAAmC;AAC9C;IAAzC,KAAK,CAAC,iCAAiC,CAAC;kDAAkC;AAEvB;IAAnD,KAAK,CAAC,2CAA2C,CAAC;sDAAiC;AAC5C;IAAvC,KAAK,CAAC,+BAA+B,CAAC;gDAAgC;AAEpB;IAAlD,KAAK,CAAC,0CAA0C,CAAC;2DAA4C;AAE/C;IAA9C,KAAK,CAAC,sCAAsC,CAAC;iDAA+B;AAC9D;IAAd,KAAK,CAAC,MAAM,CAAC;yCAAwB;AAGV;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDAAgC;AAjChD,WAAW;IADvB,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CAiZvB;SAjZY,WAAW","sourcesContent":["import { LitElement, html, css, TemplateResult } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport {\n BillingInfo,\n CustomerInfo,\n DonorContactInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { AutoCompleteFieldOptions } from './autocomplete-field-options';\nimport { SpacerOption } from '../badged-input';\nimport { BadgedInput } from '../badged-input';\nimport '../badged-input';\n\nimport emailImg from '@internetarchive/icon-email';\nimport localePinImg from '@internetarchive/icon-locale-pin';\nimport userIcon from '@internetarchive/icon-user';\n\nimport { countries } from './countries';\n\n@customElement('contact-form')\nexport class ContactForm extends LitElement {\n @query('badged-input.donation-contact-form-email') emailBadgedInput!: BadgedInput;\n @query('#donation-contact-form-email') emailField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-first-name') firstNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-first-name') firstNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-last-name') lastNameBadgedInput!: BadgedInput;\n @query('#donation-contact-form-last-name') lastNameField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-postal-code') postalBadgedInput!: BadgedInput;\n @query('#donation-contact-form-postal-code') postalCodeField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-street-address')\n streetAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-street-address') streetAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-extended-address')\n extendedAddressBadgedInput!: BadgedInput;\n @query('#donation-contact-form-extended-address') extendedAddressField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-locality') localityBadgedInput!: BadgedInput;\n @query('#donation-contact-form-locality') localityField!: HTMLInputElement;\n\n @query('badged-input.donation-contact-form-region') regionBadgedInput!: BadgedInput;\n @query('#donation-contact-form-region') regionField!: HTMLInputElement;\n\n @query('#donation-contact-form-countryCodeAlpha2') countryCodeAlpha2Field!: HTMLSelectElement;\n\n @query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;\n @query('form') form!: HTMLFormElement;\n\n /** @keyof countries */\n @property({ type: String }) selectedCountry: string = 'US';\n\n reportValidity(): boolean {\n const fieldBadgedInputs: Array<[HTMLInputElement, BadgedInput]> = [\n [this.emailField, this.emailBadgedInput],\n [this.firstNameField, this.firstNameBadgedInput],\n [this.lastNameField, this.lastNameBadgedInput],\n [this.regionField, this.regionBadgedInput],\n [this.localityField, this.localityBadgedInput],\n [this.streetAddressField, this.streetAddressBadgedInput],\n [this.postalCodeField, this.postalBadgedInput],\n ];\n\n let isValid = true;\n fieldBadgedInputs.forEach(([inputElement, badgedInput]) => {\n const fieldValid = inputElement.checkValidity();\n isValid = isValid && fieldValid;\n if (!fieldValid) {\n badgedInput.error = true;\n }\n });\n\n if (!isValid) {\n this.errorMessage.innerText = 'Please enter any missing contact information below';\n } else {\n this.errorMessage.innerText = '';\n }\n\n return isValid;\n }\n\n focus(): void {\n this.emailField.focus();\n }\n\n /** @inheritdoc */\n render(): TemplateResult {\n return html`\n <div id=\"donation-contact-form-error-message\"></div>\n <form>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-email',\n placeholder: 'Email',\n required: true,\n fieldType: 'email',\n name: 'email',\n autocomplete: 'email',\n maxlength: 255,\n icon: emailImg,\n })}\n </div>\n </fieldset>\n\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-first-name',\n placeholder: 'First name',\n name: 'fname',\n required: true,\n maxlength: 255,\n autocomplete: 'given-name',\n icon: userIcon,\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-last-name',\n placeholder: 'Last name',\n name: 'lname',\n autocomplete: 'family-name',\n required: true,\n maxlength: 255,\n })}\n </div>\n </fieldset>\n <fieldset>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-street-address',\n placeholder: 'Address Line 1',\n required: true,\n autocomplete: 'address-line1',\n icon: localePinImg,\n name: 'street-address',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-extended-address',\n placeholder: 'Address Line 2 (optional)',\n autocomplete: 'address-line2',\n required: false,\n name: 'extended-address',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-locality',\n placeholder: 'City',\n autocomplete: 'address-level2',\n required: true,\n name: 'locality',\n })}\n </div>\n <div class=\"row\">\n ${this.generateInput({\n id: 'donation-contact-form-region',\n placeholder: 'State / Province',\n autocomplete: 'address-level1',\n required: true,\n name: 'region',\n })}\n ${this.generateInput({\n id: 'donation-contact-form-postal-code',\n placeholder: 'Zip / Postal',\n autocomplete: 'postal-code',\n required: true,\n name: 'postal',\n maxlength: 9,\n // must start with a character, then may contain spaces\n validationPattern: '[a-zA-Z\\\\-\\\\d]+[a-zA-Z\\\\-\\\\d\\\\s]*',\n iconSpaceOption: SpacerOption.CompressSpace,\n })}\n </div>\n <div class=\"row\">\n ${this.countrySelectorTemplate}\n </div>\n </fieldset>\n </form>\n ${this.getStyles}\n `;\n }\n\n private get countrySelectorTemplate(): TemplateResult {\n return html`\n <badged-input>\n <select id=\"donation-contact-form-countryCodeAlpha2\"\n @change=${(e: Event) => {\n const currCountry = this.selectedCountry;\n this.selectedCountry = (e.target as HTMLInputElement)?.value ? (e.target as HTMLInputElement)?.value as string : currCountry;\n // update required visual cue on postal code\n if (this.selectedCountry === 'US') {\n this.postalBadgedInput?.setAttribute('required', '');\n this.postalCodeField?.setAttribute('required', '');\n } else {\n this.postalBadgedInput?.removeAttribute('required');\n this.postalCodeField?.removeAttribute('required');\n }\n }}>\n ${Object.keys(countries).map(key => {\n const name = countries[key];\n return html`\n <option value=${key} ?selected=${key === this.selectedCountry}>${name}</option>\n `;\n })}\n </select>\n </badged-input>\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 // Form autofill does not work properly in the shadow DOM\n // so we need our form fields in the light DOM\n return this;\n }\n\n // reset the error state when the user focuses the input\n private inputFocused(e: KeyboardEvent): void {\n this.errorMessage.innerText = '';\n const input = e.target as HTMLInputElement;\n const inputIdentifier = input.id;\n const badgedInput = this.querySelector(`badged-input.${inputIdentifier}`) as BadgedInput;\n badgedInput.error = false;\n }\n\n private generateInput(options: {\n id: string;\n placeholder: string;\n required?: boolean;\n fieldType?: 'text' | 'email';\n autocomplete?: AutoCompleteFieldOptions;\n maxlength?: number;\n name: string;\n icon?: TemplateResult;\n iconSpaceOption?: SpacerOption;\n validationPattern?: string;\n }): TemplateResult {\n const required = options.required ?? true;\n const fieldType = options.fieldType ?? 'text';\n const iconOption = options.iconSpaceOption ?? SpacerOption.LeaveSpace;\n\n return html`\n <badged-input\n class=${options.id}\n .icon=${options.icon}\n .iconSpaceOption=${iconOption}\n ?required=${options.required}\n >\n <label for=${options.id}>${options.placeholder}</label>\n <input\n type=${fieldType}\n id=${options.id}\n class=\"donation-contact-form-input\"\n name=${options.name}\n aria-label=${options.placeholder}\n placeholder=${options.placeholder}\n maxlength=${ifDefined(options.maxlength)}\n autocomplete=${options.autocomplete ?? 'on'}\n pattern=${ifDefined(options.validationPattern)}\n @focus=${this.inputFocused}\n ?required=${required}\n />\n </badged-input>\n `;\n }\n\n get donorContactInfo(): DonorContactInfo {\n return new DonorContactInfo({\n billing: this.billingInfo,\n customer: this.contactInfo,\n });\n }\n\n get billingInfo(): BillingInfo {\n const billingInfo = new BillingInfo({\n streetAddress: this.streetAddressField.value,\n extendedAddress: this.extendedAddressField.value,\n locality: this.localityField.value,\n region: this.regionField.value,\n postalCode: this.postalCodeField.value,\n countryCodeAlpha2: this.countryCodeAlpha2Field.value,\n });\n return billingInfo;\n }\n\n get contactInfo(): CustomerInfo {\n return new CustomerInfo({\n email: this.emailField.value,\n firstName: this.firstNameField.value,\n lastName: this.lastNameField.value,\n });\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 so 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 ContactForm\n */\n private get getStyles(): TemplateResult {\n const noIconSpacerWidth = css`var(--badgedInputNoIconSpacerWidth, 3rem)`;\n const iconSpacerWidth = css`var(--badgedInputIconSpacerWidth, 5rem)`;\n\n const fieldSetSpacing = css`var(--fieldSetSpacing, 1rem)`;\n const fieldFontFamily = css`var(--fontFamily, \"Helvetica Neue\", Helvetica, Arial, sans-serif)`;\n const fieldFontSize = css`var(--contactFieldFontSize, 1.6rem)`;\n const fieldFontColor = css`var(--inputFieldFontColor, #333)`;\n\n const iconFieldWidth = css`calc(100% - ${iconSpacerWidth})`;\n const noIconFieldWidth = css`calc(100% - ${noIconSpacerWidth})`;\n\n return html`\n <style>\n /*\n **NOTE**\n This element is in the lightDOM so be sure to prefix all styles\n with \"contact-form\" so styles don't leak.\n */\n contact-form fieldset {\n border: 0;\n padding: 0;\n margin: 0;\n margin-bottom: ${fieldSetSpacing};\n background-color: white;\n }\n\n /* These 1px and 0 margins in the next few selectors are to account for the\n double outlines caused by the fields being right next to each other */\n contact-form .row {\n display: flex;\n margin: -1px 0 0 0;\n }\n\n contact-form fieldset .row:first-child {\n margin-top: 0;\n }\n\n contact-form badged-input.donation-contact-form-region {\n width: 60%;\n }\n\n contact-form badged-input.donation-contact-form-postal-code {\n width: 40%;\n }\n\n contact-form #donation-contact-form-region {\n width: ${iconFieldWidth};\n }\n\n contact-form #donation-contact-form-postal-code {\n width: ${noIconFieldWidth};\n }\n\n contact-form #donation-contact-form-error-message {\n color: red;\n font-size: 1.4rem;\n margin-bottom: 0.6rem;\n }\n\n contact-form #donation-contact-form-last-name {\n width: ${noIconFieldWidth};\n }\n\n /* only show for screen readers */\n contact-form label {\n position: absolute;\n left: -10000px;\n top: auto;\n width: 1px;\n height: 1px;\n overflow: hidden;\n }\n\n contact-form .donation-contact-form-input {\n width: ${iconFieldWidth};\n border: 0;\n outline: 0;\n background: transparent;\n font-weight: bold;\n color: ${fieldFontColor};\n font-size: ${fieldFontSize};\n padding: 0;\n font-family: ${fieldFontFamily};\n }\n\n contact-form .donation-contact-form-input::placeholder {\n color: revert;\n }\n\n contact-form #donation-contact-form-countryCodeAlpha2 {\n width: ${iconFieldWidth};\n height: 100%;\n box-sizing: border-box;\n font-weight: bold;\n font-size: ${fieldFontSize};\n font-family: ${fieldFontFamily};\n border: 0;\n background: #fff;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n }\n </style>\n `;\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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iB,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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AE,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';\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-a1",
3
+ "version": "0.5.17-a1",
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.2",
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 {
@@ -165,10 +165,6 @@ export class BraintreeManager implements BraintreeManagerInterface {
165
165
  successResponse: SuccessResponse;
166
166
  upsellSuccessResponse?: SuccessResponse;
167
167
  }): void {
168
-
169
-
170
-
171
-
172
168
  this.endpointManager.donationSuccessful(options);
173
169
  }
174
170
 
@@ -1,5 +1,5 @@
1
1
  import { LitElement, html, css, TemplateResult } from 'lit';
2
- import { customElement, query } from 'lit/decorators.js';
2
+ import { customElement, property, query } from 'lit/decorators.js';
3
3
  import { ifDefined } from 'lit/directives/if-defined.js';
4
4
 
5
5
  import {
@@ -51,6 +51,9 @@ export class ContactForm extends LitElement {
51
51
  @query('#donation-contact-form-error-message') errorMessage!: HTMLDivElement;
52
52
  @query('form') form!: HTMLFormElement;
53
53
 
54
+ /** @keyof countries */
55
+ @property({ type: String }) selectedCountry: string = 'US';
56
+
54
57
  reportValidity(): boolean {
55
58
  const fieldBadgedInputs: Array<[HTMLInputElement, BadgedInput]> = [
56
59
  [this.emailField, this.emailBadgedInput],
@@ -186,15 +189,25 @@ export class ContactForm extends LitElement {
186
189
  }
187
190
 
188
191
  private get countrySelectorTemplate(): TemplateResult {
189
- const selectedCountry = 'US';
190
-
191
192
  return html`
192
193
  <badged-input>
193
- <select id="donation-contact-form-countryCodeAlpha2">
194
+ <select id="donation-contact-form-countryCodeAlpha2"
195
+ @change=${(e: Event) => {
196
+ const currCountry = this.selectedCountry;
197
+ this.selectedCountry = (e.target as HTMLInputElement)?.value ? (e.target as HTMLInputElement)?.value as string : currCountry;
198
+ // update required visual cue on postal code
199
+ if (this.selectedCountry === 'US') {
200
+ this.postalBadgedInput?.setAttribute('required', '');
201
+ this.postalCodeField?.setAttribute('required', '');
202
+ } else {
203
+ this.postalBadgedInput?.removeAttribute('required');
204
+ this.postalCodeField?.removeAttribute('required');
205
+ }
206
+ }}>
194
207
  ${Object.keys(countries).map(key => {
195
208
  const name = countries[key];
196
209
  return html`
197
- <option value=${key} ?selected=${key === selectedCountry}>${name}</option>
210
+ <option value=${key} ?selected=${key === this.selectedCountry}>${name}</option>
198
211
  `;
199
212
  })}
200
213
  </select>
@@ -417,11 +417,6 @@ export class DonationFlowModalManager implements DonationFlowModalManagerInterfa
417
417
  }
418
418
 
419
419
  /** @inheritdoc */
420
-
421
-
422
-
423
-
424
-
425
420
  handleSuccessfulDonationResponse(
426
421
  donationInfo: DonationPaymentInfo,
427
422
  response: SuccessResponse,