@spritz-finance/api-client 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,6 +18,76 @@ A Typescript library for interacting with the Spritz Finance API
18
18
  yarn add @spritz-finance/api-client
19
19
  ```
20
20
 
21
+ ## Table of contents
22
+
23
+ - [Interacting with the Spritz API](#interacting-with-the-spritz-api)
24
+ - [Creating a user](#creating-a-user)
25
+ - [Capabilities of the API Key:](#capabilities-of-the-api-key-)
26
+ - [Usage](#usage)
27
+ - [Creating a user](#creating-a-user-1)
28
+ - [Setting the User API Key](#setting-the-user-api-key)
29
+ - [Basic User Data](#basic-user-data)
30
+ - [User Verification](#user-verification)
31
+ - [Overview](#overview)
32
+ - [Process](#process)
33
+ - [How to Present Verification Flow to the User](#how-to-present-verification-flow-to-the-user)
34
+ - [Basic payment flow](#basic-payment-flow)
35
+ - [Note on Issuing the Blockchain Transaction](#note-on-issuing-the-blockchain-transaction)
36
+ - [Example](#example)
37
+ - [Accounts](#accounts)
38
+ - [Account Types](#account-types)
39
+ - [Commonalities & Differences](#commonalities---differences)
40
+ - [Bank Accounts](#bank-accounts)
41
+ - [List user bank accounts](#list-user-bank-accounts)
42
+ - [Add US bank account](#add-us-bank-account)
43
+ - [Bills](#bills)
44
+ - [List user bills](#list-user-bills)
45
+ - [Add US bill account](#add-us-bill-account)
46
+ - [Virtual Card](#virtual-card)
47
+ - [Fetch a users virtual card](#fetch-a-users-virtual-card)
48
+ - [Create a US virtual debit card](#create-a-us-virtual-debit-card)
49
+ - [Displaying sensitive card details](#displaying-sensitive-card-details)
50
+ - [Renaming accounts](#renaming-accounts)
51
+ - [Rename a bank account](#rename-a-bank-account)
52
+ - [Rename a bill](#rename-a-bill)
53
+ - [Deleting accounts](#deleting-accounts)
54
+ - [Delete a bank account](#delete-a-bank-account)
55
+ - [Delete a bill](#delete-a-bill)
56
+ - [Bill Institutions](#bill-institutions)
57
+ - [Fetching popular bill institutions](#fetching-popular-bill-institutions)
58
+ - [Searching for bill institutions by name](#searching-for-bill-institutions-by-name)
59
+ - [Payment Requests](#payment-requests)
60
+ - [Create a payment request](#create-a-payment-request)
61
+ - [Fulfil a payment request (EVM transactions)](#fulfil-a-payment-request--evm-transactions-)
62
+ - [Transaction fees](#transaction-fees)
63
+ - [Payments](#payments)
64
+ - [Retrieve the payment for a payment request](#retrieve-the-payment-for-a-payment-request)
65
+ - [Retrieve all payments for an account](#retrieve-all-payments-for-an-account)
66
+
67
+ ## Interacting with the Spritz API
68
+
69
+ **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.
70
+
71
+ ### Creating a user
72
+
73
+ When you create a user using your integration key:
74
+
75
+ - You will receive an `API key` specific to that user.
76
+ - This enables you to interact with the Spritz platform on the user's behalf.
77
+
78
+ ### Capabilities of the API Key:
79
+
80
+ Using the user-specific API key, you can:
81
+
82
+ 1. **Identity Verification**: Guide a user through the identity verification process.
83
+ 2. **Account Addition**:
84
+ - Add Bills for the user.
85
+ - Register Bank accounts.
86
+ - Issue Virtual cards.
87
+ 3. **Payment Requests**: Initiate payment requests to the aforementioned accounts.
88
+ 4. **Blockchain Transactions**: Issue blockchain-based transactions to fulfill the payment requests.
89
+ 5. **Payment Status**: Query the status of payments directed to the user's accounts.
90
+
21
91
  ## Usage
22
92
 
23
93
  Your integration key is provided by Spritz and must always be provided.
@@ -34,23 +104,26 @@ const client = SpritzApiClient.initialize({
34
104
  })
35
105
  ```
36
106
 
37
- ## User Creation
107
+ ## Creating a user
38
108
 
