-
Notifications
You must be signed in to change notification settings - Fork 5
/
ShowRefund.go
63 lines (54 loc) · 2.25 KB
/
ShowRefund.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
package taxjar
import "encoding/json"
// ShowRefundParams should be passed to `ShowRefund` to show a refund․
type ShowRefundParams struct {
Provider string `url:"provider,omitempty"`
}
// Refund is the structure for a refund returned within `CreateRefundResponse`, `ShowRefundResponse`, `UpdateRefundResponse`, and `DeleteRefundResponse`․
type Refund struct {
Order
}
// ShowRefundResponse is the structure returned from `ShowRefund`․
//
// Access the refund with `ShowRefundResponse.Refund`․
type ShowRefundResponse struct {
Refund Refund `json:"refund"`
}
// RefundLineItem is the structure for a line item passed within `CreateRefundParams.LineItems` and `UpdateRefundParams.LineItems`․
//
// RefundLineItem is also the structure for a line item returned within `CreateRefundResponse.Refund.LineItems`, `UpdateRefundResponse.Refund.LineItems`, `ShowRefundResponse.Refund.LineItems`, and `DeleteRefundResponse.Refund.LineItems`․
type RefundLineItem 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"`
Discount float64 `json:"discount,omitempty"`
SalesTax float64 `json:"sales_tax,omitempty"`
}
// ShowRefund shows an existing refund in TaxJar․
//
// See https://developers.taxjar.com/api/reference/?go#get-show-a-refund-transaction for more details․
func (client *Config) ShowRefund(transactionID string, params ...ShowRefundParams) (*ShowRefundResponse, error) {
var p interface{}
if len(params) > 0 {
p = params[0]
}
res, err := client.get("transactions/refunds/"+transactionID, p)
if err != nil {
return nil, err
}
refund := new(ShowRefundResponse)
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
}