@bitpal/checkout 0.10.0 → 0.12.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 +52 -0
- package/LICENSE +21 -21
- package/README.md +54 -14
- package/dist/index.cjs +105 -80
- package/dist/index.d.cts +100 -38
- package/dist/index.d.ts +100 -38
- package/dist/index.js +103 -79
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -9,9 +9,11 @@ interface BitPalConfig {
|
|
|
9
9
|
*
|
|
10
10
|
* BitPal 콘솔 → Developers → API Keys 에서 발급.
|
|
11
11
|
*
|
|
12
|
-
* **선택**: createSession/listSessions/products 등 서버 메서드는 필수.
|
|
13
|
-
* (getPublicSession/getStatus/issueDepositAddress)는
|
|
14
|
-
*
|
|
12
|
+
* **선택**: createSession/listSessions/products 등 서버 메서드는 필수. buyer-facing 공개 메서드
|
|
13
|
+
* (getPublicSession/getStatus/issueDepositAddress)는 apiKey 가 필요 없다(issueDepositAddress 는 session_token 필요).
|
|
14
|
+
* 단 **브라우저(CORS)** 에서 임의 머천트 도메인이 직접 부를 수 있는 것은 `getPublicSession` 뿐이다 —
|
|
15
|
+
* `issueDepositAddress`/`getStatus` 는 머천트 백엔드를 경유해 호출한다(자체 결제 UI = 헤드리스 checkout).
|
|
16
|
+
* 절대 secret 키를 브라우저에 노출하지 말 것.
|
|
15
17
|
*/
|
|
16
18
|
apiKey?: string;
|
|
17
19
|
/**
|
|
@@ -25,28 +27,30 @@ interface BitPalConfig {
|
|
|
25
27
|
/** 요청 타임아웃 (ms, 기본값: 30000) */
|
|
26
28
|
timeout?: number;
|
|
27
29
|
}
|
|
28
|
-
/** 응답/정규화된 line item — amount 는 항상 atomic
|
|
30
|
+
/** 응답/정규화된 line item — amount 는 항상 canonical 6dp atomic 정수(실제 결제 토큰 decimals 아님). */
|
|
29
31
|
interface LineItem {
|
|
30
32
|
name: string;
|
|
31
|
-
/**
|
|
33
|
+
/** canonical 6dp atomic 정수 문자열("1"="1000000", "29"="29000000"). */
|
|
32
34
|
amount: string;
|
|
33
35
|
currency: string;
|
|
34
36
|
quantity?: number;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* 세션 생성 입력용 line item. 금액은 둘 중 **하나**:
|
|
38
|
-
* - `amount`(권장): 사람 표기
|
|
39
|
-
* ※
|
|
40
|
-
*
|
|
40
|
+
* - `amount`(권장): 사람 표기 canonical 6dp 문자열(예 "29", "0.5", "29.00"). decimal 신경 쓸 필요 없음.
|
|
41
|
+
* ※ `currency`(예: 'USDC'/'USDT'/'JPYC')가 실제 결제 통화를 결정한다 — `amount`는 그 통화의 canonical
|
|
42
|
+
* 6dp 표기일 뿐 항상 USD 를 뜻하지 않는다(예: currency='JPYC' + amount="29" → 29 JPYC/29엔, 환율
|
|
43
|
+
* 변환 없음). 실제 결제 토큰 decimals(USDC 6dp / JPYC 18dp 등)로의 재스케일은 발급 시 서버가 처리.
|
|
44
|
+
* - `amount_atomic`: 이미 raw canonical 6dp 정수 문자열($1="1000000")인 경우(고급/기존 코드).
|
|
41
45
|
* 둘 다 지정하거나 둘 다 생략하면 SDK 가 에러를 throw 한다.
|
|
42
46
|
*/
|
|
43
47
|
interface LineItemInput {
|
|
44
48
|
name: string;
|
|
45
49
|
currency: string;
|
|
46
50
|
quantity?: number;
|
|
47
|
-
/** 사람 표기
|
|
51
|
+
/** 사람 표기 canonical 6dp 금액(예 "29", "0.5") — 권장. amount_atomic 과 상호배타. */
|
|
48
52
|
amount?: string;
|
|
49
|
-
/** raw
|
|
53
|
+
/** raw canonical 6dp 정수($1="1000000") — 고급/기존. amount 와 상호배타. */
|
|
50
54
|
amount_atomic?: string;
|
|
51
55
|
}
|
|
52
56
|
interface PriceLineItem {
|
|
@@ -57,7 +61,7 @@ interface PriceLineItem {
|
|
|
57
61
|
type CheckoutLineItemInput = LineItemInput | PriceLineItem;
|
|
58
62
|
interface CreateSessionParams {
|
|
59
63
|
line_items: CheckoutLineItemInput[];
|
|
60
|
-
/**
|
|
64
|
+
/** @deprecated 서버가 사용하지 않는다(무시됨). 입금자 주소는 결제 시 온체인에서 기록된다. */
|
|
61
65
|
payer_wallet?: string;
|
|
62
66
|
/** 결제 체인 (예: eip155:8453). 단일 고정 — allowed_pay_chains와 상호 배타. */
|
|
63
67
|
pay_chain?: string;
|
|
@@ -78,11 +82,19 @@ interface CreateSessionParams {
|
|
|
78
82
|
chain: string;
|
|
79
83
|
token: string;
|
|
80
84
|
}>;
|
|
81
|
-
/**
|
|
85
|
+
/** @deprecated 서버가 사용하지 않는다(무시됨). 결제 자산은 `allowed_assets` 로 지정한다. */
|
|
82
86
|
pay_asset?: string;
|
|
83
87
|
/** 허용 오차 (%, 기본값: 2.00) */
|
|
84
88
|
tolerance_percent?: string;
|
|
85
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* 결제 대기 시간(분). 1~60, 기본 15. 이 시간이 지나면 세션이 만료된다
|
|
91
|
+
* (만료 후 도착한 정확 금액은 7일 안이면 늦은 결제로 인정 — `late: true`).
|
|
92
|
+
*/
|
|
93
|
+
expires_in_minutes?: number;
|
|
94
|
+
/**
|
|
95
|
+
* @deprecated `expires_in_minutes` 를 쓴다. 60~3600 초만 허용되고 분 단위로 올림해 보낸다.
|
|
96
|
+
* (0.11 까지는 서버가 이 필드를 몰라 무시했고, 항상 기본 15분이 적용됐다.)
|
|
97
|
+
*/
|
|
86
98
|
expires_in_seconds?: number;
|
|
87
99
|
/** 메타데이터 (모든 값은 string 이어야 함) */
|
|
88
100
|
metadata?: Record<string, string>;
|
|
@@ -141,9 +153,18 @@ interface PublicSession {
|
|
|
141
153
|
status: string;
|
|
142
154
|
mode: string | null;
|
|
143
155
|
currency: string;
|
|
144
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* 주문 총액 — **canonical μUSD(6dp) 정수 문자열**(가격 통화 기준, $1 = "1000000"). 결제 토큰 decimals 와 무관하다
|
|
158
|
+
* (18dp 토큰으로 결제해도 6dp). 온체인으로 보낼 토큰 단위 금액은 `pay_amount`(또는 발급 응답 `expectedAmount`).
|
|
159
|
+
*/
|
|
145
160
|
amount_total: string;
|
|
161
|
+
/** 지금까지 입금주소에 들어온 금액 — **결제 토큰 atomic**(`token_decimals` 기준). 미입금이면 null. */
|
|
146
162
|
amount_received?: string | null;
|
|
163
|
+
/**
|
|
164
|
+
* 선택된 결제 토큰 단위의 총액(atomic, `token_decimals` 기준) — 구매자가 송금할 정확 금액. 자산 미선택이면 null.
|
|
165
|
+
* = canonicalToTokenAtomic(amount_total, token_decimals). 부족액 = pay_amount − amount_received.
|
|
166
|
+
*/
|
|
167
|
+
pay_amount?: string | null;
|
|
147
168
|
pay_chain: string | null;
|
|
148
169
|
pay_asset: string | null;
|
|
149
170
|
/** 발급된 주문별 forwarder 입금주소(미발급이면 null). */
|
|
@@ -152,7 +173,7 @@ interface PublicSession {
|
|
|
152
173
|
payment_options: PaymentOption[];
|
|
153
174
|
chain_id: number | null;
|
|
154
175
|
token_address: string | null;
|
|
155
|
-
/** 선택된 pay 토큰 decimals(발급 후).
|
|
176
|
+
/** 선택된 pay 토큰 decimals(발급 후). amount_received / pay_amount 해석에 사용 — 6dp 가정 금지(amount_total 은 항상 6dp). */
|
|
156
177
|
token_decimals?: number | null;
|
|
157
178
|
tx_hash: string | null;
|
|
158
179
|
release_tx_hash?: string | null;
|
|
@@ -284,16 +305,23 @@ interface UpdateProductParams {
|
|
|
284
305
|
}
|
|
285
306
|
/**
|
|
286
307
|
* 가격 생성 입력. 금액은 둘 중 **하나** (line item 과 동일 모델):
|
|
287
|
-
* - `amount`(권장): 사람 표기
|
|
288
|
-
* - `amount_atomic`: raw
|
|
308
|
+
* - `amount`(권장): 사람 표기 canonical 6dp 문자열(예 "29", "0.5"). decimal 신경 쓸 필요 없음.
|
|
309
|
+
* - `amount_atomic`: raw canonical 6dp 정수($1="1000000") — 고급/기존.
|
|
289
310
|
* 둘 다 지정하거나 둘 다 생략하면 서버가 400 을 반환한다.
|
|
311
|
+
*
|
|
312
|
+
* `amount`/`amount_atomic`은 실제 결제 토큰의 decimals 가 아니라 **항상 canonical 6dp**다 — 서버가
|
|
313
|
+
* 결제 시점에 실제 토큰 decimals(예: JPYC=18dp)로 재스케일한다(1:1 가정, 환율 변환 없음). 즉
|
|
314
|
+
* `token_symbol: 'JPYC'`로 "29"를 등록하면 29 JPYC(≈29엔)로 결제되지, 29 USD 상당의 JPYC로
|
|
315
|
+
* 환산되지 않는다.
|
|
316
|
+
*
|
|
317
|
+
* `currency`는 입력받지 않는다 — 서버가 `token_symbol`에서 파생한다(불일치 방지).
|
|
290
318
|
*/
|
|
291
319
|
interface CreatePriceParams {
|
|
292
|
-
/** 사람 표기
|
|
320
|
+
/** 사람 표기 canonical 6dp 금액(예 "29", "0.5") — 권장. amount_atomic 과 상호배타. */
|
|
293
321
|
amount?: string;
|
|
294
|
-
/** raw
|
|
322
|
+
/** raw canonical 6dp 정수($1="1000000") — 고급/기존. amount 와 상호배타. */
|
|
295
323
|
amount_atomic?: string;
|
|
296
|
-
currency
|
|
324
|
+
/** 'USDC' | 'USDT' | 'JPYC' — 미지정 시 'USDC'. 이 Price 의 유일한 결제 자산(currency 는 여기서 파생). */
|
|
297
325
|
token_symbol?: string;
|
|
298
326
|
billing_type?: 'one_time';
|
|
299
327
|
nickname?: string;
|
|
@@ -492,14 +520,16 @@ declare class BitPalCheckoutClient {
|
|
|
492
520
|
/**
|
|
493
521
|
* 체크아웃 세션 생성.
|
|
494
522
|
*
|
|
495
|
-
* `line_items[].amount` 는 사람 표기
|
|
496
|
-
*
|
|
523
|
+
* `line_items[].amount` 는 사람 표기 canonical 6dp 문자열("29", "0.5") — decimal 계산 불필요.
|
|
524
|
+
* `currency`('USDC'/'USDT'/'JPYC')가 실제 결제 통화를 결정하고, amount 는 항상 그 통화 기준 값이다
|
|
525
|
+
* (USD 로 고정된 게 아님 — currency='JPYC' + amount='1500' → 1500엔/1500 JPYC, 환율 변환 없음).
|
|
526
|
+
* 이미 raw canonical 6dp 정수라면 `amount_atomic`("29000000") 사용(고급). 둘은 상호 배타.
|
|
497
527
|
*
|
|
498
528
|
* @example
|
|
499
529
|
* import { BitPal } from '@bitpal/checkout';
|
|
500
530
|
* const bp = new BitPal('bp_test_...');
|
|
501
531
|
* const { data } = await bp.checkout.createSession({
|
|
502
|
-
* // amount: 사람 표기
|
|
532
|
+
* // amount: 사람 표기 canonical 6dp("29", "0.5"). 체인/토큰 decimal 은 발급 시 서버가 재스케일.
|
|
503
533
|
* line_items: [{ name: 'Pro', amount: '29', currency: 'USDC' }],
|
|
504
534
|
* });
|
|
505
535
|
* console.log(data.url); // → buyer를 redirect할 결제 페이지
|
|
@@ -571,10 +601,32 @@ declare class BitPalCheckoutClient {
|
|
|
571
601
|
amountAtomic: string;
|
|
572
602
|
}): Promise<ApiResponse<FeePreview>>;
|
|
573
603
|
}
|
|
604
|
+
/** Structured fields parsed from an API error body. All optional — older endpoints omit some. */
|
|
605
|
+
interface BitPalErrorDetails {
|
|
606
|
+
/** Machine-readable error code, e.g. `"FEATURE_NOT_ENABLED"`. */
|
|
607
|
+
code?: string;
|
|
608
|
+
/** Human-readable message from the API, when it sent one separately from the code. */
|
|
609
|
+
apiMessage?: string;
|
|
610
|
+
/** Whether retrying the same request may succeed. */
|
|
611
|
+
retryable?: boolean;
|
|
612
|
+
/** Server trace id — include it when contacting support. */
|
|
613
|
+
traceId?: string;
|
|
614
|
+
}
|
|
574
615
|
declare class BitPalError extends Error {
|
|
575
616
|
readonly statusCode: number;
|
|
576
|
-
|
|
617
|
+
readonly code?: string;
|
|
618
|
+
readonly apiMessage?: string;
|
|
619
|
+
readonly retryable?: boolean;
|
|
620
|
+
readonly traceId?: string;
|
|
621
|
+
constructor(message: string, statusCode: number, details?: BitPalErrorDetails);
|
|
577
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* API 에러 body → BitPalError 상세. 두 가지 shape 를 모두 읽는다:
|
|
625
|
+
* - 표준: `{ error: <message>, code, retryable, trace_id }`
|
|
626
|
+
* - 일부 라우트: `{ error: <CODE>, message }`
|
|
627
|
+
* `message`(Error.message)는 0.11 과 같게 `body.error` 를 유지한다(하위 호환) — 추가 정보는 필드로만.
|
|
628
|
+
*/
|
|
629
|
+
declare function parseApiErrorBody(body: unknown): BitPalErrorDetails;
|
|
578
630
|
|
|
579
631
|
/**
|
|
580
632
|
* @bitpal/checkout — Webhook 서명 검증 + 이벤트 타입
|
|
@@ -750,6 +802,7 @@ interface X402Requirements {
|
|
|
750
802
|
x402Version: 1;
|
|
751
803
|
accepts: X402Accept[];
|
|
752
804
|
}
|
|
805
|
+
/** EIP-3009 `TransferWithAuthorization` 의 서명 대상 필드. x402 표준 `payload.authorization`. */
|
|
753
806
|
interface Eip3009Authorization {
|
|
754
807
|
from: string;
|
|
755
808
|
to: string;
|
|
@@ -757,21 +810,23 @@ interface Eip3009Authorization {
|
|
|
757
810
|
validAfter: string;
|
|
758
811
|
validBefore: string;
|
|
759
812
|
nonce: string;
|
|
760
|
-
signature: {
|
|
761
|
-
v: number;
|
|
762
|
-
r: string;
|
|
763
|
-
s: string;
|
|
764
|
-
};
|
|
765
813
|
}
|
|
814
|
+
/**
|
|
815
|
+
* x402 표준 payload 그대로다 — 단일 authorization + 65바이트 packed 서명.
|
|
816
|
+
*
|
|
817
|
+
* 0.10.0 까지는 `{ merchant, fee }` 2건이었다. 포워더 없이 수수료를 나누려면 payer 가 두 번
|
|
818
|
+
* 서명해야 했고, 그 탓에 순정 x402 클라이언트가 BitPal 머천트에게 결제할 수 없었다.
|
|
819
|
+
* 이제 분배는 `payTo`(포워더) 주소가 커밋하므로 서명이 1건이면 된다.
|
|
820
|
+
*/
|
|
766
821
|
interface X402PaymentPayload {
|
|
767
822
|
x402Version: 1;
|
|
768
823
|
scheme: 'exact';
|
|
769
824
|
/** x402 wire 이름 — 'base' / 'base-sepolia'. */
|
|
770
825
|
network: string;
|
|
771
826
|
payload: {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
827
|
+
/** 65바이트 packed hex(`0x` + r + s + v). */
|
|
828
|
+
signature: string;
|
|
829
|
+
authorization: Eip3009Authorization;
|
|
775
830
|
};
|
|
776
831
|
}
|
|
777
832
|
/** `ok` = 이번 호출이 최초 점유 / `inflight` = 다른 요청이 처리 중 / `used` = 이미 리소스를 내줌. */
|
|
@@ -1080,11 +1135,18 @@ declare function createX402Payment(options: CreateX402PaymentOptions): Promise<X
|
|
|
1080
1135
|
* 65바이트(r‖s‖v)와 64바이트 EIP-2098 compact(r‖yParityAndS) 둘 다 받는다 — viem 의
|
|
1081
1136
|
* `signTypedData` 는 65바이트를 주지만 일부 지갑·라이브러리는 compact 를 돌려준다.
|
|
1082
1137
|
*/
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1138
|
+
/**
|
|
1139
|
+
* 지갑이 돌려준 서명을 **65바이트 packed hex** 로 수렴시킨다. x402 표준이 그 형태다.
|
|
1140
|
+
*
|
|
1141
|
+
* 두 가지를 정규화한다:
|
|
1142
|
+
* - EIP-2098 compact(64바이트) — 일부 지갑이 이걸 낸다. s 의 최상위 비트가 yParity 라 떼어내고
|
|
1143
|
+
* v 를 복원해 65바이트로 편다.
|
|
1144
|
+
* - v 가 0/1 인 경우 — 온체인 ecrecover 규약인 27/28 로 맞춘다.
|
|
1145
|
+
*
|
|
1146
|
+
* 서버가 130 hex 만 받으므로 여기서 안 맞추면 그쪽에서 거부된다. 그 외 값은 recover 가 어긋나
|
|
1147
|
+
* 어차피 실패하므로 여기서 끊는다.
|
|
1148
|
+
*/
|
|
1149
|
+
declare function normalizeSignature(signature: string): string;
|
|
1088
1150
|
|
|
1089
1151
|
/**
|
|
1090
1152
|
* @bitpal/checkout — BitPal Checkout SDK
|
|
@@ -1114,4 +1176,4 @@ declare class BitPal {
|
|
|
1114
1176
|
constructor(config: BitPalConfig | string);
|
|
1115
1177
|
}
|
|
1116
1178
|
|
|
1117
|
-
export { type ApiResponse, BitPal, BitPalCheckoutClient, type BitPalConfig, BitPalError, CHECKOUT_WEBHOOK_EVENTS, type CheckoutLineItemInput, type CheckoutPaymentLink, type CheckoutPrice, type CheckoutProduct, type CheckoutSession, type CheckoutWebhookEvent, type CreatePaymentLinkParams, type CreatePriceParams, type CreateProductParams, type CreateSessionParams, type CreateX402PaymentOptions, type DepositAddress, type Eip3009Authorization, type Eip712Domain, type FeePreview, type IdempotencyOptions, type IssueDepositAddressParams, type LineItem, type ListPaymentLinksParams, type ListPricesParams, type ListProductsParams, type ListResponse, PaymentLinksResource, type PaymentOption, type PriceLineItem, PricesResource, ProductsResource, type PublicSession, type SessionStatus, TRANSFER_WITH_AUTHORIZATION_TYPES, type UpdatePaymentLinkParams, type UpdatePriceParams, type UpdateProductParams, WEBHOOK_HEADERS, type WebhookPayload, type X402Accept, type X402ClaimState, type X402FeeBreakdown, X402Gate, type X402GateOptions, type X402GateResult, type X402MiddlewareOptions, type X402PaymentPayload, type X402PaymentResult, type X402ReplayStore, type X402Request, type X402Requirements, type X402Response, type X402SettledPayment, type X402Signer, type X402TypedDataRequest, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER, createMemoryReplayStore, createX402Payment, decodePaymentHeader, encodePaymentHeader, fromAtomic, fromAtomicUSDC,
|
|
1179
|
+
export { type ApiResponse, BitPal, BitPalCheckoutClient, type BitPalConfig, BitPalError, type BitPalErrorDetails, CHECKOUT_WEBHOOK_EVENTS, type CheckoutLineItemInput, type CheckoutPaymentLink, type CheckoutPrice, type CheckoutProduct, type CheckoutSession, type CheckoutWebhookEvent, type CreatePaymentLinkParams, type CreatePriceParams, type CreateProductParams, type CreateSessionParams, type CreateX402PaymentOptions, type DepositAddress, type Eip3009Authorization, type Eip712Domain, type FeePreview, type IdempotencyOptions, type IssueDepositAddressParams, type LineItem, type ListPaymentLinksParams, type ListPricesParams, type ListProductsParams, type ListResponse, PaymentLinksResource, type PaymentOption, type PriceLineItem, PricesResource, ProductsResource, type PublicSession, type SessionStatus, TRANSFER_WITH_AUTHORIZATION_TYPES, type UpdatePaymentLinkParams, type UpdatePriceParams, type UpdateProductParams, WEBHOOK_HEADERS, type WebhookPayload, type X402Accept, type X402ClaimState, type X402FeeBreakdown, X402Gate, type X402GateOptions, type X402GateResult, type X402MiddlewareOptions, type X402PaymentPayload, type X402PaymentResult, type X402ReplayStore, type X402Request, type X402Requirements, type X402Response, type X402SettledPayment, type X402Signer, type X402TypedDataRequest, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER, createMemoryReplayStore, createX402Payment, decodePaymentHeader, encodePaymentHeader, fromAtomic, fromAtomicUSDC, normalizeSignature, parseApiErrorBody, parseWebhookEvent, toAtomic, toAtomicUSDC, verifyWebhookSignature, x402 };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,9 +9,11 @@ interface BitPalConfig {
|
|
|
9
9
|
*
|
|
10
10
|
* BitPal 콘솔 → Developers → API Keys 에서 발급.
|
|
11
11
|
*
|
|
12
|
-
* **선택**: createSession/listSessions/products 등 서버 메서드는 필수.
|
|
13
|
-
* (getPublicSession/getStatus/issueDepositAddress)는
|
|
14
|
-
*
|
|
12
|
+
* **선택**: createSession/listSessions/products 등 서버 메서드는 필수. buyer-facing 공개 메서드
|
|
13
|
+
* (getPublicSession/getStatus/issueDepositAddress)는 apiKey 가 필요 없다(issueDepositAddress 는 session_token 필요).
|
|
14
|
+
* 단 **브라우저(CORS)** 에서 임의 머천트 도메인이 직접 부를 수 있는 것은 `getPublicSession` 뿐이다 —
|
|
15
|
+
* `issueDepositAddress`/`getStatus` 는 머천트 백엔드를 경유해 호출한다(자체 결제 UI = 헤드리스 checkout).
|
|
16
|
+
* 절대 secret 키를 브라우저에 노출하지 말 것.
|
|
15
17
|
*/
|
|
16
18
|
apiKey?: string;
|
|
17
19
|
/**
|
|
@@ -25,28 +27,30 @@ interface BitPalConfig {
|
|
|
25
27
|
/** 요청 타임아웃 (ms, 기본값: 30000) */
|
|
26
28
|
timeout?: number;
|
|
27
29
|
}
|
|
28
|
-
/** 응답/정규화된 line item — amount 는 항상 atomic
|
|
30
|
+
/** 응답/정규화된 line item — amount 는 항상 canonical 6dp atomic 정수(실제 결제 토큰 decimals 아님). */
|
|
29
31
|
interface LineItem {
|
|
30
32
|
name: string;
|
|
31
|
-
/**
|
|
33
|
+
/** canonical 6dp atomic 정수 문자열("1"="1000000", "29"="29000000"). */
|
|
32
34
|
amount: string;
|
|
33
35
|
currency: string;
|
|
34
36
|
quantity?: number;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* 세션 생성 입력용 line item. 금액은 둘 중 **하나**:
|
|
38
|
-
* - `amount`(권장): 사람 표기
|
|
39
|
-
* ※
|
|
40
|
-
*
|
|
40
|
+
* - `amount`(권장): 사람 표기 canonical 6dp 문자열(예 "29", "0.5", "29.00"). decimal 신경 쓸 필요 없음.
|
|
41
|
+
* ※ `currency`(예: 'USDC'/'USDT'/'JPYC')가 실제 결제 통화를 결정한다 — `amount`는 그 통화의 canonical
|
|
42
|
+
* 6dp 표기일 뿐 항상 USD 를 뜻하지 않는다(예: currency='JPYC' + amount="29" → 29 JPYC/29엔, 환율
|
|
43
|
+
* 변환 없음). 실제 결제 토큰 decimals(USDC 6dp / JPYC 18dp 등)로의 재스케일은 발급 시 서버가 처리.
|
|
44
|
+
* - `amount_atomic`: 이미 raw canonical 6dp 정수 문자열($1="1000000")인 경우(고급/기존 코드).
|
|
41
45
|
* 둘 다 지정하거나 둘 다 생략하면 SDK 가 에러를 throw 한다.
|
|
42
46
|
*/
|
|
43
47
|
interface LineItemInput {
|
|
44
48
|
name: string;
|
|
45
49
|
currency: string;
|
|
46
50
|
quantity?: number;
|
|
47
|
-
/** 사람 표기
|
|
51
|
+
/** 사람 표기 canonical 6dp 금액(예 "29", "0.5") — 권장. amount_atomic 과 상호배타. */
|
|
48
52
|
amount?: string;
|
|
49
|
-
/** raw
|
|
53
|
+
/** raw canonical 6dp 정수($1="1000000") — 고급/기존. amount 와 상호배타. */
|
|
50
54
|
amount_atomic?: string;
|
|
51
55
|
}
|
|
52
56
|
interface PriceLineItem {
|
|
@@ -57,7 +61,7 @@ interface PriceLineItem {
|
|
|
57
61
|
type CheckoutLineItemInput = LineItemInput | PriceLineItem;
|
|
58
62
|
interface CreateSessionParams {
|
|
59
63
|
line_items: CheckoutLineItemInput[];
|
|
60
|
-
/**
|
|
64
|
+
/** @deprecated 서버가 사용하지 않는다(무시됨). 입금자 주소는 결제 시 온체인에서 기록된다. */
|
|
61
65
|
payer_wallet?: string;
|
|
62
66
|
/** 결제 체인 (예: eip155:8453). 단일 고정 — allowed_pay_chains와 상호 배타. */
|
|
63
67
|
pay_chain?: string;
|
|
@@ -78,11 +82,19 @@ interface CreateSessionParams {
|
|
|
78
82
|
chain: string;
|
|
79
83
|
token: string;
|
|
80
84
|
}>;
|
|
81
|
-
/**
|
|
85
|
+
/** @deprecated 서버가 사용하지 않는다(무시됨). 결제 자산은 `allowed_assets` 로 지정한다. */
|
|
82
86
|
pay_asset?: string;
|
|
83
87
|
/** 허용 오차 (%, 기본값: 2.00) */
|
|
84
88
|
tolerance_percent?: string;
|
|
85
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* 결제 대기 시간(분). 1~60, 기본 15. 이 시간이 지나면 세션이 만료된다
|
|
91
|
+
* (만료 후 도착한 정확 금액은 7일 안이면 늦은 결제로 인정 — `late: true`).
|
|
92
|
+
*/
|
|
93
|
+
expires_in_minutes?: number;
|
|
94
|
+
/**
|
|
95
|
+
* @deprecated `expires_in_minutes` 를 쓴다. 60~3600 초만 허용되고 분 단위로 올림해 보낸다.
|
|
96
|
+
* (0.11 까지는 서버가 이 필드를 몰라 무시했고, 항상 기본 15분이 적용됐다.)
|
|
97
|
+
*/
|
|
86
98
|
expires_in_seconds?: number;
|
|
87
99
|
/** 메타데이터 (모든 값은 string 이어야 함) */
|
|
88
100
|
metadata?: Record<string, string>;
|
|
@@ -141,9 +153,18 @@ interface PublicSession {
|
|
|
141
153
|
status: string;
|
|
142
154
|
mode: string | null;
|
|
143
155
|
currency: string;
|
|
144
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* 주문 총액 — **canonical μUSD(6dp) 정수 문자열**(가격 통화 기준, $1 = "1000000"). 결제 토큰 decimals 와 무관하다
|
|
158
|
+
* (18dp 토큰으로 결제해도 6dp). 온체인으로 보낼 토큰 단위 금액은 `pay_amount`(또는 발급 응답 `expectedAmount`).
|
|
159
|
+
*/
|
|
145
160
|
amount_total: string;
|
|
161
|
+
/** 지금까지 입금주소에 들어온 금액 — **결제 토큰 atomic**(`token_decimals` 기준). 미입금이면 null. */
|
|
146
162
|
amount_received?: string | null;
|
|
163
|
+
/**
|
|
164
|
+
* 선택된 결제 토큰 단위의 총액(atomic, `token_decimals` 기준) — 구매자가 송금할 정확 금액. 자산 미선택이면 null.
|
|
165
|
+
* = canonicalToTokenAtomic(amount_total, token_decimals). 부족액 = pay_amount − amount_received.
|
|
166
|
+
*/
|
|
167
|
+
pay_amount?: string | null;
|
|
147
168
|
pay_chain: string | null;
|
|
148
169
|
pay_asset: string | null;
|
|
149
170
|
/** 발급된 주문별 forwarder 입금주소(미발급이면 null). */
|
|
@@ -152,7 +173,7 @@ interface PublicSession {
|
|
|
152
173
|
payment_options: PaymentOption[];
|
|
153
174
|
chain_id: number | null;
|
|
154
175
|
token_address: string | null;
|
|
155
|
-
/** 선택된 pay 토큰 decimals(발급 후).
|
|
176
|
+
/** 선택된 pay 토큰 decimals(발급 후). amount_received / pay_amount 해석에 사용 — 6dp 가정 금지(amount_total 은 항상 6dp). */
|
|
156
177
|
token_decimals?: number | null;
|
|
157
178
|
tx_hash: string | null;
|
|
158
179
|
release_tx_hash?: string | null;
|
|
@@ -284,16 +305,23 @@ interface UpdateProductParams {
|
|
|
284
305
|
}
|
|
285
306
|
/**
|
|
286
307
|
* 가격 생성 입력. 금액은 둘 중 **하나** (line item 과 동일 모델):
|
|
287
|
-
* - `amount`(권장): 사람 표기
|
|
288
|
-
* - `amount_atomic`: raw
|
|
308
|
+
* - `amount`(권장): 사람 표기 canonical 6dp 문자열(예 "29", "0.5"). decimal 신경 쓸 필요 없음.
|
|
309
|
+
* - `amount_atomic`: raw canonical 6dp 정수($1="1000000") — 고급/기존.
|
|
289
310
|
* 둘 다 지정하거나 둘 다 생략하면 서버가 400 을 반환한다.
|
|
311
|
+
*
|
|
312
|
+
* `amount`/`amount_atomic`은 실제 결제 토큰의 decimals 가 아니라 **항상 canonical 6dp**다 — 서버가
|
|
313
|
+
* 결제 시점에 실제 토큰 decimals(예: JPYC=18dp)로 재스케일한다(1:1 가정, 환율 변환 없음). 즉
|
|
314
|
+
* `token_symbol: 'JPYC'`로 "29"를 등록하면 29 JPYC(≈29엔)로 결제되지, 29 USD 상당의 JPYC로
|
|
315
|
+
* 환산되지 않는다.
|
|
316
|
+
*
|
|
317
|
+
* `currency`는 입력받지 않는다 — 서버가 `token_symbol`에서 파생한다(불일치 방지).
|
|
290
318
|
*/
|
|
291
319
|
interface CreatePriceParams {
|
|
292
|
-
/** 사람 표기
|
|
320
|
+
/** 사람 표기 canonical 6dp 금액(예 "29", "0.5") — 권장. amount_atomic 과 상호배타. */
|
|
293
321
|
amount?: string;
|
|
294
|
-
/** raw
|
|
322
|
+
/** raw canonical 6dp 정수($1="1000000") — 고급/기존. amount 와 상호배타. */
|
|
295
323
|
amount_atomic?: string;
|
|
296
|
-
currency
|
|
324
|
+
/** 'USDC' | 'USDT' | 'JPYC' — 미지정 시 'USDC'. 이 Price 의 유일한 결제 자산(currency 는 여기서 파생). */
|
|
297
325
|
token_symbol?: string;
|
|
298
326
|
billing_type?: 'one_time';
|
|
299
327
|
nickname?: string;
|
|
@@ -492,14 +520,16 @@ declare class BitPalCheckoutClient {
|
|
|
492
520
|
/**
|
|
493
521
|
* 체크아웃 세션 생성.
|
|
494
522
|
*
|
|
495
|
-
* `line_items[].amount` 는 사람 표기
|
|
496
|
-
*
|
|
523
|
+
* `line_items[].amount` 는 사람 표기 canonical 6dp 문자열("29", "0.5") — decimal 계산 불필요.
|
|
524
|
+
* `currency`('USDC'/'USDT'/'JPYC')가 실제 결제 통화를 결정하고, amount 는 항상 그 통화 기준 값이다
|
|
525
|
+
* (USD 로 고정된 게 아님 — currency='JPYC' + amount='1500' → 1500엔/1500 JPYC, 환율 변환 없음).
|
|
526
|
+
* 이미 raw canonical 6dp 정수라면 `amount_atomic`("29000000") 사용(고급). 둘은 상호 배타.
|
|
497
527
|
*
|
|
498
528
|
* @example
|
|
499
529
|
* import { BitPal } from '@bitpal/checkout';
|
|
500
530
|
* const bp = new BitPal('bp_test_...');
|
|
501
531
|
* const { data } = await bp.checkout.createSession({
|
|
502
|
-
* // amount: 사람 표기
|
|
532
|
+
* // amount: 사람 표기 canonical 6dp("29", "0.5"). 체인/토큰 decimal 은 발급 시 서버가 재스케일.
|
|
503
533
|
* line_items: [{ name: 'Pro', amount: '29', currency: 'USDC' }],
|
|
504
534
|
* });
|
|
505
535
|
* console.log(data.url); // → buyer를 redirect할 결제 페이지
|
|
@@ -571,10 +601,32 @@ declare class BitPalCheckoutClient {
|
|
|
571
601
|
amountAtomic: string;
|
|
572
602
|
}): Promise<ApiResponse<FeePreview>>;
|
|
573
603
|
}
|
|
604
|
+
/** Structured fields parsed from an API error body. All optional — older endpoints omit some. */
|
|
605
|
+
interface BitPalErrorDetails {
|
|
606
|
+
/** Machine-readable error code, e.g. `"FEATURE_NOT_ENABLED"`. */
|
|
607
|
+
code?: string;
|
|
608
|
+
/** Human-readable message from the API, when it sent one separately from the code. */
|
|
609
|
+
apiMessage?: string;
|
|
610
|
+
/** Whether retrying the same request may succeed. */
|
|
611
|
+
retryable?: boolean;
|
|
612
|
+
/** Server trace id — include it when contacting support. */
|
|
613
|
+
traceId?: string;
|
|
614
|
+
}
|
|
574
615
|
declare class BitPalError extends Error {
|
|
575
616
|
readonly statusCode: number;
|
|
576
|
-
|
|
617
|
+
readonly code?: string;
|
|
618
|
+
readonly apiMessage?: string;
|
|
619
|
+
readonly retryable?: boolean;
|
|
620
|
+
readonly traceId?: string;
|
|
621
|
+
constructor(message: string, statusCode: number, details?: BitPalErrorDetails);
|
|
577
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* API 에러 body → BitPalError 상세. 두 가지 shape 를 모두 읽는다:
|
|
625
|
+
* - 표준: `{ error: <message>, code, retryable, trace_id }`
|
|
626
|
+
* - 일부 라우트: `{ error: <CODE>, message }`
|
|
627
|
+
* `message`(Error.message)는 0.11 과 같게 `body.error` 를 유지한다(하위 호환) — 추가 정보는 필드로만.
|
|
628
|
+
*/
|
|
629
|
+
declare function parseApiErrorBody(body: unknown): BitPalErrorDetails;
|
|
578
630
|
|
|
579
631
|
/**
|
|
580
632
|
* @bitpal/checkout — Webhook 서명 검증 + 이벤트 타입
|
|
@@ -750,6 +802,7 @@ interface X402Requirements {
|
|
|
750
802
|
x402Version: 1;
|
|
751
803
|
accepts: X402Accept[];
|
|
752
804
|
}
|
|
805
|
+
/** EIP-3009 `TransferWithAuthorization` 의 서명 대상 필드. x402 표준 `payload.authorization`. */
|
|
753
806
|
interface Eip3009Authorization {
|
|
754
807
|
from: string;
|
|
755
808
|
to: string;
|
|
@@ -757,21 +810,23 @@ interface Eip3009Authorization {
|
|
|
757
810
|
validAfter: string;
|
|
758
811
|
validBefore: string;
|
|
759
812
|
nonce: string;
|
|
760
|
-
signature: {
|
|
761
|
-
v: number;
|
|
762
|
-
r: string;
|
|
763
|
-
s: string;
|
|
764
|
-
};
|
|
765
813
|
}
|
|
814
|
+
/**
|
|
815
|
+
* x402 표준 payload 그대로다 — 단일 authorization + 65바이트 packed 서명.
|
|
816
|
+
*
|
|
817
|
+
* 0.10.0 까지는 `{ merchant, fee }` 2건이었다. 포워더 없이 수수료를 나누려면 payer 가 두 번
|
|
818
|
+
* 서명해야 했고, 그 탓에 순정 x402 클라이언트가 BitPal 머천트에게 결제할 수 없었다.
|
|
819
|
+
* 이제 분배는 `payTo`(포워더) 주소가 커밋하므로 서명이 1건이면 된다.
|
|
820
|
+
*/
|
|
766
821
|
interface X402PaymentPayload {
|
|
767
822
|
x402Version: 1;
|
|
768
823
|
scheme: 'exact';
|
|
769
824
|
/** x402 wire 이름 — 'base' / 'base-sepolia'. */
|
|
770
825
|
network: string;
|
|
771
826
|
payload: {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
827
|
+
/** 65바이트 packed hex(`0x` + r + s + v). */
|
|
828
|
+
signature: string;
|
|
829
|
+
authorization: Eip3009Authorization;
|
|
775
830
|
};
|
|
776
831
|
}
|
|
777
832
|
/** `ok` = 이번 호출이 최초 점유 / `inflight` = 다른 요청이 처리 중 / `used` = 이미 리소스를 내줌. */
|
|
@@ -1080,11 +1135,18 @@ declare function createX402Payment(options: CreateX402PaymentOptions): Promise<X
|
|
|
1080
1135
|
* 65바이트(r‖s‖v)와 64바이트 EIP-2098 compact(r‖yParityAndS) 둘 다 받는다 — viem 의
|
|
1081
1136
|
* `signTypedData` 는 65바이트를 주지만 일부 지갑·라이브러리는 compact 를 돌려준다.
|
|
1082
1137
|
*/
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1138
|
+
/**
|
|
1139
|
+
* 지갑이 돌려준 서명을 **65바이트 packed hex** 로 수렴시킨다. x402 표준이 그 형태다.
|
|
1140
|
+
*
|
|
1141
|
+
* 두 가지를 정규화한다:
|
|
1142
|
+
* - EIP-2098 compact(64바이트) — 일부 지갑이 이걸 낸다. s 의 최상위 비트가 yParity 라 떼어내고
|
|
1143
|
+
* v 를 복원해 65바이트로 편다.
|
|
1144
|
+
* - v 가 0/1 인 경우 — 온체인 ecrecover 규약인 27/28 로 맞춘다.
|
|
1145
|
+
*
|
|
1146
|
+
* 서버가 130 hex 만 받으므로 여기서 안 맞추면 그쪽에서 거부된다. 그 외 값은 recover 가 어긋나
|
|
1147
|
+
* 어차피 실패하므로 여기서 끊는다.
|
|
1148
|
+
*/
|
|
1149
|
+
declare function normalizeSignature(signature: string): string;
|
|
1088
1150
|
|
|
1089
1151
|
/**
|
|
1090
1152
|
* @bitpal/checkout — BitPal Checkout SDK
|
|
@@ -1114,4 +1176,4 @@ declare class BitPal {
|
|
|
1114
1176
|
constructor(config: BitPalConfig | string);
|
|
1115
1177
|
}
|
|
1116
1178
|
|
|
1117
|
-
export { type ApiResponse, BitPal, BitPalCheckoutClient, type BitPalConfig, BitPalError, CHECKOUT_WEBHOOK_EVENTS, type CheckoutLineItemInput, type CheckoutPaymentLink, type CheckoutPrice, type CheckoutProduct, type CheckoutSession, type CheckoutWebhookEvent, type CreatePaymentLinkParams, type CreatePriceParams, type CreateProductParams, type CreateSessionParams, type CreateX402PaymentOptions, type DepositAddress, type Eip3009Authorization, type Eip712Domain, type FeePreview, type IdempotencyOptions, type IssueDepositAddressParams, type LineItem, type ListPaymentLinksParams, type ListPricesParams, type ListProductsParams, type ListResponse, PaymentLinksResource, type PaymentOption, type PriceLineItem, PricesResource, ProductsResource, type PublicSession, type SessionStatus, TRANSFER_WITH_AUTHORIZATION_TYPES, type UpdatePaymentLinkParams, type UpdatePriceParams, type UpdateProductParams, WEBHOOK_HEADERS, type WebhookPayload, type X402Accept, type X402ClaimState, type X402FeeBreakdown, X402Gate, type X402GateOptions, type X402GateResult, type X402MiddlewareOptions, type X402PaymentPayload, type X402PaymentResult, type X402ReplayStore, type X402Request, type X402Requirements, type X402Response, type X402SettledPayment, type X402Signer, type X402TypedDataRequest, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER, createMemoryReplayStore, createX402Payment, decodePaymentHeader, encodePaymentHeader, fromAtomic, fromAtomicUSDC,
|
|
1179
|
+
export { type ApiResponse, BitPal, BitPalCheckoutClient, type BitPalConfig, BitPalError, type BitPalErrorDetails, CHECKOUT_WEBHOOK_EVENTS, type CheckoutLineItemInput, type CheckoutPaymentLink, type CheckoutPrice, type CheckoutProduct, type CheckoutSession, type CheckoutWebhookEvent, type CreatePaymentLinkParams, type CreatePriceParams, type CreateProductParams, type CreateSessionParams, type CreateX402PaymentOptions, type DepositAddress, type Eip3009Authorization, type Eip712Domain, type FeePreview, type IdempotencyOptions, type IssueDepositAddressParams, type LineItem, type ListPaymentLinksParams, type ListPricesParams, type ListProductsParams, type ListResponse, PaymentLinksResource, type PaymentOption, type PriceLineItem, PricesResource, ProductsResource, type PublicSession, type SessionStatus, TRANSFER_WITH_AUTHORIZATION_TYPES, type UpdatePaymentLinkParams, type UpdatePriceParams, type UpdateProductParams, WEBHOOK_HEADERS, type WebhookPayload, type X402Accept, type X402ClaimState, type X402FeeBreakdown, X402Gate, type X402GateOptions, type X402GateResult, type X402MiddlewareOptions, type X402PaymentPayload, type X402PaymentResult, type X402ReplayStore, type X402Request, type X402Requirements, type X402Response, type X402SettledPayment, type X402Signer, type X402TypedDataRequest, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER, createMemoryReplayStore, createX402Payment, decodePaymentHeader, encodePaymentHeader, fromAtomic, fromAtomicUSDC, normalizeSignature, parseApiErrorBody, parseWebhookEvent, toAtomic, toAtomicUSDC, verifyWebhookSignature, x402 };
|