@spritz-finance/api-client 0.0.6 → 0.0.8
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 +106 -26
- package/dist/spritz-api-client.d.ts +12 -0
- package/dist/spritz-api-client.js +32 -32
- package/dist/spritz-api-client.js.map +1 -1
- package/dist/spritz-api-client.mjs +32 -32
- package/dist/spritz-api-client.mjs.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -20,13 +20,93 @@ A Typescript library for interacting with the Spritz Finance API
|
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
|
+
Your integration key is provided by Spritz and must always be provided.
|
|
24
|
+
The api key is specific to each user,
|
|
25
|
+
and is returned once the user is created. Leave the api key blank if you haven't created the user yet.
|
|
26
|
+
|
|
23
27
|
```typescript
|
|
24
28
|
import { SpritzApiClient, Environment } from '@spritz-finance/api-client'
|
|
25
29
|
|
|
26
30
|
const client = SpritzApiClient.initialize({
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
environment: Environment.Staging,
|
|
32
|
+
apiKey: 'YOUR_USER_API_KEY_HERE',
|
|
33
|
+
integrationKey: 'YOUR_INTEGRATION_KEY_HERE',
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## User Creation
|
|
38
|
+
|
|
39
|
+
You start the process by transmitting the user's email address.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// Fetch all bank accounts for the user
|
|
43
|
+
const user = await client.user.create({
|
|
44
|
+
email: "bilbo@shiremail.net"
|
|
29
45
|
})
|
|
46
|
+
|
|
47
|
+
// user = {
|
|
48
|
+
// email: "bilbo@shiremail.net"
|
|
49
|
+
// userId: "62d17d3b377dab6c1342136e",
|
|
50
|
+
// apiKey: "ak_ZTBGDcjfdTg3NmYtZDJlZC00ZjYyLThlMDMtZmYwNDJiZDRlMWZm"
|
|
51
|
+
// }
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Once the user is created, set the api client to use the user's api key:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
client.setApiKey(user.apiKey)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Now you're ready to issue requests on behalf of the user.
|
|
63
|
+
|
|
64
|
+
## Basic User Data
|
|
65
|
+
|
|
66
|
+
Use this to fetch the user's basic data
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const userData = await client.user.getCurrentUser()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## User Verification
|
|
73
|
+
|
|
74
|
+
Use this to get a URL for the user to pass verification, and track the user's verification status.
|
|
75
|
+
You will need to direct the user's browser to go to the provided URL.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const verificationData = await client.user.getUserVerification()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Basic payment flow
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Fetch all bank accounts for the user
|
|
85
|
+
const bankAccounts = await client.bankAccounts.list()
|
|
86
|
+
|
|
87
|
+
// Choose a bank account to use for the payment request
|
|
88
|
+
const account = bankAccounts[0]
|
|
89
|
+
|
|
90
|
+
// Create a payment request for the selected bank account
|
|
91
|
+
const paymentRequest = await client.paymentRequest.create({
|
|
92
|
+
amount: 100,
|
|
93
|
+
accountId: account.id,
|
|
94
|
+
network: PaymentNetwork.Ethereum,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// Retrieve the transaction data required to issue a blockchain transaction
|
|
98
|
+
const transactionData = await client.paymentRequest.getWeb3PaymentParams({
|
|
99
|
+
paymentRequest,
|
|
100
|
+
paymentTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on mainnet
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Issue blockchain transaction with the transaction data
|
|
105
|
+
* and wait for confirmation
|
|
106
|
+
**/
|
|
107
|
+
|
|
108
|
+
// Retrieve the payment issued for the payment request to check the payment status and confirmation
|
|
109
|
+
const payment = await client.payment.getForPaymentRequest(paymentRequest.id)
|
|
30
110
|
```
|
|
31
111
|
|
|
32
112
|
## Bank Accounts
|
|
@@ -68,7 +148,7 @@ const bankAccounts = [{
|
|
|
68
148
|
},
|
|
69
149
|
ownedByUser: true,
|
|
70
150
|
createdAt: "2023-05-03T11:25:02.401Z",
|
|
71
|
-
}]
|
|
151
|
+
}]
|
|
72
152
|
```
|
|
73
153
|
|
|
74
154
|
### Add US bank account
|
|
@@ -79,13 +159,13 @@ At present, you can only add US bank accounts to a user's account. To add a US b
|
|
|
79
159
|
// Input arguments for creating a US bank account
|
|
80
160
|
|
|
81
161
|
export interface USBankAccountInput {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
162
|
+
accountNumber: string
|
|
163
|
+
email: string
|
|
164
|
+
holder: string
|
|
165
|
+
name: string
|
|
166
|
+
ownedByUser?: boolean | null
|
|
167
|
+
routingNumber: string
|
|
168
|
+
subType: BankAccountSubType
|
|
89
169
|
}
|
|
90
170
|
```
|
|
91
171
|
|
|
@@ -93,13 +173,13 @@ export interface USBankAccountInput {
|
|
|
93
173
|
import { BankAccountType, BankAccountSubType } from '@spritz-finance/api-client'
|
|
94
174
|
|
|
95
175
|
const bankAccounts = await client.bankAccounts.create(BankAccountType.USBankAccount, {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
176
|
+
accountNumber: '123456789',
|
|
177
|
+
routingNumber: '987654321',
|
|
178
|
+
email: 'bilbo@shiremail.net',
|
|
179
|
+
holder: 'Bilbo Baggins',
|
|
180
|
+
name: 'Precious Savings',
|
|
181
|
+
ownedByUser: true,
|
|
182
|
+
subType: BankAccountSubType.Savings,
|
|
103
183
|
})
|
|
104
184
|
```
|
|
105
185
|
|
|
@@ -215,15 +295,15 @@ const payment = await client.payment.getForPaymentRequest(paymentRequest.id);
|
|
|
215
295
|
|
|
216
296
|
// Example response
|
|
217
297
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
298
|
+
{
|
|
299
|
+
id: '6368e3a3ec516e9572bbd23b',
|
|
300
|
+
userId: '63d12d3B577fab6c6382136e',
|
|
301
|
+
status: 'PENDING',
|
|
302
|
+
accountId: '6322445f10d3f4d19c4d72fe',
|
|
303
|
+
amount: 100,
|
|
304
|
+
feeAmount: null,
|
|
305
|
+
createdAt: '2022-11-07T10:53:23.998Z'
|
|
306
|
+
}
|
|
227
307
|
|
|
228
308
|
```
|
|
229
309
|
|
|
@@ -573,6 +573,7 @@ interface QueryParams<V = any> {
|
|
|
573
573
|
}
|
|
574
574
|
declare class GraphClient {
|
|
575
575
|
client: AxiosInstance;
|
|
576
|
+
baseClient: AxiosInstance;
|
|
576
577
|
constructor(environment: Environment, apiKey: string, integrationKey?: string);
|
|
577
578
|
query<Q = any, V = any>({ query, variables }: QueryParams<V>): Promise<Q>;
|
|
578
579
|
}
|
|
@@ -647,9 +648,15 @@ declare class PaymentRequestService {
|
|
|
647
648
|
}): Promise<Web3PaymentParams>;
|
|
648
649
|
}
|
|
649
650
|
|
|
651
|
+
interface CreateUserResponse {
|
|
652
|
+
userId: string;
|
|
653
|
+
email: string;
|
|
654
|
+
apiKey: string;
|
|
655
|
+
}
|
|
650
656
|
declare class UserService {
|
|
651
657
|
private client;
|
|
652
658
|
constructor(client: GraphClient);
|
|
659
|
+
createUser(email: string): Promise<CreateUserResponse>;
|
|
653
660
|
getCurrentUser(): Promise<CurrentUser_me>;
|
|
654
661
|
getUserVerification(): Promise<UserVerification_verification>;
|
|
655
662
|
}
|
|
@@ -660,13 +667,18 @@ type ClientParams = {
|
|
|
660
667
|
integrationKey?: string;
|
|
661
668
|
};
|
|
662
669
|
declare class SpritzApiClient {
|
|
670
|
+
private apiKey;
|
|
671
|
+
private integrationKey;
|
|
672
|
+
private environment;
|
|
663
673
|
private client;
|
|
664
674
|
user: UserService;
|
|
665
675
|
bankAccount: BankAccountService;
|
|
666
676
|
paymentRequest: PaymentRequestService;
|
|
667
677
|
payment: PaymentService;
|
|
678
|
+
constructor(apiKey: string, integrationKey: string, environment: Environment);
|
|
668
679
|
static initialize({ environment, apiKey, integrationKey }: ClientParams): SpritzApiClient;
|
|
669
680
|
private init;
|
|
681
|
+
setApiKey(_apiKey: string): this;
|
|
670
682
|
}
|
|
671
683
|
|
|
672
684
|
export { AccountPayments, AccountPaymentsVariables, AccountPayments_paymentsForAccount, AccountProvider, BankAccountFragment, BankAccountFragment_bankAccountDetails, BankAccountFragment_bankAccountDetails_CanadianBankAccountDetails, BankAccountFragment_bankAccountDetails_USBankAccountDetails, BankAccountFragment_institution, BankAccountSubType, BankAccountType, CreateDirectPaymentInput, CreatePaymentRequestInput, CurrentUser, CurrentUser_me, DirectPaymentStatus, Environment, GetSpritzPayParams, GetSpritzPayParamsVariables, GetSpritzPayParams_spritzPayParams, ModuleStatus, PayableAccountFragment, PayableAccountFragment_BankAccount, PayableAccountFragment_BankAccount_bankAccountDetails, PayableAccountFragment_BankAccount_bankAccountDetails_CanadianBankAccountDetails, PayableAccountFragment_BankAccount_bankAccountDetails_USBankAccountDetails, PayableAccountFragment_BankAccount_institution, PayableAccountFragment_Bill, PayableAccountFragment_Bill_institution, PayableAccountType, PaymentFragment, PaymentNetwork, PaymentRequestFragment, PaymentRequestPayment, PaymentRequestPaymentVariables, PaymentRequestPayment_paymentForPaymentRequest, PaymentStatus, SpritzApiClient, TokenBalanceFragment, TransactionPrice, TransactionPriceVariables, USBankAccountInput, UserBankAccounts, UserBankAccounts_userBankAccounts, UserBankAccounts_userBankAccounts_bankAccountDetails, UserBankAccounts_userBankAccounts_bankAccountDetails_CanadianBankAccountDetails, UserBankAccounts_userBankAccounts_bankAccountDetails_USBankAccountDetails, UserBankAccounts_userBankAccounts_institution, UserFragment, UserPayableAccounts, UserPayableAccounts_payableAccounts, UserPayableAccounts_payableAccounts_BankAccount, UserPayableAccounts_payableAccounts_BankAccount_bankAccountDetails, UserPayableAccounts_payableAccounts_BankAccount_bankAccountDetails_CanadianBankAccountDetails, UserPayableAccounts_payableAccounts_BankAccount_bankAccountDetails_USBankAccountDetails, UserPayableAccounts_payableAccounts_BankAccount_institution, UserPayableAccounts_payableAccounts_Bill, UserPayableAccounts_payableAccounts_Bill_institution, UserVerification, UserVerification_verification, UserVerification_verification_identity, UserVerification_verification_identity_user, WalletTokenBalances, WalletTokenBalancesVariables, WalletTokenBalances_tokenBalances };
|