whmcsor 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/lib/whmcsor/base.rb +94 -0
- data/lib/whmcsor/client.rb +191 -0
- data/lib/whmcsor/config.rb +103 -0
- data/lib/whmcsor/orders.rb +119 -0
- data/lib/whmcsor/payment.rb +240 -0
- data/lib/whmcsor/version.rb +3 -0
- data/lib/whmcsor.rb +70 -0
- data/whmcsor.gemspec +24 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 52c90daef743f65b7db99fcf29dda73557970540
|
4
|
+
data.tar.gz: e9c0a6cf38dd6d1f99cff6c3b4eb3d2068f4643f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f5dfcb327f57a055e5686680b58a29a4e6adad63019c7b12470b7ed6d15221cc6864aff9401b254a491e0ee894aa12aec45658c6e9f09044bf5577393609616d
|
7
|
+
data.tar.gz: a67ac5475c4ca7714acbbfa38581f7b2eb99d2a0b8dbe34c308e761dfcf106e8b8c018f9af16a6afa7f73c9c40c431cc869363fc20a53a79758b81753ab8df41
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Whmcsor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'whmcsor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install whmcsor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/whmcsor/base.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
module Whmcsor
|
2
|
+
# Whmcsor:Base class is the main class used to extend WHMCS API subclasses
|
3
|
+
class Base
|
4
|
+
|
5
|
+
# Public - Send request to the WHMCS API
|
6
|
+
def send_request(params = {})
|
7
|
+
if params[:action].nil?
|
8
|
+
raise ArgumentError, "No API action set"
|
9
|
+
end
|
10
|
+
check_config
|
11
|
+
check_whmcs_details
|
12
|
+
|
13
|
+
params.merge!(
|
14
|
+
username: Whmcsor.config[:whmcs_user],
|
15
|
+
password: Digest::MD5.new.hexdigest(Whmcsor.config[:whmcs_pass]),
|
16
|
+
responsetype: 'json'
|
17
|
+
)
|
18
|
+
|
19
|
+
agent = Mechanize.new
|
20
|
+
|
21
|
+
# Set User-Agent
|
22
|
+
agent.user_agent_alias = select_user_agent
|
23
|
+
|
24
|
+
#
|
25
|
+
# Use Proxy to connect instead of a direct connection
|
26
|
+
#
|
27
|
+
unless Whmcsor.config[:proxy_ip].nil? &&
|
28
|
+
Whmcsor.config[:proxy_port].nil?
|
29
|
+
agent.set_proxy(Whmcsor.config[:proxy_ip],
|
30
|
+
Whmcsor.config[:proxy_port].to_i)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Set HTTP Authentication block
|
35
|
+
#
|
36
|
+
unless Whmcsor.config[:auth_user].nil?
|
37
|
+
agent.add_auth(Whmcsor.config[:whmcs_url],
|
38
|
+
Whmcsor.config[:auth_user],
|
39
|
+
Whmcsor.config[:auth_pass] )
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Send request
|
44
|
+
#
|
45
|
+
page = agent.post(Whmcsor.config[:whmcs_url], params)
|
46
|
+
res = JSON.parse(page.content)
|
47
|
+
if res['result'] == 'error'
|
48
|
+
puts "Error ocurred: #{res['message']}"
|
49
|
+
else
|
50
|
+
res
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Public - Check if WHMCS settings have been set
|
55
|
+
#
|
56
|
+
# Returns nil
|
57
|
+
def check_whmcs_details
|
58
|
+
begin
|
59
|
+
Whmcsor.config[:whmcs_user]
|
60
|
+
Whmcsor.config[:whmcs_pass]
|
61
|
+
rescue NoMethodError
|
62
|
+
raise ArgumentError, 'Missing WHMCS login details'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Public - Check config entries
|
67
|
+
#
|
68
|
+
# Returns nil
|
69
|
+
def check_config
|
70
|
+
if Whmcsor.config.empty?
|
71
|
+
fail ArgumentError, 'Whmcsor configuration must be provided'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Public - Pick random user agent
|
76
|
+
#
|
77
|
+
# Returns String
|
78
|
+
def select_user_agent
|
79
|
+
ua = ['Linux Firefox (3.6.1)', 'Linux Konqueror (3)', 'Linux Mozilla',
|
80
|
+
'Mac Firefox (3.6)', 'Mac Mozilla', 'Mac Safari (5)', 'Mac Safari 4',
|
81
|
+
'Windows IE 6', 'Windows IE 7', 'Windows IE 8', 'Windows IE 9',
|
82
|
+
'Windows Mozilla', 'iPhone (3.0)', 'iPad', 'Android (Motorola Xoom)']
|
83
|
+
|
84
|
+
case Whmcsor.config[:user_agent]
|
85
|
+
when nil
|
86
|
+
'Mac Safari'
|
87
|
+
when 'random'
|
88
|
+
ua.sample
|
89
|
+
else
|
90
|
+
Whmcsor.config[:user_agent]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
module Whmcsor
|
2
|
+
# Provides WHMCS client API integration
|
3
|
+
class Client < Base
|
4
|
+
|
5
|
+
# Public - Add client
|
6
|
+
#
|
7
|
+
# params - Hash parameters:
|
8
|
+
# :firstname
|
9
|
+
# :lastname
|
10
|
+
# :email
|
11
|
+
# :address1
|
12
|
+
# :city
|
13
|
+
# :state
|
14
|
+
# :postcode
|
15
|
+
# :country - two letter ISO country code
|
16
|
+
# :phonenumber
|
17
|
+
# :password2 - password for the new user account
|
18
|
+
#
|
19
|
+
# :companyname - optional
|
20
|
+
# :address2 - optional
|
21
|
+
# :currency - the ID of the currency to set the user to
|
22
|
+
# :clientip - Pass the client IP address
|
23
|
+
# :language - the language to assign to the client
|
24
|
+
# :groupid - used to assign the client to a client group
|
25
|
+
# :securityqid - the ID of the security question for the user
|
26
|
+
# :securityqans - the answer to the client security question
|
27
|
+
# :notes
|
28
|
+
# :cctype - Visa, Mastercard, etc...
|
29
|
+
# :cardnum
|
30
|
+
# :expdate - in the format MMYY
|
31
|
+
# :startdate
|
32
|
+
# :issuenumber
|
33
|
+
# :customfields - a base64 encoded serialized array of custom
|
34
|
+
# field values
|
35
|
+
# :noemail - pass as true to surpress the client signup welcome
|
36
|
+
# email sending
|
37
|
+
# :skipvalidation - set true to not validate or check required
|
38
|
+
# fields
|
39
|
+
#
|
40
|
+
# Example:
|
41
|
+
# params = { :firstname: 'John',
|
42
|
+
# :lastname 'Doe',
|
43
|
+
# :email 'john@doe.com',
|
44
|
+
# :address1 'Silent Hill 12',
|
45
|
+
# :city 'Silent Hill',
|
46
|
+
# :state 'Silent Hill',
|
47
|
+
# :postcode '12919',
|
48
|
+
# :country 'SH',
|
49
|
+
# :phonenumber '001224221221',
|
50
|
+
# :password2 'RANDOM-PW-HER'
|
51
|
+
# }
|
52
|
+
#
|
53
|
+
# client = Whmcsor::Client.new
|
54
|
+
# client.add_client(params)
|
55
|
+
# # => { 'result' => 'success', 'clientid' => '99' )
|
56
|
+
#
|
57
|
+
# Returns JSON value
|
58
|
+
def add_client( params = {} )
|
59
|
+
params.merge!(
|
60
|
+
action: 'addclient'
|
61
|
+
)
|
62
|
+
|
63
|
+
send_request(params)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Public - Get clients list
|
67
|
+
#
|
68
|
+
# params - Hash parameters:
|
69
|
+
# :limitstart - Record to start at (default = 0)
|
70
|
+
# :limitnum - Number of records to return (default = 25)
|
71
|
+
# :search - Can be passed to filter for clients with a name/email
|
72
|
+
# matching the term entered
|
73
|
+
#
|
74
|
+
# Returns JSON
|
75
|
+
def get_clients( params = {} )
|
76
|
+
params.merge!(
|
77
|
+
action: 'getclients'
|
78
|
+
)
|
79
|
+
|
80
|
+
send_request(params)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Public - Get Client details from WHMCS API
|
84
|
+
#
|
85
|
+
# params - Hash parameters:
|
86
|
+
# :clientid - the id number of the client
|
87
|
+
# :email - the email address of the client
|
88
|
+
#
|
89
|
+
# Example:
|
90
|
+
# client = Whmcsor::Client.new
|
91
|
+
# client.get_client_details( { clientid: 1 } )
|
92
|
+
# client.get_client_details( { email: 'john@doe.com' } )
|
93
|
+
#
|
94
|
+
#
|
95
|
+
# Returns Hash
|
96
|
+
def get_client_details(params = {})
|
97
|
+
params.merge!( action: 'getclientsdetails')
|
98
|
+
send_request(params)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Public - Delete client from the WHMCS installation
|
102
|
+
#
|
103
|
+
# params - Hash parameters
|
104
|
+
# :clientid - the id number of the client
|
105
|
+
#
|
106
|
+
# Example:
|
107
|
+
#
|
108
|
+
# client = Whmcsor::Client.new
|
109
|
+
# client.delete_client( { clientid: 1 })
|
110
|
+
# # => { 'result' => 'success', 'clientid' => 'id' }
|
111
|
+
#
|
112
|
+
# Returns Hash
|
113
|
+
def delete_client(params = {})
|
114
|
+
params.merge!( action: 'deleteclient' )
|
115
|
+
send_request(params)
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# Public - Close a client account, terminates all products and canceles all
|
120
|
+
# invoices.
|
121
|
+
#
|
122
|
+
# params - Hash parameters
|
123
|
+
# :clientid - the id number of the client
|
124
|
+
#
|
125
|
+
# Returns Hash
|
126
|
+
def close_client(params = {})
|
127
|
+
params.merge!( action: 'closeclient')
|
128
|
+
send_request(params)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Public - Get quotes
|
132
|
+
#
|
133
|
+
# params - Hash parameters
|
134
|
+
# :quoteid - specific quote to obtain
|
135
|
+
# :userid - obtain quotes for a specific user
|
136
|
+
# :datecreated - Format YYYYMMDD
|
137
|
+
# :lastmodified - Format YYYYMMDD
|
138
|
+
# :validuntil - Format YYYYMMDD
|
139
|
+
# :stage - Specific stage to retrieve quotes for
|
140
|
+
# :subject - to obtain quotes with a specific subject
|
141
|
+
# :limitstart - for pagination, specify an ID to start at
|
142
|
+
# :limitnum - to restrict the number of results returned
|
143
|
+
#
|
144
|
+
# Returns Hash
|
145
|
+
def get_quotes(params = {})
|
146
|
+
params.merge!( action: 'getquotes' )
|
147
|
+
send_request(params)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Public - Create a new contact under the clients account
|
151
|
+
#
|
152
|
+
# params - Hash paramters
|
153
|
+
# :clientid - the id number of the client
|
154
|
+
#
|
155
|
+
# Optional fields:
|
156
|
+
# firstname
|
157
|
+
# lastname
|
158
|
+
# companyname
|
159
|
+
# email - must be unique if creating a sub-account
|
160
|
+
# address1
|
161
|
+
# address2
|
162
|
+
# city
|
163
|
+
# state
|
164
|
+
# postcode
|
165
|
+
# country - two letter ISO country code
|
166
|
+
# phonenumber
|
167
|
+
# password2 - if creating a sub-account
|
168
|
+
# permissions - can specify sub-account permissions
|
169
|
+
# generalemails - set true to receive general email types
|
170
|
+
# productemails - set true to receive product related emails
|
171
|
+
# domainemails - set true to receive domain related emails
|
172
|
+
# invoiceemails - set true to receive billing related emails
|
173
|
+
# supportemails - set true to receive support ticket related emails
|
174
|
+
# Returns Hash
|
175
|
+
def add_contact(params = {} )
|
176
|
+
params.merge!(action: 'addcontact')
|
177
|
+
send_requst(params)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Public - Delete the contact inside the system
|
181
|
+
#
|
182
|
+
# params - Hash parameters
|
183
|
+
# :contactid - the id number of the client
|
184
|
+
#
|
185
|
+
# Returns Hash
|
186
|
+
def delete_contact(params = {})
|
187
|
+
params.merge!(action: 'deletecontact')
|
188
|
+
send_request(params)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Whmcsor
|
2
|
+
# Configuration class for Whmcsor
|
3
|
+
class Config
|
4
|
+
|
5
|
+
# Public: A Hash that stores configuration info.
|
6
|
+
attr_accessor :config
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@config = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
# Public: Hash accessor, delegates to `@config`.
|
13
|
+
#
|
14
|
+
# Returns the value from `@config`
|
15
|
+
def [](v)
|
16
|
+
@config[v]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Sets the IP address of your proxy server.
|
20
|
+
#
|
21
|
+
# value - String URL
|
22
|
+
#
|
23
|
+
# Returns value
|
24
|
+
def proxy_ip(value)
|
25
|
+
@config[:proxy_ip] = value
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Sets the port of your proxy server.
|
29
|
+
#
|
30
|
+
# port - String port
|
31
|
+
#
|
32
|
+
# Returns value
|
33
|
+
def proxy_port(port)
|
34
|
+
@config[:proxy_port] = port
|
35
|
+
end
|
36
|
+
|
37
|
+
# Public: Sets the WHMCS API URL
|
38
|
+
#
|
39
|
+
# value - The String URL
|
40
|
+
#
|
41
|
+
# Returns value.
|
42
|
+
def whmcs_url(value)
|
43
|
+
@config[:whmcs_url] = value
|
44
|
+
end
|
45
|
+
|
46
|
+
# Public: Sets the WHMCS API username
|
47
|
+
#
|
48
|
+
# value - The String username
|
49
|
+
#
|
50
|
+
# Returns value
|
51
|
+
def whmcs_user(value)
|
52
|
+
@config[:whmcs_user] = value
|
53
|
+
end
|
54
|
+
|
55
|
+
# Public: Sets the WHMCS API password
|
56
|
+
#
|
57
|
+
# value - The String password
|
58
|
+
#
|
59
|
+
# Returns value
|
60
|
+
def whmcs_pass(value)
|
61
|
+
@config[:whmcs_pass] = value
|
62
|
+
end
|
63
|
+
|
64
|
+
# Public: Sets the WHMCS API Key for access from undefined IP addresses.
|
65
|
+
# More information on the subject: http://docs.whmcs.com/API:Access_Keys
|
66
|
+
#
|
67
|
+
# value - The String API key
|
68
|
+
#
|
69
|
+
# Returns value
|
70
|
+
def whmcs_api_key(value)
|
71
|
+
@config[:whmcs_api_key] = value
|
72
|
+
end
|
73
|
+
|
74
|
+
# Public: Sets the HTTP Auth information, if the WHMCS API page is password
|
75
|
+
# protected
|
76
|
+
#
|
77
|
+
# value - String HTTP Auth username
|
78
|
+
#
|
79
|
+
# Returns value
|
80
|
+
def auth_user(value)
|
81
|
+
@config[:auth_user] = value
|
82
|
+
end
|
83
|
+
|
84
|
+
# Public: Sets the HTTP Auth password for the WHMCS API access
|
85
|
+
#
|
86
|
+
# value - String HTTP Auth password
|
87
|
+
#
|
88
|
+
# Returns value
|
89
|
+
def auth_pass(value)
|
90
|
+
@config[:auth_pass] = value
|
91
|
+
end
|
92
|
+
|
93
|
+
# Public: Sets the User Agent shortcut used by Mechanize
|
94
|
+
#
|
95
|
+
# value - String User Agent
|
96
|
+
#
|
97
|
+
# Returns value
|
98
|
+
def user_agent(value)
|
99
|
+
@config[:user_agent] = value
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module Whmcsor
|
2
|
+
# WHMCS API Orders class
|
3
|
+
class Orders < Base
|
4
|
+
|
5
|
+
# Public - Add new order trough WHMCS API
|
6
|
+
#
|
7
|
+
# params - Hash parameters
|
8
|
+
#
|
9
|
+
# Returns Hash
|
10
|
+
def add_order(params = {})
|
11
|
+
params.merge!(action: 'addorder')
|
12
|
+
send_request(params)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public - Retrieve the lilst of orders from WHMCS API
|
16
|
+
#
|
17
|
+
# params - Hash parameters
|
18
|
+
#
|
19
|
+
# Return Hash
|
20
|
+
def get_orders(params = {})
|
21
|
+
params.merge!(action: 'getorders')
|
22
|
+
send_request(params)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Public - Get order statuses and their count
|
26
|
+
#
|
27
|
+
# params - hash parameters
|
28
|
+
#
|
29
|
+
# Returns Hash
|
30
|
+
def get_order_statuses(params = {})
|
31
|
+
params.merge!(action: 'getorderstatuses')
|
32
|
+
send_request(params)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Public - Retrieve product details
|
36
|
+
#
|
37
|
+
# params - Hash parameters
|
38
|
+
# :pid - Product ID
|
39
|
+
# :gid - Product Group ID
|
40
|
+
# :module - retrieve products assigned to a sepcific module
|
41
|
+
#
|
42
|
+
# Returns Hash
|
43
|
+
def get_products(params = {})
|
44
|
+
params.merge!(action: 'getproducts')
|
45
|
+
send_request(params)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Public - Accept a pendingo order inside the system
|
49
|
+
#
|
50
|
+
# params - hash parameters
|
51
|
+
# :orderid - Order ID which will be accepted
|
52
|
+
#
|
53
|
+
# Optional parameters:
|
54
|
+
# :serverid - the Server ID to provision any hosting products in the
|
55
|
+
# order to, overrides default
|
56
|
+
# :serviceusername - the Username to assign for provisioning,
|
57
|
+
# overrides default
|
58
|
+
# :servicepassword - the Password to assign for products being
|
59
|
+
# provisioned, overrides auto generation
|
60
|
+
# :registrar - the domain registrar module to assign any domains to
|
61
|
+
# :autosetup - true/false - determines whether product provisioning
|
62
|
+
# is performed
|
63
|
+
# :sendregistrar - true/false determines whether domain automation
|
64
|
+
# is performed
|
65
|
+
# :sendemail - true/false - sets if welcome emails for products and
|
66
|
+
# registration confirmation emails for domains should be sent
|
67
|
+
#
|
68
|
+
# Returns Hash
|
69
|
+
def accept_order(params = {})
|
70
|
+
params.merge!(action: 'acceptorder')
|
71
|
+
send_request(params)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Public - Change order status to pending
|
75
|
+
#
|
76
|
+
# params - Hash parameters
|
77
|
+
# :orderid
|
78
|
+
#
|
79
|
+
# Returns Hash
|
80
|
+
def pending_order(params = {})
|
81
|
+
params.merge!(action: 'pendingorder')
|
82
|
+
send_request(params)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Public - Cancel a pendingo order inside the WHMCS system
|
86
|
+
#
|
87
|
+
# params - Hash parameters
|
88
|
+
# :orderid - ID of the order :)
|
89
|
+
#
|
90
|
+
# Returns Hash
|
91
|
+
def cancel_order(params = {})
|
92
|
+
params.merge!(action: 'cancelorder')
|
93
|
+
send_request(params)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Public - Set order as Fraud in the system
|
97
|
+
#
|
98
|
+
# params - Hash parameters
|
99
|
+
# :orderid - ID of the order inside WHMCS
|
100
|
+
#
|
101
|
+
# Returns Hash
|
102
|
+
def fraud_order(params = {})
|
103
|
+
params.merge!(action: 'fraudorder')
|
104
|
+
send_request(params)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Public - Delete order from WHMCS
|
108
|
+
#
|
109
|
+
# params - Hash parameters
|
110
|
+
# :orderid - ID of the order
|
111
|
+
#
|
112
|
+
# Returns Hash
|
113
|
+
def delete_order(params = {})
|
114
|
+
params.merge!(action: 'deleteorder')
|
115
|
+
send_request(params)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
module Whmcsor
|
2
|
+
class Payment < Base
|
3
|
+
|
4
|
+
# Public - Retrieve invoices for a specific client or in specific status
|
5
|
+
#
|
6
|
+
# params - Hash parameters
|
7
|
+
#
|
8
|
+
# :userid - ID of the client/user
|
9
|
+
# :status - Paid, Unpaid, Cancelled, Overdue
|
10
|
+
# :limitstart - offset number to start when returning results
|
11
|
+
# (default: 0)
|
12
|
+
# :limitnum - number of records to return (default: 25)
|
13
|
+
#
|
14
|
+
# Returns Hash
|
15
|
+
def get_invoices(params = {})
|
16
|
+
params.merge!( action: 'getinvoices')
|
17
|
+
send_request(params)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public - Obtain invoice for a client
|
21
|
+
#
|
22
|
+
# params - Hash parameters
|
23
|
+
# :invoiceid - ID of the invoice
|
24
|
+
#
|
25
|
+
# Returns Hash
|
26
|
+
def get_invoice(params = {})
|
27
|
+
params.merge!(action: 'getinvoice')
|
28
|
+
send_request(params)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Public - Create a new invoice for client
|
32
|
+
#
|
33
|
+
# params - Hash parameters
|
34
|
+
# :userid - should contain the user ID of the client
|
35
|
+
# :date - The date the invoice is created in the format YYYYMMDD
|
36
|
+
# :duedate - The date that the invoice is due in the format YYYYMMDD
|
37
|
+
# :paymentmethod - The payment method for the invoice
|
38
|
+
# :ithemdescription1 - item1 description
|
39
|
+
# :itemamount1 - item 1 amount
|
40
|
+
# :itemtaxed1 - if set to true the item will be taxed
|
41
|
+
#
|
42
|
+
# Optional arguments:
|
43
|
+
# :taxrate - the rate of the tax that should be charged
|
44
|
+
# :taxrate2 - the 2nd tax rate that should be charged
|
45
|
+
# :notes - any additional notes the invoice should contain
|
46
|
+
# :sendinvoice - set to true to send the "Invoice Created" email to
|
47
|
+
# the customer
|
48
|
+
# :autoapplycredit - pass as true to auto apply any credit from the
|
49
|
+
# clients credit balance
|
50
|
+
# :itemdescription2 - item 2 description
|
51
|
+
# :itemamount2 - item 2 amount
|
52
|
+
# :itemtaxed2 - set to true if the 2nd item should be taxed.
|
53
|
+
#
|
54
|
+
# Returns Hash
|
55
|
+
def create_invoice(params = {})
|
56
|
+
params.merge!(action: 'createinvoice')
|
57
|
+
send_request(params)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Public - Update the invoice inside the WHMCS system
|
61
|
+
#
|
62
|
+
# params - Hash parameters
|
63
|
+
# :invoiceid - ID of the invoice that needs to be updated
|
64
|
+
#
|
65
|
+
# Optional arguments:
|
66
|
+
# :itemdescription - Array of existing line item descriptions to
|
67
|
+
# update. Line ID from database needed. itemamount and itemtaxed
|
68
|
+
# should be passed when updating the description.
|
69
|
+
# :itemamount - Array of existing line item amounts to update
|
70
|
+
# :itemtaxed - Array of existing line items taxed or not
|
71
|
+
# :newitemdescription - Array of new line item descriptipons to add
|
72
|
+
# :newitemamount - Array of new line item amounts
|
73
|
+
# :newitemtaxed - Array of new line items taxed or not
|
74
|
+
# :date - date of invoice format yyyymmdd
|
75
|
+
# :duedate - duedate of invoice in format YYYYMMDD
|
76
|
+
# :datepaid - date invoice was paid format YYYYMMDD
|
77
|
+
# :status - Status of the invoice - Unpaid, Paid, Cancelled,
|
78
|
+
# Collection, Refunded
|
79
|
+
# :paymentmethod - payment method of invoice eg paypal, banktransfer
|
80
|
+
# :notes - Invoice notes
|
81
|
+
# :deletelineids - an array of line IDs for the current invoice to
|
82
|
+
# remove (tblinvoiceitems.id)
|
83
|
+
#
|
84
|
+
# Returns Hash
|
85
|
+
def update_invoice(params = {})
|
86
|
+
params.merge!(action: 'updateinvoice')
|
87
|
+
send_request(params)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Public - This API call is used to add payment to the invoice
|
91
|
+
#
|
92
|
+
# params - Hash parameters
|
93
|
+
# :invoiceid - ID of the invoice
|
94
|
+
# :transid - transaction number for the payment
|
95
|
+
# :gateway - gateway used in system name format, eg. paypal,
|
96
|
+
# authorize, etc...
|
97
|
+
#
|
98
|
+
# Optional arguments:
|
99
|
+
# :amount - should contact the amount paid, can be left blank to
|
100
|
+
# take full amount of invoice
|
101
|
+
# :fees - if set defines how much fees were involved in the
|
102
|
+
# transaction
|
103
|
+
# :noemail - set to true to not send an email for the invoice
|
104
|
+
# payment
|
105
|
+
# :date - if set defines the date the payment was made Format:
|
106
|
+
# YYYY-MM-DD HH:mm:ss
|
107
|
+
#
|
108
|
+
# Returns Hash
|
109
|
+
def add_invoice_payment(params = {})
|
110
|
+
params.merge!(action: 'addinvoicepayment')
|
111
|
+
send_request(params)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Public - Attempt to capture payment when an invoice is set to a merchant
|
115
|
+
# gateway module .
|
116
|
+
#
|
117
|
+
# params - Hash parameters
|
118
|
+
# :invoiceid - the ID of the invoice the capture is to be attempted
|
119
|
+
# for
|
120
|
+
#
|
121
|
+
# Optional arguments:
|
122
|
+
# :cvv - an be used to pass the cards verification value in the
|
123
|
+
# payment request
|
124
|
+
#
|
125
|
+
# Returns Hash
|
126
|
+
def capture_payment(params = {})
|
127
|
+
params.merge!(action: 'capturepayment')
|
128
|
+
send_request(params)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Public - Apply credit from clients credit balance to an invoice inside
|
132
|
+
# WHMCS
|
133
|
+
#
|
134
|
+
# params - Hash parameters
|
135
|
+
# :invoiceid - the ID of the invoice to apply credit to
|
136
|
+
# :amount - the amount of credit to apply (must be less than or
|
137
|
+
# equal to clients available credit balance)
|
138
|
+
#
|
139
|
+
# Returns Hash
|
140
|
+
def apply_credit(params = {})
|
141
|
+
params.merge!(action: 'applycredit')
|
142
|
+
send_request(params)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Public - Add new bilable item to the system
|
146
|
+
#
|
147
|
+
# params - Hash parameters
|
148
|
+
# :clientid - Used ID to apply the change to
|
149
|
+
# :description - Description shown to client when invoiced
|
150
|
+
# :hours - number of hours/quantity (not required for single
|
151
|
+
# quantity)
|
152
|
+
# :amount - Total amount to invoice for
|
153
|
+
# :invoiceaction - noinvoice, nextcron, nextinvoice, duedate, recur
|
154
|
+
#
|
155
|
+
# Optional arguments:
|
156
|
+
# :duedate - date the invoice should be due (only required for
|
157
|
+
# duedate & recur invoice actions)
|
158
|
+
# :recur - frequency to recur - 1,2,3,etc...
|
159
|
+
# :recurcycle - Days, Weeks, Months or Years
|
160
|
+
# :recurfor - number of times to repeat
|
161
|
+
#
|
162
|
+
# Returns Hash
|
163
|
+
def add_billable_item(params = {})
|
164
|
+
params.merge!(action: 'addbillableitem')
|
165
|
+
send_request(params)
|
166
|
+
end
|
167
|
+
|
168
|
+
# Public - Add credit to the client
|
169
|
+
#
|
170
|
+
# params - Hash parameters
|
171
|
+
# :clientid - D of the client the credit is to be added to
|
172
|
+
# :description - reason for credit being added (stored in admin
|
173
|
+
# credit log)
|
174
|
+
# :amount - the amount to be added
|
175
|
+
#
|
176
|
+
# Returns Hash
|
177
|
+
def add_credit(params = {})
|
178
|
+
params.merge!(action: 'addcredit')
|
179
|
+
send_request(params)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Public - Add transaction
|
183
|
+
#
|
184
|
+
# params - Hash parameters
|
185
|
+
# :amountin - amount to add to the account
|
186
|
+
# :amountout - if an outgoing enter this
|
187
|
+
# :paymentmethod - gateway used in WHMCS
|
188
|
+
# :date - date of transaction (same format as your WHMCS eg
|
189
|
+
# DD/MM/YYYY)
|
190
|
+
#
|
191
|
+
# Optional arguments:
|
192
|
+
# :userid - Add Transaction to a user
|
193
|
+
# :invoiceid - Add transaction to a particular invoice
|
194
|
+
# :description - Description of the transaction
|
195
|
+
# :fees - transaction fee you were charged
|
196
|
+
# :transid - Transaction ID you wish to assign
|
197
|
+
# :credit - set to true to add the transaction as credit to the
|
198
|
+
# client
|
199
|
+
#
|
200
|
+
# Return Hash
|
201
|
+
def add_transaction(params = {})
|
202
|
+
params.merge!(action: 'addtransaction')
|
203
|
+
send_request(params)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Public - Update transaction
|
207
|
+
#
|
208
|
+
# params - Hash parameters
|
209
|
+
# :transcationid - he Transaction ID to update. tblaccounts.id. This
|
210
|
+
# is not the transid from the gateway
|
211
|
+
#
|
212
|
+
# Optional arguments:
|
213
|
+
# :userid - Add Transaction to a user
|
214
|
+
# :currency - Currency ID for a transaction
|
215
|
+
# :gateway - Gateway to assign transaction to
|
216
|
+
# :date - date of transaction YYYYMMDD
|
217
|
+
# :description - Description of the transaction
|
218
|
+
# :amountin - amountto add to the account
|
219
|
+
# :fees - transaction fee you were charged
|
220
|
+
# :rate - exchange rate based on master currency
|
221
|
+
# :transid - Transcation ID you wish to assign
|
222
|
+
# :invoiceid - Add transcation to the particular invoice
|
223
|
+
# :refundid - Add a refund ID if this is a refund transaction
|
224
|
+
#
|
225
|
+
# Returns Hash
|
226
|
+
def update_transaction(params = {})
|
227
|
+
params.merge!(action: 'updatetransaction')
|
228
|
+
send_request(params)
|
229
|
+
end
|
230
|
+
|
231
|
+
# Public - Get a list of payment methods available
|
232
|
+
#
|
233
|
+
# Returns Hash
|
234
|
+
def get_payment_methods
|
235
|
+
params = { action: 'getpaymentmethods'}
|
236
|
+
send_request(params)
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
end
|
data/lib/whmcsor.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'crack'
|
5
|
+
require 'digest'
|
6
|
+
|
7
|
+
require "whmcsor/version"
|
8
|
+
|
9
|
+
module Whmcsor
|
10
|
+
autoload :Config, 'whmcsor/config'
|
11
|
+
autoload :Base, 'whmcsor/base'
|
12
|
+
autoload :Client, 'whmcsor/client'
|
13
|
+
autoload :Orders, 'whmcsor/orders'
|
14
|
+
autoload :Payment, 'whmcsor/payment'
|
15
|
+
|
16
|
+
extend self
|
17
|
+
|
18
|
+
# Config
|
19
|
+
attr_accessor :configuration
|
20
|
+
|
21
|
+
# Config
|
22
|
+
attr_accessor :configuration_file
|
23
|
+
|
24
|
+
self.configuration ||= Whmcsor::Config.new
|
25
|
+
|
26
|
+
# Public - Configures Whmcsor
|
27
|
+
#
|
28
|
+
# Example
|
29
|
+
#
|
30
|
+
# Whmcsor.config do |c|
|
31
|
+
# c.proxy_ip '127.0.0.1'
|
32
|
+
# c.proxy_port '8118
|
33
|
+
# c.whmcs_url 'http://whmcs.url.com/api.php'
|
34
|
+
# c.whmcs_user 'username'
|
35
|
+
# c.whmcs_pass 'password
|
36
|
+
# c.whmcs_api_key 'xxxxx'
|
37
|
+
# end
|
38
|
+
# Returns Hash
|
39
|
+
def config
|
40
|
+
yield self.configuration if block_given?
|
41
|
+
self.configuration.config
|
42
|
+
end
|
43
|
+
|
44
|
+
# Public - Load the configuration out of a YAML file
|
45
|
+
#
|
46
|
+
# file - Path to the YAML file, default '~/.whmcsor.yaml'
|
47
|
+
#
|
48
|
+
# Raises ArgumentError if the config file does not exist
|
49
|
+
#
|
50
|
+
# Example
|
51
|
+
#
|
52
|
+
# # Load default configuration file from '~/.whmcsor.yaml'
|
53
|
+
# Whmcsor.config_file
|
54
|
+
#
|
55
|
+
# # Load custom configuration file
|
56
|
+
# Whmcsor.config_file '/path/to/.whmcsor.yaml'
|
57
|
+
#
|
58
|
+
# Returns nothing
|
59
|
+
def config_file( file = File.expand_path('~/.whmcsor.yaml'))
|
60
|
+
if File.exists?(file)
|
61
|
+
self.configuration_file = file
|
62
|
+
else
|
63
|
+
raise ArgumentError, "Configuration file doesn't exist '#{file}'"
|
64
|
+
end
|
65
|
+
|
66
|
+
config do |c|
|
67
|
+
YAML::load_file(file).each { |k, v| c.send(k, v) }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/whmcsor.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'whmcsor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "whmcsor"
|
8
|
+
spec.version = Whmcsor::VERSION
|
9
|
+
spec.authors = ["v0x.Osho"]
|
10
|
+
spec.email = ["osho@v0x.pw"]
|
11
|
+
spec.description = %q{WHMCS API gem}
|
12
|
+
spec.summary = %q{Connect to WHMCS API}
|
13
|
+
spec.homepage = "http://dev.v0x.pw/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency 'mechanize'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whmcsor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- v0x.Osho
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mechanize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: WHMCS API gem
|
56
|
+
email:
|
57
|
+
- osho@v0x.pw
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/whmcsor.rb
|
68
|
+
- lib/whmcsor/base.rb
|
69
|
+
- lib/whmcsor/client.rb
|
70
|
+
- lib/whmcsor/config.rb
|
71
|
+
- lib/whmcsor/orders.rb
|
72
|
+
- lib/whmcsor/payment.rb
|
73
|
+
- lib/whmcsor/version.rb
|
74
|
+
- whmcsor.gemspec
|
75
|
+
homepage: http://dev.v0x.pw/
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.14
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Connect to WHMCS API
|
99
|
+
test_files: []
|