forked from EasyPost/easypost-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustoms.go
134 lines (121 loc) · 5.17 KB
/
customs.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package easypost
import (
"context"
"time"
)
// CustomsInfo objects contain CustomsItem objects and all necessary information
// for the generation of customs forms required for international shipping.
type CustomsInfo struct {
ID string `json:"id,omitempty"`
Object string `json:"object,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
EELPFC string `json:"eel_pfc,omitempty"`
ContentsType string `json:"contents_type,omitempty"`
ContentsExplanation string `json:"contents_explanation,omitempty"`
CustomsCertify bool `json:"customs_certify,omitempty"`
CustomsSigner string `json:"customs_signer,omitempty"`
NonDeliveryOption string `json:"non_delivery_option,omitempty"`
RestrictionType string `json:"restriction_type,omitempty"`
CustomsItems []*CustomsItem `json:"customs_items,omitempty"`
Declaration string `json:"declaration,omitempty"`
}
// A CustomsItem object describes goods for international shipment.
type CustomsItem struct {
ID string `json:"id,omitempty"`
Object string `json:"object,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Description string `json:"description,omitempty"`
Quantity float64 `json:"quantity,omitempty"`
Value float64 `json:"value,omitempty,string"`
Weight float64 `json:"weight,omitempty"`
HSTariffNumber string `json:"hs_tariff_number,omitempty"`
Code string `json:"code,omitempty"`
OriginCountry string `json:"origin_country,omitempty"`
Currency string `json:"currency,omitempty"`
}
type createCustomsInfoRequest struct {
CustomsInfo *CustomsInfo `json:"customs_info,omitempty"`
}
type createCustomsItemRequest struct {
CustomsItem *CustomsItem `json:"customs_item,omitempty"`
}
// CreateCustomsInfo creates a new CustomsInfo object.
//
// c := easypost.New(MyEasyPostAPIKey)
// out, err := c.CreateCustomsInfo(
// &easypost.CustomsInfo{
// CustomsCertify: true,
// CustomsSigner: "Steve Brule",
// CustomsType: "merchandise",
// RestrictionType: "none",
// EELPFC: "NOEEI 30.37(a)",
// CustomsItems: []*easypost.CustomsItem{
// &easypost.CustomsItem{ID: "cstitem_2002"},
// &easypost.CustomsItem{
// Description: "Sweet shirts",
// Quantity: 2,
// Value: 23,
// Weight: 11,
// HSTariffNumber: "654321",
// OriginCountry: "US",
// },
// },
// },
// )
func (c *Client) CreateCustomsInfo(in *CustomsInfo) (out *CustomsInfo, err error) {
return c.CreateCustomsInfoWithContext(context.Background(), in)
}
// CreateCustomsInfoWithContext performs the same operation as
// CreateCustomsInfo, but allows specifying a context that can interrupt the
// request.
func (c *Client) CreateCustomsInfoWithContext(ctx context.Context, in *CustomsInfo) (out *CustomsInfo, err error) {
req := &createCustomsInfoRequest{CustomsInfo: in}
err = c.post(ctx, "customs_infos", req, &out)
return
}
// GetCustomsInfo returns the CustomsInfo object with the given ID or reference.
func (c *Client) GetCustomsInfo(customsInfoID string) (out *CustomsInfo, err error) {
return c.GetCustomsInfoWithContext(context.Background(), customsInfoID)
}
// GetCustomsInfoWithContext performs the same operation as GetCustomsInfo, but
// allows specifying a context that can interrupt the request.
func (c *Client) GetCustomsInfoWithContext(ctx context.Context, customsInfoID string) (out *CustomsInfo, err error) {
err = c.get(ctx, "customs_infos/"+customsInfoID, &out)
return
}
// CreateCustomsItem creates a new CustomsItem object.
//
// c := easypost.New(MyEasyPostAPIKey)
// out, err := c.CreateCustomsItem(
// &easypost.CustomsItem{
// Description: "T-shirt",
// Quantity: 1,
// Weight: 5,
// Value: 10,
// HSTariffNumber: "123456",
// OriginCountry: "US",
// },
// )
func (c *Client) CreateCustomsItem(in *CustomsItem) (out *CustomsItem, err error) {
return c.CreateCustomsItemWithContext(context.Background(), in)
}
// CreateCustomsItemWithContext performs the same operation as
// CreateCustomsItem, but allows specifying a context that can interrupt the
// request.
func (c *Client) CreateCustomsItemWithContext(ctx context.Context, in *CustomsItem) (out *CustomsItem, err error) {
req := &createCustomsItemRequest{CustomsItem: in}
err = c.post(ctx, "customs_items", req, &out)
return
}
// GetCustomsItem returns the CustomsInfo object with the given ID or reference.
func (c *Client) GetCustomsItem(customsItemID string) (out *CustomsItem, err error) {
return c.GetCustomsItemWithContext(context.Background(), customsItemID)
}
// GetCustomsItemWithContext performs the same operation as GetCustomsItem, but
// allows specifying a context that can interrupt the request.
func (c *Client) GetCustomsItemWithContext(ctx context.Context, customsItemID string) (out *CustomsItem, err error) {
err = c.get(ctx, "customs_items/"+customsItemID, &out)
return
}