orvex-pay 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # OrvexPay Node.js SDK
2
+
3
+ The official Node.js SDK for integrating with the OrvexPay API. Fast, type-safe, and easy to use.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install orvex-pay
9
+ ```
10
+
11
+ ## Getting Started
12
+
13
+ Initialize the client with your API Key (from the Merchant Dashboard).
14
+
15
+ ```typescript
16
+ import { OrvexClient } from 'orvex-pay';
17
+
18
+ const orvex = new OrvexClient({
19
+ apiKey: 'your_api_key_here.xxxxxxxxxxxxxxxxxxxxxxxx',
20
+ });
21
+
22
+ // Create a new invoice payment link
23
+ async function main() {
24
+ try {
25
+ const invoice = await orvex.invoices.create({
26
+ priceAmount: 50.00,
27
+ priceCurrency: "USD",
28
+ payCurrency: "USDT",
29
+ orderId: "ORDER-12345",
30
+ successUrl: "https://yourwebsite.com/success",
31
+ cancelUrl: "https://yourwebsite.com/cancel",
32
+ orderDescription: "Premium Subscription"
33
+ });
34
+
35
+ console.log("Payment URL:", invoice.payUrl);
36
+ } catch (error) {
37
+ console.error("Error creating invoice:", error);
38
+ }
39
+ }
40
+
41
+ main();
42
+ ```
43
+
44
+ ## Resources
45
+
46
+ Currently, this SDK supports the `invoices` resource.
47
+
48
+ ### `orvex.invoices.create(params)`
49
+ Creates a new payment invoice and returns an `InvoiceResponse` containing the `payUrl`.
50
+
51
+ ### `orvex.invoices.retrieve(invoiceId)`
52
+ Gets the status of an existing invoice using its `invoiceId`.
53
+
54
+ ---
55
+
56
+ *For full API documentation, visit the [OrvexPay Developer Portal](https://orvexpay.com/developers/docs).*
@@ -0,0 +1,65 @@
1
+ import { AxiosInstance } from 'axios';
2
+
3
+ interface CreateInvoiceRequest {
4
+ /** The amount the merchant wants to receive, e.g. "100.00" */
5
+ priceAmount: string | number;
6
+ /** The fiat currency of the price, e.g. "TRY", "USD", "EUR" */
7
+ priceCurrency: string;
8
+ /** The cryptocurrency the user will pay in, e.g. "USDT", "BTC" */
9
+ payCurrency: string;
10
+ /** Customer's return URL after successful payment */
11
+ successUrl: string;
12
+ /** Customer's return URL after choosing to cancel */
13
+ cancelUrl: string;
14
+ /** Merchant's internal reference ID for this order */
15
+ orderId: string;
16
+ /** Optional description for the order to display on the checkout page */
17
+ orderDescription?: string;
18
+ /** Whether the merchant or customer pays the network fee (Merchant or Customer) */
19
+ feePayer?: 'Merchant' | 'Customer';
20
+ }
21
+ interface InvoiceResponse {
22
+ id: string;
23
+ invoiceId: string;
24
+ orderId: string;
25
+ priceAmount: number;
26
+ priceCurrency: string;
27
+ payAmount: number;
28
+ payCurrency: string;
29
+ payAddress: string;
30
+ status: string;
31
+ createdAt: string;
32
+ expiresAt: string;
33
+ payUrl: string;
34
+ }
35
+ interface OrvexApiClientOptions {
36
+ /** The API Key generated from your Merchant Dashboard */
37
+ apiKey: string;
38
+ /** Optional custom base URL. Defaults to https://api.orvexpay.com */
39
+ baseURL?: string;
40
+ }
41
+
42
+ declare class InvoicesResource {
43
+ private client;
44
+ constructor(client: AxiosInstance);
45
+ /**
46
+ * Creates a new payment invoice.
47
+ * @param params
48
+ * @returns
49
+ */
50
+ create(params: CreateInvoiceRequest): Promise<InvoiceResponse>;
51
+ /**
52
+ * Retrieves an invoice by its invoiceId.
53
+ * @param id The invoice ID returned by the initial API call
54
+ * @returns
55
+ */
56
+ retrieve(invoiceId: string): Promise<InvoiceResponse>;
57
+ }
58
+
59
+ declare class OrvexClient {
60
+ invoices: InvoicesResource;
61
+ private readonly client;
62
+ constructor(options: OrvexApiClientOptions);
63
+ }
64
+
65
+ export { type CreateInvoiceRequest, type InvoiceResponse, InvoicesResource, type OrvexApiClientOptions, OrvexClient };
@@ -0,0 +1,65 @@
1
+ import { AxiosInstance } from 'axios';
2
+
3
+ interface CreateInvoiceRequest {
4
+ /** The amount the merchant wants to receive, e.g. "100.00" */
5
+ priceAmount: string | number;
6
+ /** The fiat currency of the price, e.g. "TRY", "USD", "EUR" */
7
+ priceCurrency: string;
8
+ /** The cryptocurrency the user will pay in, e.g. "USDT", "BTC" */
9
+ payCurrency: string;
10
+ /** Customer's return URL after successful payment */
11
+ successUrl: string;
12
+ /** Customer's return URL after choosing to cancel */
13
+ cancelUrl: string;
14
+ /** Merchant's internal reference ID for this order */
15
+ orderId: string;
16
+ /** Optional description for the order to display on the checkout page */
17
+ orderDescription?: string;
18
+ /** Whether the merchant or customer pays the network fee (Merchant or Customer) */
19
+ feePayer?: 'Merchant' | 'Customer';
20
+ }
21
+ interface InvoiceResponse {
22
+ id: string;
23
+ invoiceId: string;
24
+ orderId: string;
25
+ priceAmount: number;
26
+ priceCurrency: string;
27
+ payAmount: number;
28
+ payCurrency: string;
29
+ payAddress: string;
30
+ status: string;
31
+ createdAt: string;
32
+ expiresAt: string;
33
+ payUrl: string;
34
+ }
35
+ interface OrvexApiClientOptions {
36
+ /** The API Key generated from your Merchant Dashboard */
37
+ apiKey: string;
38
+ /** Optional custom base URL. Defaults to https://api.orvexpay.com */
39
+ baseURL?: string;
40
+ }
41
+
42
+ declare class InvoicesResource {
43
+ private client;
44
+ constructor(client: AxiosInstance);
45
+ /**
46
+ * Creates a new payment invoice.
47
+ * @param params
48
+ * @returns
49
+ */
50
+ create(params: CreateInvoiceRequest): Promise<InvoiceResponse>;
51
+ /**
52
+ * Retrieves an invoice by its invoiceId.
53
+ * @param id The invoice ID returned by the initial API call
54
+ * @returns
55
+ */
56
+ retrieve(invoiceId: string): Promise<InvoiceResponse>;
57
+ }
58
+
59
+ declare class OrvexClient {
60
+ invoices: InvoicesResource;
61
+ private readonly client;
62
+ constructor(options: OrvexApiClientOptions);
63
+ }
64
+
65
+ export { type CreateInvoiceRequest, type InvoiceResponse, InvoicesResource, type OrvexApiClientOptions, OrvexClient };
package/dist/index.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ InvoicesResource: () => InvoicesResource,
34
+ OrvexClient: () => OrvexClient
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/client.ts
39
+ var import_axios = __toESM(require("axios"));
40
+
41
+ // src/resources/invoices.ts
42
+ var InvoicesResource = class {
43
+ client;
44
+ constructor(client) {
45
+ this.client = client;
46
+ }
47
+ /**
48
+ * Creates a new payment invoice.
49
+ * @param params
50
+ * @returns
51
+ */
52
+ async create(params) {
53
+ try {
54
+ const response = await this.client.post("/api/invoice", params);
55
+ return response.data;
56
+ } catch (error) {
57
+ if (error.response && error.response.data) {
58
+ throw new Error(`OrvexPay API Error: ${JSON.stringify(error.response.data)}`);
59
+ }
60
+ throw error;
61
+ }
62
+ }
63
+ /**
64
+ * Retrieves an invoice by its invoiceId.
65
+ * @param id The invoice ID returned by the initial API call
66
+ * @returns
67
+ */
68
+ async retrieve(invoiceId) {
69
+ try {
70
+ const response = await this.client.get(`/api/invoice/${invoiceId}`);
71
+ return response.data;
72
+ } catch (error) {
73
+ if (error.response && error.response.data) {
74
+ throw new Error(`OrvexPay API Error: ${JSON.stringify(error.response.data)}`);
75
+ }
76
+ throw error;
77
+ }
78
+ }
79
+ };
80
+
81
+ // src/client.ts
82
+ var OrvexClient = class {
83
+ invoices;
84
+ client;
85
+ constructor(options) {
86
+ if (!options.apiKey) {
87
+ throw new Error("OrvexPay: apiKey is required to initialize the client.");
88
+ }
89
+ this.client = import_axios.default.create({
90
+ baseURL: options.baseURL ? options.baseURL.replace(/\/$/, "") : "https://api.orvexpay.com",
91
+ headers: {
92
+ "x-api-key": options.apiKey,
93
+ "Content-Type": "application/json"
94
+ },
95
+ timeout: 3e4
96
+ });
97
+ this.invoices = new InvoicesResource(this.client);
98
+ }
99
+ };
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ InvoicesResource,
103
+ OrvexClient
104
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ // src/client.ts
2
+ import axios from "axios";
3
+
4
+ // src/resources/invoices.ts
5
+ var InvoicesResource = class {
6
+ client;
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ /**
11
+ * Creates a new payment invoice.
12
+ * @param params
13
+ * @returns
14
+ */
15
+ async create(params) {
16
+ try {
17
+ const response = await this.client.post("/api/invoice", params);
18
+ return response.data;
19
+ } catch (error) {
20
+ if (error.response && error.response.data) {
21
+ throw new Error(`OrvexPay API Error: ${JSON.stringify(error.response.data)}`);
22
+ }
23
+ throw error;
24
+ }
25
+ }
26
+ /**
27
+ * Retrieves an invoice by its invoiceId.
28
+ * @param id The invoice ID returned by the initial API call
29
+ * @returns
30
+ */
31
+ async retrieve(invoiceId) {
32
+ try {
33
+ const response = await this.client.get(`/api/invoice/${invoiceId}`);
34
+ return response.data;
35
+ } catch (error) {
36
+ if (error.response && error.response.data) {
37
+ throw new Error(`OrvexPay API Error: ${JSON.stringify(error.response.data)}`);
38
+ }
39
+ throw error;
40
+ }
41
+ }
42
+ };
43
+
44
+ // src/client.ts
45
+ var OrvexClient = class {
46
+ invoices;
47
+ client;
48
+ constructor(options) {
49
+ if (!options.apiKey) {
50
+ throw new Error("OrvexPay: apiKey is required to initialize the client.");
51
+ }
52
+ this.client = axios.create({
53
+ baseURL: options.baseURL ? options.baseURL.replace(/\/$/, "") : "https://api.orvexpay.com",
54
+ headers: {
55
+ "x-api-key": options.apiKey,
56
+ "Content-Type": "application/json"
57
+ },
58
+ timeout: 3e4
59
+ });
60
+ this.invoices = new InvoicesResource(this.client);
61
+ }
62
+ };
63
+ export {
64
+ InvoicesResource,
65
+ OrvexClient
66
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "orvex-pay",
3
+ "version": "1.0.0",
4
+ "description": "Official Node.js SDK for the OrvexPay API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsup src/index.ts --format cjs,esm --dts",
10
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "orvexpay",
15
+ "crypto",
16
+ "payment",
17
+ "sdk"
18
+ ],
19
+ "author": "OrvexPay",
20
+ "license": "MIT",
21
+ "dependencies": {
22
+ "axios": "^1.6.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^20.0.0",
26
+ "tsup": "^8.0.0",
27
+ "typescript": "^5.0.0"
28
+ }
29
+ }
package/src/client.ts ADDED
@@ -0,0 +1,25 @@
1
+ import axios, { AxiosInstance } from 'axios';
2
+ import { OrvexApiClientOptions } from './types';
3
+ import { InvoicesResource } from './resources/invoices';
4
+
5
+ export class OrvexClient {
6
+ public invoices: InvoicesResource;
7
+ private readonly client: AxiosInstance;
8
+
9
+ constructor(options: OrvexApiClientOptions) {
10
+ if (!options.apiKey) {
11
+ throw new Error('OrvexPay: apiKey is required to initialize the client.');
12
+ }
13
+
14
+ this.client = axios.create({
15
+ baseURL: options.baseURL ? options.baseURL.replace(/\/$/, '') : 'https://api.orvexpay.com',
16
+ headers: {
17
+ 'x-api-key': options.apiKey,
18
+ 'Content-Type': 'application/json',
19
+ },
20
+ timeout: 30000,
21
+ });
22
+
23
+ this.invoices = new InvoicesResource(this.client);
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './client';
2
+ export * from './types';
3
+ export * from './resources/invoices';
@@ -0,0 +1,44 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { CreateInvoiceRequest, InvoiceResponse } from '../types';
3
+
4
+ export class InvoicesResource {
5
+ private client: AxiosInstance;
6
+
7
+ constructor(client: AxiosInstance) {
8
+ this.client = client;
9
+ }
10
+
11
+ /**
12
+ * Creates a new payment invoice.
13
+ * @param params
14
+ * @returns
15
+ */
16
+ async create(params: CreateInvoiceRequest): Promise<InvoiceResponse> {
17
+ try {
18
+ const response = await this.client.post<InvoiceResponse>('/api/invoice', params);
19
+ return response.data;
20
+ } catch (error: any) {
21
+ if (error.response && error.response.data) {
22
+ throw new Error(`OrvexPay API Error: ${JSON.stringify(error.response.data)}`);
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Retrieves an invoice by its invoiceId.
30
+ * @param id The invoice ID returned by the initial API call
31
+ * @returns
32
+ */
33
+ async retrieve(invoiceId: string): Promise<InvoiceResponse> {
34
+ try {
35
+ const response = await this.client.get<InvoiceResponse>(`/api/invoice/${invoiceId}`);
36
+ return response.data;
37
+ } catch (error: any) {
38
+ if (error.response && error.response.data) {
39
+ throw new Error(`OrvexPay API Error: ${JSON.stringify(error.response.data)}`);
40
+ }
41
+ throw error;
42
+ }
43
+ }
44
+ }
package/src/types.ts ADDED
@@ -0,0 +1,40 @@
1
+ export interface CreateInvoiceRequest {
2
+ /** The amount the merchant wants to receive, e.g. "100.00" */
3
+ priceAmount: string | number;
4
+ /** The fiat currency of the price, e.g. "TRY", "USD", "EUR" */
5
+ priceCurrency: string;
6
+ /** The cryptocurrency the user will pay in, e.g. "USDT", "BTC" */
7
+ payCurrency: string;
8
+ /** Customer's return URL after successful payment */
9
+ successUrl: string;
10
+ /** Customer's return URL after choosing to cancel */
11
+ cancelUrl: string;
12
+ /** Merchant's internal reference ID for this order */
13
+ orderId: string;
14
+ /** Optional description for the order to display on the checkout page */
15
+ orderDescription?: string;
16
+ /** Whether the merchant or customer pays the network fee (Merchant or Customer) */
17
+ feePayer?: 'Merchant' | 'Customer';
18
+ }
19
+
20
+ export interface InvoiceResponse {
21
+ id: string;
22
+ invoiceId: string;
23
+ orderId: string;
24
+ priceAmount: number;
25
+ priceCurrency: string;
26
+ payAmount: number;
27
+ payCurrency: string;
28
+ payAddress: string;
29
+ status: string;
30
+ createdAt: string;
31
+ expiresAt: string;
32
+ payUrl: string;
33
+ }
34
+
35
+ export interface OrvexApiClientOptions {
36
+ /** The API Key generated from your Merchant Dashboard */
37
+ apiKey: string;
38
+ /** Optional custom base URL. Defaults to https://api.orvexpay.com */
39
+ baseURL?: string;
40
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "declaration": true,
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "outDir": "./dist"
12
+ },
13
+ "include": [
14
+ "src/**/*"
15
+ ]
16
+ }