@spritz-finance/api-client 0.1.5 → 0.1.7

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,81 @@ 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
+ - [Webhooks](#webhooks)
67
+ - [Supported webhook events](#supported-webhook-events)
68
+ - [Account Events](#account-events)
69
+ - [Payment Events](#payment-events)
70
+ - [Setting up webhooks](#setting-up-webhooks)
71
+
72
+ ## Interacting with the Spritz API
73
+
74
+ **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.
75
+
76
+ ### Creating a user
77
+
78
+ When you create a user using your integration key:
79
+
80
+ - You will receive an `API key` specific to that user.
81
+ - This enables you to interact with the Spritz platform on the user's behalf.
82
+
83
+ ### Capabilities of the API Key:
84
+
85
+ Using the user-specific API key, you can:
86
+
87
+ 1. **Identity Verification**: Guide a user through the identity verification process.
88
+ 2. **Account Addition**:
89
+ - Add Bills for the user.
90
+ - Register Bank accounts.
91
+ - Issue Virtual cards.
92
+ 3. **Payment Requests**: Initiate payment requests to the aforementioned accounts.
93
+ 4. **Blockchain Transactions**: Issue blockchain-based transactions to fulfill the payment requests.
94
+ 5. **Payment Status**: Query the status of payments directed to the user's accounts.
95
+
21
96
  ## Usage
22
97
 
23
98
  Your integration key is provided by Spritz and must always be provided.
@@ -34,23 +109,26 @@ const client = SpritzApiClient.initialize({
34
109
  })
35
110
  ```
36
111
 
37
- ## User Creation
112
+ ## Creating a user
38
113
 
39
- A new Spritz user can be created by supplying the user's email address.
114
+ 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
115
 
41
116
  ```typescript
42
117
  const user = await client.user.create({
43
118
  email: 'bilbo@shiremail.net',
44
119
  })
45
120
 
46
- // user = {
47
- // email: "bilbo@shiremail.net"
48
- // userId: "62d17d3b377dab6c1342136e",
49
- // apiKey: "ak_ZTBGDcjfdTg3NmYtZDJlZC00ZjYyLThlMDMtZmYwNDJiZDRlMWZm"
50
- // }
121
+ // Response
122
+ user = {
123
+ email: "bilbo@shiremail.net"
124
+ userId: "62d17d3b377dab6c1342136e",
125
+ apiKey: "ak_ZTBGDcjfdTg3NmYtZDJlZC00ZjYyLThlMDMtZmYwNDJiZDRlMWZm"
126
+ }
51
127
  ```
52
128
 
53
- Once the user is created, set the api client to use the user's api key:
129
+ ### Setting the User API Key
130
+
131
+ After creating a user, you can easily set the user's API key onto your initialized client using the provided method:
54
132
 
55
133
  ```typescript
56
134
  client.setApiKey(user.apiKey)
@@ -68,8 +146,29 @@ const userData = await client.user.getCurrentUser()
68
146
 
69
147
  ## User Verification
70
148
 
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.
149
+ **Purpose**: To ensure users are properly identified before interacting with the Spritz platform.
150
+
151
+ ### Overview
152
+
153
+ All users must undergo basic identity verification before they can engage with the Spritz platform's features.
154
+
155
+ ### Process
156
+
157
+ 1. **User Creation**: Upon the creation of a new user, their default verification status will be set to `INITIALIZED`.
158
+
159
+ 2. **Checking Verification Status**: Use the `getUserVerification` method to retrieve the current verification status of a user.
160
+ 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.
161
+
162
+ 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.
163
+
164
+ ### How to Present Verification Flow to the User
165
+
166
+ Here are some options on how you can present the `verificationUrl` to the user:
167
+
168
+ - **Browser**: Open the URL in a new browser tab.
169
+ - **In-App**: Embed the URL in an iframe within your application.
170
+ - **Mobile**: If your platform is mobile-based, open the URL in a native mobile web view.
171
+ - **Email**: Send users an email containing the link, prompting them to complete the identity verification.
73
172
 
74
173
  ```typescript
75
174
  const verificationData = await client.user.getUserVerification()
@@ -77,6 +176,29 @@ const verificationData = await client.user.getUserVerification()
77
176
 
78
177
  ## Basic payment flow
79
178
 
179
+ Execute a payment in a few simple steps:
180
+
181
+ 1. **Select an Account**: Choose the account you wish to pay to.
182
+ 2. **Initiate Payment Request**: Use the account's ID, your desired payment amount, and the chosen blockchain network to create a payment request.
183
+ 3. **Retrieve Transaction Data**: Use the `getWeb3PaymentParams` method to obtain the necessary transaction data for fulfilling the payment request.
184
+ 4. **Blockchain Transaction**: Issue the required blockchain transaction from the user's wallet.
185
+ 5. **Payment Confirmation**: After blockchain transaction confirmation, check the status of the TradFi payment.
186
+
187
+ ### Note on Issuing the Blockchain Transaction
188
+
189
+ 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.
190
+
191
+ - **Wallet Apps**: If your application functions as a wallet, prompt the user to sign a transaction using data from `getWeb3PaymentParams`.
192
+ - **Web-based Dapps**: Use your existing connection to the user's wallet to prompt a transaction.
193
+
194
+ If your application doesn't have a connection to the user's wallet, consider implementing one. Some popular options include:
195
+
196
+ - [Web3Modal (Web-based)](https://github.com/WalletConnect/web3modal)
197
+ - [Web3Modal (React Native)](https://github.com/WalletConnect/modal-react-native)
198
+ - [Web3-Onboard](https://onboard.blocknative.com/docs/overview/introduction#features)
199
+
200
+ ### Example
201
+
80
202
  ```typescript
81
203
  // Fetch all bank accounts for the user
82
204
  const bankAccounts = await client.bankAccount.list()
@@ -106,21 +228,40 @@ const transactionData = await client.paymentRequest.getWeb3PaymentParams({
106
228
  const payment = await client.payment.getForPaymentRequest(paymentRequest.id)
107
229
  ```
108
230
 
109
- ## Bank Accounts
231
+ ## Accounts
232
+
233
+ Spritz emphasizes its capabilities in account handling and payment processing.
234
+
235
+ ### Account Types
236
+
237
+ Spritz supports three distinct types of accounts:
238
+
239
+ 1. **Bank Account**
240
+ 2. **Bill**
241
+ 3. **Virtual Card**
242
+
243
+ 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.
110
244
 
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.
245
+ ### Commonalities & Differences
112
246
 
113
- ### List user bank accounts
247
+ - **Common Properties**: Every type of account shares certain properties consistent across the platform.
248
+ - **Unique Properties**: Each account type also has attributes specific to its nature and functionality.
114
249
 
115
- You can retrieve a comprehensive list of all bank accounts that have been linked to a user's account using this functionality.
250
+ Recognizing these nuances is crucial for optimal interaction with the Spritz platform's account-related features.
251
+
252
+ ### Bank Accounts
253
+
254
+ Spritz offers a dedicated interface to manage bank accounts, allowing seamless listing and addition of bank account details for users.
255
+
256
+ #### List user bank accounts
257
+
258
+ To retrieve all bank accounts linked to a user:
116
259
 
117
260
  ```typescript
118
261
  const bankAccounts = await client.bankAccount.list()
119
262
  ```
120
263
 
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.
264
+ 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
265
 
125
266
  ```typescript
126
267
  const bankAccounts = [{
@@ -148,13 +289,14 @@ const bankAccounts = [{
148
289
  }]
149
290
  ```
150
291
 
151
- ### Add US bank account
292
+ #### Add US bank account
293
+
294
+ Currently, Spritz supports the addition of US bank accounts:
152
295
 
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.
296
+ The input structure for adding a US bank account is defined as:
154
297
 
155
298
  ```typescript
156
299
  // Input arguments for creating a US bank account
157
-
158
300
  export interface USBankAccountInput {
159
301
  accountNumber: string
160
302
  email: string
@@ -180,78 +322,62 @@ const bankAccounts = await client.bankAccount.create(BankAccountType.USBankAccou
180
322
  })
181
323
  ```
182
324
 
183
- ### Rename a bank account
325
+ ### Bills
184
326
 
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.
327
+ 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.
186
328
 
187
- ```typescript
188
- const updateAccount = await client.bankAccount.rename('62d17d3b377dab6c1342136e', 'My new account')
189
- ```
329
+ #### List user bills
190
330
 
191
- ### Delete a bank account
192
-
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.
194
-
195
- ```typescript
196
- await client.bankAccount.delete('62d17d3b377dab6c1342136e')
197
- ```
198
-
199
- ## Bills
200
-
201
- 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.
202
-
203
- ### List user bills
204
-
205
- You can retrieve a list of all the bills accounts that have been linked to a user's account using this functionality.
331
+ To retrieve all bill accounts associated with a user:
206
332
 
207
333
  ```typescript
208
334
  const bills = await client.bill.list()
209
335
  ```
210
336
 
211
- #### Example response
212
-
213
- The bills endpoint returns a response comprising an array of all the bills belonging to the user 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.
337
+ The `bill.list()` method returns an array of user-associated bills, complete with essential details for display in a UI and for processing payments:
214
338
 
215
339
  ```typescript
216
- const bills = [{
217
- id: "62d17d3b377dab6c1342136e",
218
- name: "Precious Credit Card",
219
- type: "Bill",
220
- billType: "CreditCard",
221
- userId: "62d17d3b377dab6c1342136e",
222
- mask: "4567",
223
- originator: "User",
224
- payable: true,
225
- verifying: false,
226
- billAccountDetails: {
227
- balance: 240.23,
228
- amountDue: 28.34,
229
- openedAt: "2023-05-03T11:25:02.401Z",
230
- lastPaymentAmount: null,
231
- lastPaymentDate: null,
232
- nextPaymentDueDate: "2023-06-03T11:25:02.401Z",
233
- nextPaymentMinimumAmount: 28.34,
234
- lastStatementBalance: 180.23,
235
- remainingStatementBalance: null,
236
- },
237
- country: "US",
238
- currency: "USD",
239
- dataSync {
240
- lastSync: "2023-05-03T11:25:02.401Z",
241
- syncStatus: "Active",
242
- },
243
- institution: {
244
- id: "62d27d4b277dab3c1342126e",
245
- name: "Shire Bank Credit Card",
246
- logo: "https://tinyurl.com/shire-bank-logo",
247
- },
248
- createdAt: "2023-05-03T11:25:02.401Z",
249
- }]
340
+ const bills = [
341
+ {
342
+ id: '62d17d3b377dab6c1342136e',
343
+ name: 'Precious Credit Card',
344
+ type: 'Bill',
345
+ billType: 'CreditCard',
346
+ userId: '62d17d3b377dab6c1342136e',
347
+ mask: '4567',
348
+ originator: 'User',
349
+ payable: true,
350
+ verifying: false,
351
+ billAccountDetails: {
352
+ balance: 240.23,
353
+ amountDue: 28.34,
354
+ openedAt: '2023-05-03T11:25:02.401Z',
355
+ lastPaymentAmount: null,
356
+ lastPaymentDate: null,
357
+ nextPaymentDueDate: '2023-06-03T11:25:02.401Z',
358
+ nextPaymentMinimumAmount: 28.34,
359
+ lastStatementBalance: 180.23,
360
+ remainingStatementBalance: null,
361
+ },
362
+ country: 'US',
363
+ currency: 'USD',
364
+ dataSync: {
365
+ lastSync: '2023-05-03T11:25:02.401Z',
366
+ syncStatus: 'Active',
367
+ },
368
+ institution: {
369
+ id: '62d27d4b277dab3c1342126e',
370
+ name: 'Shire Bank Credit Card',
371
+ logo: 'https://tinyurl.com/shire-bank-logo',
372
+ },
373
+ createdAt: '2023-05-03T11:25:02.401Z',
374
+ },
375
+ ]
250
376
  ```
251
377
 
252
- ### Add US bill account
378
+ #### Add US bill account
253
379
 
254
- At present, you can only add US bills to a user's account. Adding a bill involves finding the institution who holds the account, and providing the account number for the bill. To add a bill for the user, you can use the following.
380
+ 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:
255
381
 
256
382
  ```typescript
257
383
  import { BillType } from '@spritz-finance/api-client'
@@ -263,47 +389,96 @@ const accountNumber = '12345678913213'
263
389
  const bill = await client.bill.create(billInstitution.id, accountNumber, BillType.CreditCard)
264
390
  ```
265
391
 
266
- ### Rename a bill
392
+ ### Virtual Card
267
393
 
268
- 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.
394
+ 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.
395
+
396
+ #### Fetch a users virtual card
397
+
398
+ 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.
269
399
 
270
400
  ```typescript
271
- const updateAccount = await client.bill.rename('62d17d3b377dab6c1342136e', 'My first credit card')
401
+ const virtualCard = await client.virtualCard.fetch()
272
402
  ```
273
403
 
274
- ### Delete a bill
404
+ ```typescript
405
+ const virtualCard = {
406
+ id: '62d17d3b377dab6c1342136e',
407
+ type: 'VirtualCard',
408
+ virtualCardType: 'USVirtualDebitCard',
409
+ userId: '62d17d3b377dab6c1342136e',
410
+ mask: '0001',
411
+ country: 'US',
412
+ currency: 'USD',
413
+ balance: 0,
414
+ renderSecret: 'U2FsdGVkX18bLYGYLILf4AeW5fOl8VYxAvKWVDtbZI5DO7swFqkJ2o',
415
+ billingInfo: {
416
+ holder: 'Bilbo Baggins',
417
+ phone: '+123456789',
418
+ email: 'bilbo@shiremail.net',
419
+ address: {
420
+ street: '1 Bagshot Row',
421
+ street2: '',
422
+ city: 'Hobbiton',
423
+ subdivision: 'The Shire',
424
+ postalCode: '12345',
425
+ countryCode: 'ME',
426
+ },
427
+ },
428
+ }
429
+ ```
275
430
 
276
- 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.
431
+ #### Create a US virtual debit card
277
432
 
278
433
  ```typescript
279
- await client.bill.delete('62d17d3b377dab6c1342136e')
434
+ import { VirtualCardType } from '@spritz-finance/api-client'
435
+
436
+ const virtualCard = await client.virtualCard.create(VirtualCardType.USVirtualDebitCard)
280
437
  ```
281
438
 
282
- ## Bill Institutions
439
+ #### Displaying sensitive card details
283
440
 
284
- 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.
441
+ 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.
285
442
 
286
- Spritz exposes several endpoints to help users find the Institutions of their bill accounts.
443
+ We currently support and maintain the following packages for the card rendering process:
287
444
 
288
- ### Fetching popular bill institutions
445
+ - [React Library](https://www.npmjs.com/package/@spritz-finance/react-secure-elements)
446
+ - [React Native Library](https://www.npmjs.com/package/@spritz-finance/react-native-secure-elements)
447
+
448
+ ## Renaming accounts
449
+
450
+ ### Rename a bank account
451
+
452
+ 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.
289
453
 
290
454
  ```typescript
291
- const popularInstitutions = await client.institution.popularUSBillInstitutions()
455
+ const updateAccount = await client.bankAccount.rename('62d17d3b377dab6c1342136e', 'My new account')
456
+ ```
292
457
 
293
- // Optionally filter by a specific bill type
294
- const popularInstitutions = await client.institution.popularUSBillInstitutions(BillType.Mortgage)
458
+ ### Rename a bill
459
+
460
+ 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.
461
+
462
+ ```typescript
463
+ const updateAccount = await client.bill.rename('62d17d3b377dab6c1342136e', 'My first credit card')
295
464
  ```
296
465
 
297
- ### Searching for bill institutions by name
466
+ ## Deleting accounts
467
+
468
+ ### Delete a bank account
469
+
470
+ 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.
298
471
 
299
472
  ```typescript
300
- const institutions = await client.institution.searchUSBillInstitutions('american express')
473
+ await client.bankAccount.delete('62d17d3b377dab6c1342136e')
474
+ ```
301
475
 
302
- // Optionally filter by a specific bill type
303
- const institutions = await client.institution.searchUSBillInstitutions(
304
- 'american express',
305
- BillType.CreditCard
306
- )
476
+ ### Delete a bill
477
+
478
+ 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.
479
+
480
+ ```typescript
481
+ await client.bill.delete('62d17d3b377dab6c1342136e')
307
482
  ```
308
483
 
309
484
  ## Bill Institutions
@@ -333,64 +508,6 @@ const institutions = await client.institution.searchUSBillInstitutions(
333
508
  )
334
509
  ```
335
510
 
336
- ## Virtual Cards
337
-
338
- 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.
339
-
340
- ### Fetch a users virtual card
341
-
342
- 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.
343
-
344
- ```typescript
345
- const virtualCard = await client.virtualCard.fetch()
346
- ```
347
-
348
- #### Example response
349
-
350
- ```typescript
351
- const virtualCard = {
352
- id: '62d17d3b377dab6c1342136e',
353
- type: 'VirtualCard',
354
- virtualCardType: 'USVirtualDebitCard',
355
- userId: '62d17d3b377dab6c1342136e',
356
- mask: '0001',
357
- country: 'US',
358
- currency: 'USD',
359
- balance: 0,
360
- renderSecret: 'U2FsdGVkX18bLYGYLILf4AeW5fOl8VYxAvKWVDtbZI5DO7swFqkJ2o',
361
- billingInfo: {
362
- holder: 'Bilbo Baggins',
363
- phone: '+123456789',
364
- email: 'bilbo@shiremail.net',
365
- address: {
366
- street: '1 Bagshot Row',
367
- street2: '',
368
- city: 'Hobbiton',
369
- subdivision: 'The Shire',
370
- postalCose: '12345',
371
- countryCode: 'ME',
372
- },
373
- },
374
- }
375
- ```
376
-
377
- ### Create a US virtual debit card
378
-
379
- ```typescript
380
- import { VirtualCardType } from '@spritz-finance/api-client'
381
-
382
- const virtualCard = await client.virtualCard.create(VirtualCardType.USVirtualDebitCard)
383
- ```
384
-
385
- ### Displaying sensitive card details
386
-
387
- 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.
388
-
389
- We currently offer and maintain the following packages to assist with the card rendering process:
390
-
391
- - [React Library](https://www.npmjs.com/package/@spritz-finance/react-secure-elements)
392
- - [React Native Library](https://www.npmjs.com/package/@spritz-finance/react-native-secure-elements)
393
-
394
511
  ## Payment Requests
395
512
 
396
513
  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.
@@ -518,3 +635,50 @@ const payments = await client.payment.listForAccount(account.id)
518
635
  },
519
636
  ]
520
637
  ```
638
+
639
+ ## Webhooks
640
+
641
+ Instead of making a request to get information, webhooks send information to your specified endpoint as soon as an event occurs. Spritz's integration offers a variety of webhook events that can be crucial for maintaining data integrity and responsiveness in applications. Let's dive into how you can best utilize these.
642
+
643
+ ### Supported webhook events
644
+
645
+ Spritz currently supports the following webhook events:
646
+
647
+ #### Account Events
648
+
649
+ - `account.created`: Triggered when a new account is created.
650
+ - `account.updated`: Triggered when details of an account are updated.
651
+ - `account.deleted`: Triggered when an account is deleted.
652
+
653
+ #### Payment Events
654
+
655
+ - `payment.created`: Triggered when a new payment is initiated.
656
+ - `payment.updated`: Triggered when details of a payment are updated.
657
+ - `payment.completed`: Triggered when a payment is successfully completed.
658
+ - `payment.refunded`: Triggered when a payment is refunded.
659
+
660
+ These events allow you to respond to changes in the account and payments for a user.
661
+
662
+ ### Setting up webhooks
663
+
664
+ To set up a webhook with Spritz, you'll need to provide:
665
+
666
+ 1. **URL**: The endpoint URL where Spritz will send the webhook data.
667
+ 2. **Events**: The specific events you want to listen for.
668
+
669
+ ```typescript
670
+ const webhook = await client.webhook.create({
671
+ url: 'https://my.webhook.url/spritz',
672
+ events: ['account.created', 'account.updated', 'account.deleted'],
673
+ })
674
+ ```
675
+
676
+ Upon receiving a webhook, your server will get a payload with the following structure:
677
+
678
+ ```json
679
+ {
680
+ "userId": "user-id-here",
681
+ "id": "resource-id-here",
682
+ "eventName": "name-of-the-event-here"
683
+ }
684
+ ```
@@ -1184,9 +1184,29 @@ declare class VirtualCardService {
1184
1184
  create<T extends VirtualCardType>(type: T, input: CreateInputMapping[T]): Promise<NonNullable<CreateMutationMapping[T]["query"][keyof CreateMutationMapping[T]["query"]]> | null>;
1185
1185
  }
1186
1186
 
1187
+ declare const EVENTS: readonly ["account.created", "account.updated", "account.deleted", "payment.created", "payment.updated", "payment.completed", "payment.refunded"];
1188
+ type WebhookEvent = (typeof EVENTS)[number];
1189
+ type IntegratorWebhook = {
1190
+ id: string;
1191
+ integratorId: string;
1192
+ failureCount: number;
1193
+ events: string[];
1194
+ url: string;
1195
+ createdAt: string;
1196
+ };
1197
+ type CreateWebhookArgs = {
1198
+ url: string;
1199
+ events: WebhookEvent[];
1200
+ };
1201
+ declare class WebhookService {
1202
+ private client;
1203
+ constructor(client: GraphClient);
1204
+ create(args: CreateWebhookArgs): Promise<IntegratorWebhook>;
1205
+ }
1206
+
1187
1207
  type ClientParams = {
1188
1208
  environment: Environment;
1189
- apiKey: string;
1209
+ apiKey?: string;
1190
1210
  integrationKey?: string;
1191
1211
  };
1192
1212
  declare class SpritzApiClient {
@@ -1201,6 +1221,7 @@ declare class SpritzApiClient {
1201
1221
  virtualCard: VirtualCardService;
1202
1222
  bill: BillService;
1203
1223
  institution: InstitutionService;
1224
+ webhook: WebhookService;
1204
1225
  constructor(apiKey: string, integrationKey: string, environment: Environment);
1205
1226
  static initialize({ environment, apiKey, integrationKey }: ClientParams): SpritzApiClient;
1206
1227
  private init;