@instabrain-sdks/api-client 2.3.3 → 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.
@@ -1,31 +1,117 @@
1
1
  import { HttpClient } from '../utils/http-client';
2
2
  import { BaseService } from './base.service';
3
- import { ThirdPartyPureTermQuoteReq } from '../types/pureterm.types';
4
- import { ThirdPartyQuoteResp } from '../types';
3
+ import { ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq } from '../types/pureterm.types';
4
+ import { ThirdPartyQuoteResp, ThirdPartyStartAppResp } from '../types';
5
5
  /**
6
6
  * Pure Term (InstaBrain Pure Term) service
7
- * Handles quoting for the Pure Term product.
7
+ * Handles lookup, quoting, and application for the Pure Term product (ages 18–60).
8
8
  *
9
9
  * Flow:
10
- * 1. getQuote() → quoteResponseId
11
- * 2. InstaBrainClient.startApplication() → agentLink / applicantLink / eAppAgentLink
10
+ * 1. (optional) getRiderDetails(stateCode, age, flagNicotineUse) → rider availability + codes
11
+ * 2. getQuote() → quoteResponseId
12
+ * 3. startApplication() → opportunityId + links (or isDeclined=true)
13
+ * 4. (optional) getExistingQuote(opportunityId) → re-fetch the stored quote
12
14
  *
13
15
  * After startApplication(), direct the agent or applicant to the returned link.
14
16
  * All remaining steps (underwriting, payment, signing) complete inside the
15
- * InstaBrain frontend. Do NOT call saveEftPayment(), SecureSign methods, or
16
- * finalSubmit() for Pure Term.
17
+ * InstaBrain frontend — the same hand-off family as IB Term. Do NOT wire a Pure
18
+ * Term `opportunityId` into the shared SecureSign, finalSubmit(), or credit-card
19
+ * iframe clients. Shared EFT (`saveEftPayment()`) is allowed; the credit-card
20
+ * iframe is not supported for Pure Term and returns
21
+ * `CcPaymentIframeNotSupportedForProduct`.
17
22
  */
18
23
  export declare class PureTermService extends BaseService {
19
24
  constructor(httpClient: HttpClient);
25
+ /**
26
+ * Get available riders for Pure Term in a given state, filtered by the
27
+ * applicant's age and nicotine-use status.
28
+ *
29
+ * Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
30
+ * in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
31
+ * do not proceed to the Quote API. The empty `riders` array in that case is a
32
+ * valid business state, not an error, and is returned as-is by the SDK.
33
+ *
34
+ * Use `riderCode` from the response as `riders[n].rider` on the Pure Term quote.
35
+ *
36
+ * @param stateCode - Two-letter US state code (e.g. "TX").
37
+ * @param age - Applicant's age, integer, 18–60 inclusive.
38
+ * @param flagNicotineUse - Whether the applicant uses nicotine; required by the backend.
39
+ * @returns Rider list + product availability flag.
40
+ */
41
+ getRiderDetails(stateCode: string, age: number, flagNicotineUse: boolean): Promise<PureTermRiderDetailsResp>;
20
42
  /**
21
43
  * Get a Pure Term insurance quote.
22
44
  *
23
- * Provide exactly one rating group: `rateClass`, OR `healthClass`, OR
24
- * both `height` and `weightInLbs`. `benefitPeriod` and `stateCode` are
25
- * required. Supply `age` OR `dateOfBirth` (18–60).
45
+ * `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
46
+ * required. Supply at least one rating group — `rateClass`, `healthClass`, or
47
+ * both `height` and `weightInLbs`; passing more than one is allowed. Supply
48
+ * `age` OR `dateOfBirth` (18–60); `dateOfBirth` wins when both are sent.
49
+ * `flagTobaccoUse` defaults to `false`.
50
+ *
51
+ * Pure Term uses the same quote request shape as IB Term but different product
52
+ * rules (rate classes including Rated C/D, term lengths including 15,
53
+ * coverage/benefit tables) — see {@link ThirdPartyPureTermQuoteReq} for the
54
+ * exact rules in check order.
55
+ *
56
+ * **Errors come from two stages.** Request validation issues dedicated
57
+ * top-level codes only for `BenefitPeriodNotAvailable` and
58
+ * `CoverageNotAvailable`; every other field failure surfaces as
59
+ * `InvalidRequestFormat` with PascalCase keys under `value.fields`. Once
60
+ * validation passes, the shared quote-eligibility pipeline can still return
61
+ * `NotAvailableForState`, `QuoteNotEligibleForGivenConditions`,
62
+ * `RiderNotAvailable`, `RiderFaceAmountNotValid`, or `outsideBuildChart` —
63
+ * do not assume those never occur for Pure Term.
26
64
  *
27
65
  * @param request - The Pure Term quote request payload.
28
66
  * @returns Promise with the quote response including `quoteResponseId`.
29
67
  */
30
68
  getQuote(request: ThirdPartyPureTermQuoteReq): Promise<ThirdPartyQuoteResp>;
69
+ /**
70
+ * Get the existing quote for an in-flight Pure Term opportunity.
71
+ *
72
+ * Use to resume or review a previously generated Pure Term quote by its
73
+ * opportunity ID without re-quoting. The response reuses the same shape as
74
+ * `getQuote()` — `productName` is `"InstaBrain Pure Term"`.
75
+ *
76
+ * Unlike rider-details product-unavailability, a not-found result here is an
77
+ * error (surfaced via the SDK error model), not a valid business state:
78
+ * - missing / empty / non-GUID `opportunityId` → `InvalidRequestFormat`
79
+ * ("OpportunityId is required." / "OpportunityId does not exist.")
80
+ * - opportunity belongs to a different product → "OpportunityId does not
81
+ * match selected product." (field-level message under `InvalidRequestFormat`)
82
+ * - opportunity exists but has no stored quote → `QuoteNotFound` (top-level, `value: null`)
83
+ *
84
+ * @param opportunityId - UUID from a prior Pure Term application/quote flow.
85
+ * @returns Promise with the current quote response.
86
+ */
87
+ getExistingQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
88
+ /**
89
+ * Start a Pure Term application from a prior Pure Term quote.
90
+ *
91
+ * This is a dedicated endpoint, separate from the generic
92
+ * `InstaBrainClient.startApplication()` (`/api/ThirdPartyStartApp/start-application`),
93
+ * which remains unchanged for other products.
94
+ *
95
+ * Notes:
96
+ * - `isDeclined: true` is a valid success response (knockout), not an error.
97
+ * Knockouts: `isUsCitizenOrIsPermanentResident=false`,
98
+ * `isPayerAlsoOwnerAndInsured=false`, `isHoldingValidDriverLicense=false`,
99
+ * `areListedConditionsNotApplicable=false`, any of the four `childRiderInfo`
100
+ * knockout questions `=true`, or height/weight outside allowed limits.
101
+ * - `quoteResponseId` must belong to the Pure Term product.
102
+ * - `childRiderInfo` is required only when the Dependent Child Rider was on the
103
+ * quote, and must NOT be sent otherwise.
104
+ * - Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense only).
105
+ * - Start Application is one shared service across both Term products, so the
106
+ * error set matches IB Term. Business failures return HTTP 400 with
107
+ * `value: null` and a top-level `agentNotFound` (missing user context),
108
+ * `StateMismatchIdentified` (quote state differs from `address.state`),
109
+ * `dataNotFound` (quote response not found), or `internalServerError`.
110
+ * - After a successful, non-declined start, hand off via the returned links —
111
+ * do not continue into shared SecureSign / finalSubmit with this `opportunityId`.
112
+ *
113
+ * @param request - The Pure Term application request payload.
114
+ * @returns Promise with opportunityId, links, isDeclined flag, and `isQuoteChanged`.
115
+ */
116
+ startApplication(request: PureTermStartApplicationReq): Promise<ThirdPartyStartAppResp>;
31
117
  }
