@spritz-finance/api-client 0.0.4 → 0.0.5

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
@@ -28,8 +28,12 @@ const client = SpritzApiClient.initialize(Environment.Staging, 'YOUR_API_KEY_HER
28
28
 
29
29
  ## Bank Accounts
30
30
 
31
+ 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.
32
+
31
33
  ### List user bank accounts
32
34
 
35
+ You can retrieve a comprehensive list of all bank accounts that have been linked to a user's account using this functionality.
36
+
33
37
  ```typescript
34
38
  const bankAccounts = await client.bankAccounts.list()
35
39
  ```
@@ -40,33 +44,37 @@ The bank accounts endpoint returns a standard response comprising an array of al
40
44
 
41
45
  ```typescript
42
46
  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",
47
+ id: "62d17d3b377dab6c1342136e",
48
+ name: "Precious Savings",
49
+ type: "BankAccount",
50
+ bankAccountType: "USBankAccount",
51
+ bankAccountSubType: "Checking",
52
+ userId: "62d17d3b377dab6c1342136e",
53
+ accountNumber: "1234567",
54
+ bankAccountDetails: {
55
+ routingNumber: "00000123",
56
+ }
57
+ country: "US",
58
+ currency: "USD",
59
+ email: "bilbo@shiremail.net",
60
+ holder: "Bilbo Baggins",
61
+ institution: {
62
+ id: "62d27d4b277dab3c1342126e",
63
+ name: "Shire Bank",
64
+ logo: "https://tinyurl.com/shire-bank-logo",
65
+ },
66
+ ownedByUser: true,
67
+ createdAt: "2023-05-03T11:25:02.401Z",
64
68
  }];
65
69
  ```
66
70
 
67
71
  ### Add US bank account
68
72
 
73
+ 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.
74
+
69
75
  ```typescript
76
+ // Input arguments for creating a US bank account
77
+
70
78
  export interface USBankAccountInput {
71
79
  accountNumber: string
72
80
  email: string
@@ -94,12 +102,144 @@ const bankAccounts = await client.bankAccounts.create(BankAccountType.USBankAcco
94
102
 
95
103
  ### Rename a bank account
96
104
 
105
+ 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.
106
+
97
107
  ```typescript
98
108
  const updateAccount = await client.bankAccounts.rename('62d17d3b377dab6c1342136e', 'My new account')
99
109
  ```
100
110
 
101
111
  ### Delete a bank account
102
112
 
113
+ 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.
114
+
103
115
  ```typescript
104
116
  await client.bankAccounts.delete('62d17d3b377dab6c1342136e')
105
117
  ```
118
+
119
+ ## Payment Requests
120
+
121
+ 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.
122
+
123
+ ### Create a payment request
124
+
125
+ 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.
126
+
127
+ ```typescript
128
+ import {PaymentNetwork} from '@spritz-finance/api-client';
129
+
130
+ const paymentRequest = await client.paymentRequest.create({
131
+ amount: 100,
132
+ accountId: account.id,
133
+ network: PaymentNetwork.Ethereum,
134
+ });
135
+
136
+ // Example response
137
+
138
+ {
139
+ id: '645399c8c1ac408007b12273',
140
+ userId: '63d12d3B577fab6c6382136e',
141
+ accountId: '6322445f10d3f4d19c4d72fe',
142
+ status: 'CREATED',
143
+ amount: 100,
144
+ feeAmount: 0,
145
+ amountDue: 100,
146
+ network: 'ethereum',
147
+ createdAt: '2023-05-04T11:40:56.488Z'
148
+ }
149
+ ```
150
+
151
+ ### Fulfil a payment request (EVM transactions)
152
+
153
+ 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)).
154
+
155
+ To obtain the data needed for the transaction, you can use the following endpoint.
156
+
157
+ ```typescript
158
+ import {PaymentNetwork} from '@spritz-finance/api-client';
159
+
160
+ const paymentRequest = await client.paymentRequest.create({
161
+ amount: 100,
162
+ accountId: account.id,
163
+ network: PaymentNetwork.Ethereum,
164
+ });
165
+
166
+ const transactionData = await client.paymentRequest.getWeb3PaymentParams({
167
+ paymentRequest,
168
+ paymentTokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC on mainnet
169
+ })
170
+
171
+ // Example response
172
+
173
+ {
174
+ contractAddress: '0xbF7Abc15f00a8C2d6b13A952c58d12b7c194A8D0',
175
+ method: 'payWithToken',
176
+ calldata: '0xd71d9632000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000064539a31c1ac408007b12277',
177
+ value: null,
178
+ requiredTokenInput: '100000000',
179
+ suggestedGasLimit: '110000'
180
+ }
181
+ ```
182
+
183
+ 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.
184
+
185
+ ### Transaction fees
186
+
187
+ 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.
188
+
189
+ ```typescript
190
+ const fees = await client.paymentRequest.transactionPrice(101)
191
+
192
+ // Example response
193
+ 0.01
194
+ ```
195
+
196
+ ## Payments
197
+
198
+ 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.
199
+
200
+ ### Retrieve the payment for a payment request
201
+
202
+ ```typescript
203
+ import {PaymentNetwork} from '@spritz-finance/api-client';
204
+
205
+ const paymentRequest = await client.paymentRequest.create({
206
+ amount: 100,
207
+ accountId: account.id,
208
+ network: PaymentNetwork.Ethereum,
209
+ });
210
+
211
+ const payment = await client.payment.getForPaymentRequest(paymentRequest.id);
212
+
213
+ // Example response
214
+
215
+ {
216
+ id: '6368e3a3ec516e9572bbd23b',
217
+ userId: '63d12d3B577fab6c6382136e',
218
+ status: 'PENDING',
219
+ accountId: '6322445f10d3f4d19c4d72fe',
220
+ amount: 100,
221
+ feeAmount: null,
222
+ createdAt: '2022-11-07T10:53:23.998Z'
223
+ }
224
+
225
+ ```
226
+
227
+ ### Retrieve all payments for an account
228
+
229
+ ```typescript
230
+ const payments = await client.payment.listForAccount(account.id)
231
+
232
+ // Example response
233
+
234
+ ;[
235
+ {
236
+ id: '6368e3a3ec516e9572bbd23b',
237
+ userId: '63d12d3B577fab6c6382136e',
238
+ status: 'PENDING',
239
+ accountId: '6322445f10d3f4d19c4d72fe',
240
+ amount: 100,
241
+ feeAmount: null,
242
+ createdAt: '2022-11-07T10:53:23.998Z',
243
+ },
244
+ ]
245
+ ```
@@ -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 };