botonpay-sdk 1.3.1
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 +18 -0
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +220 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.js +1 -0
- package/package.json +34 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@botonpay/sdk` are documented here.
|
|
4
|
+
The project follows [Semantic Versioning](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [1.3.0] - 2026-07-09
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- Initial public release of the official BOTONPAY TypeScript / JavaScript SDK.
|
|
10
|
+
- `BotonPay` client with bearer-token auth, configurable `baseUrl`, custom `fetch`, and automatic retries on `429` / `5xx` (honours `Retry-After`).
|
|
11
|
+
- `deals.create` / `deals.list` / `deals.get` / `deals.cancel`.
|
|
12
|
+
- `rates.list`, `currencies.list`, `me()`.
|
|
13
|
+
- `verifyWebhook(rawBody, signature, secret)` — HMAC SHA-256 signature verification using Web Crypto (Node ≥ 18, Deno, Bun, browsers).
|
|
14
|
+
- `BotonPayError` with `code`, `status`, `requestId`, `retryAfter`, `details`.
|
|
15
|
+
- Idempotency (`Idempotency-Key`) and correlation (`X-Correlation-ID`) support per request.
|
|
16
|
+
- Dual ESM + CJS build with full `.d.ts` types.
|
|
17
|
+
|
|
18
|
+
[1.3.0]: https://docs.botonpay.com/changelog#1-3-0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BOTONPAY
|
|
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
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @botonpay/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript / JavaScript client for the [BOTONPAY Public API v1.3](https://docs.botonpay.com).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @botonpay/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { BotonPay } from "@botonpay/sdk";
|
|
15
|
+
|
|
16
|
+
const bp = new BotonPay({ apiKey: process.env.BOTONPAY_API_KEY! });
|
|
17
|
+
|
|
18
|
+
const deal = await bp.deals.create({
|
|
19
|
+
fiat: "RUB",
|
|
20
|
+
amount_fiat: 5000,
|
|
21
|
+
merchant_order_id: "ORDER-124",
|
|
22
|
+
callback_url: "https://merchant.com/webhook",
|
|
23
|
+
});
|
|
24
|
+
console.log(deal.deal.payment_url);
|
|
25
|
+
|
|
26
|
+
const list = await bp.deals.list({ status: "completed", page: 1, limit: 20 });
|
|
27
|
+
await bp.deals.cancel(deal.deal.id);
|
|
28
|
+
|
|
29
|
+
const rates = await bp.rates.list();
|
|
30
|
+
const me = await bp.me();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Idempotency
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
await bp.deals.create(payload, { idempotencyKey: crypto.randomUUID() });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Errors
|
|
40
|
+
|
|
41
|
+
Non-2xx responses throw `BotonPayError` with `code`, `status`, `message`, `requestId`, `retryAfter`, `details`.
|
|
42
|
+
|
|
43
|
+
## Webhooks
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { verifyWebhook } from "@botonpay/sdk";
|
|
47
|
+
const ok = await verifyWebhook(rawBody, req.headers["x-signature"], webhookSecret);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT
|
|
53
|
+
|
|
54
|
+
## Publishing (maintainers)
|
|
55
|
+
|
|
56
|
+
The package is published manually — no CI required.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd sdk/js
|
|
60
|
+
npm install # install devDependencies (tsup, typescript, vitest)
|
|
61
|
+
npm test # optional: run unit tests
|
|
62
|
+
npm run build # produces dist/ (ESM + CJS + .d.ts)
|
|
63
|
+
|
|
64
|
+
npm login # once per machine
|
|
65
|
+
npm publish --access public # publishes @botonpay/sdk to npm
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`npm publish` automatically runs `prepublishOnly` (which runs `npm run build`), so `dist/` is always fresh in the published tarball. Bump the `version` field in `package.json` and add a `CHANGELOG.md` entry before each release.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var g=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var T=(i,e)=>{for(var t in e)g(i,t,{get:e[t],enumerable:!0})},k=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of x(e))!v.call(i,s)&&s!==t&&g(i,s,{get:()=>e[s],enumerable:!(r=w(e,s))||r.enumerable});return i};var O=i=>k(g({},"__esModule",{value:!0}),i);var C={};T(C,{BotonPay:()=>p,BotonPayError:()=>c,SDK_VERSION:()=>b,default:()=>E,verifyWebhook:()=>I});module.exports=O(C);var b="1.3.0",A="https://api.botonpay.com",c=class extends Error{code;status;requestId;retryAfter;details;constructor(e){super(e.message),this.name="BotonPayError",this.code=e.code,this.status=e.status,this.requestId=e.requestId,this.retryAfter=e.retryAfter,this.details=e.details}},p=class{apiKey;baseUrl;fetchImpl;maxRetries;extraHeaders;constructor(e){if(!e.apiKey)throw new Error("BotonPay: apiKey is required");this.apiKey=e.apiKey,this.baseUrl=(e.baseUrl??A).replace(/\/$/,""),this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis),this.maxRetries=e.maxRetries??2,this.extraHeaders=e.headers??{}}async request(e,t,r,s={}){let u=`${this.baseUrl}${t}`,a={Authorization:`Bearer ${this.apiKey}`,Accept:"application/json","User-Agent":`botonpay-sdk-js/${b}`,...this.extraHeaders};r!==void 0&&(a["Content-Type"]="application/json"),s.idempotencyKey&&(a["Idempotency-Key"]=s.idempotencyKey),s.correlationId&&(a["X-Correlation-ID"]=s.correlationId);let o=0;for(;;){let n=await this.fetchImpl(u,{method:e,headers:a,body:r!==void 0?JSON.stringify(r):void 0,signal:s.signal}),l=await n.text(),f=n.headers.get("x-request-id")??void 0,m=n.headers.get("retry-after"),h=m?Number(m):void 0;if(n.ok)return l?JSON.parse(l):void 0;let y=o<this.maxRetries&&(n.status===429||n.status>=500),d={};try{d=l?JSON.parse(l):{}}catch{}let _=new c({code:d?.error?.code??`http_${n.status}`,status:n.status,message:d?.error?.message??n.statusText,requestId:f,retryAfter:h,details:d?.error?.details});if(!y)throw _;let q=(h??Math.pow(2,o))*1e3;await new Promise(R=>setTimeout(R,q)),o++}}deals={create:(e,t)=>this.request("POST","/api/public/v1/deals",e,t),list:(e={},t)=>{let r=new URLSearchParams;for(let[u,a]of Object.entries(e))a!==void 0&&r.set(u,String(a));let s=r.toString();return this.request("GET",`/api/public/v1/deals${s?"?"+s:""}`,void 0,t)},get:(e,t)=>this.request("GET",`/api/public/v1/deals/${encodeURIComponent(e)}`,void 0,t),cancel:(e,t)=>this.request("POST",`/api/public/v1/deals/${encodeURIComponent(e)}/cancel`,{},t),history:(e,t)=>this.request("GET",`/api/public/v1/deals/${encodeURIComponent(e)}/history`,void 0,t)};currencies={list:e=>this.request("GET","/api/public/v1/currencies",void 0,e)};rates={list:(e,t)=>this.request("GET",`/api/public/v1/rates${e?"?fiat="+encodeURIComponent(e):""}`,void 0,t)};webhooks={test:(e,t)=>this.request("POST","/api/public/v1/webhooks/test",e?{url:e}:{},t)};me=e=>this.request("GET","/api/public/v1/me",void 0,e);health=e=>this.request("GET","/api/public/v1/health",void 0,e);status=e=>this.request("GET","/api/public/v1/status",void 0,e);apiKeys={list:e=>this.request("GET","/api/public/v1/api-keys",void 0,e),create:(e,t)=>this.request("POST","/api/public/v1/api-keys",e,t),get:(e,t)=>this.request("GET",`/api/public/v1/api-keys/${encodeURIComponent(e)}`,void 0,t),update:(e,t,r)=>this.request("PATCH",`/api/public/v1/api-keys/${encodeURIComponent(e)}`,t,r),delete:(e,t)=>this.request("DELETE",`/api/public/v1/api-keys/${encodeURIComponent(e)}`,void 0,t)}};async function I(i,e,t){if(!e)return!1;let r=new TextEncoder,s=await crypto.subtle.importKey("raw",r.encode(t),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),u=await crypto.subtle.sign("HMAC",s,r.encode(i)),a=Array.from(new Uint8Array(u)).map(n=>n.toString(16).padStart(2,"0")).join("");if(a.length!==e.length)return!1;let o=0;for(let n=0;n<a.length;n++)o|=a.charCodeAt(n)^e.charCodeAt(n);return o===0}var E=p;0&&(module.exports={BotonPay,BotonPayError,SDK_VERSION,verifyWebhook});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @botonpay/sdk — official BOTONPAY Public API v1 client.
|
|
3
|
+
*/
|
|
4
|
+
declare const SDK_VERSION = "1.3.0";
|
|
5
|
+
interface BotonPayOptions {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
fetch?: typeof globalThis.fetch;
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
interface RequestOptions {
|
|
13
|
+
idempotencyKey?: string;
|
|
14
|
+
correlationId?: string;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
type ApiErrorCode = "invalid_request" | "invalid_api_key" | "forbidden" | "origin_not_allowed" | "not_found" | "rate_limited" | "conflict" | "unprocessable" | "internal_error";
|
|
18
|
+
declare class BotonPayError extends Error {
|
|
19
|
+
readonly code: ApiErrorCode | string;
|
|
20
|
+
readonly status: number;
|
|
21
|
+
readonly requestId?: string;
|
|
22
|
+
readonly retryAfter?: number;
|
|
23
|
+
readonly details?: unknown;
|
|
24
|
+
constructor(opts: {
|
|
25
|
+
code: string;
|
|
26
|
+
status: number;
|
|
27
|
+
message: string;
|
|
28
|
+
requestId?: string;
|
|
29
|
+
retryAfter?: number;
|
|
30
|
+
details?: unknown;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
interface Deal {
|
|
34
|
+
id: string;
|
|
35
|
+
external_id: string;
|
|
36
|
+
merchant_order_id: string | null;
|
|
37
|
+
status: "waiting_payment" | "paid" | "completed" | "cancelled" | "expired" | "disputed";
|
|
38
|
+
fiat: string;
|
|
39
|
+
amount_fiat: number;
|
|
40
|
+
amount_usdt: number;
|
|
41
|
+
rate: number;
|
|
42
|
+
created_at: string;
|
|
43
|
+
paid_at: string | null;
|
|
44
|
+
completed_at: string | null;
|
|
45
|
+
expires_at: string | null;
|
|
46
|
+
payment_url: string | null;
|
|
47
|
+
deal_url: string | null;
|
|
48
|
+
metadata: Record<string, unknown>;
|
|
49
|
+
is_test: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface CreateDealInput {
|
|
52
|
+
fiat?: string;
|
|
53
|
+
amount_fiat?: number;
|
|
54
|
+
merchant_order_id?: string;
|
|
55
|
+
callback_url?: string;
|
|
56
|
+
success_url?: string;
|
|
57
|
+
cancel_url?: string;
|
|
58
|
+
customer_id?: string;
|
|
59
|
+
label?: string;
|
|
60
|
+
metadata?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
interface ListDealsQuery {
|
|
63
|
+
status?: string;
|
|
64
|
+
date_from?: string;
|
|
65
|
+
date_to?: string;
|
|
66
|
+
merchant_order_id?: string;
|
|
67
|
+
page?: number;
|
|
68
|
+
limit?: number;
|
|
69
|
+
}
|
|
70
|
+
interface Paginated<T> {
|
|
71
|
+
success: true;
|
|
72
|
+
data: T[];
|
|
73
|
+
page: number;
|
|
74
|
+
limit: number;
|
|
75
|
+
total: number;
|
|
76
|
+
pages: number;
|
|
77
|
+
has_next: boolean;
|
|
78
|
+
has_prev: boolean;
|
|
79
|
+
}
|
|
80
|
+
declare class BotonPay {
|
|
81
|
+
private readonly apiKey;
|
|
82
|
+
private readonly baseUrl;
|
|
83
|
+
private readonly fetchImpl;
|
|
84
|
+
private readonly maxRetries;
|
|
85
|
+
private readonly extraHeaders;
|
|
86
|
+
constructor(opts: BotonPayOptions);
|
|
87
|
+
private request;
|
|
88
|
+
deals: {
|
|
89
|
+
create: (input: CreateDealInput, options?: RequestOptions) => Promise<{
|
|
90
|
+
success: true;
|
|
91
|
+
deal: Deal;
|
|
92
|
+
idempotent?: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
list: (query?: ListDealsQuery, options?: RequestOptions) => Promise<Paginated<Deal>>;
|
|
95
|
+
get: (id: string, options?: RequestOptions) => Promise<{
|
|
96
|
+
success: true;
|
|
97
|
+
deal: Deal;
|
|
98
|
+
}>;
|
|
99
|
+
cancel: (id: string, options?: RequestOptions) => Promise<{
|
|
100
|
+
success: true;
|
|
101
|
+
status: "cancelled";
|
|
102
|
+
idempotent?: boolean;
|
|
103
|
+
}>;
|
|
104
|
+
history: (id: string, options?: RequestOptions) => Promise<{
|
|
105
|
+
success: true;
|
|
106
|
+
data: {
|
|
107
|
+
deal_id: string;
|
|
108
|
+
external_id: string;
|
|
109
|
+
current_status: string;
|
|
110
|
+
history: Array<{
|
|
111
|
+
event: string;
|
|
112
|
+
at: string;
|
|
113
|
+
status?: string;
|
|
114
|
+
actor?: string;
|
|
115
|
+
metadata?: unknown;
|
|
116
|
+
}>;
|
|
117
|
+
};
|
|
118
|
+
}>;
|
|
119
|
+
};
|
|
120
|
+
currencies: {
|
|
121
|
+
list: (options?: RequestOptions) => Promise<{
|
|
122
|
+
success: true;
|
|
123
|
+
data: Array<{
|
|
124
|
+
code: string;
|
|
125
|
+
min_amount: number;
|
|
126
|
+
max_amount: number;
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
}>;
|
|
129
|
+
}>;
|
|
130
|
+
};
|
|
131
|
+
rates: {
|
|
132
|
+
list: (fiat?: string, options?: RequestOptions) => Promise<{
|
|
133
|
+
success: true;
|
|
134
|
+
data: {
|
|
135
|
+
base: string;
|
|
136
|
+
rates: Record<string, number>;
|
|
137
|
+
cached_seconds: number;
|
|
138
|
+
timestamp: string;
|
|
139
|
+
};
|
|
140
|
+
}>;
|
|
141
|
+
};
|
|
142
|
+
webhooks: {
|
|
143
|
+
test: (url?: string, options?: RequestOptions) => Promise<{
|
|
144
|
+
success: boolean;
|
|
145
|
+
data: {
|
|
146
|
+
url: string;
|
|
147
|
+
status_code: number | null;
|
|
148
|
+
latency_ms: number;
|
|
149
|
+
response_body: string | null;
|
|
150
|
+
error: string | null;
|
|
151
|
+
};
|
|
152
|
+
}>;
|
|
153
|
+
};
|
|
154
|
+
me: (options?: RequestOptions) => Promise<{
|
|
155
|
+
success: true;
|
|
156
|
+
data: unknown;
|
|
157
|
+
}>;
|
|
158
|
+
health: (options?: RequestOptions) => Promise<{
|
|
159
|
+
status: string;
|
|
160
|
+
version: string;
|
|
161
|
+
database: string;
|
|
162
|
+
webhooks: string;
|
|
163
|
+
exchange_rate: string;
|
|
164
|
+
uptime_seconds: number;
|
|
165
|
+
timestamp: string;
|
|
166
|
+
}>;
|
|
167
|
+
status: (options?: RequestOptions) => Promise<{
|
|
168
|
+
status: string;
|
|
169
|
+
checks: Record<string, unknown>;
|
|
170
|
+
}>;
|
|
171
|
+
apiKeys: {
|
|
172
|
+
list: (options?: RequestOptions) => Promise<{
|
|
173
|
+
success: true;
|
|
174
|
+
data: unknown[];
|
|
175
|
+
available_scopes: string[];
|
|
176
|
+
}>;
|
|
177
|
+
create: (input: {
|
|
178
|
+
name: string;
|
|
179
|
+
is_test?: boolean;
|
|
180
|
+
scopes?: string[];
|
|
181
|
+
allowed_fiats?: string[];
|
|
182
|
+
allowed_origins?: string[];
|
|
183
|
+
webhook_url?: string;
|
|
184
|
+
}, options?: RequestOptions) => Promise<{
|
|
185
|
+
success: true;
|
|
186
|
+
data: {
|
|
187
|
+
id: string;
|
|
188
|
+
key: string;
|
|
189
|
+
prefix: string;
|
|
190
|
+
scopes: string[];
|
|
191
|
+
};
|
|
192
|
+
}>;
|
|
193
|
+
get: (id: string, options?: RequestOptions) => Promise<{
|
|
194
|
+
success: true;
|
|
195
|
+
data: unknown;
|
|
196
|
+
}>;
|
|
197
|
+
update: (id: string, patch: Partial<{
|
|
198
|
+
name: string;
|
|
199
|
+
active: boolean;
|
|
200
|
+
scopes: string[];
|
|
201
|
+
allowed_fiats: string[];
|
|
202
|
+
allowed_origins: string[];
|
|
203
|
+
webhook_url: string | null;
|
|
204
|
+
}>, options?: RequestOptions) => Promise<{
|
|
205
|
+
success: true;
|
|
206
|
+
data: unknown;
|
|
207
|
+
}>;
|
|
208
|
+
delete: (id: string, options?: RequestOptions) => Promise<{
|
|
209
|
+
success: true;
|
|
210
|
+
data: {
|
|
211
|
+
id: string;
|
|
212
|
+
deleted: true;
|
|
213
|
+
};
|
|
214
|
+
}>;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** Verify an incoming webhook signature (HMAC-SHA256 hex of the raw JSON body). */
|
|
218
|
+
declare function verifyWebhook(rawBody: string, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
219
|
+
|
|
220
|
+
export { type ApiErrorCode, BotonPay, BotonPayError, type BotonPayOptions, type CreateDealInput, type Deal, type ListDealsQuery, type Paginated, type RequestOptions, SDK_VERSION, BotonPay as default, verifyWebhook };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @botonpay/sdk — official BOTONPAY Public API v1 client.
|
|
3
|
+
*/
|
|
4
|
+
declare const SDK_VERSION = "1.3.0";
|
|
5
|
+
interface BotonPayOptions {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
fetch?: typeof globalThis.fetch;
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
interface RequestOptions {
|
|
13
|
+
idempotencyKey?: string;
|
|
14
|
+
correlationId?: string;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
type ApiErrorCode = "invalid_request" | "invalid_api_key" | "forbidden" | "origin_not_allowed" | "not_found" | "rate_limited" | "conflict" | "unprocessable" | "internal_error";
|
|
18
|
+
declare class BotonPayError extends Error {
|
|
19
|
+
readonly code: ApiErrorCode | string;
|
|
20
|
+
readonly status: number;
|
|
21
|
+
readonly requestId?: string;
|
|
22
|
+
readonly retryAfter?: number;
|
|
23
|
+
readonly details?: unknown;
|
|
24
|
+
constructor(opts: {
|
|
25
|
+
code: string;
|
|
26
|
+
status: number;
|
|
27
|
+
message: string;
|
|
28
|
+
requestId?: string;
|
|
29
|
+
retryAfter?: number;
|
|
30
|
+
details?: unknown;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
interface Deal {
|
|
34
|
+
id: string;
|
|
35
|
+
external_id: string;
|
|
36
|
+
merchant_order_id: string | null;
|
|
37
|
+
status: "waiting_payment" | "paid" | "completed" | "cancelled" | "expired" | "disputed";
|
|
38
|
+
fiat: string;
|
|
39
|
+
amount_fiat: number;
|
|
40
|
+
amount_usdt: number;
|
|
41
|
+
rate: number;
|
|
42
|
+
created_at: string;
|
|
43
|
+
paid_at: string | null;
|
|
44
|
+
completed_at: string | null;
|
|
45
|
+
expires_at: string | null;
|
|
46
|
+
payment_url: string | null;
|
|
47
|
+
deal_url: string | null;
|
|
48
|
+
metadata: Record<string, unknown>;
|
|
49
|
+
is_test: boolean;
|
|
50
|
+
}
|
|
51
|
+
interface CreateDealInput {
|
|
52
|
+
fiat?: string;
|
|
53
|
+
amount_fiat?: number;
|
|
54
|
+
merchant_order_id?: string;
|
|
55
|
+
callback_url?: string;
|
|
56
|
+
success_url?: string;
|
|
57
|
+
cancel_url?: string;
|
|
58
|
+
customer_id?: string;
|
|
59
|
+
label?: string;
|
|
60
|
+
metadata?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
interface ListDealsQuery {
|
|
63
|
+
status?: string;
|
|
64
|
+
date_from?: string;
|
|
65
|
+
date_to?: string;
|
|
66
|
+
merchant_order_id?: string;
|
|
67
|
+
page?: number;
|
|
68
|
+
limit?: number;
|
|
69
|
+
}
|
|
70
|
+
interface Paginated<T> {
|
|
71
|
+
success: true;
|
|
72
|
+
data: T[];
|
|
73
|
+
page: number;
|
|
74
|
+
limit: number;
|
|
75
|
+
total: number;
|
|
76
|
+
pages: number;
|
|
77
|
+
has_next: boolean;
|
|
78
|
+
has_prev: boolean;
|
|
79
|
+
}
|
|
80
|
+
declare class BotonPay {
|
|
81
|
+
private readonly apiKey;
|
|
82
|
+
private readonly baseUrl;
|
|
83
|
+
private readonly fetchImpl;
|
|
84
|
+
private readonly maxRetries;
|
|
85
|
+
private readonly extraHeaders;
|
|
86
|
+
constructor(opts: BotonPayOptions);
|
|
87
|
+
private request;
|
|
88
|
+
deals: {
|
|
89
|
+
create: (input: CreateDealInput, options?: RequestOptions) => Promise<{
|
|
90
|
+
success: true;
|
|
91
|
+
deal: Deal;
|
|
92
|
+
idempotent?: boolean;
|
|
93
|
+
}>;
|
|
94
|
+
list: (query?: ListDealsQuery, options?: RequestOptions) => Promise<Paginated<Deal>>;
|
|
95
|
+
get: (id: string, options?: RequestOptions) => Promise<{
|
|
96
|
+
success: true;
|
|
97
|
+
deal: Deal;
|
|
98
|
+
}>;
|
|
99
|
+
cancel: (id: string, options?: RequestOptions) => Promise<{
|
|
100
|
+
success: true;
|
|
101
|
+
status: "cancelled";
|
|
102
|
+
idempotent?: boolean;
|
|
103
|
+
}>;
|
|
104
|
+
history: (id: string, options?: RequestOptions) => Promise<{
|
|
105
|
+
success: true;
|
|
106
|
+
data: {
|
|
107
|
+
deal_id: string;
|
|
108
|
+
external_id: string;
|
|
109
|
+
current_status: string;
|
|
110
|
+
history: Array<{
|
|
111
|
+
event: string;
|
|
112
|
+
at: string;
|
|
113
|
+
status?: string;
|
|
114
|
+
actor?: string;
|
|
115
|
+
metadata?: unknown;
|
|
116
|
+
}>;
|
|
117
|
+
};
|
|
118
|
+
}>;
|
|
119
|
+
};
|
|
120
|
+
currencies: {
|
|
121
|
+
list: (options?: RequestOptions) => Promise<{
|
|
122
|
+
success: true;
|
|
123
|
+
data: Array<{
|
|
124
|
+
code: string;
|
|
125
|
+
min_amount: number;
|
|
126
|
+
max_amount: number;
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
}>;
|
|
129
|
+
}>;
|
|
130
|
+
};
|
|
131
|
+
rates: {
|
|
132
|
+
list: (fiat?: string, options?: RequestOptions) => Promise<{
|
|
133
|
+
success: true;
|
|
134
|
+
data: {
|
|
135
|
+
base: string;
|
|
136
|
+
rates: Record<string, number>;
|
|
137
|
+
cached_seconds: number;
|
|
138
|
+
timestamp: string;
|
|
139
|
+
};
|
|
140
|
+
}>;
|
|
141
|
+
};
|
|
142
|
+
webhooks: {
|
|
143
|
+
test: (url?: string, options?: RequestOptions) => Promise<{
|
|
144
|
+
success: boolean;
|
|
145
|
+
data: {
|
|
146
|
+
url: string;
|
|
147
|
+
status_code: number | null;
|
|
148
|
+
latency_ms: number;
|
|
149
|
+
response_body: string | null;
|
|
150
|
+
error: string | null;
|
|
151
|
+
};
|
|
152
|
+
}>;
|
|
153
|
+
};
|
|
154
|
+
me: (options?: RequestOptions) => Promise<{
|
|
155
|
+
success: true;
|
|
156
|
+
data: unknown;
|
|
157
|
+
}>;
|
|
158
|
+
health: (options?: RequestOptions) => Promise<{
|
|
159
|
+
status: string;
|
|
160
|
+
version: string;
|
|
161
|
+
database: string;
|
|
162
|
+
webhooks: string;
|
|
163
|
+
exchange_rate: string;
|
|
164
|
+
uptime_seconds: number;
|
|
165
|
+
timestamp: string;
|
|
166
|
+
}>;
|
|
167
|
+
status: (options?: RequestOptions) => Promise<{
|
|
168
|
+
status: string;
|
|
169
|
+
checks: Record<string, unknown>;
|
|
170
|
+
}>;
|
|
171
|
+
apiKeys: {
|
|
172
|
+
list: (options?: RequestOptions) => Promise<{
|
|
173
|
+
success: true;
|
|
174
|
+
data: unknown[];
|
|
175
|
+
available_scopes: string[];
|
|
176
|
+
}>;
|
|
177
|
+
create: (input: {
|
|
178
|
+
name: string;
|
|
179
|
+
is_test?: boolean;
|
|
180
|
+
scopes?: string[];
|
|
181
|
+
allowed_fiats?: string[];
|
|
182
|
+
allowed_origins?: string[];
|
|
183
|
+
webhook_url?: string;
|
|
184
|
+
}, options?: RequestOptions) => Promise<{
|
|
185
|
+
success: true;
|
|
186
|
+
data: {
|
|
187
|
+
id: string;
|
|
188
|
+
key: string;
|
|
189
|
+
prefix: string;
|
|
190
|
+
scopes: string[];
|
|
191
|
+
};
|
|
192
|
+
}>;
|
|
193
|
+
get: (id: string, options?: RequestOptions) => Promise<{
|
|
194
|
+
success: true;
|
|
195
|
+
data: unknown;
|
|
196
|
+
}>;
|
|
197
|
+
update: (id: string, patch: Partial<{
|
|
198
|
+
name: string;
|
|
199
|
+
active: boolean;
|
|
200
|
+
scopes: string[];
|
|
201
|
+
allowed_fiats: string[];
|
|
202
|
+
allowed_origins: string[];
|
|
203
|
+
webhook_url: string | null;
|
|
204
|
+
}>, options?: RequestOptions) => Promise<{
|
|
205
|
+
success: true;
|
|
206
|
+
data: unknown;
|
|
207
|
+
}>;
|
|
208
|
+
delete: (id: string, options?: RequestOptions) => Promise<{
|
|
209
|
+
success: true;
|
|
210
|
+
data: {
|
|
211
|
+
id: string;
|
|
212
|
+
deleted: true;
|
|
213
|
+
};
|
|
214
|
+
}>;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** Verify an incoming webhook signature (HMAC-SHA256 hex of the raw JSON body). */
|
|
218
|
+
declare function verifyWebhook(rawBody: string, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
|
|
219
|
+
|
|
220
|
+
export { type ApiErrorCode, BotonPay, BotonPayError, type BotonPayOptions, type CreateDealInput, type Deal, type ListDealsQuery, type Paginated, type RequestOptions, SDK_VERSION, BotonPay as default, verifyWebhook };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var q="1.3.0",R="https://api.botonpay.com",c=class extends Error{code;status;requestId;retryAfter;details;constructor(e){super(e.message),this.name="BotonPayError",this.code=e.code,this.status=e.status,this.requestId=e.requestId,this.retryAfter=e.retryAfter,this.details=e.details}},p=class{apiKey;baseUrl;fetchImpl;maxRetries;extraHeaders;constructor(e){if(!e.apiKey)throw new Error("BotonPay: apiKey is required");this.apiKey=e.apiKey,this.baseUrl=(e.baseUrl??R).replace(/\/$/,""),this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis),this.maxRetries=e.maxRetries??2,this.extraHeaders=e.headers??{}}async request(e,t,n,i={}){let o=`${this.baseUrl}${t}`,r={Authorization:`Bearer ${this.apiKey}`,Accept:"application/json","User-Agent":`botonpay-sdk-js/${q}`,...this.extraHeaders};n!==void 0&&(r["Content-Type"]="application/json"),i.idempotencyKey&&(r["Idempotency-Key"]=i.idempotencyKey),i.correlationId&&(r["X-Correlation-ID"]=i.correlationId);let a=0;for(;;){let s=await this.fetchImpl(o,{method:e,headers:r,body:n!==void 0?JSON.stringify(n):void 0,signal:i.signal}),u=await s.text(),h=s.headers.get("x-request-id")??void 0,g=s.headers.get("retry-after"),m=g?Number(g):void 0;if(s.ok)return u?JSON.parse(u):void 0;let b=a<this.maxRetries&&(s.status===429||s.status>=500),l={};try{l=u?JSON.parse(u):{}}catch{}let f=new c({code:l?.error?.code??`http_${s.status}`,status:s.status,message:l?.error?.message??s.statusText,requestId:h,retryAfter:m,details:l?.error?.details});if(!b)throw f;let y=(m??Math.pow(2,a))*1e3;await new Promise(_=>setTimeout(_,y)),a++}}deals={create:(e,t)=>this.request("POST","/api/public/v1/deals",e,t),list:(e={},t)=>{let n=new URLSearchParams;for(let[o,r]of Object.entries(e))r!==void 0&&n.set(o,String(r));let i=n.toString();return this.request("GET",`/api/public/v1/deals${i?"?"+i:""}`,void 0,t)},get:(e,t)=>this.request("GET",`/api/public/v1/deals/${encodeURIComponent(e)}`,void 0,t),cancel:(e,t)=>this.request("POST",`/api/public/v1/deals/${encodeURIComponent(e)}/cancel`,{},t),history:(e,t)=>this.request("GET",`/api/public/v1/deals/${encodeURIComponent(e)}/history`,void 0,t)};currencies={list:e=>this.request("GET","/api/public/v1/currencies",void 0,e)};rates={list:(e,t)=>this.request("GET",`/api/public/v1/rates${e?"?fiat="+encodeURIComponent(e):""}`,void 0,t)};webhooks={test:(e,t)=>this.request("POST","/api/public/v1/webhooks/test",e?{url:e}:{},t)};me=e=>this.request("GET","/api/public/v1/me",void 0,e);health=e=>this.request("GET","/api/public/v1/health",void 0,e);status=e=>this.request("GET","/api/public/v1/status",void 0,e);apiKeys={list:e=>this.request("GET","/api/public/v1/api-keys",void 0,e),create:(e,t)=>this.request("POST","/api/public/v1/api-keys",e,t),get:(e,t)=>this.request("GET",`/api/public/v1/api-keys/${encodeURIComponent(e)}`,void 0,t),update:(e,t,n)=>this.request("PATCH",`/api/public/v1/api-keys/${encodeURIComponent(e)}`,t,n),delete:(e,t)=>this.request("DELETE",`/api/public/v1/api-keys/${encodeURIComponent(e)}`,void 0,t)}};async function w(d,e,t){if(!e)return!1;let n=new TextEncoder,i=await crypto.subtle.importKey("raw",n.encode(t),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),o=await crypto.subtle.sign("HMAC",i,n.encode(d)),r=Array.from(new Uint8Array(o)).map(s=>s.toString(16).padStart(2,"0")).join("");if(r.length!==e.length)return!1;let a=0;for(let s=0;s<r.length;s++)a|=r.charCodeAt(s)^e.charCodeAt(s);return a===0}var x=p;export{p as BotonPay,c as BotonPayError,q as SDK_VERSION,x as default,w as verifyWebhook};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "botonpay-sdk",
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"description": "Official BOTONPAY Public API client for TypeScript and JavaScript",
|
|
5
|
+
"keywords": ["botonpay", "payments", "crypto", "usdt", "p2p", "api-client"],
|
|
6
|
+
"author": "BOTONPAY <support@botonpay.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://docs.botonpay.com",
|
|
9
|
+
"bugs": { "email": "support@botonpay.com" },
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": ["dist", "README.md", "LICENSE", "CHANGELOG.md"],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --minify",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"prepublishOnly": "npm run build",
|
|
26
|
+
"publish:npm": "npm publish --access public"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.3.0",
|
|
30
|
+
"typescript": "^5.5.0",
|
|
31
|
+
"vitest": "^2.1.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": { "node": ">=18" }
|
|
34
|
+
}
|