@spritz-finance/api-client 0.0.4 → 0.0.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/LICENCE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2023, Spritz Finance Inc.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -23,13 +23,20 @@ A Typescript library for interacting with the Spritz Finance API
23
23
  ```typescript
24
24
  import { SpritzApiClient, Environment } from '@spritz-finance/api-client'
25
25
 
26
- const client = SpritzApiClient.initialize(Environment.Staging, 'YOUR_API_KEY_HERE')
26
+ const client = SpritzApiClient.initialize({
27
+ environment: Environment.Staging,
28
+ apiKey: 'YOUR_API_KEY_HERE'
29
+ })
27
30
  ```
28
31
 
29
32
  ## Bank Accounts
30
33
 
34
+ 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.
35
+
31
36
  ### List user bank accounts
32
37
 
38
+ You can retrieve a comprehensive list of all bank accounts that have been linked to a user's account using this functionality.
39
+
33
40
  ```typescript
34
41
  const bankAccounts = await client.bankAccounts.list()
35
42
  ```
@@ -40,33 +47,37 @@ The bank accounts endpoint returns a standard response comprising an array of al
40
47
 
41
48
  ```typescript
42
49
  const bankAccounts = [{
43
- id: "62d17d3b377dab6c1342136e",
44
- name: "Precious Savings",
45
- type: "BankAccount",
46
- bankAccountType: "USBankAccount",
47
- bankAccountSubType: "Checking",
48
- userId: "62d17d3b377dab6c1342136e",
49
- accountNumber: "1234567",
50
- bankAccountDetails: {
51
- routingNumber: "00000123",
52
- }
53
- country: "US",
54
- currency: "USD",
55
- email: "bilbo@shiremail.net",
56
- holder: "Bilbo Baggins",
57
- institution: {
58
- id: "62d27d4b277dab3c1342126e",
59
- name: "Shire Bank",
60
- logo: "https://tinyurl.com/shire-bank-logo",
61
- },
62
- ownedByUser: true,
63
- createdAt: "2023-05-03T11:25:02.401Z",
50
+ id: "62d17d3b377dab6c1342136e",
51
+ name: "Precious Savings",
52
+ type: "BankAccount",
53
+ bankAccountType: "USBankAccount",
54
+ bankAccountSubType: "Checking",
55
+ userId: "62d17d3b377dab6c1342136e",
56
+ accountNumber: "1234567",
57
+ bankAccountDetails: {
58
+ routingNumber: "00000123",
59
+ }
60
+ country: "US",
61
+ currency: "USD",
62
+ email: "bilbo@shiremail.net",
63
+ holder: "Bilbo Baggins",
64
+ institution: {
65
+ id: "62d27d4b277dab3c1342126e",
66
+ name: "Shire Bank",
67
+ logo: "https://tinyurl.com/shire-bank-logo",
68
+ },
69
+ ownedByUser: true,
70
+ createdAt: "2023-05-03T11:25:02.401Z",
64
71
  }];
65
72
  ```
66
73
 
67
74
  ### Add US bank account
68
75
 
76
+ 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.
77
+
69
78
  ```typescript
79
+ // Input arguments for creating a US bank account
80
+
70
81
  export interface USBankAccountInput {
71
82
  accountNumber: string
72
83
  email: string
@@ -94,12 +105,144 @@ const bankAccounts = await client.bankAccounts.create(BankAccountType.USBankAcco
94
105
 
95
106
  ### Rename a bank account
96
107
 
108
+ 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.
109
+
97
110
  ```typescript
98
111
  const updateAccount = await client.bankAccounts.rename('62d17d3b377dab6c1342136e', 'My new account')
99
112
  ```
100
113
 
101
114
  ### Delete a bank account
102
115
 
116
+ 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.
117
+
103
118
  ```typescript
104
119
  await client.bankAccounts.delete('62d17d3b377dab6c1342136e')
