@spritz-finance/api-client 0.4.1 → 0.4.3
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 +123 -69
- package/dist/spritz-api-client.cjs +95 -78
- package/dist/spritz-api-client.d.ts +73 -11
- package/dist/spritz-api-client.mjs +95 -78
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -18,44 +18,87 @@ A Typescript library for interacting with the Spritz Finance API
|
|
|
18
18
|
yarn add @spritz-finance/api-client
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
Get started with Spritz in minutes:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import {
|
|
27
|
+
SpritzApiClient,
|
|
28
|
+
Environment,
|
|
29
|
+
PaymentNetwork,
|
|
30
|
+
BankAccountType,
|
|
31
|
+
BankAccountSubType,
|
|
32
|
+
} from '@spritz-finance/api-client'
|
|
33
|
+
|
|
34
|
+
// Initialize the client with your integration key
|
|
35
|
+
const client = SpritzApiClient.initialize({
|
|
36
|
+
environment: Environment.Sandbox,
|
|
37
|
+
integrationKey: 'YOUR_INTEGRATION_KEY_HERE',
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// Create a user
|
|
41
|
+
const user = await client.user.create({
|
|
42
|
+
email: 'user@example.com',
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Set the user's API key
|
|
46
|
+
client.setApiKey(user.apiKey)
|
|
47
|
+
|
|
48
|
+
// Add a bank account
|
|
49
|
+
const bankAccount = await client.bankAccount.create(BankAccountType.USBankAccount, {
|
|
50
|
+
accountNumber: '123456789',
|
|
51
|
+
routingNumber: '987654321',
|
|
52
|
+
holder: 'John Doe',
|
|
53
|
+
name: 'My Checking Account',
|
|
54
|
+
ownedByUser: true,
|
|
55
|
+
subType: BankAccountSubType.Checking,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Create a payment request
|
|
59
|
+
const paymentRequest = await client.paymentRequest.create({
|
|
60
|
+
amount: 100,
|
|
61
|
+
accountId: bankAccount.id,
|
|
62
|
+
network: PaymentNetwork.Ethereum,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// Get transaction data for blockchain payment
|
|
66
|
+
const transactionData = await client.paymentRequest.getWeb3PaymentParams({
|
|
67
|
+
paymentRequest,
|
|
68
|
+
paymentTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on mainnet
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Use transactionData to execute blockchain transaction in your app
|
|
72
|
+
```
|
|
73
|
+
|
|
21
74
|
## Table of contents
|
|
22
75
|
|
|
23
|
-
- [
|
|
76
|
+
- [Quick Start](#quick-start)
|
|
77
|
+
- [Installation](#installation)
|
|
78
|
+
- [API Overview](#api-overview)
|
|
24
79
|
- [Creating a user](#creating-a-user)
|
|
25
|
-
- [Capabilities of the API Key
|
|
80
|
+
- [Capabilities of the API Key](#capabilities-of-the-api-key)
|
|
26
81
|
- [Usage](#usage)
|
|
27
|
-
- [
|
|
82
|
+
- [User Management](#user-management)
|
|
83
|
+
- [Creating a user](#creating-a-user-1)
|
|
28
84
|
- [Setting the User API Key](#setting-the-user-api-key)
|
|
29
|
-
- [Reauthorizing a user](#reauthorizing-a-user)
|
|
30
|
-
- [Basic User Data](#basic-user-data)
|
|
31
|
-
- [User Verification](#user-verification)
|
|
32
|
-
|
|
33
|
-
- [
|
|
34
|
-
- [How to Present Verification Flow to the User](#how-to-present-verification-flow-to-the-user)
|
|
35
|
-
- [Basic payment flow](#basic-payment-flow)
|
|
85
|
+
- [Reauthorizing a user](#reauthorizing-a-user)
|
|
86
|
+
- [Basic User Data](#basic-user-data)
|
|
87
|
+
- [User Verification](#user-verification)
|
|
88
|
+
- [Payment Flow](#payment-flow)
|
|
89
|
+
- [Basic payment flow](#basic-payment-flow)
|
|
36
90
|
- [Note on Issuing the Blockchain Transaction](#note-on-issuing-the-blockchain-transaction)
|
|
37
91
|
- [Example](#example)
|
|
38
92
|
- [Accounts](#accounts)
|
|
39
93
|
- [Account Types](#account-types)
|
|
40
94
|
- [Commonalities & Differences](#commonalities---differences)
|
|
41
95
|
- [Bank Accounts](#bank-accounts)
|
|
42
|
-
- [List user bank accounts](#list-user-bank-accounts)
|
|
43
|
-
- [Add US bank account](#add-us-bank-account)
|
|
44
|
-
- [Add Canadian bank account](#add-canadian-bank-account)
|
|
45
96
|
- [Bills](#bills)
|
|
46
|
-
- [List user bills](#list-user-bills)
|
|
47
|
-
- [Add US bill account](#add-us-bill-account)
|
|
48
97
|
- [Virtual Card](#virtual-card)
|
|
49
|
-
- [Fetch a users virtual card](#fetch-a-users-virtual-card)
|
|
50
|
-
- [Create a US virtual debit card](#create-a-us-virtual-debit-card)
|
|
51
|
-
- [Displaying sensitive card details](#displaying-sensitive-card-details)
|
|
52
98
|
- [Address Book](#address-book)
|
|
53
|
-
- [
|
|
54
|
-
- [
|
|
55
|
-
- [
|
|
56
|
-
- [Deleting accounts](#deleting-accounts)
|
|
57
|
-
- [Delete a bank account](#delete-a-bank-account)
|
|
58
|
-
- [Delete a bill](#delete-a-bill)
|
|
99
|
+
- [Account Management](#account-management)
|
|
100
|
+
- [Renaming accounts](#renaming-accounts)
|
|
101
|
+
- [Deleting accounts](#deleting-accounts)
|
|
59
102
|
- [Bill Institutions](#bill-institutions)
|
|
60
103
|
- [Fetching popular bill institutions](#fetching-popular-bill-institutions)
|
|
61
104
|
- [Searching for bill institutions by name](#searching-for-bill-institutions-by-name)
|
|
@@ -71,11 +114,9 @@ A Typescript library for interacting with the Spritz Finance API
|
|
|
71
114
|
- [Retrieve all onramp payments for an account](#retrieve-all-onramp-payments-for-an-account)
|
|
72
115
|
- [Webhooks](#webhooks)
|
|
73
116
|
- [Supported webhook events](#supported-webhook-events)
|
|
74
|
-
- [Account Events](#account-events)
|
|
75
|
-
- [Payment Events](#payment-events)
|
|
76
117
|
- [Setting up webhooks](#setting-up-webhooks)
|
|
77
118
|
|
|
78
|
-
##
|
|
119
|
+
## API Overview
|
|
79
120
|
|
|
80
121
|
**Purpose**: As an integrator, this guide will assist you in creating users and performing user-specific operations on the Spritz platform using the provided API key.
|
|
81
122
|
|
|
@@ -86,7 +127,7 @@ When you create a user using your integration key:
|
|
|
86
127
|
- You will receive an `API key` specific to that user.
|
|
87
128
|
- This enables you to interact with the Spritz platform on the user's behalf.
|
|
88
129
|
|
|
89
|
-
### Capabilities of the API Key
|
|
130
|
+
### Capabilities of the API Key
|
|
90
131
|
|
|
91
132
|
Using the user-specific API key, you can:
|
|
92
133
|
|
|
@@ -109,13 +150,15 @@ and is returned once the user is created. Leave the api key blank if you haven't
|
|
|
109
150
|
import { SpritzApiClient, Environment } from '@spritz-finance/api-client'
|
|
110
151
|
|
|
111
152
|
const client = SpritzApiClient.initialize({
|
|
112
|
-
environment: Environment.
|
|
153
|
+
environment: Environment.Sandbox,
|
|
113
154
|
apiKey: 'YOUR_USER_API_KEY_HERE',
|
|
114
155
|
integrationKey: 'YOUR_INTEGRATION_KEY_HERE',
|
|
115
156
|
})
|
|
116
157
|
```
|
|
117
158
|
|
|
118
|
-
##
|
|
159
|
+
## User Management
|
|
160
|
+
|
|
161
|
+
### Creating a user
|
|
119
162
|
|
|
120
163
|
To create a new Spritz user, all you need is the user's email address. Note that trying to create a user with an email that already exists in the Spritz platform will throw an error.
|
|
121
164
|
|
|
@@ -142,7 +185,7 @@ client.setApiKey(user.apiKey)
|
|
|
142
185
|
|
|
143
186
|
Now you're ready to issue requests on behalf of the user.
|
|
144
187
|
|
|
145
|
-
|
|
188
|
+
### Reauthorizing a user
|
|
146
189
|
|
|
147
190
|
There is a scenrio where you may need to get access to a users API key again. This can happen if you are trying to sign in a user that already has a Spritz account, or if you have lost access to their API key. In this case, you can reauthorize the user by providing their email. The process is that we will send the user an OTP code to their email, and then the user must pass that code on to you to confirm that they are allowing you to interact with their account on their behalf.
|
|
148
191
|
|
|
@@ -155,7 +198,7 @@ const { apiKey, userId, email } = await client.user.authorizeApiKeyWithOTP({
|
|
|
155
198
|
})
|
|
156
199
|
```
|
|
157
200
|
|
|
158
|
-
|
|
201
|
+
### Basic User Data
|
|
159
202
|
|
|
160
203
|
Use this to fetch the user's basic data
|
|
161
204
|
|
|
@@ -163,7 +206,7 @@ Use this to fetch the user's basic data
|
|
|
163
206
|
const userData = await client.user.getCurrentUser()
|
|
164
207
|
```
|
|
165
208
|
|
|
166
|
-
|
|
209
|
+
### User Verification
|
|
167
210
|
|
|
168
211
|
**Purpose**: To ensure users are properly identified before interacting with the Spritz platform.
|
|
169
212
|
|
|
@@ -173,12 +216,13 @@ All users must undergo basic identity verification before they can engage with t
|
|
|
173
216
|
|
|
174
217
|
### Process
|
|
175
218
|
|
|
176
|
-
1. **User Creation**: Upon the creation of a new user, their default verification status will be set to `
|
|
219
|
+
1. **User Creation**: Upon the creation of a new user, their default verification status will be set to `NotStarted`.
|
|
177
220
|
|
|
178
|
-
2. **Checking Verification Status**:
|
|
179
|
-
3. **Verification Transition**: Once a user completes the identity verification process, their status will change from `INITIALIZED` to `ACTIVE`. Only then can the user fully interact with the platform.
|
|
221
|
+
2. **Checking Verification Status**: The user's verification data is included in the `getCurrentUser` response, including verification status, verification URL, verified country, and retry capability.
|
|
180
222
|
|
|
181
|
-
|
|
223
|
+
3. **Verification Transition**: Once a user completes the identity verification process, their status will change from `NotStarted` to `Verified`. Only then can the user fully interact with the platform.
|
|
224
|
+
|
|
225
|
+
4. **Getting Verification URL**: The verification URL is included in the user data response and is essential for the user to proceed with their identity verification.
|
|
182
226
|
|
|
183
227
|
### How to Present Verification Flow to the User
|
|
184
228
|
|
|
@@ -190,10 +234,17 @@ Here are some options on how you can present the `verificationUrl` to the user:
|
|
|
190
234
|
- **Email**: Send users an email containing the link, prompting them to complete the identity verification.
|
|
191
235
|
|
|
192
236
|
```typescript
|
|
193
|
-
const
|
|
237
|
+
const userData = await client.user.getCurrentUser()
|
|
238
|
+
// Access verification data directly from user object
|
|
239
|
+
const verificationStatus = userData.verificationStatus
|
|
240
|
+
const verificationUrl = userData.verificationUrl
|
|
241
|
+
const verifiedCountry = userData.verifiedCountry
|
|
242
|
+
const canRetryVerification = userData.canRetryVerification
|
|
194
243
|
```
|
|
195
244
|
|
|
196
|
-
##
|
|
245
|
+
## Payment Flow
|
|
246
|
+
|
|
247
|
+
### Basic payment flow
|
|
197
248
|
|
|
198
249
|
Execute a payment in a few simple steps:
|
|
199
250
|
|
|
@@ -525,9 +576,11 @@ Each account created in Spritz is allocated a unique on-chain payment address fo
|
|
|
525
576
|
]
|
|
526
577
|
```
|
|
527
578
|
|
|
528
|
-
##
|
|
579
|
+
## Account Management
|
|
529
580
|
|
|
530
|
-
###
|
|
581
|
+
### Renaming accounts
|
|
582
|
+
|
|
583
|
+
#### Rename a bank account
|
|
531
584
|
|
|
532
585
|
You can conveniently change the display name of a bank account using the following endpoint. The first argument specifies the ID of the bank account, while the second argument represents the desired new name for the account.
|
|
533
586
|
|
|
@@ -535,7 +588,7 @@ You can conveniently change the display name of a bank account using the followi
|
|
|
535
588
|
const updateAccount = await client.bankAccount.rename('62d17d3b377dab6c1342136e', 'My new account')
|
|
536
589
|
```
|
|
537
590
|
|
|
538
|
-
|
|
591
|
+
#### Rename a bill
|
|
539
592
|
|
|
540
593
|
You can conveniently change the display name of a bill using the following endpoint. The first argument specifies the ID of the bill, while the second argument represents the desired new name for the account.
|
|
541
594
|
|
|
@@ -543,9 +596,9 @@ You can conveniently change the display name of a bill using the following endpo
|
|
|
543
596
|
const updateAccount = await client.bill.rename('62d17d3b377dab6c1342136e', 'My first credit card')
|
|
544
597
|
```
|
|
545
598
|
|
|
546
|
-
|
|
599
|
+
### Deleting accounts
|
|
547
600
|
|
|
548
|
-
|
|
601
|
+
#### Delete a bank account
|
|
549
602
|
|
|
550
603
|
To remove a bank account from a user's account, you can use the following endpoint. You only need to specify the ID of the bank account that you want to delete as an argument.
|
|
551
604
|
|
|
@@ -553,7 +606,7 @@ To remove a bank account from a user's account, you can use the following endpoi
|
|
|
553
606
|
await client.bankAccount.delete('62d17d3b377dab6c1342136e')
|
|
554
607
|
```
|
|
555
608
|
|
|
556
|
-
|
|
609
|
+
#### Delete a bill
|
|
557
610
|
|
|
558
611
|
To remove a bill from a user's account, you can use the following endpoint. You only need to specify the ID of the bill that you want to delete as an argument.
|
|
559
612
|
|
|
@@ -762,31 +815,32 @@ const onrampPayment = await client.onrampPayment.create({
|
|
|
762
815
|
### Retrieve all onramp payments for an account
|
|
763
816
|
|
|
764
817
|
```typescript
|
|
765
|
-
const payments =
|
|
766
|
-
|
|
818
|
+
const payments =
|
|
819
|
+
await client.onrampPayment.list()[
|
|
820
|
+
// Example response
|
|
767
821
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
]
|
|
822
|
+
{
|
|
823
|
+
id: '653fab35ad263e5ae8b0e605',
|
|
824
|
+
amount: 100,
|
|
825
|
+
feeAmount: 1.5,
|
|
826
|
+
depositInstructions: {
|
|
827
|
+
amount: 101.5,
|
|
828
|
+
currency: 'USD',
|
|
829
|
+
bankName: 'Bank of Nowhere',
|
|
830
|
+
bankAddress: '1800 North Pole St., Orlando, FL 32801',
|
|
831
|
+
bankBeneficiaryName: 'Bridge Ventures Inc',
|
|
832
|
+
bankRoutingNumber: '123456789',
|
|
833
|
+
bankAccountNumber: '11223344556677',
|
|
834
|
+
paymentMethod: 'WIRE',
|
|
835
|
+
depositMessage: 'BVI72D90851F051F4189',
|
|
836
|
+
},
|
|
837
|
+
network: 'ethereum',
|
|
838
|
+
token: 'USDC',
|
|
839
|
+
address: '0xbb76483e33e01315438d8f6cf1aee9c9b85f433b',
|
|
840
|
+
status: 'AWAITING_FUNDS',
|
|
841
|
+
createdAt: '2023-10-30T13:10:13.521Z',
|
|
842
|
+
}
|
|
843
|
+
]
|
|
790
844
|
```
|
|
791
845
|
|
|
792
846
|
## Webhooks
|