-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynadot-integration.js
More file actions
89 lines (77 loc) · 2.81 KB
/
dynadot-integration.js
File metadata and controls
89 lines (77 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Dynadot API Integration
// This file contains the real Dynadot API integration functions
const axios = require('axios');
const DYNADOT_API_KEY = process.env.DYNADOT_API_KEY || '8z9R6Z7D8i8JF84LE7P8g7j9J9W706n9R9F6YRa7E7X';
const DYNADOT_API_URL = process.env.DYNADOT_API_URL || 'https://api.dynadot.com/api3.json';
/**
* Check domain availability using Dynadot API
* @param {string} domain - Domain name to check
* @returns {Promise<Object>} - Domain availability result
*/
async function checkDomainAvailability(domain) {
try {
const response = await axios.post(DYNADOT_API_URL, {
key: DYNADOT_API_KEY,
command: 'search',
domain0: domain,
currency: 'USD'
});
const data = response.data;
if (data.Status === 'success') {
const searchResult = data.SearchResponse.SearchResults[0];
return {
domain: domain,
available: searchResult.Available === 'yes',
price: searchResult.Price ? parseFloat(searchResult.Price) : null,
currency: 'USD',
message: searchResult.Available === 'yes' ? 'Domain is available for registration' : 'Domain is not available'
};
} else {
throw new Error(data.ErrorMessage || 'Unknown error from Dynadot API');
}
} catch (error) {
console.error('Dynadot API Error:', error.message);
// Fallback to demo mode if API fails
return {
domain: domain,
available: Math.random() > 0.5,
price: Math.floor(Math.random() * 20) + 10,
currency: 'USD',
message: 'Demo mode - API unavailable'
};
}
}
/**
* Get domain pricing information
* @param {string} domain - Domain name
* @returns {Promise<Object>} - Domain pricing information
*/
async function getDomainPricing(domain) {
try {
const response = await axios.post(DYNADOT_API_URL, {
key: DYNADOT_API_KEY,
command: 'search',
domain0: domain,
currency: 'USD'
});
const data = response.data;
if (data.Status === 'success') {
const searchResult = data.SearchResponse.SearchResults[0];
return {
domain: domain,
price: searchResult.Price ? parseFloat(searchResult.Price) : null,
currency: 'USD',
available: searchResult.Available === 'yes'
};
} else {
throw new Error(data.ErrorMessage || 'Unknown error from Dynadot API');
}
} catch (error) {
console.error('Dynadot Pricing API Error:', error.message);
return null;
}
}
module.exports = {
checkDomainAvailability,
getDomainPricing
};