39
- A new Spritz user can be created by supplying the user's email address.
109
+ 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.
40
110
 
41
111
  ```typescript
42
112
  const user = await client.user.create({
43
113
  email: 'bilbo@shiremail.net',
44
114
  })
45
115
 
46
- // user = {
47
- // email: "bilbo@shiremail.net"
48
- // userId: "62d17d3b377dab6c1342136e",
49
- // apiKey: "ak_ZTBGDcjfdTg3NmYtZDJlZC00ZjYyLThlMDMtZmYwNDJiZDRlMWZm"
50
- // }
116
+ // Response
117
+ user = {
118
+ email: "bilbo@shiremail.net"
119
+ userId: "62d17d3b377dab6c1342136e",
120
+ apiKey: "ak_ZTBGDcjfdTg3NmYtZDJlZC00ZjYyLThlMDMtZmYwNDJiZDRlMWZm"
121
+ }
51
122
  ```
52
123
 
53
- Once the user is created, set the api client to use the user's api key:
124
+ ### Setting the User API Key
125
+
126
+ After creating a user, you can easily set the user's API key onto your initialized client using the provided method:
54
127
 
55
128
  ```typescript
56
129
  client.setApiKey(user.apiKey)
@@ -68,8 +141,29 @@ const userData = await client.user.getCurrentUser()
68
141
 
69
142
  ## User Verification
70
143
 
71
- Use this to get a URL for the user to pass verification, and track the user's verification status.
72
- You will need to direct the user's browser to go to the provided URL.
144
+ **Purpose**: To ensure users are properly identified before interacting with the Spritz platform.
145
+
146
+ ### Overview
147
+
148
+ All users must undergo basic identity verification before they can engage with the Spritz platform's features.
149
+
150
+ ### Process
151
+
152
+ 1. **User Creation**: Upon the creation of a new user, their default verification status will be set to `INITIALIZED`.
153
+
154
+ 2. **Checking Verification Status**: Use the `getUserVerification` method to retrieve the current verification status of a user.
155
+ 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.
156
+
157
+ 4. **Getting Verification URL**: When you request a user's verification status, the response will provide a `verificationUrl`. This URL is essential for the user to proceed with their identity verification.
158
+
159
+ ### How to Present Verification Flow to the User
160
+
161
+ Here are some options on how you can present the `verificationUrl` to the user:
162
+
163
+ - **Browser**: Open the URL in a new browser tab.
164
+ - **In-App**: Embed the URL in an iframe within your application.
165
+ - **Mobile**: If your platform is mobile-based, open the URL in a native mobile web view.
166
+ - **Email**: Send users an email containing the link, prompting them to complete the identity verification.
73
167
 
74
168
  ```typescript
75
169
  const verificationData = await client.user.getUserVerification()
@@ -77,6 +171,29 @@ const verificationData = await client.user.getUserVerification()
77
171
 
78
172
  ## Basic payment flow
79
173
 
