@100pay-hq/100pay.js 1.2.0 → 1.2.2
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.md +21 -0
- package/README.md +177 -111
- package/dist/index.cjs +31 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -3
- package/dist/index.d.ts +70 -3
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 100Pay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
|
-
# 100Pay
|
|
1
|
+
# 100Pay SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<!--
|
|
6
|
-
## ✋ ✋ PACKAGE HAS BEEN DISCONTINUED
|
|
7
|
-
## Please 👉 [click here](https://npmjs.com/@100pay-hq/checkout) for the updated package 📦 -->
|
|
8
|
-
|
|
9
|
-
## Getting Started
|
|
10
|
-
|
|
11
|
-
Before you can start accepting crypto payments, you need to create a [100pay account](https://100pay.co) and obtain your API keys from the [100Developers platform](https://100pay.co)
|
|
12
|
-
|
|
13
|
-
For API documentation, please click here 👉 [100Developers API documentation](https://documenter.getpostman.com/view/13045730/2s93RMUatE)
|
|
3
|
+
A TypeScript library for integrating with the 100Pay payment platform, enabling developers to easily accept cryptocurrency payments.
|
|
14
4
|
|
|
15
5
|
## Features
|
|
16
6
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
- ✅ Verify cryptocurrency payments
|
|
8
|
+
- ✅ Create and manage subaccounts
|
|
9
|
+
- ✅ Make cryptocurrency transfers
|
|
10
|
+
- ✅ Full TypeScript support with comprehensive typing
|
|
11
|
+
- ✅ Secure server-to-server communication with request signing
|
|
21
12
|
|
|
22
13
|
## Installation
|
|
23
14
|
|
|
24
|
-
Install the package using npm:
|
|
25
|
-
|
|
26
15
|
```bash
|
|
27
16
|
npm install @100pay-hq/100pay.js
|
|
28
17
|
```
|
|
@@ -33,36 +22,21 @@ Or using yarn:
|
|
|
33
22
|
yarn add @100pay-hq/100pay.js
|
|
34
23
|
```
|
|
35
24
|
|
|
36
|
-
##
|
|
37
|
-
|
|
38
|
-
This package is fully written in TypeScript and includes type definitions. No additional type packages are required.
|
|
39
|
-
|
|
40
|
-
## Breaking Changes from JavaScript Version
|
|
41
|
-
|
|
42
|
-
The TypeScript version includes some breaking changes from the original JavaScript version:
|
|
43
|
-
|
|
44
|
-
1. The SDK now uses `axios` instead of `request` for HTTP requests
|
|
45
|
-
2. Proper error handling with typed errors (`PaymentVerificationError`)
|
|
46
|
-
3. Stricter type checking for method parameters and return values
|
|
47
|
-
4. Constructor now requires an object with `publicKey` and `secretKey` properties
|
|
48
|
-
|
|
49
|
-
## Usage
|
|
50
|
-
|
|
51
|
-
### TypeScript
|
|
25
|
+
## Quick Start
|
|
52
26
|
|
|
53
27
|
```typescript
|
|
54
|
-
import {
|
|
28
|
+
import { Pay100 } from '@100pay-hq/100pay.js';
|
|
55
29
|
|
|
56
30
|
// Initialize the 100Pay client
|
|
57
|
-
const
|
|
31
|
+
const client = new Pay100({
|
|
58
32
|
publicKey: 'your_public_key',
|
|
59
33
|
secretKey: 'your_secret_key'
|
|
60
34
|
});
|
|
61
35
|
|
|
62
36
|
// Verify a transaction
|
|
63
|
-
async function verifyTransaction(transactionId
|
|
37
|
+
async function verifyTransaction(transactionId) {
|
|
64
38
|
try {
|
|
65
|
-
const result = await
|
|
39
|
+
const result = await client.verify(transactionId);
|
|
66
40
|
|
|
67
41
|
if (result.status === 'success') {
|
|
68
42
|
console.log('Transaction verified:', result.data);
|
|
@@ -72,117 +46,209 @@ async function verifyTransaction(transactionId: string) {
|
|
|
72
46
|
return null;
|
|
73
47
|
}
|
|
74
48
|
} catch (error) {
|
|
75
|
-
|
|
76
|
-
console.error('Error:', error.message);
|
|
77
|
-
}
|
|
49
|
+
console.error('Error:', error.message);
|
|
78
50
|
throw error;
|
|
79
51
|
}
|
|
80
52
|
}
|
|
81
53
|
```
|
|
82
54
|
|
|
83
|
-
|
|
55
|
+
## API Reference
|
|
84
56
|
|
|
85
|
-
|
|
86
|
-
const { _100Pay } = require('@100pay-hq/100pay.js');
|
|
57
|
+
### Initialization
|
|
87
58
|
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
publicKey:
|
|
91
|
-
secretKey
|
|
59
|
+
```typescript
|
|
60
|
+
const client = new Pay100({
|
|
61
|
+
publicKey: string, // Your 100Pay public API key (required)
|
|
62
|
+
secretKey?: string, // Your 100Pay secret API key (required for server-side operations)
|
|
63
|
+
baseUrl?: string // Optional custom API base URL
|
|
92
64
|
});
|
|
65
|
+
```
|
|
93
66
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
67
|
+
### Transaction Verification
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Verify a crypto payment transaction
|
|
71
|
+
const result = await client.verify(transactionId);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Parameters:**
|
|
75
|
+
|
|
76
|
+
| Parameter | Type | Description |
|
|
77
|
+
|-----------|------|-------------|
|
|
78
|
+
| transactionId | string | The unique ID of the transaction to verify |
|
|
79
|
+
|
|
80
|
+
**Returns:**
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
interface IVerifyResponse {
|
|
84
|
+
status: "success" | "error";
|
|
85
|
+
data: ITransactionData | Record<string, never>;
|
|
86
|
+
message?: string;
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Example:**
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
try {
|
|
94
|
+
const result = await client.verify("tx_123456789");
|
|
95
|
+
|
|
96
|
+
if (result.status === 'success') {
|
|
97
|
+
// Payment is valid
|
|
98
|
+
const { amount, currency, status } = result.data;
|
|
99
|
+
// Process order fulfillment
|
|
100
|
+
} else {
|
|
101
|
+
// Payment verification failed
|
|
102
|
+
console.error(result.message);
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
// Handle verification error
|
|
106
|
+
if (error instanceof PaymentVerificationError) {
|
|
107
|
+
console.error(`Payment verification failed: ${error.message}`);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
```
|
|
112
111
|
|
|
113
|
-
|
|
112
|
+
### Subaccounts
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
Subaccounts allow you to create and manage separate accounts under your main account.
|
|
116
115
|
|
|
117
116
|
```typescript
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
// Create a subaccount
|
|
118
|
+
const subaccount = await client.subaccounts.create({
|
|
119
|
+
name: "Partner Store",
|
|
120
|
+
email: "partner@example.com",
|
|
121
|
+
// Additional properties as needed
|
|
122
|
+
});
|
|
122
123
|
```
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
**Parameters:**
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
interface CreateSubAccountData {
|
|
129
|
+
name: string;
|
|
130
|
+
email: string;
|
|
131
|
+
// Additional properties defined in types
|
|
132
|
+
}
|
|
133
|
+
```
|
|
128
134
|
|
|
129
|
-
|
|
135
|
+
**Returns:**
|
|
130
136
|
|
|
131
|
-
|
|
137
|
+
```typescript
|
|
138
|
+
interface CreateSubAccountResponse {
|
|
139
|
+
status: string;
|
|
140
|
+
message: string;
|
|
141
|
+
data: {
|
|
142
|
+
// Subaccount properties
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
```
|
|
132
146
|
|
|
133
|
-
|
|
147
|
+
### Generic API Requests
|
|
134
148
|
|
|
135
|
-
|
|
136
|
-
|-----------|------|-------------|
|
|
137
|
-
| transactionId | string | The ID of the transaction to verify |
|
|
149
|
+
The SDK provides a generic `request` method for making any API call to the 100Pay API:
|
|
138
150
|
|
|
139
|
-
|
|
151
|
+
```typescript
|
|
152
|
+
const response = await client.request<ResponseType>(
|
|
153
|
+
method, // 'GET', 'POST', 'PUT', or 'DELETE'
|
|
154
|
+
endpoint, // API endpoint path
|
|
155
|
+
data // Request payload
|
|
156
|
+
);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Error Handling
|
|
160
|
+
|
|
161
|
+
The SDK provides typed error handling:
|
|
140
162
|
|
|
141
163
|
```typescript
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
164
|
+
try {
|
|
165
|
+
const result = await client.verify(transactionId);
|
|
166
|
+
// Process result
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error instanceof PaymentVerificationError) {
|
|
169
|
+
// Handle payment verification specific error
|
|
170
|
+
console.error(`Payment verification failed: ${error.message}`);
|
|
171
|
+
} else if (error instanceof Error) {
|
|
172
|
+
// Handle general error
|
|
173
|
+
console.error(`API error: ${error.message}`);
|
|
174
|
+
}
|
|
146
175
|
}
|
|
147
176
|
```
|
|
148
177
|
|
|
178
|
+
## Security and Authentication
|
|
179
|
+
|
|
180
|
+
This SDK implements secure authentication with 100Pay using API keys and request signing for server-to-server communications. All requests that require authentication automatically include the necessary headers with timestamps and signatures.
|
|
181
|
+
|
|
182
|
+
## TypeScript Support
|
|
183
|
+
|
|
184
|
+
This package is built with TypeScript and includes full type definitions. The main types are exported for your convenience:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { Pay100, PaymentVerificationError, CreateSubAccountData } from '@100pay-hq/100pay.js';
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Common Use Cases
|
|
191
|
+
|
|
192
|
+
### Accepting Cryptocurrency Payments
|
|
193
|
+
|
|
194
|
+
1. Initialize the SDK with your API keys
|
|
195
|
+
2. When a payment is received, use the `verify` method to confirm the transaction
|
|
196
|
+
3. Process the order or service based on the verification result
|
|
197
|
+
|
|
198
|
+
### Creating Subaccounts for Partners or Marketplaces
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const subaccount = await client.subaccounts.create({
|
|
202
|
+
name: "Partner Name",
|
|
203
|
+
email: "partner@example.com"
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Save the subaccount information for future use
|
|
207
|
+
console.log(`Created subaccount: ${subaccount.data.id}`);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Resources
|
|
211
|
+
|
|
212
|
+
- [100Pay Platform](https://100pay.co)
|
|
213
|
+
- [100Developers Portal](https://100pay.co) - Get your API keys here
|
|
214
|
+
- [API Documentation](https://documenter.getpostman.com/view/13045730/2s93RMUatE)
|
|
215
|
+
|
|
149
216
|
## Development
|
|
150
217
|
|
|
151
|
-
###
|
|
218
|
+
### Building from Source
|
|
152
219
|
|
|
153
|
-
|
|
220
|
+
```bash
|
|
221
|
+
# Clone the repository
|
|
222
|
+
git clone https://github.com/shop100global/100pay.js.git
|
|
223
|
+
cd 100pay.js
|
|
154
224
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
cd 100pay.js
|
|
158
|
-
```
|
|
225
|
+
# Install dependencies
|
|
226
|
+
npm install
|
|
159
227
|
|
|
160
|
-
|
|
228
|
+
# Build the project
|
|
229
|
+
npm run build
|
|
230
|
+
```
|
|
161
231
|
|
|
162
|
-
|
|
163
|
-
npm install
|
|
164
|
-
```
|
|
232
|
+
### Available Scripts
|
|
165
233
|
|
|
166
|
-
|
|
234
|
+
- `npm run build` - Build the TypeScript code
|
|
235
|
+
- `npm run build:clean` - Clean the dist directory and build
|
|
236
|
+
- `npm run test` - Run tests
|
|
237
|
+
- `npm run lint` - Lint the code
|
|
238
|
+
- `npm run lint:fix` - Lint and fix code
|
|
167
239
|
|
|
168
|
-
|
|
169
|
-
npm run build
|
|
170
|
-
```
|
|
240
|
+
## Migration from JavaScript Version
|
|
171
241
|
|
|
172
|
-
|
|
242
|
+
The TypeScript version includes some improvements over the original JavaScript version:
|
|
243
|
+
|
|
244
|
+
1. Uses `axios` instead of the deprecated `request` library
|
|
245
|
+
2. Better error handling with typed errors
|
|
246
|
+
3. Stricter type checking for method parameters and return values
|
|
247
|
+
4. Object-based constructor for better flexibility
|
|
173
248
|
|
|
174
|
-
|
|
249
|
+
If you're migrating from the JavaScript version, note that the constructor now requires an object parameter rather than individual arguments.
|
|
175
250
|
|
|
176
|
-
|
|
177
|
-
* `npm run build:clean` - Clean the dist directory and build
|
|
178
|
-
* `npm run type-check` - Check TypeScript types without emitting files
|
|
179
|
-
* `npm run test` - Run tests
|
|
180
|
-
* `npm run test:watch` - Run tests in watch mode
|
|
181
|
-
* `npm run test:coverage` - Run tests with coverage report
|
|
182
|
-
* `npm run lint` - Lint the code
|
|
183
|
-
* `npm run lint:fix` - Lint and fix code
|
|
184
|
-
* `npm run verify` - Run linting, tests, and build
|
|
251
|
+
## License
|
|
185
252
|
|
|
186
|
-
|
|
253
|
+
[Include your license information here]
|
|
187
254
|
|
|
188
|
-
This package has migrated from the deprecated `request` library to `axios` for making HTTP requests. This provides better TypeScript support and improved error handling.
|
package/dist/index.cjs
CHANGED
|
@@ -101,6 +101,16 @@ var Pay100 = class {
|
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
|
+
// subaccount methods
|
|
105
|
+
this.subaccounts = {
|
|
106
|
+
create: async (data) => {
|
|
107
|
+
return this.request(
|
|
108
|
+
"POST",
|
|
109
|
+
"/api/v1/assets/subaccount/create",
|
|
110
|
+
data
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
104
114
|
this.publicKey = publicKey;
|
|
105
115
|
this.secretKey = secretKey;
|
|
106
116
|
this.baseUrl = baseUrl;
|
|
@@ -112,7 +122,17 @@ var Pay100 = class {
|
|
|
112
122
|
*/
|
|
113
123
|
createSignature(payload) {
|
|
114
124
|
const timestamp = Date.now().toString();
|
|
115
|
-
|
|
125
|
+
let signingSecret = this?.secretKey;
|
|
126
|
+
if (this?.secretKey?.includes(";")) {
|
|
127
|
+
const secretKeyParts = this.secretKey.split(";");
|
|
128
|
+
if (secretKeyParts.length === 3) {
|
|
129
|
+
signingSecret = secretKeyParts[2];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!signingSecret) {
|
|
133
|
+
throw new Error("Secret key is required for signing");
|
|
134
|
+
}
|
|
135
|
+
const signature = crypto.createHmac("sha256", signingSecret).update(timestamp + JSON.stringify(payload)).digest("hex");
|
|
116
136
|
return { timestamp, signature };
|
|
117
137
|
}
|
|
118
138
|
/**
|
|
@@ -122,12 +142,18 @@ var Pay100 = class {
|
|
|
122
142
|
* @returns Headers object
|
|
123
143
|
*/
|
|
124
144
|
getHeaders(payload = {}) {
|
|
125
|
-
|
|
145
|
+
if (this.secretKey) {
|
|
146
|
+
const { timestamp, signature } = this.createSignature(payload);
|
|
147
|
+
return {
|
|
148
|
+
"api-key": this.publicKey,
|
|
149
|
+
"x-secret-key": this.secretKey,
|
|
150
|
+
"x-timestamp": timestamp,
|
|
151
|
+
"x-signature": signature,
|
|
152
|
+
"Content-Type": "application/json"
|
|
153
|
+
};
|
|
154
|
+
}
|
|
126
155
|
return {
|
|
127
156
|
"api-key": this.publicKey,
|
|
128
|
-
"x-secret-key": this.secretKey,
|
|
129
|
-
"x-timestamp": timestamp,
|
|
130
|
-
"x-signature": signature,
|
|
131
157
|
"Content-Type": "application/json"
|
|
132
158
|
};
|
|
133
159
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\n\n// Interface for constructor parameters\ninterface IPay100Config {\n publicKey: string;\n secretKey: string;\n baseUrl?: string;\n}\n\n// Interface for transaction data from API\ninterface ITransactionData {\n [key: string]: unknown; // For flexibility, since we don't know the exact structure\n}\n\n// Interface for raw API response\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Interface for API success response\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n// Error type for payment verification\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\nexport class Pay100 {\n private publicKey: string;\n private secretKey: string;\n private baseUrl: string;\n\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a request signature for secure server-to-server communication\n * @param payload Request payload to sign\n * @returns Object containing timestamp and signature\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", this.secretKey)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Create common headers for API requests\n * @param additionalHeaders Additional headers to include\n * @param payload Payload to sign (if signature is needed)\n * @returns Headers object\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate signature based on payload\n const { timestamp, signature } = this.createSignature(payload);\n\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verify a transaction\n * @param transactionId Transaction ID to verify\n * @returns Promise resolving to verification result\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Generic method to make authenticated API calls\n * @param method HTTP method\n * @param endpoint API endpoint\n * @param data Request payload\n * @returns Promise resolving to API response\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n return response.data as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n const errorMessage =\n axiosError.response?.data &&\n typeof axiosError.response.data === \"object\" &&\n \"message\" in axiosError.response.data\n ? String(axiosError.response.data.message)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AACjD,aAAwB;AA6BxB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAGlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAA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]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\nimport {\n CreateSubAccountData,\n CreateSubAccountResponse,\n} from \"./types/subAccount\";\n\n// Interface for constructor parameters\ninterface IPay100Config {\n publicKey: string;\n secretKey?: string;\n baseUrl?: string;\n}\n\n// Interface for transaction data from API\ninterface ITransactionData {\n [key: string]: unknown; // For flexibility, since we don't know the exact structure\n}\n\n// Interface for raw API response\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Interface for API success response\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n// Error type for payment verification\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\nexport class Pay100 {\n // optional\n private publicKey: string;\n private secretKey?: string;\n private baseUrl: string;\n\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a request signature for secure server-to-server communication\n * @param payload Request payload to sign\n * @returns Object containing timestamp and signature\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Extract the token part from the secret key if it's in the format\n // STATUS;TYPE;TOKEN (e.g., \"LIVE;SK;eyJhbGciOiJIUzI1...\")\n let signingSecret = this?.secretKey;\n\n if (this?.secretKey?.includes(\";\")) {\n const secretKeyParts = this.secretKey.split(\";\");\n if (secretKeyParts.length === 3) {\n // Use just the token part as the signing secret\n // This matches what the server expects in the verifySignature middleware\n signingSecret = secretKeyParts[2];\n }\n }\n\n if (!signingSecret) {\n throw new Error(\"Secret key is required for signing\");\n }\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", signingSecret)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Create common headers for API requests\n * @param additionalHeaders Additional headers to include\n * @param payload Payload to sign (if signature is needed)\n * @returns Headers object\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate signature based on payload\n\n if (this.secretKey) {\n const { timestamp, signature } = this.createSignature(payload);\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n return {\n \"api-key\": this.publicKey,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verify a transaction\n * @param transactionId Transaction ID to verify\n * @returns Promise resolving to verification result\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n // subaccount methods\n subaccounts = {\n create: async (\n data: CreateSubAccountData\n ): Promise<CreateSubAccountResponse> => {\n return this.request<CreateSubAccountResponse>(\n \"POST\",\n \"/api/v1/assets/subaccount/create\",\n data\n );\n },\n };\n\n /**\n * Generic method to make authenticated API calls\n * @param method HTTP method\n * @param endpoint API endpoint\n * @param data Request payload\n * @returns Promise resolving to API response\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n return response.data as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n const errorMessage =\n axiosError.response?.data &&\n typeof axiosError.response.data === \"object\" &&\n \"message\" in axiosError.response.data\n ? String(axiosError.response.data.message)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n throw error;\n }\n }\n}\n\nexport * from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AACjD,aAAwB;AAiCxB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAGlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,CAAC;AAAA,EACf;AACF;AAEO,IAAM,SAAN,MAAa;AA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A;AAAA,QACA,MAAM,WAAW,QAAQ,OAAO;AAAA,QAChC,QAAQ,WAAW,QAAQ,OAAO;AAAA,MACpC,CAAC;AAED,aAAO,SAAS;AAAA,IAClB,SAAS,OAAO;AACd,UAAI,aAAAA,QAAM,aAAa,KAAK,GAAG;AAC7B,cAAM,aAAa;AACnB,cAAM,eACJ,WAAW,UAAU,QACrB,OAAO,WAAW,SAAS,SAAS,YACpC,aAAa,WAAW,SAAS,OAC7B,OAAO,WAAW,SAAS,KAAK,OAAO,IACvC,WAAW;AAEjB,cAAM,IAAI,MAAM,uBAAuB,YAAY,EAAE;AAAA,MACvD;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["axios"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
|
+
type CreateSubAccountData = {
|
|
2
|
+
symbols: string[];
|
|
3
|
+
networks: string[];
|
|
4
|
+
owner: {
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
phone: string;
|
|
8
|
+
};
|
|
9
|
+
metadata: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
type CreateSubAccountResponse = {
|
|
12
|
+
message: string;
|
|
13
|
+
accounts: Account[];
|
|
14
|
+
};
|
|
15
|
+
type Account = {
|
|
16
|
+
balance: {
|
|
17
|
+
available: number | null;
|
|
18
|
+
locked: number | null;
|
|
19
|
+
};
|
|
20
|
+
accountType: string;
|
|
21
|
+
walletType: string;
|
|
22
|
+
status: string;
|
|
23
|
+
_id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
symbol: string;
|
|
26
|
+
decimals: string;
|
|
27
|
+
account: AccountDetails;
|
|
28
|
+
contractAddress: string;
|
|
29
|
+
logo: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
appId: string;
|
|
32
|
+
network: string;
|
|
33
|
+
ownerId: string;
|
|
34
|
+
parentWallet: string;
|
|
35
|
+
__v: number;
|
|
36
|
+
};
|
|
37
|
+
type AccountDetails = {
|
|
38
|
+
address: string;
|
|
39
|
+
key: Key;
|
|
40
|
+
network: string;
|
|
41
|
+
};
|
|
42
|
+
type Key = {
|
|
43
|
+
version: number;
|
|
44
|
+
id: string;
|
|
45
|
+
address: string;
|
|
46
|
+
crypto: Crypto;
|
|
47
|
+
};
|
|
48
|
+
type Crypto = {
|
|
49
|
+
ciphertext: string;
|
|
50
|
+
cipherparams: {
|
|
51
|
+
iv: string;
|
|
52
|
+
};
|
|
53
|
+
cipher: string;
|
|
54
|
+
kdf: string;
|
|
55
|
+
kdfparams: {
|
|
56
|
+
dklen: number;
|
|
57
|
+
salt: string;
|
|
58
|
+
n: number;
|
|
59
|
+
r: number;
|
|
60
|
+
p: number;
|
|
61
|
+
};
|
|
62
|
+
mac: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
1
65
|
interface IPay100Config {
|
|
2
66
|
publicKey: string;
|
|
3
|
-
secretKey
|
|
67
|
+
secretKey?: string;
|
|
4
68
|
baseUrl?: string;
|
|
5
69
|
}
|
|
6
70
|
interface ITransactionData {
|
|
@@ -18,7 +82,7 @@ declare class PaymentVerificationError extends Error {
|
|
|
18
82
|
}
|
|
19
83
|
declare class Pay100 {
|
|
20
84
|
private publicKey;
|
|
21
|
-
private secretKey
|
|
85
|
+
private secretKey?;
|
|
22
86
|
private baseUrl;
|
|
23
87
|
constructor({ publicKey, secretKey, baseUrl }: IPay100Config);
|
|
24
88
|
/**
|
|
@@ -40,6 +104,9 @@ declare class Pay100 {
|
|
|
40
104
|
* @returns Promise resolving to verification result
|
|
41
105
|
*/
|
|
42
106
|
verify: (transactionId: string) => Promise<IVerifyResponse>;
|
|
107
|
+
subaccounts: {
|
|
108
|
+
create: (data: CreateSubAccountData) => Promise<CreateSubAccountResponse>;
|
|
109
|
+
};
|
|
43
110
|
/**
|
|
44
111
|
* Generic method to make authenticated API calls
|
|
45
112
|
* @param method HTTP method
|
|
@@ -50,4 +117,4 @@ declare class Pay100 {
|
|
|
50
117
|
request<T>(method: "GET" | "POST" | "PUT" | "DELETE", endpoint: string, data?: Record<string, unknown>): Promise<T>;
|
|
51
118
|
}
|
|
52
119
|
|
|
53
|
-
export { Pay100, PaymentVerificationError };
|
|
120
|
+
export { type Account, type AccountDetails, type CreateSubAccountData, type CreateSubAccountResponse, type Crypto, type Key, Pay100, PaymentVerificationError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
|
+
type CreateSubAccountData = {
|
|
2
|
+
symbols: string[];
|
|
3
|
+
networks: string[];
|
|
4
|
+
owner: {
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
phone: string;
|
|
8
|
+
};
|
|
9
|
+
metadata: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
type CreateSubAccountResponse = {
|
|
12
|
+
message: string;
|
|
13
|
+
accounts: Account[];
|
|
14
|
+
};
|
|
15
|
+
type Account = {
|
|
16
|
+
balance: {
|
|
17
|
+
available: number | null;
|
|
18
|
+
locked: number | null;
|
|
19
|
+
};
|
|
20
|
+
accountType: string;
|
|
21
|
+
walletType: string;
|
|
22
|
+
status: string;
|
|
23
|
+
_id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
symbol: string;
|
|
26
|
+
decimals: string;
|
|
27
|
+
account: AccountDetails;
|
|
28
|
+
contractAddress: string;
|
|
29
|
+
logo: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
appId: string;
|
|
32
|
+
network: string;
|
|
33
|
+
ownerId: string;
|
|
34
|
+
parentWallet: string;
|
|
35
|
+
__v: number;
|
|
36
|
+
};
|
|
37
|
+
type AccountDetails = {
|
|
38
|
+
address: string;
|
|
39
|
+
key: Key;
|
|
40
|
+
network: string;
|
|
41
|
+
};
|
|
42
|
+
type Key = {
|
|
43
|
+
version: number;
|
|
44
|
+
id: string;
|
|
45
|
+
address: string;
|
|
46
|
+
crypto: Crypto;
|
|
47
|
+
};
|
|
48
|
+
type Crypto = {
|
|
49
|
+
ciphertext: string;
|
|
50
|
+
cipherparams: {
|
|
51
|
+
iv: string;
|
|
52
|
+
};
|
|
53
|
+
cipher: string;
|
|
54
|
+
kdf: string;
|
|
55
|
+
kdfparams: {
|
|
56
|
+
dklen: number;
|
|
57
|
+
salt: string;
|
|
58
|
+
n: number;
|
|
59
|
+
r: number;
|
|
60
|
+
p: number;
|
|
61
|
+
};
|
|
62
|
+
mac: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
1
65
|
interface IPay100Config {
|
|
2
66
|
publicKey: string;
|
|
3
|
-
secretKey
|
|
67
|
+
secretKey?: string;
|
|
4
68
|
baseUrl?: string;
|
|
5
69
|
}
|
|
6
70
|
interface ITransactionData {
|
|
@@ -18,7 +82,7 @@ declare class PaymentVerificationError extends Error {
|
|
|
18
82
|
}
|
|
19
83
|
declare class Pay100 {
|
|
20
84
|
private publicKey;
|
|
21
|
-
private secretKey
|
|
85
|
+
private secretKey?;
|
|
22
86
|
private baseUrl;
|
|
23
87
|
constructor({ publicKey, secretKey, baseUrl }: IPay100Config);
|
|
24
88
|
/**
|
|
@@ -40,6 +104,9 @@ declare class Pay100 {
|
|
|
40
104
|
* @returns Promise resolving to verification result
|
|
41
105
|
*/
|
|
42
106
|
verify: (transactionId: string) => Promise<IVerifyResponse>;
|
|
107
|
+
subaccounts: {
|
|
108
|
+
create: (data: CreateSubAccountData) => Promise<CreateSubAccountResponse>;
|
|
109
|
+
};
|
|
43
110
|
/**
|
|
44
111
|
* Generic method to make authenticated API calls
|
|
45
112
|
* @param method HTTP method
|
|
@@ -50,4 +117,4 @@ declare class Pay100 {
|
|
|
50
117
|
request<T>(method: "GET" | "POST" | "PUT" | "DELETE", endpoint: string, data?: Record<string, unknown>): Promise<T>;
|
|
51
118
|
}
|
|
52
119
|
|
|
53
|
-
export { Pay100, PaymentVerificationError };
|
|
120
|
+
export { type Account, type AccountDetails, type CreateSubAccountData, type CreateSubAccountResponse, type Crypto, type Key, Pay100, PaymentVerificationError };
|
package/dist/index.js
CHANGED
|
@@ -66,6 +66,16 @@ var Pay100 = class {
|
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
+
// subaccount methods
|
|
70
|
+
this.subaccounts = {
|
|
71
|
+
create: async (data) => {
|
|
72
|
+
return this.request(
|
|
73
|
+
"POST",
|
|
74
|
+
"/api/v1/assets/subaccount/create",
|
|
75
|
+
data
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
69
79
|
this.publicKey = publicKey;
|
|
70
80
|
this.secretKey = secretKey;
|
|
71
81
|
this.baseUrl = baseUrl;
|
|
@@ -77,7 +87,17 @@ var Pay100 = class {
|
|
|
77
87
|
*/
|
|
78
88
|
createSignature(payload) {
|
|
79
89
|
const timestamp = Date.now().toString();
|
|
80
|
-
|
|
90
|
+
let signingSecret = this?.secretKey;
|
|
91
|
+
if (this?.secretKey?.includes(";")) {
|
|
92
|
+
const secretKeyParts = this.secretKey.split(";");
|
|
93
|
+
if (secretKeyParts.length === 3) {
|
|
94
|
+
signingSecret = secretKeyParts[2];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!signingSecret) {
|
|
98
|
+
throw new Error("Secret key is required for signing");
|
|
99
|
+
}
|
|
100
|
+
const signature = crypto.createHmac("sha256", signingSecret).update(timestamp + JSON.stringify(payload)).digest("hex");
|
|
81
101
|
return { timestamp, signature };
|
|
82
102
|
}
|
|
83
103
|
/**
|
|
@@ -87,12 +107,18 @@ var Pay100 = class {
|
|
|
87
107
|
* @returns Headers object
|
|
88
108
|
*/
|
|
89
109
|
getHeaders(payload = {}) {
|
|
90
|
-
|
|
110
|
+
if (this.secretKey) {
|
|
111
|
+
const { timestamp, signature } = this.createSignature(payload);
|
|
112
|
+
return {
|
|
113
|
+
"api-key": this.publicKey,
|
|
114
|
+
"x-secret-key": this.secretKey,
|
|
115
|
+
"x-timestamp": timestamp,
|
|
116
|
+
"x-signature": signature,
|
|
117
|
+
"Content-Type": "application/json"
|
|
118
|
+
};
|
|
119
|
+
}
|
|
91
120
|
return {
|
|
92
121
|
"api-key": this.publicKey,
|
|
93
|
-
"x-secret-key": this.secretKey,
|
|
94
|
-
"x-timestamp": timestamp,
|
|
95
|
-
"x-signature": signature,
|
|
96
122
|
"Content-Type": "application/json"
|
|
97
123
|
};
|
|
98
124
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\n\n// Interface for constructor parameters\ninterface IPay100Config {\n publicKey: string;\n secretKey: string;\n baseUrl?: string;\n}\n\n// Interface for transaction data from API\ninterface ITransactionData {\n [key: string]: unknown; // For flexibility, since we don't know the exact structure\n}\n\n// Interface for raw API response\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Interface for API success response\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n// Error type for payment verification\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\nexport class Pay100 {\n private publicKey: string;\n private secretKey: string;\n private baseUrl: string;\n\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a request signature for secure server-to-server communication\n * @param payload Request payload to sign\n * @returns Object containing timestamp and signature\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", this.secretKey)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Create common headers for API requests\n * @param additionalHeaders Additional headers to include\n * @param payload Payload to sign (if signature is needed)\n * @returns Headers object\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate signature based on payload\n const { timestamp, signature } = this.createSignature(payload);\n\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verify a transaction\n * @param transactionId Transaction ID to verify\n * @returns Promise resolving to verification result\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Generic method to make authenticated API calls\n * @param method HTTP method\n * @param endpoint API endpoint\n * @param data Request payload\n * @returns Promise resolving to API response\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n return response.data as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n const errorMessage =\n axiosError.response?.data &&\n typeof axiosError.response.data === \"object\" &&\n \"message\" in axiosError.response.data\n ? String(axiosError.response.data.message)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n throw error;\n }\n }\n}\n"],"mappings":";AAAA,OAAO,WAA0C;AACjD,YAAY,YAAY;AA6BxB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAGlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,CAAC;AAAA,EACf;AACF;AAEO,IAAM,SAAN,MAAa;AAAA,EAKlB,YAAY,EAAE,WAAW,WAAW,UAAU,SAAS,GAAkB;AAoDzE;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAS,OAAO,kBAAoD;AAClE,UAAI;AACF,cAAM,UAAU,EAAE,cAAc;AAEhC,cAAM,WAA2C,MAAM,MAAM;AAAA,UAC3D,QAAQ;AAAA,UACR,KAAK,GAAG,KAAK,OAAO,8BAA8B,aAAa;AAAA,UAC/D,SAAS,KAAK,WAAW,OAAO;AAAA,UAChC,MAAM;AAAA,QACR,CAAC;AAGD,YAAI,CAAC,SAAS,MAAM;AAClB,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM,CAAC;AAAA,YACP,SACE;AAAA,UAC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;AAAA,IAClB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoFA,MAAM,QACJ,QACA,UACA,OAAgC,CAAC,GACrB;AACZ,QAAI;AACF,YAAM,MAAM,GAAG,KAAK,OAAO,GAAG,QAAQ;AACtC,YAAM,UAAU,KAAK,WAAW,IAAI;AAEpC,YAAM,WAAW,MAAM,MAAM;AAAA,QAC3B;AAAA,QACA;AAAA,QACA;AAAA,QACA,MAAM,WAAW,QAAQ,OAAO;AAAA,QAChC,QAAQ,WAAW,QAAQ,OAAO;AAAA,MACpC,CAAC;AAED,aAAO,SAAS;AAAA,IAClB,SAAS,OAAO;AACd,UAAI,MAAM,aAAa,KAAK,GAAG;AAC7B,cAAM,aAAa;AACnB,cAAM,eACJ,WAAW,UAAU,QACrB,OAAO,WAAW,SAAS,SAAS,YACpC,aAAa,WAAW,SAAS,OAC7B,OAAO,WAAW,SAAS,KAAK,OAAO,IACvC,WAAW;AAEjB,cAAM,IAAI,MAAM,uBAAuB,YAAY,EAAE;AAAA,MACvD;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\nimport {\n CreateSubAccountData,\n CreateSubAccountResponse,\n} from \"./types/subAccount\";\n\n// Interface for constructor parameters\ninterface IPay100Config {\n publicKey: string;\n secretKey?: string;\n baseUrl?: string;\n}\n\n// Interface for transaction data from API\ninterface ITransactionData {\n [key: string]: unknown; // For flexibility, since we don't know the exact structure\n}\n\n// Interface for raw API response\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Interface for API success response\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n// Error type for payment verification\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\nexport class Pay100 {\n // optional\n private publicKey: string;\n private secretKey?: string;\n private baseUrl: string;\n\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a request signature for secure server-to-server communication\n * @param payload Request payload to sign\n * @returns Object containing timestamp and signature\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Extract the token part from the secret key if it's in the format\n // STATUS;TYPE;TOKEN (e.g., \"LIVE;SK;eyJhbGciOiJIUzI1...\")\n let signingSecret = this?.secretKey;\n\n if (this?.secretKey?.includes(\";\")) {\n const secretKeyParts = this.secretKey.split(\";\");\n if (secretKeyParts.length === 3) {\n // Use just the token part as the signing secret\n // This matches what the server expects in the verifySignature middleware\n signingSecret = secretKeyParts[2];\n }\n }\n\n if (!signingSecret) {\n throw new Error(\"Secret key is required for signing\");\n }\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", signingSecret)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Create common headers for API requests\n * @param additionalHeaders Additional headers to include\n * @param payload Payload to sign (if signature is needed)\n * @returns Headers object\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate signature based on payload\n\n if (this.secretKey) {\n const { timestamp, signature } = this.createSignature(payload);\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n return {\n \"api-key\": this.publicKey,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verify a transaction\n * @param transactionId Transaction ID to verify\n * @returns Promise resolving to verification result\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n // subaccount methods\n subaccounts = {\n create: async (\n data: CreateSubAccountData\n ): Promise<CreateSubAccountResponse> => {\n return this.request<CreateSubAccountResponse>(\n \"POST\",\n \"/api/v1/assets/subaccount/create\",\n data\n );\n },\n };\n\n /**\n * Generic method to make authenticated API calls\n * @param method HTTP method\n * @param endpoint API endpoint\n * @param data Request payload\n * @returns Promise resolving to API response\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n return response.data as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n const errorMessage =\n axiosError.response?.data &&\n typeof axiosError.response.data === \"object\" &&\n \"message\" in axiosError.response.data\n ? String(axiosError.response.data.message)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n throw error;\n }\n }\n}\n\nexport * from \"./types\";\n"],"mappings":";AAAA,OAAO,WAA0C;AACjD,YAAY,YAAY;AAiCxB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAGlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,CAAC;AAAA,EACf;AACF;AAEO,IAAM,SAAN,MAAa;AAAA,EAMlB,YAAY,EAAE,WAAW,WAAW,UAAU,SAAS,GAAkB;AA2EzE;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAS,OAAO,kBAAoD;AAClE,UAAI;AACF,cAAM,UAAU,EAAE,cAAc;AAEhC,cAAM,WAA2C,MAAM,MAAM;AAAA,UAC3D,QAAQ;AAAA,UACR,KAAK,GAAG,KAAK,OAAO,8BAA8B,aAAa;AAAA,UAC/D,SAAS,KAAK,WAAW,OAAO;AAAA,UAChC,MAAM;AAAA,QACR,CAAC;AAGD,YAAI,CAAC,SAAS,MAAM;AAClB,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM,CAAC;AAAA,YACP,SACE;AAAA,UACJ;AAAA,QACF;AAGA,YAAI,OAAO,SAAS,SAAS,UAAU;AACrC,cAAI,SAAS,SAAS,uCAAuC;AAC3D,mBAAO;AAAA,cACL,QAAQ;AAAA,cACR,MAAM,CAAC;AAAA,cACP,S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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,WACN,UAAmC,CAAC,GACZ;AAGxB,QAAI,KAAK,WAAW;AAClB,YAAM,EAAE,WAAW,UAAU,IAAI,KAAK,gBAAgB,OAAO;AAC7D,aAAO;AAAA,QACL,WAAW,KAAK;AAAA,QAChB,gBAAgB,KAAK;AAAA,QACrB,eAAe;AAAA,QACf,eAAe;AAAA,QACf,gBAAgB;AAAA,MAClB;AAAA,IACF;AACA,WAAO;AAAA,MACL,WAAW,KAAK;AAAA,MAChB,gBAAgB;AAAA,IAClB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiGA,MAAM,QACJ,QACA,UACA,OAAgC,CAAC,GACrB;AACZ,QAAI;AACF,YAAM,MAAM,GAAG,KAAK,OAAO,GAAG,QAAQ;AACtC,YAAM,UAAU,KAAK,WAAW,IAAI;AAEpC,YAAM,WAAW,MAAM,MAAM;AAAA,QAC3B;AAAA,QACA;AAAA,QACA;AAAA,QACA,MAAM,WAAW,QAAQ,OAAO;AAAA,QAChC,QAAQ,WAAW,QAAQ,OAAO;AAAA,MACpC,CAAC;AAED,aAAO,SAAS;AAAA,IAClB,SAAS,OAAO;AACd,UAAI,MAAM,aAAa,KAAK,GAAG;AAC7B,cAAM,aAAa;AACnB,cAAM,eACJ,WAAW,UAAU,QACrB,OAAO,WAAW,SAAS,SAAS,YACpC,aAAa,WAAW,SAAS,OAC7B,OAAO,WAAW,SAAS,KAAK,OAAO,IACvC,WAAW;AAEjB,cAAM,IAAI,MAAM,uBAAuB,YAAY,EAAE;AAAA,MACvD;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@100pay-hq/100pay.js",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "100Pay.js is the official Nodejs API wrapper SDK that lets you easily verify crypto payments, run bulk payout, transfer assets and many more.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
|
+
"start": "npm run build",
|
|
29
|
+
"dev": "nodemon",
|
|
28
30
|
"build": "tsup",
|
|
29
31
|
"build:clean": "rm -rf dist && tsup",
|
|
30
32
|
"test": "jest",
|