-
Notifications
You must be signed in to change notification settings - Fork 5
/
ShowOrder.go
57 lines (50 loc) · 2.05 KB
/
ShowOrder.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
package taxjar
import "encoding/json"
// ShowOrderParams should be passed to `ShowOrder` to show an order․
type ShowOrderParams struct {
Provider string `url:"provider,omitempty"`
}
// ShowOrderResponse is the structure returned from `ShowOrder`․
//
// Access the order with `ShowOrderResponse.Order`․
type ShowOrderResponse struct {
Order Order `json:"order"`
}
// OrderLineItem is the structure for a line item passed within `CreateOrderParams.LineItems` and `UpdateOrderParams.LineItems`․
//
// OrderLineItem is also the structure for a line item returned within `CreateOrderResponse.Order.LineItems`, `UpdateOrderResponse.Order.LineItems`, `ShowOrderResponse.Order.LineItems`, and `DeleteOrderResponse.Order.LineItems`․
type OrderLineItem struct {
ID string `json:"id,omitempty"`
Quantity int `json:"quantity,omitempty"`
ProductIdentifier string `json:"product_identifier,omitempty"`
Description string `json:"description,omitempty"`
ProductTaxCode string `json:"product_tax_code,omitempty"`
UnitPrice float64 `json:"unit_price,omitempty,string"`
Discount float64 `json:"discount,omitempty,string"`
SalesTax float64 `json:"sales_tax,omitempty,string"`
}
// ShowOrder shows an existing order in TaxJar․
//
// See https://developers.taxjar.com/api/reference/?go#get-show-an-order-transaction for more details․
func (client *Config) ShowOrder(transactionID string, params ...ShowOrderParams) (*ShowOrderResponse, error) {
var p interface{}
if len(params) > 0 {
p = params[0]
}
res, err := client.get("transactions/orders/"+transactionID, p)
if err != nil {
return nil, err
}
order := new(ShowOrderResponse)
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
}