creatachain-payment-gateway 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 +22 -0
- package/coins.js +66 -0
- package/index.js +28 -0
- package/package.json +21 -0
- package/payments.js +83 -0
- package/subscription.js +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Payment Gateway
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install creatachain-payment-gateway
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
const PaymentGateway = require("creatachain-payment-gateway");
|
|
13
|
+
|
|
14
|
+
const client = PaymentGateway({
|
|
15
|
+
API_KEY: process.env.API_KEY,
|
|
16
|
+
SECRET_KEY: process.env.SECRET_KEY
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await client.Payment.payWithCTA({
|
|
20
|
+
amount: 1
|
|
21
|
+
});
|
|
22
|
+
```
|
package/coins.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
|
|
3
|
+
class Coins {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
this.basePath = "/api/v1/supportcoin";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Internal request helper
|
|
10
|
+
async request(method, path, data = {}, params = {}) {
|
|
11
|
+
try {
|
|
12
|
+
const res = await axios({
|
|
13
|
+
method,
|
|
14
|
+
url: `${this.client.baseUrl}${path}`,
|
|
15
|
+
headers: {
|
|
16
|
+
"api-key": this.client.apiKey,
|
|
17
|
+
"secret-key": this.client.apiSecret,
|
|
18
|
+
"Content-Type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
data,
|
|
21
|
+
params
|
|
22
|
+
});
|
|
23
|
+
return res.data;
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (err.response) {
|
|
26
|
+
throw new Error(err.response.data?.message || "API request failed");
|
|
27
|
+
}
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Crypto payment methods
|
|
33
|
+
async getSupportedCoins(payload) {
|
|
34
|
+
if(payload && payload.symbol) {
|
|
35
|
+
return this.request("GET", `${this.basePath}/coins`, {}, { symbol: payload.symbol });
|
|
36
|
+
}
|
|
37
|
+
return this.request("GET", `${this.basePath}/coins`, {});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async getCoin(symbol) {
|
|
41
|
+
if (!symbol) throw new Error("Coin symbol is required");
|
|
42
|
+
return this.request("GET", `${this.basePath}/${symbol}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async currencyConverter(payload) {
|
|
46
|
+
let { curr_out, usd_amount } = payload;
|
|
47
|
+
const currency = curr_out?.toUpperCase();
|
|
48
|
+
const usdAmount = parseFloat(usd_amount);
|
|
49
|
+
|
|
50
|
+
if (!currency) {
|
|
51
|
+
throw new Error("Invalid out currency..");
|
|
52
|
+
}
|
|
53
|
+
if(isNaN(usdAmount) || usdAmount <= 0)
|
|
54
|
+
{
|
|
55
|
+
throw new Error("Invalid usd amount..");
|
|
56
|
+
}
|
|
57
|
+
return this.request("GET", `${this.basePath}/converter`, {}, { curr_out, usd_amount });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async accountDetail() {
|
|
61
|
+
return this.request("GET", `${this.basePath}/my_wallet`, {}, {});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = Coins;
|
package/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/sdk/index.js
|
|
2
|
+
const Payment = require("./payments");
|
|
3
|
+
const Coins = require("./coins");
|
|
4
|
+
const Subscription = require("./subscription");
|
|
5
|
+
|
|
6
|
+
let baseUrl = "http://182.176.169.225:19007";
|
|
7
|
+
|
|
8
|
+
class Client {
|
|
9
|
+
constructor({ API_KEY, SECRET_KEY }) {
|
|
10
|
+
if (!API_KEY || !SECRET_KEY) {
|
|
11
|
+
throw new Error("API_KEY and SECRET_KEY are required");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
this.apiKey = API_KEY;
|
|
15
|
+
this.apiSecret = SECRET_KEY;
|
|
16
|
+
this.baseUrl = baseUrl || "http://182.176.169.225:19007";
|
|
17
|
+
|
|
18
|
+
this.Payment = new Payment(this);
|
|
19
|
+
this.Coins = new Coins(this);
|
|
20
|
+
this.Subscription = new Subscription(this);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function PaymentGateway(config = {}) {
|
|
25
|
+
return new Client(config);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = PaymentGateway;
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "creatachain-payment-gateway",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"payment",
|
|
11
|
+
"crypto",
|
|
12
|
+
"gateway",
|
|
13
|
+
"sdk",
|
|
14
|
+
"creatachain"
|
|
15
|
+
],
|
|
16
|
+
"author": "Nadeem",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"axios": "^1.13.4"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/payments.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
|
|
3
|
+
class Payment {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
this.basePath = "/api/v2/order";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Internal request helper
|
|
10
|
+
async request(method, path, data) {
|
|
11
|
+
try {
|
|
12
|
+
const res = await axios({
|
|
13
|
+
method,
|
|
14
|
+
url: `${this.client.baseUrl}${path}`,
|
|
15
|
+
headers: {
|
|
16
|
+
"api-key": this.client.apiKey,
|
|
17
|
+
"secret-key": this.client.apiSecret,
|
|
18
|
+
"Content-Type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
data
|
|
21
|
+
});
|
|
22
|
+
return res.data;
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (err.response) {
|
|
25
|
+
throw new Error(err.response.data?.message || "API request failed");
|
|
26
|
+
}
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Crypto payment methods
|
|
32
|
+
async payWithCTA(payload) {
|
|
33
|
+
await checkPayload(payload);
|
|
34
|
+
return this.request("POST", `${this.basePath}/cta-order-submit`, payload);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async payWithUSDT(payload) {
|
|
38
|
+
await checkPayload(payload);
|
|
39
|
+
return this.request("POST", `${this.basePath}/usdt-order-submit`, payload);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async payWithBTC(payload) {
|
|
43
|
+
await checkPayload(payload);
|
|
44
|
+
return this.request("POST", `${this.basePath}/btc-order-submit`, payload);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async payWithETH(payload) {
|
|
48
|
+
await checkPayload(payload);
|
|
49
|
+
return this.request("POST", `${this.basePath}/eth-order-submit`, payload);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async getTransactions(params) {
|
|
53
|
+
return this.request("GET", `${this.basePath}/get-transactions`, { params });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async verifySignature(payload) {
|
|
57
|
+
return this.request("POST", `${this.basePath}/verify-signature`, payload);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async supportedCoin(payload) {
|
|
61
|
+
return this.request("POST", `${this.basePath}/supported-coin`, payload);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function checkPayload(payload) {
|
|
66
|
+
const requiredFields = {
|
|
67
|
+
senderAddress: "Sender address is required",
|
|
68
|
+
amount: "Amount is required",
|
|
69
|
+
email: "Email is required",
|
|
70
|
+
currency: "Currency is required",
|
|
71
|
+
phoneNumber: "Phone number is required",
|
|
72
|
+
orderId: "Order ID is required",
|
|
73
|
+
orderDescription: "Order description is required",
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
for (const [field, message] of Object.entries(requiredFields)) {
|
|
77
|
+
if (!payload[field]) {
|
|
78
|
+
throw new Error(message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = Payment;
|
package/subscription.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
|
|
3
|
+
class Subscription {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
this.basePath = "/api/v1/subscription";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Internal request helper
|
|
10
|
+
async request(method, path, data = {}, params = {}) {
|
|
11
|
+
try {
|
|
12
|
+
const res = await axios({
|
|
13
|
+
method,
|
|
14
|
+
url: `${this.client.baseUrl}${path}`,
|
|
15
|
+
headers: {
|
|
16
|
+
"api-key": this.client.apiKey,
|
|
17
|
+
"secret-key": this.client.apiSecret,
|
|
18
|
+
"Content-Type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
data,
|
|
21
|
+
params
|
|
22
|
+
});
|
|
23
|
+
return res.data;
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (err.response) {
|
|
26
|
+
throw new Error(err.response.data?.message || "API request failed");
|
|
27
|
+
}
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async mySubscription() {
|
|
33
|
+
return this.request("GET", `${this.basePath}/mySubscriptions`, {});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = Subscription;
|