-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmy-prices.php
76 lines (53 loc) · 1.86 KB
/
my-prices.php
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
<?php
// Require ODR API demo class
require_once '../Api/Odr.php';
// Configuration array, with user API Keys
$config = array(
'api_key' => '#API_KEY#',
'api_secret' => '#API_SECRET#',
);
// ID of billing plan you want to know how to register
// If ID = NULL, current user's billing plan ID will be used
$billingPlanId = null;
// Create new instance of API demo class
$demo = new Api_Odr($config);
// Login into API
$demo->login();
$loginResult = $demo->getResult();
if ($loginResult['status'] === Api_Odr::STATUS_ERROR) {
echo 'Can\'t login, reason - '. $loginResult['response'];
exit(1);
}
if ($billingPlanId === null) {
$demo->custom('/user');
$user = $demo->getResult();
$billingPlanId = $user['response']['billing_plan_id'];
}
if ($billingPlanId === null) {
echo 'Unknown billing plan ID, please contact administration team';
exit(1);
}
// Request information about domain registration
$demo->custom('/billing-plan/' . $billingPlanId . '/items/');
// Get result of request
$result = $demo->getResult();
if ($result['status'] !== Api_Odr::STATUS_SUCCESS) {
echo 'Following error occurred: '. (is_array($result['response']) ? $result['response']['message'] : $result['response']);
if (!empty($result['response']['data'])) {
foreach ($result['response']['data'] as $name => $error) {
echo "\r\n\t{$name}: {$error}";
}
}
exit(1);
}
$result = $result['response'];
$registerPrices = array();
foreach ($result['items'] as $tld => $ops) {
if (empty($ops['create_domain'])) {
continue;
}
echo 'Price for .' . $tld . ' - ' . $ops['create_domain'] . '' . PHP_EOL; // This is just a demonstration
$registerPrices[$tld] = $ops['create_domain'];
}
// $registerPrices is key-value, where key is a TLD and value is a price for registering domain within TLD
print_r($registerPrices);