@@ -4,27 +4,67 @@ exports.PureTermService = void 0;
4
4
  const base_service_1 = require("./base.service");
5
5
  /**
6
6
  * Pure Term (InstaBrain Pure Term) service
7
- * Handles quoting for the Pure Term product.
7
+ * Handles lookup, quoting, and application for the Pure Term product (ages 18–60).
8
8
  *
9
9
  * Flow:
10
- * 1. getQuote() → quoteResponseId
11
- * 2. InstaBrainClient.startApplication() → agentLink / applicantLink / eAppAgentLink
10
+ * 1. (optional) getRiderDetails(stateCode, age, flagNicotineUse) → rider availability + codes
11
+ * 2. getQuote() → quoteResponseId
12
+ * 3. startApplication() → opportunityId + links (or isDeclined=true)
13
+ * 4. (optional) getExistingQuote(opportunityId) → re-fetch the stored quote
12
14
  *
13
15
  * After startApplication(), direct the agent or applicant to the returned link.
14
16
  * All remaining steps (underwriting, payment, signing) complete inside the
15
- * InstaBrain frontend. Do NOT call saveEftPayment(), SecureSign methods, or
16
- * finalSubmit() for Pure Term.
17
+ * InstaBrain frontend — the same hand-off family as IB Term. Do NOT wire a Pure
18
+ * Term `opportunityId` into the shared SecureSign, finalSubmit(), or credit-card
19
+ * iframe clients. Shared EFT (`saveEftPayment()`) is allowed; the credit-card
20
+ * iframe is not supported for Pure Term and returns
21
+ * `CcPaymentIframeNotSupportedForProduct`.
17
22
  */
