-
Notifications
You must be signed in to change notification settings - Fork 5
/
DeleteRefund.go
44 lines (37 loc) · 1.26 KB
/
DeleteRefund.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"
// DeleteRefundParams should be passed to `DeleteRefund` to delete a refund․
type DeleteRefundParams struct {
Provider string `url:"provider,omitempty"`
}
// DeleteRefundResponse is the structure returned from `DeleteRefund`․
//
// Access the deleted refund with `DeleteRefundResponse.Refund`․
type DeleteRefundResponse struct {
Refund Refund `json:"refund"`
}
// DeleteRefund deletes a refund in TaxJar․
//
// See https://developers.taxjar.com/api/reference/?go#delete-delete-a-refund-transaction for more details․
func (client *Config) DeleteRefund(transactionID string, params ...DeleteRefundParams) (*DeleteRefundResponse, error) {
var p interface{}
if len(params) > 0 {
p = params[0]
}
res, err := client.delete("transactions/refunds/"+transactionID, p)
if err != nil {
return nil, err
}
refund := new(DeleteRefundResponse)
if err := json.Unmarshal(res.([]byte), &refund); 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 == "refund.line_items.id" && typeError.Value == "number") {
return nil, err
}
} else {
return nil, err
}
}
return refund, nil
}