zyropai 1.0.0
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/.eslintrc.json +16 -0
- package/.github/workflows/ci.yml +26 -0
- package/.github/workflows/publish.yml +52 -0
- package/.prettierrc +7 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/client.d.ts +42 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +175 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +71 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/base.d.ts +14 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +29 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/currencies.d.ts +16 -0
- package/dist/resources/currencies.d.ts.map +1 -0
- package/dist/resources/currencies.js +38 -0
- package/dist/resources/currencies.js.map +1 -0
- package/dist/resources/custody.d.ts +50 -0
- package/dist/resources/custody.d.ts.map +1 -0
- package/dist/resources/custody.js +42 -0
- package/dist/resources/custody.js.map +1 -0
- package/dist/resources/donations.d.ts +44 -0
- package/dist/resources/donations.d.ts.map +1 -0
- package/dist/resources/donations.js +50 -0
- package/dist/resources/donations.js.map +1 -0
- package/dist/resources/index.d.ts +2 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +3 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/invoices.d.ts +15 -0
- package/dist/resources/invoices.d.ts.map +1 -0
- package/dist/resources/invoices.js +34 -0
- package/dist/resources/invoices.js.map +1 -0
- package/dist/resources/network.d.ts +21 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/network.js +18 -0
- package/dist/resources/network.js.map +1 -0
- package/dist/resources/payments.d.ts +24 -0
- package/dist/resources/payments.d.ts.map +1 -0
- package/dist/resources/payments.js +50 -0
- package/dist/resources/payments.js.map +1 -0
- package/dist/resources/payouts.d.ts +102 -0
- package/dist/resources/payouts.d.ts.map +1 -0
- package/dist/resources/payouts.js +52 -0
- package/dist/resources/payouts.js.map +1 -0
- package/dist/resources/pos.d.ts +71 -0
- package/dist/resources/pos.d.ts.map +1 -0
- package/dist/resources/pos.js +26 -0
- package/dist/resources/pos.js.map +1 -0
- package/dist/resources/rates.d.ts +26 -0
- package/dist/resources/rates.d.ts.map +1 -0
- package/dist/resources/rates.js +29 -0
- package/dist/resources/rates.js.map +1 -0
- package/dist/resources/status.d.ts +22 -0
- package/dist/resources/status.d.ts.map +1 -0
- package/dist/resources/status.js +17 -0
- package/dist/resources/status.js.map +1 -0
- package/dist/resources/timezones.d.ts +26 -0
- package/dist/resources/timezones.d.ts.map +1 -0
- package/dist/resources/timezones.js +20 -0
- package/dist/resources/timezones.js.map +1 -0
- package/dist/resources/webhooks.d.ts +8 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +30 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/helpers.d.ts +2 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +3 -0
- package/dist/utils/helpers.js.map +1 -0
- package/examples/mass-payout.js +0 -0
- package/examples/quickstart.js +0 -0
- package/examples/webhook-server.js +0 -0
- package/jest.config.js +19 -0
- package/package.json +55 -0
- package/src/client.ts +167 -0
- package/src/errors.ts +74 -0
- package/src/index.ts +8 -0
- package/src/resources/base.ts +33 -0
- package/src/resources/currencies.ts +39 -0
- package/src/resources/custody.ts +82 -0
- package/src/resources/donations.ts +84 -0
- package/src/resources/index.ts +0 -0
- package/src/resources/invoices.ts +35 -0
- package/src/resources/network.ts +26 -0
- package/src/resources/payments.ts +50 -0
- package/src/resources/payouts.ts +136 -0
- package/src/resources/pos.ts +90 -0
- package/src/resources/rates.ts +36 -0
- package/src/resources/status.ts +30 -0
- package/src/resources/timezones.ts +38 -0
- package/src/resources/webhooks.ts +28 -0
- package/src/types.ts +79 -0
- package/src/utils/helpers.ts +0 -0
- package/tests/unit/client.test.ts +0 -0
- package/tests/unit/payments.test.ts +0 -0
- package/tests/unit/webhooks.test.ts +0 -0
- package/tsconfig.json +21 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main client for ZyroPAI API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import axios, { AxiosInstance, AxiosError, AxiosRequestConfig } from 'axios';
|
|
6
|
+
import {
|
|
7
|
+
ZyroPAIError,
|
|
8
|
+
AuthenticationError,
|
|
9
|
+
RateLimitError,
|
|
10
|
+
InvalidRequestError,
|
|
11
|
+
APIError,
|
|
12
|
+
ConnectionError,
|
|
13
|
+
TimeoutError,
|
|
14
|
+
} from './errors';
|
|
15
|
+
import { ZyroPAIConfig } from './types';
|
|
16
|
+
import { PaymentsResource } from './resources/payments';
|
|
17
|
+
import { InvoicesResource } from './resources/invoices';
|
|
18
|
+
import { PayoutsResource } from './resources/payouts';
|
|
19
|
+
import { CurrenciesResource } from './resources/currencies';
|
|
20
|
+
import { CustodyResource } from './resources/custody';
|
|
21
|
+
import { RatesResource } from './resources/rates';
|
|
22
|
+
import { DonationsResource } from './resources/donations';
|
|
23
|
+
import { POSResource } from './resources/pos';
|
|
24
|
+
import { NetworkResource } from './resources/network';
|
|
25
|
+
import { StatusResource } from './resources/status';
|
|
26
|
+
import { TimezonesResource } from './resources/timezones';
|
|
27
|
+
import { WebhooksResource } from './resources/webhooks';
|
|
28
|
+
|
|
29
|
+
export class ZyroPAI {
|
|
30
|
+
public readonly payments: PaymentsResource;
|
|
31
|
+
public readonly invoices: InvoicesResource;
|
|
32
|
+
public readonly payouts: PayoutsResource;
|
|
33
|
+
public readonly currencies: CurrenciesResource;
|
|
34
|
+
public readonly custody: CustodyResource;
|
|
35
|
+
public readonly rates: RatesResource;
|
|
36
|
+
public readonly donations: DonationsResource;
|
|
37
|
+
public readonly pos: POSResource;
|
|
38
|
+
public readonly network: NetworkResource;
|
|
39
|
+
public readonly status: StatusResource;
|
|
40
|
+
public readonly timezones: TimezonesResource;
|
|
41
|
+
public readonly webhooks: WebhooksResource;
|
|
42
|
+
|
|
43
|
+
private readonly apiKey: string;
|
|
44
|
+
private readonly baseUrl: string;
|
|
45
|
+
private readonly timeout: number;
|
|
46
|
+
private readonly maxRetries: number;
|
|
47
|
+
private readonly client: AxiosInstance;
|
|
48
|
+
|
|
49
|
+
constructor(config: ZyroPAIConfig = {}) {
|
|
50
|
+
this.apiKey = config.apiKey || process.env.ZYROPAI_API_KEY || '';
|
|
51
|
+
if (!this.apiKey) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'API key is required. Pass it in config or set ZYROPAI_API_KEY environment variable.'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const mode = config.mode || 'test';
|
|
58
|
+
this.baseUrl =
|
|
59
|
+
config.baseUrl ||
|
|
60
|
+
(mode === 'test'
|
|
61
|
+
? 'https://sandbox-api.zyropai.com/api/v1'
|
|
62
|
+
: 'https://api.zyropai.com/api/v1');
|
|
63
|
+
|
|
64
|
+
this.timeout = config.timeout || 30000;
|
|
65
|
+
this.maxRetries = config.maxRetries || 3;
|
|
66
|
+
|
|
67
|
+
this.client = axios.create({
|
|
68
|
+
baseURL: this.baseUrl,
|
|
69
|
+
timeout: this.timeout,
|
|
70
|
+
headers: {
|
|
71
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
72
|
+
'Content-Type': 'application/json',
|
|
73
|
+
'User-Agent': 'ZyroPAI-Node-SDK/1.0.0',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Initialize resources
|
|
78
|
+
this.payments = new PaymentsResource(this);
|
|
79
|
+
this.invoices = new InvoicesResource(this);
|
|
80
|
+
this.payouts = new PayoutsResource(this);
|
|
81
|
+
this.currencies = new CurrenciesResource(this);
|
|
82
|
+
this.custody = new CustodyResource(this);
|
|
83
|
+
this.rates = new RatesResource(this);
|
|
84
|
+
this.donations = new DonationsResource(this);
|
|
85
|
+
this.pos = new POSResource(this);
|
|
86
|
+
this.network = new NetworkResource(this);
|
|
87
|
+
this.status = new StatusResource(this);
|
|
88
|
+
this.timezones = new TimezonesResource(this);
|
|
89
|
+
this.webhooks = new WebhooksResource(this);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async request<T = any>(method: string, path: string, data?: any, retryCount = 0): Promise<T> {
|
|
93
|
+
try {
|
|
94
|
+
const config: AxiosRequestConfig = {
|
|
95
|
+
method,
|
|
96
|
+
url: path,
|
|
97
|
+
...(data && { data }),
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const response = await this.client.request<T>(config);
|
|
101
|
+
return response.data;
|
|
102
|
+
} catch (err: unknown) {
|
|
103
|
+
// Handle Axios errors
|
|
104
|
+
if (err instanceof AxiosError) {
|
|
105
|
+
const status = err.response?.status || 0;
|
|
106
|
+
const responseData = err.response?.data as any;
|
|
107
|
+
const message = responseData?.detail || err.message;
|
|
108
|
+
const requestId = err.response?.headers?.['x-request-id'];
|
|
109
|
+
|
|
110
|
+
// Handle rate limiting
|
|
111
|
+
if (status === 429 && retryCount < this.maxRetries) {
|
|
112
|
+
const retryAfter = parseInt(err.response?.headers['retry-after'] || `${Math.pow(2, retryCount)}`);
|
|
113
|
+
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
|
|
114
|
+
return this.request(method, path, data, retryCount + 1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (status === 401) {
|
|
118
|
+
throw new AuthenticationError(message, status, responseData, requestId);
|
|
119
|
+
}
|
|
120
|
+
if (status === 429) {
|
|
121
|
+
const retryAfter = parseInt(err.response?.headers['retry-after'] || '30');
|
|
122
|
+
throw new RateLimitError(message, retryAfter, status, responseData, requestId);
|
|
123
|
+
}
|
|
124
|
+
if (status === 400) {
|
|
125
|
+
throw new InvalidRequestError(message, status, responseData, requestId);
|
|
126
|
+
}
|
|
127
|
+
if (status >= 500) {
|
|
128
|
+
throw new APIError(message, status, responseData, requestId);
|
|
129
|
+
}
|
|
130
|
+
throw new APIError(message, status, responseData, requestId);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Handle other error types with proper type checking
|
|
134
|
+
if (typeof err === 'object' && err !== null) {
|
|
135
|
+
const errorObj = err as any;
|
|
136
|
+
|
|
137
|
+
if (errorObj.code === 'ECONNABORTED') {
|
|
138
|
+
throw new TimeoutError(`Request timeout after ${this.timeout}ms`);
|
|
139
|
+
}
|
|
140
|
+
if (errorObj.code === 'ECONNREFUSED') {
|
|
141
|
+
throw new ConnectionError(`Connection refused to ${this.baseUrl}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Fallback error
|
|
146
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
147
|
+
throw new ZyroPAIError(`Request failed: ${errorMessage}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async get<T = any>(path: string): Promise<T> {
|
|
152
|
+
return this.request<T>('GET', path);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async post<T = any>(path: string, data?: any): Promise<T> {
|
|
156
|
+
return this.request<T>('POST', path, data);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async put<T = any>(path: string, data?: any): Promise<T> {
|
|
160
|
+
return this.request<T>('PUT', path, data);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async delete<T = any>(path: string): Promise<T> {
|
|
164
|
+
return this.request<T>('DELETE', path);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for ZyroPAI SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export class ZyroPAIError extends Error {
|
|
6
|
+
public readonly status?: number;
|
|
7
|
+
public readonly responseBody?: any;
|
|
8
|
+
public readonly requestId?: string;
|
|
9
|
+
|
|
10
|
+
constructor(message: string, status?: number, responseBody?: any, requestId?: string) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'ZyroPAIError';
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.responseBody = responseBody;
|
|
15
|
+
this.requestId = requestId;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class AuthenticationError extends ZyroPAIError {
|
|
20
|
+
constructor(message: string, status?: number, responseBody?: any, requestId?: string) {
|
|
21
|
+
super(message, status, responseBody, requestId);
|
|
22
|
+
this.name = 'AuthenticationError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class RateLimitError extends ZyroPAIError {
|
|
27
|
+
public readonly retryAfter?: number;
|
|
28
|
+
|
|
29
|
+
constructor(message: string, retryAfter?: number, status?: number, responseBody?: any, requestId?: string) {
|
|
30
|
+
super(message, status, responseBody, requestId);
|
|
31
|
+
this.name = 'RateLimitError';
|
|
32
|
+
this.retryAfter = retryAfter;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class InvalidRequestError extends ZyroPAIError {
|
|
37
|
+
constructor(message: string, status?: number, responseBody?: any, requestId?: string) {
|
|
38
|
+
super(message, status, responseBody, requestId);
|
|
39
|
+
this.name = 'InvalidRequestError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class APIError extends ZyroPAIError {
|
|
44
|
+
constructor(message: string, status?: number, responseBody?: any, requestId?: string) {
|
|
45
|
+
super(message, status, responseBody, requestId);
|
|
46
|
+
this.name = 'APIError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class WebhookSignatureError extends ZyroPAIError {
|
|
51
|
+
constructor(message: string) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = 'WebhookSignatureError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class ConnectionError extends ZyroPAIError {
|
|
58
|
+
constructor(message: string) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'ConnectionError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class TimeoutError extends ZyroPAIError {
|
|
65
|
+
constructor(message: string) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = 'TimeoutError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base resource class
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ZyroPAI } from '../client';
|
|
6
|
+
|
|
7
|
+
export class APIResource {
|
|
8
|
+
protected client: ZyroPAI;
|
|
9
|
+
|
|
10
|
+
constructor(client: ZyroPAI) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
protected async request<T = any>(method: string, path: string, data?: any): Promise<T> {
|
|
15
|
+
return this.client.request<T>(method, path, data);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
protected async get<T = any>(path: string): Promise<T> {
|
|
19
|
+
return this.client.get<T>(path);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected async post<T = any>(path: string, data?: any): Promise<T> {
|
|
23
|
+
return this.client.post<T>(path, data);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected async put<T = any>(path: string, data?: any): Promise<T> {
|
|
27
|
+
return this.client.put<T>(path, data);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected async delete<T = any>(path: string): Promise<T> {
|
|
31
|
+
return this.client.delete<T>(path);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currencies resource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { APIResource } from './base';
|
|
6
|
+
import { CurrenciesListParams } from '../types';
|
|
7
|
+
|
|
8
|
+
export class CurrenciesResource extends APIResource {
|
|
9
|
+
async list(params?: CurrenciesListParams): Promise<any> {
|
|
10
|
+
const queryParams = new URLSearchParams();
|
|
11
|
+
if (params?.include_rates) queryParams.append('include_rates', 'true');
|
|
12
|
+
if (params?.include_networks) queryParams.append('include_networks', 'true');
|
|
13
|
+
|
|
14
|
+
const path = `/currencies${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
15
|
+
return this.request('GET', path);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getDetails(currency: string): Promise<any> {
|
|
19
|
+
return this.request('GET', `/currencies/${currency}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getNetworks(currency: string): Promise<any> {
|
|
23
|
+
return this.request('GET', `/currencies/${currency}/networks`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getFiat(): Promise<any> {
|
|
27
|
+
return this.request('GET', '/currencies/fiat');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getSupported(params?: { category?: string; min_confirmations?: number }): Promise<any> {
|
|
31
|
+
const queryParams = new URLSearchParams();
|
|
32
|
+
if (params?.category) queryParams.append('category', params.category);
|
|
33
|
+
if (params?.min_confirmations) queryParams.append('min_confirmations', String(params.min_confirmations));
|
|
34
|
+
|
|
35
|
+
const path = `/currencies/supported${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
36
|
+
return this.request('GET', path);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custody/Wallets resource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { APIResource } from './base';
|
|
6
|
+
import { WithdrawalCreateParams } from '../types';
|
|
7
|
+
|
|
8
|
+
export interface WalletResponse {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
currency: string;
|
|
12
|
+
network: string;
|
|
13
|
+
address: string;
|
|
14
|
+
is_default: boolean;
|
|
15
|
+
settlement_preference: string;
|
|
16
|
+
created_at: string;
|
|
17
|
+
updated_at: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WalletBalanceResponse {
|
|
21
|
+
currency: string;
|
|
22
|
+
network: string;
|
|
23
|
+
balance: number;
|
|
24
|
+
balance_usd: number;
|
|
25
|
+
available_for_withdrawal: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface WithdrawalResponse {
|
|
29
|
+
id: string;
|
|
30
|
+
status: string;
|
|
31
|
+
amount: number;
|
|
32
|
+
currency: string;
|
|
33
|
+
destination_address: string;
|
|
34
|
+
created_at: string;
|
|
35
|
+
estimated_completion?: string;
|
|
36
|
+
tx_hash?: string;
|
|
37
|
+
fee_amount?: number;
|
|
38
|
+
fee_currency?: string;
|
|
39
|
+
completed_at?: string;
|
|
40
|
+
explorer_url?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class CustodyResource extends APIResource {
|
|
44
|
+
async listWallets(): Promise<WalletResponse[]> {
|
|
45
|
+
return this.request('GET', '/custody/wallets');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getBalance(walletId: string): Promise<WalletBalanceResponse> {
|
|
49
|
+
return this.request('GET', `/custody/wallets/${walletId}/balance`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async createWithdrawal(params: WithdrawalCreateParams): Promise<WithdrawalResponse> {
|
|
53
|
+
const data = {
|
|
54
|
+
amount: params.amount,
|
|
55
|
+
currency: params.currency,
|
|
56
|
+
address: params.address,
|
|
57
|
+
network: params.network || 'solana',
|
|
58
|
+
};
|
|
59
|
+
return this.request('POST', '/custody/withdrawals', data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async listWithdrawals(params?: {
|
|
63
|
+
limit?: number;
|
|
64
|
+
offset?: number;
|
|
65
|
+
status?: string;
|
|
66
|
+
currency?: string;
|
|
67
|
+
}): Promise<WithdrawalResponse[]> {
|
|
68
|
+
const queryParams = new URLSearchParams();
|
|
69
|
+
if (params?.limit) queryParams.append('limit', String(params.limit));
|
|
70
|
+
if (params?.offset) queryParams.append('offset', String(params.offset));
|
|
71
|
+
if (params?.status) queryParams.append('status', params.status);
|
|
72
|
+
if (params?.currency) queryParams.append('currency', params.currency);
|
|
73
|
+
|
|
74
|
+
const path = `/custody/withdrawals${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
75
|
+
return this.request('GET', path);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getWithdrawalStatus(withdrawalId: string): Promise<WithdrawalResponse> {
|
|
79
|
+
return this.request('GET', `/custody/withdrawals/${withdrawalId}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Donations resource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { APIResource } from './base';
|
|
6
|
+
|
|
7
|
+
export interface DonationCreateParams {
|
|
8
|
+
api_key?: string;
|
|
9
|
+
amount: number;
|
|
10
|
+
currency?: string;
|
|
11
|
+
crypto_currency?: string;
|
|
12
|
+
donor_name?: string;
|
|
13
|
+
donor_email?: string;
|
|
14
|
+
donor_phone?: string;
|
|
15
|
+
donor_social?: string;
|
|
16
|
+
donor_address?: string;
|
|
17
|
+
donor_comment?: string;
|
|
18
|
+
source?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface DonationResponse {
|
|
22
|
+
donation_id: string;
|
|
23
|
+
amount: number;
|
|
24
|
+
currency: string;
|
|
25
|
+
crypto_amount: number;
|
|
26
|
+
crypto_currency: string;
|
|
27
|
+
pay_address: string;
|
|
28
|
+
status: string;
|
|
29
|
+
expires_at: string;
|
|
30
|
+
qr_code: string;
|
|
31
|
+
created_at: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class DonationsResource extends APIResource {
|
|
35
|
+
async create(params: DonationCreateParams): Promise<DonationResponse> {
|
|
36
|
+
const data: any = {
|
|
37
|
+
api_key: params.api_key,
|
|
38
|
+
amount: params.amount,
|
|
39
|
+
currency: params.currency || 'USD',
|
|
40
|
+
crypto_currency: params.crypto_currency || 'SOL',
|
|
41
|
+
source: params.source || 'api',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (params.donor_name) data.donor_name = params.donor_name;
|
|
45
|
+
if (params.donor_email) data.donor_email = params.donor_email;
|
|
46
|
+
if (params.donor_phone) data.donor_phone = params.donor_phone;
|
|
47
|
+
if (params.donor_social) data.donor_social = params.donor_social;
|
|
48
|
+
if (params.donor_address) data.donor_address = params.donor_address;
|
|
49
|
+
if (params.donor_comment) data.donor_comment = params.donor_comment;
|
|
50
|
+
|
|
51
|
+
return this.request('POST', '/donations/create', data);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async createPublic(
|
|
55
|
+
slug: string,
|
|
56
|
+
params: Omit<DonationCreateParams, 'api_key'>
|
|
57
|
+
): Promise<DonationResponse> {
|
|
58
|
+
const data: any = {
|
|
59
|
+
amount: params.amount,
|
|
60
|
+
currency: params.currency || 'USD',
|
|
61
|
+
crypto_currency: params.crypto_currency || 'SOL',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (params.donor_name) data.donor_name = params.donor_name;
|
|
65
|
+
if (params.donor_email) data.donor_email = params.donor_email;
|
|
66
|
+
if (params.donor_comment) data.donor_comment = params.donor_comment;
|
|
67
|
+
|
|
68
|
+
return this.request('POST', `/donations/public/${slug}`, data);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getStatus(donationId: string): Promise<{
|
|
72
|
+
donation_id: string;
|
|
73
|
+
amount: number;
|
|
74
|
+
currency: string;
|
|
75
|
+
crypto_amount: number;
|
|
76
|
+
crypto_currency: string;
|
|
77
|
+
pay_address: string;
|
|
78
|
+
status: string;
|
|
79
|
+
created_at: string;
|
|
80
|
+
}> {
|
|
81
|
+
return this.request('GET', `/donations/${donationId}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invoices resource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { APIResource } from './base';
|
|
6
|
+
import { InvoiceCreateParams, InvoiceResponse } from '../types';
|
|
7
|
+
|
|
8
|
+
export class InvoicesResource extends APIResource {
|
|
9
|
+
async create(params: InvoiceCreateParams): Promise<InvoiceResponse> {
|
|
10
|
+
const data: Record<string, any> = {
|
|
11
|
+
price_amount: params.price_amount,
|
|
12
|
+
price_currency: params.price_currency || 'USD',
|
|
13
|
+
pay_currency: params.pay_currency || 'USDC',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if (params.order_id) data.order_id = params.order_id;
|
|
17
|
+
if (params.order_description) data.order_description = params.order_description;
|
|
18
|
+
if (params.customer_email) data.customer_email = params.customer_email;
|
|
19
|
+
if (params.success_url) data.success_url = params.success_url;
|
|
20
|
+
if (params.cancel_url) data.cancel_url = params.cancel_url;
|
|
21
|
+
if (params.metadata) data.metadata = params.metadata;
|
|
22
|
+
|
|
23
|
+
return this.request('POST', '/invoice', data);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async retrieve(invoiceId: string): Promise<InvoiceResponse & {
|
|
27
|
+
order_id?: string;
|
|
28
|
+
order_description?: string;
|
|
29
|
+
success_url?: string;
|
|
30
|
+
cancel_url?: string;
|
|
31
|
+
}> {
|
|
32
|
+
return this.request('GET', `/invoice/${invoiceId}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network Fees resource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { APIResource } from './base';
|
|
6
|
+
|
|
7
|
+
export interface NetworkFeeResponse {
|
|
8
|
+
network: string;
|
|
9
|
+
currency: string;
|
|
10
|
+
native_fee: number;
|
|
11
|
+
native_fee_currency: string;
|
|
12
|
+
fee: number;
|
|
13
|
+
fee_currency: string;
|
|
14
|
+
fee_usd: number;
|
|
15
|
+
updated_at: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class NetworkResource extends APIResource {
|
|
19
|
+
async getFee(params: { network: string; currency?: string }): Promise<NetworkFeeResponse> {
|
|
20
|
+
const queryParams = new URLSearchParams({
|
|
21
|
+
network: params.network,
|
|
22
|
+
currency: params.currency || 'SOL',
|
|
23
|
+
});
|
|
24
|
+
return this.request('GET', `/network-fee?${queryParams.toString()}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payments resource
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { APIResource } from './base';
|
|
6
|
+
import { PaymentCreateParams, PaymentResponse } from '../types';
|
|
7
|
+
|
|
8
|
+
export class PaymentsResource extends APIResource {
|
|
9
|
+
async create(params: PaymentCreateParams): Promise<PaymentResponse> {
|
|
10
|
+
const data: Record<string, any> = {
|
|
11
|
+
price_amount: params.price_amount,
|
|
12
|
+
price_currency: params.price_currency || 'USD',
|
|
13
|
+
pay_currency: params.pay_currency || 'USDC',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if (params.order_id) data.order_id = params.order_id;
|
|
17
|
+
if (params.order_description) data.order_description = params.order_description;
|
|
18
|
+
if (params.customer_email) data.customer_email = params.customer_email;
|
|
19
|
+
if (params.ipn_callback_url) data.ipn_callback_url = params.ipn_callback_url;
|
|
20
|
+
if (params.success_url) data.success_url = params.success_url;
|
|
21
|
+
if (params.cancel_url) data.cancel_url = params.cancel_url;
|
|
22
|
+
if (params.metadata) data.metadata = params.metadata;
|
|
23
|
+
|
|
24
|
+
return this.request('POST', '/payments', data);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async retrieve(paymentId: string): Promise<PaymentResponse> {
|
|
28
|
+
return this.request('GET', `/payments/${paymentId}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async list(params?: { limit?: number; page?: number; status?: string }): Promise<{
|
|
32
|
+
payments: PaymentResponse[];
|
|
33
|
+
total: number;
|
|
34
|
+
limit: number;
|
|
35
|
+
offset: number;
|
|
36
|
+
}> {
|
|
37
|
+
const queryParams = new URLSearchParams();
|
|
38
|
+
if (params?.limit) queryParams.append('limit', String(params.limit));
|
|
39
|
+
if (params?.page) queryParams.append('page', String(params.page));
|
|
40
|
+
if (params?.status) queryParams.append('status', params.status);
|
|
41
|
+
|
|
42
|
+
const path = `/payments${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
|
43
|
+
return this.request('GET', path);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async cancel(paymentId: string): Promise<{ success: boolean; message: string }> {
|
|
47
|
+
return this.request('POST', `/payments/${paymentId}/cancel`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|