@instabrain-sdks/api-client 2.4.0 → 2.5.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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ TypeScript SDK for Node.js. All operations go through `InstaBrainClient` — req
8
8
 
9
9
  - **GIGDB & ADB** — full client flow: `get*Quote()` → `start*Application()` → `saveEftPayment()` → SecureSign methods → `finalSubmit()`.
10
10
  - **IB Term** — client flow ends at `startIBTermApplication()`; use returned `agentLink` / `applicantLink` / `eAppAgentLink` for the InstaBrain frontend.
11
- - **Pure Term** — pre-fill flow: `getPureTermQuote()` → `startApplication()`; use returned links for the InstaBrain frontend.
11
+ - **Pure Term** — pre-fill flow: `getPureTermQuote()` → `startPureTermApplication()`; use returned links for the InstaBrain frontend.
12
12
 
13
13
  ```typescript
14
14
  import { InstaBrainClient } from '@instabrain-sdks/api-client';
@@ -48,7 +48,9 @@ Credentials (`userId` and `accessToken`) are provisioned during onboarding.
48
48
  - [Get existing quote](#ib-term--get-existing-quote)
49
49
  7. [Pure Term](#pure-term)
50
50
  - [Integration flow](#integration-flow-3)
51
+ - [Rider lookup](#pure-term--rider-lookup)
51
52
  - [Get quote](#pure-term--get-quote)
53
+ - [Get existing quote](#pure-term--get-existing-quote)
52
54
  - [Start application](#pure-term--start-application)
53
55
  8. [Final Expense](#final-expense)
54
56
  - [Integration flow](#integration-flow-4)
@@ -58,6 +60,9 @@ Credentials (`userId` and `accessToken`) are provisioned during onboarding.
58
60
  - [Update quote](#final-expense--update-quote)
59
61
  - [Underwriting status (async)](#final-expense--underwriting-status-async)
60
62
  9. [Shared methods — GIGDB, ADB & Final Expense](#shared-methods--gigdb-adb--final-expense)
63
+ - [Payment — EFT or credit card](#payment--eft-or-credit-card)
64
+ - [Get credit card iframe URL](#get-credit-card-iframe-url)
65
+ - [Credit card payment status](#credit-card-payment-status)
61
66
  - [Save EFT payment](#save-eft-payment)
62
67
  - [Prepare docs & get delivery channels](#prepare-docs--get-delivery-channels)
63
68
  - [Send PIN & get documents link](#send-pin--get-documents-link)
@@ -1644,27 +1649,108 @@ const { quoteResponseId, quoteAmount } = quoteResp.selectedQuote;
1644
1649
 
1645
1650
  ## Pure Term
1646
1651
 
1647
- **InstaBrain Pure Term** — simplified term life product.
1652
+ **InstaBrain Pure Term** — term life product.
1648
1653
 
1649
- This is a **pre-fill flow**: use `getPureTermQuote()` then `startApplication()`, then hand off via `agentLink`, `applicantLink`, and `eAppAgentLink`. Do **not** call `saveEftPayment()`, SecureSign methods, or `finalSubmit()` for Pure Term.
1654
+ This is a **pre-fill flow**: quote, start the application via the dedicated Pure Term endpoint, then hand off via `agentLink`, `applicantLink`, and `eAppAgentLink`. All remaining underwriting and signing happens inside the InstaBrain frontend — the same hand-off family as IB Term.
1650
1655
 
1651
1656
  - **Eligible ages:** 18–60
1652
1657
  - **Rating:** `rateClass`, `healthClass`, or `height` + `weightInLbs`
1653
- - **Term lengths:** 10, 20, or 30 years (`benefitPeriod`)
1658
+ - **Term lengths:** 10, 15, 20, or 30 years (`benefitPeriod`) — age and nicotine dependent
1659
+ - **Not available in:** WY, NY
1660
+ - **Dedicated controller:** start application posts to `ThirdPartyPureTermApplication` (not the generic `ThirdPartyStartApp`)
1661
+
1662
+ > **Do not** wire a Pure Term `opportunityId` into `finalSubmit()`, the SecureSign methods, or the credit-card iframe — the credit-card iframe is not supported for this product and returns `CcPaymentIframeNotSupportedForProduct`. Shared `saveEftPayment()` is allowed.
1663
+
1664
+ > **Pure Term follows the same Term SDK pattern as [IB Term](#ib-term)** — rider lookup → quote → start application → link hand-off, with an optional existing-quote fetch. Shared behavior, error models, business rules, and knockouts are the same; treat the IB Term sections as the reference and read the differences below as an overlay.
1665
+
1666
+ **Product differences from IB Term:**
1667
+
1668
+ | Topic | IB Term | Pure Term |
1669
+ |---|---|---|
1670
+ | `benefitPeriod` | 10 / 20 / 30 | 10 / **15** / 20 / 30 |
1671
+ | `rateClass` | Preferred Plus, Preferred, Standard, Standard Extra (`RateClass`) | The same four **plus Rated C and Rated D** (`PureTermRateClass`) |
1672
+ | Living benefits | Included | **Not offered** |
1673
+ | Identity checks | Quote / opportunity must be IB Term | Quote / opportunity must be Pure Term |
1674
+
1675
+ Coverage and benefit-period availability tables are Pure-Term-specific — see [Get Quote](#pure-term--get-quote).
1654
1676
 
1655
1677
  ---
1656
1678
 
1657
1679
  ## Integration flow
1658
1680
 
1659
1681
  ```