18
23
  class PureTermService extends base_service_1.BaseService {
19
24
  constructor(httpClient) {
20
25
  super(httpClient);
21
26
  }
27
+ /**
28
+ * Get available riders for Pure Term in a given state, filtered by the
29
+ * applicant's age and nicotine-use status.
30
+ *
31
+ * Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
32
+ * in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
33
+ * do not proceed to the Quote API. The empty `riders` array in that case is a
34
+ * valid business state, not an error, and is returned as-is by the SDK.
35
+ *
36
+ * Use `riderCode` from the response as `riders[n].rider` on the Pure Term quote.
37
+ *
38
+ * @param stateCode - Two-letter US state code (e.g. "TX").
39
+ * @param age - Applicant's age, integer, 18–60 inclusive.
40
+ * @param flagNicotineUse - Whether the applicant uses nicotine; required by the backend.
41
+ * @returns Rider list + product availability flag.
42
+ */
43
+ async getRiderDetails(stateCode, age, flagNicotineUse) {
44
+ return this.get('get Pure Term rider details', '/api/ThirdPartyIbPureTermLookup/get-rider-details', { params: { stateCode, age, flagNicotineUse } });
45
+ }
22
46
  /**
23
47
  * Get a Pure Term insurance quote.
24
48
  *
25
- * Provide exactly one rating group: `rateClass`, OR `healthClass`, OR
26
- * both `height` and `weightInLbs`. `benefitPeriod` and `stateCode` are
27
- * required. Supply `age` OR `dateOfBirth` (18–60).
49
+ * `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
50
+ * required. Supply at least one rating group — `rateClass`, `healthClass`, or
51
+ * both `height` and `weightInLbs`; passing more than one is allowed. Supply
52
+ * `age` OR `dateOfBirth` (18–60); `dateOfBirth` wins when both are sent.
53
+ * `flagTobaccoUse` defaults to `false`.
54
+ *
55
+ * Pure Term uses the same quote request shape as IB Term but different product
56
+ * rules (rate classes including Rated C/D, term lengths including 15,
57
+ * coverage/benefit tables) — see {@link ThirdPartyPureTermQuoteReq} for the
58
+ * exact rules in check order.
59
+ *
60
+ * **Errors come from two stages.** Request validation issues dedicated
61
+ * top-level codes only for `BenefitPeriodNotAvailable` and
62
+ * `CoverageNotAvailable`; every other field failure surfaces as
63
+ * `InvalidRequestFormat` with PascalCase keys under `value.fields`. Once
64
+ * validation passes, the shared quote-eligibility pipeline can still return
65
+ * `NotAvailableForState`, `QuoteNotEligibleForGivenConditions`,
66
+ * `RiderNotAvailable`, `RiderFaceAmountNotValid`, or `outsideBuildChart` —
67
+ * do not assume those never occur for Pure Term.
28
68
  *
29
69
  * @param request - The Pure Term quote request payload.
30
70
  * @returns Promise with the quote response including `quoteResponseId`.
@@ -32,5 +72,57 @@ class PureTermService extends base_service_1.BaseService {
32
72
  async getQuote(request) {
33
73
  return this.post('get Pure Term quote', '/api/ThirdPartyIbPureTermQuote/get', request);
34
74
  }
75
+ /**
76
+ * Get the existing quote for an in-flight Pure Term opportunity.
77
+ *
78
+ * Use to resume or review a previously generated Pure Term quote by its
79
+ * opportunity ID without re-quoting. The response reuses the same shape as
80
+ * `getQuote()` — `productName` is `"InstaBrain Pure Term"`.
81
+ *
82
+ * Unlike rider-details product-unavailability, a not-found result here is an
83
+ * error (surfaced via the SDK error model), not a valid business state:
84
+ * - missing / empty / non-GUID `opportunityId` → `InvalidRequestFormat`
85
+ * ("OpportunityId is required." / "OpportunityId does not exist.")
86
+ * - opportunity belongs to a different product → "OpportunityId does not
87
+ * match selected product." (field-level message under `InvalidRequestFormat`)
88
+ * - opportunity exists but has no stored quote → `QuoteNotFound` (top-level, `value: null`)
89
+ *
90
+ * @param opportunityId - UUID from a prior Pure Term application/quote flow.
91
+ * @returns Promise with the current quote response.
92
+ */
93
+ async getExistingQuote(opportunityId) {
94
+ return this.get('get existing Pure Term quote', '/api/ThirdPartyIbPureTermQuote/get-existing-quote', { params: { opportunityId } });
95
+ }
96
+ /**
97
+ * Start a Pure Term application from a prior Pure Term quote.
98
+ *
99
+ * This is a dedicated endpoint, separate from the generic
100
+ * `InstaBrainClient.startApplication()` (`/api/ThirdPartyStartApp/start-application`),
101
+ * which remains unchanged for other products.
102
+ *
103
+ * Notes:
104
+ * - `isDeclined: true` is a valid success response (knockout), not an error.
105
+ * Knockouts: `isUsCitizenOrIsPermanentResident=false`,
106
+ * `isPayerAlsoOwnerAndInsured=false`, `isHoldingValidDriverLicense=false`,
107
+ * `areListedConditionsNotApplicable=false`, any of the four `childRiderInfo`
108
+ * knockout questions `=true`, or height/weight outside allowed limits.
109
+ * - `quoteResponseId` must belong to the Pure Term product.
110
+ * - `childRiderInfo` is required only when the Dependent Child Rider was on the
111
+ * quote, and must NOT be sent otherwise.
112
+ * - Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense only).
113
+ * - Start Application is one shared service across both Term products, so the
114
+ * error set matches IB Term. Business failures return HTTP 400 with
115
+ * `value: null` and a top-level `agentNotFound` (missing user context),
116
+ * `StateMismatchIdentified` (quote state differs from `address.state`),
117
+ * `dataNotFound` (quote response not found), or `internalServerError`.
118
+ * - After a successful, non-declined start, hand off via the returned links —
119
+ * do not continue into shared SecureSign / finalSubmit with this `opportunityId`.
120
+ *
121
+ * @param request - The Pure Term application request payload.
122
+ * @returns Promise with opportunityId, links, isDeclined flag, and `isQuoteChanged`.
123
+ */
124
+ async startApplication(request) {
125
+ return this.post('start Pure Term application', '/api/ThirdPartyPureTermApplication/start-application', request);
126
+ }
35
127
  }
