@profullstack/coinpay 0.2.0 → 0.3.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/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +686 -323
- package/bin/coinpay.js +2 -2
- package/package.json +29 -12
- package/src/client.d.ts +266 -0
- package/src/client.js +1 -1
- package/src/index.d.ts +37 -0
- package/src/payments.d.ts +153 -0
- package/src/payments.js +4 -4
- package/src/webhooks.d.ts +134 -0
package/bin/coinpay.js
CHANGED
|
@@ -154,7 +154,7 @@ ${colors.cyan}Options:${colors.reset}
|
|
|
154
154
|
--business-id <id> Business ID for operations
|
|
155
155
|
--amount <amount> Payment amount in fiat currency
|
|
156
156
|
--currency <code> Fiat currency (USD, EUR, etc.) - default: USD
|
|
157
|
-
--blockchain <code> Blockchain (BTC, ETH, SOL,
|
|
157
|
+
--blockchain <code> Blockchain (BTC, ETH, SOL, POL, BCH, USDC_ETH, USDC_POL, USDC_SOL)
|
|
158
158
|
--description <text> Payment description
|
|
159
159
|
|
|
160
160
|
${colors.cyan}Examples:${colors.reset}
|
|
@@ -168,7 +168,7 @@ ${colors.cyan}Examples:${colors.reset}
|
|
|
168
168
|
coinpay payment create --business-id biz_123 --amount 50 --blockchain ETH --description "Order #12345"
|
|
169
169
|
|
|
170
170
|
# Create a USDC payment on Polygon
|
|
171
|
-
coinpay payment create --business-id biz_123 --amount 25 --blockchain
|
|
171
|
+
coinpay payment create --business-id biz_123 --amount 25 --blockchain USDC_POL
|
|
172
172
|
|
|
173
173
|
# Get payment status
|
|
174
174
|
coinpay payment get pay_abc123
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/coinpay",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "CoinPay SDK & CLI
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "CoinPay SDK & CLI — Accept cryptocurrency payments (BTC, ETH, SOL, POL, BCH, USDC) in your Node.js application",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
7
8
|
"bin": {
|
|
8
9
|
"coinpay": "./bin/coinpay.js"
|
|
9
10
|
},
|
|
@@ -24,22 +25,44 @@
|
|
|
24
25
|
"files": [
|
|
25
26
|
"src",
|
|
26
27
|
"bin",
|
|
27
|
-
"README.md"
|
|
28
|
+
"README.md",
|
|
29
|
+
"CHANGELOG.md",
|
|
30
|
+
"LICENSE"
|
|
28
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"lint": "eslint src bin test",
|
|
36
|
+
"format": "prettier --write src bin test",
|
|
37
|
+
"prepublishOnly": "npm run test && npm run lint"
|
|
38
|
+
},
|
|
29
39
|
"keywords": [
|
|
30
40
|
"coinpay",
|
|
31
41
|
"profullstack",
|
|
32
42
|
"cryptocurrency",
|
|
43
|
+
"crypto",
|
|
33
44
|
"payments",
|
|
34
45
|
"bitcoin",
|
|
35
46
|
"ethereum",
|
|
36
47
|
"solana",
|
|
37
48
|
"polygon",
|
|
49
|
+
"usdc",
|
|
50
|
+
"stablecoin",
|
|
51
|
+
"non-custodial",
|
|
52
|
+
"wallet",
|
|
38
53
|
"sdk",
|
|
39
|
-
"cli"
|
|
54
|
+
"cli",
|
|
55
|
+
"web3",
|
|
56
|
+
"blockchain",
|
|
57
|
+
"payment-gateway",
|
|
58
|
+
"merchant"
|
|
40
59
|
],
|
|
41
60
|
"author": "Profullstack, Inc.",
|
|
42
61
|
"license": "MIT",
|
|
62
|
+
"homepage": "https://coinpayportal.com",
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/profullstack/coinpayportal/issues"
|
|
65
|
+
},
|
|
43
66
|
"repository": {
|
|
44
67
|
"type": "git",
|
|
45
68
|
"url": "https://github.com/profullstack/coinpayportal.git",
|
|
@@ -54,11 +77,5 @@
|
|
|
54
77
|
"prettier": "^3.4.1"
|
|
55
78
|
},
|
|
56
79
|
"peerDependencies": {},
|
|
57
|
-
"dependencies": {}
|
|
58
|
-
|
|
59
|
-
"test": "vitest run",
|
|
60
|
-
"test:watch": "vitest",
|
|
61
|
-
"lint": "eslint src bin test",
|
|
62
|
-
"format": "prettier --write src bin test"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
80
|
+
"dependencies": {}
|
|
81
|
+
}
|
package/src/client.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CoinPay API Client
|
|
3
|
+
* Main client class for interacting with the CoinPay API
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Options for constructing a CoinPayClient */
|
|
7
|
+
export interface CoinPayClientOptions {
|
|
8
|
+
/** Your CoinPay API key (starts with `cp_live_` or `cp_test_`) */
|
|
9
|
+
apiKey: string;
|
|
10
|
+
/** API base URL (default: `https://coinpayportal.com/api`) */
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
/** Request timeout in milliseconds (default: `30000`) */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Parameters for creating a payment */
|
|
17
|
+
export interface PaymentParams {
|
|
18
|
+
/** Business ID from your CoinPay dashboard */
|
|
19
|
+
businessId: string;
|
|
20
|
+
/** Amount in fiat currency (e.g., `100.00`) */
|
|
21
|
+
amount: number;
|
|
22
|
+
/** Fiat currency code (default: `'USD'`) */
|
|
23
|
+
currency?: string;
|
|
24
|
+
/** Blockchain/cryptocurrency code: `BTC`, `ETH`, `SOL`, `POL`, `BCH`, `USDC_ETH`, `USDC_POL`, `USDC_SOL` */
|
|
25
|
+
blockchain: string;
|
|
26
|
+
/** Payment description shown to the customer */
|
|
27
|
+
description?: string;
|
|
28
|
+
/** Custom metadata attached to the payment (e.g., `{ orderId: 'ORD-123' }`) */
|
|
29
|
+
metadata?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Parameters for listing payments */
|
|
33
|
+
export interface ListPaymentsParams {
|
|
34
|
+
/** Business ID */
|
|
35
|
+
businessId: string;
|
|
36
|
+
/** Filter by payment status */
|
|
37
|
+
status?: string;
|
|
38
|
+
/** Number of results to return (default: `20`) */
|
|
39
|
+
limit?: number;
|
|
40
|
+
/** Pagination offset (default: `0`) */
|
|
41
|
+
offset?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Options for the `waitForPayment` polling method */
|
|
45
|
+
export interface WaitForPaymentOptions {
|
|
46
|
+
/** Polling interval in milliseconds (default: `5000`) */
|
|
47
|
+
interval?: number;
|
|
48
|
+
/** Maximum wait time in milliseconds (default: `3600000` — 1 hour) */
|
|
49
|
+
timeout?: number;
|
|
50
|
+
/** Payment statuses that stop polling (default: `['confirmed', 'forwarded', 'expired', 'failed']`) */
|
|
51
|
+
targetStatuses?: string[];
|
|
52
|
+
/** Callback invoked when the payment status changes */
|
|
53
|
+
onStatusChange?: (status: string, payment: Record<string, unknown>) => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Parameters for creating a business */
|
|
57
|
+
export interface CreateBusinessParams {
|
|
58
|
+
/** Business name */
|
|
59
|
+
name: string;
|
|
60
|
+
/** Webhook URL for payment notifications */
|
|
61
|
+
webhookUrl?: string;
|
|
62
|
+
/** Wallet addresses keyed by blockchain code */
|
|
63
|
+
walletAddresses?: Record<string, string>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Generic API response envelope */
|
|
67
|
+
export interface ApiResponse<T = Record<string, unknown>> {
|
|
68
|
+
success: boolean;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Payment object returned by the API */
|
|
73
|
+
export interface Payment {
|
|
74
|
+
id: string;
|
|
75
|
+
business_id: string;
|
|
76
|
+
amount: number;
|
|
77
|
+
currency: string;
|
|
78
|
+
blockchain: string;
|
|
79
|
+
crypto_amount: string;
|
|
80
|
+
payment_address: string;
|
|
81
|
+
qr_code?: string;
|
|
82
|
+
status: string;
|
|
83
|
+
tx_hash?: string;
|
|
84
|
+
expires_at?: string;
|
|
85
|
+
created_at: string;
|
|
86
|
+
metadata?: Record<string, unknown>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Response from payment creation */
|
|
90
|
+
export interface CreatePaymentResponse {
|
|
91
|
+
success: boolean;
|
|
92
|
+
payment: Payment;
|
|
93
|
+
usage?: {
|
|
94
|
+
current: number;
|
|
95
|
+
limit: number;
|
|
96
|
+
remaining: number;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Response from getting a single payment */
|
|
101
|
+
export interface GetPaymentResponse {
|
|
102
|
+
success: boolean;
|
|
103
|
+
payment: Payment;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Response from listing payments */
|
|
107
|
+
export interface ListPaymentsResponse {
|
|
108
|
+
success: boolean;
|
|
109
|
+
payments: Payment[];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* CoinPay API Client
|
|
114
|
+
*
|
|
115
|
+
* The primary class for interacting with the CoinPay payment API.
|
|
116
|
+
* Handles authentication, request signing, and provides methods
|
|
117
|
+
* for all API operations.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { CoinPayClient } from '@profullstack/coinpay';
|
|
122
|
+
*
|
|
123
|
+
* const client = new CoinPayClient({ apiKey: 'cp_live_xxxxx' });
|
|
124
|
+
*
|
|
125
|
+
* const payment = await client.createPayment({
|
|
126
|
+
* businessId: 'biz_123',
|
|
127
|
+
* amount: 99.99,
|
|
128
|
+
* blockchain: 'BTC',
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export class CoinPayClient {
|
|
133
|
+
/**
|
|
134
|
+
* Create a new CoinPay client
|
|
135
|
+
* @throws {Error} If `apiKey` is not provided
|
|
136
|
+
*/
|
|
137
|
+
constructor(options: CoinPayClientOptions);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Make an authenticated API request.
|
|
141
|
+
*
|
|
142
|
+
* Automatically adds `Authorization: Bearer <apiKey>` and `Content-Type: application/json` headers.
|
|
143
|
+
* Handles timeouts via `AbortController`.
|
|
144
|
+
*
|
|
145
|
+
* @param endpoint - API endpoint path (e.g., `/payments/create`)
|
|
146
|
+
* @param options - Standard `fetch` options (method, body, headers, etc.)
|
|
147
|
+
* @returns Parsed JSON response
|
|
148
|
+
* @throws {Error} On HTTP errors (non-2xx) or timeout
|
|
149
|
+
*/
|
|
150
|
+
request(endpoint: string, options?: RequestInit): Promise<Record<string, unknown>>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Create a new payment request.
|
|
154
|
+
*
|
|
155
|
+
* Generates a unique blockchain address and optional QR code for the customer to pay.
|
|
156
|
+
*
|
|
157
|
+
* @returns Created payment with `payment_address`, `crypto_amount`, and `qr_code`
|
|
158
|
+
*/
|
|
159
|
+
createPayment(params: PaymentParams): Promise<CreatePaymentResponse>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get payment details by ID.
|
|
163
|
+
*
|
|
164
|
+
* @param paymentId - Payment ID (e.g., `'pay_abc123'`)
|
|
165
|
+
* @returns Payment details including current status
|
|
166
|
+
*/
|
|
167
|
+
getPayment(paymentId: string): Promise<GetPaymentResponse>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Poll until a payment reaches a terminal status.
|
|
171
|
+
*
|
|
172
|
+
* Terminal statuses: `confirmed`, `forwarded`, `expired`, `failed`.
|
|
173
|
+
* For production, prefer webhooks over polling.
|
|
174
|
+
*
|
|
175
|
+
* @param paymentId - Payment ID
|
|
176
|
+
* @param options - Polling configuration
|
|
177
|
+
* @returns Final payment details
|
|
178
|
+
* @throws {Error} If timeout is reached before a terminal status
|
|
179
|
+
*/
|
|
180
|
+
waitForPayment(paymentId: string, options?: WaitForPaymentOptions): Promise<GetPaymentResponse>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* List payments for a business.
|
|
184
|
+
*
|
|
185
|
+
* @returns Paginated list of payments
|
|
186
|
+
*/
|
|
187
|
+
listPayments(params: ListPaymentsParams): Promise<ListPaymentsResponse>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get a URL pointing to the QR code image for a payment.
|
|
191
|
+
*
|
|
192
|
+
* The URL returns binary PNG data suitable for `<img src="...">`.
|
|
193
|
+
* This method is synchronous — it does not make a network request.
|
|
194
|
+
*
|
|
195
|
+
* @param paymentId - Payment ID
|
|
196
|
+
* @returns Full URL to the QR code PNG endpoint
|
|
197
|
+
*/
|
|
198
|
+
getPaymentQRUrl(paymentId: string): string;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Fetch the QR code image as binary data.
|
|
202
|
+
*
|
|
203
|
+
* @param paymentId - Payment ID
|
|
204
|
+
* @returns QR code PNG image as an `ArrayBuffer`
|
|
205
|
+
*/
|
|
206
|
+
getPaymentQR(paymentId: string): Promise<ArrayBuffer>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get the exchange rate for a cryptocurrency.
|
|
210
|
+
*
|
|
211
|
+
* @param cryptocurrency - Crypto code (e.g., `'BTC'`, `'ETH'`)
|
|
212
|
+
* @param fiatCurrency - Fiat code (default: `'USD'`)
|
|
213
|
+
*/
|
|
214
|
+
getExchangeRate(cryptocurrency: string, fiatCurrency?: string): Promise<Record<string, unknown>>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Get exchange rates for multiple cryptocurrencies in a single request.
|
|
218
|
+
*
|
|
219
|
+
* @param cryptocurrencies - Array of crypto codes
|
|
220
|
+
* @param fiatCurrency - Fiat code (default: `'USD'`)
|
|
221
|
+
*/
|
|
222
|
+
getExchangeRates(cryptocurrencies: string[], fiatCurrency?: string): Promise<Record<string, unknown>>;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Get business details.
|
|
226
|
+
*
|
|
227
|
+
* @param businessId - Business ID
|
|
228
|
+
*/
|
|
229
|
+
getBusiness(businessId: string): Promise<Record<string, unknown>>;
|
|
230
|
+
|
|
231
|
+
/** List all businesses associated with your API key. */
|
|
232
|
+
listBusinesses(): Promise<Record<string, unknown>>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Create a new business.
|
|
236
|
+
*
|
|
237
|
+
* @param params - Business creation parameters
|
|
238
|
+
*/
|
|
239
|
+
createBusiness(params: CreateBusinessParams): Promise<Record<string, unknown>>;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Update an existing business.
|
|
243
|
+
*
|
|
244
|
+
* @param businessId - Business ID
|
|
245
|
+
* @param params - Fields to update
|
|
246
|
+
*/
|
|
247
|
+
updateBusiness(businessId: string, params: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get webhook delivery logs for a business.
|
|
251
|
+
*
|
|
252
|
+
* @param businessId - Business ID
|
|
253
|
+
* @param limit - Number of log entries (default: `50`)
|
|
254
|
+
*/
|
|
255
|
+
getWebhookLogs(businessId: string, limit?: number): Promise<Record<string, unknown>>;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Send a test webhook event to your configured endpoint.
|
|
259
|
+
*
|
|
260
|
+
* @param businessId - Business ID
|
|
261
|
+
* @param eventType - Event type to simulate (default: `'payment.completed'`)
|
|
262
|
+
*/
|
|
263
|
+
testWebhook(businessId: string, eventType?: string): Promise<Record<string, unknown>>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export default CoinPayClient;
|
package/src/client.js
CHANGED
|
@@ -83,7 +83,7 @@ export class CoinPayClient {
|
|
|
83
83
|
* @param {string} params.businessId - Business ID (from your CoinPay dashboard)
|
|
84
84
|
* @param {number} params.amount - Amount in fiat currency (e.g., 100.00)
|
|
85
85
|
* @param {string} [params.currency='USD'] - Fiat currency code (USD, EUR, etc.)
|
|
86
|
-
* @param {string} params.blockchain - Blockchain/cryptocurrency (BTC, ETH, SOL,
|
|
86
|
+
* @param {string} params.blockchain - Blockchain/cryptocurrency (BTC, ETH, SOL, POL, BCH, USDC_ETH, USDC_POL, USDC_SOL)
|
|
87
87
|
* @param {string} [params.description] - Payment description (shown to customer)
|
|
88
88
|
* @param {Object} [params.metadata] - Custom metadata (e.g., { orderId: 'ORD-123', customerId: 'CUST-456' })
|
|
89
89
|
* @returns {Promise<Object>} Created payment with address and QR code
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @profullstack/coinpay - CoinPay SDK
|
|
3
|
+
* Cryptocurrency payment integration for Node.js
|
|
4
|
+
*
|
|
5
|
+
* @module @profullstack/coinpay
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { CoinPayClient } from './client.js';
|
|
9
|
+
export type { CoinPayClientOptions, PaymentParams, ListPaymentsParams, WaitForPaymentOptions, CreateBusinessParams } from './client.js';
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
createPayment,
|
|
13
|
+
getPayment,
|
|
14
|
+
listPayments,
|
|
15
|
+
Blockchain,
|
|
16
|
+
Cryptocurrency,
|
|
17
|
+
PaymentStatus,
|
|
18
|
+
FiatCurrency,
|
|
19
|
+
} from './payments.js';
|
|
20
|
+
export type { CreatePaymentParams, GetPaymentParams, ListPaymentsFnParams } from './payments.js';
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
verifyWebhookSignature,
|
|
24
|
+
generateWebhookSignature,
|
|
25
|
+
parseWebhookPayload,
|
|
26
|
+
createWebhookHandler,
|
|
27
|
+
WebhookEvent,
|
|
28
|
+
} from './webhooks.js';
|
|
29
|
+
export type {
|
|
30
|
+
VerifyWebhookParams,
|
|
31
|
+
GenerateWebhookParams,
|
|
32
|
+
WebhookHandlerOptions,
|
|
33
|
+
ParsedWebhookEvent,
|
|
34
|
+
} from './webhooks.js';
|
|
35
|
+
|
|
36
|
+
import { CoinPayClient } from './client.js';
|
|
37
|
+
export default CoinPayClient;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment utilities for CoinPay SDK
|
|
3
|
+
*
|
|
4
|
+
* Standalone functions for creating and managing payments without
|
|
5
|
+
* manually instantiating a `CoinPayClient`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { CoinPayClient } from './client.js';
|
|
9
|
+
|
|
10
|
+
/** Parameters for the standalone `createPayment` function */
|
|
11
|
+
export interface CreatePaymentParams {
|
|
12
|
+
/** API key — required if `client` is not provided */
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
/** Existing CoinPayClient instance (takes precedence over `apiKey`) */
|
|
15
|
+
client?: CoinPayClient;
|
|
16
|
+
/** Business ID from your CoinPay dashboard */
|
|
17
|
+
businessId: string;
|
|
18
|
+
/** Amount in fiat currency */
|
|
19
|
+
amount: number;
|
|
20
|
+
/** Fiat currency code (default: `'USD'`) */
|
|
21
|
+
currency?: string;
|
|
22
|
+
/** Blockchain code: `BTC`, `ETH`, `SOL`, `POL`, `BCH`, `USDC_ETH`, `USDC_POL`, `USDC_SOL` */
|
|
23
|
+
blockchain: string;
|
|
24
|
+
/** Payment description shown to the customer */
|
|
25
|
+
description?: string;
|
|
26
|
+
/** Custom metadata for your records */
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Parameters for the standalone `getPayment` function */
|
|
31
|
+
export interface GetPaymentParams {
|
|
32
|
+
/** API key — required if `client` is not provided */
|
|
33
|
+
apiKey?: string;
|
|
34
|
+
/** Existing CoinPayClient instance */
|
|
35
|
+
client?: CoinPayClient;
|
|
36
|
+
/** Payment ID to look up */
|
|
37
|
+
paymentId: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Parameters for the standalone `listPayments` function */
|
|
41
|
+
export interface ListPaymentsFnParams {
|
|
42
|
+
/** API key — required if `client` is not provided */
|
|
43
|
+
apiKey?: string;
|
|
44
|
+
/** Existing CoinPayClient instance */
|
|
45
|
+
client?: CoinPayClient;
|
|
46
|
+
/** Business ID */
|
|
47
|
+
businessId: string;
|
|
48
|
+
/** Filter by payment status */
|
|
49
|
+
status?: string;
|
|
50
|
+
/** Number of results (default: `20`) */
|
|
51
|
+
limit?: number;
|
|
52
|
+
/** Pagination offset */
|
|
53
|
+
offset?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create a payment using an API key or existing client.
|
|
58
|
+
*
|
|
59
|
+
* Convenience wrapper — for multiple operations, prefer creating a
|
|
60
|
+
* `CoinPayClient` instance and reusing it.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import { createPayment, Blockchain } from '@profullstack/coinpay';
|
|
65
|
+
*
|
|
66
|
+
* const result = await createPayment({
|
|
67
|
+
* apiKey: 'cp_live_xxxxx',
|
|
68
|
+
* businessId: 'biz_123',
|
|
69
|
+
* amount: 50,
|
|
70
|
+
* blockchain: Blockchain.BTC,
|
|
71
|
+
* });
|
|
72
|
+
* console.log(result.payment.payment_address);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function createPayment(params: CreatePaymentParams): Promise<Record<string, unknown>>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get a payment by ID.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const result = await getPayment({
|
|
83
|
+
* apiKey: 'cp_live_xxxxx',
|
|
84
|
+
* paymentId: 'pay_abc123',
|
|
85
|
+
* });
|
|
86
|
+
* console.log(result.payment.status);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export function getPayment(params: GetPaymentParams): Promise<Record<string, unknown>>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* List payments for a business.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const result = await listPayments({
|
|
97
|
+
* apiKey: 'cp_live_xxxxx',
|
|
98
|
+
* businessId: 'biz_123',
|
|
99
|
+
* status: 'completed',
|
|
100
|
+
* limit: 10,
|
|
101
|
+
* });
|
|
102
|
+
* console.log(result.payments);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function listPayments(params: ListPaymentsFnParams): Promise<Record<string, unknown>>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Supported blockchains/cryptocurrencies.
|
|
109
|
+
*
|
|
110
|
+
* Use these constants when creating payments to avoid typos.
|
|
111
|
+
*/
|
|
112
|
+
export declare const Blockchain: {
|
|
113
|
+
/** Bitcoin */
|
|
114
|
+
readonly BTC: 'BTC';
|
|
115
|
+
/** Bitcoin Cash */
|
|
116
|
+
readonly BCH: 'BCH';
|
|
117
|
+
/** Ethereum */
|
|
118
|
+
readonly ETH: 'ETH';
|
|
119
|
+
/** Polygon (POL) */
|
|
120
|
+
readonly POL: 'POL';
|
|
121
|
+
/** Solana */
|
|
122
|
+
readonly SOL: 'SOL';
|
|
123
|
+
/** USDC on Ethereum */
|
|
124
|
+
readonly USDC_ETH: 'USDC_ETH';
|
|
125
|
+
/** USDC on Polygon */
|
|
126
|
+
readonly USDC_POL: 'USDC_POL';
|
|
127
|
+
/** USDC on Solana */
|
|
128
|
+
readonly USDC_SOL: 'USDC_SOL';
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated Use `Blockchain` instead.
|
|
133
|
+
*/
|
|
134
|
+
export declare const Cryptocurrency: typeof Blockchain;
|
|
135
|
+
|
|
136
|
+
/** Payment status constants */
|
|
137
|
+
export declare const PaymentStatus: {
|
|
138
|
+
readonly PENDING: 'pending';
|
|
139
|
+
readonly CONFIRMING: 'confirming';
|
|
140
|
+
readonly COMPLETED: 'completed';
|
|
141
|
+
readonly EXPIRED: 'expired';
|
|
142
|
+
readonly FAILED: 'failed';
|
|
143
|
+
readonly REFUNDED: 'refunded';
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** Supported fiat currencies */
|
|
147
|
+
export declare const FiatCurrency: {
|
|
148
|
+
readonly USD: 'USD';
|
|
149
|
+
readonly EUR: 'EUR';
|
|
150
|
+
readonly GBP: 'GBP';
|
|
151
|
+
readonly CAD: 'CAD';
|
|
152
|
+
readonly AUD: 'AUD';
|
|
153
|
+
};
|
package/src/payments.js
CHANGED
|
@@ -31,7 +31,7 @@ import { CoinPayClient } from './client.js';
|
|
|
31
31
|
* @param {string} params.businessId - Business ID from your CoinPay dashboard
|
|
32
32
|
* @param {number} params.amount - Amount in fiat currency (e.g., 100.00)
|
|
33
33
|
* @param {string} [params.currency='USD'] - Fiat currency code (USD, EUR, etc.)
|
|
34
|
-
* @param {string} params.blockchain - Blockchain to use (BTC, ETH, SOL,
|
|
34
|
+
* @param {string} params.blockchain - Blockchain to use (BTC, ETH, SOL, POL, BCH, USDC_ETH, USDC_POL, USDC_SOL)
|
|
35
35
|
* @param {string} [params.description] - Payment description shown to customer
|
|
36
36
|
* @param {Object} [params.metadata] - Custom metadata for your records
|
|
37
37
|
* @returns {Promise<Object>} Created payment with address and QR code
|
|
@@ -143,14 +143,14 @@ export const Blockchain = {
|
|
|
143
143
|
BCH: 'BCH',
|
|
144
144
|
/** Ethereum */
|
|
145
145
|
ETH: 'ETH',
|
|
146
|
-
/** Polygon (
|
|
147
|
-
|
|
146
|
+
/** Polygon (POL) */
|
|
147
|
+
POL: 'POL',
|
|
148
148
|
/** Solana */
|
|
149
149
|
SOL: 'SOL',
|
|
150
150
|
/** USDC on Ethereum */
|
|
151
151
|
USDC_ETH: 'USDC_ETH',
|
|
152
152
|
/** USDC on Polygon */
|
|
153
|
-
|
|
153
|
+
USDC_POL: 'USDC_POL',
|
|
154
154
|
/** USDC on Solana */
|
|
155
155
|
USDC_SOL: 'USDC_SOL',
|
|
156
156
|
};
|