-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathorder.go
110 lines (95 loc) · 3.98 KB
/
order.go
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package whmcs
import (
"errors"
"strings"
)
// Errors which are returned when validating orders for completeness/accuracy.
var (
ErrNoClientID = errors.New("Empty client ID")
ErrNoPID = errors.New("Empty PID")
ErrNoDomain = errors.New("Empty domain")
ErrNoBillingCycle = errors.New("Empty billing cycle")
ErrNoDomainType = errors.New("Empty domain type")
ErrInvalidDomainType = errors.New("Invalid domain type")
ErrNoRegPeriod = errors.New("Empty registration period")
ErrNoNameserver = errors.New("Empty nameserver")
ErrNoPaymentMethod = errors.New("Empty payment method")
)
// Order is all the data needed to create a WHMCS order.
type Order struct {
// Required attributes
ClientID int64 `json:"clientid,string"`
PID int64 `json:"pid,string,omitempty"`
Domain string `json:"domain"`
BillingCycle string `json:"billingcycle"`
DomainType string `json:"domaintype"`
Regperiod int64 `json:"regperiod,string"`
EppCode string `json:"eppcode"`
Nameserver1 string `json:"nameserver1"`
PaymentMethod string `json:"paymentmethod"`
// Optional attributes
CustomFields CustomFields `json:"customfields,omitempty"`
ConfigOptions ConfigOptions `json:"configoptions,omitempty"`
PriceOverride float64 `json:"priceoverride,string,omitempty"`
PromoCode string `json:"promocode,omitempty"`
PromoOverride string `json:"promooverride,omitempty"`
AffID string `json:"affid,omitempty"`
NoInvoice bool `json:"noinvoice,string,omitempty"`
NoInvoiceEmail bool `json:"noinvoiceemail,string,omitempty"`
ClientIP string `json:"clientip,omitempty"`
Addons string `json:"addons,omitempty"`
// For VPS/Dedicated Server Orders only
Hostname string `json:"hostname,omitempty"`
NS1Prefix string `json:"ns1prefix,omitempty"`
NS2Prefix string `json:"ns2prefix,omitempty"`
RootPw string `json:"rootpw,omitempty"`
// For domain reg only
ContactID int64 `json:"contactid,omitempty"`
DNSManagement bool `json:"dnsmanagement,omitempty"`
EmailForwarding bool `json:"emailforwarding,omitempty"`
IDProtection bool `json:"idprotection,omitempty"`
Nameserver2 string `json:"nameserver2,omitempty"`
Nameserver3 string `json:"nameserver3,omitempty"`
Nameserver4 string `json:"nameserver4,omitempty"`
DomainRenewOverride int64 `json:"domainrenewoverride,omitempty"`
DomainPriceOverride int64 `json:"domainpriceoverride,omitempty"`
}
func (o *Order) Error() error {
return nil
}
// OrderResponse holds the successful order information sent via from the WHMCS API.
type OrderResponse struct {
Result string `json:"result"`
OrderID int64 `json:"orderid"`
InvoiceID int64 `json:"invoiceid"`
ProductIDs string `json:"productids"`
AddonIDs string `json:"addonids"`
DomainIDs string `json:"domainids"`
}
// Products returns a slice of product ids related to the order.
func (o *OrderResponse) Products() []string {
return strings.Split(o.ProductIDs, "/")
}
// Addons returns a slice of addon ids related to the order.
func (o *OrderResponse) Addons() []string {
return strings.Split(o.AddonIDs, ",")
}
// Domains returns a slice of domains related to the order.
func (o *OrderResponse) Domains() []string {
return strings.Split(o.DomainIDs, ",")
}
// AcceptOrderRequest is a struct of available parameters to accept an order.
type AcceptOrderRequest struct {
OrderID int64 `json:"orderid,string"`
// Optional attributes
ServerID int64 `json:"serverid,string,omitempty"`
ServiceUsername string `json:"serviceusername,omitempty"`
ServicePassword string `json:"servicepassword,omitempty"`
AutoSetup bool `json:"autosetup,string,omitempty"`
Registrar string `json:"registrar,omitempty"`
SendRegistrar bool `json:"sendregistrar,string,omitempty"`
SendEmail bool `json:"sendemail,string,omitempty"`
}
func (o *AcceptOrderRequest) Error() error {
return nil
}