Finance Assistant Enquiry Page
Overview
The Finance Assistant enquiry page captures customer details after the calculator step and submits them to the Finance Assistant API. It is rendered by scripts/enquiry-page.js, wired by scripts/finance-assistant.js, and styled by finmatch-p/css/finmatch.css (deployed to GCS).
Source of truth: Always fetch the latest scripts from https://storage.googleapis.com/finmatch-p/scripts/.
Architecture
- Renderer:
renderEnquiryPage()inscripts/enquiry-page.jsbuilds the DOM (finance details, customer inputs, CTA). - Controller:
renderFinanceAssistant()inscripts/finance-assistant.jswires submit + edit actions and swaps tobon-voyage.json success/error. - Calculator context:
scripts/finance-container.jsrenders the calculator and provides current finance values used by the enquiry page. - Preview/builder: Admin lender settings load production scripts from
https://storage.googleapis.com/finmatch-p/scripts/inside an iframesrcdoc(seeadmin/js/lender-marketing-builder.js).
Flow
- Calculator renders via
finance-container.js. - Finance Assistant renders enquiry UI via
renderEnquiryPage(). - Submit triggers
submitEnquiry()which validates and posts to Finance Assistant API. bon-voyage.jshandles pending/success/error states.
Form Fields
Rendered input fields (default):
- First name (
firstName) - Second name (
secondName) - Email (
email) - Mobile (
mobile) - Address (
address)
Each field can be disabled via customerDetails config in merchant overrides.
Validation Rules
Validation happens in validateInputs():
- Required: empty required fields are marked invalid.
- Email: must match basic email regex.
- Mobile: accepts UK patterns
+44...or0.... - Hidden inputs: hidden/disabled/aria-hidden inputs are skipped to avoid false negatives.
- Address: if Postcoder UI is active, read from the visible selection text or stored dataset value.
Validation failures highlight fields and show a generic alert.
Submission Payload
submitEnquiry() collects:
- Merchant details (ID, company name, domain).
- Event details (page + timestamp).
- Finance details (purchase amount, deposit percent, credit product) from DOM, with fallback to supplied data.
- Customer details (values from the form).
Email Template Overrides
If present, the payload can include an emailTemplate object to customize the email:
subjectintrofooter
This is sourced from lender overrides (__email) and passed through scripts/enquiry-page.js.
The payload is posted to:
https://finance-assistant-238644427841.europe-west2.run.app/v1/submit-enquiry
An API key is required unless previewMode: true is set in merchant config.
Postcoder Integration
Postcoder is integrated directly in scripts/enquiry-page.js:
- Autocomplete:
https://ws.postcoder.com/pcw/autocomplete/find - Retrieve:
https://ws.postcoder.com/pcw/autocomplete/retrieve
When a suggestion is selected, the full address is formatted and written back to the address input so validation and submission succeed.
Configurable Keys (merchant config)
Postcoder can be configured without code changes using:
postcoderApiKey/postcoderKey/postcoder.apiKeypostcoderCountry/postcoder.country(defaultUK)postcoderEnabled/postcoder.enabled(defaulttrue)
Deployment Location
Source of truth: https://storage.googleapis.com/finmatch-p/scripts/
The live enquiry page script is served from:
https://storage.googleapis.com/finmatch-p/scripts/enquiry-page.js
Any changes must be deployed to gs://finmatch-p/scripts/ so they are available at the source-of-truth URL above.
Styling
Autocomplete UI styling is provided in:
https://storage.googleapis.com/finmatch-p/css/finmatch.css
Styling
Autocomplete UI styling is provided in:
finmatch-p/css/finmatch.css
Troubleshooting
- Missing Finance Assistant API key: ensure
financeAssistantApiKey(or equivalent) exists in merchant config, or setpreviewMode: true. - Autocomplete not showing: confirm Postcoder API key and that queries are 3+ characters.
- Address missing on submission: check that the selected address appears in the
addressinput and thatdata-address-valueis set. - Email shows as "skipped": the Finance Assistant API logs a skip reason in
eventDetails.emailReason.missing_contact_email: no recipient email could be resolved for the merchant.missing_sendgrid_key:SENDGRID_API_KEYis not set in Cloud Run.missing_sendgrid_from:SENDGRID_FROMis not set in Cloud Run.
- Email shows as "failed": SendGrid returned an error; check
eventDetails.emailReasonand Cloud Run logs.- Example:
Invalid character in header content ["Authorization"]indicates a malformed SendGrid key (often newline/whitespace). A 401 response indicates an invalid or insufficient-scope key. - Manual Cloud Run env vars can be lost during deploys if the workflow replaces env vars without supplying the full set. Re-confirm
SENDGRID_API_KEY,SENDGRID_FROM,MERCHANT_API_BASE, andCONTACTS_API_BASEafter deploys.
- Example:
Email Delivery Requirements (Cloud Run)
The Finance Assistant API requires these environment variables to send email:
SENDGRID_API_KEYSENDGRID_FROM- Optional:
SENDGRID_BCC(defaults tosupport@finmatch.io) MERCHANT_API_BASECONTACTS_API_BASE
Note: SENDGRID_API_KEY is stored in Cloud Run and should not be committed to the repo.
Recipient resolution order:
merchantUser.metadata.contactEmailmerchantUser.contactEmailmerchantUser.emailpayload.merchantDetails.contactEmail- Merchant profile ->
contactIds.primary-> Contacts API lookup - Contacts API query (
type=primary)
SendGrid Key Rotation
SendGrid API keys cannot be edited or rotated in place. To update a key:
- Go to SendGrid Settings -> API Keys.
- Delete the old key.
- Create a new key (with Mail Send permissions).
- Update
SENDGRID_API_KEYin Cloud Run and redeploy.
References
- Postcoder Autocomplete Find: https://postcoder.com/docs/address-lookup/autocomplete-find
- Postcoder Autocomplete Retrieve: https://postcoder.com/docs/address-lookup/autocomplete-retrieve