swapped-commerce-sdk 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/LICENSE +21 -0
- package/README.md +948 -0
- package/package.json +68 -0
- package/src/client/createClient.ts +182 -0
- package/src/index.ts +29 -0
- package/src/resources/balances.ts +39 -0
- package/src/resources/kyc.ts +39 -0
- package/src/resources/orders.ts +54 -0
- package/src/resources/paymentLinks.ts +24 -0
- package/src/resources/paymentRoutes.ts +24 -0
- package/src/resources/payments.ts +20 -0
- package/src/resources/payouts.ts +58 -0
- package/src/resources/quotes.ts +24 -0
- package/src/types/balances.ts +27 -0
- package/src/types/common.ts +46 -0
- package/src/types/currencies.ts +26 -0
- package/src/types/index.ts +93 -0
- package/src/types/kyc.ts +65 -0
- package/src/types/orders.ts +122 -0
- package/src/types/payments.ts +115 -0
- package/src/types/payouts.ts +68 -0
- package/src/types/quotes.ts +49 -0
- package/src/types/webhooks.ts +31 -0
- package/src/utils/errors.ts +104 -0
- package/src/utils/http.ts +180 -0
- package/src/utils/retry.ts +57 -0
- package/src/utils/webhooks.ts +82 -0
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "swapped-commerce-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for Swapped Commerce Integration API - Functional, performant, and fully typed",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"module": "src/index.ts",
|
|
8
|
+
"types": "src/index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.ts",
|
|
12
|
+
"import": "./src/index.ts",
|
|
13
|
+
"default": "./src/index.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
18
|
+
"test": "bun test",
|
|
19
|
+
"test:watch": "bun test --watch",
|
|
20
|
+
"test:coverage": "bun test --coverage",
|
|
21
|
+
"test:unit": "bun test tests/unit",
|
|
22
|
+
"test:integration": "bun test tests/integration",
|
|
23
|
+
"benchmark": "bun run scripts/run-benchmarks.ts",
|
|
24
|
+
"benchmark:test": "bun test benchmarks/performance.test.ts",
|
|
25
|
+
"lint": "bunx biome check src",
|
|
26
|
+
"lint:fix": "bunx biome check --write src",
|
|
27
|
+
"format": "bunx biome format --write src"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"swapped",
|
|
31
|
+
"commerce",
|
|
32
|
+
"crypto",
|
|
33
|
+
"payment",
|
|
34
|
+
"gateway",
|
|
35
|
+
"cryptocurrency",
|
|
36
|
+
"bitcoin",
|
|
37
|
+
"ethereum",
|
|
38
|
+
"sdk",
|
|
39
|
+
"typescript"
|
|
40
|
+
],
|
|
41
|
+
"author": {
|
|
42
|
+
"name": "xpriori",
|
|
43
|
+
"url": "https://github.com/phtn"
|
|
44
|
+
},
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/bun": "latest"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"typescript": "^5"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"src",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
],
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/phtn/swapped-commerce-sdk.git"
|
|
60
|
+
},
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/phtn/swapped-commerce-sdk/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/phtn/swapped-commerce-sdk#readme",
|
|
65
|
+
"engines": {
|
|
66
|
+
"bun": ">=1.0.0"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SwappedConfig,
|
|
3
|
+
RequiredSwappedConfig,
|
|
4
|
+
HttpConfig,
|
|
5
|
+
ApiResponse,
|
|
6
|
+
Order,
|
|
7
|
+
ListOrdersParams,
|
|
8
|
+
OrdersResponse,
|
|
9
|
+
RefundParams,
|
|
10
|
+
RefundResponse,
|
|
11
|
+
CreateLinkParams,
|
|
12
|
+
PaymentLinkResponse,
|
|
13
|
+
CreateRouteParams,
|
|
14
|
+
PaymentRouteResponse,
|
|
15
|
+
Payment,
|
|
16
|
+
Balance,
|
|
17
|
+
ListBalancesParams,
|
|
18
|
+
BalancesResponse,
|
|
19
|
+
GetQuoteParams,
|
|
20
|
+
QuoteResponse,
|
|
21
|
+
Payout,
|
|
22
|
+
CreatePayoutParams,
|
|
23
|
+
CreatePayoutResponse,
|
|
24
|
+
PaginationParams,
|
|
25
|
+
PayoutsResponse,
|
|
26
|
+
KYCStatusResponse,
|
|
27
|
+
SubmitKYCParams,
|
|
28
|
+
SubmitKYCResponse,
|
|
29
|
+
WebhookEvent,
|
|
30
|
+
} from '../types'
|
|
31
|
+
import * as ordersResource from '../resources/orders'
|
|
32
|
+
import * as paymentLinksResource from '../resources/paymentLinks'
|
|
33
|
+
import * as paymentRoutesResource from '../resources/paymentRoutes'
|
|
34
|
+
import * as paymentsResource from '../resources/payments'
|
|
35
|
+
import * as balancesResource from '../resources/balances'
|
|
36
|
+
import * as quotesResource from '../resources/quotes'
|
|
37
|
+
import * as payoutsResource from '../resources/payouts'
|
|
38
|
+
import * as kycResource from '../resources/kyc'
|
|
39
|
+
import { verifyWebhookSignature, parseWebhookEvent } from '../utils/webhooks'
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Swapped Commerce Client interface
|
|
43
|
+
*/
|
|
44
|
+
export interface SwappedClient {
|
|
45
|
+
readonly orders: {
|
|
46
|
+
readonly list: (
|
|
47
|
+
params?: Readonly<ListOrdersParams>
|
|
48
|
+
) => Promise<ApiResponse<OrdersResponse>>
|
|
49
|
+
readonly get: (orderId: string) => Promise<ApiResponse<Order>>
|
|
50
|
+
readonly refund: (
|
|
51
|
+
orderId: string,
|
|
52
|
+
params: Readonly<RefundParams>
|
|
53
|
+
) => Promise<ApiResponse<RefundResponse>>
|
|
54
|
+
}
|
|
55
|
+
readonly paymentLinks: {
|
|
56
|
+
readonly create: (
|
|
57
|
+
params: Readonly<CreateLinkParams>
|
|
58
|
+
) => Promise<ApiResponse<PaymentLinkResponse>>
|
|
59
|
+
}
|
|
60
|
+
readonly paymentRoutes: {
|
|
61
|
+
readonly create: (
|
|
62
|
+
params: Readonly<CreateRouteParams>
|
|
63
|
+
) => Promise<ApiResponse<PaymentRouteResponse>>
|
|
64
|
+
}
|
|
65
|
+
readonly payments: {
|
|
66
|
+
readonly get: (paymentId: string) => Promise<ApiResponse<Payment>>
|
|
67
|
+
}
|
|
68
|
+
readonly balances: {
|
|
69
|
+
readonly list: (
|
|
70
|
+
params?: Readonly<ListBalancesParams>
|
|
71
|
+
) => Promise<ApiResponse<BalancesResponse>>
|
|
72
|
+
readonly get: (currencyId: string) => Promise<ApiResponse<Balance>>
|
|
73
|
+
}
|
|
74
|
+
readonly quotes: {
|
|
75
|
+
readonly get: (
|
|
76
|
+
params: Readonly<GetQuoteParams>
|
|
77
|
+
) => Promise<ApiResponse<QuoteResponse>>
|
|
78
|
+
}
|
|
79
|
+
readonly payouts: {
|
|
80
|
+
readonly create: (
|
|
81
|
+
params: Readonly<CreatePayoutParams>
|
|
82
|
+
) => Promise<ApiResponse<CreatePayoutResponse>>
|
|
83
|
+
readonly list: (
|
|
84
|
+
params?: Readonly<PaginationParams>
|
|
85
|
+
) => Promise<ApiResponse<PayoutsResponse>>
|
|
86
|
+
readonly get: (payoutId: string) => Promise<ApiResponse<Payout>>
|
|
87
|
+
}
|
|
88
|
+
readonly kyc: {
|
|
89
|
+
readonly getStatus: (
|
|
90
|
+
customerId: string
|
|
91
|
+
) => Promise<ApiResponse<KYCStatusResponse>>
|
|
92
|
+
readonly submit: (
|
|
93
|
+
params: Readonly<SubmitKYCParams>
|
|
94
|
+
) => Promise<ApiResponse<SubmitKYCResponse>>
|
|
95
|
+
}
|
|
96
|
+
readonly verifyWebhookSignature: (
|
|
97
|
+
payload: string,
|
|
98
|
+
signature: string,
|
|
99
|
+
secret: string
|
|
100
|
+
) => Promise<boolean>
|
|
101
|
+
readonly parseWebhookEvent: (payload: string) => WebhookEvent
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Default configuration values
|
|
106
|
+
*/
|
|
107
|
+
const DEFAULT_CONFIG: Omit<RequiredSwappedConfig, 'apiKey'> = {
|
|
108
|
+
environment: 'production',
|
|
109
|
+
timeout: 30000,
|
|
110
|
+
retries: 3,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Base URL for Swapped Commerce API
|
|
115
|
+
*/
|
|
116
|
+
const BASE_URL = 'https://pay-api.swapped.com'
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Factory function to create a Swapped Commerce client
|
|
120
|
+
*
|
|
121
|
+
* @param config - Client configuration
|
|
122
|
+
* @returns Swapped Commerce client instance
|
|
123
|
+
*/
|
|
124
|
+
export function createClient(config: SwappedConfig): SwappedClient {
|
|
125
|
+
const requiredConfig: RequiredSwappedConfig = {
|
|
126
|
+
...DEFAULT_CONFIG,
|
|
127
|
+
...config,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const httpConfig: HttpConfig = {
|
|
131
|
+
config: requiredConfig,
|
|
132
|
+
baseUrl: BASE_URL,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
orders: {
|
|
137
|
+
list: (params?: Readonly<ListOrdersParams>) =>
|
|
138
|
+
ordersResource.listOrders(httpConfig, params),
|
|
139
|
+
get: (orderId: string) => ordersResource.getOrder(httpConfig, orderId),
|
|
140
|
+
refund: (orderId: string, params: Readonly<RefundParams>) =>
|
|
141
|
+
ordersResource.refundOrder(httpConfig, orderId, params),
|
|
142
|
+
},
|
|
143
|
+
paymentLinks: {
|
|
144
|
+
create: (params: Readonly<CreateLinkParams>) =>
|
|
145
|
+
paymentLinksResource.createPaymentLink(httpConfig, params),
|
|
146
|
+
},
|
|
147
|
+
paymentRoutes: {
|
|
148
|
+
create: (params: Readonly<CreateRouteParams>) =>
|
|
149
|
+
paymentRoutesResource.createPaymentRoute(httpConfig, params),
|
|
150
|
+
},
|
|
151
|
+
payments: {
|
|
152
|
+
get: (paymentId: string) =>
|
|
153
|
+
paymentsResource.getPayment(httpConfig, paymentId),
|
|
154
|
+
},
|
|
155
|
+
balances: {
|
|
156
|
+
list: (params?: Readonly<ListBalancesParams>) =>
|
|
157
|
+
balancesResource.listBalances(httpConfig, params),
|
|
158
|
+
get: (currencyId: string) =>
|
|
159
|
+
balancesResource.getBalance(httpConfig, currencyId),
|
|
160
|
+
},
|
|
161
|
+
quotes: {
|
|
162
|
+
get: (params: Readonly<GetQuoteParams>) =>
|
|
163
|
+
quotesResource.getQuote(httpConfig, params),
|
|
164
|
+
},
|
|
165
|
+
payouts: {
|
|
166
|
+
create: (params: Readonly<CreatePayoutParams>) =>
|
|
167
|
+
payoutsResource.createPayout(httpConfig, params),
|
|
168
|
+
list: (params?: Readonly<PaginationParams>) =>
|
|
169
|
+
payoutsResource.listPayouts(httpConfig, params),
|
|
170
|
+
get: (payoutId: string) =>
|
|
171
|
+
payoutsResource.getPayout(httpConfig, payoutId),
|
|
172
|
+
},
|
|
173
|
+
kyc: {
|
|
174
|
+
getStatus: (customerId: string) =>
|
|
175
|
+
kycResource.getKYCStatus(httpConfig, customerId),
|
|
176
|
+
submit: (params: Readonly<SubmitKYCParams>) =>
|
|
177
|
+
kycResource.submitKYC(httpConfig, params),
|
|
178
|
+
},
|
|
179
|
+
verifyWebhookSignature,
|
|
180
|
+
parseWebhookEvent,
|
|
181
|
+
}
|
|
182
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swapped Commerce SDK - Main Export
|
|
3
|
+
*
|
|
4
|
+
* A performant, functional TypeScript SDK for the Swapped Commerce API.
|
|
5
|
+
* Built with Bun-native patterns, pure functions, and strict typing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Client factory
|
|
9
|
+
export { createClient } from './client/createClient'
|
|
10
|
+
export type { SwappedClient } from './client/createClient'
|
|
11
|
+
|
|
12
|
+
// Types
|
|
13
|
+
export * from './types'
|
|
14
|
+
|
|
15
|
+
// Error classes
|
|
16
|
+
export {
|
|
17
|
+
SwappedError,
|
|
18
|
+
SwappedAuthenticationError,
|
|
19
|
+
SwappedValidationError,
|
|
20
|
+
SwappedRateLimitError,
|
|
21
|
+
SwappedNotFoundError,
|
|
22
|
+
createAuthenticationError,
|
|
23
|
+
createValidationError,
|
|
24
|
+
createRateLimitError,
|
|
25
|
+
createNotFoundError,
|
|
26
|
+
} from './utils/errors'
|
|
27
|
+
|
|
28
|
+
// Webhook utilities
|
|
29
|
+
export { verifyWebhookSignature, parseWebhookEvent } from './utils/webhooks'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
Balance,
|
|
5
|
+
ListBalancesParams,
|
|
6
|
+
BalancesResponse,
|
|
7
|
+
} from '../types'
|
|
8
|
+
import { request } from '../utils/http'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* List balances with optional filtering
|
|
12
|
+
*/
|
|
13
|
+
export async function listBalances(
|
|
14
|
+
httpConfig: HttpConfig,
|
|
15
|
+
params?: Readonly<ListBalancesParams>
|
|
16
|
+
): Promise<ApiResponse<BalancesResponse>> {
|
|
17
|
+
return request<BalancesResponse>(
|
|
18
|
+
httpConfig.config,
|
|
19
|
+
'GET',
|
|
20
|
+
'/v1/merchants/balances',
|
|
21
|
+
{
|
|
22
|
+
params,
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get balance for a specific currency
|
|
29
|
+
*/
|
|
30
|
+
export async function getBalance(
|
|
31
|
+
httpConfig: HttpConfig,
|
|
32
|
+
currencyId: string
|
|
33
|
+
): Promise<ApiResponse<Balance>> {
|
|
34
|
+
return request<Balance>(
|
|
35
|
+
httpConfig.config,
|
|
36
|
+
'GET',
|
|
37
|
+
`/v1/merchants/balances/${encodeURIComponent(currencyId)}`
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
KYCStatusResponse,
|
|
5
|
+
SubmitKYCParams,
|
|
6
|
+
SubmitKYCResponse,
|
|
7
|
+
} from '../types'
|
|
8
|
+
import { request } from '../utils/http'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get KYC status for a customer
|
|
12
|
+
*/
|
|
13
|
+
export async function getKYCStatus(
|
|
14
|
+
httpConfig: HttpConfig,
|
|
15
|
+
customerId: string
|
|
16
|
+
): Promise<ApiResponse<KYCStatusResponse>> {
|
|
17
|
+
return request<KYCStatusResponse>(
|
|
18
|
+
httpConfig.config,
|
|
19
|
+
'GET',
|
|
20
|
+
`/v1/merchants/kyc/${encodeURIComponent(customerId)}`
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Submit KYC information for a customer
|
|
26
|
+
*/
|
|
27
|
+
export async function submitKYC(
|
|
28
|
+
httpConfig: HttpConfig,
|
|
29
|
+
params: Readonly<SubmitKYCParams>
|
|
30
|
+
): Promise<ApiResponse<SubmitKYCResponse>> {
|
|
31
|
+
return request<SubmitKYCResponse>(
|
|
32
|
+
httpConfig.config,
|
|
33
|
+
'POST',
|
|
34
|
+
'/v1/merchants/kyc',
|
|
35
|
+
{
|
|
36
|
+
body: params,
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
Order,
|
|
5
|
+
ListOrdersParams,
|
|
6
|
+
OrdersResponse,
|
|
7
|
+
RefundParams,
|
|
8
|
+
RefundResponse,
|
|
9
|
+
} from '../types'
|
|
10
|
+
import { request } from '../utils/http'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* List orders with optional filtering and pagination
|
|
14
|
+
*/
|
|
15
|
+
export async function listOrders(
|
|
16
|
+
httpConfig: HttpConfig,
|
|
17
|
+
params?: Readonly<ListOrdersParams>
|
|
18
|
+
): Promise<ApiResponse<OrdersResponse>> {
|
|
19
|
+
return request<OrdersResponse>(httpConfig.config, 'GET', '/v1/merchants/orders', {
|
|
20
|
+
params,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get a single order by ID
|
|
26
|
+
*/
|
|
27
|
+
export async function getOrder(
|
|
28
|
+
httpConfig: HttpConfig,
|
|
29
|
+
orderId: string
|
|
30
|
+
): Promise<ApiResponse<Order>> {
|
|
31
|
+
return request<Order>(
|
|
32
|
+
httpConfig.config,
|
|
33
|
+
'GET',
|
|
34
|
+
`/v1/merchants/orders/${encodeURIComponent(orderId)}`
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Refund an order
|
|
40
|
+
*/
|
|
41
|
+
export async function refundOrder(
|
|
42
|
+
httpConfig: HttpConfig,
|
|
43
|
+
orderId: string,
|
|
44
|
+
params: Readonly<RefundParams>
|
|
45
|
+
): Promise<ApiResponse<RefundResponse>> {
|
|
46
|
+
return request<RefundResponse>(
|
|
47
|
+
httpConfig.config,
|
|
48
|
+
'POST',
|
|
49
|
+
`/v1/merchants/orders/${encodeURIComponent(orderId)}/refund`,
|
|
50
|
+
{
|
|
51
|
+
body: params,
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
CreateLinkParams,
|
|
5
|
+
PaymentLinkResponse,
|
|
6
|
+
} from '../types'
|
|
7
|
+
import { request } from '../utils/http'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a payment link
|
|
11
|
+
*/
|
|
12
|
+
export async function createPaymentLink(
|
|
13
|
+
httpConfig: HttpConfig,
|
|
14
|
+
params: Readonly<CreateLinkParams>
|
|
15
|
+
): Promise<ApiResponse<PaymentLinkResponse>> {
|
|
16
|
+
return request<PaymentLinkResponse>(
|
|
17
|
+
httpConfig.config,
|
|
18
|
+
'POST',
|
|
19
|
+
'/v1/orders',
|
|
20
|
+
{
|
|
21
|
+
body: params,
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
CreateRouteParams,
|
|
5
|
+
PaymentRouteResponse,
|
|
6
|
+
} from '../types'
|
|
7
|
+
import { request } from '../utils/http'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a payment route
|
|
11
|
+
*/
|
|
12
|
+
export async function createPaymentRoute(
|
|
13
|
+
httpConfig: HttpConfig,
|
|
14
|
+
params: Readonly<CreateRouteParams>
|
|
15
|
+
): Promise<ApiResponse<PaymentRouteResponse>> {
|
|
16
|
+
return request<PaymentRouteResponse>(
|
|
17
|
+
httpConfig.config,
|
|
18
|
+
'POST',
|
|
19
|
+
'/v1/merchants/payment-routes',
|
|
20
|
+
{
|
|
21
|
+
body: params,
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
Payment,
|
|
5
|
+
} from '../types'
|
|
6
|
+
import { request } from '../utils/http'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get payment information by ID
|
|
10
|
+
*/
|
|
11
|
+
export async function getPayment(
|
|
12
|
+
httpConfig: HttpConfig,
|
|
13
|
+
paymentId: string
|
|
14
|
+
): Promise<ApiResponse<Payment>> {
|
|
15
|
+
return request<Payment>(
|
|
16
|
+
httpConfig.config,
|
|
17
|
+
'GET',
|
|
18
|
+
`/v1/merchants/payments/${encodeURIComponent(paymentId)}`
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
Payout,
|
|
5
|
+
CreatePayoutParams,
|
|
6
|
+
CreatePayoutResponse,
|
|
7
|
+
PaginationParams,
|
|
8
|
+
PayoutsResponse,
|
|
9
|
+
} from '../types'
|
|
10
|
+
import { request } from '../utils/http'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a payout
|
|
14
|
+
*/
|
|
15
|
+
export async function createPayout(
|
|
16
|
+
httpConfig: HttpConfig,
|
|
17
|
+
params: Readonly<CreatePayoutParams>
|
|
18
|
+
): Promise<ApiResponse<CreatePayoutResponse>> {
|
|
19
|
+
return request<CreatePayoutResponse>(
|
|
20
|
+
httpConfig.config,
|
|
21
|
+
'POST',
|
|
22
|
+
'/v1/merchants/payouts',
|
|
23
|
+
{
|
|
24
|
+
body: params,
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* List payouts with pagination
|
|
31
|
+
*/
|
|
32
|
+
export async function listPayouts(
|
|
33
|
+
httpConfig: HttpConfig,
|
|
34
|
+
params?: Readonly<PaginationParams>
|
|
35
|
+
): Promise<ApiResponse<PayoutsResponse>> {
|
|
36
|
+
return request<PayoutsResponse>(
|
|
37
|
+
httpConfig.config,
|
|
38
|
+
'GET',
|
|
39
|
+
'/v1/merchants/payouts',
|
|
40
|
+
{
|
|
41
|
+
params,
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get a single payout by ID
|
|
48
|
+
*/
|
|
49
|
+
export async function getPayout(
|
|
50
|
+
httpConfig: HttpConfig,
|
|
51
|
+
payoutId: string
|
|
52
|
+
): Promise<ApiResponse<Payout>> {
|
|
53
|
+
return request<Payout>(
|
|
54
|
+
httpConfig.config,
|
|
55
|
+
'GET',
|
|
56
|
+
`/v1/merchants/payouts/${encodeURIComponent(payoutId)}`
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpConfig,
|
|
3
|
+
ApiResponse,
|
|
4
|
+
GetQuoteParams,
|
|
5
|
+
QuoteResponse,
|
|
6
|
+
} from '../types'
|
|
7
|
+
import { request } from '../utils/http'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get a quote for currency conversion
|
|
11
|
+
*/
|
|
12
|
+
export async function getQuote(
|
|
13
|
+
httpConfig: HttpConfig,
|
|
14
|
+
params: Readonly<GetQuoteParams>
|
|
15
|
+
): Promise<ApiResponse<QuoteResponse>> {
|
|
16
|
+
return request<QuoteResponse>(
|
|
17
|
+
httpConfig.config,
|
|
18
|
+
'POST',
|
|
19
|
+
'/v1/merchants/quotes',
|
|
20
|
+
{
|
|
21
|
+
body: params,
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Currency } from './currencies'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Balance information
|
|
5
|
+
*/
|
|
6
|
+
export interface Balance {
|
|
7
|
+
readonly currency: Currency
|
|
8
|
+
readonly available: string
|
|
9
|
+
readonly pending: string
|
|
10
|
+
readonly total: string
|
|
11
|
+
readonly lastUpdated: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parameters for listing balances
|
|
16
|
+
*/
|
|
17
|
+
export interface ListBalancesParams {
|
|
18
|
+
readonly currency?: string
|
|
19
|
+
readonly blockchain?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Response for listing balances
|
|
24
|
+
*/
|
|
25
|
+
export interface BalancesResponse {
|
|
26
|
+
readonly balances: readonly Balance[]
|
|
27
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core configuration types
|
|
3
|
+
*/
|
|
4
|
+
export interface SwappedConfig {
|
|
5
|
+
readonly apiKey: string
|
|
6
|
+
readonly environment?: 'sandbox' | 'production'
|
|
7
|
+
readonly timeout?: number
|
|
8
|
+
readonly retries?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type RequiredSwappedConfig = Required<SwappedConfig>
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* API Response wrapper
|
|
15
|
+
*/
|
|
16
|
+
export interface ApiResponse<T> {
|
|
17
|
+
readonly data: T
|
|
18
|
+
readonly message: string
|
|
19
|
+
readonly success: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Pagination parameters
|
|
24
|
+
*/
|
|
25
|
+
export interface PaginationParams {
|
|
26
|
+
readonly page?: number
|
|
27
|
+
readonly limit?: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Pagination response
|
|
32
|
+
*/
|
|
33
|
+
export interface PaginationResponse {
|
|
34
|
+
readonly currentPage: number
|
|
35
|
+
readonly totalPages: number
|
|
36
|
+
readonly totalItems: number
|
|
37
|
+
readonly itemsPerPage: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* HTTP configuration for resource functions
|
|
42
|
+
*/
|
|
43
|
+
export interface HttpConfig {
|
|
44
|
+
readonly config: RequiredSwappedConfig
|
|
45
|
+
readonly baseUrl: string
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency and blockchain types
|
|
3
|
+
*/
|
|
4
|
+
export type CurrencyType = 'FIAT' | 'CRYPTO'
|
|
5
|
+
|
|
6
|
+
export type CurrencyFlow = 'PAYMENT' | 'SETTLEMENT' | 'BOTH'
|
|
7
|
+
|
|
8
|
+
export interface Blockchain {
|
|
9
|
+
readonly id: string
|
|
10
|
+
readonly name: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Currency {
|
|
14
|
+
readonly id: string
|
|
15
|
+
readonly symbol: string
|
|
16
|
+
readonly name: string
|
|
17
|
+
readonly officialId: string
|
|
18
|
+
readonly type: CurrencyType
|
|
19
|
+
readonly precision: number
|
|
20
|
+
readonly flows: readonly CurrencyFlow[]
|
|
21
|
+
readonly blockchain?: Blockchain
|
|
22
|
+
readonly blockchainId?: string
|
|
23
|
+
readonly isStablecoin?: boolean
|
|
24
|
+
readonly decimals?: number
|
|
25
|
+
readonly isNative?: boolean
|
|
26
|
+
}
|