@internetarchive/donation-form 1.0.3-webdev-8122.0 → 1.0.3-webdev-8114.0

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.
@@ -22,7 +22,6 @@ export declare class ContactForm extends LitElement {
22
22
  countryCodeAlpha2Field: HTMLSelectElement;
23
23
  errorMessage: HTMLDivElement;
24
24
  form: HTMLFormElement;
25
- /** @keyof countries */
26
25
  selectedCountry: string;
27
26
  donorEmail: string;
28
27
  updated(changed: PropertyValues): void;
@@ -30,6 +29,7 @@ export declare class ContactForm extends LitElement {
30
29
  focus(): void;
31
30
  /** @inheritdoc */
32
31
  render(): TemplateResult;
32
+ private get regionAndPostalCodeRequired();
33
33
  private get countrySelectorTemplate();
34
34
  /** @inheritdoc */
35
35
  createRenderRoot(): this;
@@ -12,7 +12,6 @@ import { countries } from './countries';
12
12
  let ContactForm = class ContactForm extends LitElement {
13
13
  constructor() {
14
14
  super(...arguments);
15
- /** @keyof countries */
16
15
  this.selectedCountry = 'US';
17
16
  this.donorEmail = '';
18
17
  }
@@ -41,7 +40,7 @@ let ContactForm = class ContactForm extends LitElement {
41
40
  }
42
41
  });
43
42
  if (!isValid) {
44
- this.errorMessage.innerText = 'Please enter any missing contact information below';
43
+ this.errorMessage.innerText = 'Please enter any missing or invalid contact information below';
45
44
  }
46
45
  else {
47
46
  this.errorMessage.innerText = '';
@@ -65,6 +64,7 @@ let ContactForm = class ContactForm extends LitElement {
65
64
  fieldType: 'email',
66
65
  name: 'email',
67
66
  autocomplete: 'email',
67
+ minlength: 5,
68
68
  maxlength: 255,
69
69
  icon: emailImg,
70
70
  })}
@@ -78,6 +78,7 @@ let ContactForm = class ContactForm extends LitElement {
78
78
  placeholder: 'First name',
79
79
  name: 'fname',
80
80
  required: true,
81
+ validationPattern: '.*\\S{2,}.*',
81
82
  maxlength: 255,
82
83
  autocomplete: 'given-name',
83
84
  icon: userIcon,
@@ -90,6 +91,7 @@ let ContactForm = class ContactForm extends LitElement {
90
91
  name: 'lname',
91
92
  autocomplete: 'family-name',
92
93
  required: true,
94
+ validationPattern: '.*\\S{2,}.*',
93
95
  maxlength: 255,
94
96
  })}
95
97
  </div>
@@ -103,6 +105,7 @@ let ContactForm = class ContactForm extends LitElement {
103
105
  autocomplete: 'address-line1',
104
106
  icon: localePinImg,
105
107
  name: 'street-address',
108
+ validationPattern: '.*?\\S.{2,}\\S.*?',
106
109
  })}
107
110
  </div>
108
111
  <div class="row">
@@ -121,6 +124,7 @@ let ContactForm = class ContactForm extends LitElement {
121
124
  autocomplete: 'address-level2',
122
125
  required: true,
123
126
  name: 'locality',
127
+ validationPattern: '.*\\S{2,}.*',
124
128
  })}
125
129
  </div>
126
130
  <div class="row">
@@ -128,15 +132,17 @@ let ContactForm = class ContactForm extends LitElement {
128
132
  id: 'donation-contact-form-region',
129
133
  placeholder: 'State / Province',
130
134
  autocomplete: 'address-level1',
131
- required: true,
135
+ required: this.regionAndPostalCodeRequired,
132
136
  name: 'region',
137
+ validationPattern: '.*\\S{2,}.*',
133
138
  })}
