@dj-test/payment-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/README.md +325 -0
- package/dist/chunk-3AOMSDLI.mjs +223 -0
- package/dist/chunk-3RYOE2SM.mjs +205 -0
- package/dist/chunk-KJPPSTIW.mjs +216 -0
- package/dist/chunk-MJBDAWQX.mjs +211 -0
- package/dist/chunk-PR2U6WKA.mjs +209 -0
- package/dist/chunk-T6PKEDYJ.mjs +207 -0
- package/dist/index.d.mts +3905 -0
- package/dist/index.d.ts +3905 -0
- package/dist/index.js +3849 -0
- package/dist/index.mjs +3789 -0
- package/dist/orders-64PVYGCW.mjs +12 -0
- package/dist/orders-6A74XIYV.mjs +12 -0
- package/dist/orders-BNESRMMA.mjs +12 -0
- package/dist/orders-EWAUCVY3.mjs +12 -0
- package/dist/orders-SBMFAKCC.mjs +12 -0
- package/dist/orders-UO6XKPAX.mjs +12 -0
- package/package.json +54 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/api/orders.ts
|
|
8
|
+
var orders_exports = {};
|
|
9
|
+
__export(orders_exports, {
|
|
10
|
+
createOrder: () => createOrder,
|
|
11
|
+
getOrder: () => getOrder,
|
|
12
|
+
getOrders: () => getOrders,
|
|
13
|
+
notifyTransaction: () => notifyTransaction
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// src/api/client.ts
|
|
17
|
+
import axios from "axios";
|
|
18
|
+
|
|
19
|
+
// src/core/constants.ts
|
|
20
|
+
var SDK_VERSION = "1.0.0";
|
|
21
|
+
var API_ENDPOINTS = {
|
|
22
|
+
ORDERS: "/payments",
|
|
23
|
+
PRODUCTS: "/products"
|
|
24
|
+
};
|
|
25
|
+
var ENVIRONMENT_URLS = {
|
|
26
|
+
production: "http://localhost:8080",
|
|
27
|
+
sandbox: "http://localhost:8080"
|
|
28
|
+
};
|
|
29
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
30
|
+
var ORDER_EXPIRY_MINUTES = 30;
|
|
31
|
+
var MIN_WITHDRAWAL_AMOUNT = 0.01;
|
|
32
|
+
var SUPPORTED_CHAINS = {
|
|
33
|
+
ETHEREUM: "1",
|
|
34
|
+
SEPOLIA: "11155111",
|
|
35
|
+
POLYGON: "137"
|
|
36
|
+
};
|
|
37
|
+
var ERROR_CODES = {
|
|
38
|
+
INVALID_API_KEY: "INVALID_API_KEY",
|
|
39
|
+
INVALID_PRODUCT: "INVALID_PRODUCT",
|
|
40
|
+
ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
|
|
41
|
+
ORDER_EXPIRED: "ORDER_EXPIRED",
|
|
42
|
+
INSUFFICIENT_BALANCE: "INSUFFICIENT_BALANCE",
|
|
43
|
+
SELF_TRANSFER: "SELF_TRANSFER",
|
|
44
|
+
INVALID_ADDRESS: "INVALID_ADDRESS",
|
|
45
|
+
NETWORK_ERROR: "NETWORK_ERROR"
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/core/config.ts
|
|
49
|
+
var Config = class _Config {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.config = null;
|
|
52
|
+
}
|
|
53
|
+
static getInstance() {
|
|
54
|
+
if (!_Config.instance) {
|
|
55
|
+
_Config.instance = new _Config();
|
|
56
|
+
}
|
|
57
|
+
return _Config.instance;
|
|
58
|
+
}
|
|
59
|
+
initialize(config2) {
|
|
60
|
+
if (!config2.baseUrl && config2.environment) {
|
|
61
|
+
config2.baseUrl = ENVIRONMENT_URLS[config2.environment];
|
|
62
|
+
}
|
|
63
|
+
if (!config2.timeout) {
|
|
64
|
+
config2.timeout = DEFAULT_TIMEOUT;
|
|
65
|
+
}
|
|
66
|
+
this.config = config2;
|
|
67
|
+
}
|
|
68
|
+
getConfig() {
|
|
69
|
+
if (!this.config) {
|
|
70
|
+
return {
|
|
71
|
+
environment: "sandbox",
|
|
72
|
+
baseUrl: ENVIRONMENT_URLS.sandbox,
|
|
73
|
+
timeout: DEFAULT_TIMEOUT
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return this.config;
|
|
77
|
+
}
|
|
78
|
+
isInitialized() {
|
|
79
|
+
return this.config !== null;
|
|
80
|
+
}
|
|
81
|
+
reset() {
|
|
82
|
+
this.config = null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var config = Config.getInstance();
|
|
86
|
+
|
|
87
|
+
// src/types/sdk.ts
|
|
88
|
+
var SDKError = class extends Error {
|
|
89
|
+
constructor(message, code, details) {
|
|
90
|
+
super(message);
|
|
91
|
+
this.code = code;
|
|
92
|
+
this.details = details;
|
|
93
|
+
this.name = "SDKError";
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var APIError = class extends SDKError {
|
|
97
|
+
constructor(message, statusCode, details) {
|
|
98
|
+
super(message, "API_ERROR", details);
|
|
99
|
+
this.statusCode = statusCode;
|
|
100
|
+
this.name = "APIError";
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/api/client.ts
|
|
105
|
+
var APIClient = class {
|
|
106
|
+
constructor() {
|
|
107
|
+
this.instance = null;
|
|
108
|
+
}
|
|
109
|
+
getClient() {
|
|
110
|
+
if (!this.instance) {
|
|
111
|
+
const sdkConfig = config.getConfig();
|
|
112
|
+
this.instance = axios.create({
|
|
113
|
+
baseURL: sdkConfig.baseUrl,
|
|
114
|
+
timeout: sdkConfig.timeout,
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json"
|
|
117
|
+
},
|
|
118
|
+
withCredentials: true
|
|
119
|
+
// 기존 프로젝트 패턴과 일치
|
|
120
|
+
});
|
|
121
|
+
this.instance.interceptors.request.use(
|
|
122
|
+
(requestConfig) => {
|
|
123
|
+
return requestConfig;
|
|
124
|
+
},
|
|
125
|
+
(error) => Promise.reject(error)
|
|
126
|
+
);
|
|
127
|
+
this.instance.interceptors.response.use(
|
|
128
|
+
(response) => response,
|
|
129
|
+
(error) => {
|
|
130
|
+
const status = error.response?.status;
|
|
131
|
+
const data = error.response?.data;
|
|
132
|
+
const message = data?.message || error.message;
|
|
133
|
+
const details = error.response?.data;
|
|
134
|
+
throw new APIError(message, status, details);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return this.instance;
|
|
139
|
+
}
|
|
140
|
+
reset() {
|
|
141
|
+
this.instance = null;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var apiClient = new APIClient();
|
|
145
|
+
|
|
146
|
+
// src/api/orders.ts
|
|
147
|
+
var extractPublicOrderId = (orderUrl) => {
|
|
148
|
+
const match = orderUrl.match(/order=([a-f0-9-]+)/);
|
|
149
|
+
return match ? match[1] : "";
|
|
150
|
+
};
|
|
151
|
+
var createOrder = async (productId, redirectUrl, webhookUrl) => {
|
|
152
|
+
const request = {
|
|
153
|
+
productId,
|
|
154
|
+
redirectUrl,
|
|
155
|
+
webhookUrl
|
|
156
|
+
};
|
|
157
|
+
const response = await apiClient.getClient().post(
|
|
158
|
+
API_ENDPOINTS.ORDERS,
|
|
159
|
+
request
|
|
160
|
+
);
|
|
161
|
+
const order = response.data.output;
|
|
162
|
+
const publicOrderId = extractPublicOrderId(order.orderUrl);
|
|
163
|
+
return {
|
|
164
|
+
orderId: order.orderId,
|
|
165
|
+
publicOrderId,
|
|
166
|
+
paymentUrl: order.orderUrl,
|
|
167
|
+
amount: order.price,
|
|
168
|
+
coinId: order.coin,
|
|
169
|
+
chainId: order.chain,
|
|
170
|
+
status: order.orderStat,
|
|
171
|
+
expiresAt: order.expireDt
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
var getOrder = async (publicOrderId) => {
|
|
175
|
+
const response = await apiClient.getClient().get(
|
|
176
|
+
`${API_ENDPOINTS.ORDERS}/${publicOrderId}`
|
|
177
|
+
);
|
|
178
|
+
return response.data.output;
|
|
179
|
+
};
|
|
180
|
+
var getOrders = async () => {
|
|
181
|
+
const response = await apiClient.getClient().get(API_ENDPOINTS.ORDERS);
|
|
182
|
+
return response.data.output;
|
|
183
|
+
};
|
|
184
|
+
var notifyTransaction = async (publicOrderId, txHash) => {
|
|
185
|
+
await apiClient.getClient().post(
|
|
186
|
+
`${API_ENDPOINTS.ORDERS}/${publicOrderId}/transaction`,
|
|
187
|
+
{ txHash }
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export {
|
|
192
|
+
__export,
|
|
193
|
+
SDK_VERSION,
|
|
194
|
+
API_ENDPOINTS,
|
|
195
|
+
ENVIRONMENT_URLS,
|
|
196
|
+
DEFAULT_TIMEOUT,
|
|
197
|
+
ORDER_EXPIRY_MINUTES,
|
|
198
|
+
MIN_WITHDRAWAL_AMOUNT,
|
|
199
|
+
SUPPORTED_CHAINS,
|
|
200
|
+
ERROR_CODES,
|
|
201
|
+
config,
|
|
202
|
+
SDKError,
|
|
203
|
+
APIError,
|
|
204
|
+
createOrder,
|
|
205
|
+
getOrder,
|
|
206
|
+
getOrders,
|
|
207
|
+
notifyTransaction,
|
|
208
|
+
orders_exports
|
|
209
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/api/orders.ts
|
|
8
|
+
var orders_exports = {};
|
|
9
|
+
__export(orders_exports, {
|
|
10
|
+
createOrder: () => createOrder,
|
|
11
|
+
getOrder: () => getOrder,
|
|
12
|
+
getOrders: () => getOrders,
|
|
13
|
+
notifyTransaction: () => notifyTransaction
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// src/api/client.ts
|
|
17
|
+
import axios from "axios";
|
|
18
|
+
|
|
19
|
+
// src/core/constants.ts
|
|
20
|
+
var SDK_VERSION = "1.0.0";
|
|
21
|
+
var API_ENDPOINTS = {
|
|
22
|
+
ORDERS: "/payments",
|
|
23
|
+
PRODUCTS: "/products"
|
|
24
|
+
};
|
|
25
|
+
var ENVIRONMENT_URLS = {
|
|
26
|
+
production: "http://localhost:8080",
|
|
27
|
+
sandbox: "http://localhost:8080"
|
|
28
|
+
};
|
|
29
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
30
|
+
var ORDER_EXPIRY_MINUTES = 30;
|
|
31
|
+
var MIN_WITHDRAWAL_AMOUNT = 0.01;
|
|
32
|
+
var SUPPORTED_CHAINS = {
|
|
33
|
+
ETHEREUM: "1",
|
|
34
|
+
SEPOLIA: "11155111",
|
|
35
|
+
POLYGON: "137"
|
|
36
|
+
};
|
|
37
|
+
var ERROR_CODES = {
|
|
38
|
+
INVALID_API_KEY: "INVALID_API_KEY",
|
|
39
|
+
INVALID_PRODUCT: "INVALID_PRODUCT",
|
|
40
|
+
ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
|
|
41
|
+
ORDER_EXPIRED: "ORDER_EXPIRED",
|
|
42
|
+
INSUFFICIENT_BALANCE: "INSUFFICIENT_BALANCE",
|
|
43
|
+
SELF_TRANSFER: "SELF_TRANSFER",
|
|
44
|
+
INVALID_ADDRESS: "INVALID_ADDRESS",
|
|
45
|
+
NETWORK_ERROR: "NETWORK_ERROR"
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/core/config.ts
|
|
49
|
+
var Config = class _Config {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.config = null;
|
|
52
|
+
}
|
|
53
|
+
static getInstance() {
|
|
54
|
+
if (!_Config.instance) {
|
|
55
|
+
_Config.instance = new _Config();
|
|
56
|
+
}
|
|
57
|
+
return _Config.instance;
|
|
58
|
+
}
|
|
59
|
+
initialize(config2) {
|
|
60
|
+
if (!config2.baseUrl && config2.environment) {
|
|
61
|
+
config2.baseUrl = ENVIRONMENT_URLS[config2.environment];
|
|
62
|
+
}
|
|
63
|
+
if (!config2.timeout) {
|
|
64
|
+
config2.timeout = DEFAULT_TIMEOUT;
|
|
65
|
+
}
|
|
66
|
+
this.config = config2;
|
|
67
|
+
}
|
|
68
|
+
getConfig() {
|
|
69
|
+
if (!this.config) {
|
|
70
|
+
return {
|
|
71
|
+
environment: "sandbox",
|
|
72
|
+
baseUrl: ENVIRONMENT_URLS.sandbox,
|
|
73
|
+
timeout: DEFAULT_TIMEOUT
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return this.config;
|
|
77
|
+
}
|
|
78
|
+
isInitialized() {
|
|
79
|
+
return this.config !== null;
|
|
80
|
+
}
|
|
81
|
+
reset() {
|
|
82
|
+
this.config = null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var config = Config.getInstance();
|
|
86
|
+
|
|
87
|
+
// src/types/sdk.ts
|
|
88
|
+
var SDKError = class extends Error {
|
|
89
|
+
constructor(message, code, details) {
|
|
90
|
+
super(message);
|
|
91
|
+
this.code = code;
|
|
92
|
+
this.details = details;
|
|
93
|
+
this.name = "SDKError";
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var APIError = class extends SDKError {
|
|
97
|
+
constructor(message, statusCode, details) {
|
|
98
|
+
super(message, "API_ERROR", details);
|
|
99
|
+
this.statusCode = statusCode;
|
|
100
|
+
this.name = "APIError";
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/api/client.ts
|
|
105
|
+
var APIClient = class {
|
|
106
|
+
constructor() {
|
|
107
|
+
this.instance = null;
|
|
108
|
+
}
|
|
109
|
+
getClient() {
|
|
110
|
+
if (!this.instance) {
|
|
111
|
+
const sdkConfig = config.getConfig();
|
|
112
|
+
this.instance = axios.create({
|
|
113
|
+
baseURL: sdkConfig.baseUrl,
|
|
114
|
+
timeout: sdkConfig.timeout,
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json"
|
|
117
|
+
},
|
|
118
|
+
withCredentials: true
|
|
119
|
+
// 기존 프로젝트 패턴과 일치
|
|
120
|
+
});
|
|
121
|
+
this.instance.interceptors.request.use(
|
|
122
|
+
(requestConfig) => {
|
|
123
|
+
return requestConfig;
|
|
124
|
+
},
|
|
125
|
+
(error) => Promise.reject(error)
|
|
126
|
+
);
|
|
127
|
+
this.instance.interceptors.response.use(
|
|
128
|
+
(response) => response,
|
|
129
|
+
(error) => {
|
|
130
|
+
const status = error.response?.status;
|
|
131
|
+
const data = error.response?.data;
|
|
132
|
+
const message = data?.message || error.message;
|
|
133
|
+
const details = error.response?.data;
|
|
134
|
+
throw new APIError(message, status, details);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return this.instance;
|
|
139
|
+
}
|
|
140
|
+
reset() {
|
|
141
|
+
this.instance = null;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var apiClient = new APIClient();
|
|
145
|
+
|
|
146
|
+
// src/api/orders.ts
|
|
147
|
+
var createOrder = async (productId, redirectUrl, webhookUrl) => {
|
|
148
|
+
const request = {
|
|
149
|
+
productId,
|
|
150
|
+
redirectUrl,
|
|
151
|
+
webhookUrl
|
|
152
|
+
};
|
|
153
|
+
const response = await apiClient.getClient().post(
|
|
154
|
+
API_ENDPOINTS.ORDERS,
|
|
155
|
+
request
|
|
156
|
+
);
|
|
157
|
+
const order = response.data.output;
|
|
158
|
+
return {
|
|
159
|
+
orderId: order.orderId,
|
|
160
|
+
publicOrderId: order.orderId,
|
|
161
|
+
paymentUrl: "",
|
|
162
|
+
// 사용 안 함
|
|
163
|
+
amount: order.price,
|
|
164
|
+
coinId: order.coin,
|
|
165
|
+
chainId: order.chain,
|
|
166
|
+
status: order.orderStat,
|
|
167
|
+
expiresAt: order.expireDt,
|
|
168
|
+
redirectUrl: order.redirectUrl || null
|
|
169
|
+
// 서버 응답의 redirectUrl
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
var getOrder = async (publicOrderId) => {
|
|
173
|
+
const response = await apiClient.getClient().get(
|
|
174
|
+
`${API_ENDPOINTS.ORDERS}/${publicOrderId}`
|
|
175
|
+
);
|
|
176
|
+
return response.data.output;
|
|
177
|
+
};
|
|
178
|
+
var getOrders = async () => {
|
|
179
|
+
const response = await apiClient.getClient().get(API_ENDPOINTS.ORDERS);
|
|
180
|
+
return response.data.output;
|
|
181
|
+
};
|
|
182
|
+
var notifyTransaction = async (publicOrderId, txHash) => {
|
|
183
|
+
await apiClient.getClient().post(
|
|
184
|
+
`${API_ENDPOINTS.ORDERS}/${publicOrderId}/transaction`,
|
|
185
|
+
{ txHash }
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export {
|
|
190
|
+
__export,
|
|
191
|
+
SDK_VERSION,
|
|
192
|
+
API_ENDPOINTS,
|
|
193
|
+
ENVIRONMENT_URLS,
|
|
194
|
+
DEFAULT_TIMEOUT,
|
|
195
|
+
ORDER_EXPIRY_MINUTES,
|
|
196
|
+
MIN_WITHDRAWAL_AMOUNT,
|
|
197
|
+
SUPPORTED_CHAINS,
|
|
198
|
+
ERROR_CODES,
|
|
199
|
+
config,
|
|
200
|
+
SDKError,
|
|
201
|
+
APIError,
|
|
202
|
+
createOrder,
|
|
203
|
+
getOrder,
|
|
204
|
+
getOrders,
|
|
205
|
+
notifyTransaction,
|
|
206
|
+
orders_exports
|
|
207
|
+
};
|