whmcs-api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ module WHMCS
2
+ # WHMCS::Config stores configuration data for connecting to the WHMCS API
3
+ class Config
4
+ # The WHMCS API username
5
+ attr_accessor :api_username
6
+
7
+ # The WHMCS API password
8
+ attr_accessor :api_password
9
+
10
+ # The WHMCS API URL
11
+ attr_accessor :api_url
12
+
13
+ # The WHMCS API Access Key
14
+ attr_accessor :api_key
15
+
16
+ # Create a new config object
17
+ def initialize
18
+ @api_username = 'Admin'
19
+ @api_password = 'demo-in-md5'
20
+ @api_url = 'http://demo.whmcs.com/includes/api.php'
21
+ @api_key = 'whmcsdemo'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,214 @@
1
+ module WHMCS
2
+ # WHMCS:Domain class for domains management
3
+ class Domain < Base
4
+
5
+ # Register Domain
6
+ # This command is used to send a Register command to the registrar
7
+ #
8
+ # Parameters:
9
+ # * <tt>:domainid</tt> - Domain ID from WHMCS
10
+ # * <tt>:domain</tt> - The domain name (send domain id *or* domain)
11
+ #
12
+ # See:
13
+ #
14
+ # http://docs.whmcs.com/API:Register_Domain
15
+ def self.register(params = {})
16
+ params.merge!(:action => 'domainregister')
17
+ send_request(params)
18
+ end
19
+
20
+ # Release Domain
21
+ # This command is used to send a Release command to the registrar
22
+ #
23
+ # Parameters:
24
+ # * <tt>:domainid</tt> - Domain ID from WHMCS
25
+ # * <tt>:domain</tt> - The domain name (send domain id *or* domain)
26
+ # * <tt>:newtag</tt> - The new tag for the domain [Tag List](http://www.nominet.org.uk/registrars/becomeregistrar/taglist/)
27
+ #
28
+ # See:
29
+ #
30
+ # http://docs.whmcs.com/API:Release_Domain
31
+ def self.release(params = {})
32
+ params.merge!(:action => 'domainrelease')
33
+ send_request(params)
34
+ end
35
+
36
+
37
+ # Renew Domain
38
+ # This command is used to send a Renew command to the registrar
39
+ #
40
+ # Parameters:
41
+ # * <tt>:domainid</tt> - Domain ID from WHMCS
42
+ # * <tt>:domain</tt> - The domain name (send domain id *or* domain)
43
+ #
44
+ # See:
45
+ #
46
+ # http://docs.whmcs.com/API:Renew_Domain
47
+ def self.renew(params = {})
48
+ params.merge!(:action => 'domainrenew')
49
+ send_request(params)
50
+ end
51
+
52
+ # Transfer Domain
53
+ # This command is used to send a Transfer command to the registrar
54
+ #
55
+ # Parameters:
56
+ # * <tt>:domainid</tt> - Domain ID from WHMCS
57
+ # * <tt>:domain</tt> - The domain name (send domain id *or* domain)
58
+ #
59
+ # Optional attributes:
60
+ #
61
+ # * <tt>:eppcode</tt> - The EPP code for the transfer
62
+ #
63
+ # See:
64
+ #
65
+ # http://docs.whmcs.com/API:Transfer_Domain
66
+ def self.transfer(params = {})
67
+ params.merge!(:action => 'domaintransfer')
68
+ send_request(params)
69
+ end
70
+
71
+
72
+ # Get Domain WHOIS
73
+ # This command is used to obtain the WHOIS of a domain from the registrar
74
+ #
75
+ # Parameters:
76
+ # * <tt>:domainid</tt> - ID of the domain in WHMCS
77
+ #
78
+ # See:
79
+ #
80
+ # http://docs.whmcs.com/API:Get_Domain_WHOIS
81
+ def self.get_domain_whois(params = {})
82
+ params.merge!(:action => 'domaingetwhoisinfo')
83
+ send_request(params)
84
+ end
85
+
86
+ # Domain Locking Status
87
+ # This command is used to obtain the lock state of a domain
88
+ #
89
+ # Parameters:
90
+ # * <tt>:domainid</tt> - ID of the domain in your WHMCS
91
+ #
92
+ # See:
93
+ #
94
+ # http://docs.whmcs.com/API:Domain_Locking_Status
95
+ def self.get_lockstatus(params = {})
96
+ params.merge!(:action => 'domaingetlockingstatus')
97
+ send_request(params)
98
+ end
99
+
100
+ # Domain EPP
101
+ # This command is used to obtain the EPP Code of a domain
102
+ #
103
+ # Parameters:
104
+ # * <tt>:domainid</tt> - ID of the domain in WHMCS
105
+ #
106
+ # See:
107
+ #
108
+ # http://docs.whmcs.com/API:Domain_EPP
109
+ def self.request_epp(params = {})
110
+ params.merge!(:action => 'domainrequestepp')
111
+ send_request(params)
112
+ end
113
+
114
+
115
+ # Domain WHOIS
116
+ # This command is used to perform a whois lookup on a specified domain.
117
+ #
118
+ # Parameters:
119
+ # * <tt>:domain</tt> - the domain to check
120
+ #
121
+ # See:
122
+ #
123
+ # http://docs.whmcs.com/API:Domain_WHOIS
124
+ def self.whois(params = {})
125
+ params.merge!(:action => 'domainwhois')
126
+ send_request(params)
127
+ end
128
+
129
+
130
+ # Toggle ID Protect
131
+ # This command is used to toggle the ID Protection status of a domain assigned to certain registrars. For example all LogicBoxes modules.
132
+ #
133
+ # Parameters:
134
+ # * <tt>:domainid</tt> - ID of the domain in WHMCS
135
+ # * <tt>:dprotect</tt> - true/false
136
+ #
137
+ # See:
138
+ #
139
+ # http://docs.whmcs.com/API:Toggle_ID_Protect
140
+ def self.toggle_idprotect(params = {})
141
+ params.merge!(:action => 'domaintoggleidprotect')
142
+ send_request(params)
143
+ end
144
+
145
+ # Domain Nameservers
146
+ #
147
+ # This command is used to obtain the nameservers of a domain
148
+ #
149
+ # Parameters:
150
+ # * <tt>:domainid</tt> - ID of the domain in WHMCS
151
+ #
152
+ # See:
153
+ #
154
+ # http://docs.whmcs.com/API:Domain_Nameservers
155
+ def self.get_nameservers(params = {})
156
+ params.merge!(:action => 'domaingetnameservers')
157
+ send_request(params)
158
+ end
159
+
160
+ # Domain Update Nameservers
161
+ # This command is used to update the nameservers of a domain
162
+ #
163
+ # Parameters:
164
+ # * <tt>:domainid</tt> - ID of the domain in WHMCS
165
+ # * <tt>:domain</tt> - domainname to update (use domainid OR domain)
166
+ # * <tt>:ns1</tt> - nameserver1
167
+ # * <tt>:ns2</tt> - nameserver2
168
+ #
169
+ # Optional attributes:
170
+ # * <tt>:ns3</tt> - nameserver3
171
+ # * <tt>:ns4</tt> - nameserver4
172
+ # * <tt>:ns5</tt> - nameserver5
173
+ #
174
+ # See:
175
+ #
176
+ # http://docs.whmcs.com/API:Domain_Update_Nameservers
177
+ def self.update_nameservers(params = {})
178
+ params.merge!(:action => 'domainupdatenameservers')
179
+ send_request(params)
180
+ end
181
+
182
+ # Domain Update Lock
183
+ # This command is used to update the lock state of a domain
184
+ #
185
+ # Parameters:
186
+ # * <tt>:domainid</tt> - ID of the domain in WHMCS
187
+ #
188
+ # Optional attributes:
189
+ # * <tt>:lockstatus</tt> - set to 1 to lock the domain
190
+ #
191
+ # See:
192
+ #
193
+ # http://docs.whmcs.com/API:Domain_Update_Lock
194
+ def self.update_lockstatus(params = {})
195
+ params.merge!(:action => 'domainupdatelockingstatus')
196
+ send_request(params)
197
+ end
198
+
199
+ # Domain Update WHOIS
200
+ # This command is used to update the contact information on a domain
201
+ #
202
+ # Parameters:
203
+ # * <tt>:domainid</tt> - ID of the domain in WHMCS
204
+ # * <tt>:xml</tt> - xml of the details to update [Get WHOIS](http://docs.whmcs.com/API:Get_Domain_WHOIS)
205
+ #
206
+ # See:
207
+ #
208
+ # http://docs.whmcs.com/API:Domain_Update_WHOIS
209
+ def self.update_domain_whois(params = {})
210
+ params.merge!(:action => 'domainupdatewhoisinfo')
211
+ send_request(params)
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,253 @@
1
+ module WHMCS
2
+ # WHMCS::Invoice is the class for managing invoices
3
+ class Invoice < Base
4
+
5
+ # Get invoices
6
+ #
7
+ # Optional attributes:
8
+ #
9
+ # * <tt>:userid</tt> - the client ID to retrieve invoices for
10
+ # * <tt>:status</tt> - the status to filter for, Paid, Unpaid, Cancelled, etc...
11
+ # * <tt>:limitstart</tt> - the offset number to start at when returning matches (optional, default 0)
12
+ # * <tt>:limitnum</tt> - the number of records to return (optional, default 25)
13
+ #
14
+ # See:
15
+ #
16
+ # http://docs.whmcs.com/API:Get_Invoices
17
+ def self.get_invoices(params = {})
18
+ params.merge!(:action => 'getinvoices')
19
+ send_request(params)
20
+ end
21
+
22
+ # Get an invoice
23
+ #
24
+ # Parameters:
25
+ #
26
+ # * <tt>:invoiceid</tt> - should be the invoice id you wish to retrieve
27
+ #
28
+ # See:
29
+ #
30
+ # http://docs.whmcs.com/API:Get_Invoice
31
+ def self.get_invoice(params = {})
32
+ params.merge!(:action => 'getinvoice')
33
+ send_request(params)
34
+ end
35
+
36
+ # Create a new invoice
37
+ #
38
+ # Parameters:
39
+ #
40
+ # * <tt>:userid</tt> - should contain the user id of the client you wish to create the invoice for
41
+ # * <tt>:date</tt> - the date the invoice is created in the format YYYYMMDD
42
+ # * <tt>:duedate</tt> - the date the invoice is due in the format YYYYMMDD
43
+ # * <tt>:paymentmethod</tt> - the payment method for the invoice eg. banktransfer
44
+ # * <tt>:itemdescription1</tt> - item 1 description
45
+ # * <tt>:itemtaxed1</tt> - set to true if item 1 should be taxed
46
+ # * <tt>:itemamount1</tt> - item 1 amount
47
+ #
48
+ # * <tt>:taxrate</tt> - the rate of tax that should be charged
49
+ # * <tt>:taxrate2</tt> - the 2nd rate of tax that should be charged
50
+ # * <tt>:autoapplycredit</tt> - pass as true to auto apply any available credit from the clients credit balance
51
+ # * <tt>:itemamount2</tt> - item 2 amount
52
+ # * <tt>:itemtaxed2</tt> - set to true if item 2 should be taxed
53
+ # * <tt>:notes</tt> - any additional notes the invoice should display to the customer
54
+ # * <tt>:sendinvoice</tt> - set to true to send the "Invoice Created" email to the customer
55
+ # * <tt>:itemdescription2</tt> - item 2 description
56
+ #
57
+ # etc...
58
+ #
59
+ # See:
60
+ #
61
+ # http://docs.whmcs.com/API:Create_Invoice
62
+ def self.create_invoice(params = {})
63
+ params.merge!(:action => 'createinvoice')
64
+ send_request(params)
65
+ end
66
+
67
+ # Update an existing invoice
68
+ #
69
+ # Parameters:
70
+ #
71
+ # * <tt>:invoiceid</tt> - The ID of the invoice to update
72
+ #
73
+ # Optional attributes:
74
+ # * <tt>:itemdescription</tt> - Array of existing line item descriptions to update. Line ID from database needed
75
+ # * <tt>:itemamount</tt> - Array of existing line item amounts to update
76
+ # * <tt>:itemtaxed</tt> - Array of existing line items taxed or not
77
+ # * <tt>:newitemdescription</tt> - Array of new line item descriptipons to add
78
+ # * <tt>:newitemamount</tt> - Array of new line item amounts
79
+ # * <tt>:newitemtaxed</tt> - Array of new line items taxed or not
80
+ # * <tt>:date</tt> - date of invoice format yyyymmdd
81
+ # * <tt>:duedate</tt> - duedate of invoice format yyyymmdd
82
+ # * <tt>:datepaid</tt> - date invoice was paid format yyyymmdd
83
+ # * <tt>:status</tt> - status of invoice. Unpaid, Paid, Cancelled, Collection, Refunded
84
+ # * <tt>:paymentmethod</tt> - payment method of invoice eg paypal, banktransfer
85
+ # * <tt>:notes</tt> - invoice notes
86
+ # * <tt>:deletelineids</tt> - an array of line IDs for the current invoice to remove (tblinvoiceitems.id)
87
+ #
88
+ # Other than invoiceid, no other fields are required
89
+ #
90
+ # See:
91
+ #
92
+ # http://docs.whmcs.com/API:Update_Invoice
93
+ def self.update_invoice(params = {})
94
+ params.merge!(:action => 'updateinvoice')
95
+ send_request(params)
96
+ end
97
+
98
+ # Add an invoice payment
99
+ #
100
+ # Parameters:
101
+ #
102
+ # * <tt>:invoiceid</tt> - should contact the ID number of the invoice to add the payment to
103
+ # * <tt>:transid</tt> - should contain the transaction number for the payment
104
+ # * <tt>:gateway</tt> - should contain the gateway used in system name format, eg. paypal, authorize, etc...
105
+ #
106
+ # Optional attributes:
107
+ # * <tt>:amount</tt> - should contact the amount paid, can be left blank to take full amount of invoice
108
+ # * <tt>:fees</tt> - optional, if set defines how much fees were involved in the transaction
109
+ # * <tt>:noemail</tt> - set to true to not send an email if the payment marks the invoice paid
110
+ # * <tt>:date</tt> - optional, if set defines the date the payment was made
111
+ #
112
+ # See:
113
+ #
114
+ # http://docs.whmcs.com/API:Add_Invoice_Payment
115
+ def self.add_invoice_payment(params = {})
116
+ params.merge!(:action => 'addinvoicepayment')
117
+ send_request(params)
118
+ end
119
+
120
+ # Attempt to capture payment for an invoice
121
+ #
122
+ # Parameters:
123
+ #
124
+ # * <tt>:invoiceid</tt> - the ID of the invoice the capture is to be attempted for
125
+ #
126
+ # Optional attributes:
127
+ # * <tt>:cvv</tt> - optionally can be used to pass the cards verification value in the payment request
128
+ #
129
+ # See:
130
+ #
131
+ # http://docs.whmcs.com/API:Capture_Payment
132
+ def self.capture_payment(params = {})
133
+ params.merge!(:action => 'capturepayment')
134
+ send_request(params)
135
+ end
136
+
137
+ # Add a new billable item
138
+ #
139
+ # Parameters:
140
+ #
141
+ # * <tt>:clientid</tt>
142
+ # * <tt>:description</tt>
143
+ # * <tt>:hours</tt>
144
+ # * <tt>:amount</tt>
145
+ # * <tt>:invoiceaction</tt> - noinvoice, nextcron, nextinvoice, duedate, recur
146
+ #
147
+ # Optional attributes:
148
+ # * <tt>:duedate</tt> - date the invoice should be due
149
+ # * <tt>:recur</tt> - frequency to recur - 1,2,3,etc...
150
+ # * <tt>:recurcycle</tt> - Days, Weeks, Months or Years
151
+ # * <tt>:recurfor</tt> - number of times to repeat
152
+ #
153
+ # See:
154
+ #
155
+ # http://docs.whmcs.com/API:Add_Billable_Item
156
+ def self.add_billable_item(params = {})
157
+ params.merge!(:action => 'addbillableitem')
158
+ send_request(params)
159
+ end
160
+
161
+ # Add a credit to client's account
162
+ #
163
+ # Parameters:
164
+ #
165
+ # * <tt>:clientid</tt> - the ID of the client the credit is to be added to
166
+ # * <tt>:description</tt> - reason for credit being added (stored in admin credit log)
167
+ # * <tt>:amount</tt> - the amount to be added
168
+ #
169
+ # See:
170
+ #
171
+ # http://docs.whmcs.com/API:Add_Credit
172
+ def self.add_credit(params = {})
173
+ params.merge!(:action => 'addcredit')
174
+ send_request(params)
175
+ end
176
+
177
+ # Add transaction
178
+ #
179
+ # Parameters:
180
+ # * <tt>:amountin</tt> - amount to add to the account
181
+ # * <tt>:amountout</tt> - if an outgoing enter this
182
+ # * <tt>:paymentmethod</tt> - gateway used in WHMCS
183
+ # * <tt>:date</tt> - date of transaction (same format as your WHMCS eg DD/MM/YYYY)
184
+
185
+ # * <tt>:userid</tt> - Optional Add Transaction to a user
186
+ # * <tt>:invoiceid</tt> - Optional Add transaction to a particular invoice
187
+ # * <tt>:description</tt> - Description of the transaction
188
+ # * <tt>:fees</tt> - transaction fee you were charged
189
+ # * <tt>:transid</tt> - Transaction ID you wish to assign
190
+ # * <tt>:credit</tt> - set to true to add the transaction as credit to the client
191
+ # See:
192
+ #
193
+ # http://docs.whmcs.com/API:Add_Transaction
194
+ def self.add_transaction(params = {})
195
+ params.merge!(:action => 'addtransaction')
196
+ send_request(params)
197
+ end
198
+
199
+ # Update Transaction
200
+ #
201
+ # Parameters:
202
+ # * <tt>:transactionid</tt> - The Transaction ID to update. tblaccounts.id
203
+ #
204
+ # Optional attributes:
205
+ # * <tt>:userid</tt> - Add Transaction to a user
206
+ # * <tt>:currency</tt> - Currency ID for a transaction
207
+ # * <tt>:gateway</tt> - Gateway to assign transaction to
208
+ # * <tt>:date</tt> - date of transaction YYYYMMDD
209
+ # * <tt>:description</tt> - Description of the transaction
210
+ # * <tt>:amountin</tt> - amount to add to the account
211
+ # * <tt>:fees</tt> - transaction fee you were charged
212
+ # * <tt>:amountout</tt> - if an outgoing enter this
213
+ # * <tt>:rate</tt> - exchange rate based on master currency. Set to 1 if on default currency
214
+ # * <tt>:transid</tt> - Transaction ID you wish to assign
215
+ # * <tt>:invoiceid</tt> - Add transaction to a particular invoice
216
+ # * <tt>:refundid</tt> - Add a refund ID if this is a refund transaction
217
+ #
218
+ # See:
219
+ #
220
+ # http://docs.whmcs.com/API:Update_Transaction
221
+ def self.update_transaction(params = {})
222
+ params.merge!(:action => 'updatetransaction')
223
+ send_request(params)
224
+ end
225
+
226
+ # Get configured payment methods
227
+ #
228
+ # See:
229
+ #
230
+ # http://docs.whmcs.com/API:Get_Payment_Methods
231
+ def self.get_payment_methods(params = {})
232
+ params.merge!(:action => 'getpaymentmethods')
233
+ send_request(params)
234
+ end
235
+
236
+ # Apply Credit
237
+ #
238
+ # Parameters:
239
+ # * <tt>:invoiceid</tt> - the ID to apply the credit to
240
+ # * <tt>:amount</tt> - the amount of credit to apply (must be less than or equal to clients available credit balance)
241
+ #
242
+ # See:
243
+ #
244
+ # http://docs.whmcs.com/API:Apply_Credit
245
+ def self.apply_credit(params = {})
246
+ params.merge!(:action => 'applycredit')
247
+ send_request(params)
248
+ end
249
+
250
+
251
+
252
+ end
253
+ end