@spritz-finance/api-client 0.9.0 → 0.10.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 +127 -0
- package/dist/spritz-api-client.cjs +35 -35
- package/dist/spritz-api-client.d.ts +987 -122
- package/dist/spritz-api-client.mjs +35 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -331,6 +331,133 @@ interface CABankAccountInput {
|
|
|
331
331
|
}
|
|
332
332
|
```
|
|
333
333
|
|
|
334
|
+
#### Link a US Bank Account with Plaid
|
|
335
|
+
|
|
336
|
+
Rather than collecting raw account and routing numbers, link a US bank account through [Plaid Link](https://plaid.com/docs/link/). Plaid verifies account ownership, returns institution metadata, and — for ACH-eligible accounts — provisions the **funding source** required for [ACH onramp](#ach-onramp-direct-debit).
|
|
337
|
+
|
|
338
|
+
> **Plaid Link must be enabled on your integration.** It is gated per account. If `createLinkToken()` returns `403`, contact Spritz to enable it, and fall back to [Create US Bank Account](#create-us-bank-account) in the meantime (see [Fall back to manual entry](#fall-back-to-manual-entry) below).
|
|
339
|
+
|
|
340
|
+
Linking is a two-part flow: create a link token on your **server**, then run the Plaid Link UI on the **client**. The SDK is server-side only — only the Plaid Link UI runs in the browser.
|
|
341
|
+
|
|
342
|
+
**1. Create a link token (server)**
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
const { linkToken, hostedLinkUrl, expiration } = await client.bankAccount.createLinkToken()
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
| Field | Type | Description |
|
|
349
|
+
| --------------- | ---------------- | --------------------------------------------------------- |
|
|
350
|
+
| `linkToken` | `string` | Token for initializing the Plaid Link SDK |
|
|
351
|
+
| `hostedLinkUrl` | `string \| null` | Plaid-hosted linking URL (alternative to running the SDK) |
|
|
352
|
+
| `expiration` | `string` | Token expiry (ISO 8601) |
|
|
353
|
+
|
|
354
|
+
If a bank uses OAuth, pass the OAuth target as `redirectUri` (see [Handle OAuth redirects](#handle-oauth-redirects)):
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
await client.bankAccount.createLinkToken({
|
|
358
|
+
// Web / iOS: an https:// return URL or iOS universal link
|
|
359
|
+
// Android: your package name (e.g. 'com.example.app')
|
|
360
|
+
redirectUri: 'https://app.example.com/plaid/oauth-return',
|
|
361
|
+
})
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**2. Run Plaid Link (client)**
|
|
365
|
+
|
|
366
|
+
Hand the `linkToken` to the Plaid Link SDK ([React Native](https://plaid.com/docs/link/react-native/), [Web](https://plaid.com/docs/link/web/), [iOS](https://plaid.com/docs/link/ios/), [Android](https://plaid.com/docs/link/android/)). On success, send the public token and selected account IDs back to your server.
|
|
367
|
+
|
|
368
|
+
React Native ([`react-native-plaid-link-sdk`](https://github.com/plaid/react-native-plaid-link-sdk) v11+):
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
import { create, open } from 'react-native-plaid-link-sdk'
|
|
372
|
+
|
|
373
|
+
create({
|
|
374
|
+
token: linkToken,
|
|
375
|
+
onSuccess: async (success) => {
|
|
376
|
+
await yourServer.completePlaidLink({
|
|
377
|
+
publicToken: success.publicToken,
|
|
378
|
+
accountIds: success.metadata.accounts.map((a) => a.id),
|
|
379
|
+
institutionId: success.metadata.institution?.id,
|
|
380
|
+
institutionName: success.metadata.institution?.name,
|
|
381
|
+
})
|
|
382
|
+
},
|
|
383
|
+
onExit: (exit) => {
|
|
384
|
+
if (exit.error) console.error('Plaid error:', exit.error)
|
|
385
|
+
},
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
open()
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Web ([`react-plaid-link`](https://github.com/plaid/react-plaid-link) or the vanilla JS SDK):
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
const handler = Plaid.create({
|
|
395
|
+
token: linkToken,
|
|
396
|
+
onSuccess: async (publicToken, metadata) => {
|
|
397
|
+
await yourServer.completePlaidLink({
|
|
398
|
+
publicToken,
|
|
399
|
+
accountIds: metadata.accounts.map((a) => a.id),
|
|
400
|
+
// Web SDK uses institution_id; the RN SDK uses id
|
|
401
|
+
institutionId: metadata.institution?.institution_id,
|
|
402
|
+
institutionName: metadata.institution?.name,
|
|
403
|
+
})
|
|
404
|
+
},
|
|
405
|
+
})
|
|
406
|
+
handler.open()
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**3. Complete linking (server)**
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
const { bankAccounts } = await client.bankAccount.completeLinking({
|
|
413
|
+
publicToken,
|
|
414
|
+
accountIds,
|
|
415
|
+
institutionId,
|
|
416
|
+
institutionName,
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
// A funding source is provisioned for ACH-eligible accounts. Its presence is
|
|
420
|
+
// the signal that the account can be used for ACH onramp.
|
|
421
|
+
const onrampable = bankAccounts.find((b) => b.fundingSourceId)
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
`completeLinking` exchanges the public token, stores the linked bank account(s), and provisions a funding source for ACH-eligible accounts. A `null` `fundingSourceId` means the account is usable for off-ramp only. See the [ACH Onramp Integration Guide](docs/ach-onramp-guide.md#bank-accounts-vs-funding-sources) for the bank-account-vs-funding-source model.
|
|
425
|
+
|
|
426
|
+
##### Handle OAuth redirects
|
|
427
|
+
|
|
428
|
+
Some institutions send the user out to their bank's OAuth page and redirect back when auth completes. Because Spritz creates the link token, the redirect targets must be **allowlisted on Spritz's Plaid account** — send them to Spritz before going live:
|
|
429
|
+
|
|
430
|
+
| Platform | What to register |
|
|
431
|
+
| -------- | ------------------------------------------------------------------------------------------------------- |
|
|
432
|
+
| Web | An HTTPS return URL on a domain you control (e.g. `https://app.example.com/plaid/oauth-return`) |
|
|
433
|
+
| iOS | The universal link URL you receive the redirect on — custom URL schemes (`yourapp://`) are not accepted |
|
|
434
|
+
| Android | Your app's package name (e.g. `com.example.app`) |
|
|
435
|
+
|
|
436
|
+
Pass the same value as `redirectUri` when creating the link token. The client-side work to resume the flow differs per platform (web requires re-initializing Link with `receivedRedirectUri`; native iOS/Android forward the redirect into the in-memory SDK). See [Handle OAuth redirects](docs/ach-onramp-guide.md#1c-handle-oauth-redirects) in the ACH Onramp guide for the full per-platform breakdown.
|
|
437
|
+
|
|
438
|
+
##### Fall back to manual entry
|
|
439
|
+
|
|
440
|
+
Plaid Link can be unavailable — it may not be enabled on your integration yet, `createLinkToken()` can fail, or the user may abandon or hit an error in the Link UI. Treat manual account/routing entry as a fallback so users can always add a bank account:
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
import { BankAccountType, BankAccountSubType } from '@spritz-finance/api-client'
|
|
444
|
+
|
|
445
|
+
try {
|
|
446
|
+
const { linkToken } = await client.bankAccount.createLinkToken()
|
|
447
|
+
// hand linkToken to Plaid Link on the client, then completeLinking(...)
|
|
448
|
+
} catch {
|
|
449
|
+
// Plaid unavailable — collect account + routing numbers and create directly
|
|
450
|
+
const bankAccount = await client.bankAccount.create(BankAccountType.USBankAccount, {
|
|
451
|
+
accountNumber: '123456789',
|
|
452
|
+
routingNumber: '987654321',
|
|
453
|
+
subType: BankAccountSubType.Checking,
|
|
454
|
+
ownedByUser: true,
|
|
455
|
+
})
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
A manually added account is immediately usable for **off-ramp**. **ACH on-ramp** additionally requires a funding source, and the Plaid link flow is what provisions it — so prefer Plaid Link whenever ACH onramp is in scope, and use manual entry as the off-ramp fallback.
|
|
460
|
+
|
|
334
461
|
### Debit Cards
|
|
335
462
|
|
|
336
463
|
Supported networks: **Visa** and **Mastercard**.
|