-
Notifications
You must be signed in to change notification settings - Fork 5
/
DeleteOrder.go
44 lines (37 loc) · 1.23 KB
/
DeleteOrder.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
package taxjar
import "encoding/json"
// DeleteOrderParams should be passed to `DeleteOrder` to delete an order․
type DeleteOrderParams struct {
Provider string `url:"provider,omitempty"`
}
// DeleteOrderResponse is the structure returned from `DeleteOrder`․
//
// Access the deleted order with `DeleteOrderResponse.Order`․
type DeleteOrderResponse struct {
Order Order `json:"order"`
}
// DeleteOrder deletes an order in TaxJar․
//
// See https://developers.taxjar.com/api/reference/?go#delete-delete-an-order-transaction for more details․
func (client *Config) DeleteOrder(transactionID string, params ...DeleteOrderParams) (*DeleteOrderResponse, error) {
var p interface{}
if len(params) > 0 {
p = params[0]
}
res, err := client.delete("transactions/orders/"+transactionID, p)
if err != nil {
return nil, err
}
order := new(DeleteOrderResponse)
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
}