134
139
  ${this.generateInput({
135
140
  id: 'donation-contact-form-postal-code',
136
141
  placeholder: 'Zip / Postal',
137
142
  autocomplete: 'postal-code',
138
- required: true,
143
+ required: this.regionAndPostalCodeRequired,
139
144
  name: 'postal',
145
+ minlength: 5,
140
146
  maxlength: 9,
141
147
  // must start with a character, then may contain spaces
142
148
  validationPattern: '[a-zA-Z\\-\\d]+[a-zA-Z\\-\\d\\s]*',
@@ -149,30 +155,18 @@ let ContactForm = class ContactForm extends LitElement {
149
155
  ${this.getStyles}
150
156
  `;
151
157
  }
158
+ get regionAndPostalCodeRequired() {
159
+ return this.selectedCountry === 'US';
160
+ }
152
161
  get countrySelectorTemplate() {
153
162
  return html `
154
163
  <badged-input>
155
164
  <select
156
165
  id="donation-contact-form-countryCodeAlpha2"
157
166
  @change=${(e) => {
158
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
159
- const currCountry = this.selectedCountry;
160
- this.selectedCountry = ((_a = e.target) === null || _a === void 0 ? void 0 : _a.value)
161
- ? (_b = e.target) === null || _b === void 0 ? void 0 : _b.value
162
- : currCountry;
163
- // update required visual cue on region/state/province & postal code fields
164
- if (this.selectedCountry === 'US') {
165
- (_c = this.postalBadgedInput) === null || _c === void 0 ? void 0 : _c.setAttribute('required', '');
166
- (_d = this.postalCodeField) === null || _d === void 0 ? void 0 : _d.setAttribute('required', '');
167
- (_e = this.regionBadgedInput) === null || _e === void 0 ? void 0 : _e.setAttribute('required', '');
168
- (_f = this.regionField) === null || _f === void 0 ? void 0 : _f.setAttribute('required', '');
169
- }
170
- else {
171
- (_g = this.postalBadgedInput) === null || _g === void 0 ? void 0 : _g.removeAttribute('required');
172
- (_h = this.postalCodeField) === null || _h === void 0 ? void 0 : _h.removeAttribute('required');
173
- (_j = this.regionBadgedInput) === null || _j === void 0 ? void 0 : _j.removeAttribute('required');
174
- (_k = this.regionField) === null || _k === void 0 ? void 0 : _k.removeAttribute('required');
175
- }
167
+ const newValue = e.target.value;
168
+ if (countries[newValue])
169
+ this.selectedCountry = newValue;
176
170
  }}
177
171
  >
178
172
  ${Object.keys(countries).map(key => {
@@ -222,6 +216,7 @@ let ContactForm = class ContactForm extends LitElement {
222
216
  aria-label=${options.placeholder}
223
217
  placeholder=${options.placeholder}
224
218
  maxlength=${ifDefined(options.maxlength)}
219
+ minlength=${ifDefined(options.minlength)}
225
220
  autocomplete=${(_d = options.autocomplete) !== null && _d !== void 0 ? _d : 'on'}
226
221
  pattern=${ifDefined(options.validationPattern)}
227
222
  @focus=${this.inputFocused}
@@ -238,8 +233,6 @@ let ContactForm = class ContactForm extends LitElement {
238
233
  }
239
234
  get billingInfo() {
240
235
  const billingInfo = new BillingInfo({
241
- firstName: this.firstNameField.value,
242
- lastName: this.lastNameField.value,
243
236
  streetAddress: this.streetAddressField.value,
244
237
  extendedAddress: this.extendedAddressField.value,
245
238
  locality: this.localityField.value,
@@ -1 +1 @@
1
- {"version":3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AAkC;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;oDAAwB;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAiB;AAnCjC,WAAW;IADvB,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CA8ZvB","sourcesContent":["import { LitElement, html, css, TemplateResult, PropertyValues } 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/index.js';\nimport localePinImg from '@internetarchive/icon-locale-pin/index.js';\nimport userIcon from '@internetarchive/icon-user/index.js';\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 = 'US';\n\n @property({ type: String }) donorEmail = '';\n\n updated(changed: PropertyValues): void {\n if (changed.has('donorEmail')) {\n this.emailField.value = this.donorEmail ?? '';\n }\n }\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\">${this.countrySelectorTemplate}</div>\n </fieldset>\n </form>\n ${this.getStyles}\n `;\n }\n\n private get countrySelectorTemplate(): TemplateResult {\n return html`\n <badged-input>\n <select\n id=\"donation-contact-form-countryCodeAlpha2\"\n @change=${(e: Event) => {\n const currCountry = this.selectedCountry;\n this.selectedCountry = (e.target as HTMLInputElement)?.value\n ? ((e.target as HTMLInputElement)?.value as string)\n : currCountry;\n // update required visual cue on region/state/province & postal code fields\n if (this.selectedCountry === 'US') {\n this.postalBadgedInput?.setAttribute('required', '');\n this.postalCodeField?.setAttribute('required', '');\n this.regionBadgedInput?.setAttribute('required', '');\n this.regionField?.setAttribute('required', '');\n } else {\n this.postalBadgedInput?.removeAttribute('required');\n this.postalCodeField?.removeAttribute('required');\n this.regionBadgedInput?.removeAttribute('required');\n this.regionField?.removeAttribute('required');\n }\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 firstName: this.firstNameField.value,\n lastName: this.lastNameField.value,\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: calc(100%);\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 }\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,EAAkC,MAAM,KAAK,CA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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;AAEV;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDAAwB;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAiB;AAlCjC,WAAW;IADvB,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CA0ZvB","sourcesContent":["import { LitElement, html, css, TemplateResult, PropertyValues } 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/index.js';\nimport localePinImg from '@internetarchive/icon-locale-pin/index.js';\nimport userIcon from '@internetarchive/icon-user/index.js';\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 @property({ type: String }) selectedCountry = 'US';\n\n @property({ type: String }) donorEmail = '';\n\n updated(changed: PropertyValues): void {\n if (changed.has('donorEmail')) {\n this.emailField.value = this.donorEmail ?? '';\n }\n }\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 or invalid 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 minlength: 5,\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 validationPattern: '.*\\\\S{2,}.*',\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 validationPattern: '.*\\\\S{2,}.*',\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 validationPattern: '.*?\\\\S.{2,}\\\\S.*?',\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 validationPattern: '.*\\\\S{2,}.*',\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: this.regionAndPostalCodeRequired,\n name: 'region',\n validationPattern: '.*\\\\S{2,}.*',\n })}\n ${this.generateInput({\n id: 'donation-contact-form-postal-code',\n placeholder: 'Zip / Postal',\n autocomplete: 'postal-code',\n required: this.regionAndPostalCodeRequired,\n name: 'postal',\n minlength: 5,\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\">${this.countrySelectorTemplate}</div>\n </fieldset>\n </form>\n ${this.getStyles}\n `;\n }\n\n private get regionAndPostalCodeRequired(): boolean {\n return this.selectedCountry === 'US';\n }\n\n private get countrySelectorTemplate(): TemplateResult {\n return html`\n <badged-input>\n <select\n id=\"donation-contact-form-countryCodeAlpha2\"\n @change=${(e: Event) => {\n const newValue = (e.target as HTMLSelectElement).value;\n if (countries[newValue]) this.selectedCountry = newValue;\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 minlength?: number;\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 minlength=${ifDefined(options.minlength)}\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: calc(100%);\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 }\n </style>\n `;\n }\n}\n"]}
@@ -48,8 +48,6 @@ export class GooglePayFlowHandler {
48
48
  lastName,
49
49
  });
50
50
  const billing = new BillingInfo({
51
- firstName,
52
- lastName,
53
51
  streetAddress: billingInfo === null || billingInfo === void 0 ? void 0 : billingInfo.address1,
54
52
  extendedAddress: billingInfo === null || billingInfo === void 0 ? void 0 : billingInfo.address2,
55
53
  locality: billingInfo === null || billingInfo === void 0 ? void 0 : billingInfo.locality,
@@ -1 +1 @@
1
- {"version":3,"file":"googlepay-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/googlepay-flow-handler.ts"],"names":[],"mappings":";AACA,OAAO,EAEL,eAAe,EACf,YAAY,EACZ,WAAW,GACZ,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAW,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAcpE,MAAM,OAAO,oBAAoB;IAQ/B,YAAY,OAGX;QANO,YAAO,GACb,gBAAgB,EAA8B,CAAC;QAM/C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IACnE,CAAC;IAED,EAAE,CACA,KAAQ,EACR,QAAuC;QAEvC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,4CAA4C;IACtC,gBAAgB,CAAC,YAAiC;;;YACtD,MAAM,O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CAAC,wBAAwB,CAAC,UAAU,EAAE,CAAC;YAC7C,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["import { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\nimport {\n DonationPaymentInfo,\n PaymentProvider,\n CustomerInfo,\n BillingInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { DonationFlowModalManagerInterface } from '../donation-flow-modal-manager';\nimport { Emitter, createNanoEvents, Unsubscribe } from 'nanoevents';\n\nexport interface GooglePayFlowHandlerInterface {\n paymentInitiated(donationInfo: DonationPaymentInfo): Promise<void>;\n on<E extends keyof GooglePayFlowHandlerEvents>(\n event: E,\n callback: GooglePayFlowHandlerEvents[E],\n ): Unsubscribe;\n}\n\nexport interface GooglePayFlowHandlerEvents {\n paymentCancelled: () => void;\n}\n\nexport class GooglePayFlowHandler implements GooglePayFlowHandlerInterface {\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private emitter: Emitter<GooglePayFlowHandlerEvents> =\n createNanoEvents<GooglePayFlowHandlerEvents>();\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n }\n\n on<E extends keyof GooglePayFlowHandlerEvents>(\n event: E,\n callback: GooglePayFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n // GooglePayFlowHandlerInterface conformance\n async paymentInitiated(donationInfo: DonationPaymentInfo): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.googlePayHandler.get();\n const instance = await handler.instance.get();\n\n const paymentDataRequest = await instance.createPaymentDataRequest({\n emailRequired: true,\n transactionInfo: {\n currencyCode: 'USD',\n totalPriceStatus: 'FINAL',\n totalPrice: `${donationInfo.total}`,\n },\n });\n\n const cardPaymentMethod = paymentDataRequest.allowedPaymentMethods[0];\n cardPaymentMethod.parameters.billingAddressRequired = true;\n cardPaymentMethod.parameters.billingAddressParameters = {\n format: 'FULL',\n phoneNumberRequired: false,\n };\n\n try {\n const paymentData = await handler.paymentsClient.loadPaymentData(paymentDataRequest);\n const result: braintree.GooglePaymentTokenizePayload =\n await instance.parseResponse(paymentData);\n\n const billingInfo = paymentData.paymentMethodData.info?.billingAddress;\n const name = billingInfo?.name;\n let firstName: string | undefined = name;\n let lastName: string | undefined = '';\n const lastSpace = name?.lastIndexOf(' ');\n if (lastSpace && lastSpace !== -1) {\n firstName = name?.substr(0, lastSpace);\n lastName = name?.substr(lastSpace);\n }\n\n const customer = new CustomerInfo({\n email: paymentData.email,\n firstName,\n lastName,\n });\n\n const billing = new BillingInfo({\n firstName,\n lastName,\n streetAddress: billingInfo?.address1,\n extendedAddress: billingInfo?.address2,\n locality: billingInfo?.locality,\n region: billingInfo?.administrativeArea,\n postalCode: billingInfo?.postalCode,\n countryCodeAlpha2: billingInfo?.countryCode,\n });\n\n this.donationFlowModalManager.startDonationSubmissionFlow({\n nonce: result.nonce,\n paymentProvider: PaymentProvider.GooglePay,\n bin: result.details.bin,\n binName: result.binData.issuingBank,\n donationInfo: donationInfo,\n customerInfo: customer,\n billingInfo: billing,\n });\n } catch {\n this.emitter.emit('paymentCancelled');\n this.donationFlowModalManager.closeModal();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"googlepay-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/googlepay-flow-handler.ts"],"names":[],"mappings":";AACA,OAAO,EAEL,eAAe,EACf,YAAY,EACZ,WAAW,GACZ,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAW,gBAAgB,EAAe,MAAM,YAAY,CAAC;AAcpE,MAAM,OAAO,oBAAoB;IAQ/B,YAAY,OAGX;QANO,YAAO,GACb,gBAAgB,EAA8B,CAAC;QAM/C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,wBAAwB,GAAG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ACnC,YAAY,EAAE,YAAY;oBAC1B,YAAY,EAAE,QAAQ;oBACtB,WAAW,EAAE,OAAO;iBACrB,CAAC,CAAC;YACL,CAAC;YAAC,WAAM,CAAC;gBACP,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBACtC,IAAI,CAAC,wBAAwB,CAAC,UAAU,EAAE,CAAC;YAC7C,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["import { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\nimport {\n DonationPaymentInfo,\n PaymentProvider,\n CustomerInfo,\n BillingInfo,\n} from '@internetarchive/donation-form-data-models';\nimport { DonationFlowModalManagerInterface } from '../donation-flow-modal-manager';\nimport { Emitter, createNanoEvents, Unsubscribe } from 'nanoevents';\n\nexport interface GooglePayFlowHandlerInterface {\n paymentInitiated(donationInfo: DonationPaymentInfo): Promise<void>;\n on<E extends keyof GooglePayFlowHandlerEvents>(\n event: E,\n callback: GooglePayFlowHandlerEvents[E],\n ): Unsubscribe;\n}\n\nexport interface GooglePayFlowHandlerEvents {\n paymentCancelled: () => void;\n}\n\nexport class GooglePayFlowHandler implements GooglePayFlowHandlerInterface {\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private emitter: Emitter<GooglePayFlowHandlerEvents> =\n createNanoEvents<GooglePayFlowHandlerEvents>();\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n }\n\n on<E extends keyof GooglePayFlowHandlerEvents>(\n event: E,\n callback: GooglePayFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n // GooglePayFlowHandlerInterface conformance\n async paymentInitiated(donationInfo: DonationPaymentInfo): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.googlePayHandler.get();\n const instance = await handler.instance.get();\n\n const paymentDataRequest = await instance.createPaymentDataRequest({\n emailRequired: true,\n transactionInfo: {\n currencyCode: 'USD',\n totalPriceStatus: 'FINAL',\n totalPrice: `${donationInfo.total}`,\n },\n });\n\n const cardPaymentMethod = paymentDataRequest.allowedPaymentMethods[0];\n cardPaymentMethod.parameters.billingAddressRequired = true;\n cardPaymentMethod.parameters.billingAddressParameters = {\n format: 'FULL',\n phoneNumberRequired: false,\n };\n\n try {\n const paymentData = await handler.paymentsClient.loadPaymentData(paymentDataRequest);\n const result: braintree.GooglePaymentTokenizePayload =\n await instance.parseResponse(paymentData);\n\n const billingInfo = paymentData.paymentMethodData.info?.billingAddress;\n const name = billingInfo?.name;\n let firstName: string | undefined = name;\n let lastName: string | undefined = '';\n const lastSpace = name?.lastIndexOf(' ');\n if (lastSpace && lastSpace !== -1) {\n firstName = name?.substr(0, lastSpace);\n lastName = name?.substr(lastSpace);\n }\n\n const customer = new CustomerInfo({\n email: paymentData.email,\n firstName,\n lastName,\n });\n\n const billing = new BillingInfo({\n streetAddress: billingInfo?.address1,\n extendedAddress: billingInfo?.address2,\n locality: billingInfo?.locality,\n region: billingInfo?.administrativeArea,\n postalCode: billingInfo?.postalCode,\n countryCodeAlpha2: billingInfo?.countryCode,\n });\n\n this.donationFlowModalManager.startDonationSubmissionFlow({\n nonce: result.nonce,\n paymentProvider: PaymentProvider.GooglePay,\n bin: result.details.bin,\n binName: result.binData.issuingBank,\n donationInfo: donationInfo,\n customerInfo: customer,\n billingInfo: billing,\n });\n } catch {\n this.emitter.emit('paymentCancelled');\n this.donationFlowModalManager.closeModal();\n }\n }\n}\n"]}
@@ -81,8 +81,6 @@ export class PayPalFlowHandler {
81
81
  });
82
82
  const shippingAddress = details.shippingAddress;
83
83
  const billingInfo = new BillingInfo({
84
- firstName: details === null || details === void 0 ? void 0 : details.firstName,
85
- lastName: details === null || details === void 0 ? void 0 : details.lastName,
86
84
  streetAddress: shippingAddress === null || shippingAddress === void 0 ? void 0 : shippingAddress.line1,
87
85
  extendedAddress: shippingAddress === null || shippingAddress === void 0 ? void 0 : shippingAddress.line2,
88
86
  locality: shippingAddress === null || shippingAddress === void 0 ? void 0 : shippingAddress.city,
@@ -1 +1 @@
1
- {"version":3,"file":"paypal-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/paypal-flow-handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAC;AAMpE,OAAO,EAEL,YAAY,EACZ,mBAAmB,EAEnB,YAAY,EACZ,WAAW,EACX,eAAe,GAEhB,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAEL,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AAYxC;;;;GAIG;AACH,MAAM,yBAAyB;IAK7B,YAAY,OAIX;QACC,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAC/D,CAAC;CACF;AASD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAa5B,kBAAkB,CAAC,YAAiC;QAClD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,IAAI,CAAC,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;QACpD,CAAC;IACH,CAAC;IAED,wBAAwB,CAAC,YAAiC;QACxD,IAAI,IAAI,CAAC,+BAA+B,EAAE,CAAC;YACzC,IAAI,CAAC,+BAA+B,CAAC,sBAAsB,CAAC,YAAY,GAAG,YAAY,CAAC;QAC1F,CAAC;IACH,CAAC;IAED,YAAY,OAGX;QAjBO,YAAO,GAAqC,gBAAgB,EAA2B,CAAC;QAkB9F,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC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AC;YAEH,IAAI,sBAAsB,EAAE,CAAC;gBAC3B,sBAAsB,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACvC,IAAI,CAAC,+BAA+B,GAAG,IAAI,yBAAyB,CAAC;oBACnE,sBAAsB,EAAE,sBAAsB;oBAC9C,cAAc,EAAE,OAAO,CAAC,cAAc;oBACtC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;iBACvD,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["import { createNanoEvents, Emitter, Unsubscribe } from 'nanoevents';\n\nimport {\n PayPalButtonDataSourceInterface,\n PayPalButtonDataSourceDelegate,\n} from '../../braintree-manager/payment-providers/paypal/paypal-button-datasource';\nimport {\n DonationResponse,\n DonationType,\n DonationPaymentInfo,\n SuccessResponse,\n CustomerInfo,\n BillingInfo,\n PaymentProvider,\n ErrorResponse,\n} from '@internetarchive/donation-form-data-models';\nimport { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\n\nimport { UpsellModalCTAMode } from '../../modals/upsell-modal-content';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from '../donation-flow-modal-manager';\n\nexport interface PayPalFlowHandlerInterface {\n updateDonationInfo(donationInfo: DonationPaymentInfo): void;\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void;\n renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void>;\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe;\n}\n\n/**\n * This is a class to combine the data from the one-time purchase to the upsell\n *\n * @class UpsellDataSourceContainer\n */\nclass UpsellDataSourceContainer {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n\n constructor(options: {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }) {\n this.upsellButtonDataSource = options.upsellButtonDataSource;\n this.oneTimePayload = options.oneTimePayload;\n this.oneTimeSuccessResponse = options.oneTimeSuccessResponse;\n }\n}\n\nexport interface PayPalFlowHandlerEvents {\n payPalPaymentStarted: (dataSource: PayPalButtonDataSourceInterface, options: object) => void;\n payPalPaymentCancelled: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;\n payPalPaymentError: (dataSource: PayPalButtonDataSourceInterface, error: string) => void;\n payPalPaymentConfirmed: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;\n}\n\n/**\n * This class manages the user-flow for PayPal.\n *\n * @export\n * @class PayPalFlowHandler\n * @implements {PayPalFlowHandlerInterface}\n * @implements {PayPalButtonDataSourceDelegate}\n */\nexport class PayPalFlowHandler\n implements PayPalFlowHandlerInterface, PayPalButtonDataSourceDelegate\n{\n private upsellButtonDataSourceContainer?: UpsellDataSourceContainer;\n\n private buttonDataSource?: PayPalButtonDataSourceInterface;\n\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private emitter: Emitter<PayPalFlowHandlerEvents> = createNanoEvents<PayPalFlowHandlerEvents>();\n\n updateDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.buttonDataSource) {\n this.buttonDataSource.donationInfo = donationInfo;\n }\n }\n\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo = donationInfo;\n }\n }\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n }\n\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n async payPalPaymentStarted(\n dataSource: PayPalButtonDataSourceInterface,\n\n options: object,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentStarted', dataSource, options);\n }\n\n /**\n * Once we have the dataSource & payload, we ask patron to confirm donation.\n * Once confirmed, we move forward to: `payPalPaymentConfirmed`\n */\n async payPalPaymentAuthorized(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n const { donationType, total } = dataSource.donationInfo;\n this.donationFlowModalManager.showConfirmationStepModal({\n donationType,\n amount: total,\n currencyType: 'USD', // defaults to USD for now\n confirmDonationCB: () => {\n this.payPalPaymentConfirmed(dataSource, payload);\n },\n cancelDonationCB: () => {\n this.donationFlowModalManager.closeModal();\n this.payPalPaymentCancelled(dataSource, {});\n },\n });\n }\n\n async payPalPaymentConfirmed(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentConfirmed', dataSource, {});\n this.donationFlowModalManager.showProcessingModal();\n\n const donationType = dataSource.donationInfo.donationType;\n\n const details = payload?.details;\n\n const customerInfo = new CustomerInfo({\n email: details?.email,\n firstName: details?.firstName,\n lastName: details?.lastName,\n });\n\n const shippingAddress = details.shippingAddress;\n\n const billingInfo = new BillingInfo({\n firstName: details?.firstName,\n lastName: details?.lastName,\n streetAddress: shippingAddress?.line1,\n extendedAddress: shippingAddress?.line2,\n locality: shippingAddress?.city,\n region: shippingAddress?.state,\n postalCode: shippingAddress?.postalCode,\n countryCodeAlpha2: shippingAddress?.countryCode,\n });\n\n const oneTimeTransaction = this.upsellButtonDataSourceContainer\n ? this.upsellButtonDataSourceContainer.oneTimeSuccessResponse.transaction_id\n : undefined;\n\n const response: DonationResponse = await this.braintreeManager.submitDonation({\n nonce: payload.nonce,\n paymentProvider: PaymentProvider.PayPal,\n donationInfo: dataSource.donationInfo,\n customerInfo: customerInfo,\n billingInfo: billingInfo,\n upsellOnetimeTransactionId: oneTimeTransaction,\n });\n\n if (!response.success) {\n const error = response.value as ErrorResponse;\n this.donationFlowModalManager.showErrorModal({\n message: error.message,\n });\n return;\n }\n\n const successResponse = response.value as SuccessResponse;\n\n switch (donationType) {\n case DonationType.OneTime:\n this.showUpsellModal(payload, successResponse);\n break;\n case DonationType.Monthly:\n // show thank you, redirect\n this.donationFlowModalManager.showThankYouModal({ successResponse });\n break;\n case DonationType.Upsell:\n if (this.upsellButtonDataSourceContainer) {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: this.upsellButtonDataSourceContainer.oneTimeSuccessResponse,\n upsellSuccessResponse: successResponse,\n });\n } else {\n // we're in the upsell flow, but no upsell data source container.. this should not happen\n this.donationFlowModalManager.showErrorModal({\n message: 'Error setting up monthly donation',\n });\n }\n break;\n }\n }\n\n async payPalPaymentCancelled(\n dataSource: PayPalButtonDataSourceInterface,\n\n data: object,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentCancelled', dataSource, data);\n }\n\n async payPalPaymentError(\n dataSource: PayPalButtonDataSourceInterface,\n error: string,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentError', dataSource, error);\n console.error(\n 'PaymentSector:payPalPaymentError error:',\n dataSource,\n dataSource.donationInfo,\n error,\n );\n }\n\n async renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n this.buttonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption, // I'm not sure why I can't access the enum directly here.. I get a UMD error\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'medium' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: donationInfo,\n });\n\n if (this.buttonDataSource) {\n this.buttonDataSource.delegate = this;\n }\n }\n\n private async showUpsellModal(\n oneTimePayload: paypal.TokenizePayload,\n oneTimeSuccessResponse: SuccessResponse,\n ): Promise<void> {\n this.donationFlowModalManager.showUpsellModal({\n oneTimeAmount: oneTimeSuccessResponse.amount,\n amountChanged: this.upsellAmountChanged.bind(this),\n noSelected: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n ctaMode: UpsellModalCTAMode.PayPalUpsellSlot,\n userClosedModalCallback: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n });\n\n const amount = DonationFlowModalManager.getDefaultUpsellAmount(oneTimeSuccessResponse.amount);\n\n const upsellDonationInfo = new DonationPaymentInfo({\n amount: amount,\n donationType: DonationType.Upsell,\n coverFees: false,\n });\n\n if (!this.upsellButtonDataSourceContainer) {\n this.renderUpsellPayPalButton({\n donationInfo: upsellDonationInfo,\n oneTimePayload,\n oneTimeSuccessResponse,\n });\n }\n }\n\n private upsellAmountChanged(amount: number): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo.amount = amount;\n }\n }\n\n private async renderUpsellPayPalButton(options: {\n donationInfo: DonationPaymentInfo;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n const upsellButtonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-upsell-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption,\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'responsive' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: options.donationInfo,\n });\n\n if (upsellButtonDataSource) {\n upsellButtonDataSource.delegate = this;\n this.upsellButtonDataSourceContainer = new UpsellDataSourceContainer({\n upsellButtonDataSource: upsellButtonDataSource,\n oneTimePayload: options.oneTimePayload,\n oneTimeSuccessResponse: options.oneTimeSuccessResponse,\n });\n } else {\n console.error('error rendering paypal upsell button');\n }\n }\n}\n"]}
1
+ {"version":3,"file":"paypal-flow-handler.js","sourceRoot":"","sources":["../../../../src/payment-flow-handlers/handlers/paypal-flow-handler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAwB,MAAM,YAAY,CAAC;AAMpE,OAAO,EAEL,YAAY,EACZ,mBAAmB,EAEnB,YAAY,EACZ,WAAW,EACX,eAAe,GAEhB,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAEL,wBAAwB,GACzB,MAAM,gCAAgC,CAAC;AAYxC;;;;GAIG;AACH,MAAM,yBAAyB;IAK7B,YAAY,OAIX;QACC,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAC/D,CAAC;CACF;AASD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAa5B,kBAAkB,CAAC,YAAiC;QAClD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,IAAI,CAAC,gBAAgB,CAAC,YAAY,GAAG,YAAY,CAAC;QACpD,CAAC;IACH,CAAC;IAED,wBAAwB,CAAC,YAAiC;QACxD,IAAI,IAAI,CAAC,+BAA+B,EAAE,CAAC;YACzC,IAAI,CAAC,+BAA+B,CAAC,sBAAsB,CAAC,YAAY,GAAG,YAAY,CAAC;QAC1F,CAAC;IACH,CAAC;IAED,YAAY,OAGX;QAjBO,YAAO,GAAqC,gBAAgB,EAA2B,CAAC;QAkB9F,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IACnE,CAAC;IAED,EAAE,CACA,KAAQ,EACR,QAAoC;QAEpC,OAAO,IAAI,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CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;KAAA;CACF","sourcesContent":["import { createNanoEvents, Emitter, Unsubscribe } from 'nanoevents';\n\nimport {\n PayPalButtonDataSourceInterface,\n PayPalButtonDataSourceDelegate,\n} from '../../braintree-manager/payment-providers/paypal/paypal-button-datasource';\nimport {\n DonationResponse,\n DonationType,\n DonationPaymentInfo,\n SuccessResponse,\n CustomerInfo,\n BillingInfo,\n PaymentProvider,\n ErrorResponse,\n} from '@internetarchive/donation-form-data-models';\nimport { BraintreeManagerInterface } from '../../braintree-manager/braintree-interfaces';\n\nimport { UpsellModalCTAMode } from '../../modals/upsell-modal-content';\nimport {\n DonationFlowModalManagerInterface,\n DonationFlowModalManager,\n} from '../donation-flow-modal-manager';\n\nexport interface PayPalFlowHandlerInterface {\n updateDonationInfo(donationInfo: DonationPaymentInfo): void;\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void;\n renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void>;\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe;\n}\n\n/**\n * This is a class to combine the data from the one-time purchase to the upsell\n *\n * @class UpsellDataSourceContainer\n */\nclass UpsellDataSourceContainer {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n\n constructor(options: {\n upsellButtonDataSource: PayPalButtonDataSourceInterface;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }) {\n this.upsellButtonDataSource = options.upsellButtonDataSource;\n this.oneTimePayload = options.oneTimePayload;\n this.oneTimeSuccessResponse = options.oneTimeSuccessResponse;\n }\n}\n\nexport interface PayPalFlowHandlerEvents {\n payPalPaymentStarted: (dataSource: PayPalButtonDataSourceInterface, options: object) => void;\n payPalPaymentCancelled: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;\n payPalPaymentError: (dataSource: PayPalButtonDataSourceInterface, error: string) => void;\n payPalPaymentConfirmed: (dataSource: PayPalButtonDataSourceInterface, data: object) => void;\n}\n\n/**\n * This class manages the user-flow for PayPal.\n *\n * @export\n * @class PayPalFlowHandler\n * @implements {PayPalFlowHandlerInterface}\n * @implements {PayPalButtonDataSourceDelegate}\n */\nexport class PayPalFlowHandler\n implements PayPalFlowHandlerInterface, PayPalButtonDataSourceDelegate\n{\n private upsellButtonDataSourceContainer?: UpsellDataSourceContainer;\n\n private buttonDataSource?: PayPalButtonDataSourceInterface;\n\n private donationFlowModalManager: DonationFlowModalManagerInterface;\n\n private braintreeManager: BraintreeManagerInterface;\n\n private emitter: Emitter<PayPalFlowHandlerEvents> = createNanoEvents<PayPalFlowHandlerEvents>();\n\n updateDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.buttonDataSource) {\n this.buttonDataSource.donationInfo = donationInfo;\n }\n }\n\n updateUpsellDonationInfo(donationInfo: DonationPaymentInfo): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo = donationInfo;\n }\n }\n\n constructor(options: {\n braintreeManager: BraintreeManagerInterface;\n donationFlowModalManager: DonationFlowModalManagerInterface;\n }) {\n this.braintreeManager = options.braintreeManager;\n this.donationFlowModalManager = options.donationFlowModalManager;\n }\n\n on<E extends keyof PayPalFlowHandlerEvents>(\n event: E,\n callback: PayPalFlowHandlerEvents[E],\n ): Unsubscribe {\n return this.emitter.on(event, callback);\n }\n\n async payPalPaymentStarted(\n dataSource: PayPalButtonDataSourceInterface,\n\n options: object,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentStarted', dataSource, options);\n }\n\n /**\n * Once we have the dataSource & payload, we ask patron to confirm donation.\n * Once confirmed, we move forward to: `payPalPaymentConfirmed`\n */\n async payPalPaymentAuthorized(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n const { donationType, total } = dataSource.donationInfo;\n this.donationFlowModalManager.showConfirmationStepModal({\n donationType,\n amount: total,\n currencyType: 'USD', // defaults to USD for now\n confirmDonationCB: () => {\n this.payPalPaymentConfirmed(dataSource, payload);\n },\n cancelDonationCB: () => {\n this.donationFlowModalManager.closeModal();\n this.payPalPaymentCancelled(dataSource, {});\n },\n });\n }\n\n async payPalPaymentConfirmed(\n dataSource: PayPalButtonDataSourceInterface,\n payload: paypal.TokenizePayload,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentConfirmed', dataSource, {});\n this.donationFlowModalManager.showProcessingModal();\n\n const donationType = dataSource.donationInfo.donationType;\n\n const details = payload?.details;\n\n const customerInfo = new CustomerInfo({\n email: details?.email,\n firstName: details?.firstName,\n lastName: details?.lastName,\n });\n\n const shippingAddress = details.shippingAddress;\n\n const billingInfo = new BillingInfo({\n streetAddress: shippingAddress?.line1,\n extendedAddress: shippingAddress?.line2,\n locality: shippingAddress?.city,\n region: shippingAddress?.state,\n postalCode: shippingAddress?.postalCode,\n countryCodeAlpha2: shippingAddress?.countryCode,\n });\n\n const oneTimeTransaction = this.upsellButtonDataSourceContainer\n ? this.upsellButtonDataSourceContainer.oneTimeSuccessResponse.transaction_id\n : undefined;\n\n const response: DonationResponse = await this.braintreeManager.submitDonation({\n nonce: payload.nonce,\n paymentProvider: PaymentProvider.PayPal,\n donationInfo: dataSource.donationInfo,\n customerInfo: customerInfo,\n billingInfo: billingInfo,\n upsellOnetimeTransactionId: oneTimeTransaction,\n });\n\n if (!response.success) {\n const error = response.value as ErrorResponse;\n this.donationFlowModalManager.showErrorModal({\n message: error.message,\n });\n return;\n }\n\n const successResponse = response.value as SuccessResponse;\n\n switch (donationType) {\n case DonationType.OneTime:\n this.showUpsellModal(payload, successResponse);\n break;\n case DonationType.Monthly:\n // show thank you, redirect\n this.donationFlowModalManager.showThankYouModal({ successResponse });\n break;\n case DonationType.Upsell:\n if (this.upsellButtonDataSourceContainer) {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: this.upsellButtonDataSourceContainer.oneTimeSuccessResponse,\n upsellSuccessResponse: successResponse,\n });\n } else {\n // we're in the upsell flow, but no upsell data source container.. this should not happen\n this.donationFlowModalManager.showErrorModal({\n message: 'Error setting up monthly donation',\n });\n }\n break;\n }\n }\n\n async payPalPaymentCancelled(\n dataSource: PayPalButtonDataSourceInterface,\n\n data: object,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentCancelled', dataSource, data);\n }\n\n async payPalPaymentError(\n dataSource: PayPalButtonDataSourceInterface,\n error: string,\n ): Promise<void> {\n this.emitter.emit('payPalPaymentError', dataSource, error);\n console.error(\n 'PaymentSector:payPalPaymentError error:',\n dataSource,\n dataSource.donationInfo,\n error,\n );\n }\n\n async renderPayPalButton(donationInfo: DonationPaymentInfo): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n this.buttonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption, // I'm not sure why I can't access the enum directly here.. I get a UMD error\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'medium' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: donationInfo,\n });\n\n if (this.buttonDataSource) {\n this.buttonDataSource.delegate = this;\n }\n }\n\n private async showUpsellModal(\n oneTimePayload: paypal.TokenizePayload,\n oneTimeSuccessResponse: SuccessResponse,\n ): Promise<void> {\n this.donationFlowModalManager.showUpsellModal({\n oneTimeAmount: oneTimeSuccessResponse.amount,\n amountChanged: this.upsellAmountChanged.bind(this),\n noSelected: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n ctaMode: UpsellModalCTAMode.PayPalUpsellSlot,\n userClosedModalCallback: () => {\n this.donationFlowModalManager.showThankYouModal({\n successResponse: oneTimeSuccessResponse,\n });\n },\n });\n\n const amount = DonationFlowModalManager.getDefaultUpsellAmount(oneTimeSuccessResponse.amount);\n\n const upsellDonationInfo = new DonationPaymentInfo({\n amount: amount,\n donationType: DonationType.Upsell,\n coverFees: false,\n });\n\n if (!this.upsellButtonDataSourceContainer) {\n this.renderUpsellPayPalButton({\n donationInfo: upsellDonationInfo,\n oneTimePayload,\n oneTimeSuccessResponse,\n });\n }\n }\n\n private upsellAmountChanged(amount: number): void {\n if (this.upsellButtonDataSourceContainer) {\n this.upsellButtonDataSourceContainer.upsellButtonDataSource.donationInfo.amount = amount;\n }\n }\n\n private async renderUpsellPayPalButton(options: {\n donationInfo: DonationPaymentInfo;\n oneTimePayload: paypal.TokenizePayload;\n oneTimeSuccessResponse: SuccessResponse;\n }): Promise<void> {\n const handler = await this.braintreeManager?.paymentProviders.paypalHandler.get();\n\n const upsellButtonDataSource = await handler?.renderPayPalButton({\n selector: '#paypal-upsell-button',\n style: {\n color: 'blue' as paypal.ButtonColorOption,\n label: 'paypal' as paypal.ButtonLabelOption,\n shape: 'rect' as paypal.ButtonShapeOption,\n size: 'responsive' as paypal.ButtonSizeOption,\n tagline: false,\n },\n donationInfo: options.donationInfo,\n });\n\n if (upsellButtonDataSource) {\n upsellButtonDataSource.delegate = this;\n this.upsellButtonDataSourceContainer = new UpsellDataSourceContainer({\n upsellButtonDataSource: upsellButtonDataSource,\n oneTimePayload: options.oneTimePayload,\n oneTimeSuccessResponse: options.oneTimeSuccessResponse,\n });\n } else {\n console.error('error rendering paypal upsell button');\n }\n }\n}\n"]}
@@ -1,7 +1,5 @@
1
1
  import { BillingInfo } from '@internetarchive/donation-form-data-models';
2
2
  export const mockBillingInfo = new BillingInfo({
3
- firstName: 'Fooey',
4
- lastName: 'McBarrison',
5
3
  streetAddress: '123 Fake St',
6
4
  extendedAddress: 'Apt 123',
7
5
  locality: 'San Francisco',
@@ -1 +1 @@
1
- {"version":3,"file":"mock-billing-info.js","sourceRoot":"","sources":["../../../../test/mocks/models/mock-billing-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AAEzE,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC;IAC7C,SAAS,EAAE,OAAO;IAClB,QAAQ,EAAE,YAAY;IACtB,aAAa,EAAE,aAAa;IAC5B,eAAe,EAAE,SAAS;IAC1B,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,OAAO;IACnB,iBAAiB,EAAE,IAAI;CACxB,CAAC,CAAC","sourcesContent":["import { BillingInfo } from '@internetarchive/donation-form-data-models';\n\nexport const mockBillingInfo = new BillingInfo({\n firstName: 'Fooey',\n lastName: 'McBarrison',\n streetAddress: '123 Fake St',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n region: 'CA',\n postalCode: '12345',\n countryCodeAlpha2: 'US',\n});\n"]}
1
+ {"version":3,"file":"mock-billing-info.js","sourceRoot":"","sources":["../../../../test/mocks/models/mock-billing-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AAEzE,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC;IAC7C,aAAa,EAAE,aAAa;IAC5B,eAAe,EAAE,SAAS;IAC1B,QAAQ,EAAE,eAAe;IACzB,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,OAAO;IACnB,iBAAiB,EAAE,IAAI;CACxB,CAAC,CAAC","sourcesContent":["import { BillingInfo } from '@internetarchive/donation-form-data-models';\n\nexport const mockBillingInfo = new BillingInfo({\n streetAddress: '123 Fake St',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n region: 'CA',\n postalCode: '12345',\n countryCodeAlpha2: 'US',\n});\n"]}
@@ -193,8 +193,6 @@ describe('Donation Flow Modal Manager', () => {
193
193
  value: {
194
194
  amount: 5,
195
195
  billing: {
196
- firstName: 'Fooey',
197
- lastName: 'McBarrison',
198
196
  countryCodeAlpha2: 'US',
199
197
  extendedAddress: 'Apt 123',
200
198
  locality: 'San Francisco',
@@ -1 +1 @@
1
- {"version":3,"file":"donation-flow-modal-manager.test.js","sourceRoot":"","sources":["../../../../test/tests/flow-handlers/donation-flow-modal-manager.test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gEAAgE,CAAC;AAE1G,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAEzE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,IAAI,SAAiD,CAAC;AAEtD,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG;YACV,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE;YACtB,oBAAoB,EAAE,KAAK,CAAC,IAAI,EAAE;SACnC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qBAAqB,EAAE,GAAS,EAAE;QACnC,MAAM,gBAAgB,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAA;;KAE3C,CAAC,CAAqB,CAAC;QACxB,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC;QACxD,MAAM,OAAO,GAAG,IAAI,wBAAwB,CAAC;YAC3C,gBA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BACP,SAAS,EAAE,OAAO;oBAClB,QAAQ,EAAE,YAAY;oBACtB,iBAAiB,EAAE,IAAI;oBACvB,eAAe,EAAE,SAAS;oBAC1B,QAAQ,EAAE,eAAe;oBACzB,UAAU,EAAE,OAAO;oBACnB,MAAM,EAAE,IAAI;oBACZ,aAAa,EAAE,aAAa;iBAC7B;gBACD,QAAQ,EAAE;oBACR,KAAK,EAAE,aAAa;oBACpB,SAAS,EAAE,OAAO;oBAClB,QAAQ,EAAE,YAAY;iBACvB;gBACD,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,UAAU;gBACxB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,aAAa;gBAC9B,cAAc,EAAE,KAAK;aACtB;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { html, fixture, expect } from '@open-wc/testing';\nimport { DonationFlowModalManager } from '../../../src/payment-flow-handlers/donation-flow-modal-manager';\nimport { MockModalManager } from '../../mocks/mock-modal-manager';\nimport '../../mocks/mock-modal-manager';\nimport { MockBraintreeManager } from '../../mocks/mock-braintree-manager';\nimport { mockSuccessResponse } from '../../mocks/models/mock-success-response';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport { mockBillingInfo } from '../../mocks/models/mock-billing-info';\nimport { mockCustomerInfo } from '../../mocks/models/mock-customer-info';\nimport { DonationControllerEventLoggerInterface } from '../../../src/@types/analytics-handler';\nimport sinon from 'sinon';\n\nlet analytics: DonationControllerEventLoggerInterface;\n\ndescribe('Donation Flow Modal Manager', () => {\n beforeEach(() => {\n analytics = {\n logEvent: sinon.fake(),\n logDonationFlowEvent: sinon.fake(),\n };\n });\n afterEach(() => {\n sinon.restore();\n });\n it('can close the modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.closeModal();\n expect(mockModalManager.closeCalled).to.be.true;\n });\n\n it('can calculate the proper default upsell amount', async () => {\n const defaultAmount = 8;\n let amount = DonationFlowModalManager.getDefaultUpsellAmount(1);\n expect(amount).to.equal(defaultAmount);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10);\n expect(amount).to.equal(defaultAmount);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10.01);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25.01);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100.01);\n expect(amount).to.equal(50);\n });\n\n it('can show the processing modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.showProcessingModal();\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#497fbf');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.processingImageMode).to.equal('processing');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.false;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Processing...');\n });\n\n it('can show the error modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.showErrorModal({ message: 'foo-error' });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#691916');\n expect(modalOptions?.config.showProcessingIndicator).to.be.false;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.headline?.strings[0]).to.contain(\n \"There's been a problem completing your donation.\",\n );\n expect(modalOptions?.config.message?.values[0]).to.equal('foo-error');\n });\n\n it('shows the thank you modal and calls `donationSuccessful` to take user to thank you page', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const logEvent = sinon.fake();\n const logDonationFlowEvent = sinon.fake();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics: {\n logEvent,\n logDonationFlowEvent,\n },\n });\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.processingImageMode).to.equal('complete');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Thank You!');\n const response = mockBraintreeManager.donationSuccessfulOptions?.successResponse;\n expect(response).to.deep.equal(mockSuccessResponse);\n });\n\n it('donation submitted analytics gets sent when drawing thank you modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const logEvent = sinon.fake();\n const logDonationFlowEvent = sinon.fake();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics: {\n logEvent,\n logDonationFlowEvent,\n },\n });\n const successResponse = mockSuccessResponse;\n successResponse.paymentProvider = PaymentProvider.GooglePay;\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n\n // fires analytics\n expect(logDonationFlowEvent.callCount).to.equal(1);\n expect(logDonationFlowEvent.args[0][0]).to.equal(`Donated-GooglePay`);\n expect(logDonationFlowEvent.args[0][1]).to.equal(DonationType.OneTime);\n });\n\n it('can show the confirmation modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.showConfirmationStepModal({\n donationType: DonationType.Upsell,\n amount: 8,\n currencyType: 'USD',\n cancelDonationCB: () => console.log('donation cancelled'),\n confirmDonationCB: () => console.log('donation confirmed'),\n });\n\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config?.title?.values).to.contain('Confirm monthly donation');\n });\n\n it('can start the donation submission flow', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n const result = await manager.startDonationSubmissionFlow({\n nonce: 'foo',\n paymentProvider: PaymentProvider.CreditCard,\n donationInfo: new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 5,\n coverFees: false,\n }),\n billingInfo: mockBillingInfo,\n customerInfo: mockCustomerInfo,\n });\n\n expect(result).to.deep.equal({\n success: true,\n value: {\n amount: 5,\n billing: {\n firstName: 'Fooey',\n lastName: 'McBarrison',\n countryCodeAlpha2: 'US',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n postalCode: '12345',\n region: 'CA',\n streetAddress: '123 Fake St',\n },\n customer: {\n email: 'foo@bar.com',\n firstName: 'Fooey',\n lastName: 'McBarrison',\n },\n customer_id: 'bar',\n donationType: 'one-time',\n paymentMethodNonce: 'foo',\n paymentProvider: 'Credit Card',\n transaction_id: 'foo',\n },\n });\n });\n});\n"]}
1
+ {"version":3,"file":"donation-flow-modal-manager.test.js","sourceRoot":"","sources":["../../../../test/tests/flow-handlers/donation-flow-modal-manager.test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gEAAgE,CAAC;AAE1G,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAEzE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,IAAI,SAAiD,CAAC;AAEtD,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG;YACV,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE;YACtB,oBAAoB,EAAE,KAAK,CAAC,IAAI,EAAE;SACnC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qBAAqB,EAAE,GAAS,EAAE;QACnC,MAAM,gBAAgB,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAA;;KAE3C,CAAC,CAAqB,CAAC;QACxB,MAAM,oBA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,CAAC;YAC3B,OAAO,EAAE,IAAI;YACb,KAAK,EAAE;gBACL,MAAM,EAAE,CAAC;gBACT,OAAO,EAAE;oBACP,iBAAiB,EAAE,IAAI;oBACvB,eAAe,EAAE,SAAS;oBAC1B,QAAQ,EAAE,eAAe;oBACzB,UAAU,EAAE,OAAO;oBACnB,MAAM,EAAE,IAAI;oBACZ,aAAa,EAAE,aAAa;iBAC7B;gBACD,QAAQ,EAAE;oBACR,KAAK,EAAE,aAAa;oBACpB,SAAS,EAAE,OAAO;oBAClB,QAAQ,EAAE,YAAY;iBACvB;gBACD,WAAW,EAAE,KAAK;gBAClB,YAAY,EAAE,UAAU;gBACxB,kBAAkB,EAAE,KAAK;gBACzB,eAAe,EAAE,aAAa;gBAC9B,cAAc,EAAE,KAAK;aACtB;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { html, fixture, expect } from '@open-wc/testing';\nimport { DonationFlowModalManager } from '../../../src/payment-flow-handlers/donation-flow-modal-manager';\nimport { MockModalManager } from '../../mocks/mock-modal-manager';\nimport '../../mocks/mock-modal-manager';\nimport { MockBraintreeManager } from '../../mocks/mock-braintree-manager';\nimport { mockSuccessResponse } from '../../mocks/models/mock-success-response';\nimport {\n PaymentProvider,\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\nimport { mockBillingInfo } from '../../mocks/models/mock-billing-info';\nimport { mockCustomerInfo } from '../../mocks/models/mock-customer-info';\nimport { DonationControllerEventLoggerInterface } from '../../../src/@types/analytics-handler';\nimport sinon from 'sinon';\n\nlet analytics: DonationControllerEventLoggerInterface;\n\ndescribe('Donation Flow Modal Manager', () => {\n beforeEach(() => {\n analytics = {\n logEvent: sinon.fake(),\n logDonationFlowEvent: sinon.fake(),\n };\n });\n afterEach(() => {\n sinon.restore();\n });\n it('can close the modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.closeModal();\n expect(mockModalManager.closeCalled).to.be.true;\n });\n\n it('can calculate the proper default upsell amount', async () => {\n const defaultAmount = 8;\n let amount = DonationFlowModalManager.getDefaultUpsellAmount(1);\n expect(amount).to.equal(defaultAmount);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10);\n expect(amount).to.equal(defaultAmount);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(10.01);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25);\n expect(amount).to.equal(10);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(25.01);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100);\n expect(amount).to.equal(25);\n amount = DonationFlowModalManager.getDefaultUpsellAmount(100.01);\n expect(amount).to.equal(50);\n });\n\n it('can show the processing modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.showProcessingModal();\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#497fbf');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.processingImageMode).to.equal('processing');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.false;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Processing...');\n });\n\n it('can show the error modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.showErrorModal({ message: 'foo-error' });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#691916');\n expect(modalOptions?.config.showProcessingIndicator).to.be.false;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.headline?.strings[0]).to.contain(\n \"There's been a problem completing your donation.\",\n );\n expect(modalOptions?.config.message?.values[0]).to.equal('foo-error');\n });\n\n it('shows the thank you modal and calls `donationSuccessful` to take user to thank you page', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const logEvent = sinon.fake();\n const logDonationFlowEvent = sinon.fake();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics: {\n logEvent,\n logDonationFlowEvent,\n },\n });\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.processingImageMode).to.equal('complete');\n expect(modalOptions?.config.showProcessingIndicator).to.be.true;\n expect(modalOptions?.config.closeOnBackdropClick).to.be.true;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config.title?.strings[0]).to.contain('Thank You!');\n const response = mockBraintreeManager.donationSuccessfulOptions?.successResponse;\n expect(response).to.deep.equal(mockSuccessResponse);\n });\n\n it('donation submitted analytics gets sent when drawing thank you modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const logEvent = sinon.fake();\n const logDonationFlowEvent = sinon.fake();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics: {\n logEvent,\n logDonationFlowEvent,\n },\n });\n const successResponse = mockSuccessResponse;\n successResponse.paymentProvider = PaymentProvider.GooglePay;\n manager.showThankYouModal({\n successResponse: mockSuccessResponse,\n });\n\n // fires analytics\n expect(logDonationFlowEvent.callCount).to.equal(1);\n expect(logDonationFlowEvent.args[0][0]).to.equal(`Donated-GooglePay`);\n expect(logDonationFlowEvent.args[0][1]).to.equal(DonationType.OneTime);\n });\n\n it('can show the confirmation modal', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n manager.showConfirmationStepModal({\n donationType: DonationType.Upsell,\n amount: 8,\n currencyType: 'USD',\n cancelDonationCB: () => console.log('donation cancelled'),\n confirmDonationCB: () => console.log('donation confirmed'),\n });\n\n const modalOptions = mockModalManager.showModalOptions;\n expect(modalOptions?.config.headerColor).to.equal('#55A183');\n expect(modalOptions?.config.closeOnBackdropClick).to.be.false;\n expect(modalOptions?.config.showCloseButton).to.be.true;\n expect(modalOptions?.config?.title?.values).to.contain('Confirm monthly donation');\n });\n\n it('can start the donation submission flow', async () => {\n const mockModalManager = (await fixture(html`\n <mock-modal-manager></mock-modal-manager>\n `)) as MockModalManager;\n const mockBraintreeManager = new MockBraintreeManager();\n const manager = new DonationFlowModalManager({\n braintreeManager: mockBraintreeManager,\n modalManager: mockModalManager,\n analytics,\n });\n const result = await manager.startDonationSubmissionFlow({\n nonce: 'foo',\n paymentProvider: PaymentProvider.CreditCard,\n donationInfo: new DonationPaymentInfo({\n donationType: DonationType.OneTime,\n amount: 5,\n coverFees: false,\n }),\n billingInfo: mockBillingInfo,\n customerInfo: mockCustomerInfo,\n });\n\n expect(result).to.deep.equal({\n success: true,\n value: {\n amount: 5,\n billing: {\n countryCodeAlpha2: 'US',\n extendedAddress: 'Apt 123',\n locality: 'San Francisco',\n postalCode: '12345',\n region: 'CA',\n streetAddress: '123 Fake St',\n },\n customer: {\n email: 'foo@bar.com',\n firstName: 'Fooey',\n lastName: 'McBarrison',\n },\n customer_id: 'bar',\n donationType: 'one-time',\n paymentMethodNonce: 'foo',\n paymentProvider: 'Credit Card',\n transaction_id: 'foo',\n },\n });\n });\n});\n"]}
@@ -0,0 +1 @@
1
+ import '../../../src/form-elements/contact-form/contact-form';
@@ -0,0 +1,132 @@
1
+ import { __awaiter } from "tslib";
2
+ import { fixture, elementUpdated, expect } from '@open-wc/testing';
3
+ import { html } from 'lit';
4
+ import '../../../src/form-elements/contact-form/contact-form';
5
+ describe('ContactForm', () => {
6
+ it('validates required fields', () => __awaiter(void 0, void 0, void 0, function* () {
7
+ const el = (yield fixture(html `<contact-form></contact-form>`));
8
+ const firstNameInput = el.querySelector('#donation-contact-form-first-name');
9
+ const lastNameInput = el.querySelector('#donation-contact-form-last-name');
10
+ const emailInput = el.querySelector('#donation-contact-form-email');
11
+ firstNameInput.value = ' ';
12
+ lastNameInput.value = ' ';
13
+ emailInput.value = '';
14
+ expect(firstNameInput.checkValidity()).to.be.false;
15
+ expect(lastNameInput.checkValidity()).to.be.false;
16
+ expect(emailInput.checkValidity()).to.be.false;
17
+ firstNameInput.value = 'John';
18
+ lastNameInput.value = 'Doe';
19
+ emailInput.value = 'john.doe@example.com';
20
+ yield elementUpdated(el);
21
+ expect(firstNameInput.checkValidity()).to.be.true;
22
+ expect(lastNameInput.checkValidity()).to.be.true;
23
+ expect(emailInput.checkValidity()).to.be.true;
24
+ }));
25
+ it('requires minimum number of characters for first and last name', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const el = (yield fixture(html `<contact-form></contact-form>`));
27
+ const firstNameInput = el.querySelector('#donation-contact-form-first-name');
28
+ const lastNameInput = el.querySelector('#donation-contact-form-last-name');
29
+ firstNameInput.value = 'A';
30
+ lastNameInput.value = 'B';
31
+ yield elementUpdated(el);
32
+ expect(firstNameInput.checkValidity()).to.be.false;
33
+ expect(lastNameInput.checkValidity()).to.be.false;
34
+ }));
35
+ it('requires email by default', () => __awaiter(void 0, void 0, void 0, function* () {
36
+ const el = (yield fixture(html `<contact-form></contact-form>`));
37
+ const emailInput = el.querySelector('#donation-contact-form-email');
38
+ expect(emailInput.required).to.be.true;
39
+ }));
40
+ it('street address requires minimum number of characters', () => __awaiter(void 0, void 0, void 0, function* () {
41
+ const el = (yield fixture(html `<contact-form></contact-form>`));
42
+ const streetAddressInput = el.querySelector('#donation-contact-form-street-address');
43
+ streetAddressInput.value = '1 b';
44
+ yield elementUpdated(el);
45
+ expect(streetAddressInput.checkValidity()).to.be.false;
46
+ streetAddressInput.value = '1 st';
47
+ yield elementUpdated(el);
48
+ expect(streetAddressInput.checkValidity()).to.be.true;
49
+ }));
50
+ describe('region and postal code requirements', () => {
51
+ it('state and postal code required for US address', () => __awaiter(void 0, void 0, void 0, function* () {
52
+ const el = (yield fixture(html `<contact-form></contact-form>`));
53
+ el.selectedCountry = 'US';
54
+ yield elementUpdated(el);
55
+ const regionInput = el.querySelector('#donation-contact-form-region');
56
+ const postalCodeInput = el.querySelector('#donation-contact-form-postal-code');
57
+ expect(regionInput.required).to.be.true;
58
+ expect(postalCodeInput.required).to.be.true;
59
+ }));
60
+ it('state and postal code optional for non-US address', () => __awaiter(void 0, void 0, void 0, function* () {
61
+ const el = (yield fixture(html `<contact-form></contact-form>`));
62
+ el.selectedCountry = 'CA';
63
+ yield elementUpdated(el);
64
+ const regionInput = el.querySelector('#donation-contact-form-region');
65
+ const postalCodeInput = el.querySelector('#donation-contact-form-postal-code');
66
+ expect(regionInput.required).to.be.false;
67
+ expect(postalCodeInput.required).to.be.false;
68
+ }));
69
+ });
70
+ describe('country selector', () => {
71
+ it('defaults selectedCountry to US', () => __awaiter(void 0, void 0, void 0, function* () {
72
+ const el = (yield fixture(html `<contact-form></contact-form>`));
73
+ expect(el.selectedCountry).to.equal('US');
74
+ }));
75
+ it('dropdown updates selectedCountry property', () => __awaiter(void 0, void 0, void 0, function* () {
76
+ const el = (yield fixture(html `<contact-form></contact-form>`));
77
+ const countrySelect = el.querySelector('#donation-contact-form-countryCodeAlpha2');
78
+ countrySelect.value = 'CA';
79
+ countrySelect.dispatchEvent(new Event('change'));
80
+ yield elementUpdated(el);
81
+ expect(el.selectedCountry).to.equal('CA');
82
+ }));
83
+ it('does not update selectedCountry property for invalid country code', () => __awaiter(void 0, void 0, void 0, function* () {
84
+ const el = (yield fixture(html `<contact-form></contact-form>`));
85
+ const countrySelect = el.querySelector('#donation-contact-form-countryCodeAlpha2');
86
+ const initialCountry = el.selectedCountry;
87
+ countrySelect.value = 'XX'; // Invalid country code
88
+ countrySelect.dispatchEvent(new Event('change'));
89
+ yield elementUpdated(el);
90
+ expect(el.selectedCountry).to.equal(initialCountry);
91
+ }));
92
+ });
93
+ describe('reportValidity()', () => {
94
+ it('returns false if required fields are empty and shows validation messages', () => __awaiter(void 0, void 0, void 0, function* () {
95
+ const el = (yield fixture(html `<contact-form></contact-form>`));
96
+ const firstNameInput = el.querySelector('#donation-contact-form-first-name');
97
+ const lastNameInput = el.querySelector('#donation-contact-form-last-name');
98
+ const emailInput = el.querySelector('#donation-contact-form-email');
99
+ firstNameInput.value = '';
100
+ lastNameInput.value = '';
101
+ emailInput.value = '';
102
+ const validityResult = el.reportValidity();
103
+ expect(validityResult).to.be.false;
104
+ expect(firstNameInput.validationMessage).to.not.equal('');
105
+ expect(lastNameInput.validationMessage).to.not.equal('');
106
+ expect(emailInput.validationMessage).to.not.equal('');
107
+ }));
108
+ it('returns true if all required fields are filled correctly', () => __awaiter(void 0, void 0, void 0, function* () {
109
+ const el = (yield fixture(html `<contact-form></contact-form>`));
110
+ const firstNameInput = el.querySelector('#donation-contact-form-first-name');
111
+ const lastNameInput = el.querySelector('#donation-contact-form-last-name');
112
+ const emailInput = el.querySelector('#donation-contact-form-email');
113
+ const streetAddressInput = el.querySelector('#donation-contact-form-street-address');
114
+ const cityInput = el.querySelector('#donation-contact-form-locality');
115
+ const regionInput = el.querySelector('#donation-contact-form-region');
116
+ const postalCodeInput = el.querySelector('#donation-contact-form-postal-code');
117
+ streetAddressInput.value = '123 Main St';
118
+ cityInput.value = 'Anytown';
119
+ regionInput.value = 'CA';
120
+ postalCodeInput.value = '12345';
121
+ firstNameInput.value = 'John';
122
+ lastNameInput.value = 'Doe';
123
+ emailInput.value = 'john.doe@example.com';
124
+ const validityResult = el.reportValidity();
125
+ expect(validityResult).to.be.true;
126
+ expect(firstNameInput.validationMessage).to.equal('');
127
+ expect(lastNameInput.validationMessage).to.equal('');
128
+ expect(emailInput.validationMessage).to.equal('');
129
+ }));
130
+ });
131
+ });
132
+ //# sourceMappingURL=contact-form.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contact-form.test.js","sourceRoot":"","sources":["../../../../test/tests/form-elements/contact-form.test.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,sDAAsD,CAAC;AAG9D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,2BAA2B,EAAE,GAAS,EAAE;QACzC,MAAM,EAAE,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAA,+BAA+B,CAAC,CAAgB,CAAC;QAC/E,MAAM,cAAc,GAAG,EAAE,CAAC,aAAa,CACrC,mCAAmC,CAChB,CAAC;QACtB,MAAM,aAAa,GAAG,EAAE,CAAC,aAAa,CAAC,kCAAkC,CAAqB,CAAC;QAC/F,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,8BAA8B,CAAqB,CAAC;QAExF,cAAc,CAAC,KAAK,GAAG,KAAK,CAAC;QAC7B,aAAa,CAAC,KAAK,GAAG,GAAG,CAAC;QAC1B,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC;QAEtB,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,CAAC,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ACtB,MAAM,SAAS,GAAG,EAAE,CAAC,aAAa,CAAC,iCAAiC,CAAqB,CAAC;YAC1F,MAAM,WAAW,GAAG,EAAE,CAAC,aAAa,CAAC,+BAA+B,CAAqB,CAAC;YAC1F,MAAM,eAAe,GAAG,EAAE,CAAC,aAAa,CACtC,oCAAoC,CACjB,CAAC;YAEtB,kBAAkB,CAAC,KAAK,GAAG,aAAa,CAAC;YACzC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;YAC5B,WAAW,CAAC,KAAK,GAAG,IAAI,CAAC;YACzB,eAAe,CAAC,KAAK,GAAG,OAAO,CAAC;YAEhC,cAAc,CAAC,KAAK,GAAG,MAAM,CAAC;YAC9B,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC;YAC5B,UAAU,CAAC,KAAK,GAAG,sBAAsB,CAAC;YAE1C,MAAM,cAAc,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC;YAE3C,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;YAClC,MAAM,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtD,MAAM,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACrD,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACpD,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { fixture, elementUpdated, expect } from '@open-wc/testing';\nimport { html } from 'lit';\nimport '../../../src/form-elements/contact-form/contact-form';\nimport type { ContactForm } from '../../../src/form-elements/contact-form/contact-form';\n\ndescribe('ContactForm', () => {\n it('validates required fields', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const firstNameInput = el.querySelector(\n '#donation-contact-form-first-name',\n ) as HTMLInputElement;\n const lastNameInput = el.querySelector('#donation-contact-form-last-name') as HTMLInputElement;\n const emailInput = el.querySelector('#donation-contact-form-email') as HTMLInputElement;\n\n firstNameInput.value = ' ';\n lastNameInput.value = ' ';\n emailInput.value = '';\n\n expect(firstNameInput.checkValidity()).to.be.false;\n expect(lastNameInput.checkValidity()).to.be.false;\n expect(emailInput.checkValidity()).to.be.false;\n\n firstNameInput.value = 'John';\n lastNameInput.value = 'Doe';\n emailInput.value = 'john.doe@example.com';\n await elementUpdated(el);\n\n expect(firstNameInput.checkValidity()).to.be.true;\n expect(lastNameInput.checkValidity()).to.be.true;\n expect(emailInput.checkValidity()).to.be.true;\n });\n\n it('requires minimum number of characters for first and last name', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const firstNameInput = el.querySelector(\n '#donation-contact-form-first-name',\n ) as HTMLInputElement;\n const lastNameInput = el.querySelector('#donation-contact-form-last-name') as HTMLInputElement;\n firstNameInput.value = 'A';\n lastNameInput.value = 'B';\n await elementUpdated(el);\n expect(firstNameInput.checkValidity()).to.be.false;\n expect(lastNameInput.checkValidity()).to.be.false;\n });\n\n it('requires email by default', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const emailInput = el.querySelector('#donation-contact-form-email') as HTMLInputElement;\n expect(emailInput.required).to.be.true;\n });\n\n it('street address requires minimum number of characters', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const streetAddressInput = el.querySelector(\n '#donation-contact-form-street-address',\n ) as HTMLInputElement;\n streetAddressInput.value = '1 b';\n await elementUpdated(el);\n expect(streetAddressInput.checkValidity()).to.be.false;\n streetAddressInput.value = '1 st';\n await elementUpdated(el);\n expect(streetAddressInput.checkValidity()).to.be.true;\n });\n\n describe('region and postal code requirements', () => {\n it('state and postal code required for US address', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n el.selectedCountry = 'US';\n await elementUpdated(el);\n const regionInput = el.querySelector('#donation-contact-form-region') as HTMLInputElement;\n const postalCodeInput = el.querySelector(\n '#donation-contact-form-postal-code',\n ) as HTMLInputElement;\n expect(regionInput.required).to.be.true;\n expect(postalCodeInput.required).to.be.true;\n });\n\n it('state and postal code optional for non-US address', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n el.selectedCountry = 'CA';\n await elementUpdated(el);\n const regionInput = el.querySelector('#donation-contact-form-region') as HTMLInputElement;\n const postalCodeInput = el.querySelector(\n '#donation-contact-form-postal-code',\n ) as HTMLInputElement;\n expect(regionInput.required).to.be.false;\n expect(postalCodeInput.required).to.be.false;\n });\n });\n\n describe('country selector', () => {\n it('defaults selectedCountry to US', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n expect(el.selectedCountry).to.equal('US');\n });\n\n it('dropdown updates selectedCountry property', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const countrySelect = el.querySelector(\n '#donation-contact-form-countryCodeAlpha2',\n ) as HTMLSelectElement;\n countrySelect.value = 'CA';\n countrySelect.dispatchEvent(new Event('change'));\n await elementUpdated(el);\n expect(el.selectedCountry).to.equal('CA');\n });\n\n it('does not update selectedCountry property for invalid country code', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const countrySelect = el.querySelector(\n '#donation-contact-form-countryCodeAlpha2',\n ) as HTMLSelectElement;\n const initialCountry = el.selectedCountry;\n countrySelect.value = 'XX'; // Invalid country code\n countrySelect.dispatchEvent(new Event('change'));\n await elementUpdated(el);\n expect(el.selectedCountry).to.equal(initialCountry);\n });\n });\n\n describe('reportValidity()', () => {\n it('returns false if required fields are empty and shows validation messages', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const firstNameInput = el.querySelector(\n '#donation-contact-form-first-name',\n ) as HTMLInputElement;\n const lastNameInput = el.querySelector(\n '#donation-contact-form-last-name',\n ) as HTMLInputElement;\n const emailInput = el.querySelector('#donation-contact-form-email') as HTMLInputElement;\n\n firstNameInput.value = '';\n lastNameInput.value = '';\n emailInput.value = '';\n\n const validityResult = el.reportValidity();\n\n expect(validityResult).to.be.false;\n expect(firstNameInput.validationMessage).to.not.equal('');\n expect(lastNameInput.validationMessage).to.not.equal('');\n expect(emailInput.validationMessage).to.not.equal('');\n });\n\n it('returns true if all required fields are filled correctly', async () => {\n const el = (await fixture(html`<contact-form></contact-form>`)) as ContactForm;\n const firstNameInput = el.querySelector(\n '#donation-contact-form-first-name',\n ) as HTMLInputElement;\n const lastNameInput = el.querySelector(\n '#donation-contact-form-last-name',\n ) as HTMLInputElement;\n const emailInput = el.querySelector('#donation-contact-form-email') as HTMLInputElement;\n const streetAddressInput = el.querySelector(\n '#donation-contact-form-street-address',\n ) as HTMLInputElement;\n const cityInput = el.querySelector('#donation-contact-form-locality') as HTMLInputElement;\n const regionInput = el.querySelector('#donation-contact-form-region') as HTMLInputElement;\n const postalCodeInput = el.querySelector(\n '#donation-contact-form-postal-code',\n ) as HTMLInputElement;\n\n streetAddressInput.value = '123 Main St';\n cityInput.value = 'Anytown';\n regionInput.value = 'CA';\n postalCodeInput.value = '12345';\n\n firstNameInput.value = 'John';\n lastNameInput.value = 'Doe';\n emailInput.value = 'john.doe@example.com';\n\n const validityResult = el.reportValidity();\n\n expect(validityResult).to.be.true;\n expect(firstNameInput.validationMessage).to.equal('');\n expect(lastNameInput.validationMessage).to.equal('');\n expect(emailInput.validationMessage).to.equal('');\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/donation-form",
3
- "version": "1.0.3-webdev-8122.0",
3
+ "version": "1.0.3-webdev-8114.0",
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.4",
32
32
  "@internetarchive/donation-form-currency-validator": "^0.3.1",
33
- "@internetarchive/donation-form-data-models": "0.3.7-webdev-8122.0",
33
+ "@internetarchive/donation-form-data-models": "^0.3.6",
34
34
  "@internetarchive/donation-form-edit-donation": "^1.1.5",
35
35
  "@internetarchive/donation-form-section": "^0.3.6",
36
36
  "@internetarchive/icon-applepay": "^1.3.2",
@@ -51,7 +51,6 @@ 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
54
  @property({ type: String }) selectedCountry = 'US';
56
55
 
57
56
  @property({ type: String }) donorEmail = '';
@@ -83,7 +82,7 @@ export class ContactForm extends LitElement {
83
82
  });
84
83
 
85
84
  if (!isValid) {
86
- this.errorMessage.innerText = 'Please enter any missing contact information below';
85
+ this.errorMessage.innerText = 'Please enter any missing or invalid contact information below';
87
86
  } else {
88
87
  this.errorMessage.innerText = '';
89
88
  }
@@ -109,6 +108,7 @@ export class ContactForm extends LitElement {
109
108
  fieldType: 'email',
110
109
  name: 'email',
111
110
  autocomplete: 'email',
111
+ minlength: 5,
112
112
  maxlength: 255,
113
113
  icon: emailImg,
114
114
  })}
@@ -122,6 +122,7 @@ export class ContactForm extends LitElement {
122
122
  placeholder: 'First name',
123
123
  name: 'fname',
124
124
  required: true,
125
+ validationPattern: '.*\\S{2,}.*',
125
126
  maxlength: 255,
126
127
  autocomplete: 'given-name',
127
128
  icon: userIcon,
@@ -134,6 +135,7 @@ export class ContactForm extends LitElement {
134
135
  name: 'lname',
135
136
  autocomplete: 'family-name',
136
137
  required: true,
138
+ validationPattern: '.*\\S{2,}.*',
137
139
  maxlength: 255,
138
140
  })}
139
141
  </div>
@@ -147,6 +149,7 @@ export class ContactForm extends LitElement {
147
149
  autocomplete: 'address-line1',
148
150
  icon: localePinImg,
149
151
  name: 'street-address',
152
+ validationPattern: '.*?\\S.{2,}\\S.*?',
150
153
  })}
151
154
  </div>
152
155
  <div class="row">
@@ -165,6 +168,7 @@ export class ContactForm extends LitElement {
165
168
  autocomplete: 'address-level2',
166
169
  required: true,
167
170
  name: 'locality',
171
+ validationPattern: '.*\\S{2,}.*',
168
172
  })}
169
173
  </div>
170
174
  <div class="row">
@@ -172,15 +176,17 @@ export class ContactForm extends LitElement {
172
176
  id: 'donation-contact-form-region',
173
177
  placeholder: 'State / Province',
174
178
  autocomplete: 'address-level1',
175
- required: true,
179
+ required: this.regionAndPostalCodeRequired,
176
180
  name: 'region',
181
+ validationPattern: '.*\\S{2,}.*',
177
182
  })}
178
183
  ${this.generateInput({
179
184
  id: 'donation-contact-form-postal-code',
180
185
  placeholder: 'Zip / Postal',
181
186
  autocomplete: 'postal-code',
182
- required: true,
187
+ required: this.regionAndPostalCodeRequired,
183
188
  name: 'postal',
189
+ minlength: 5,
184
190
  maxlength: 9,
185
191
  // must start with a character, then may contain spaces
186
192
  validationPattern: '[a-zA-Z\\-\\d]+[a-zA-Z\\-\\d\\s]*',
@@ -194,28 +200,18 @@ export class ContactForm extends LitElement {
194
200
  `;
195
201
  }
196
202
 
203
+ private get regionAndPostalCodeRequired(): boolean {
204
+ return this.selectedCountry === 'US';
205
+ }
206
+
197
207
  private get countrySelectorTemplate(): TemplateResult {
198
208
  return html`
199
209
  <badged-input>
200
210
  <select
201
211
  id="donation-contact-form-countryCodeAlpha2"
202
212
  @change=${(e: Event) => {
203
- const currCountry = this.selectedCountry;
204
- this.selectedCountry = (e.target as HTMLInputElement)?.value
205
- ? ((e.target as HTMLInputElement)?.value as string)
206
- : currCountry;
207
- // update required visual cue on region/state/province & postal code fields
208
- if (this.selectedCountry === 'US') {
209
- this.postalBadgedInput?.setAttribute('required', '');
210
- this.postalCodeField?.setAttribute('required', '');
211
- this.regionBadgedInput?.setAttribute('required', '');
212
- this.regionField?.setAttribute('required', '');
213
- } else {
214
- this.postalBadgedInput?.removeAttribute('required');
215
- this.postalCodeField?.removeAttribute('required');
216
- this.regionBadgedInput?.removeAttribute('required');
217
- this.regionField?.removeAttribute('required');
218
- }
213
+ const newValue = (e.target as HTMLSelectElement).value;
214
+ if (countries[newValue]) this.selectedCountry = newValue;
219
215
  }}
220
216
  >
221
217
  ${Object.keys(countries).map(key => {
@@ -253,6 +249,7 @@ export class ContactForm extends LitElement {
253
249
  required?: boolean;
254
250
  fieldType?: 'text' | 'email';
255
251
  autocomplete?: AutoCompleteFieldOptions;
252
+ minlength?: number;
256
253
  maxlength?: number;
257
254
  name: string;
258
255
  icon?: TemplateResult;
@@ -279,6 +276,7 @@ export class ContactForm extends LitElement {
279
276
  aria-label=${options.placeholder}
280
277
  placeholder=${options.placeholder}
281
278
  maxlength=${ifDefined(options.maxlength)}
279
+ minlength=${ifDefined(options.minlength)}
282
280
  autocomplete=${options.autocomplete ?? 'on'}
283
281
  pattern=${ifDefined(options.validationPattern)}
284
282
  @focus=${this.inputFocused}
@@ -297,8 +295,6 @@ export class ContactForm extends LitElement {
297
295
 
298
296
  get billingInfo(): BillingInfo {
299
297
  const billingInfo = new BillingInfo({
300
- firstName: this.firstNameField.value,
301
- lastName: this.lastNameField.value,
302
298
  streetAddress: this.streetAddressField.value,
303
299
  extendedAddress: this.extendedAddressField.value,
304
300
  locality: this.localityField.value,
@@ -86,8 +86,6 @@ export class GooglePayFlowHandler implements GooglePayFlowHandlerInterface {
86
86
  });
87
87
 
88
88
  const billing = new BillingInfo({
89
- firstName,
90
- lastName,
91
89
  streetAddress: billingInfo?.address1,
92
90
  extendedAddress: billingInfo?.address2,
93
91
  locality: billingInfo?.locality,
@@ -159,8 +159,6 @@ export class PayPalFlowHandler
159
159
  const shippingAddress = details.shippingAddress;
160
160
 
161
161
  const billingInfo = new BillingInfo({
162
- firstName: details?.firstName,
163
- lastName: details?.lastName,
164
162
  streetAddress: shippingAddress?.line1,
165
163
  extendedAddress: shippingAddress?.line2,
166
164
  locality: shippingAddress?.city,