1660
- 1. [`getPureTermQuote()`](#pure-term--get-quote) Get quote → quoteResponseId
1661
- 2. [`startApplication()`](#pure-term--start-application) Start app → agentLink / applicantLink
1662
- ├── isDeclined = true → STOP
1682
+ 1. [`getPureTermRiderDetails()`](#pure-term--rider-lookup) (optional) Rider availability + codes
1683
+ └── flagProductNotAvailableForState = true → STOP (not sold in this state)
1684
+ 2. [`getPureTermQuote()`](#pure-term--get-quote) Get quote → quoteResponseId
1685
+ 3. [`startPureTermApplication()`](#pure-term--start-application) Start app → opportunityId + links
1686
+ ├── isDeclined = true → STOP (knockout)
1663
1687
  └── isQuoteChanged = true → re-present updated premium, then hand off via links
1664
1688
 
1689
+ [`getPureTermExistingQuote()`](#pure-term--get-existing-quote) (optional) Re-fetch the stored quote
1690
+
1665
1691
  → Direct agent or applicant to agentLink / applicantLink / eAppAgentLink
1666
1692
  All remaining steps complete inside the InstaBrain frontend.
1667
- No further InstaBrainClient methods for Pure Term.
1693
+ ```
1694
+
1695
+ ---
1696
+
1697
+ ## Pure Term — Rider Lookup
1698
+
1699
+ **Method:** `client.getPureTermRiderDetails(stateCode, age, flagNicotineUse)` · **Returns:** `PureTermRiderDetailsResp`
1700
+
1701
+ Optional pre-quote step. Filters the available Pure Term riders by state, age, and nicotine use so you can present the correct choices before quoting.
1702
+
1703
+
1704
+ ***
1705
+
1706
+ ### Request Fields
1707
+
1708
+ All three are sent as query-string parameters.
1709
+
1710
+ | Parameter | Type | Required | Description |
1711
+ |---|---|---|---|
1712
+ | `stateCode` | `string` | Yes | 2-letter US state code (e.g. `"TX"`) |
1713
+ | `age` | `number` | Yes | Integer, 18–60 inclusive |
1714
+ | `flagNicotineUse` | `boolean` | Yes | Must be sent explicitly as `true` or `false` — not optional |
1715
+
1716
+
1717
+ ***
1718
+
1719
+ ### Business Rules
1720
+
1721
+ 1. `flagProductNotAvailableForState: true` with an empty `riders` array is a **valid `200` response**, not an error — the SDK returns it as-is and does not throw. Pure Term is not sold in every state (e.g. WY, NY).
1722
+ 2. Use `riderCode` from the response as `riders[n].rider` in the Pure Term quote request.
1723
+ 3. Backend validation failures (invalid state, age out of range) surface through the SDK error model as usual.
1724
+
1725
+
1726
+ ***
1727
+
1728
+ ### Response
1729
+
1730
+ | Field | Type | Description |
1731
+ |---|---|---|
1732
+ | `flagProductNotAvailableForState` | `boolean` | `true` = product unavailable for this state/age/nicotine combination; `riders` is empty |
1733
+ | `riders` | `PureTermRider[]` | Available rider options |
1734
+ | `riders[].riderCode` | `string` | Pass as `riders[n].rider` on the quote |
1735
+ | `riders[].riderTitle` | `string` | Display title |
1736
+ | `riders[].riderDescription` | `string` | Display description |
1737
+
1738
+
1739
+ ***
1740
+
1741
+ ### Example
1742
+
1743
+ ```typescript
1744
+ const riderInfo = await client.getPureTermRiderDetails('TX', 35, false);
1745
+
1746
+ if (riderInfo.flagProductNotAvailableForState) {
1747
+ // Pure Term is not sold for this state/age/nicotine combination — stop here.
1748
+ return;
1749
+ }
1750
+
1751
+ for (const rider of riderInfo.riders) {
1752
+ console.log(rider.riderCode, '—', rider.riderTitle);
1753
+ }
1668
1754
  ```
1669
1755
 
1670
1756
  ---
@@ -1678,16 +1764,16 @@ This is a **pre-fill flow**: use `getPureTermQuote()` then `startApplication()`,
1678
1764
 
1679
1765
  ### Request Fields
1680
1766
 
1681
- Provide exactly one rating group (†) and exactly one age input (‡).
1767
+ Provide at least one rating group (†) and one age input (‡).
1682
1768
 
1683
1769
  | Field | Type | Required | Description | Validation Error |
1684
1770
  |---|---|---|---|---|
1685
- | `faceAmount` | `number` | Yes | Coverage amount — age-based limits apply | `Coverage amount (FaceAmount) is required.` |
1686
- | `benefitPeriod` | `number` | Yes | Term: 10, 20, or 30 years (state/age/tobacco dependent) | `Benefit period is required.` |
1771
+ | `faceAmount` | `number` | Yes | Coverage amount — age-based limits apply (see below) | `Coverage amount (FaceAmount) is required.` |
1772
+ | `benefitPeriod` | `number` | Yes | Term: 10, 15, 20, or 30 years (state/age/tobacco dependent) | `Benefit period is required.` |
1687
1773
  | `flagTobaccoUse` | `boolean` | No | Defaults to `false` when omitted | — |
1688
1774
  | `gender` | `Gender` | Yes | `Gender.Male`, `Gender.Female` | `Gender is required.` / `Invalid gender.` |
1689
- | `stateCode` | `string` | Yes | 2-letter US state code | `State code is required.` / `State code is not valid.` / `This product is not available for the selected state.` |
1690
- | `rateClass` | `RateClass` | One of † | `"Preferred Plus"`, `"Preferred"`, `"Standard"`, `"Standard Extra"` | `Either RateClass, HealthClass, or Height and WeightInLbs must be provided.` |
1775
+ | `stateCode` | `string` | Yes | 2-letter US state code. Send `stateCode` only — do **not** send `zipCode` | `State code is required.` / `State code is not valid.` / `This product is not available for the selected state.` |
1776
+ | `rateClass` | `PureTermRateClass` | One of † | `"Preferred Plus"`, `"Preferred"`, `"Standard"`, `"Standard Extra"`, `"Rated C"`, `"Rated D"` | `Either RateClass, HealthClass, or Height and WeightInLbs must be provided.` / `Rate class is invalid. Allowed values: Preferred Plus, Preferred, Standard, Standard Extra, Rated C, Rated D.` |
1691
1777
  | `healthClass` | `HealthClass` | One of † | `"excellent"`, `"great"`, `"good"`, `"average"` (case-insensitive) | `Health class is invalid.` |
1692
1778
  | `height` | `ThirdPartyQuoteReqHeight \| null` | One of † | `feet` (1–8), `inches` (0–11) — required with `weightInLbs` | `Height or weight is invalid.` |
1693
1779
  | `weightInLbs` | `number \| null` | One of † | Paired with `height` | — |
@@ -1700,24 +1786,87 @@ Provide exactly one rating group (†) and exactly one age input (‡).
1700
1786
  | `email` | `string` | No | Lead capture | `Please enter a valid email address.` |
1701
1787
  | `phoneNum` | `string` | No | 10 digits or E.164 — lead capture | `Phone number format is incorrect.` |
1702
1788
 
1703
- > **†** Supply exactly **one** rating group: `rateClass`, OR `healthClass`, OR both `height` and `weightInLbs`.
1789
+ > **†** Supply **at least one** rating group: `rateClass`, `healthClass`, or both `height` and `weightInLbs`. Sending more than one is accepted — the requirement is that at least one is present.
1704
1790
  > **‡** Provide `age` OR `dateOfBirth`. When both are sent, `dateOfBirth` takes priority.
1705
1791
 
1792
+ **Coverage limits by age** — `faceAmount` outside these ranges returns `CoverageNotAvailable`:
1793
+
1794
+ | Age | Allowed `faceAmount` |
1795
+ |---|---|
1796
+ | Up to 55 | $50,000 – $1,000,000 |
1797
+ | 56 | up to $900,000 |
1798
+ | 57 | up to $800,000 |
1799
+ | 58 | up to $700,000 |
1800
+ | 59 | up to $600,000 |
1801
+ | 60 | up to $500,000 |
1802
+
1803
+ **Benefit periods by age and nicotine use** — other values return `BenefitPeriodNotAvailable`:
1804
+
1805
+ | Age | Non-smoker | Smoker |
1806
+ |---|---|---|
1807
+ | 18–45 | 10, 15, 20, 30 | 10, 15, 20, 30 |
1808
+ | 46–50 | 10, 15, 20, 30 | 10, 15, 20 |
1809
+ | 51–60 | 10, 15, 20 | 10, 15, 20 |
1810
+
1811
+ > **15 is a Pure-Term-only term length.** IB Term offers 10 / 20 / 30 — do not reuse IB Term's benefit-period rules here.
1812
+
1813
+
1814
+ ***
1815
+
1816
+ ### Validation Rules
1817
+
1818
+ The server applies these in order. Only rules 9's two outcomes get dedicated top-level error codes; everything else surfaces as `InvalidRequestFormat` with PascalCase field keys under `value.fields` (at most one message per field).
1819
+
1820
+ 1. `benefitPeriod` is required.
1821
+ 2. `stateCode`, when present, must be a state where Pure Term is available.
1822
+ 3. At least one of `rateClass`, `healthClass`, or (`height` **and** `weightInLbs`) must be provided.
1823
+ 4. `rateClass`, when present, must be a valid **Pure Term** rate class — note Pure Term does **not** offer `Guaranteed`.
1824
+ 5. `healthClass`, when present, must be valid (case-insensitive).
1825
+ 6. `height` / `weightInLbs`, when present, must be a valid combination.
1826
+ 7. Age — from `dateOfBirth` when present, else `age` — must be 18–60 inclusive.
1827
+ 8. `riders`, when present, must be valid for Pure Term.
1828
+ 9. When `stateCode` and (`age` or `dateOfBirth`) are present: `benefitPeriod` is checked against carrier availability (`BenefitPeriodNotAvailable`) and `faceAmount` against coverage rules (`CoverageNotAvailable`).
1829
+
1706
1830
 
1707
1831
  ***
1708
1832
 
1709
1833
  ### Error Codes
1710
1834
 
1711
- | Code | When |
1712
- |---|---|
1713
- | `InvalidRequestFormat` | Any field validation failure — inspect `value.fields` |
1714
- | `BenefitPeriodNotAvailable` | `benefitPeriod` not allowed for state/age/nicotine combination |
1715
- | `CoverageNotAvailable` | `faceAmount` outside allowed range for state/age/nicotine |
1716
- | `NotAvailableForState` | Pure Term not available in the requested state |
1717
- | `QuoteNotEligibleForGivenConditions` | State/age/nicotine combination not eligible |
1718
- | `OutsideBuildChart` | Height/weight outside carrier build chart |
1719
- | `RiderNotAvailable` | Rider unavailable for product or state |
1720
- | `RiderFaceAmountNotValid` | Rider face amount outside allowed range |
1835
+ `getPureTermQuote()` throws `APIValidationError` when the server returns `flagStatus: false`. The code set matches [IB Term](#ib-term--get-quote):
1836
+
1837
+ | Code | `err.response.value` | When |
1838
+ |---|---|---|
1839
+ | `InvalidRequestFormat` | `fields` object present | Any field validation failure |
1840
+ | `StateNotFound` | `null` | State code not recognized |
1841
+ | `AgeNotFound` | `null` | Neither age nor date of birth supplied, or age could not be derived |
1842
+ | `BenefitPeriodNotAvailable` | `fields` object present | `benefitPeriod` not allowed for state/age/nicotine |
1843
+ | `CoverageNotAvailable` | `fields` object present | `faceAmount` out of range for state/age/nicotine |
1844
+ | `NotAvailableForState` | `null` | Product not available in this state |
1845
+ | `QuoteNotEligibleForGivenConditions` | `null` | State/age/nicotine combination not eligible |
1846
+ | `OutsideBuildChart` | `null` | Height/weight outside carrier build chart |
1847
+ | `RiderNotAvailable` | `null` | Rider not available for this product/state |
1848
+ | `RiderFaceAmountNotValid` | `null` | Rider face amount outside allowed range |
1849
+
1850
+ > **Two stages produce these.** Request validation issues dedicated top-level codes only for `BenefitPeriodNotAvailable` and `CoverageNotAvailable` — everything else at that stage, **including an invalid rate class**, arrives as `InvalidRequestFormat` with a PascalCase key under `value.fields`. Once validation passes, the request still runs through the shared quote-eligibility pipeline, which can return `NotAvailableForState`, `QuoteNotEligibleForGivenConditions`, `RiderNotAvailable`, `RiderFaceAmountNotValid`, or `OutsideBuildChart`. Do not assume those never occur for Pure Term.
1851
+
1852
+ ```typescript
1853
+ import { APIValidationError, APIErrorCode } from '@instabrain-sdks/api-client';
1854
+
1855
+ try {
1856
+ await client.getPureTermQuote(request);
1857
+ } catch (err) {
1858
+ if (err instanceof APIValidationError) {
1859
+ if (err.isErrorType(APIErrorCode.BenefitPeriodNotAvailable)) {
1860
+ // Offer a different term length for this age / state / nicotine combination
1861
+ } else if (err.isErrorType(APIErrorCode.CoverageNotAvailable)) {
1862
+ // Offer a face amount inside the age band
1863
+ } else {
1864
+ // InvalidRequestFormat — per-field messages
1865
+ console.log(err.response?.value?.fields);
1866
+ }
1867
+ }
1868
+ }
1869
+ ```
1721
1870
 
1722
1871
 
1723
1872
  ***
@@ -1726,12 +1875,16 @@ Provide exactly one rating group (†) and exactly one age input (‡).
1726
1875
 
1727
1876
  | Field | Type | Description |
1728
1877
  |---|---|---|
1729
- | `productName` | `string` | `"InstaPureTerm"` |
1730
- | `selectedQuote.quoteResponseId` | `string` | Pass as `quoteResponseId` in `startApplication()` |
1878
+ | `productName` | `string` | `"InstaBrain Pure Term"` |
1879
+ | `selectedQuote.quoteResponseId` | `string` | Pass as `quoteResponseId` in `startPureTermApplication()` |
1731
1880
  | `selectedQuote.quoteAmount` | `number` | Premium at requested payment frequency |
1881
+ | `selectedQuote.premiumSaveWhenSelectingAnnual` | `number \| null` | Annual-billing savings vs monthly; `null` when already `Annually` |
1882
+ | `selectedQuote.maxQuoteAmount` | `number \| null` | Upper premium bound for the quoted profile |
1883
+ | `selectedQuote.minQuoteAmount` | `number \| null` | Lower premium bound for the quoted profile |
1732
1884
  | `selectedQuote.faceAmount` | `number` | Coverage amount |
1733
1885
  | `selectedQuote.benefitPeriod` | `number \| null` | Term length in years |
1734
1886
  | `selectedQuote.paymentFrequency` | `string \| null` | `"Monthly"` or `"Annually"` |
1887
+ | `selectedQuote.selectedRiders` | `object[]` | Riders on the quote — `rider`, `riderFaceAmount`, `riderQuoteAmount`. Subtract every `riderQuoteAmount` from `quoteAmount` to derive the base premium |
1735
1888
 
1736
1889
 
1737
1890
  ***
@@ -1757,12 +1910,60 @@ const { quoteResponseId, quoteAmount } = quoteResp.selectedQuote;
1757
1910
 
1758
1911
  ---
1759
1912
 
1913
+ ## Pure Term — Get Existing Quote
1914
+
1915
+ **Method:** `client.getPureTermExistingQuote(opportunityId)` · **Returns:** `ThirdPartyQuoteResp`
1916
+
1917
+ Re-fetches a previously generated Pure Term quote by its opportunity ID, without re-quoting. Use it to resume or review an in-flight opportunity — for example when `isQuoteChanged` came back `true` from start application.
1918
+
1919
+
1920
+ ***
1921
+
1922
+ ### Request Fields
1923
+
1924
+ | Parameter | Type | Required | Description |
1925
+ |---|---|---|---|
1926
+ | `opportunityId` | `string` | Yes | Valid UUID, passed as a **query-string** parameter (not a body field) |
1927
+
1928
+
1929
+ ***
1930
+
1931
+ ### Business Rules
1932
+
1933
+ 1. The response reuses the same shape as `getPureTermQuote()` — `productName` is `"InstaBrain Pure Term"`.
1934
+ 2. Unlike rider-lookup product-unavailability, a not-found result here **is** an error and is thrown through the SDK error model — it is not a valid business state.
1935
+
1936
+
1937
+ ***
1938
+
1939
+ ### Error Codes
1940
+
1941
+ | Code | When |
1942
+ |---|---|
1943
+ | `InvalidRequestFormat` | Missing, empty, or non-GUID `opportunityId` (`OpportunityId is required.` / `OpportunityId does not exist.`), or the opportunity belongs to another product (`OpportunityId does not match selected product.`) |
1944
+ | `QuoteNotFound` | The opportunity exists but has no stored quote (top-level, `value: null`) |
1945
+
1946
+ > A valid but unauthorized `opportunityId` returns HTTP `403`.
1947
+
1948
+
1949
+ ***
1950
+
1951
+ ### Example
1952
+
1953
+ ```typescript
1954
+ const existing = await client.getPureTermExistingQuote(opportunityId);
1955
+ console.log(existing.selectedQuote.quoteAmount, existing.selectedQuote.benefitPeriod);
1956
+ ```
1957
+
1958
+ ---
1959
+
1760
1960
  ## Pure Term — Start Application
1761
1961
 
1762
- **Method:** `client.startApplication(request)` · **Type:** `ThirdPartyStartApplicationReq`
1962
+ **Method:** `client.startPureTermApplication(request)` · **Type:** `PureTermStartApplicationReq`
1763
1963
 
1964
+ A **dedicated** Pure Term endpoint. This is separate from the generic `client.startApplication()`, which is unchanged and still serves other products — do not substitute one for the other.
1764
1965
 
1765
- This is the **generic** start-application endpoint shared across products that use the pre-fill link hand-off flow. For Pure Term, call this after `getPureTermQuote()` using the `quoteResponseId` from the quote response.
1966
+ The backend shares one request contract between IB Term and Pure Term start-application: same fields, same nesting, same optionality, same validation messages. `PureTermStartApplicationReq` is therefore the same structure as `IBTermStartApplicationReq`, and the full field-by-field tables in [IB Term — Start Application](#ib-term--start-application) apply here unchanged. Only the differences are listed below.
1766
1967
 
1767
1968
 
1768
1969
  ***
@@ -1771,12 +1972,10 @@ This is the **generic** start-application endpoint shared across products that u
1771
1972
 
1772
1973
  | Field | Type | Required | Description |
1773
1974
  |---|---|---|---|
1774
- | `quoteResponseId` | `string` | Yes | UUID from `getPureTermQuote()` |
1775
- | `firstName` | `string \| null` | Yes | Applicant first name |
1776
- | `lastName` | `string \| null` | Yes | Applicant last name |
1777
- | `email` | `string \| null` | Yes | Applicant email address |
1778
- | `phoneNumber` | `string \| null` | Yes | Applicant phone number — 10-digit local or E.164 |
1779
- | `proCode` | `string \| null` | No | Product variant code. When omitted the base product is started. Contact InstaBrain support for the correct code if a specific variant is required. |
1975
+ | `quoteResponseId` | `string` | Yes | UUID from `getPureTermQuote()` — must belong to the **Pure Term** product |
1976
+ | *(all other fields)* | — | — | Identical to [IB Term — Start Application](#ib-term--start-application) |
1977
+
1978
+ > `proCode` does **not** apply here — it belongs to the generic `startApplication()` only.
1780
1979
 
1781
1980
 
1782
1981
  ***
@@ -1784,14 +1983,43 @@ This is the **generic** start-application endpoint shared across products that u
1784
1983
  ### Business Rules
1785
1984
 
1786
1985
  1. `isDeclined: true` is a valid success response (knockout) — the SDK does **not** throw.
1787
- 2. When `isQuoteChanged = true`, the carrier adjusted the premium. Re-present the updated premium to the applicant before directing them to the link.
1986
+ 2. When `isQuoteChanged = true`, the carrier adjusted the premium. Re-present it before directing the applicant to the link, or call `getPureTermExistingQuote()` to read the updated quote.
1987
+ 3. `quoteResponseId` must belong to Pure Term, otherwise: `QuoteResponseId does not exist or does not belong to the requested product.`
1988
+ 4. `address.state` (when sent) must match the quote state — a mismatch returns `StateMismatchIdentified`.
1989
+ 5. `childRiderInfo` is required **only** when the Dependent Child Rider was selected on the originating quote, and must **not** be sent otherwise — sending it without the rider fails with `Child rider was not included in the quote. Cannot add child rider details.`
1990
+ 6. `tobaccoNicotineUsage.cigarUsagePerYear` is required only when `productTypesUsed` is **exactly** `['cigars']`. When cigars are selected alongside other product types it is not required.
1991
+ 7. `physicianDetails.stateCode` rejects both `"Outside Of The USA"` and `"OutsideUSA"`.
1992
+ 8. Pure Term does **not** run the `ApplicationLimitReached` duplicate SSN/email/phone check (that applies to GIGDB, ADB, and Final Expense).
1993
+ 9. Validation returns at most one message per field; `value.fields` keys are PascalCase and may be nested (e.g. `ChildRiderInfo.IsAnyChildTakingMedication`).
1788
1994
 
1789
1995
 
1790
1996
  ***
1791
1997
 
1792
1998
  ### Knockout Rules
1793
1999
 
1794
- Returns `isDeclined: true` on a successful response — the SDK does **not** throw. Check the field explicitly; do not treat it as an exception.
2000
+ Any of the following returns HTTP `200` with `isDeclined: true` — the SDK does **not** throw. Check the field explicitly.
2001
+
2002
+ - `isUsCitizenOrIsPermanentResident = false`
2003
+ - `isPayerAlsoOwnerAndInsured = false`
2004
+ - `isHoldingValidDriverLicense = false`
2005
+ - `areListedConditionsNotApplicable = false`
2006
+ - Any of the four `childRiderInfo` knockout questions = `true`
2007
+ - Height / weight outside the carrier's allowed limits
2008
+
2009
+
2010
+ ***
2011
+
2012
+ ### Error Codes
2013
+
2014
+ Start Application is one shared service across both Term products, so the code set matches [IB Term](#ib-term--start-application). Business failures return HTTP `400` with `value: null`.
2015
+
2016
+ | Code | `err.response.value` | When |
2017
+ |---|---|---|
2018
+ | `InvalidRequestFormat` | `fields` object present | Any field validation failure |
2019
+ | `StateMismatchIdentified` | `null` | Quote state ≠ `address.state` |
2020
+ | `AgentNotFound` | `null` | Quote cannot be linked to the agent account — verify credentials |
2021
+ | `DataNotFound` | `null` | The quote response could not be found for the supplied `quoteResponseId` |
2022
+ | `InternalServerError` | `null` | Unexpected backend failure — retry; contact support if persistent |
1795
2023
 
1796
2024
 
1797
2025
  ***
@@ -1800,14 +2028,14 @@ Returns `isDeclined: true` on a successful response — the SDK does **not** thr
1800
2028
 
1801
2029
  | Field | Type | Description |
1802
2030
  |---|---|---|
1803
- | `opportunityId` | `string` | All-zero UUID when declined before opportunity creation |
2031
+ | `opportunityId` | `string` | All-zero UUID when declined before opportunity creation — never `null` |
1804
2032
  | `isDeclined` | `boolean` | `true` = knockout; stop the flow |
1805
2033
  | `isQuoteChanged` | `boolean` | `true` = carrier adjusted premium; re-present before handoff |
1806
2034
  | `agentLink` | `string \| null` | Agent Conversational UI |
1807
2035
  | `applicantLink` | `string \| null` | Applicant Conversational UI |
1808
2036
  | `eAppAgentLink` | `string \| null` | Agent E-App |
1809
2037
 
1810
- > After a non-declined response, direct the agent or applicant to the appropriate link. All remaining steps (underwriting, payment, signing) complete inside the InstaBrain frontend.
2038
+ > After a non-declined response, direct the agent or applicant to the appropriate link. All remaining steps (underwriting, payment, signing) complete inside the InstaBrain frontend. Do not pass this `opportunityId` to `finalSubmit()`, the SecureSign methods, or the credit-card iframe.
1811
2039
 
1812
2040
 
1813
2041
  ***
@@ -1815,19 +2043,55 @@ Returns `isDeclined: true` on a successful response — the SDK does **not** thr
1815
2043
  ### Example
1816
2044
 
1817
2045
  ```typescript
1818
- const appResp = await client.startApplication({
2046
+ import {
2047
+ Gender,
2048
+ BeneficiaryType,
2049
+ BeneficiaryRelationship,
2050
+ TobaccoNicotineLastUsedPeriod
2051
+ } from '@instabrain-sdks/api-client';
2052
+
2053
+ const appResp = await client.startPureTermApplication({
1819
2054
  quoteResponseId,
1820
2055
  firstName: 'Jane',
1821
2056
  lastName: 'Doe',
1822
2057
  email: 'jane.doe@example.com',
1823
2058
  phoneNumber: '5551234567',
1824
- // proCode: 'VARIANT_CODE' // omit to start the base product
2059
+ isUsCitizenOrIsPermanentResident: true,
2060
+ isPayerAlsoOwnerAndInsured: true,
2061
+ dateOfBirth: '1989-03-15',
2062
+ socialSecurityNumber: '123456789',
2063
+ address: { addressLine1: '123 Main St', city: 'Austin', state: 'TX', zipcode: '78701' },
2064
+ birthJurisdiction: { country: 'US', state: 'TX' },
2065
+ height: { feet: 5, inches: 6 },
2066
+ weight: 140,
2067
+ isHoldingValidDriverLicense: true,
2068
+ driverLicenseState: 'TX',
2069
+ driverLicenseNumber: 'D12345678',
2070
+ hasPrimaryCarePhysician: false,
2071
+ physicianDetails: null,
2072
+ tobaccoNicotineUsage: {
2073
+ lastUsedPeriod: TobaccoNicotineLastUsedPeriod.Never,
2074
+ lastTimeUsed: null,
2075
+ productTypesUsed: null
2076
+ },
2077
+ areListedConditionsNotApplicable: true,
2078
+ hasExistingCoverage: false,
2079
+ beneficiaryDetails: {
2080
+ beneficiaryType: BeneficiaryType.Person,
2081
+ beneficiaryPerson: {
2082
+ firstName: 'John',
2083
+ lastName: 'Doe',
2084
+ relationship: BeneficiaryRelationship.Spouse
2085
+ }
2086
+ }
2087
+ // childRiderInfo — send ONLY when the Dependent Child Rider is on the quote
1825
2088
  });
1826
2089
 
1827
2090
  if (appResp.isDeclined) {
1828
2091
  return;
1829
2092
  }
1830
2093
  if (appResp.isQuoteChanged) {
2094
+ const updated = await client.getPureTermExistingQuote(appResp.opportunityId);
1831
2095
  // Re-present updated premium before directing to link
1832
2096
  }
1833
2097
  // Hand off to InstaBrain frontend
@@ -2383,6 +2647,149 @@ These methods apply to **GIGDB, ADB, and Final Expense**. IB Term and Pure Term
2383
2647
 
2384
2648
  ---
2385
2649
 
2650
+ ## Payment — EFT or Credit Card
2651
+
2652
+ The payment step sits between Start Application and Prepare Docs, and offers **two mutually exclusive options** for a given `opportunityId`:
2653
+
2654
+ ```
2655
+ Start Application
2656
+ → Payment — choose exactly ONE:
2657
+ EFT: saveEftPayment()
2658
+ Credit card: getCcPaymentIframeUrl() → render iframe → pollCcPaymentStatus()
2659
+ → Prepare Docs → PIN → finalSubmit()
2660
+ ```
2661
+
2662
+ Pick one per opportunity. After a successful EFT save, `getCcPaymentIframeUrl()` returns `EftPaymentAlreadyCompleted`.
2663
+
2664
+ **Who charges the card, and when** — the most important distinction:
2665
+
2666
+ | Product | Card charged at | `finalSubmit()` payment-decline errors? |
2667
+ |---|---|---|
2668
+ | ADB / GIGDB | **`finalSubmit()`**, by InstaBrain | **Yes** — see the decline codes below |
2669
+ | Final Expense | **Never at `finalSubmit()`** — the carrier collects after underwriting | **No** |
2670
+
2671
+ `'approved'` means the card was **captured**, not charged — for every product.
2672
+
2673
+ ---
2674
+
2675
+ ## Get Credit Card Iframe URL
2676
+
2677
+ **Method:** `client.getCcPaymentIframeUrl(opportunityId)` · **Returns:** `Promise<string>`
2678
+
2679
+ Returns the TrustCommerce hosted-page URL for card capture. The SDK never handles card data — render this URL and let the applicant complete the form. **Supported for ADB, GIGDB, and Final Expense only.**
2680
+
2681
+ > **Persist the returned URL keyed by `opportunityId` and reuse it.** A new link is only issued once the latest attempt has **failed**. Calling this again while capture is `pending` *or* already `approved` returns `TcIframeLinkAlreadyGenerated` — that's a signal to reuse the URL you already have, not an error to recover from.
2682
+
2683
+ ### Request
2684
+
2685
+ | Parameter | Type | Required | Description |
2686
+ |---|---|---|---|
2687
+ | `opportunityId` | `string` (query) | Yes | The `opportunityId` from Start Application |
2688
+
2689
+ ### Response
2690
+
2691
+ | Field | Type | Description |
2692
+ |---|---|---|
2693
+ | *(return value)* | `string` | The fully-qualified TrustCommerce iframe URL |
2694
+
2695
+ ### Error Codes
2696
+
2697
+ All return HTTP 400, each as a **distinct** top-level code.
2698
+
2699
+ | Code | When | What to do |
2700
+ |---|---|---|
2701
+ | `InvalidRequestFormat` | `opportunityId` missing or unknown | Fix the ID |
2702
+ | `CcPaymentIframeNotSupportedForProduct` | Product is not ADB / GIGDB / Final Expense | Use `saveEftPayment()` instead (IB Term / Pure Term) |
2703
+ | `ApplicationNotReady` | Start Application has not completed successfully | Complete start application, then retry |
2704
+ | `EftPaymentAlreadyCompleted` | A successful EFT payment already exists | EFT and card are mutually exclusive — nothing to do |
2705
+ | `TcIframeLinkAlreadyGenerated` | A link exists and the latest attempt has not failed | **Reuse the stored URL**; only request a new one after `'failed'` |
2706
+
2707
+ ### Example
2708
+
2709
+ ```typescript
2710
+ const iframeUrl = await client.getCcPaymentIframeUrl(opportunityId);
2711
+ // Persist it — you'll need it again while status is 'pending'.
2712
+ await savePaymentUrl(opportunityId, iframeUrl);
2713
+ // Render iframeUrl to the applicant.
2714
+ ```
2715
+
2716
+ ---
2717
+
2718
+ ## Credit Card Payment Status
2719
+
2720
+ **Methods:** `client.pollCcPaymentStatus(opportunityId, options?)` (recommended) · `client.getCcPaymentStatus(opportunityId)` (single check)
2721
+ **Type:** `ThirdPartyCcPaymentStatusRes`
2722
+
2723
+ Reports whether card capture has completed. Drive your loop off `shouldContinuePolling`, not the `status` string.
2724
+
2725
+ ### Response
2726
+
2727
+ | Field | Type | Description |
2728
+ |---|---|---|
2729
+ | `status` | `CcPaymentStatus` | `'pending'` · `'approved'` · `'failed'` |
2730
+ | `shouldContinuePolling` | `boolean` | `true` only while `'pending'` |
2731
+
2732
+ ### Status values
2733
+
2734
+ | `status` | `shouldContinuePolling` | Meaning | What to do next |
2735
+ |---|---|---|---|
2736
+ | `pending` | `true` | Capture in progress, or the iframe was never opened | Keep polling. **Reuse the stored URL** — do not call `getCcPaymentIframeUrl()`. Do not call `finalSubmit()` (returns `paymentNotMade`). |
2737
+ | `approved` | `false` | Card captured successfully | Proceed to Prepare Docs → signing → `finalSubmit()` |
2738
+ | `failed` | `false` | Declined in the iframe, or (ADB/GIGDB) the `finalSubmit()` charge failed | Call `getCcPaymentIframeUrl()` for a **new** card, then poll again. Do not call `finalSubmit()` (returns `LatestPaymentNotSuccessful`). |
2739
+
2740
+ ### Polling options (`PollCcPaymentStatusOptions`)
2741
+
2742
+ | Option | Default | Meaning |
2743
+ |---|---|---|
2744
+ | `intervalMs` | `10_000` (10s) | Interval between polls — matches the rate limit. **Never set below `10_000`.** |
2745
+ | `maxTotalDurationMs` | `1_800_000` (30 min) | Client-side safety net, matching the Final Expense poller. Card capture has no server-side timeout — it stays `'pending'` until the applicant finishes, so this budget is the only stop. On expiry the poll resolves with the last response rather than throwing. |
2746
+ | `onPoll` | — | `(result, attempt, elapsedMs) => void`, invoked after every poll including the terminal one. Use it to show "waiting for card capture…" instead of awaiting silently. |
2747
+
2748
+ > **Rate limit:** 1 request per 10 seconds per `opportunityId`; exceeding it returns HTTP `429` with `Retry-After: 10`. `pollCcPaymentStatus()` **transparently retries** a 429 after that delay — the managed poll never aborts on rate limiting. A single `getCcPaymentStatus()` call does **not** auto-retry; handle the 429 yourself.
2749
+
2750
+ > `pollCcPaymentStatus()` **never requests a new iframe URL**, including on `'failed'` — the applicant must re-enter card details, so that call is always yours to make.
2751
+
2752
+ ### Example — full card-capture flow
2753
+
2754
+ ```typescript
2755
+ const iframeUrl = await client.getCcPaymentIframeUrl(opportunityId);
2756
+ // …render iframeUrl, applicant submits the card…
2757
+
2758
+ const result = await client.pollCcPaymentStatus(opportunityId, {
2759
+ onPoll: (r, attempt, ms) =>
2760
+ console.log(`poll #${attempt} (${Math.round(ms / 1000)}s): ${r.status}`),
2761
+ });
2762
+
2763
+ switch (result.status) {
2764
+ case 'approved':
2765
+ // Card captured — continue to signing, then finalSubmit().
2766
+ break;
2767
+ case 'failed':
2768
+ // Capture a NEW card, then poll again.
2769
+ await client.getCcPaymentIframeUrl(opportunityId);
2770
+ break;
2771
+ case 'pending':
2772
+ // Budget expired without the applicant finishing — resume later.
2773
+ break;
2774
+ }
2775
+ ```
2776
+
2777
+ ### Recovery after a decline (ADB / GIGDB)
2778
+
2779
+ When `finalSubmit()` fails with a payment decline, the application is **not** submitted:
2780
+
2781
+ 1. `pollCcPaymentStatus()` reports `'failed'` on the next poll
2782
+ 2. Calling `finalSubmit()` again immediately returns `LatestPaymentNotSuccessful`
2783
+ 3. Call `getCcPaymentIframeUrl()` for a new capture → poll to `'approved'` → retry `finalSubmit()`
2784
+
2785
+ **Decline codes** (ADB / GIGDB only — Final Expense never produces these):
2786
+
2787
+ `PaymentCvvInvalid` · `PaymentDeclinedContactBank` · `PaymentDeclined` · `PaymentDeclinedPermanent` · `PaymentPinLocked` · `PaymentInsufficientFunds` · `PaymentProcessingError` · `PaymentSuspectedFraud` · `PaymentCardExpired` · `PaymentInvalidCardData` · `PaymentCardError` · `PaymentContactBank` · `PaymentRelatedError`
2788
+
2789
+ Each maps to a distinct `APIErrorCode` with its own `getUserFriendlyMessage()`.
2790
+
2791
+ ---
2792
+
2386
2793
  ## Save EFT Payment
2387
2794
 
2388
2795
  **Method:** `client.saveEftPayment(request)` · **Type:** `ThirdPartyEftPaymentReq`
@@ -2397,17 +2804,22 @@ Saves bank account details for premium payment. Call after Start Application, be
2397
2804
 
2398
2805
  | Field | Type | Required | Validation Error |
2399
2806
  |---|---|---|---|
2400
- | `opportunityId` | `string` | Yes | `OpportunityId is required.` |
2401
- | `accountHolderName` | `string` | Yes | `Account holder name is required.` / `Account holder name must be 100 characters or fewer.` |
2807
+ | `opportunityId` | `string` | Yes | `OpportunityId is required.` / `OpportunityId does not exist.` |
2808
+ | `accountHolderName` | `string` | Yes | `Account holder name is required.` / `Account holder name must be 100 characters or fewer.` / `Account holder name may only contain letters, spaces, hyphens, and apostrophes.` |
2402
2809
  | `routingNumber` | `string` | Yes | `Routing number is required.` / `Routing number must be 9 digits.` |
2403
2810
  | `accountNumber` | `string` | Yes | `Account number is required.` / `Account number must be 4 to 17 digits.` |
2404
2811
 
2812
+ > `accountHolderName` accepts **letters, spaces, hyphens, and apostrophes only** — max 100 characters. Digits and other punctuation are rejected.
2813
+
2405
2814
 
2406
2815
  ***
2407
2816
 
2408
2817
  ### Business Rules
2409
2818
 
2410
2819
  1. Once EFT payment is saved, quote update calls for the same `opportunityId` are blocked.
2820
+ 2. **EFT and credit card are mutually exclusive per `opportunityId`.** A successful payment that already exists — a prior EFT save, or a card that has already been charged — returns `PaymentAlreadyMade`. After a successful EFT save, [`getCcPaymentIframeUrl()`](#get-credit-card-iframe-url) returns `EftPaymentAlreadyCompleted`.
2821
+ 3. **No application-readiness gate here.** Unlike `getCcPaymentIframeUrl()`, this endpoint does not require Start Application to be fully complete at request validation — it only checks that the opportunity exists and that payment has not already completed. Still call it after Start Application in the integration flow.
2822
+ 4. A successful save **satisfies the payment prerequisite for [`finalSubmit()`](#final-submit)** — no charge runs again at final submit, and neither `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for payment reasons.
2411
2823
 
2412
2824
 
2413
2825
  ***
@@ -2416,8 +2828,10 @@ Saves bank account details for premium payment. Call after Start Application, be
2416
2828
 
2417
2829
  | Code | When |
2418
2830
  |---|---|
2419
- | `InvalidRequestFormat` | Any field validation failure — inspect `value.fields` |
2420
- | `PaymentAlreadyMade` | EFT already saved for this opportunity |
2831
+ | `InvalidRequestFormat` | Any field validation failure, or `opportunityId` does not exist — inspect `value.fields` |
2832
+ | `PaymentAlreadyMade` | A successful payment already exists for this opportunity (prior EFT save, or a card already charged) |
2833
+
2834
+ > A credit card that was only **captured** and not yet charged does not trigger `PaymentAlreadyMade` at request validation. Do not rely on that edge case — treat the two payment methods as mutually exclusive.
2421
2835
 
2422
2836
 
2423
2837
  ***
@@ -2448,7 +2862,7 @@ await client.saveEftPayment({
2448
2862
  **Method:** `client.prepareDocsAndGetDeliveryChannels(opportunityId)`
2449
2863
 
2450
2864
 
2451
- Always call this first in the signing flow. Prepares e-signature documents server-side and returns available delivery channels.
2865
+ Always call this first in the signing flow. Prepares e-signature documents server-side and returns available delivery channels. Applies to **ADB, GIGDB, and Final Expense**.
2452
2866
 
2453
2867
 
2454
2868
  ***
@@ -2465,6 +2879,8 @@ Always call this first in the signing flow. Prepares e-signature documents serve
2465
2879
  ### Business Rules
2466
2880
 
2467
2881
  1. If `isSignCompleted = true`, documents are already signed — skip Send PIN, Resend PIN, and Verify PIN. Call Final Submit directly.
2882
+ 2. `isSmsAvailable` / `isEmailAvailable` determine which channels may be selected in [Send PIN](#send-pin--get-documents-link) — only an available channel is accepted.
2883
+ 3. **Start Application must have completed successfully** before this endpoint can be called. If not, it returns `ApplicationNotReady` — the same lifecycle gate [`getCcPaymentIframeUrl()`](#get-credit-card-iframe-url) applies.
2468
2884
 
2469
2885
 
2470
2886
  ***
@@ -2474,11 +2890,14 @@ Always call this first in the signing flow. Prepares e-signature documents serve
2474
2890
  | Code | When |
2475
2891
  |---|---|
2476
2892
  | `InvalidRequestFormat` | `OpportunityId is required.` / `OpportunityId does not exist.` / `Documents are already signed.` (field-level) |
2893
+ | `ApplicationNotReady` | Start Application has not completed successfully, or signing was called too early. Message: `Application is not ready for e-signing. Complete Start Application successfully, then retry.` |
2477
2894
  | `DocumentsAlreadySigned` | Documents already completed for this opportunity |
2478
2895
  | `SecureSignRelatedError` | Generic SecureSign failure during document preparation — retry; if persistent, contact support |
2479
2896
 
2480
2897
  > When signing is already complete, you may see `DocumentsAlreadySigned` or the `InvalidRequestFormat` field message `"Documents are already signed."` — both are terminal; do not retry Prepare Docs / Send PIN.
2481
2898
 
2899
+ > `ApplicationNotReady` is **retryable** — unlike the terminal codes above. Complete Start Application, then call this again.
2900
+
2482
2901
 
2483
2902
  ***
2484
2903
 
@@ -2709,7 +3128,7 @@ if (verifyResp.isVerified) {
2709
3128
  **Method:** `client.finalSubmit(opportunityId)`
2710
3129
 
2711
3130
 
2712
- Submits the signed application to the carrier. Can only be called once per opportunity.
3131
+ Submits the signed application to the carrier.
2713
3132
 
2714
3133
 
2715
3134
  ***
@@ -2718,9 +3137,7 @@ Submits the signed application to the carrier. Can only be called once per oppor
2718
3137
 
2719
3138
  | Field | Type | Required | Validation Error |
2720
3139
  |---|---|---|---|
2721
- | `opportunityId` | `string` | Yes | `OpportunityId is required.` / `OpportunityId does not exist.` / `Application has already been final submitted.` |
2722
-
2723
- > `"Application has already been final submitted."` is a terminal state — do not retry.
3140
+ | `opportunityId` | `string` | Yes | `OpportunityId is required.` / `OpportunityId does not exist.` |
2724
3141
 
2725
3142
  > Throws `AuthenticationError` when `opportunityId` is not authorized for the current JWT.
2726
3143
 
@@ -2729,11 +3146,49 @@ Submits the signed application to the carrier. Can only be called once per oppor
2729
3146
 
2730
3147
  ### Business Rules
2731
3148
 
2732
- 1. Can only be called once. Subsequent calls for the same `opportunityId` are rejected.
3149
+ 1. **A repeat call after a successful submit is idempotent.** The API does not re-submit to the carrier or re-charge payment — it returns the existing result, including the same `policyNumber`. Do not guard against it client-side or treat it as an error.
2733
3150
  2. `policyNumber` may be `null` — carrier decisions can be async/pending. A `null` on `flagStatus: true` is **not** an error.
2734
3151
  3. **Response shape differs by product:**
2735
3152
  - **ADB / GIGDB (synchronous):** `policyNumber` is a non-null string; `applicationStatus` is **absent**.
2736
3153
  - **Final Expense (asynchronous):** `policyNumber` is `null` and `applicationStatus` is `'InProgress'`. Check `applicationStatus === 'InProgress'` and then poll [`pollFinalExpenseUnderwritingStatus()`](#final-expense--underwriting-status-async).
3154
+ 4. **Payment must already be successful.** How that is satisfied depends on the method:
3155
+ - **EFT (all products)** — collected at `saveEftPayment()`; no charge runs here.
3156
+ - **Credit card, ADB / GIGDB** — the captured card is charged here, and the application is submitted only if the charge succeeds. A decline returns a `Payment*` code and the application is **not** submitted.
3157
+ - **Credit card, Final Expense** — capture to `approved` is required, but InstaBrain does not charge here; the carrier collects after underwriting. Final Expense never returns a `Payment*` decline code.
3158
+
3159
+
3160
+ ***
3161
+
3162
+ ### Pre-Submit Gates
3163
+
3164
+ Three checks run in this order. They are **separate, distinguishable codes** — do not collapse the last two into one client-side case.
3165
+
3166
+ | Order | Code | Meaning | Recovery |
3167
+ |---|---|---|---|
3168
+ | 1 | `SecureSignNotCompleted` | Signing is not finished | Complete the PIN flow, or confirm `isSignCompleted` from prepare-docs |
3169
+ | 2 | `paymentNotMade` | Nothing to submit yet — no payment was started, **or** a card capture is still `pending` | Finish the iframe and poll to `approved`, or save EFT. While pending, **reuse the stored iframe URL** — do not request a new one |
3170
+ | 3 | `LatestPaymentNotSuccessful` | A payment was attempted and the latest attempt **failed** | Call `getCcPaymentIframeUrl()` for a new capture, poll to `approved`, then retry |
3171
+
3172
+ > The distinction matters: `paymentNotMade` means "keep waiting or start a payment"; `LatestPaymentNotSuccessful` means "a payment was tried and it failed — start a new capture." Retrying final submit after a decline without a new successful capture returns `LatestPaymentNotSuccessful`, not another decline code.
3173
+
3174
+ ```typescript
3175
+ import { APIValidationError, APIErrorCode } from '@instabrain-sdks/api-client';
3176
+
3177
+ try {
3178
+ const resp = await client.finalSubmit(opportunityId);
3179
+ } catch (err) {
3180
+ if (err instanceof APIValidationError) {
3181
+ if (err.isErrorType(APIErrorCode.SecureSignNotCompleted)) {
3182
+ // Finish signing first
3183
+ } else if (err.isErrorType(APIErrorCode.PaymentNotMade)) {
3184
+ // Reuse the existing iframe URL and keep polling — do NOT request a new one
3185
+ } else if (err.isErrorType(APIErrorCode.LatestPaymentNotSuccessful)) {
3186
+ // Start a fresh capture
3187
+ const url = await client.getCcPaymentIframeUrl(opportunityId);
3188
+ }
3189
+ }
3190
+ }
3191
+ ```
2737
3192
 
2738
3193
 
2739
3194
  ***
@@ -2742,9 +3197,12 @@ Submits the signed application to the carrier. Can only be called once per oppor
2742
3197
 
2743
3198
  | Code | When |
2744
3199
  |---|---|
2745
- | `InvalidRequestFormat` | `opportunityId` missing, not found, or already submitted |
2746
- | `PaymentNotMade` | EFT not saved — call `saveEftPayment()` first |
3200
+ | `InvalidRequestFormat` | `opportunityId` missing or not found |
3201
+ | `SecureSignNotCompleted` | Signing not complete — gate 1 |
3202
+ | `paymentNotMade` | No payment started, or card capture still pending — gate 2 |
3203
+ | `LatestPaymentNotSuccessful` | Latest payment attempt failed — gate 3 |
2747
3204
  | `FidelityFinalSubmitError` | Fidelity carrier rejected or failed to process the final submission — contact support with the `opportunityId` |
3205
+ | `Payment*` decline codes | ADB / GIGDB only — the card charge was declined at final submit and the application was **not** submitted. See [Get credit card iframe URL](#get-credit-card-iframe-url) |
2748
3206
 
2749
3207
 
2750
3208
  ***
@@ -3032,10 +3490,24 @@ Named entity types: `Business` · `Corporation` · `CharitableOrganization` · `
3032
3490
  ```
3033
3491
  InstaBrainError
3034
3492
  ├── AuthenticationError — invalid credentials, expired JWT, or unauthorized opportunityId
3035
- ├── ValidationError — client-side / transport validation before a successful response
3036
- └── APIValidationError — server returned flagStatus: false (check APIErrorCode)
3493
+ ├── ValidationError — retained for backward compatibility; no longer thrown by the SDK
3494
+ └── APIValidationError — business / validation failure (check APIErrorCode)
3037
3495
  ```
3038
3496
 
3497
+ **`APIValidationError` covers both failure shapes.** The API reports a rejected request two ways — HTTP `400` with a top-level `error`, or HTTP `200` with `flagStatus: false` — and which one you get varies by endpoint. Both now produce an `APIValidationError` with the same `errorCode` and `response`, so a single `catch` handles either:
3498
+
3499
+ ```typescript
3500
+ catch (err) {
3501
+ if (err instanceof APIValidationError) {
3502
+ err.isErrorType(APIErrorCode.ApplicationNotReady); // works on both paths
3503
+ err.getUserFriendlyMessage();
3504
+ err.response?.value?.fields; // per-field detail
3505
+ }
3506
+ }
3507
+ ```
3508
+
3509
+ > `ValidationError` is still exported so existing `import` statements keep compiling, but nothing in the SDK throws it. If you have a `catch` branch testing `err instanceof ValidationError`, switch it to `APIValidationError`.
3510
+
3039
3511
 
3040
3512
  ***
3041
3513
 
@@ -3109,25 +3581,36 @@ if (err instanceof APIValidationError && err.isErrorType(APIErrorCode.InvalidReq
3109
3581
 
3110
3582
  Active `APIErrorCode` enum members match the tables below. Compare failures with `err.isErrorType(APIErrorCode.X)` — do not rely on raw string casing; use the **String Value** column when logging or debugging.
3111
3583
 
3112
- Deprecated enum members (`QuoteNotFound`, `HeightNotValid`, `DocumentsNotViewed`, and others) remain in the package for backward compatibility but are **not** listed here; the API surfaces those cases via `InvalidRequestFormat` and `value.fields` instead.
3584
+ Some enum members remain in the package for backward compatibility but are **not** listed here; the API surfaces those cases via `InvalidRequestFormat` and `value.fields` instead. Note that scope is **per product** — a code that is field-level for one product can be a top-level business code for another, so a member being absent from one product's table does not make it dead.
3113
3585
 
3114
3586
 
3115
3587
  ***
3116
3588
 
3117
3589
  ### Quote Errors
3118
3590
 
3119
- | Code | String Value | Products | When |
3120
- |---|---|---|---|
3121
- | `InvalidRequestFormat` | `'InvalidRequestFormat'` | All | Any validation failure — inspect `value.fields` |
3122
- | `StateNotFound` | `'stateNotFound'` | All quotes | State code not recognized |
3123
- | `AgeNotFound` | `'AgeNotFound'` | All quotes | Neither age nor date of birth supplied, or age could not be derived |
3124
- | `NotAvailableForState` | `'NotAvailableForState'` | All quotes | Product not available in state |
3125
- | `QuoteNotEligibleForGivenConditions` | `'QuoteNotEligibleForGivenConditions'` | All quotes | State/age/nicotine combo not eligible |
3126
- | `CoverageNotAvailable` | `'CoverageNotAvailable'` | All quotes | Face amount out of range |
3127
- | `RiderNotAvailable` | `'RiderNotAvailable'` | ADB, IB Term | Rider unavailable for product/state |
3128
- | `RiderFaceAmountNotValid` | `'RiderFaceAmountNotValid'` | ADB, IB Term | Rider face amount out of range |
3129
- | `BenefitPeriodNotAvailable` | `'BenefitPeriodNotAvailable'` | IB Term | Benefit period not allowed for state/age/nicotine |
3130
- | `OutsideBuildChart` | `'outsideBuildChart'` | IB Term | Height & weight provided and outside carrier build chart |
3591
+ | Code | String Value | When |
3592
+ |---|---|---|
3593
+ | `InvalidRequestFormat` | `'InvalidRequestFormat'` | Any field validation failure — inspect `value.fields` |
3594
+ | `StateNotFound` | `'stateNotFound'` | State code not recognized |
3595
+ | `AgeNotFound` | `'AgeNotFound'` | Neither age nor date of birth supplied, or age could not be derived |
3596
+ | `NotAvailableForState` | `'NotAvailableForState'` | Product not available in state |
3597
+ | `QuoteNotEligibleForGivenConditions` | `'QuoteNotEligibleForGivenConditions'` | State/age/nicotine combo not eligible |
3598
+ | `CoverageNotAvailable` | `'CoverageNotAvailable'` | Face amount out of range |
3599
+ | `RiderNotAvailable` | `'RiderNotAvailable'` | Rider unavailable for product/state |
3600
+ | `RiderFaceAmountNotValid` | `'RiderFaceAmountNotValid'` | Rider face amount out of range |
3601
+ | `BenefitPeriodNotAvailable` | `'BenefitPeriodNotAvailable'` | Benefit period not allowed for state/age/nicotine |
3602
+ | `OutsideBuildChart` | `'outsideBuildChart'` | Height & weight provided and outside carrier build chart |
3603
+ | `HeightNotValid` | `'HeightNotValid'` | `height.feet` / `height.inches` out of range (feet 1–8, inches 0–11) |
3604
+
3605
+ **Which codes each product returns** — the rider codes are the main difference, so branch per product rather than assuming one shared list:
3606
+
3607
+ | Product | Business codes returned as top-level `error` |
3608
+ |---|---|
3609
+ | **ADB** | `QuoteNotEligibleForGivenConditions`, `NotAvailableForState`, `CoverageNotAvailable`, `RiderNotAvailable`, `RiderFaceAmountNotValid` |
3610
+ | **GIGDB** | `QuoteNotEligibleForGivenConditions`, `NotAvailableForState`, `CoverageNotAvailable` — rider codes do **not** apply |
3611
+ | **Final Expense** | `stateNotFound`, `AgeNotFound`, `HeightNotValid`, `BenefitPeriodNotAvailable`, `QuoteNotEligibleForGivenConditions`, `NotAvailableForState`, `CoverageNotAvailable` |
3612
+ | **IB Term** | `BenefitPeriodNotAvailable`, `CoverageNotAvailable`, `outsideBuildChart`, `QuoteNotEligibleForGivenConditions`, `NotAvailableForState`, `RiderNotAvailable`, `RiderFaceAmountNotValid` |
3613
+ | **Pure Term** | Same set as IB Term. Request validation produces dedicated codes only for `BenefitPeriodNotAvailable` / `CoverageNotAvailable` (everything else is field-level `InvalidRequestFormat`), but the shared eligibility pipeline that runs **after** validation can still return `NotAvailableForState`, `QuoteNotEligibleForGivenConditions`, `RiderNotAvailable`, `RiderFaceAmountNotValid`, and `outsideBuildChart` |
3131
3614
 
3132
3615
 
3133
3616
  ***
@@ -3136,10 +3619,21 @@ Deprecated enum members (`QuoteNotFound`, `HeightNotValid`, `DocumentsNotViewed`
3136
3619
 
3137
3620
  | Code | String Value | Products | When |
3138
3621
  |---|---|---|---|
3139
- | `ApplicationLimitReached` | `'ApplicationLimitReached'` | ADB, GIGDB, Final Expense | Same SSN/email/phone has policy within last 30 days. Not used by IB Term. |
3622
+ | `ApplicationLimitReached` | `'ApplicationLimitReached'` | ADB, GIGDB, Final Expense | Same SSN/email/phone has policy within last 30 days. Not used by IB Term or Pure Term. |
3140
3623
  | `StateMismatchIdentified` | `'StateMismatchIdentified'` | All | Quote state ≠ application address state — re-quote |
3141
3624
  | `AgentNotFound` | `'agentNotFound'` | All | Quote cannot be linked to agent account — verify credentials |
3142
3625
  | `InternalServerError` | `'internalServerError'` | All | Unexpected backend failure — retry; if persistent contact support |
3626
+ | `DataNotFound` | `'dataNotFound'` | IB Term, Pure Term | The quote referenced by `quoteResponseId` could not be found — create a new quote |
3627
+
3628
+ **Three outcome shapes — do not conflate them.** Start Application distinguishes field validation, business failure, and knockout:
3629
+
3630
+ | Outcome | HTTP | Response shape | Codes |
3631
+ |---|---|---|---|
3632
+ | **Field validation** | `400` | `value.fields` populated with per-field messages | `InvalidRequestFormat`, `ApplicationLimitReached` |
3633
+ | **Business failure** | `400` | `value: null`, top-level `error` | `StateMismatchIdentified`, `agentNotFound`, `internalServerError`, `dataNotFound` |
3634
+ | **Decline / knockout** | **`200`** | `flagStatus: true`, `value.isDeclined: true` | **None** — a knockout is *not* an error code and the SDK does **not** throw |
3635
+
3636
+ > The decline row is the one that trips integrations up: a knockout arrives as a **successful** response. Check `resp.isDeclined` explicitly — it will never reach your `catch` block.
3143
3637
 
3144
3638
 
3145
3639
  ***
@@ -3148,7 +3642,9 @@ Deprecated enum members (`QuoteNotFound`, `HeightNotValid`, `DocumentsNotViewed`
3148
3642
 
3149
3643
  | Code | String Value | Products | When |
3150
3644
  |---|---|---|---|
3151
- | `PaymentAlreadyMade` | `'PaymentAlreadyMade'` | ADB, GIGDB | `update*Quote()` or `saveEftPayment()` after EFT is already saved for the opportunity |
3645
+ | `PaymentAlreadyMade` | `'PaymentAlreadyMade'` | ADB, GIGDB, Final Expense | `update*Quote()` or `saveEftPayment()` when a **successful** payment already exists — a prior EFT save, or a card already charged. A card that was only captured and not yet charged does not trigger this |
3646
+ | `EftPaymentAlreadyCompleted` | `'EftPaymentAlreadyCompleted'` | ADB, GIGDB, Final Expense | `getCcPaymentIframeUrl()` after a successful EFT save — the two methods are mutually exclusive per opportunity |
3647
+ | `ApplicationNotReady` | `'ApplicationNotReady'` | ADB, GIGDB, Final Expense | `getCcPaymentIframeUrl()` or `prepareDocsAndGetDeliveryChannels()` before Start Application has completed successfully. **Retryable** — complete Start Application, then call again |
3152
3648
 
3153
3649
 
3154
3650
  ***
@@ -3173,7 +3669,9 @@ Deprecated enum members (`QuoteNotFound`, `HeightNotValid`, `DocumentsNotViewed`
3173
3669
 
3174
3670
  | Code | String Value | When |
3175
3671
  |---|---|---|
3176
- | `PaymentNotMade` | `'paymentNotMade'` | EFT not saved — call `saveEftPayment()` before `finalSubmit()` |
3672
+ | `SecureSignNotCompleted` | `'SecureSignNotCompleted'` | **Gate 1** — signing not finished. Complete the PIN flow, or confirm `isSignCompleted` from prepare-docs |
3673
+ | `PaymentNotMade` | `'paymentNotMade'` | **Gate 2** — nothing to submit yet: no payment was started, **or** a card capture is still `pending`. Finish the capture and poll to `approved`, or call `saveEftPayment()`. Reuse the stored iframe URL while pending |
3674
+ | `LatestPaymentNotSuccessful` | `'LatestPaymentNotSuccessful'` | **Gate 3** — a payment was attempted and the latest attempt **failed**. Call `getCcPaymentIframeUrl()` for a new capture, poll to `approved`, then retry |
3177
3675
  | `FidelityFinalSubmitError` | `'FidelityFinalSubmitError'` | Fidelity carrier rejected or failed to process the submission — contact support with the `opportunityId` |
3178
3676
  | `FinalSubmitStatusNotSupported` | `'FinalSubmitStatusNotSupported'` | Underwriting status polling attempted for a non-Final-Expense product — `pingFinalExpenseUnderwritingStatus()` / `pollFinalExpenseUnderwritingStatus()` are Final Expense only |
3179
3677