bohudur 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/LICENSE +21 -0
- package/README.md +290 -0
- package/dist/errors.cjs +56 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +11 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +11 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +54 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +149 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +149 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +69 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +69 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 theabmmohi
|
|
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,290 @@
|
|
|
1
|
+
> [!WARNING]
|
|
2
|
+
> **This project is archived and no longer maintained.**
|
|
3
|
+
>
|
|
4
|
+
> On 27 September 2026, Bohudur's website, API, and support channels went offline. As a result, this SDK no longer works, and the links below (including the docs, the console, and the API and checkout URLs) may not resolve.
|
|
5
|
+
>
|
|
6
|
+
> The code is kept here for reference only. If Bohudur returns, this repository may be unarchived.
|
|
7
|
+
|
|
8
|
+
The first unofficial Node.js SDK (before official 🙂) for the [Bohudur Payment API](https://bohudur.one) — a free payment automation platform supporting Binance, bKash, Nagad, Rocket and more.
|
|
9
|
+
|
|
10
|
+
Wraps the official [Bohudur REST API](https://docs.bohudur.one/curl/) with a small class-based interface.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install bohudur
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Works with both ESM and CJS:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// ESM
|
|
22
|
+
import Bohudur from "bohudur"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// CJS
|
|
27
|
+
const Bohudur = require("bohudur")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Getting an API key
|
|
31
|
+
|
|
32
|
+
Sign in at [console.bohudur.one](https://console.bohudur.one) with Google and copy your API key from there.
|
|
33
|
+
|
|
34
|
+
> **Keep your key secret.** Never expose it in frontend JavaScript, mobile app code, or public repos — always call this SDK from your server.
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import Bohudur from "bohudur"
|
|
40
|
+
|
|
41
|
+
const bohudur = new Bohudur(process.env.BOHUDUR_API_KEY!)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Optional second argument for advanced configuration:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const bohudur = new Bohudur(process.env.BOHUDUR_API_KEY!, {
|
|
48
|
+
baseURL: "https://request.bohudur.one", // override if Bohudur gives you a different endpoint
|
|
49
|
+
timeout: 10000, // ms before a request is aborted (default: 10000)
|
|
50
|
+
headers: { "X-Custom-Header": "value" } // merged into every request
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API Flow
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
1. bohudur.create() → get paymentURL + paykey
|
|
58
|
+
↓
|
|
59
|
+
2. Redirect user to paymentURL
|
|
60
|
+
↓
|
|
61
|
+
3. User pays or cancels on the hosted checkout page
|
|
62
|
+
↓
|
|
63
|
+
4. Webhook sent to your server (if configured)
|
|
64
|
+
↓
|
|
65
|
+
5. bohudur.verifyWebhook() → confirm the real status, don't trust the webhook body
|
|
66
|
+
↓
|
|
67
|
+
6. bohudur.execute() → finalize, only once verifyWebhook() confirms COMPLETED
|
|
68
|
+
↓
|
|
69
|
+
7. bohudur.query() → check status anytime
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## `create(request)`
|
|
73
|
+
|
|
74
|
+
Creates a new payment session and returns a hosted checkout URL.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const result = await bohudur.create({
|
|
78
|
+
name: "Jane Doe",
|
|
79
|
+
email: "jane@example.com",
|
|
80
|
+
amount: 10,
|
|
81
|
+
returnType: "GET",
|
|
82
|
+
redirectURL: "https://example.com/redirect/",
|
|
83
|
+
cancelURL: "https://example.com/cancel/",
|
|
84
|
+
metadata: {
|
|
85
|
+
order_id: "ORD-1001",
|
|
86
|
+
user_id: 55
|
|
87
|
+
},
|
|
88
|
+
webhook: {
|
|
89
|
+
success: "https://example.com/webhook/success",
|
|
90
|
+
cancel: "https://example.com/webhook/cancel"
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Request
|
|
96
|
+
|
|
97
|
+
| Parameter | Type | Required | Maps to (Bohudur API) | Description |
|
|
98
|
+
| ------------------ | ------ | -------- | ----------------------- | -------------------------------------------------------------------------- |
|
|
99
|
+
| `name` | string | YES | `full_name` | Customer full name |
|
|
100
|
+
| `email` | string | YES | `email` | Customer email address |
|
|
101
|
+
| `amount` | number | YES | `amount` | Payment amount in your account's default currency |
|
|
102
|
+
| `returnType` | string | YES | `return_type` | How params are returned after payment: `"GET"` or `"POST"` |
|
|
103
|
+
| `redirectURL` | string | YES | `redirect_url` | Redirect URL after successful payment. Use `"default"` for Bohudur's page |
|
|
104
|
+
| `cancelURL` | string | YES | `cancel_url` | Redirect URL after cancellation. Use `"default"` for Bohudur's page |
|
|
105
|
+
| `metadata` | object | NO | `metadata` | Any custom key-value data to attach to this payment |
|
|
106
|
+
| `webhook.success` | string | NO | `webhook.success` | Your server URL to receive a POST when payment succeeds |
|
|
107
|
+
| `webhook.cancel` | string | NO | `webhook.cancel` | Your server URL to receive a POST when payment is cancelled |
|
|
108
|
+
|
|
109
|
+
### Response
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
{
|
|
113
|
+
paykey: "5RWS4w2w1R5nFAvoP5U0JS4O74UrMXGt",
|
|
114
|
+
paymentURL: "https://checkout.bohudur.one/payment/5RWS4w2w1R5nFAvoP5U0JS4O74UrMXGt"
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Redirect your customer to `paymentURL` and store `paykey`.
|
|
119
|
+
|
|
120
|
+
## `execute(request)`
|
|
121
|
+
|
|
122
|
+
Finalizes a completed payment. Call this from your server after `query()` (or `verifyWebhook()`) confirms the status is `COMPLETED`.
|
|
123
|
+
|
|
124
|
+
> A payment can be executed **exactly once**. A second attempt fails with code `3108` — this prevents duplicate charges. Store the execute response immediately after a successful call.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const result = await bohudur.execute({ paykey: "fnPwIkdIsMjN4FJxYxw6DF75GuW9qStn" })
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Response
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
{
|
|
134
|
+
name: "Gabriel Adams",
|
|
135
|
+
email: "gabriel@example.com",
|
|
136
|
+
paykey: "fnPwIkdIsMjN4FJxYxw6DF75GuW9qStn",
|
|
137
|
+
amount: 40,
|
|
138
|
+
convertedAmount: 4878,
|
|
139
|
+
totalAmount: 40,
|
|
140
|
+
transactionFee: 0,
|
|
141
|
+
defaultCurrency: "USD",
|
|
142
|
+
paymentCurrency: "BDT",
|
|
143
|
+
currencyValue: 121.951,
|
|
144
|
+
createdAt: Date, // parsed from created_time
|
|
145
|
+
paidAt: Date | null, // parsed from payment_time
|
|
146
|
+
receipt: "https://pay.bohudur.one/receipt/download/102f89389f9e",
|
|
147
|
+
metadata: null,
|
|
148
|
+
webhook: null,
|
|
149
|
+
paymentInfo: { m0: "Stripe" }, // payment provider used, plus provider-specific fields
|
|
150
|
+
status: "EXECUTED"
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`createdAt` and `paidAt` are native `Date` objects, not raw strings.
|
|
155
|
+
|
|
156
|
+
`metadata`, `webhook`, and `paymentInfo` are each `null` when nothing was set on that payment, and the parsed object when something was — the shape returned by the actual API varies with the payment's status (e.g. a `PENDING` payment has no `receipt` or `paymentInfo` yet), not just with which fields you passed to `create()`.
|
|
157
|
+
|
|
158
|
+
## `query(request)`
|
|
159
|
+
|
|
160
|
+
Retrieves the full details and current status of any payment. Safe to call at any time, as many times as you like.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const result = await bohudur.query({ paykey: "fnPwIkdIsMjN4FJxYxw6DF75GuW9qStn" })
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Response
|
|
167
|
+
|
|
168
|
+
Same shape as `execute()` above.
|
|
169
|
+
|
|
170
|
+
| `status` | Meaning |
|
|
171
|
+
| ----------- | ----------------------------------------------------------------- |
|
|
172
|
+
| `PENDING` | Session created, customer hasn't paid yet |
|
|
173
|
+
| `COMPLETED` | Customer has paid — call `execute()` next to finalize |
|
|
174
|
+
| `EXECUTED` | Payment finalized by your server via `execute()` |
|
|
175
|
+
| `CANCELLED` | Cancelled by the user or system — cannot be executed |
|
|
176
|
+
|
|
177
|
+
## Webhooks
|
|
178
|
+
|
|
179
|
+
If you configure `webhook.success` / `webhook.cancel` on `create()`, Bohudur `POST`s a small payload to that URL when a payment succeeds or is cancelled:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"full_name": "Jane Doe",
|
|
184
|
+
"email": "jane@example.com",
|
|
185
|
+
"amount": 1,
|
|
186
|
+
"paymentkey": "CrD85r3ibMK6ip38reUcuECvVhaF0xOT",
|
|
187
|
+
"status": "COMPLETED"
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Webhooks are not final truth.** Bohudur can retry a webhook delivery, and the payload's own `status` field is just what Bohudur is *claiming* — not a guarantee. `verifyWebhook()` re-checks the real status with `query()` before you act on it:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
const result = await bohudur.verifyWebhook(req.body) // req.body typed as WebhookPayload
|
|
195
|
+
// result: { paykey: string, status: "COMPLETED" | "CANCELLED" }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
If the real, freshly-confirmed status is `PENDING` or `EXECUTED` (e.g. a retried webhook arriving after your server already executed the payment), `verifyWebhook()` throws a `BohudurError` with `type: "validation"` instead of returning — a webhook handler only has two outcomes to act on, so those two cases are surfaced as errors rather than squeezed into the return type.
|
|
199
|
+
|
|
200
|
+
### Express example
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import express from "express"
|
|
204
|
+
import Bohudur from "bohudur"
|
|
205
|
+
import { BohudurError } from "bohudur/errors"
|
|
206
|
+
import type { WebhookPayload } from "bohudur/types"
|
|
207
|
+
|
|
208
|
+
const app = express()
|
|
209
|
+
app.use(express.json())
|
|
210
|
+
|
|
211
|
+
const bohudur = new Bohudur(process.env.BOHUDUR_API_KEY!)
|
|
212
|
+
|
|
213
|
+
app.post("/webhook/bohudur", async (req, res) => {
|
|
214
|
+
res.sendStatus(200) // acknowledge immediately — Bohudur retries on anything else
|
|
215
|
+
|
|
216
|
+
const payload = req.body as WebhookPayload
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const result = await bohudur.verifyWebhook(payload)
|
|
220
|
+
|
|
221
|
+
if (result.status === "COMPLETED") {
|
|
222
|
+
// trusted — this came from verifyWebhook()'s own query(), not payload.status
|
|
223
|
+
// execute to mark as EXECUTED
|
|
224
|
+
await bohudur.execute({ paykey: result.paykey })
|
|
225
|
+
// deliver the product/service here
|
|
226
|
+
} else {
|
|
227
|
+
// result.status === "CANCELLED"
|
|
228
|
+
// release any reserved stock, mark the order cancelled, etc.
|
|
229
|
+
}
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (error instanceof BohudurError) {
|
|
232
|
+
console.error(`Webhook verification failed: [${error.code}] ${error.message}`)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
> Always return HTTP 200 from your webhook route immediately, and do any order-fulfillment logic asynchronously afterward — a slow or failing response causes Bohudur to retry.
|
|
239
|
+
|
|
240
|
+
## Error handling
|
|
241
|
+
|
|
242
|
+
Every method — `create()`, `execute()`, `query()`, `verifyWebhook()` — throws a `BohudurError` on failure rather than returning a wrapped result:
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import Bohudur from "bohudur"
|
|
246
|
+
import { BohudurError } from "bohudur/errors"
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
const result = await bohudur.query({ paykey: "..." })
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (error instanceof BohudurError) {
|
|
252
|
+
console.error(error.code) // e.g. 3052
|
|
253
|
+
console.error(error.type) // "api" | "network" | "server" | "validation"
|
|
254
|
+
console.error(error.message) // human-readable description
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
`error.type` tells you what kind of failure it was:
|
|
260
|
+
|
|
261
|
+
| `type` | Meaning |
|
|
262
|
+
| -------------- | -------------------------------------------------------------------------------- |
|
|
263
|
+
| `"api"` | Bohudur received the request and rejected it — `code` is one of Bohudur's own error codes |
|
|
264
|
+
| `"server"` | Bohudur responded with a non-2xx HTTP status, or an unparseable body |
|
|
265
|
+
| `"network"` | The request never reached Bohudur — timeout, DNS failure, connection error |
|
|
266
|
+
| `"validation"` | The SDK rejected the request or response locally (e.g. a malformed URL, or `verifyWebhook()` seeing a `PENDING`/`EXECUTED` status) |
|
|
267
|
+
|
|
268
|
+
## Error codes
|
|
269
|
+
|
|
270
|
+
For `type: "api"` errors, `code` comes directly from Bohudur's API. Common ones:
|
|
271
|
+
|
|
272
|
+
| Code | Meaning |
|
|
273
|
+
| ------ | ------------------------------------------- |
|
|
274
|
+
| `3000`/`3100`/`3050` | API key missing from the request |
|
|
275
|
+
| `3013`/`3101`/`3103`/`3051`/`3053` | API key invalid or inactive |
|
|
276
|
+
| `3102`/`3052` | `paykey` malformed or doesn't exist |
|
|
277
|
+
| `3105`/`3055` | No payment found for that `paykey` |
|
|
278
|
+
| `3106` | Payment still pending — customer hasn't paid |
|
|
279
|
+
| `3107` | Payment was cancelled — cannot be executed |
|
|
280
|
+
| `3108` | Payment already executed |
|
|
281
|
+
| `3016`/`3104`/`3054` | Request blocked — IP not authorized |
|
|
282
|
+
|
|
283
|
+
Full list: [Bohudur cURL / REST API reference](https://docs.bohudur.one/curl/).
|
|
284
|
+
|
|
285
|
+
## Links
|
|
286
|
+
|
|
287
|
+
- [Bohudur Docs](https://docs.bohudur.one/)
|
|
288
|
+
- [Console (get your API key)](https://console.bohudur.one/)
|
|
289
|
+
- [Telegram support (Bohudur)](https://t.me/bohudur)
|
|
290
|
+
- [Telegram support (Me)](https://t.me/theabmmohi)
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/error/bohudurError.ts
|
|
3
|
+
var BohudurError = class extends Error {
|
|
4
|
+
code;
|
|
5
|
+
type;
|
|
6
|
+
constructor(message, code, type) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.type = type;
|
|
10
|
+
this.name = "BohudurError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/error/errorCodes.ts
|
|
15
|
+
const ErrorCodes = {
|
|
16
|
+
3e3: "API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.",
|
|
17
|
+
3001: "Required parameters not found. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" are all required.",
|
|
18
|
+
3002: "One or more required parameters are empty. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" must all have non-empty values.",
|
|
19
|
+
3003: "Invalid \"name\" format. It must be a valid non-empty string.",
|
|
20
|
+
3004: "Invalid \"email\" format. Provide a valid email address.",
|
|
21
|
+
3005: "Invalid \"amount\" format. It must be a positive numeric value.",
|
|
22
|
+
3006: "Invalid \"returnType\" format. Only \"GET\" or \"POST\" is allowed.",
|
|
23
|
+
3007: "Invalid \"redirectURL\" format. Provide a valid URL, or \"default\" to use Bohudur's default page.",
|
|
24
|
+
3008: "Invalid \"cancelURL\" format. Provide a valid URL, or \"default\" to use Bohudur's default page.",
|
|
25
|
+
3009: "Invalid JSON format in \"metadata\". It must be a valid JSON object.",
|
|
26
|
+
3010: "Invalid JSON format in \"webhook\". It must form a valid webhook object.",
|
|
27
|
+
3011: "Invalid webhook actions. Only \"success\" and \"cancel\" are allowed.",
|
|
28
|
+
3012: "Invalid JSON format in \"metadata\" or \"webhook\". One or both are malformed.",
|
|
29
|
+
3013: "Invalid API key. The provided key is incorrect or inactive.",
|
|
30
|
+
3014: "Oops! Internal error. Try again.",
|
|
31
|
+
3015: "Unknown amount provided. The \"amount\" value is not acceptable.",
|
|
32
|
+
3016: "You don't have access. This request was blocked due to an IP restriction.",
|
|
33
|
+
3017: "Oops! Internal error. Try again.",
|
|
34
|
+
3018: "Unable to create payment. The payment session could not be created.",
|
|
35
|
+
3050: "API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.",
|
|
36
|
+
3051: "API key not valid. The provided key is invalid or inactive.",
|
|
37
|
+
3052: "Invalid \"paykey\". It does not exist or is malformed.",
|
|
38
|
+
3053: "Invalid API key. It does not match any active account.",
|
|
39
|
+
3054: "You don't have access. Your server's IP is not authorized.",
|
|
40
|
+
3055: "Payment data not found. No payment exists for this \"paykey\".",
|
|
41
|
+
3100: "API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.",
|
|
42
|
+
3101: "API key not valid. The provided key is invalid or inactive.",
|
|
43
|
+
3102: "Invalid \"paykey\". It is malformed or does not exist.",
|
|
44
|
+
3103: "Invalid API key. It does not match any active account.",
|
|
45
|
+
3104: "You don't have access. Your server's IP is not authorized.",
|
|
46
|
+
3105: "Payment data not found. No payment exists for this \"paykey\".",
|
|
47
|
+
3106: "Payment is pending. The customer has not completed payment yet.",
|
|
48
|
+
3107: "Payment is cancelled. Cancelled payments cannot be executed.",
|
|
49
|
+
3108: "Payment already executed. This payment was already executed once and cannot be executed again.",
|
|
50
|
+
3109: "Failed to execute payment due to a server or processing error."
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.BohudurError = BohudurError;
|
|
54
|
+
exports.ErrorCodes = ErrorCodes;
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/error/bohudurError.ts","../src/error/errorCodes.ts"],"sourcesContent":["export class BohudurError extends Error {\n constructor(\n message: string,\n readonly code: number,\n readonly type: \"api\" | \"network\" | \"server\" | \"validation\"\n ) {\n super(message)\n this.name = \"BohudurError\"\n }\n}\n","export const ErrorCodes: Record<number, string> = {\n 3000: 'API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.',\n 3001: 'Required parameters not found. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" are all required.',\n 3002: 'One or more required parameters are empty. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" must all have non-empty values.',\n 3003: 'Invalid \"name\" format. It must be a valid non-empty string.',\n 3004: 'Invalid \"email\" format. Provide a valid email address.',\n 3005: 'Invalid \"amount\" format. It must be a positive numeric value.',\n 3006: 'Invalid \"returnType\" format. Only \"GET\" or \"POST\" is allowed.',\n 3007: 'Invalid \"redirectURL\" format. Provide a valid URL, or \"default\" to use Bohudur\\'s default page.',\n 3008: 'Invalid \"cancelURL\" format. Provide a valid URL, or \"default\" to use Bohudur\\'s default page.',\n 3009: 'Invalid JSON format in \"metadata\". It must be a valid JSON object.',\n 3010: 'Invalid JSON format in \"webhook\". It must form a valid webhook object.',\n 3011: 'Invalid webhook actions. Only \"success\" and \"cancel\" are allowed.',\n 3012: 'Invalid JSON format in \"metadata\" or \"webhook\". One or both are malformed.',\n 3013: \"Invalid API key. The provided key is incorrect or inactive.\",\n 3014: \"Oops! Internal error. Try again.\",\n 3015: 'Unknown amount provided. The \"amount\" value is not acceptable.',\n 3016: \"You don't have access. This request was blocked due to an IP restriction.\",\n 3017: \"Oops! Internal error. Try again.\",\n 3018: \"Unable to create payment. The payment session could not be created.\",\n 3050: 'API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.',\n 3051: \"API key not valid. The provided key is invalid or inactive.\",\n 3052: 'Invalid \"paykey\". It does not exist or is malformed.',\n 3053: \"Invalid API key. It does not match any active account.\",\n 3054: \"You don't have access. Your server's IP is not authorized.\",\n 3055: 'Payment data not found. No payment exists for this \"paykey\".',\n 3100: 'API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.',\n 3101: \"API key not valid. The provided key is invalid or inactive.\",\n 3102: 'Invalid \"paykey\". It is malformed or does not exist.',\n 3103: \"Invalid API key. It does not match any active account.\",\n 3104: \"You don't have access. Your server's IP is not authorized.\",\n 3105: 'Payment data not found. No payment exists for this \"paykey\".',\n 3106: \"Payment is pending. The customer has not completed payment yet.\",\n 3107: \"Payment is cancelled. Cancelled payments cannot be executed.\",\n 3108: \"Payment already executed. This payment was already executed once and cannot be executed again.\",\n 3109: \"Failed to execute payment due to a server or processing error.\"\n}\n"],"mappings":";;AAAA,IAAa,eAAb,cAAkC,MAAM;CAG3B;CACA;CAHX,YACE,SACA,MACA,MACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;EACA,KAAA,OAAA;EAGT,KAAK,OAAO;CACd;AACF;;;ACTA,MAAa,aAAqC;CAChD,KAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/error/bohudurError.d.ts
|
|
2
|
+
export declare class BohudurError extends Error {
|
|
3
|
+
readonly code: number;
|
|
4
|
+
readonly type: "api" | "network" | "server" | "validation";
|
|
5
|
+
constructor(message: string, code: number, type: "api" | "network" | "server" | "validation");
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/error/errorCodes.d.ts
|
|
9
|
+
export declare const ErrorCodes: Record<number, string>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../src/error/bohudurError.ts","../src/error/errorCodes.ts"],"mappings":";qBAAa,qBAAqB;WAGrB;WACA;EAHX,YACE,iBACS,cACA;;;;qBCJA,YAAY"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/error/bohudurError.d.ts
|
|
2
|
+
export declare class BohudurError extends Error {
|
|
3
|
+
readonly code: number;
|
|
4
|
+
readonly type: "api" | "network" | "server" | "validation";
|
|
5
|
+
constructor(message: string, code: number, type: "api" | "network" | "server" | "validation");
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/error/errorCodes.d.ts
|
|
9
|
+
export declare const ErrorCodes: Record<number, string>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/error/bohudurError.ts","../src/error/errorCodes.ts"],"mappings":";qBAAa,qBAAqB;WAGrB;WACA;EAHX,YACE,iBACS,cACA;;;;qBCJA,YAAY"}
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/error/bohudurError.ts
|
|
2
|
+
var BohudurError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
type;
|
|
5
|
+
constructor(message, code, type) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.type = type;
|
|
9
|
+
this.name = "BohudurError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/error/errorCodes.ts
|
|
14
|
+
const ErrorCodes = {
|
|
15
|
+
3e3: "API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.",
|
|
16
|
+
3001: "Required parameters not found. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" are all required.",
|
|
17
|
+
3002: "One or more required parameters are empty. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" must all have non-empty values.",
|
|
18
|
+
3003: "Invalid \"name\" format. It must be a valid non-empty string.",
|
|
19
|
+
3004: "Invalid \"email\" format. Provide a valid email address.",
|
|
20
|
+
3005: "Invalid \"amount\" format. It must be a positive numeric value.",
|
|
21
|
+
3006: "Invalid \"returnType\" format. Only \"GET\" or \"POST\" is allowed.",
|
|
22
|
+
3007: "Invalid \"redirectURL\" format. Provide a valid URL, or \"default\" to use Bohudur's default page.",
|
|
23
|
+
3008: "Invalid \"cancelURL\" format. Provide a valid URL, or \"default\" to use Bohudur's default page.",
|
|
24
|
+
3009: "Invalid JSON format in \"metadata\". It must be a valid JSON object.",
|
|
25
|
+
3010: "Invalid JSON format in \"webhook\". It must form a valid webhook object.",
|
|
26
|
+
3011: "Invalid webhook actions. Only \"success\" and \"cancel\" are allowed.",
|
|
27
|
+
3012: "Invalid JSON format in \"metadata\" or \"webhook\". One or both are malformed.",
|
|
28
|
+
3013: "Invalid API key. The provided key is incorrect or inactive.",
|
|
29
|
+
3014: "Oops! Internal error. Try again.",
|
|
30
|
+
3015: "Unknown amount provided. The \"amount\" value is not acceptable.",
|
|
31
|
+
3016: "You don't have access. This request was blocked due to an IP restriction.",
|
|
32
|
+
3017: "Oops! Internal error. Try again.",
|
|
33
|
+
3018: "Unable to create payment. The payment session could not be created.",
|
|
34
|
+
3050: "API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.",
|
|
35
|
+
3051: "API key not valid. The provided key is invalid or inactive.",
|
|
36
|
+
3052: "Invalid \"paykey\". It does not exist or is malformed.",
|
|
37
|
+
3053: "Invalid API key. It does not match any active account.",
|
|
38
|
+
3054: "You don't have access. Your server's IP is not authorized.",
|
|
39
|
+
3055: "Payment data not found. No payment exists for this \"paykey\".",
|
|
40
|
+
3100: "API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.",
|
|
41
|
+
3101: "API key not valid. The provided key is invalid or inactive.",
|
|
42
|
+
3102: "Invalid \"paykey\". It is malformed or does not exist.",
|
|
43
|
+
3103: "Invalid API key. It does not match any active account.",
|
|
44
|
+
3104: "You don't have access. Your server's IP is not authorized.",
|
|
45
|
+
3105: "Payment data not found. No payment exists for this \"paykey\".",
|
|
46
|
+
3106: "Payment is pending. The customer has not completed payment yet.",
|
|
47
|
+
3107: "Payment is cancelled. Cancelled payments cannot be executed.",
|
|
48
|
+
3108: "Payment already executed. This payment was already executed once and cannot be executed again.",
|
|
49
|
+
3109: "Failed to execute payment due to a server or processing error."
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { BohudurError, ErrorCodes };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/error/bohudurError.ts","../src/error/errorCodes.ts"],"sourcesContent":["export class BohudurError extends Error {\n constructor(\n message: string,\n readonly code: number,\n readonly type: \"api\" | \"network\" | \"server\" | \"validation\"\n ) {\n super(message)\n this.name = \"BohudurError\"\n }\n}\n","export const ErrorCodes: Record<number, string> = {\n 3000: 'API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.',\n 3001: 'Required parameters not found. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" are all required.',\n 3002: 'One or more required parameters are empty. \"name\", \"email\", \"amount\", \"returnType\", \"redirectURL\", and \"cancelURL\" must all have non-empty values.',\n 3003: 'Invalid \"name\" format. It must be a valid non-empty string.',\n 3004: 'Invalid \"email\" format. Provide a valid email address.',\n 3005: 'Invalid \"amount\" format. It must be a positive numeric value.',\n 3006: 'Invalid \"returnType\" format. Only \"GET\" or \"POST\" is allowed.',\n 3007: 'Invalid \"redirectURL\" format. Provide a valid URL, or \"default\" to use Bohudur\\'s default page.',\n 3008: 'Invalid \"cancelURL\" format. Provide a valid URL, or \"default\" to use Bohudur\\'s default page.',\n 3009: 'Invalid JSON format in \"metadata\". It must be a valid JSON object.',\n 3010: 'Invalid JSON format in \"webhook\". It must form a valid webhook object.',\n 3011: 'Invalid webhook actions. Only \"success\" and \"cancel\" are allowed.',\n 3012: 'Invalid JSON format in \"metadata\" or \"webhook\". One or both are malformed.',\n 3013: \"Invalid API key. The provided key is incorrect or inactive.\",\n 3014: \"Oops! Internal error. Try again.\",\n 3015: 'Unknown amount provided. The \"amount\" value is not acceptable.',\n 3016: \"You don't have access. This request was blocked due to an IP restriction.\",\n 3017: \"Oops! Internal error. Try again.\",\n 3018: \"Unable to create payment. The payment session could not be created.\",\n 3050: 'API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.',\n 3051: \"API key not valid. The provided key is invalid or inactive.\",\n 3052: 'Invalid \"paykey\". It does not exist or is malformed.',\n 3053: \"Invalid API key. It does not match any active account.\",\n 3054: \"You don't have access. Your server's IP is not authorized.\",\n 3055: 'Payment data not found. No payment exists for this \"paykey\".',\n 3100: 'API key not found. Make sure the \"AH-BOHUDUR-API-KEY\" header is included in the request.',\n 3101: \"API key not valid. The provided key is invalid or inactive.\",\n 3102: 'Invalid \"paykey\". It is malformed or does not exist.',\n 3103: \"Invalid API key. It does not match any active account.\",\n 3104: \"You don't have access. Your server's IP is not authorized.\",\n 3105: 'Payment data not found. No payment exists for this \"paykey\".',\n 3106: \"Payment is pending. The customer has not completed payment yet.\",\n 3107: \"Payment is cancelled. Cancelled payments cannot be executed.\",\n 3108: \"Payment already executed. This payment was already executed once and cannot be executed again.\",\n 3109: \"Failed to execute payment due to a server or processing error.\"\n}\n"],"mappings":";AAAA,IAAa,eAAb,cAAkC,MAAM;CAG3B;CACA;CAHX,YACE,SACA,MACA,MACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;EACA,KAAA,OAAA;EAGT,KAAK,OAAO;CACd;AACF;;;ACTA,MAAa,aAAqC;CAChD,KAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;AACR"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const require_errors = require("./errors.cjs");
|
|
2
|
+
//#region src/bohudur/http.ts
|
|
3
|
+
const DEFAULT_BASEURL = "https://request.bohudur.one";
|
|
4
|
+
const DEFAULT_TIMEOUT = 1e4;
|
|
5
|
+
async function Request(key, options, path, body) {
|
|
6
|
+
const baseURL = options.baseURL ?? DEFAULT_BASEURL;
|
|
7
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
8
|
+
const controller = new AbortController();
|
|
9
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch(`${baseURL}${path}`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
"AH-BOHUDUR-API-KEY": key,
|
|
16
|
+
...options.headers
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify(body),
|
|
19
|
+
signal: controller.signal
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) throw new require_errors.BohudurError(`Server error (HTTP ${response.status}).`, response.status, "server");
|
|
22
|
+
let data;
|
|
23
|
+
try {
|
|
24
|
+
data = await response.json();
|
|
25
|
+
} catch {
|
|
26
|
+
throw new require_errors.BohudurError("Failed to parse server response as JSON.", 0, "server");
|
|
27
|
+
}
|
|
28
|
+
if (data.status === "failed") throw new require_errors.BohudurError(require_errors.ErrorCodes[data.responseCode] ?? data.message ?? "Server responded with failed status.", data.responseCode, "api");
|
|
29
|
+
return data;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof require_errors.BohudurError) throw error;
|
|
32
|
+
if (error instanceof Error && error.name === "AbortError") throw new require_errors.BohudurError(`Request timed out after ${timeout}ms`, 0, "network");
|
|
33
|
+
throw new require_errors.BohudurError(error instanceof Error ? error.message : "Unknown error", 0, "network");
|
|
34
|
+
} finally {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/bohudur/create.ts
|
|
40
|
+
const path$2 = "/create/v2/";
|
|
41
|
+
async function create(key, options, request) {
|
|
42
|
+
const data = await Request(key, options, path$2, {
|
|
43
|
+
full_name: request.name,
|
|
44
|
+
email: request.email,
|
|
45
|
+
amount: request.amount,
|
|
46
|
+
return_type: request.returnType,
|
|
47
|
+
redirect_url: request.redirectURL,
|
|
48
|
+
cancel_url: request.cancelURL,
|
|
49
|
+
metadata: request.metadata,
|
|
50
|
+
webhook: request.webhook
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
paykey: data.paymentkey,
|
|
54
|
+
paymentURL: data.payment_url
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/bohudur/helpers.ts
|
|
59
|
+
function toDate(raw) {
|
|
60
|
+
if (!raw || raw === "NONE") return null;
|
|
61
|
+
return /* @__PURE__ */ new Date(raw.replace(" ", "T") + "+06:00");
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/bohudur/execute.ts
|
|
65
|
+
const path$1 = "/execute/v2/";
|
|
66
|
+
async function execute(key, options, request) {
|
|
67
|
+
const data = await Request(key, options, path$1, { paymentkey: request.paykey });
|
|
68
|
+
return {
|
|
69
|
+
name: data.full_name,
|
|
70
|
+
email: data.email,
|
|
71
|
+
amount: data.amount,
|
|
72
|
+
convertedAmount: data.converted_amount,
|
|
73
|
+
totalAmount: data.total_amount,
|
|
74
|
+
transactionFee: data.transaction_fee,
|
|
75
|
+
defaultCurrency: data.default_currency,
|
|
76
|
+
paymentCurrency: data.payment_currency,
|
|
77
|
+
currencyValue: data.currency_value,
|
|
78
|
+
metadata: Array.isArray(data.metadata) ? null : data.metadata,
|
|
79
|
+
createdAt: toDate(data.created_time),
|
|
80
|
+
paidAt: toDate(data.payment_time),
|
|
81
|
+
paykey: data.paymentkey,
|
|
82
|
+
receipt: data.receipt === "NONE" ? null : data.receipt,
|
|
83
|
+
webhook: Array.isArray(data.webhook) ? null : data.webhook,
|
|
84
|
+
paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,
|
|
85
|
+
status: data.status
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/bohudur/query.ts
|
|
90
|
+
const path = "/query/v2/";
|
|
91
|
+
async function query(key, options, request) {
|
|
92
|
+
const data = await Request(key, options, path, { paymentkey: request.paykey });
|
|
93
|
+
return {
|
|
94
|
+
name: data.full_name,
|
|
95
|
+
email: data.email,
|
|
96
|
+
amount: data.amount,
|
|
97
|
+
convertedAmount: data.converted_amount,
|
|
98
|
+
totalAmount: data.total_amount,
|
|
99
|
+
transactionFee: data.transaction_fee,
|
|
100
|
+
defaultCurrency: data.default_currency,
|
|
101
|
+
paymentCurrency: data.payment_currency,
|
|
102
|
+
currencyValue: data.currency_value,
|
|
103
|
+
metadata: Array.isArray(data.metadata) ? null : data.metadata,
|
|
104
|
+
createdAt: toDate(data.created_time),
|
|
105
|
+
paidAt: toDate(data.payment_time),
|
|
106
|
+
paykey: data.paymentkey,
|
|
107
|
+
receipt: data.receipt === "NONE" ? null : data.receipt,
|
|
108
|
+
webhook: Array.isArray(data.webhook) ? null : data.webhook,
|
|
109
|
+
paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,
|
|
110
|
+
status: data.status
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/bohudur/verifyWebhook.ts
|
|
115
|
+
async function verifyWebhook(key, options, payload) {
|
|
116
|
+
const queryResult = await query(key, options, { paykey: payload.paymentkey });
|
|
117
|
+
const status = queryResult.status;
|
|
118
|
+
if (status === "EXECUTED" || status === "PENDING") throw new require_errors.BohudurError(`Webhook cannot process status: ${status}`, 0, "validation");
|
|
119
|
+
return {
|
|
120
|
+
paykey: queryResult.paykey,
|
|
121
|
+
status
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/index.ts
|
|
126
|
+
var Bohudur = class {
|
|
127
|
+
key;
|
|
128
|
+
options;
|
|
129
|
+
constructor(key, options = {}) {
|
|
130
|
+
this.key = key;
|
|
131
|
+
this.options = options;
|
|
132
|
+
}
|
|
133
|
+
create(request) {
|
|
134
|
+
return create(this.key, this.options, request);
|
|
135
|
+
}
|
|
136
|
+
execute(request) {
|
|
137
|
+
return execute(this.key, this.options, request);
|
|
138
|
+
}
|
|
139
|
+
query(request) {
|
|
140
|
+
return query(this.key, this.options, request);
|
|
141
|
+
}
|
|
142
|
+
verifyWebhook(payload) {
|
|
143
|
+
return verifyWebhook(this.key, this.options, payload);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
//#endregion
|
|
147
|
+
module.exports = Bohudur;
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["BohudurError","ErrorCodes","path","path","BohudurError"],"sources":["../src/bohudur/http.ts","../src/bohudur/create.ts","../src/bohudur/helpers.ts","../src/bohudur/execute.ts","../src/bohudur/query.ts","../src/bohudur/verifyWebhook.ts","../src/index.ts"],"sourcesContent":["import { BohudurError, ErrorCodes } from \"@error/index\"\nimport type { BohudurOptions } from \"@type/index\"\n\nconst DEFAULT_BASEURL = \"https://request.bohudur.one\"\nconst DEFAULT_TIMEOUT = 10000\n\nexport async function Request<T>(key: string, options: BohudurOptions, path: string, body: unknown): Promise<T> {\n const baseURL = options.baseURL ?? DEFAULT_BASEURL\n const timeout = options.timeout ?? DEFAULT_TIMEOUT\n\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeout)\n\n try {\n const response = await fetch(`${baseURL}${path}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"AH-BOHUDUR-API-KEY\": key,\n ...options.headers\n },\n body: JSON.stringify(body),\n signal: controller.signal\n })\n if (!response.ok) throw new BohudurError(`Server error (HTTP ${response.status}).`, response.status, \"server\")\n\n let data: any\n try {\n data = await response.json()\n } catch {\n throw new BohudurError(\"Failed to parse server response as JSON.\", 0, \"server\")\n }\n\n if (data.status === \"failed\") throw new BohudurError(ErrorCodes[data.responseCode] ?? data.message ?? \"Server responded with failed status.\", data.responseCode, \"api\")\n return data as T\n } catch (error) {\n if (error instanceof BohudurError) throw error\n if (error instanceof Error && error.name === \"AbortError\") throw new BohudurError(`Request timed out after ${timeout}ms`, 0, \"network\")\n throw new BohudurError(error instanceof Error ? error.message : \"Unknown error\", 0, \"network\")\n } finally {\n clearTimeout(timer)\n }\n}\n","import type { BohudurOptions, CreateRequest, CreateResponse } from \"@type/index\"\nimport { Request } from \"@bohudur/http\"\n\nconst path: string = \"/create/v2/\"\n\ninterface CreateResponseWire {\n paymentkey: string\n payment_url: string\n}\n\nexport default async function create(key: string, options: BohudurOptions, request: CreateRequest): Promise<CreateResponse> {\n const data = await Request<CreateResponseWire>(key, options, path, {\n full_name: request.name,\n email: request.email,\n amount: request.amount,\n return_type: request.returnType,\n redirect_url: request.redirectURL,\n cancel_url: request.cancelURL,\n metadata: request.metadata,\n webhook: request.webhook\n })\n return {\n paykey: data.paymentkey,\n paymentURL: data.payment_url\n }\n}\n","export function toDate(raw: string): Date | null {\n if (!raw || raw === \"NONE\") return null\n return new Date(raw.replace(\" \", \"T\") + \"+06:00\")\n}\n","import type { BohudurOptions, ExecuteRequest, ExecuteResponse } from \"@type/index\"\nimport { Request } from \"@bohudur/http\"\nimport { toDate } from \"@bohudur/helpers\"\n\nconst path: string = \"/execute/v2/\"\n\ninterface ExecuteResponseWire {\n full_name: string\n email: string\n amount: number\n converted_amount: number\n total_amount: number\n transaction_fee: number\n default_currency: string\n payment_currency: string\n currency_value: number\n metadata: Record<string, unknown> | unknown[]\n created_time: string\n payment_time: string\n paymentkey: string\n receipt: string\n webhook: Record<string, unknown> | unknown[]\n payment_info: Record<string, unknown> | unknown[]\n status: \"PENDING\" | \"COMPLETED\" | \"EXECUTED\" | \"CANCELLED\"\n}\n\nexport default async function execute(key: string, options: BohudurOptions, request: ExecuteRequest): Promise<ExecuteResponse> {\n const data = await Request<ExecuteResponseWire>(key, options, path, {\n paymentkey: request.paykey\n })\n return {\n name: data.full_name,\n email: data.email,\n amount: data.amount,\n convertedAmount: data.converted_amount,\n totalAmount: data.total_amount,\n transactionFee: data.transaction_fee,\n defaultCurrency: data.default_currency,\n paymentCurrency: data.payment_currency,\n currencyValue: data.currency_value,\n metadata: Array.isArray(data.metadata) ? null : data.metadata,\n createdAt: toDate(data.created_time),\n paidAt: toDate(data.payment_time),\n paykey: data.paymentkey,\n receipt: data.receipt === \"NONE\" ? null : data.receipt,\n webhook: Array.isArray(data.webhook) ? null : data.webhook,\n paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,\n status: data.status\n }\n}\n","import type { BohudurOptions, QueryRequest, QueryResponse } from \"@type/index\"\nimport { Request } from \"@bohudur/http\"\nimport { toDate } from \"@bohudur/helpers\"\n\nconst path: string = \"/query/v2/\"\n\ninterface QueryResponseWire {\n full_name: string\n email: string\n amount: number\n converted_amount: number\n total_amount: number\n transaction_fee: number\n default_currency: string\n payment_currency: string\n currency_value: number\n metadata: Record<string, unknown> | unknown[]\n created_time: string\n payment_time: string\n paymentkey: string\n receipt: string\n webhook: Record<string, unknown> | unknown[]\n payment_info: Record<string, unknown> | unknown[]\n status: \"PENDING\" | \"COMPLETED\" | \"EXECUTED\" | \"CANCELLED\"\n}\n\nexport default async function query(key: string, options: BohudurOptions, request: QueryRequest): Promise<QueryResponse> {\n const data = await Request<QueryResponseWire>(key, options, path, {\n paymentkey: request.paykey\n })\n return {\n name: data.full_name,\n email: data.email,\n amount: data.amount,\n convertedAmount: data.converted_amount,\n totalAmount: data.total_amount,\n transactionFee: data.transaction_fee,\n defaultCurrency: data.default_currency,\n paymentCurrency: data.payment_currency,\n currencyValue: data.currency_value,\n metadata: Array.isArray(data.metadata) ? null : data.metadata,\n createdAt: toDate(data.created_time),\n paidAt: toDate(data.payment_time),\n paykey: data.paymentkey,\n receipt: data.receipt === \"NONE\" ? null : data.receipt,\n webhook: Array.isArray(data.webhook) ? null : data.webhook,\n paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,\n status: data.status\n }\n}\n","import type { BohudurOptions, WebhookPayload, WebhookResult } from \"@type/index\"\nimport { BohudurError } from \"@error/index\"\nimport query from \"@bohudur/query\"\n\nexport default async function verifyWebhook(key: string, options: BohudurOptions, payload: WebhookPayload): Promise<WebhookResult> {\n const queryResult = await query(key, options, {\n paykey: payload.paymentkey\n })\n\n const status = queryResult.status\n if (status === \"EXECUTED\" || status === \"PENDING\") throw new BohudurError(`Webhook cannot process status: ${status}`, 0, \"validation\")\n\n return {\n paykey: queryResult.paykey,\n status: status\n }\n}\n","import type { BohudurOptions, CreateRequest, ExecuteRequest, QueryRequest, WebhookPayload } from \"@type/index\"\nimport create from \"@bohudur/create\"\nimport execute from \"@bohudur/execute\"\nimport query from \"@bohudur/query\"\nimport verifyWebhook from \"@bohudur/verifyWebhook\"\n\nexport default class Bohudur {\n constructor(\n private readonly key: string,\n private readonly options: BohudurOptions = {}\n ) {}\n create(request: CreateRequest) {\n return create(this.key, this.options, request)\n }\n execute(request: ExecuteRequest) {\n return execute(this.key, this.options, request)\n }\n query(request: QueryRequest) {\n return query(this.key, this.options, request)\n }\n verifyWebhook(payload: WebhookPayload) {\n return verifyWebhook(this.key, this.options, payload)\n }\n}\n"],"mappings":";;AAGA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAExB,eAAsB,QAAW,KAAa,SAAyB,MAAc,MAA2B;CAC9G,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,UAAU,QAAQ,WAAW;CAEnC,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,QAAQ,iBAAiB,WAAW,MAAM,GAAG,OAAO;CAE1D,IAAI;EACF,MAAM,WAAW,MAAM,MAAM,GAAG,UAAU,QAAQ;GAChD,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,sBAAsB;IACtB,GAAG,QAAQ;GACb;GACA,MAAM,KAAK,UAAU,IAAI;GACzB,QAAQ,WAAW;EACrB,CAAC;EACD,IAAI,CAAC,SAAS,IAAI,MAAM,IAAIA,eAAAA,aAAa,sBAAsB,SAAS,OAAO,KAAK,SAAS,QAAQ,QAAQ;EAE7G,IAAI;EACJ,IAAI;GACF,OAAO,MAAM,SAAS,KAAK;EAC7B,QAAQ;GACN,MAAM,IAAIA,eAAAA,aAAa,4CAA4C,GAAG,QAAQ;EAChF;EAEA,IAAI,KAAK,WAAW,UAAU,MAAM,IAAIA,eAAAA,aAAaC,eAAAA,WAAW,KAAK,iBAAiB,KAAK,WAAW,wCAAwC,KAAK,cAAc,KAAK;EACtK,OAAO;CACT,SAAS,OAAO;EACd,IAAI,iBAAiBD,eAAAA,cAAc,MAAM;EACzC,IAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc,MAAM,IAAIA,eAAAA,aAAa,2BAA2B,QAAQ,KAAK,GAAG,SAAS;EACtI,MAAM,IAAIA,eAAAA,aAAa,iBAAiB,QAAQ,MAAM,UAAU,iBAAiB,GAAG,SAAS;CAC/F,UAAU;EACR,aAAa,KAAK;CACpB;AACF;;;ACvCA,MAAME,SAAe;AAOrB,eAA8B,OAAO,KAAa,SAAyB,SAAiD;CAC1H,MAAM,OAAO,MAAM,QAA4B,KAAK,SAASA,QAAM;EACjE,WAAW,QAAQ;EACnB,OAAO,QAAQ;EACf,QAAQ,QAAQ;EAChB,aAAa,QAAQ;EACrB,cAAc,QAAQ;EACtB,YAAY,QAAQ;EACpB,UAAU,QAAQ;EAClB,SAAS,QAAQ;CACnB,CAAC;CACD,OAAO;EACL,QAAQ,KAAK;EACb,YAAY,KAAK;CACnB;AACF;;;ACzBA,SAAgB,OAAO,KAA0B;CAC/C,IAAI,CAAC,OAAO,QAAQ,QAAQ,OAAO;CACnC,uBAAO,IAAI,KAAK,IAAI,QAAQ,KAAK,GAAG,IAAI,QAAQ;AAClD;;;ACCA,MAAMC,SAAe;AAsBrB,eAA8B,QAAQ,KAAa,SAAyB,SAAmD;CAC7H,MAAM,OAAO,MAAM,QAA6B,KAAK,SAASA,QAAM,EAClE,YAAY,QAAQ,OACtB,CAAC;CACD,OAAO;EACL,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,iBAAiB,KAAK;EACtB,aAAa,KAAK;EAClB,gBAAgB,KAAK;EACrB,iBAAiB,KAAK;EACtB,iBAAiB,KAAK;EACtB,eAAe,KAAK;EACpB,UAAU,MAAM,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK;EACrD,WAAW,OAAO,KAAK,YAAY;EACnC,QAAQ,OAAO,KAAK,YAAY;EAChC,QAAQ,KAAK;EACb,SAAS,KAAK,YAAY,SAAS,OAAO,KAAK;EAC/C,SAAS,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO,KAAK;EACnD,aAAa,MAAM,QAAQ,KAAK,YAAY,IAAI,OAAO,KAAK;EAC5D,QAAQ,KAAK;CACf;AACF;;;AC7CA,MAAM,OAAe;AAsBrB,eAA8B,MAAM,KAAa,SAAyB,SAA+C;CACvH,MAAM,OAAO,MAAM,QAA2B,KAAK,SAAS,MAAM,EAChE,YAAY,QAAQ,OACtB,CAAC;CACD,OAAO;EACL,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,iBAAiB,KAAK;EACtB,aAAa,KAAK;EAClB,gBAAgB,KAAK;EACrB,iBAAiB,KAAK;EACtB,iBAAiB,KAAK;EACtB,eAAe,KAAK;EACpB,UAAU,MAAM,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK;EACrD,WAAW,OAAO,KAAK,YAAY;EACnC,QAAQ,OAAO,KAAK,YAAY;EAChC,QAAQ,KAAK;EACb,SAAS,KAAK,YAAY,SAAS,OAAO,KAAK;EAC/C,SAAS,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO,KAAK;EACnD,aAAa,MAAM,QAAQ,KAAK,YAAY,IAAI,OAAO,KAAK;EAC5D,QAAQ,KAAK;CACf;AACF;;;AC7CA,eAA8B,cAAc,KAAa,SAAyB,SAAiD;CACjI,MAAM,cAAc,MAAM,MAAM,KAAK,SAAS,EAC5C,QAAQ,QAAQ,WAClB,CAAC;CAED,MAAM,SAAS,YAAY;CAC3B,IAAI,WAAW,cAAc,WAAW,WAAW,MAAM,IAAIC,eAAAA,aAAa,kCAAkC,UAAU,GAAG,YAAY;CAErI,OAAO;EACL,QAAQ,YAAY;EACZ;CACV;AACF;;;ACVA,IAAqB,UAArB,MAA6B;CAER;CACA;CAFnB,YACE,KACA,UAA2C,CAAC,GAC5C;EAFiB,KAAA,MAAA;EACA,KAAA,UAAA;CAChB;CACH,OAAO,SAAwB;EAC7B,OAAO,OAAO,KAAK,KAAK,KAAK,SAAS,OAAO;CAC/C;CACA,QAAQ,SAAyB;EAC/B,OAAO,QAAQ,KAAK,KAAK,KAAK,SAAS,OAAO;CAChD;CACA,MAAM,SAAuB;EAC3B,OAAO,MAAM,KAAK,KAAK,KAAK,SAAS,OAAO;CAC9C;CACA,cAAc,SAAyB;EACrC,OAAO,cAAc,KAAK,KAAK,KAAK,SAAS,OAAO;CACtD;AACF"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BohudurOptions, CreateRequest, CreateResponse, ExecuteRequest, ExecuteResponse, QueryRequest, QueryResponse, WebhookPayload, WebhookResult } from "./types.cjs";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
declare class Bohudur {
|
|
4
|
+
private readonly key;
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(key: string, options?: BohudurOptions);
|
|
7
|
+
create(request: CreateRequest): Promise<CreateResponse>;
|
|
8
|
+
execute(request: ExecuteRequest): Promise<ExecuteResponse>;
|
|
9
|
+
query(request: QueryRequest): Promise<QueryResponse>;
|
|
10
|
+
verifyWebhook(payload: WebhookPayload): Promise<WebhookResult>;
|
|
11
|
+
}
|
|
12
|
+
export = Bohudur;
|
|
13
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["_$_type_index0.CreateResponse","_$_type_index0.ExecuteResponse","_$_type_index0.QueryResponse","_$_type_index0.WebhookResult"],"sources":["../src/index.ts"],"mappings":";;cAMqB;mBAEA;mBACA;EAFnB,YACmB,aACA,UAAS;EAE5B,OAAO,SAAS,gBAAa,QAAbA;EAGhB,QAAQ,SAAS,iBAAc,QAAdC;EAGjB,MAAM,SAAS,eAAY,QAAZC;EAGf,cAAc,SAAS,iBAAc,QAAdC"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BohudurOptions, CreateRequest, CreateResponse, ExecuteRequest, ExecuteResponse, QueryRequest, QueryResponse, WebhookPayload, WebhookResult } from "./types.mjs";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export default class Bohudur {
|
|
4
|
+
private readonly key;
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(key: string, options?: BohudurOptions);
|
|
7
|
+
create(request: CreateRequest): Promise<CreateResponse>;
|
|
8
|
+
execute(request: ExecuteRequest): Promise<ExecuteResponse>;
|
|
9
|
+
query(request: QueryRequest): Promise<QueryResponse>;
|
|
10
|
+
verifyWebhook(payload: WebhookPayload): Promise<WebhookResult>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["_$_type_index0.CreateResponse","_$_type_index0.ExecuteResponse","_$_type_index0.QueryResponse","_$_type_index0.WebhookResult"],"sources":["../src/index.ts"],"mappings":";;qBAMqB;mBAEA;mBACA;EAFnB,YACmB,aACA,UAAS;EAE5B,OAAO,SAAS,gBAAa,QAAbA;EAGhB,QAAQ,SAAS,iBAAc,QAAdC;EAGjB,MAAM,SAAS,eAAY,QAAZC;EAGf,cAAc,SAAS,iBAAc,QAAdC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { BohudurError, ErrorCodes } from "./errors.mjs";
|
|
2
|
+
//#region src/bohudur/http.ts
|
|
3
|
+
const DEFAULT_BASEURL = "https://request.bohudur.one";
|
|
4
|
+
const DEFAULT_TIMEOUT = 1e4;
|
|
5
|
+
async function Request(key, options, path, body) {
|
|
6
|
+
const baseURL = options.baseURL ?? DEFAULT_BASEURL;
|
|
7
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
8
|
+
const controller = new AbortController();
|
|
9
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch(`${baseURL}${path}`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
"AH-BOHUDUR-API-KEY": key,
|
|
16
|
+
...options.headers
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify(body),
|
|
19
|
+
signal: controller.signal
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) throw new BohudurError(`Server error (HTTP ${response.status}).`, response.status, "server");
|
|
22
|
+
let data;
|
|
23
|
+
try {
|
|
24
|
+
data = await response.json();
|
|
25
|
+
} catch {
|
|
26
|
+
throw new BohudurError("Failed to parse server response as JSON.", 0, "server");
|
|
27
|
+
}
|
|
28
|
+
if (data.status === "failed") throw new BohudurError(ErrorCodes[data.responseCode] ?? data.message ?? "Server responded with failed status.", data.responseCode, "api");
|
|
29
|
+
return data;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof BohudurError) throw error;
|
|
32
|
+
if (error instanceof Error && error.name === "AbortError") throw new BohudurError(`Request timed out after ${timeout}ms`, 0, "network");
|
|
33
|
+
throw new BohudurError(error instanceof Error ? error.message : "Unknown error", 0, "network");
|
|
34
|
+
} finally {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/bohudur/create.ts
|
|
40
|
+
const path$2 = "/create/v2/";
|
|
41
|
+
async function create(key, options, request) {
|
|
42
|
+
const data = await Request(key, options, path$2, {
|
|
43
|
+
full_name: request.name,
|
|
44
|
+
email: request.email,
|
|
45
|
+
amount: request.amount,
|
|
46
|
+
return_type: request.returnType,
|
|
47
|
+
redirect_url: request.redirectURL,
|
|
48
|
+
cancel_url: request.cancelURL,
|
|
49
|
+
metadata: request.metadata,
|
|
50
|
+
webhook: request.webhook
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
paykey: data.paymentkey,
|
|
54
|
+
paymentURL: data.payment_url
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/bohudur/helpers.ts
|
|
59
|
+
function toDate(raw) {
|
|
60
|
+
if (!raw || raw === "NONE") return null;
|
|
61
|
+
return /* @__PURE__ */ new Date(raw.replace(" ", "T") + "+06:00");
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/bohudur/execute.ts
|
|
65
|
+
const path$1 = "/execute/v2/";
|
|
66
|
+
async function execute(key, options, request) {
|
|
67
|
+
const data = await Request(key, options, path$1, { paymentkey: request.paykey });
|
|
68
|
+
return {
|
|
69
|
+
name: data.full_name,
|
|
70
|
+
email: data.email,
|
|
71
|
+
amount: data.amount,
|
|
72
|
+
convertedAmount: data.converted_amount,
|
|
73
|
+
totalAmount: data.total_amount,
|
|
74
|
+
transactionFee: data.transaction_fee,
|
|
75
|
+
defaultCurrency: data.default_currency,
|
|
76
|
+
paymentCurrency: data.payment_currency,
|
|
77
|
+
currencyValue: data.currency_value,
|
|
78
|
+
metadata: Array.isArray(data.metadata) ? null : data.metadata,
|
|
79
|
+
createdAt: toDate(data.created_time),
|
|
80
|
+
paidAt: toDate(data.payment_time),
|
|
81
|
+
paykey: data.paymentkey,
|
|
82
|
+
receipt: data.receipt === "NONE" ? null : data.receipt,
|
|
83
|
+
webhook: Array.isArray(data.webhook) ? null : data.webhook,
|
|
84
|
+
paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,
|
|
85
|
+
status: data.status
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/bohudur/query.ts
|
|
90
|
+
const path = "/query/v2/";
|
|
91
|
+
async function query(key, options, request) {
|
|
92
|
+
const data = await Request(key, options, path, { paymentkey: request.paykey });
|
|
93
|
+
return {
|
|
94
|
+
name: data.full_name,
|
|
95
|
+
email: data.email,
|
|
96
|
+
amount: data.amount,
|
|
97
|
+
convertedAmount: data.converted_amount,
|
|
98
|
+
totalAmount: data.total_amount,
|
|
99
|
+
transactionFee: data.transaction_fee,
|
|
100
|
+
defaultCurrency: data.default_currency,
|
|
101
|
+
paymentCurrency: data.payment_currency,
|
|
102
|
+
currencyValue: data.currency_value,
|
|
103
|
+
metadata: Array.isArray(data.metadata) ? null : data.metadata,
|
|
104
|
+
createdAt: toDate(data.created_time),
|
|
105
|
+
paidAt: toDate(data.payment_time),
|
|
106
|
+
paykey: data.paymentkey,
|
|
107
|
+
receipt: data.receipt === "NONE" ? null : data.receipt,
|
|
108
|
+
webhook: Array.isArray(data.webhook) ? null : data.webhook,
|
|
109
|
+
paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,
|
|
110
|
+
status: data.status
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/bohudur/verifyWebhook.ts
|
|
115
|
+
async function verifyWebhook(key, options, payload) {
|
|
116
|
+
const queryResult = await query(key, options, { paykey: payload.paymentkey });
|
|
117
|
+
const status = queryResult.status;
|
|
118
|
+
if (status === "EXECUTED" || status === "PENDING") throw new BohudurError(`Webhook cannot process status: ${status}`, 0, "validation");
|
|
119
|
+
return {
|
|
120
|
+
paykey: queryResult.paykey,
|
|
121
|
+
status
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/index.ts
|
|
126
|
+
var Bohudur = class {
|
|
127
|
+
key;
|
|
128
|
+
options;
|
|
129
|
+
constructor(key, options = {}) {
|
|
130
|
+
this.key = key;
|
|
131
|
+
this.options = options;
|
|
132
|
+
}
|
|
133
|
+
create(request) {
|
|
134
|
+
return create(this.key, this.options, request);
|
|
135
|
+
}
|
|
136
|
+
execute(request) {
|
|
137
|
+
return execute(this.key, this.options, request);
|
|
138
|
+
}
|
|
139
|
+
query(request) {
|
|
140
|
+
return query(this.key, this.options, request);
|
|
141
|
+
}
|
|
142
|
+
verifyWebhook(payload) {
|
|
143
|
+
return verifyWebhook(this.key, this.options, payload);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
//#endregion
|
|
147
|
+
export { Bohudur as default };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["path","path"],"sources":["../src/bohudur/http.ts","../src/bohudur/create.ts","../src/bohudur/helpers.ts","../src/bohudur/execute.ts","../src/bohudur/query.ts","../src/bohudur/verifyWebhook.ts","../src/index.ts"],"sourcesContent":["import { BohudurError, ErrorCodes } from \"@error/index\"\nimport type { BohudurOptions } from \"@type/index\"\n\nconst DEFAULT_BASEURL = \"https://request.bohudur.one\"\nconst DEFAULT_TIMEOUT = 10000\n\nexport async function Request<T>(key: string, options: BohudurOptions, path: string, body: unknown): Promise<T> {\n const baseURL = options.baseURL ?? DEFAULT_BASEURL\n const timeout = options.timeout ?? DEFAULT_TIMEOUT\n\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeout)\n\n try {\n const response = await fetch(`${baseURL}${path}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"AH-BOHUDUR-API-KEY\": key,\n ...options.headers\n },\n body: JSON.stringify(body),\n signal: controller.signal\n })\n if (!response.ok) throw new BohudurError(`Server error (HTTP ${response.status}).`, response.status, \"server\")\n\n let data: any\n try {\n data = await response.json()\n } catch {\n throw new BohudurError(\"Failed to parse server response as JSON.\", 0, \"server\")\n }\n\n if (data.status === \"failed\") throw new BohudurError(ErrorCodes[data.responseCode] ?? data.message ?? \"Server responded with failed status.\", data.responseCode, \"api\")\n return data as T\n } catch (error) {\n if (error instanceof BohudurError) throw error\n if (error instanceof Error && error.name === \"AbortError\") throw new BohudurError(`Request timed out after ${timeout}ms`, 0, \"network\")\n throw new BohudurError(error instanceof Error ? error.message : \"Unknown error\", 0, \"network\")\n } finally {\n clearTimeout(timer)\n }\n}\n","import type { BohudurOptions, CreateRequest, CreateResponse } from \"@type/index\"\nimport { Request } from \"@bohudur/http\"\n\nconst path: string = \"/create/v2/\"\n\ninterface CreateResponseWire {\n paymentkey: string\n payment_url: string\n}\n\nexport default async function create(key: string, options: BohudurOptions, request: CreateRequest): Promise<CreateResponse> {\n const data = await Request<CreateResponseWire>(key, options, path, {\n full_name: request.name,\n email: request.email,\n amount: request.amount,\n return_type: request.returnType,\n redirect_url: request.redirectURL,\n cancel_url: request.cancelURL,\n metadata: request.metadata,\n webhook: request.webhook\n })\n return {\n paykey: data.paymentkey,\n paymentURL: data.payment_url\n }\n}\n","export function toDate(raw: string): Date | null {\n if (!raw || raw === \"NONE\") return null\n return new Date(raw.replace(\" \", \"T\") + \"+06:00\")\n}\n","import type { BohudurOptions, ExecuteRequest, ExecuteResponse } from \"@type/index\"\nimport { Request } from \"@bohudur/http\"\nimport { toDate } from \"@bohudur/helpers\"\n\nconst path: string = \"/execute/v2/\"\n\ninterface ExecuteResponseWire {\n full_name: string\n email: string\n amount: number\n converted_amount: number\n total_amount: number\n transaction_fee: number\n default_currency: string\n payment_currency: string\n currency_value: number\n metadata: Record<string, unknown> | unknown[]\n created_time: string\n payment_time: string\n paymentkey: string\n receipt: string\n webhook: Record<string, unknown> | unknown[]\n payment_info: Record<string, unknown> | unknown[]\n status: \"PENDING\" | \"COMPLETED\" | \"EXECUTED\" | \"CANCELLED\"\n}\n\nexport default async function execute(key: string, options: BohudurOptions, request: ExecuteRequest): Promise<ExecuteResponse> {\n const data = await Request<ExecuteResponseWire>(key, options, path, {\n paymentkey: request.paykey\n })\n return {\n name: data.full_name,\n email: data.email,\n amount: data.amount,\n convertedAmount: data.converted_amount,\n totalAmount: data.total_amount,\n transactionFee: data.transaction_fee,\n defaultCurrency: data.default_currency,\n paymentCurrency: data.payment_currency,\n currencyValue: data.currency_value,\n metadata: Array.isArray(data.metadata) ? null : data.metadata,\n createdAt: toDate(data.created_time),\n paidAt: toDate(data.payment_time),\n paykey: data.paymentkey,\n receipt: data.receipt === \"NONE\" ? null : data.receipt,\n webhook: Array.isArray(data.webhook) ? null : data.webhook,\n paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,\n status: data.status\n }\n}\n","import type { BohudurOptions, QueryRequest, QueryResponse } from \"@type/index\"\nimport { Request } from \"@bohudur/http\"\nimport { toDate } from \"@bohudur/helpers\"\n\nconst path: string = \"/query/v2/\"\n\ninterface QueryResponseWire {\n full_name: string\n email: string\n amount: number\n converted_amount: number\n total_amount: number\n transaction_fee: number\n default_currency: string\n payment_currency: string\n currency_value: number\n metadata: Record<string, unknown> | unknown[]\n created_time: string\n payment_time: string\n paymentkey: string\n receipt: string\n webhook: Record<string, unknown> | unknown[]\n payment_info: Record<string, unknown> | unknown[]\n status: \"PENDING\" | \"COMPLETED\" | \"EXECUTED\" | \"CANCELLED\"\n}\n\nexport default async function query(key: string, options: BohudurOptions, request: QueryRequest): Promise<QueryResponse> {\n const data = await Request<QueryResponseWire>(key, options, path, {\n paymentkey: request.paykey\n })\n return {\n name: data.full_name,\n email: data.email,\n amount: data.amount,\n convertedAmount: data.converted_amount,\n totalAmount: data.total_amount,\n transactionFee: data.transaction_fee,\n defaultCurrency: data.default_currency,\n paymentCurrency: data.payment_currency,\n currencyValue: data.currency_value,\n metadata: Array.isArray(data.metadata) ? null : data.metadata,\n createdAt: toDate(data.created_time),\n paidAt: toDate(data.payment_time),\n paykey: data.paymentkey,\n receipt: data.receipt === \"NONE\" ? null : data.receipt,\n webhook: Array.isArray(data.webhook) ? null : data.webhook,\n paymentInfo: Array.isArray(data.payment_info) ? null : data.payment_info,\n status: data.status\n }\n}\n","import type { BohudurOptions, WebhookPayload, WebhookResult } from \"@type/index\"\nimport { BohudurError } from \"@error/index\"\nimport query from \"@bohudur/query\"\n\nexport default async function verifyWebhook(key: string, options: BohudurOptions, payload: WebhookPayload): Promise<WebhookResult> {\n const queryResult = await query(key, options, {\n paykey: payload.paymentkey\n })\n\n const status = queryResult.status\n if (status === \"EXECUTED\" || status === \"PENDING\") throw new BohudurError(`Webhook cannot process status: ${status}`, 0, \"validation\")\n\n return {\n paykey: queryResult.paykey,\n status: status\n }\n}\n","import type { BohudurOptions, CreateRequest, ExecuteRequest, QueryRequest, WebhookPayload } from \"@type/index\"\nimport create from \"@bohudur/create\"\nimport execute from \"@bohudur/execute\"\nimport query from \"@bohudur/query\"\nimport verifyWebhook from \"@bohudur/verifyWebhook\"\n\nexport default class Bohudur {\n constructor(\n private readonly key: string,\n private readonly options: BohudurOptions = {}\n ) {}\n create(request: CreateRequest) {\n return create(this.key, this.options, request)\n }\n execute(request: ExecuteRequest) {\n return execute(this.key, this.options, request)\n }\n query(request: QueryRequest) {\n return query(this.key, this.options, request)\n }\n verifyWebhook(payload: WebhookPayload) {\n return verifyWebhook(this.key, this.options, payload)\n }\n}\n"],"mappings":";;AAGA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAExB,eAAsB,QAAW,KAAa,SAAyB,MAAc,MAA2B;CAC9G,MAAM,UAAU,QAAQ,WAAW;CACnC,MAAM,UAAU,QAAQ,WAAW;CAEnC,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,QAAQ,iBAAiB,WAAW,MAAM,GAAG,OAAO;CAE1D,IAAI;EACF,MAAM,WAAW,MAAM,MAAM,GAAG,UAAU,QAAQ;GAChD,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,sBAAsB;IACtB,GAAG,QAAQ;GACb;GACA,MAAM,KAAK,UAAU,IAAI;GACzB,QAAQ,WAAW;EACrB,CAAC;EACD,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,aAAa,sBAAsB,SAAS,OAAO,KAAK,SAAS,QAAQ,QAAQ;EAE7G,IAAI;EACJ,IAAI;GACF,OAAO,MAAM,SAAS,KAAK;EAC7B,QAAQ;GACN,MAAM,IAAI,aAAa,4CAA4C,GAAG,QAAQ;EAChF;EAEA,IAAI,KAAK,WAAW,UAAU,MAAM,IAAI,aAAa,WAAW,KAAK,iBAAiB,KAAK,WAAW,wCAAwC,KAAK,cAAc,KAAK;EACtK,OAAO;CACT,SAAS,OAAO;EACd,IAAI,iBAAiB,cAAc,MAAM;EACzC,IAAI,iBAAiB,SAAS,MAAM,SAAS,cAAc,MAAM,IAAI,aAAa,2BAA2B,QAAQ,KAAK,GAAG,SAAS;EACtI,MAAM,IAAI,aAAa,iBAAiB,QAAQ,MAAM,UAAU,iBAAiB,GAAG,SAAS;CAC/F,UAAU;EACR,aAAa,KAAK;CACpB;AACF;;;ACvCA,MAAMA,SAAe;AAOrB,eAA8B,OAAO,KAAa,SAAyB,SAAiD;CAC1H,MAAM,OAAO,MAAM,QAA4B,KAAK,SAASA,QAAM;EACjE,WAAW,QAAQ;EACnB,OAAO,QAAQ;EACf,QAAQ,QAAQ;EAChB,aAAa,QAAQ;EACrB,cAAc,QAAQ;EACtB,YAAY,QAAQ;EACpB,UAAU,QAAQ;EAClB,SAAS,QAAQ;CACnB,CAAC;CACD,OAAO;EACL,QAAQ,KAAK;EACb,YAAY,KAAK;CACnB;AACF;;;ACzBA,SAAgB,OAAO,KAA0B;CAC/C,IAAI,CAAC,OAAO,QAAQ,QAAQ,OAAO;CACnC,uBAAO,IAAI,KAAK,IAAI,QAAQ,KAAK,GAAG,IAAI,QAAQ;AAClD;;;ACCA,MAAMC,SAAe;AAsBrB,eAA8B,QAAQ,KAAa,SAAyB,SAAmD;CAC7H,MAAM,OAAO,MAAM,QAA6B,KAAK,SAASA,QAAM,EAClE,YAAY,QAAQ,OACtB,CAAC;CACD,OAAO;EACL,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,iBAAiB,KAAK;EACtB,aAAa,KAAK;EAClB,gBAAgB,KAAK;EACrB,iBAAiB,KAAK;EACtB,iBAAiB,KAAK;EACtB,eAAe,KAAK;EACpB,UAAU,MAAM,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK;EACrD,WAAW,OAAO,KAAK,YAAY;EACnC,QAAQ,OAAO,KAAK,YAAY;EAChC,QAAQ,KAAK;EACb,SAAS,KAAK,YAAY,SAAS,OAAO,KAAK;EAC/C,SAAS,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO,KAAK;EACnD,aAAa,MAAM,QAAQ,KAAK,YAAY,IAAI,OAAO,KAAK;EAC5D,QAAQ,KAAK;CACf;AACF;;;AC7CA,MAAM,OAAe;AAsBrB,eAA8B,MAAM,KAAa,SAAyB,SAA+C;CACvH,MAAM,OAAO,MAAM,QAA2B,KAAK,SAAS,MAAM,EAChE,YAAY,QAAQ,OACtB,CAAC;CACD,OAAO;EACL,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,iBAAiB,KAAK;EACtB,aAAa,KAAK;EAClB,gBAAgB,KAAK;EACrB,iBAAiB,KAAK;EACtB,iBAAiB,KAAK;EACtB,eAAe,KAAK;EACpB,UAAU,MAAM,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK;EACrD,WAAW,OAAO,KAAK,YAAY;EACnC,QAAQ,OAAO,KAAK,YAAY;EAChC,QAAQ,KAAK;EACb,SAAS,KAAK,YAAY,SAAS,OAAO,KAAK;EAC/C,SAAS,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO,KAAK;EACnD,aAAa,MAAM,QAAQ,KAAK,YAAY,IAAI,OAAO,KAAK;EAC5D,QAAQ,KAAK;CACf;AACF;;;AC7CA,eAA8B,cAAc,KAAa,SAAyB,SAAiD;CACjI,MAAM,cAAc,MAAM,MAAM,KAAK,SAAS,EAC5C,QAAQ,QAAQ,WAClB,CAAC;CAED,MAAM,SAAS,YAAY;CAC3B,IAAI,WAAW,cAAc,WAAW,WAAW,MAAM,IAAI,aAAa,kCAAkC,UAAU,GAAG,YAAY;CAErI,OAAO;EACL,QAAQ,YAAY;EACZ;CACV;AACF;;;ACVA,IAAqB,UAArB,MAA6B;CAER;CACA;CAFnB,YACE,KACA,UAA2C,CAAC,GAC5C;EAFiB,KAAA,MAAA;EACA,KAAA,UAAA;CAChB;CACH,OAAO,SAAwB;EAC7B,OAAO,OAAO,KAAK,KAAK,KAAK,SAAS,OAAO;CAC/C;CACA,QAAQ,SAAyB;EAC/B,OAAO,QAAQ,KAAK,KAAK,KAAK,SAAS,OAAO;CAChD;CACA,MAAM,SAAuB;EAC3B,OAAO,MAAM,KAAK,KAAK,KAAK,SAAS,OAAO;CAC9C;CACA,cAAc,SAAyB;EACrC,OAAO,cAAc,KAAK,KAAK,KAAK,SAAS,OAAO;CACtD;AACF"}
|
package/dist/types.cjs
ADDED
|
File without changes
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/type/options.d.ts
|
|
2
|
+
export interface BohudurOptions {
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/type/request.d.ts
|
|
9
|
+
export interface CreateRequest {
|
|
10
|
+
name: string;
|
|
11
|
+
email: string;
|
|
12
|
+
amount: number;
|
|
13
|
+
returnType: "GET" | "POST";
|
|
14
|
+
redirectURL: string;
|
|
15
|
+
cancelURL: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
webhook?: {
|
|
18
|
+
success?: string;
|
|
19
|
+
cancel?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface QueryRequest {
|
|
23
|
+
paykey: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ExecuteRequest {
|
|
26
|
+
paykey: string;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/type/response.d.ts
|
|
30
|
+
interface ExecuteOrQuery {
|
|
31
|
+
name: string;
|
|
32
|
+
email: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
convertedAmount: number;
|
|
35
|
+
totalAmount: number;
|
|
36
|
+
transactionFee: number;
|
|
37
|
+
defaultCurrency: string;
|
|
38
|
+
paymentCurrency: string;
|
|
39
|
+
currencyValue: number;
|
|
40
|
+
metadata: Record<string, unknown> | null;
|
|
41
|
+
createdAt: Date | null;
|
|
42
|
+
paidAt: Date | null;
|
|
43
|
+
paykey: string;
|
|
44
|
+
receipt: string | null;
|
|
45
|
+
webhook: Record<string, unknown> | null;
|
|
46
|
+
paymentInfo: Record<string, unknown> | null;
|
|
47
|
+
status: "PENDING" | "COMPLETED" | "EXECUTED" | "CANCELLED";
|
|
48
|
+
}
|
|
49
|
+
export interface CreateResponse {
|
|
50
|
+
paykey: string;
|
|
51
|
+
paymentURL: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ExecuteResponse extends ExecuteOrQuery {}
|
|
54
|
+
export interface QueryResponse extends ExecuteOrQuery {}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/type/webhook.d.ts
|
|
57
|
+
export interface WebhookPayload {
|
|
58
|
+
full_name: string;
|
|
59
|
+
email: string;
|
|
60
|
+
amount: number;
|
|
61
|
+
paymentkey: string;
|
|
62
|
+
status: "COMPLETED" | "CANCELLED";
|
|
63
|
+
}
|
|
64
|
+
export interface WebhookResult {
|
|
65
|
+
paykey: string;
|
|
66
|
+
status: "COMPLETED" | "CANCELLED";
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/type/options.ts","../src/type/request.ts","../src/type/response.ts","../src/type/webhook.ts"],"mappings":";iBAAiB;EACf;EACA,UAAU;EACV;;;;iBCHe;EACf;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;IACE;IACA;;;iBAIa;EACf;;iBAGe;EACf;;;;UCnBQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,WAAW;EACX,QAAQ;EACR;EACA;EACA,SAAS;EACT,aAAa;EACb;;iBAGe;EACf;EACA;;iBAGe,wBAAwB;iBAExB,sBAAsB;;;iBC3BtB;EACf;EACA;EACA;EACA;EACA;;iBAGe;EACf;EACA"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/type/options.d.ts
|
|
2
|
+
export interface BohudurOptions {
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/type/request.d.ts
|
|
9
|
+
export interface CreateRequest {
|
|
10
|
+
name: string;
|
|
11
|
+
email: string;
|
|
12
|
+
amount: number;
|
|
13
|
+
returnType: "GET" | "POST";
|
|
14
|
+
redirectURL: string;
|
|
15
|
+
cancelURL: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
webhook?: {
|
|
18
|
+
success?: string;
|
|
19
|
+
cancel?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface QueryRequest {
|
|
23
|
+
paykey: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ExecuteRequest {
|
|
26
|
+
paykey: string;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/type/response.d.ts
|
|
30
|
+
interface ExecuteOrQuery {
|
|
31
|
+
name: string;
|
|
32
|
+
email: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
convertedAmount: number;
|
|
35
|
+
totalAmount: number;
|
|
36
|
+
transactionFee: number;
|
|
37
|
+
defaultCurrency: string;
|
|
38
|
+
paymentCurrency: string;
|
|
39
|
+
currencyValue: number;
|
|
40
|
+
metadata: Record<string, unknown> | null;
|
|
41
|
+
createdAt: Date | null;
|
|
42
|
+
paidAt: Date | null;
|
|
43
|
+
paykey: string;
|
|
44
|
+
receipt: string | null;
|
|
45
|
+
webhook: Record<string, unknown> | null;
|
|
46
|
+
paymentInfo: Record<string, unknown> | null;
|
|
47
|
+
status: "PENDING" | "COMPLETED" | "EXECUTED" | "CANCELLED";
|
|
48
|
+
}
|
|
49
|
+
export interface CreateResponse {
|
|
50
|
+
paykey: string;
|
|
51
|
+
paymentURL: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ExecuteResponse extends ExecuteOrQuery {}
|
|
54
|
+
export interface QueryResponse extends ExecuteOrQuery {}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/type/webhook.d.ts
|
|
57
|
+
export interface WebhookPayload {
|
|
58
|
+
full_name: string;
|
|
59
|
+
email: string;
|
|
60
|
+
amount: number;
|
|
61
|
+
paymentkey: string;
|
|
62
|
+
status: "COMPLETED" | "CANCELLED";
|
|
63
|
+
}
|
|
64
|
+
export interface WebhookResult {
|
|
65
|
+
paykey: string;
|
|
66
|
+
status: "COMPLETED" | "CANCELLED";
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/type/options.ts","../src/type/request.ts","../src/type/response.ts","../src/type/webhook.ts"],"mappings":";iBAAiB;EACf;EACA,UAAU;EACV;;;;iBCHe;EACf;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;IACE;IACA;;;iBAIa;EACf;;iBAGe;EACf;;;;UCnBQ;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,WAAW;EACX,QAAQ;EACR;EACA;EACA,SAAS;EACT,aAAa;EACb;;iBAGe;EACf;EACA;;iBAGe,wBAAwB;iBAExB,sBAAsB;;;iBC3BtB;EACf;EACA;EACA;EACA;EACA;;iBAGe;EACf;EACA"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bohudur",
|
|
3
|
+
"author": "@theabmmohi",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"bohudur",
|
|
8
|
+
"payment",
|
|
9
|
+
"binance",
|
|
10
|
+
"bkash",
|
|
11
|
+
"nagad",
|
|
12
|
+
"rocket",
|
|
13
|
+
"sdk"
|
|
14
|
+
],
|
|
15
|
+
"description": "TypeScript SDK for the Bohudur payment automation software",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/theabmmohi/bohudur.git"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "tsdown --watch",
|
|
25
|
+
"format:fix": "prettier --write \"src/**/*.ts\"",
|
|
26
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"build": "tsdown",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"pack:check": "npm pack --dry-run",
|
|
31
|
+
"prepublishOnly": "npm run typecheck && npm run test && npm run build"
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"type": "module",
|
|
35
|
+
"module": "./dist/index.mjs",
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/index.d.mts",
|
|
41
|
+
"default": "./dist/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/index.d.cts",
|
|
45
|
+
"default": "./dist/index.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./types": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/types.d.mts",
|
|
51
|
+
"default": "./dist/types.mjs"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/types.d.cts",
|
|
55
|
+
"default": "./dist/types.cjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./errors": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/errors.d.mts",
|
|
61
|
+
"default": "./dist/errors.mjs"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./dist/errors.d.cts",
|
|
65
|
+
"default": "./dist/errors.cjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"./package.json": "./package.json"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=18"
|
|
72
|
+
},
|
|
73
|
+
"sideEffects": false,
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@types/node": "^26.6.2",
|
|
76
|
+
"prettier": "3.9.9",
|
|
77
|
+
"tsdown": "^0.23.0",
|
|
78
|
+
"typescript": "^7.0.2",
|
|
79
|
+
"unrun": "^0.3.1",
|
|
80
|
+
"vitest": "^5.0.1"
|
|
81
|
+
}
|
|
82
|
+
}
|