@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 +568 -70
- package/dist/client/instabrain-client.d.ts +124 -9
- package/dist/client/instabrain-client.js +136 -8
- package/dist/services/application.service.d.ts +29 -2
- package/dist/services/application.service.js +29 -2
- package/dist/services/gigdb.service.d.ts +25 -3
- package/dist/services/gigdb.service.js +25 -3
- package/dist/services/payment.service.d.ts +94 -0
- package/dist/services/payment.service.js +161 -0
- package/dist/services/pureterm.service.d.ts +96 -10
- package/dist/services/pureterm.service.js +100 -8
- package/dist/services/secure-sign.service.d.ts +19 -3
- package/dist/services/secure-sign.service.js +19 -3
- package/dist/types/enums.d.ts +74 -2
- package/dist/types/enums.js +86 -3
- package/dist/types/errors.js +26 -2
- package/dist/types/gigdb.types.d.ts +32 -0
- package/dist/types/ibterm.types.d.ts +5 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/payment.types.d.ts +52 -0
- package/dist/types/payment.types.js +3 -0
- package/dist/types/pureterm.types.d.ts +186 -31
- package/dist/utils/error-utils.d.ts +9 -1
- package/dist/utils/error-utils.js +18 -3
- package/dist/utils/http-client.js +11 -2
- package/package.json +1 -1
|
@@ -7,8 +7,9 @@ import { AdbService } from '../services/adb.service';
|
|
|
7
7
|
import { IBTermService } from '../services/ibterm.service';
|
|
8
8
|
import { PureTermService } from '../services/pureterm.service';
|
|
9
9
|
import { FinalExpenseService } from '../services/finalexpense.service';
|
|
10
|
+
import { PaymentService } from '../services/payment.service';
|
|
10
11
|
import { SecureSignService } from '../services/secure-sign.service';
|
|
11
|
-
import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
|
|
12
|
+
import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
|
|
12
13
|
/**
|
|
13
14
|
* Main InstaBrain SDK client
|
|
14
15
|
*/
|
|
@@ -23,6 +24,7 @@ export declare class InstaBrainClient {
|
|
|
23
24
|
readonly ibterm: IBTermService;
|
|
24
25
|
readonly pureTerm: PureTermService;
|
|
25
26
|
readonly finalExpense: FinalExpenseService;
|
|
27
|
+
readonly payment: PaymentService;
|
|
26
28
|
readonly secureSign: SecureSignService;
|
|
27
29
|
constructor(config?: InstaBrainConfig);
|
|
28
30
|
/**
|
|
@@ -84,6 +86,16 @@ export declare class InstaBrainClient {
|
|
|
84
86
|
* Save EFT payment details for a GIGDB, ADB, or Final Expense application.
|
|
85
87
|
* Must be called after startGigdbApplication / startAdbApplication /
|
|
86
88
|
* startFinalExpenseApplication and before the SecureSign flow.
|
|
89
|
+
*
|
|
90
|
+
* `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
|
|
91
|
+
* apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
|
|
92
|
+
*
|
|
93
|
+
* EFT and credit card are mutually exclusive per opportunity — a successful
|
|
94
|
+
* payment that already exists returns `PaymentAlreadyMade`, and after a
|
|
95
|
+
* successful EFT save `getCcPaymentIframeUrl()` returns
|
|
96
|
+
* `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
|
|
97
|
+
* prerequisite for `finalSubmit()`; no charge runs again at final submit.
|
|
98
|
+
*
|
|
87
99
|
* @param request - The EFT payment request with opportunityId and bank account details
|
|
88
100
|
* @returns Promise resolving to true on success
|
|
89
101
|
*/
|
|
@@ -185,21 +197,73 @@ export declare class InstaBrainClient {
|
|
|
185
197
|
* @returns Promise with the current quote response
|
|
186
198
|
*/
|
|
187
199
|
getExistingIBTermQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
|
|
200
|
+
/**
|
|
201
|
+
* Get available riders for Pure Term in a given state, filtered by the
|
|
202
|
+
* applicant's age and nicotine-use status.
|
|
203
|
+
*
|
|
204
|
+
* Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
|
|
205
|
+
* in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
|
|
206
|
+
* do not proceed to the Quote API. The empty `riders` array is a valid business
|
|
207
|
+
* state, not an error.
|
|
208
|
+
*
|
|
209
|
+
* @param stateCode - Two-letter US state code (e.g. "TX")
|
|
210
|
+
* @param age - Applicant's age, integer, 18–60 inclusive
|
|
211
|
+
* @param flagNicotineUse - Whether the applicant uses nicotine
|
|
212
|
+
* @returns Promise with riders list and product availability flag
|
|
213
|
+
*/
|
|
214
|
+
getPureTermRiderDetails(stateCode: string, age: number, flagNicotineUse: boolean): Promise<PureTermRiderDetailsResp>;
|
|
188
215
|
/**
|
|
189
216
|
* Get a Pure Term insurance quote.
|
|
190
217
|
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
218
|
+
* `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
|
|
219
|
+
* required. Supply at least one rating group — `rateClass`, `healthClass`, or
|
|
220
|
+
* both `height` and `weightInLbs`; passing more than one is allowed. Supply
|
|
221
|
+
* `age` OR `dateOfBirth` (18–60). `flagTobaccoUse` defaults to `false` when
|
|
222
|
+
* omitted.
|
|
223
|
+
*
|
|
224
|
+
* Pure Term uses the same quote request shape as IB Term but different product
|
|
225
|
+
* rules (rate classes including Rated C/D, term lengths including 15,
|
|
226
|
+
* coverage/benefit tables). FluentValidation uses dedicated top-level codes
|
|
227
|
+
* only for `BenefitPeriodNotAvailable` and `CoverageNotAvailable`; other field
|
|
228
|
+
* failures use `InvalidRequestFormat`. Post-validation eligibility can still
|
|
229
|
+
* return codes such as `NotAvailableForState`, `RiderNotAvailable`, and
|
|
230
|
+
* `outsideBuildChart`.
|
|
194
231
|
*
|
|
195
|
-
* After the quote, call `
|
|
196
|
-
* `quoteResponseId
|
|
197
|
-
* frontend.
|
|
232
|
+
* After the quote, call `startPureTermApplication()` with the returned
|
|
233
|
+
* `quoteResponseId`.
|
|
198
234
|
*
|
|
199
235
|
* @param request - The Pure Term quote request parameters
|
|
200
236
|
* @returns Promise with the quote response containing quoteResponseId
|
|
201
237
|
*/
|
|
202
238
|
getPureTermQuote(request: ThirdPartyPureTermQuoteReq): Promise<ThirdPartyQuoteResp>;
|
|
239
|
+
/**
|
|
240
|
+
* Get the existing quote for an in-flight Pure Term opportunity.
|
|
241
|
+
*
|
|
242
|
+
* Use to resume or review a previously generated Pure Term quote by its
|
|
243
|
+
* opportunity ID without re-quoting. A not-found result is an error (surfaced
|
|
244
|
+
* via the SDK error model), not a valid business state.
|
|
245
|
+
*
|
|
246
|
+
* @param opportunityId - UUID from a prior Pure Term application/quote flow
|
|
247
|
+
* @returns Promise with the current quote response
|
|
248
|
+
*/
|
|
249
|
+
getPureTermExistingQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
|
|
250
|
+
/**
|
|
251
|
+
* Start a Pure Term application from a prior Pure Term quote.
|
|
252
|
+
*
|
|
253
|
+
* Dedicated endpoint — separate from the generic `startApplication()`, which is
|
|
254
|
+
* unchanged and still serves other products.
|
|
255
|
+
*
|
|
256
|
+
* `isDeclined: true` is a valid success response (knockout), not an error.
|
|
257
|
+
* Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
|
|
258
|
+
* only). `childRiderInfo` must be sent only when the Dependent Child Rider was
|
|
259
|
+
* on the quote. After a non-declined start, hand off via the returned links —
|
|
260
|
+
* do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
|
|
261
|
+
* credit-card iframe.
|
|
262
|
+
*
|
|
263
|
+
* @param request - The Pure Term application request payload
|
|
264
|
+
* @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
|
|
265
|
+
*/
|
|
266
|
+
startPureTermApplication(request: PureTermStartApplicationReq): Promise<ThirdPartyStartAppResp>;
|
|
203
267
|
/**
|
|
204
268
|
* Get a Final Expense insurance quote (simplified-issue whole life, ages 50–85).
|
|
205
269
|
*
|
|
@@ -258,6 +322,44 @@ export declare class InstaBrainClient {
|
|
|
258
322
|
* @returns Promise with the final ping response (terminal status, or last `'InProgress'` on timeout)
|
|
259
323
|
*/
|
|
260
324
|
pollFinalExpenseUnderwritingStatus(opportunityId: string, options?: PollUnderwritingStatusOptions): Promise<ThirdPartyFinalExpensePingRes>;
|
|
325
|
+
/**
|
|
326
|
+
* Get the TrustCommerce hosted iframe URL for credit card capture.
|
|
327
|
+
*
|
|
328
|
+
* Call after Start Application and before the Secure Sign flow. **Persist the
|
|
329
|
+
* returned URL keyed by `opportunityId`** and reuse it while
|
|
330
|
+
* `pollCcPaymentStatus()` reports `'pending'` — requesting a second link
|
|
331
|
+
* before the current attempt fails returns `TcIframeLinkAlreadyGenerated`.
|
|
332
|
+
*
|
|
333
|
+
* Supported for ADB, GIGDB, and Final Expense only. IB Term / Pure Term
|
|
334
|
+
* return `CcPaymentIframeNotSupportedForProduct`.
|
|
335
|
+
*
|
|
336
|
+
* @param opportunityId - The OpportunityId from the Start Application response
|
|
337
|
+
* @returns Promise resolving to the fully-qualified iframe URL
|
|
338
|
+
*/
|
|
339
|
+
getCcPaymentIframeUrl(opportunityId: string): Promise<string>;
|
|
340
|
+
/**
|
|
341
|
+
* Check credit card capture status once.
|
|
342
|
+
*
|
|
343
|
+
* Rate-limited to 1 request per 10 seconds per `opportunityId`. Prefer
|
|
344
|
+
* `pollCcPaymentStatus()` for a managed loop that handles the rate limit.
|
|
345
|
+
*
|
|
346
|
+
* @param opportunityId - The OpportunityId from the Start Application response
|
|
347
|
+
* @returns Promise with the current `status` and `shouldContinuePolling`
|
|
348
|
+
*/
|
|
349
|
+
getCcPaymentStatus(opportunityId: string): Promise<ThirdPartyCcPaymentStatusRes>;
|
|
350
|
+
/**
|
|
351
|
+
* Poll credit card capture status until it resolves (`'approved'` or
|
|
352
|
+
* `'failed'`) or the time budget expires.
|
|
353
|
+
*
|
|
354
|
+
* Polls every 10s by default and transparently retries HTTP 429. Never
|
|
355
|
+
* requests a new iframe URL — on `'failed'`, call `getCcPaymentIframeUrl()`
|
|
356
|
+
* again for a fresh capture, then poll again.
|
|
357
|
+
*
|
|
358
|
+
* @param opportunityId - The OpportunityId from the Start Application response
|
|
359
|
+
* @param options - Optional polling cadence overrides
|
|
360
|
+
* @returns Promise with the terminal response, or the last `'pending'` one on timeout
|
|
361
|
+
*/
|
|
362
|
+
pollCcPaymentStatus(opportunityId: string, options?: PollCcPaymentStatusOptions): Promise<ThirdPartyCcPaymentStatusRes>;
|
|
261
363
|
/**
|
|
262
364
|
* Prepare the signing package and check available delivery channels
|
|
263
365
|
* Always call this first in the signing flow. If isSignCompleted is true, skip to finalSubmit().
|
|
@@ -286,9 +388,22 @@ export declare class InstaBrainClient {
|
|
|
286
388
|
*/
|
|
287
389
|
verifyPin(request: ThirdPartyVerifyPinReq): Promise<ThirdPartyVerifyPinResp>;
|
|
288
390
|
/**
|
|
289
|
-
* Submit the application to the carrier for a final underwriting decision
|
|
391
|
+
* Submit the application to the carrier for a final underwriting decision.
|
|
290
392
|
* Call after the signing flow is complete or when isSignCompleted is true.
|
|
291
|
-
*
|
|
393
|
+
*
|
|
394
|
+
* Note: A null policyNumber means the carrier has not yet issued a number
|
|
395
|
+
* (pending decision) — not an error.
|
|
396
|
+
*
|
|
397
|
+
* Calling this again after a successful submit is **idempotent** — it does not
|
|
398
|
+
* re-submit or re-charge, and returns the existing result including the same
|
|
399
|
+
* `policyNumber`. No client-side guard is needed.
|
|
400
|
+
*
|
|
401
|
+
* Three distinct pre-submit gates, in order: `SecureSignNotCompleted` →
|
|
402
|
+
* `paymentNotMade` (no payment started, or card capture still pending) →
|
|
403
|
+
* `LatestPaymentNotSuccessful` (payment attempted and failed). Handle the last
|
|
404
|
+
* two separately: the first means "keep waiting or start a payment", the
|
|
405
|
+
* second means "start a new capture".
|
|
406
|
+
*
|
|
292
407
|
* @param opportunityId - The OpportunityId from the Start Application response
|
|
293
408
|
* @returns Promise with the final submit response containing policyNumber
|
|
294
409
|
*/
|
|
@@ -11,6 +11,7 @@ const adb_service_1 = require("../services/adb.service");
|
|
|
11
11
|
const ibterm_service_1 = require("../services/ibterm.service");
|
|
12
12
|
const pureterm_service_1 = require("../services/pureterm.service");
|
|
13
13
|
const finalexpense_service_1 = require("../services/finalexpense.service");
|
|
14
|
+
const payment_service_1 = require("../services/payment.service");
|
|
14
15
|
const secure_sign_service_1 = require("../services/secure-sign.service");
|
|
15
16
|
/**
|
|
16
17
|
* Main InstaBrain SDK client
|
|
@@ -27,6 +28,7 @@ class InstaBrainClient {
|
|
|
27
28
|
this.ibterm = new ibterm_service_1.IBTermService(this.httpClient);
|
|
28
29
|
this.pureTerm = new pureterm_service_1.PureTermService(this.httpClient);
|
|
29
30
|
this.finalExpense = new finalexpense_service_1.FinalExpenseService(this.httpClient);
|
|
31
|
+
this.payment = new payment_service_1.PaymentService(this.httpClient);
|
|
30
32
|
this.secureSign = new secure_sign_service_1.SecureSignService(this.httpClient);
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
@@ -111,6 +113,16 @@ class InstaBrainClient {
|
|
|
111
113
|
* Save EFT payment details for a GIGDB, ADB, or Final Expense application.
|
|
112
114
|
* Must be called after startGigdbApplication / startAdbApplication /
|
|
113
115
|
* startFinalExpenseApplication and before the SecureSign flow.
|
|
116
|
+
*
|
|
117
|
+
* `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
|
|
118
|
+
* apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
|
|
119
|
+
*
|
|
120
|
+
* EFT and credit card are mutually exclusive per opportunity — a successful
|
|
121
|
+
* payment that already exists returns `PaymentAlreadyMade`, and after a
|
|
122
|
+
* successful EFT save `getCcPaymentIframeUrl()` returns
|
|
123
|
+
* `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
|
|
124
|
+
* prerequisite for `finalSubmit()`; no charge runs again at final submit.
|
|
125
|
+
*
|
|
114
126
|
* @param request - The EFT payment request with opportunityId and bank account details
|
|
115
127
|
* @returns Promise resolving to true on success
|
|
116
128
|
*/
|
|
@@ -239,16 +251,42 @@ class InstaBrainClient {
|
|
|
239
251
|
return this.ibterm.getExistingQuote(opportunityId);
|
|
240
252
|
}
|
|
241
253
|
// ── Pure Term Methods ──────────────────────────────────────────────
|
|
254
|
+
/**
|
|
255
|
+
* Get available riders for Pure Term in a given state, filtered by the
|
|
256
|
+
* applicant's age and nicotine-use status.
|
|
257
|
+
*
|
|
258
|
+
* Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
|
|
259
|
+
* in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
|
|
260
|
+
* do not proceed to the Quote API. The empty `riders` array is a valid business
|
|
261
|
+
* state, not an error.
|
|
262
|
+
*
|
|
263
|
+
* @param stateCode - Two-letter US state code (e.g. "TX")
|
|
264
|
+
* @param age - Applicant's age, integer, 18–60 inclusive
|
|
265
|
+
* @param flagNicotineUse - Whether the applicant uses nicotine
|
|
266
|
+
* @returns Promise with riders list and product availability flag
|
|
267
|
+
*/
|
|
268
|
+
async getPureTermRiderDetails(stateCode, age, flagNicotineUse) {
|
|
269
|
+
return this.pureTerm.getRiderDetails(stateCode, age, flagNicotineUse);
|
|
270
|
+
}
|
|
242
271
|
/**
|
|
243
272
|
* Get a Pure Term insurance quote.
|
|
244
273
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
274
|
+
* `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
|
|
275
|
+
* required. Supply at least one rating group — `rateClass`, `healthClass`, or
|
|
276
|
+
* both `height` and `weightInLbs`; passing more than one is allowed. Supply
|
|
277
|
+
* `age` OR `dateOfBirth` (18–60). `flagTobaccoUse` defaults to `false` when
|
|
278
|
+
* omitted.
|
|
279
|
+
*
|
|
280
|
+
* Pure Term uses the same quote request shape as IB Term but different product
|
|
281
|
+
* rules (rate classes including Rated C/D, term lengths including 15,
|
|
282
|
+
* coverage/benefit tables). FluentValidation uses dedicated top-level codes
|
|
283
|
+
* only for `BenefitPeriodNotAvailable` and `CoverageNotAvailable`; other field
|
|
284
|
+
* failures use `InvalidRequestFormat`. Post-validation eligibility can still
|
|
285
|
+
* return codes such as `NotAvailableForState`, `RiderNotAvailable`, and
|
|
286
|
+
* `outsideBuildChart`.
|
|
248
287
|
*
|
|
249
|
-
* After the quote, call `
|
|
250
|
-
* `quoteResponseId
|
|
251
|
-
* frontend.
|
|
288
|
+
* After the quote, call `startPureTermApplication()` with the returned
|
|
289
|
+
* `quoteResponseId`.
|
|
252
290
|
*
|
|
253
291
|
* @param request - The Pure Term quote request parameters
|
|
254
292
|
* @returns Promise with the quote response containing quoteResponseId
|
|
@@ -256,6 +294,38 @@ class InstaBrainClient {
|
|
|
256
294
|
async getPureTermQuote(request) {
|
|
257
295
|
return this.pureTerm.getQuote(request);
|
|
258
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Get the existing quote for an in-flight Pure Term opportunity.
|
|
299
|
+
*
|
|
300
|
+
* Use to resume or review a previously generated Pure Term quote by its
|
|
301
|
+
* opportunity ID without re-quoting. A not-found result is an error (surfaced
|
|
302
|
+
* via the SDK error model), not a valid business state.
|
|
303
|
+
*
|
|
304
|
+
* @param opportunityId - UUID from a prior Pure Term application/quote flow
|
|
305
|
+
* @returns Promise with the current quote response
|
|
306
|
+
*/
|
|
307
|
+
async getPureTermExistingQuote(opportunityId) {
|
|
308
|
+
return this.pureTerm.getExistingQuote(opportunityId);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Start a Pure Term application from a prior Pure Term quote.
|
|
312
|
+
*
|
|
313
|
+
* Dedicated endpoint — separate from the generic `startApplication()`, which is
|
|
314
|
+
* unchanged and still serves other products.
|
|
315
|
+
*
|
|
316
|
+
* `isDeclined: true` is a valid success response (knockout), not an error.
|
|
317
|
+
* Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
|
|
318
|
+
* only). `childRiderInfo` must be sent only when the Dependent Child Rider was
|
|
319
|
+
* on the quote. After a non-declined start, hand off via the returned links —
|
|
320
|
+
* do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
|
|
321
|
+
* credit-card iframe.
|
|
322
|
+
*
|
|
323
|
+
* @param request - The Pure Term application request payload
|
|
324
|
+
* @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
|
|
325
|
+
*/
|
|
326
|
+
async startPureTermApplication(request) {
|
|
327
|
+
return this.pureTerm.startApplication(request);
|
|
328
|
+
}
|
|
259
329
|
// ── Final Expense Methods ──────────────────────────────────────────────
|
|
260
330
|
/**
|
|
261
331
|
* Get a Final Expense insurance quote (simplified-issue whole life, ages 50–85).
|
|
@@ -327,6 +397,51 @@ class InstaBrainClient {
|
|
|
327
397
|
async pollFinalExpenseUnderwritingStatus(opportunityId, options) {
|
|
328
398
|
return this.finalExpense.pollUnderwritingStatus(opportunityId, options);
|
|
329
399
|
}
|
|
400
|
+
// ── Credit Card Payment Methods (ADB / GIGDB / Final Expense) ──────────
|
|
401
|
+
/**
|
|
402
|
+
* Get the TrustCommerce hosted iframe URL for credit card capture.
|
|
403
|
+
*
|
|
404
|
+
* Call after Start Application and before the Secure Sign flow. **Persist the
|
|
405
|
+
* returned URL keyed by `opportunityId`** and reuse it while
|
|
406
|
+
* `pollCcPaymentStatus()` reports `'pending'` — requesting a second link
|
|
407
|
+
* before the current attempt fails returns `TcIframeLinkAlreadyGenerated`.
|
|
408
|
+
*
|
|
409
|
+
* Supported for ADB, GIGDB, and Final Expense only. IB Term / Pure Term
|
|
410
|
+
* return `CcPaymentIframeNotSupportedForProduct`.
|
|
411
|
+
*
|
|
412
|
+
* @param opportunityId - The OpportunityId from the Start Application response
|
|
413
|
+
* @returns Promise resolving to the fully-qualified iframe URL
|
|
414
|
+
*/
|
|
415
|
+
async getCcPaymentIframeUrl(opportunityId) {
|
|
416
|
+
return this.payment.getIframeUrl(opportunityId);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Check credit card capture status once.
|
|
420
|
+
*
|
|
421
|
+
* Rate-limited to 1 request per 10 seconds per `opportunityId`. Prefer
|
|
422
|
+
* `pollCcPaymentStatus()` for a managed loop that handles the rate limit.
|
|
423
|
+
*
|
|
424
|
+
* @param opportunityId - The OpportunityId from the Start Application response
|
|
425
|
+
* @returns Promise with the current `status` and `shouldContinuePolling`
|
|
426
|
+
*/
|
|
427
|
+
async getCcPaymentStatus(opportunityId) {
|
|
428
|
+
return this.payment.getCcPaymentStatus(opportunityId);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Poll credit card capture status until it resolves (`'approved'` or
|
|
432
|
+
* `'failed'`) or the time budget expires.
|
|
433
|
+
*
|
|
434
|
+
* Polls every 10s by default and transparently retries HTTP 429. Never
|
|
435
|
+
* requests a new iframe URL — on `'failed'`, call `getCcPaymentIframeUrl()`
|
|
436
|
+
* again for a fresh capture, then poll again.
|
|
437
|
+
*
|
|
438
|
+
* @param opportunityId - The OpportunityId from the Start Application response
|
|
439
|
+
* @param options - Optional polling cadence overrides
|
|
440
|
+
* @returns Promise with the terminal response, or the last `'pending'` one on timeout
|
|
441
|
+
*/
|
|
442
|
+
async pollCcPaymentStatus(opportunityId, options) {
|
|
443
|
+
return this.payment.pollCcPaymentStatus(opportunityId, options);
|
|
444
|
+
}
|
|
330
445
|
// ── Secure Sign Methods ─────────────────────────────────────────────
|
|
331
446
|
/**
|
|
332
447
|
* Prepare the signing package and check available delivery channels
|
|
@@ -365,9 +480,22 @@ class InstaBrainClient {
|
|
|
365
480
|
}
|
|
366
481
|
// ── Final Submit ───────────────────────────────────────────────────
|
|
367
482
|
/**
|
|
368
|
-
* Submit the application to the carrier for a final underwriting decision
|
|
483
|
+
* Submit the application to the carrier for a final underwriting decision.
|
|
369
484
|
* Call after the signing flow is complete or when isSignCompleted is true.
|
|
370
|
-
*
|
|
485
|
+
*
|
|
486
|
+
* Note: A null policyNumber means the carrier has not yet issued a number
|
|
487
|
+
* (pending decision) — not an error.
|
|
488
|
+
*
|
|
489
|
+
* Calling this again after a successful submit is **idempotent** — it does not
|
|
490
|
+
* re-submit or re-charge, and returns the existing result including the same
|
|
491
|
+
* `policyNumber`. No client-side guard is needed.
|
|
492
|
+
*
|
|
493
|
+
* Three distinct pre-submit gates, in order: `SecureSignNotCompleted` →
|
|
494
|
+
* `paymentNotMade` (no payment started, or card capture still pending) →
|
|
495
|
+
* `LatestPaymentNotSuccessful` (payment attempted and failed). Handle the last
|
|
496
|
+
* two separately: the first means "keep waiting or start a payment", the
|
|
497
|
+
* second means "start a new capture".
|
|
498
|
+
*
|
|
371
499
|
* @param opportunityId - The OpportunityId from the Start Application response
|
|
372
500
|
* @returns Promise with the final submit response containing policyNumber
|
|
373
501
|
*/
|
|
@@ -24,8 +24,35 @@ export declare class ApplicationService extends BaseService {
|
|
|
24
24
|
* `pollFinalExpenseUnderwritingStatus(opportunityId)` for the terminal decision.
|
|
25
25
|
*
|
|
26
26
|
* Note: a `null` policyNumber does not indicate failure.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* **Calling `finalSubmit()` again after a successful submit is idempotent.**
|
|
29
|
+
* The API does not re-submit to the carrier or re-charge payment — it returns
|
|
30
|
+
* the existing result, including the same `policyNumber` for ADB / GIGDB (or
|
|
31
|
+
* the issued number for Final Expense once underwriting completes). Do not
|
|
32
|
+
* treat a repeat call as an error or guard against it client-side.
|
|
33
|
+
*
|
|
34
|
+
* **Three pre-submit gates, checked in this order.** They are distinct and
|
|
35
|
+
* separately actionable — do not collapse the last two into one case:
|
|
36
|
+
* 1. `SecureSignNotCompleted` — signing is not finished. Complete the PIN
|
|
37
|
+
* flow (or confirm `isSignCompleted`) first.
|
|
38
|
+
* 2. `paymentNotMade` — nothing to submit yet. Either no payment was ever
|
|
39
|
+
* started, **or** a credit card capture is still pending (`cc-payment-status`
|
|
40
|
+
* is `'pending'`). Finish the capture and poll to `'approved'`, or save
|
|
41
|
+
* EFT, then retry. While pending, reuse the stored iframe URL.
|
|
42
|
+
* 3. `LatestPaymentNotSuccessful` — a payment was attempted and the latest
|
|
43
|
+
* attempt failed. Call `getCcPaymentIframeUrl()` for a new capture, poll
|
|
44
|
+
* to `'approved'`, then retry.
|
|
45
|
+
*
|
|
46
|
+
* **Payment behavior by product:**
|
|
47
|
+
* - **ADB / GIGDB with credit card** — the captured card is charged here,
|
|
48
|
+
* and the application is submitted only if the charge succeeds. A declined
|
|
49
|
+
* charge returns one of the `Payment*` decline codes and the application
|
|
50
|
+
* is NOT submitted; `cc-payment-status` then reports `'failed'`.
|
|
51
|
+
* - **Final Expense with credit card** — capture to `'approved'` is still
|
|
52
|
+
* required, but InstaBrain does not charge here; the carrier collects
|
|
53
|
+
* after underwriting. Final Expense never returns a `Payment*` decline code.
|
|
54
|
+
* - **EFT (all products)** — payment was collected at `saveEftPayment()`,
|
|
55
|
+
* so the prerequisite is already met and no charge runs here.
|
|
29
56
|
*
|
|
30
57
|
* @param opportunityId - The OpportunityId from the Start Application response
|
|
31
58
|
* @returns Promise with the final submit response (`policyNumber`, optional `applicationStatus`)
|
|
@@ -29,8 +29,35 @@ class ApplicationService extends base_service_1.BaseService {
|
|
|
29
29
|
* `pollFinalExpenseUnderwritingStatus(opportunityId)` for the terminal decision.
|
|
30
30
|
*
|
|
31
31
|
* Note: a `null` policyNumber does not indicate failure.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
*
|
|
33
|
+
* **Calling `finalSubmit()` again after a successful submit is idempotent.**
|
|
34
|
+
* The API does not re-submit to the carrier or re-charge payment — it returns
|
|
35
|
+
* the existing result, including the same `policyNumber` for ADB / GIGDB (or
|
|
36
|
+
* the issued number for Final Expense once underwriting completes). Do not
|
|
37
|
+
* treat a repeat call as an error or guard against it client-side.
|
|
38
|
+
*
|
|
39
|
+
* **Three pre-submit gates, checked in this order.** They are distinct and
|
|
40
|
+
* separately actionable — do not collapse the last two into one case:
|
|
41
|
+
* 1. `SecureSignNotCompleted` — signing is not finished. Complete the PIN
|
|
42
|
+
* flow (or confirm `isSignCompleted`) first.
|
|
43
|
+
* 2. `paymentNotMade` — nothing to submit yet. Either no payment was ever
|
|
44
|
+
* started, **or** a credit card capture is still pending (`cc-payment-status`
|
|
45
|
+
* is `'pending'`). Finish the capture and poll to `'approved'`, or save
|
|
46
|
+
* EFT, then retry. While pending, reuse the stored iframe URL.
|
|
47
|
+
* 3. `LatestPaymentNotSuccessful` — a payment was attempted and the latest
|
|
48
|
+
* attempt failed. Call `getCcPaymentIframeUrl()` for a new capture, poll
|
|
49
|
+
* to `'approved'`, then retry.
|
|
50
|
+
*
|
|
51
|
+
* **Payment behavior by product:**
|
|
52
|
+
* - **ADB / GIGDB with credit card** — the captured card is charged here,
|
|
53
|
+
* and the application is submitted only if the charge succeeds. A declined
|
|
54
|
+
* charge returns one of the `Payment*` decline codes and the application
|
|
55
|
+
* is NOT submitted; `cc-payment-status` then reports `'failed'`.
|
|
56
|
+
* - **Final Expense with credit card** — capture to `'approved'` is still
|
|
57
|
+
* required, but InstaBrain does not charge here; the carrier collects
|
|
58
|
+
* after underwriting. Final Expense never returns a `Payment*` decline code.
|
|
59
|
+
* - **EFT (all products)** — payment was collected at `saveEftPayment()`,
|
|
60
|
+
* so the prerequisite is already met and no charge runs here.
|
|
34
61
|
*
|
|
35
62
|
* @param opportunityId - The OpportunityId from the Start Application response
|
|
36
63
|
* @returns Promise with the final submit response (`policyNumber`, optional `applicationStatus`)
|
|
@@ -21,9 +21,31 @@ export declare class GigdbService extends BaseService {
|
|
|
21
21
|
*/
|
|
22
22
|
startApplication(request: ThirdPartyGigdbAppReq): Promise<ThirdPartyStartAppResp>;
|
|
23
23
|
/**
|
|
24
|
-
* Save EFT payment details for
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* Save bank-account (EFT) payment details for an in-progress application.
|
|
25
|
+
*
|
|
26
|
+
* Shared endpoint — used by GIGDB, ADB, and Final Expense. Call after Start
|
|
27
|
+
* Application and before `prepareDocsAndGetDeliveryChannels()`.
|
|
28
|
+
*
|
|
29
|
+
* Validation: `accountHolderName` is required, max 100 characters, and may
|
|
30
|
+
* contain only letters, spaces, hyphens, and apostrophes; `routingNumber` is
|
|
31
|
+
* exactly 9 digits; `accountNumber` is 4–17 digits. Failures return
|
|
32
|
+
* `InvalidRequestFormat` with the field under `value.fields`.
|
|
33
|
+
*
|
|
34
|
+
* Business rules:
|
|
35
|
+
* - **EFT and credit card are mutually exclusive** per `opportunityId`.
|
|
36
|
+
* A successful payment that already exists (a prior EFT save, or a card
|
|
37
|
+
* that has already been charged) returns `PaymentAlreadyMade`. Afterwards,
|
|
38
|
+
* `getCcPaymentIframeUrl()` returns `EftPaymentAlreadyCompleted`.
|
|
39
|
+
* - No application-readiness gate here, unlike `getCcPaymentIframeUrl()` —
|
|
40
|
+
* only that the opportunity exists and payment has not completed.
|
|
41
|
+
* - Once saved, quote updates for the same opportunity are blocked.
|
|
42
|
+
* - A successful save **satisfies the payment prerequisite for
|
|
43
|
+
* `finalSubmit()`** — no charge runs again at final submit, and neither
|
|
44
|
+
* `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for
|
|
45
|
+
* payment reasons.
|
|
46
|
+
*
|
|
47
|
+
* @param request - The EFT payment request with opportunityId and bank account details
|
|
48
|
+
* @returns Promise resolving to true on success
|
|
27
49
|
*/
|
|
28
50
|
saveEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>;
|
|
29
51
|
/**
|
|
@@ -28,9 +28,31 @@ class GigdbService extends base_service_1.BaseService {
|
|
|
28
28
|
return this.post('start GIGDB application', '/api/ThirdPartyGigdbApplication/start-application', request);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Save EFT payment details for
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Save bank-account (EFT) payment details for an in-progress application.
|
|
32
|
+
*
|
|
33
|
+
* Shared endpoint — used by GIGDB, ADB, and Final Expense. Call after Start
|
|
34
|
+
* Application and before `prepareDocsAndGetDeliveryChannels()`.
|
|
35
|
+
*
|
|
36
|
+
* Validation: `accountHolderName` is required, max 100 characters, and may
|
|
37
|
+
* contain only letters, spaces, hyphens, and apostrophes; `routingNumber` is
|
|
38
|
+
* exactly 9 digits; `accountNumber` is 4–17 digits. Failures return
|
|
39
|
+
* `InvalidRequestFormat` with the field under `value.fields`.
|
|
40
|
+
*
|
|
41
|
+
* Business rules:
|
|
42
|
+
* - **EFT and credit card are mutually exclusive** per `opportunityId`.
|
|
43
|
+
* A successful payment that already exists (a prior EFT save, or a card
|
|
44
|
+
* that has already been charged) returns `PaymentAlreadyMade`. Afterwards,
|
|
45
|
+
* `getCcPaymentIframeUrl()` returns `EftPaymentAlreadyCompleted`.
|
|
46
|
+
* - No application-readiness gate here, unlike `getCcPaymentIframeUrl()` —
|
|
47
|
+
* only that the opportunity exists and payment has not completed.
|
|
48
|
+
* - Once saved, quote updates for the same opportunity are blocked.
|
|
49
|
+
* - A successful save **satisfies the payment prerequisite for
|
|
50
|
+
* `finalSubmit()`** — no charge runs again at final submit, and neither
|
|
51
|
+
* `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for
|
|
52
|
+
* payment reasons.
|
|
53
|
+
*
|
|
54
|
+
* @param request - The EFT payment request with opportunityId and bank account details
|
|
55
|
+
* @returns Promise resolving to true on success
|
|
34
56
|
*/
|
|
35
57
|
async saveEftPayment(request) {
|
|
36
58
|
const result = await this.post('save EFT payment', '/api/ThirdPartyPayment/save-eft-payment', request, undefined, true // allowNullValue — API returns BaseResponse<boolean>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { HttpClient } from '../utils/http-client';
|
|
2
|
+
import { BaseService } from './base.service';
|
|
3
|
+
import { ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions } from '../types/payment.types';
|
|
4
|
+
/**
|
|
5
|
+
* Credit card payment service (shared — **ADB, GIGDB, and Final Expense only**).
|
|
6
|
+
*
|
|
7
|
+
* Card capture happens in a TrustCommerce hosted iframe. The SDK never touches
|
|
8
|
+
* card data — it hands you a URL to render, then reports when capture completes.
|
|
9
|
+
*
|
|
10
|
+
* Flow (slots between Start Application and Prepare Signing Docs):
|
|
11
|
+
* 1. getIframeUrl(opportunityId) → URL to render; **persist it**
|
|
12
|
+
* 2. applicant submits the hosted form
|
|
13
|
+
* 3. pollCcPaymentStatus(...) → until `approved`
|
|
14
|
+
* 4. Secure Sign → InstaBrainClient.finalSubmit()
|
|
15
|
+
*
|
|
16
|
+
* Key rules:
|
|
17
|
+
* - **Persist and reuse the URL.** A new link is only issued once the latest
|
|
18
|
+
* attempt has `failed`. Calling {@link getIframeUrl} again while capture is
|
|
19
|
+
* `pending` **or** already `approved` returns `TcIframeLinkAlreadyGenerated`.
|
|
20
|
+
* - **EFT and credit card are mutually exclusive** per opportunity. After a
|
|
21
|
+
* successful `saveEftPayment()`, this endpoint returns `EftPaymentAlreadyCompleted`.
|
|
22
|
+
* - `'approved'` means the card was **captured**, not charged. ADB/GIGDB charge
|
|
23
|
+
* at `finalSubmit()`; for Final Expense the carrier collects after underwriting.
|
|
24
|
+
* - **Not supported for IB Term / Pure Term** — returns
|
|
25
|
+
* `CcPaymentIframeNotSupportedForProduct`. Those products use the shared EFT
|
|
26
|
+
* endpoint or hand off via their returned links.
|
|
27
|
+
*/
|
|
28
|
+
export declare class PaymentService extends BaseService {
|
|
29
|
+
constructor(httpClient: HttpClient);
|
|
30
|
+
/**
|
|
31
|
+
* Get the TrustCommerce hosted iframe URL for card capture.
|
|
32
|
+
*
|
|
33
|
+
* Call after Start Application has completed successfully and before Prepare
|
|
34
|
+
* Signing Docs. **Persist the returned URL keyed by `opportunityId`** and
|
|
35
|
+
* reuse it while {@link pollCcPaymentStatus} reports `'pending'` — requesting
|
|
36
|
+
* a second link before the current attempt fails returns
|
|
37
|
+
* `TcIframeLinkAlreadyGenerated`.
|
|
38
|
+
*
|
|
39
|
+
* Errors (all HTTP 400, each a distinct top-level code):
|
|
40
|
+
* - `InvalidRequestFormat` — `opportunityId` missing or unknown
|
|
41
|
+
* - `CcPaymentIframeNotSupportedForProduct` — product is not ADB / GIGDB / Final Expense
|
|
42
|
+
* - `ApplicationNotReady` — Start Application has not completed successfully
|
|
43
|
+
* - `EftPaymentAlreadyCompleted` — a successful EFT payment already exists
|
|
44
|
+
* - `TcIframeLinkAlreadyGenerated` — a link exists and the latest attempt has not failed
|
|
45
|
+
*
|
|
46
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
47
|
+
* @returns Promise resolving to the fully-qualified iframe URL.
|
|
48
|
+
*/
|
|
49
|
+
getIframeUrl(opportunityId: string): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Single check of credit card capture status.
|
|
52
|
+
*
|
|
53
|
+
* Rate-limited to 1 request per 10 seconds per `opportunityId`; exceeding it
|
|
54
|
+
* throws an `InstaBrainError` with `statusCode: 429`. This method does **not**
|
|
55
|
+
* auto-retry — use {@link pollCcPaymentStatus} for a managed loop.
|
|
56
|
+
*
|
|
57
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
58
|
+
* @returns Promise with the current `status` and `shouldContinuePolling`.
|
|
59
|
+
*/
|
|
60
|
+
getCcPaymentStatus(opportunityId: string): Promise<ThirdPartyCcPaymentStatusRes>;
|
|
61
|
+
/**
|
|
62
|
+
* Poll card-capture status until it resolves or the time budget is exhausted.
|
|
63
|
+
*
|
|
64
|
+
* Polls every 10s (configurable) and stops as soon as `shouldContinuePolling`
|
|
65
|
+
* is `false` — i.e. `'approved'` or `'failed'`. A `429` is transparently
|
|
66
|
+
* retried after the documented `Retry-After: 10` rather than aborting the poll.
|
|
67
|
+
*
|
|
68
|
+
* This method **never requests a new iframe URL**. On `'failed'` it returns and
|
|
69
|
+
* the caller needs to call {@link getIframeUrl} again for a fresh capture.
|
|
70
|
+
*
|
|
71
|
+
* On budget expiry it resolves with the last response (still `'pending'`)
|
|
72
|
+
* rather than throwing — inspect `status` to detect it.
|
|
73
|
+
*
|
|
74
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
75
|
+
* @param options - Optional cadence overrides.
|
|
76
|
+
* @returns Promise with the terminal response, or the last `'pending'` one on timeout.
|
|
77
|
+
*/
|
|
78
|
+
pollCcPaymentStatus(opportunityId: string, options?: PollCcPaymentStatusOptions): Promise<ThirdPartyCcPaymentStatusRes>;
|
|
79
|
+
/**
|
|
80
|
+
* Single status call that transparently retries a `429` (rate limit) after
|
|
81
|
+
* {@link RATE_LIMIT_RETRY_MS}, as long as another attempt fits within the poll
|
|
82
|
+
* deadline.
|
|
83
|
+
*
|
|
84
|
+
* When the retry budget is exhausted on a `429`, resolves with `fallback` (the
|
|
85
|
+
* last known response) rather than aborting the managed poll. If no `fallback`
|
|
86
|
+
* exists (the very first call), the `429` propagates. Any non-`429` error
|
|
87
|
+
* always propagates.
|
|
88
|
+
*/
|
|
89
|
+
private getStatusWithRateLimitRetry;
|
|
90
|
+
/**
|
|
91
|
+
* Promise-based sleep. Extracted so tests can drive polling with fake timers.
|
|
92
|
+
*/
|
|
93
|
+
protected delay(ms: number): Promise<void>;
|
|
94
|
+
}
|