36
128
  exports.PureTermService = PureTermService;
@@ -15,9 +15,25 @@ import { ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, T
15
15
  export declare class SecureSignService extends BaseService {
16
16
  constructor(httpClient: HttpClient);
17
17
  /**
18
- * Prepare the signing package and check available delivery channels
19
- * Always call this first — it prepares the signing package.
20
- * If isSignCompleted is true, skip the PIN flow and proceed to Final Submit.
18
+ * Prepare the signing package and check available delivery channels.
19
+ *
20
+ * Applies to **ADB, GIGDB, and Final Expense**. Always call this first — it
21
+ * prepares the documents server-side. If `isSignCompleted` is `true`, the
22
+ * documents are already signed: skip the PIN flow entirely and go straight to
23
+ * `finalSubmit()`.
24
+ *
25
+ * `isSmsAvailable` / `isEmailAvailable` determine which channels may be
26
+ * selected in `sendPinAndGetDocumentsLink()` — only an available channel is
27
+ * accepted.
28
+ *
29
+ * Errors:
30
+ * - `ApplicationNotReady` — Start Application has not completed
31
+ * successfully, or payment/signing was called too early. This is the same
32
+ * lifecycle gate `getCcPaymentIframeUrl()` applies. Complete Start
33
+ * Application, then retry.
34
+ * - `InvalidRequestFormat` — `opportunityId` missing, non-existent, or the
35
+ * documents are already signed (`Documents are already signed.`).
36
+ *
21
37
  * @param opportunityId - The OpportunityId from the Start Application response
22
38
  * @returns Promise with delivery channels and sign completion status
23
39
  */
@@ -18,9 +18,25 @@ class SecureSignService extends base_service_1.BaseService {
18
18
  super(httpClient);
19
19
  }
20
20
  /**
21
- * Prepare the signing package and check available delivery channels
22
- * Always call this first — it prepares the signing package.
23
- * If isSignCompleted is true, skip the PIN flow and proceed to Final Submit.
21
+ * Prepare the signing package and check available delivery channels.
22
+ *
23
+ * Applies to **ADB, GIGDB, and Final Expense**. Always call this first — it
24
+ * prepares the documents server-side. If `isSignCompleted` is `true`, the
25
+ * documents are already signed: skip the PIN flow entirely and go straight to
26
+ * `finalSubmit()`.
27
+ *
28
+ * `isSmsAvailable` / `isEmailAvailable` determine which channels may be
29
+ * selected in `sendPinAndGetDocumentsLink()` — only an available channel is
30
+ * accepted.
31
+ *
32
+ * Errors:
33
+ * - `ApplicationNotReady` — Start Application has not completed
34
+ * successfully, or payment/signing was called too early. This is the same
35
+ * lifecycle gate `getCcPaymentIframeUrl()` applies. Complete Start
36
+ * Application, then retry.
37
+ * - `InvalidRequestFormat` — `opportunityId` missing, non-existent, or the
38
+ * documents are already signed (`Documents are already signed.`).
39
+ *
24
40
  * @param opportunityId - The OpportunityId from the Start Application response
25
41
  * @returns Promise with delivery channels and sign completion status
26
42
  */
@@ -472,7 +472,7 @@ export declare enum APIErrorCode {
472
472
  BenefitPeriodNotAvailable = "BenefitPeriodNotAvailable",
473
473
  /** IB Term Quote only — height + weight fall outside the carrier's acceptable build chart. */
474
474
  OutsideBuildChart = "outsideBuildChart",
475
- /** ADB / GIGDB Start Application only — same SSN, email, or phone already has a policy generated within the last 30 days. IB Term does NOT use this code. */
475
+ /** ADB / GIGDB / Final Expense Start Application only — same SSN, email, or phone already has a policy generated within the last 30 days. IB Term does NOT use this code. */
476
476
  ApplicationLimitReached = "ApplicationLimitReached",
477
477
  /** Quote state and `Address.State` on Start Application refer to different US states (case-insensitive compare). Returned only after request validation passes. */
478
478
  StateMismatchIdentified = "StateMismatchIdentified",
@@ -480,8 +480,60 @@ export declare enum APIErrorCode {
480
480
  AgentNotFound = "agentNotFound",
481
481
  /** Unexpected backend failure while processing a Start Application request. */
482
482
  InternalServerError = "internalServerError",
483
- /** Update quote or save EFT when payment is already recorded for the opportunity. */
483
+ /**
484
+ * IB Term / Pure Term Start Application — the quote response referenced by
485
+ * `quoteResponseId` could not be found. HTTP 400 with `value: null`.
486
+ *
487
+ * Note: this code was removed in the 2.3.0 cleanup as "not returned by the
488
+ * API". That was true for the products checked at the time; it **is** returned
489
+ * by the IB Term and Pure Term start-application endpoints, so it is back and
490
+ * scoped. Do not delete it again without checking those two products.
491
+ */
492
+ DataNotFound = "dataNotFound",
493
+ /**
494
+ * Update quote or `saveEftPayment()` when a **successful** payment already
495
+ * exists for the opportunity — a prior EFT save, or a credit card that has
496
+ * already been charged.
497
+ *
498
+ * A credit card that was only captured and not yet charged does not trigger
499
+ * this on request validation. Do not rely on that edge case: treat EFT and
500
+ * credit card as mutually exclusive per `opportunityId`.
501
+ */
484
502
  PaymentAlreadyMade = "PaymentAlreadyMade",
503
+ /** `getCcPaymentIframeUrl()` — a link already exists and the latest attempt has not failed (capture is `pending` or already `approved`). Reuse the URL you already have; a new one is only issued after a `failed` attempt. */
504
+ TcIframeLinkAlreadyGenerated = "TcIframeLinkAlreadyGenerated",
505
+ /** `getCcPaymentIframeUrl()` — the product does not support the credit card iframe. Returned for IB Term / Pure Term, which use shared EFT or their hand-off links instead. */
506
+ CcPaymentIframeNotSupportedForProduct = "CcPaymentIframeNotSupportedForProduct",
507
+ /** `getCcPaymentIframeUrl()` / `prepareDocsAndGetDeliveryChannels()` — Start Application has not completed successfully yet. */
508
+ ApplicationNotReady = "ApplicationNotReady",
509
+ /** `getCcPaymentIframeUrl()` — a successful EFT payment already exists. EFT and credit card are mutually exclusive per opportunity. */
510
+ EftPaymentAlreadyCompleted = "EftPaymentAlreadyCompleted",
511
+ /** Card CVV was rejected. */
512
+ PaymentCvvInvalid = "PaymentCvvInvalid",
513
+ /** Declined — the applicant must contact their bank. */
514
+ PaymentDeclinedContactBank = "PaymentDeclinedContactBank",
515
+ /** Card declined. */
516
+ PaymentDeclined = "PaymentDeclined",
517
+ /** Card declined permanently — do not retry the same card. */
518
+ PaymentDeclinedPermanent = "PaymentDeclinedPermanent",
519
+ /** Card PIN is locked. */
520
+ PaymentPinLocked = "PaymentPinLocked",
521
+ /** Insufficient funds on the card. */
522
+ PaymentInsufficientFunds = "PaymentInsufficientFunds",
523
+ /** Processor-side error while charging the card. */
524
+ PaymentProcessingError = "PaymentProcessingError",
525
+ /** Charge blocked as suspected fraud. */
526
+ PaymentSuspectedFraud = "PaymentSuspectedFraud",
527
+ /** Card is expired. */
528
+ PaymentCardExpired = "PaymentCardExpired",
529
+ /** Card data supplied in the iframe was invalid. */
530
+ PaymentInvalidCardData = "PaymentInvalidCardData",
531
+ /** Generic card error. */
532
+ PaymentCardError = "PaymentCardError",
533
+ /** Issuer requires the applicant to contact their bank. */
534
+ PaymentContactBank = "PaymentContactBank",
535
+ /** Generic payment-related failure at final submit. */
536
+ PaymentRelatedError = "PaymentRelatedError",
485
537
  /** Generic Secure Sign failure. */
486
538
  SecureSignRelatedError = "SecureSignRelatedError",
487
539
  /** Signing package missing — call `prepareDocsAndGetDeliveryChannels()` first. */
@@ -498,10 +550,32 @@ export declare enum APIErrorCode {
498
550
  EmailDeliveryFailed = "EmailDeliveryFailed",
499
551
  /** SMS delivery failed on Send PIN / Resend PIN. */
500
552
  MessageNotDelivered = "MessageNotDelivered",
501
- /** EFT payment not saved — call `saveEftPayment()` before `finalSubmit()`. */
553
+ /** Secure signing has not been completed for the opportunity — finish the PIN flow (or confirm `isSignCompleted`) before `finalSubmit()`. */
554
+ SecureSignNotCompleted = "SecureSignNotCompleted",
555
+ /**
556
+ * No payment has been completed for the opportunity. Covers **two** cases:
557
+ * no payment was ever started (neither `saveEftPayment()` nor
558
+ * `getCcPaymentIframeUrl()`), **or** a credit card capture is still pending
559
+ * (iframe issued, `cc-payment-status` is `'pending'`).
560
+ *
561
+ * Recovery: complete the payment — finish the iframe and poll to `'approved'`,
562
+ * or save EFT — then retry. While capture is pending, reuse the stored iframe
563
+ * URL; do not request a new one.
564
+ */
502
565
  PaymentNotMade = "paymentNotMade",
566
+ /**
567
+ * A payment was attempted and the most recent attempt finished unsuccessfully
568
+ * (`cc-payment-status` is `'failed'` after a capture or charge decline).
569
+ *
570
+ * Recovery: call `getCcPaymentIframeUrl()` for a new capture, poll to
571
+ * `'approved'`, then retry `finalSubmit()`. Retrying `finalSubmit()` without a
572
+ * new successful capture returns this code again, not a fresh decline code.
573
+ */
574
+ LatestPaymentNotSuccessful = "LatestPaymentNotSuccessful",
503
575
  /** Fidelity carrier rejected or failed to process final submit. */
504
576
  FidelityFinalSubmitError = "FidelityFinalSubmitError",
577
+ /** Underwriting status polling is not supported for the product (ADB/GIGDB) — Final Expense only. Returned by `pingFinalExpenseUnderwritingStatus()` / `pollFinalExpenseUnderwritingStatus()` for a non-Final-Expense opportunity. */
578
+ FinalSubmitStatusNotSupported = "FinalSubmitStatusNotSupported",
505
579
  AgentLogout = "AgentLogout",
506
580
  /** Top-level code returned by `getExistingIBTermQuote()` / `getExistingGigdbQuote()` / `getExistingAdbQuote()` when no quote is on file for the opportunityId. HTTP 400, `value: null`. */
507
581
  QuoteNotFound = "QuoteNotFound",
@@ -508,7 +508,7 @@ var APIErrorCode;
508
508
  /** IB Term Quote only — height + weight fall outside the carrier's acceptable build chart. */
509
509
  APIErrorCode["OutsideBuildChart"] = "outsideBuildChart";
510
510
  // ─── Start Application — duplicate-detection limit ───────────────────────
511
- /** ADB / GIGDB Start Application only — same SSN, email, or phone already has a policy generated within the last 30 days. IB Term does NOT use this code. */
511
+ /** ADB / GIGDB / Final Expense Start Application only — same SSN, email, or phone already has a policy generated within the last 30 days. IB Term does NOT use this code. */
512
512
  APIErrorCode["ApplicationLimitReached"] = "ApplicationLimitReached";
513
513
  // ─── Start Application — business top-level errors (ADB / GIGDB / IB Term) ─
514
514
  /** Quote state and `Address.State` on Start Application refer to different US states (case-insensitive compare). Returned only after request validation passes. */
@@ -517,9 +517,67 @@ var APIErrorCode;
517
517
  APIErrorCode["AgentNotFound"] = "agentNotFound";
518
518
  /** Unexpected backend failure while processing a Start Application request. */
519
519
  APIErrorCode["InternalServerError"] = "internalServerError";
520
+ /**
521
+ * IB Term / Pure Term Start Application — the quote response referenced by
522
+ * `quoteResponseId` could not be found. HTTP 400 with `value: null`.
523
+ *
524
+ * Note: this code was removed in the 2.3.0 cleanup as "not returned by the
525
+ * API". That was true for the products checked at the time; it **is** returned
526
+ * by the IB Term and Pure Term start-application endpoints, so it is back and
527
+ * scoped. Do not delete it again without checking those two products.
528
+ */
529
+ APIErrorCode["DataNotFound"] = "dataNotFound";
520
530
  // ─── Payment & quote update (after Start Application) ─────────────────────
521
- /** Update quote or save EFT when payment is already recorded for the opportunity. */
531
+ /**
532
+ * Update quote or `saveEftPayment()` when a **successful** payment already
533
+ * exists for the opportunity — a prior EFT save, or a credit card that has
534
+ * already been charged.
535
+ *
536
+ * A credit card that was only captured and not yet charged does not trigger
537
+ * this on request validation. Do not rely on that edge case: treat EFT and
538
+ * credit card as mutually exclusive per `opportunityId`.
539
+ */
522
540
  APIErrorCode["PaymentAlreadyMade"] = "PaymentAlreadyMade";
541
+ // ─── Credit card payment — iframe gates (ADB / GIGDB / Final Expense) ─────
542
+ /** `getCcPaymentIframeUrl()` — a link already exists and the latest attempt has not failed (capture is `pending` or already `approved`). Reuse the URL you already have; a new one is only issued after a `failed` attempt. */
543
+ APIErrorCode["TcIframeLinkAlreadyGenerated"] = "TcIframeLinkAlreadyGenerated";
544
+ /** `getCcPaymentIframeUrl()` — the product does not support the credit card iframe. Returned for IB Term / Pure Term, which use shared EFT or their hand-off links instead. */
545
+ APIErrorCode["CcPaymentIframeNotSupportedForProduct"] = "CcPaymentIframeNotSupportedForProduct";
546
+ /** `getCcPaymentIframeUrl()` / `prepareDocsAndGetDeliveryChannels()` — Start Application has not completed successfully yet. */
547
+ APIErrorCode["ApplicationNotReady"] = "ApplicationNotReady";
548
+ /** `getCcPaymentIframeUrl()` — a successful EFT payment already exists. EFT and credit card are mutually exclusive per opportunity. */
549
+ APIErrorCode["EftPaymentAlreadyCompleted"] = "EftPaymentAlreadyCompleted";
550
+ // ─── Credit card decline codes — `finalSubmit()`, ADB / GIGDB only ────────
551
+ // Returned when the stored card is charged at final submit and the charge is
552
+ // declined. The application is NOT submitted. Recovery is always: request a
553
+ // new iframe URL → poll to `approved` → retry `finalSubmit()`.
554
+ // Final Expense never produces these — the carrier charges after underwriting.
555
+ /** Card CVV was rejected. */
556
+ APIErrorCode["PaymentCvvInvalid"] = "PaymentCvvInvalid";
557
+ /** Declined — the applicant must contact their bank. */
558
+ APIErrorCode["PaymentDeclinedContactBank"] = "PaymentDeclinedContactBank";
559
+ /** Card declined. */
560
+ APIErrorCode["PaymentDeclined"] = "PaymentDeclined";
561
+ /** Card declined permanently — do not retry the same card. */
562
+ APIErrorCode["PaymentDeclinedPermanent"] = "PaymentDeclinedPermanent";
563
+ /** Card PIN is locked. */
564
+ APIErrorCode["PaymentPinLocked"] = "PaymentPinLocked";
565
+ /** Insufficient funds on the card. */
566
+ APIErrorCode["PaymentInsufficientFunds"] = "PaymentInsufficientFunds";
567
+ /** Processor-side error while charging the card. */
568
+ APIErrorCode["PaymentProcessingError"] = "PaymentProcessingError";
569
+ /** Charge blocked as suspected fraud. */
570
+ APIErrorCode["PaymentSuspectedFraud"] = "PaymentSuspectedFraud";
571
+ /** Card is expired. */
572
+ APIErrorCode["PaymentCardExpired"] = "PaymentCardExpired";
573
+ /** Card data supplied in the iframe was invalid. */
574
+ APIErrorCode["PaymentInvalidCardData"] = "PaymentInvalidCardData";
575
+ /** Generic card error. */
576
+ APIErrorCode["PaymentCardError"] = "PaymentCardError";
577
+ /** Issuer requires the applicant to contact their bank. */
578
+ APIErrorCode["PaymentContactBank"] = "PaymentContactBank";
579
+ /** Generic payment-related failure at final submit. */
580
+ APIErrorCode["PaymentRelatedError"] = "PaymentRelatedError";
523
581
  // ─── Secure Sign ───────────────────────────────────────────────────────────
524
582
  /** Generic Secure Sign failure. */
525
583
  APIErrorCode["SecureSignRelatedError"] = "SecureSignRelatedError";
@@ -537,11 +595,38 @@ var APIErrorCode;
537
595
  APIErrorCode["EmailDeliveryFailed"] = "EmailDeliveryFailed";
538
596
  /** SMS delivery failed on Send PIN / Resend PIN. */
539
597
  APIErrorCode["MessageNotDelivered"] = "MessageNotDelivered";
540
- // ─── Final Submit ──────────────────────────────────────────────────────────
541
- /** EFT payment not saved — call `saveEftPayment()` before `finalSubmit()`. */
598
+ // ─── Final Submit — pre-submit gates, checked in this order ────────────────
599
+ // 1. SecureSignNotCompleted → 2. PaymentNotMade → 3. LatestPaymentNotSuccessful
600
+ // These are three distinct, separately actionable states. Do NOT collapse
601
+ // PaymentNotMade and LatestPaymentNotSuccessful into one client-side case:
602
+ // the first means "nothing to submit yet", the second means "a payment was
603
+ // tried and failed, start a new capture".
604
+ /** Secure signing has not been completed for the opportunity — finish the PIN flow (or confirm `isSignCompleted`) before `finalSubmit()`. */
605
+ APIErrorCode["SecureSignNotCompleted"] = "SecureSignNotCompleted";
606
+ /**
607
+ * No payment has been completed for the opportunity. Covers **two** cases:
608
+ * no payment was ever started (neither `saveEftPayment()` nor
609
+ * `getCcPaymentIframeUrl()`), **or** a credit card capture is still pending
610
+ * (iframe issued, `cc-payment-status` is `'pending'`).
611
+ *
612
+ * Recovery: complete the payment — finish the iframe and poll to `'approved'`,
613
+ * or save EFT — then retry. While capture is pending, reuse the stored iframe
614
+ * URL; do not request a new one.
615
+ */
542
616
  APIErrorCode["PaymentNotMade"] = "paymentNotMade";
617
+ /**
618
+ * A payment was attempted and the most recent attempt finished unsuccessfully
619
+ * (`cc-payment-status` is `'failed'` after a capture or charge decline).
620
+ *
621
+ * Recovery: call `getCcPaymentIframeUrl()` for a new capture, poll to
622
+ * `'approved'`, then retry `finalSubmit()`. Retrying `finalSubmit()` without a
623
+ * new successful capture returns this code again, not a fresh decline code.
624
+ */
625
+ APIErrorCode["LatestPaymentNotSuccessful"] = "LatestPaymentNotSuccessful";
543
626
  /** Fidelity carrier rejected or failed to process final submit. */
544
627
  APIErrorCode["FidelityFinalSubmitError"] = "FidelityFinalSubmitError";
628
+ /** Underwriting status polling is not supported for the product (ADB/GIGDB) — Final Expense only. Returned by `pingFinalExpenseUnderwritingStatus()` / `pollFinalExpenseUnderwritingStatus()` for a non-Final-Expense opportunity. */
629
+ APIErrorCode["FinalSubmitStatusNotSupported"] = "FinalSubmitStatusNotSupported";
545
630
  // ─── Session ─────────────────────────────────────────────────────────────
546
631
  APIErrorCode["AgentLogout"] = "AgentLogout";
547
632
  // ─── Get Existing Quote ──────────────────────────────────────────────────
@@ -80,19 +80,44 @@ class APIValidationError extends InstaBrainError {
80
80
  'EmailDeliveryFailed': 'Email delivery failed. Retry or switch to SMS.',
81
81
  'MessageNotDelivered': 'SMS delivery failed. Retry or switch to email.',
82
82
  'FidelityFinalSubmitError': 'Fidelity carrier rejected or failed to process the submission. Contact support with the opportunityId.',
83
+ 'FinalSubmitStatusNotSupported': 'Underwriting status polling is not supported for this product — Final Expense only.',
84
+ // Credit card payment — iframe gates
85
+ 'TcIframeLinkAlreadyGenerated': 'A payment link was already generated for this application. Reuse the existing link; a new one can only be issued after the current card attempt fails.',
86
+ 'CcPaymentIframeNotSupportedForProduct': 'Credit card payment is not available for this product. Use EFT payment instead.',
87
+ 'ApplicationNotReady': 'The application is not ready for this step. Complete the start-application step successfully, then retry.',
88
+ 'EftPaymentAlreadyCompleted': 'An EFT payment has already been completed for this application. EFT and credit card cannot both be used.',
89
+ // Credit card decline codes (ADB / GIGDB charge at final submit)
90
+ 'PaymentCvvInvalid': 'The card security code (CVV) was rejected. Please re-enter the card details.',
91
+ 'PaymentDeclinedContactBank': 'The card was declined. The cardholder should contact their bank, then try a different card.',
92
+ 'PaymentDeclined': 'The card was declined. Please try a different card.',
93
+ 'PaymentDeclinedPermanent': 'The card was permanently declined. Please use a different card.',
94
+ 'PaymentPinLocked': 'The card PIN is locked. Please use a different card.',
95
+ 'PaymentInsufficientFunds': 'The card has insufficient funds. Please use a different card.',
96
+ 'PaymentProcessingError': 'The payment processor could not complete the charge. Please try again or use a different card.',
97
+ 'PaymentSuspectedFraud': 'The charge was blocked as suspected fraud. Please use a different card.',
98
+ 'PaymentCardExpired': 'The card has expired. Please use a different card.',
99
+ 'PaymentInvalidCardData': 'The card details entered were invalid. Please re-enter them.',
100
+ 'PaymentCardError': 'There was a problem with the card. Please try a different card.',
101
+ 'PaymentContactBank': 'The card issuer requires the cardholder to contact their bank before this charge can proceed.',
102
+ 'PaymentRelatedError': 'The payment could not be completed. Capture a new card and retry the submission.',
103
+ // IB Term / Pure Term Start Application
104
+ 'dataNotFound': 'The quote could not be found for the supplied quoteResponseId. Create a new quote and retry.',
105
+ // Final Submit — pre-submit gates (checked in this order)
106
+ 'SecureSignNotCompleted': 'Secure signing is not complete. Finish the PIN flow before submitting.',
107
+ 'LatestPaymentNotSuccessful': 'The most recent payment attempt failed. Capture a new card and poll until approved, then retry final submit.',
83
108
  'AgentLogout': 'Agent session has expired. Please re-authenticate.',
84
109
  'InvalidBirthCountry': 'The birth country provided is not valid.',
85
110
  'InvalidBirthState': 'The birth state provided is not valid.',
86
111
  'InvalidResidenceState': 'The residence state provided is not valid.',
87
112
  'OneOfTheExistingCoveragesQuestionsNotFound': 'One or more existing coverage questions were not answered.',
88
- 'PaymentAlreadyMade': 'Payment has already been made for this application.',
113
+ 'PaymentAlreadyMade': 'A successful payment already exists for this application. EFT and credit card are mutually exclusive per opportunity.',
89
114
  'ErrorInSaveEftPaymentDetails': 'Failed to save EFT payment details. Please verify account information.',
90
115
  'InvalidPaymentScheduledDate': 'The scheduled payment date is not valid.',
91
116
  'ThirdPartyQuoteError': 'An error occurred while retrieving the quote.',
92
117
  'InvalidQuoteParameters': 'The quote parameters provided are not valid.',
93
118
  'InvalidStateCode': 'State not supported for ADB (MA, NH, AK unavailable; CA coming next release).',
94
119
  'InvalidAdbAgeRange': 'Age must be between 20 and 59 for ADB.',
95
- 'paymentNotMade': 'EFT payment must be completed before submitting the application.'
120
+ 'paymentNotMade': 'No payment has been completed — either none was started, or a credit card capture is still pending. Complete payment, then retry final submit.'
96
121
  };
97
122
  return errorMessages[this.errorCode] || this.message;
98
123
  }