-
Notifications
You must be signed in to change notification settings - Fork 5
/
UpdateOrder.go
56 lines (50 loc) · 2.24 KB
/
UpdateOrder.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
package taxjar
import "encoding/json"
// UpdateOrderParams should be passed to `UpdateOrder` to update an existing order․
type UpdateOrderParams struct {
TransactionID string `json:"transaction_id,omitempty"`
TransactionDate string `json:"transaction_date,omitempty"`
FromCountry string `json:"from_country,omitempty"`
FromZip string `json:"from_zip,omitempty"`
FromState string `json:"from_state,omitempty"`
FromCity string `json:"from_city,omitempty"`
FromStreet string `json:"from_street,omitempty"`
ToCountry string `json:"to_country,omitempty"`
ToZip string `json:"to_zip,omitempty"`
ToState string `json:"to_state,omitempty"`
ToCity string `json:"to_city,omitempty"`
ToStreet string `json:"to_street,omitempty"`
Amount float64 `json:"amount,omitempty"`
Shipping float64 `json:"shipping,omitempty"`
SalesTax float64 `json:"sales_tax,omitempty"`
CustomerID string `json:"customer_id,omitempty"`
ExemptionType string `json:"exemption_type,omitempty"`
LineItems []OrderLineItem `json:"line_items,omitempty"`
}
// UpdateOrderResponse is the structure returned from `UpdateOrder`․
//
// Access the updated order with `UpdateOrderResponse.Order`․
type UpdateOrderResponse struct {
Order Order `json:"order"`
}
// UpdateOrder updates an existing order in TaxJar․
//
// See https://developers.taxjar.com/api/reference/?go#put-update-an-order-transaction for more details․
func (client *Config) UpdateOrder(params UpdateOrderParams) (*UpdateOrderResponse, error) {
res, err := client.put("transactions/orders/"+params.TransactionID, params)
if err != nil {
return nil, err
}
order := new(UpdateOrderResponse)
if err := json.Unmarshal(res.([]byte), &order); err != nil {
if typeError, ok := err.(*json.UnmarshalTypeError); ok {
// Ignores JSON line_item.id type errors due to API's conversion of numeric strings to integers
if !(typeError.Field == "order.line_items.id" && typeError.Value == "number") {
return nil, err
}
} else {
return nil, err
}
}
return order, nil
}