105
120
  ```
121
+
122
+ ## Payment Requests
123
+
124
+ 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.
125
+
126
+ ### Create a payment request
127
+
128
+ To initiate a payment request for a specific account, you can use the following functionality. The required inputs for creating a payment request include the ID of the account to be paid, the amount of the fiat payment in USD, and the network on which the blockchain transaction will settle.
129
+
130
+ ```typescript
131
+ import {PaymentNetwork} from '@spritz-finance/api-client';
132
+
133
+ const paymentRequest = await client.paymentRequest.create({
134
+ amount: 100,
135
+ accountId: account.id,
136
+ network: PaymentNetwork.Ethereum,
137
+ });
138
+
139
+ // Example response
140
+
141
+ {
142
+ id: '645399c8c1ac408007b12273',
143
+ userId: '63d12d3B577fab6c6382136e',
144
+ accountId: '6322445f10d3f4d19c4d72fe',
145
+ status: 'CREATED',
146
+ amount: 100,
147
+ feeAmount: 0,
148
+ amountDue: 100,
149
+ network: 'ethereum',
150
+ createdAt: '2023-05-04T11:40:56.488Z'
151
+ }
152
+ ```
153
+
154
+ ### Fulfil a payment request (EVM transactions)
155
+
156
+ After creating a payment request, you must issue a blockchain transaction to settle the payment request. For EVM compatible networks, this involves interacting with the SpritzPay smart contract (see: [SpritzPay deployments](https://docs.spritz.finance/docs/deployment-addresses)).
157
+
158
+ To obtain the data needed for the transaction, you can use the following endpoint.
159
+
160
+ ```typescript
161
+ import {PaymentNetwork} from '@spritz-finance/api-client';
162
+
163
+ const paymentRequest = await client.paymentRequest.create({
164
+ amount: 100,
165
+ accountId: account.id,
166
+ network: PaymentNetwork.Ethereum,
167
+ });
168
+
169
+ const transactionData = await client.paymentRequest.getWeb3PaymentParams({
170
+ paymentRequest,
171
+ paymentTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on mainnet
172
+ })
173
+
174
+ // Example response
175
+
176
+ {
177
+ contractAddress: '0xbF7Abc15f00a8C2d6b13A952c58d12b7c194A8D0',
178
+ method: 'payWithToken',
179
+ calldata: '0xd71d9632000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000064539a31c1ac408007b12277',
180
+ value: null,
181
+ requiredTokenInput: '100000000',
182
+ suggestedGasLimit: '110000'
183
+ }
184
+ ```
185
+
186
+ The contract address (to), calldata (data), and value are the primary components used to execute the blockchain transaction. You can use the `requiredTokenInput` to verify that the user's wallet has sufficient funds to complete the payment before initiating the transaction.
187
+
188
+ ### Transaction fees
189
+
190
+ Transaction fees are applied once the monthly transaction volume exceeds $100. To determine the fee amount for a specific payment value, you can use the following endpoint.
191
+
192
+ ```typescript
193
+ const fees = await client.paymentRequest.transactionPrice(101)
194
+
195
+ // Example response
196
+ 0.01
197
+ ```
198
+
199
+ ## Payments
200
+
201
+ Payments represent a fiat payment that has been issued to the account. Once the status of the Payment Request has moved to `Confirmed` then the Payment will be created.
202
+
203
+ ### Retrieve the payment for a payment request
204
+
205
+ ```typescript
206
+ import {PaymentNetwork} from '@spritz-finance/api-client';
207
+
208
+ const paymentRequest = await client.paymentRequest.create({
209
+ amount: 100,
210
+ accountId: account.id,
211
+ network: PaymentNetwork.Ethereum,
212
+ });
213
+
214
+ const payment = await client.payment.getForPaymentRequest(paymentRequest.id);
215
+
216
+ // Example response
217
+
218
+ {
219
+ id: '6368e3a3ec516e9572bbd23b',
220
+ userId: '63d12d3B577fab6c6382136e',
221
+ status: 'PENDING',
222
+ accountId: '6322445f10d3f4d19c4d72fe',
223
+ amount: 100,
224
+ feeAmount: null,
225
+ createdAt: '2022-11-07T10:53:23.998Z'
226
+ }
227
+
228
+ ```
229
+
230
+ ### Retrieve all payments for an account
231
+
232
+ ```typescript
233
+ const payments = await client.payment.listForAccount(account.id)
234
+
235
+ // Example response
236
+
237
+ [
238
+ {
239
+ id: '6368e3a3ec516e9572bbd23b',
240
+ userId: '63d12d3B577fab6c6382136e',
241
+ status: 'PENDING',
242
+ accountId: '6322445f10d3f4d19c4d72fe',
243
+ amount: 100,
244
+ feeAmount: null,
245
+ createdAt: '2022-11-07T10:53:23.998Z',
246
+ },
247
+ ]
248
+ ```
@@ -41,6 +41,18 @@ declare enum PayableAccountType {
41
41
  Bill = "Bill",
42
42
  DebitCard = "DebitCard"
43
43
  }
44
+ declare enum PaymentStatus {
45
+ CANCELLED = "CANCELLED",
46
+ COMPLETED = "COMPLETED",
47
+ FAILED = "FAILED",
48
+ INITIALIZED = "INITIALIZED",
49
+ PENDING = "PENDING",
50
+ REFUNDED = "REFUNDED",
51
+ REVERSAL_IN_PROGRESS = "REVERSAL_IN_PROGRESS",
52
+ REVERSED = "REVERSED",
53
+ SCHEDULED = "SCHEDULED",
54
+ SENT = "SENT"
55
+ }
44
56
  interface CreateDirectPaymentInput {
45
57
  accountId: string;
46
58
  amount: number;
@@ -139,6 +151,23 @@ interface RenameBankAccount_renamePayableAccount_BankAccount {
139
151
  }
140
152
  type RenameBankAccount_renamePayableAccount = RenameBankAccount_renamePayableAccount_Bill | RenameBankAccount_renamePayableAccount_BankAccount;
141
153
 
154
+ interface AccountPayments_paymentsForAccount {
155
+ __typename: 'Payment';
156
+ id: string;
157
+ userId: any;
158
+ status: PaymentStatus;
159
+ accountId: any | null;
160
+ amount: number | null;
161
+ feeAmount: number | null;
162
+ createdAt: any;
163
+ }
164
+ interface AccountPayments {
165
+ paymentsForAccount: AccountPayments_paymentsForAccount[];
166
+ }
167
+ interface AccountPaymentsVariables {
168
+ accountId: string;
169
+ }
170
+
142
171
  interface BankAccountFragment_bankAccountDetails_CanadianBankAccountDetails {
143
172
  __typename: 'CanadianBankAccountDetails';
144
173
  }
@@ -264,6 +293,17 @@ interface PayableAccountFragment_BankAccount {
264
293
  }
265
294
  type PayableAccountFragment = PayableAccountFragment_Bill | PayableAccountFragment_BankAccount;
266
295
 
296
+ interface PaymentFragment {
297
+ __typename: 'Payment';
298
+ id: string;
299
+ userId: any;
300
+ status: PaymentStatus;
301
+ accountId: any | null;
302
+ amount: number | null;
303
+ feeAmount: number | null;
304
+ createdAt: any;
305
+ }
306
+
267
307
  interface PaymentRequestFragment {
268
308
  __typename: 'DirectPayment';
269
309
  id: string;
@@ -271,10 +311,29 @@ interface PaymentRequestFragment {
271
311
  accountId: any;
272
312
  status: DirectPaymentStatus;
273
313
  amount: number;
314
+ feeAmount: number | null;
315
+ amountDue: number;
274
316
  network: string;
275
317
  createdAt: any;
276
318
  }
277
319
 
320
+ interface PaymentRequestPayment_paymentForPaymentRequest {
321
+ __typename: 'Payment';
322
+ id: string;
323
+ userId: any;
324
+ status: PaymentStatus;
325
+ accountId: any | null;
326
+ amount: number | null;
327
+ feeAmount: number | null;
328
+ createdAt: any;
329
+ }
330
+ interface PaymentRequestPayment {
331
+ paymentForPaymentRequest: PaymentRequestPayment_paymentForPaymentRequest | null;
332
+ }
333
+ interface PaymentRequestPaymentVariables {
334
+ paymentRequestId: string;
335
+ }
336
+
278
337
  interface TokenBalanceFragment {
279
338
  __typename: 'TokenBalance';
280
339
  /**
@@ -298,6 +357,13 @@ interface TokenBalanceFragment {
298
357
  tokenImageUrl: string;
299
358
  }
300
359
 
360
+ interface TransactionPrice {
361
+ transactionPrice: number;
362
+ }
363
+ interface TransactionPriceVariables {
364
+ amount: number;
365
+ }
366
+
301
367
  interface UserBankAccounts_userBankAccounts_bankAccountDetails_CanadianBankAccountDetails {
302
368
  __typename: 'CanadianBankAccountDetails';
303
369
  }
@@ -507,7 +573,7 @@ interface QueryParams<V = any> {
507
573
  }
508
574
  declare class GraphClient {
509
575
  client: AxiosInstance;
510
- constructor(environment: Environment, apiKey: string);
576
+ constructor(environment: Environment, apiKey: string, integrationKey?: string);
511
577
  query<Q = any, V = any>({ query, variables }: QueryParams<V>): Promise<Q>;
512
578
  }
513
579
 
@@ -530,6 +596,13 @@ declare class BankAccountService {
530
596
  create<T extends BankAccountType>(type: T, input: CreateInputMapping[T]): Promise<NonNullable<CreateMutationMapping[T]["query"][keyof CreateMutationMapping[T]["query"]]> | null>;
531
597
  }
532
598
 
599
+ declare class PaymentService {
600
+ private client;
601
+ constructor(client: GraphClient);
602
+ listForAccount(accountId: string): Promise<AccountPayments_paymentsForAccount[]>;
603
+ getForPaymentRequest(paymentRequestId: string): Promise<PaymentRequestPayment_paymentForPaymentRequest | null>;
604
+ }
605
+
533
606
  interface CreatePaymentRequest_createDirectPayment {
534
607
  __typename: 'DirectPayment';
535
608
  id: string;
@@ -537,6 +610,8 @@ interface CreatePaymentRequest_createDirectPayment {
537
610
  accountId: any;
538
611
  status: DirectPaymentStatus;
539
612
  amount: number;
613
+ feeAmount: number | null;
614
+ amountDue: number;
540
615
  network: string;
541
616
  createdAt: any;
542
617
  }
@@ -559,30 +634,17 @@ interface CreatePaymentRequestInput {
559
634
  network: PaymentNetwork;
560
635
  }
561
636
 
637
+ type PaymentRequest = CreatePaymentRequest_createDirectPayment;
638
+ type Web3PaymentParams = GetSpritzPayParams_spritzPayParams;
562
639
  declare class PaymentRequestService {
563
640
  private client;
564
641
  constructor(client: GraphClient);
565
642
  create(input: CreatePaymentRequestInput): Promise<CreatePaymentRequest_createDirectPayment>;
566
- /**
567
- * Retrieves the Web3 payment parameters for a specified payment request.
568
- *
569
- * @async
570
- * @param {Object} input - The input object containing payment request details.
571
- * @param {string} input.paymentRequestId - The unique identifier for the payment request.
572
- * @param {number} input.amount - The amount to be paid in the transaction, decimals in USD (eg. 12.45)
573
- * @param {PaymentNetwork} input.network - The Ethereum network to be used for the transaction
574
- * @param {string} input.paymentTokenAddress - The Ethereum address of the ERC20 token used for payment.
575
- * @param {boolean} [validateChecksum=false] - Optional flag to validate the EIP-55 checksum of the paymentTokenAddress.
576
- * If set to true, the function will throw an error if the checksum is invalid. Default is false.
577
- * @returns {Promise<Object>} A Promise that resolves to an object containing the Web3 payment parameters.
578
- * @throws {Error} If the validateChecksum flag is true and the paymentTokenAddress has an invalid EIP-55 checksum.
579
- */
643
+ transactionPrice(paymentAmount: number): Promise<number>;
580
644
  getWeb3PaymentParams(input: {
581
- paymentRequestId: string;
582
- amount: number;
583
- network: PaymentNetwork;
645
+ paymentRequest: PaymentRequest;
584
646
  paymentTokenAddress: string;
585
- }, validateChecksum?: boolean): Promise<GetSpritzPayParams_spritzPayParams>;
647
+ }): Promise<Web3PaymentParams>;
586
648
  }
587
649
 
588
650
  declare class UserService {
@@ -592,13 +654,19 @@ declare class UserService {
592
654
  getUserVerification(): Promise<UserVerification_verification>;
593
655
  }
594
656
 
657
+ type ClientParams = {
658
+ environment: Environment;
659
+ apiKey: string;
660
+ integrationKey?: string;
661
+ };
595
662
  declare class SpritzApiClient {
596
663
  private client;
597
664
  user: UserService;
598
665
  bankAccount: BankAccountService;
599
666
  paymentRequest: PaymentRequestService;
600
- static initialize(environment: Environment, apiKey: string): SpritzApiClient;
667
+ payment: PaymentService;
668
+ static initialize({ environment, apiKey, integrationKey }: ClientParams): SpritzApiClient;
601
669
  private init;
602
670
  }
603
671
 
604
- export { 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, PaymentNetwork, PaymentRequestFragment, SpritzApiClient, TokenBalanceFragment, 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 };
672
+ 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 };