174
+ Execute a payment in a few simple steps:
175
+
176
+ 1. **Select an Account**: Choose the account you wish to pay to.
177
+ 2. **Initiate Payment Request**: Use the account's ID, your desired payment amount, and the chosen blockchain network to create a payment request.
178
+ 3. **Retrieve Transaction Data**: Use the `getWeb3PaymentParams` method to obtain the necessary transaction data for fulfilling the payment request.
179
+ 4. **Blockchain Transaction**: Issue the required blockchain transaction from the user's wallet.
180
+ 5. **Payment Confirmation**: After blockchain transaction confirmation, check the status of the TradFi payment.
181
+
182
+ ### Note on Issuing the Blockchain Transaction
183
+
184
+ For Spritz to process a TradFi payment to an account, we need to receive a blockchain transaction on our smart contract, which provides us the crypto funds. As an integrator, it's essential to manage how the blockchain transaction is initiated from the user's wallet to Spritz.
185
+
186
+ - **Wallet Apps**: If your application functions as a wallet, prompt the user to sign a transaction using data from `getWeb3PaymentParams`.
187
+ - **Web-based Dapps**: Use your existing connection to the user's wallet to prompt a transaction.
188
+
189
+ If your application doesn't have a connection to the user's wallet, consider implementing one. Some popular options include:
190
+
191
+ - [Web3Modal (Web-based)](https://github.com/WalletConnect/web3modal)
192
+ - [Web3Modal (React Native)](https://github.com/WalletConnect/modal-react-native)
193
+ - [Web3-Onboard](https://onboard.blocknative.com/docs/overview/introduction#features)
194
+
195
+ ### Example
196
+
80
197
  ```typescript
81
198
  // Fetch all bank accounts for the user
82
199
  const bankAccounts = await client.bankAccount.list()
@@ -106,21 +223,40 @@ const transactionData = await client.paymentRequest.getWeb3PaymentParams({
106
223
  const payment = await client.payment.getForPaymentRequest(paymentRequest.id)
107
224
  ```
108
225
 
109
- ## Bank Accounts
226
+ ## Accounts
227
+
228
+ Spritz emphasizes its capabilities in account handling and payment processing.
229
+
230
+ ### Account Types
110
231
 
111
- Spritz provides robust support for bank accounts, allowing you to easily manage and interact with a user's bank account. To leverage these capabilities, you can utilize our specific methods and functionalities designed for bank accounts.
232
+ Spritz supports three distinct types of accounts:
112
233
 
113
- ### List user bank accounts
234
+ 1. **Bank Account**
235
+ 2. **Bill**
236
+ 3. **Virtual Card**
114
237
 
115
- You can retrieve a comprehensive list of all bank accounts that have been linked to a user's account using this functionality.
238
+ Though each account type possesses its unique creation process and specific properties, it's important to understand that all of them are uniformly termed as an "account" within the Spritz platform.
239
+
240
+ ### Commonalities & Differences
241
+
242
+ - **Common Properties**: Every type of account shares certain properties consistent across the platform.
243
+ - **Unique Properties**: Each account type also has attributes specific to its nature and functionality.
244
+
245
+ Recognizing these nuances is crucial for optimal interaction with the Spritz platform's account-related features.
246
+
247
+ ### Bank Accounts
248
+
249
+ Spritz offers a dedicated interface to manage bank accounts, allowing seamless listing and addition of bank account details for users.
250
+
251
+ #### List user bank accounts
252
+
253
+ To retrieve all bank accounts linked to a user:
116
254
 
117
255
  ```typescript
118
- const bankAccounts = await client.bankAccounts.list()
256
+ const bankAccounts = await client.bankAccount.list()
119
257
  ```
120
258
 
121
- #### Example response
122
-
123
- The bank accounts endpoint returns a standard response comprising an array of all the user-added bank accounts that are available for making payments. This array provides all the necessary information to both display the account details in a user interface and process payments to the respective accounts.
259
+ The `bankAccount.list()` method returns an array of user-linked bank accounts, complete with essential details to display in a UI and facilitate payments:
124
260
 
125
261
  ```typescript
126
262
  const bankAccounts = [{
@@ -148,13 +284,14 @@ const bankAccounts = [{
148
284
  }]
149
285
  ```
150
286
 
151
- ### Add US bank account
287
+ #### Add US bank account
152
288
 
153
- At present, you can only add US bank accounts to a user's account. To add a US bank account for the user, you can use the following.
289
+ Currently, Spritz supports the addition of US bank accounts:
290
+
291
+ The input structure for adding a US bank account is defined as:
154
292
 
155
293
  ```typescript
156
294
  // Input arguments for creating a US bank account
157
-
158
295
  export interface USBankAccountInput {
159
296
  accountNumber: string
160
297
  email: string
@@ -169,7 +306,7 @@ export interface USBankAccountInput {
169
306
  ```typescript
170
307
  import { BankAccountType, BankAccountSubType } from '@spritz-finance/api-client'
171
308
 
172
- const bankAccounts = await client.bankAccounts.create(BankAccountType.USBankAccount, {
309
+ const bankAccounts = await client.bankAccount.create(BankAccountType.USBankAccount, {
173
310
  accountNumber: '123456789',
174
311
  routingNumber: '987654321',
175
312
  email: 'bilbo@shiremail.net',
@@ -180,36 +317,85 @@ const bankAccounts = await client.bankAccounts.create(BankAccountType.USBankAcco
180
317
  })
181
318
  ```
182
319
 
183
- ### Rename a bank account
320
+ ### Bills
184
321
 
185
- 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.
322
+ Spritz provides robust support for bills, allowing seamless management and interaction with user billing accounts. Below is a guide to the methods and functionalities specifically designed for handling bills within Spritz.
323
+
324
+ #### List user bills
325
+
326
+ To retrieve all bill accounts associated with a user:
186
327
 
187
328
  ```typescript
188
- const updateAccount = await client.bankAccounts.rename('62d17d3b377dab6c1342136e', 'My new account')
329
+ const bills = await client.bill.list()
189
330
  ```
190
331
 
191
- ### Delete a bank account
332
+ The `bill.list()` method returns an array of user-associated bills, complete with essential details for display in a UI and for processing payments:
192
333
 
193
- 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.
334
+ ```typescript
335
+ const bills = [
336
+ {
337
+ id: '62d17d3b377dab6c1342136e',
338
+ name: 'Precious Credit Card',
339
+ type: 'Bill',
340
+ billType: 'CreditCard',
341
+ userId: '62d17d3b377dab6c1342136e',
342
+ mask: '4567',
343
+ originator: 'User',
344
+ payable: true,
345
+ verifying: false,
346
+ billAccountDetails: {
347
+ balance: 240.23,
348
+ amountDue: 28.34,
349
+ openedAt: '2023-05-03T11:25:02.401Z',
350
+ lastPaymentAmount: null,
351
+ lastPaymentDate: null,
352
+ nextPaymentDueDate: '2023-06-03T11:25:02.401Z',
353
+ nextPaymentMinimumAmount: 28.34,
354
+ lastStatementBalance: 180.23,
355
+ remainingStatementBalance: null,
356
+ },
357
+ country: 'US',
358
+ currency: 'USD',
359
+ dataSync: {
360
+ lastSync: '2023-05-03T11:25:02.401Z',
361
+ syncStatus: 'Active',
362
+ },
363
+ institution: {
364
+ id: '62d27d4b277dab3c1342126e',
365
+ name: 'Shire Bank Credit Card',
366
+ logo: 'https://tinyurl.com/shire-bank-logo',
367
+ },
368
+ createdAt: '2023-05-03T11:25:02.401Z',
369
+ },
370
+ ]
371
+ ```
372
+
373
+ #### Add US bill account
374
+
375
+ Currently, Spritz allows the addition of US bill accounts only. The process involves identifying the institution managing the bill and inputting the bill's account number. Here's a guide on how to add a bill for a user:
194
376
 
195
377
  ```typescript
196
- await client.bankAccounts.delete('62d17d3b377dab6c1342136e')
378
+ import { BillType } from '@spritz-finance/api-client'
379
+
380
+ const institutions = await client.institution.popularUSBillInstitutions(BillType.CreditCard)
381
+ const billInstitution = institutions[0]
382
+ const accountNumber = '12345678913213'
383
+
384
+ const bill = await client.bill.create(billInstitution.id, accountNumber, BillType.CreditCard)
197
385
  ```
198
386
 
199
- ## Virtual Cards
387
+ ### Virtual Card
200
388
 
201
- Spritz enables the creation of virtual cards, which can be funded using cryptocurrency. Similar to bank accounts, these virtual cards represent an additional type of payable account provided by Spritz. Utilize the endpoints detailed below to interact with the Virtual Card API.
389
+ Spritz offers the ability to create virtual cards that users can fund using cryptocurrency. These virtual cards represent an alternative payment account offered by Spritz. To effectively interact with the Virtual Card feature, use the API endpoints detailed below.
202
390
 
203
- ### Fetch a users virtual card
391
+ #### Fetch a users virtual card
204
392
 
205
- The fetch endpoint returns an object encompassing all the details associated with the virtual card. Please note, this object does not include sensitive card information such as the card number or the CVV.
393
+ The fetch endpoint returns an object containing details associated with the virtual card. Importantly, this object excludes sensitive card information such as the card number and the CVV.
206
394
 
207
395
  ```typescript
208
396
  const virtualCard = await client.virtualCard.fetch()
209
397
  ```
210
398
 
211
- #### Example response
212
-
213
399
  ```typescript
214
400
  const virtualCard = {
215
401
  id: '62d17d3b377dab6c1342136e',
@@ -230,14 +416,14 @@ const virtualCard = {
230
416
  street2: '',
231
417
  city: 'Hobbiton',
232
418
  subdivision: 'The Shire',
233
- postalCose: '12345',
419
+ postalCode: '12345',
234
420
  countryCode: 'ME',
235
421
  },
236
422
  },
237
423
  }
238
424
  ```
239
425
 
240
- ### Create a US virtual debit card
426
+ #### Create a US virtual debit card
241
427
 
242
428
  ```typescript
243
429
  import { VirtualCardType } from '@spritz-finance/api-client'
@@ -245,15 +431,78 @@ import { VirtualCardType } from '@spritz-finance/api-client'
245
431
  const virtualCard = await client.virtualCard.create(VirtualCardType.USVirtualDebitCard)
246
432
  ```
247
433
 
248
- ### Displaying sensitive card details
434
+ #### Displaying sensitive card details
249
435
 
250
- In order to display the sensitive card details necessary for a user to make payments, you must utilize our drop-in widget, which securely renders the card. This process requires the renderSecret, returned from the standard fetch card endpoint, in combination with the user's API key.
436
+ To show the sensitive card details that users require for payment transactions, you must integrate our dedicated drop-in widget. This widget securely renders card details. Use the renderSecret, obtained from the standard fetch card endpoint, in conjunction with the user's API key.
251
437
 
252
- We currently offer and maintain the following packages to assist with the card rendering process:
438
+ We currently support and maintain the following packages for the card rendering process:
253
439
 
254
440
  - [React Library](https://www.npmjs.com/package/@spritz-finance/react-secure-elements)
255
441
  - [React Native Library](https://www.npmjs.com/package/@spritz-finance/react-native-secure-elements)
256
442
 
443
+ ## Renaming accounts
444
+
445
+ ### Rename a bank account
446
+
447
+ 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.
448
+
449
+ ```typescript
450
+ const updateAccount = await client.bankAccount.rename('62d17d3b377dab6c1342136e', 'My new account')
451
+ ```
452
+
453
+ ### Rename a bill
454
+
455
+ 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.
456
+
457
+ ```typescript
458
+ const updateAccount = await client.bill.rename('62d17d3b377dab6c1342136e', 'My first credit card')
459
+ ```
460
+
461
+ ## Deleting accounts
462
+
463
+ ### Delete a bank account
464
+
465
+ 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.
466
+
467
+ ```typescript
468
+ await client.bankAccount.delete('62d17d3b377dab6c1342136e')
469
+ ```
470
+
471
+ ### Delete a bill
472
+
473
+ 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.
474
+
475
+ ```typescript
476
+ await client.bill.delete('62d17d3b377dab6c1342136e')
477
+ ```
478
+
479
+ ## Bill Institutions
480
+
481
+ When adding a new bill for a user, we need to provide a reference to the institution who holds the account for the user. As an example, if a user wanted to add their Chase Visa Credit Card to their Spritz account, the Institution of the account would be `Chase Credit Cards` and then the account number provided would be the 16-digit card number for their credit card.
482
+
483
+ Spritz exposes several endpoints to help users find the Institutions of their bill accounts.
484
+
485
+ ### Fetching popular bill institutions
486
+
487
+ ```typescript
488
+ const popularInstitutions = await client.institution.popularUSBillInstitutions()
489
+
490
+ // Optionally filter by a specific bill type
491
+ const popularInstitutions = await client.institution.popularUSBillInstitutions(BillType.Mortgage)
492
+ ```
493
+
494
+ ### Searching for bill institutions by name
495
+
496
+ ```typescript
497
+ const institutions = await client.institution.searchUSBillInstitutions('american express')
498
+
499
+ // Optionally filter by a specific bill type
500
+ const institutions = await client.institution.searchUSBillInstitutions(
501
+ 'american express',
502
+ BillType.CreditCard
503
+ )
504
+ ```
505
+
257
506
  ## Payment Requests
258
507
 
259
508
  A payment request refers to the intent to initiate a payment to a specific account. Once a payment request is created, a blockchain transaction is required to fulfill it. After the blockchain transaction settles, the payment request is completed, and a fiat payment is issued to the designated account.
@@ -1186,7 +1186,7 @@ declare class VirtualCardService {
1186
1186
 
1187
1187
  type ClientParams = {
1188
1188
  environment: Environment;
1189
- apiKey: string;
1189
+ apiKey?: string;
1190
1190
  integrationKey?: string;
1191
1191
  };
1192
1192
  declare class SpritzApiClient {