diff --git a/.gitignore b/.gitignore index 256f889..ac9948d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /pkg/ -/vendor/ \ No newline at end of file +/vendor/ +.idea \ No newline at end of file diff --git a/client/address.go b/client/address.go index 84cf4d1..e408a0b 100644 --- a/client/address.go +++ b/client/address.go @@ -9,29 +9,29 @@ import ( ) // CreateAddress creates a new address object. -func (c *Client) CreateAddress(input *models.AddressInput) (*models.Address, error) { +func (c *Client) CreateAddress(input *models.AddressInput, shippoSubAccountID string) (*models.Address, error) { if input == nil { return nil, errors.New("nil input") } output := &models.Address{} - err := c.do(http.MethodPost, "/addresses/", input, output) + err := c.do(http.MethodPost, "/addresses/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveAddress retrieves an existing address by object id. -func (c *Client) RetrieveAddress(objectID string) (*models.Address, error) { +func (c *Client) RetrieveAddress(objectID string, shippoSubAccountID string) (*models.Address, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Address{} - err := c.do(http.MethodGet, "/addresses/"+objectID, nil, output) + err := c.do(http.MethodGet, "/addresses/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllAddresses lists all addresses. -func (c *Client) ListAllAddresses() ([]*models.Address, error) { +func (c *Client) ListAllAddresses(shippoSubAccountID string) ([]*models.Address, error) { list := []*models.Address{} err := c.doList(http.MethodGet, "/addresses/", nil, func(v json.RawMessage) error { item := &models.Address{} @@ -41,6 +41,6 @@ func (c *Client) ListAllAddresses() ([]*models.Address, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } diff --git a/client/batch.go b/client/batch.go index bda4687..42317ff 100644 --- a/client/batch.go +++ b/client/batch.go @@ -12,7 +12,7 @@ import ( // RetrieveBatch retrieves an existing batch. BatchShipments are displayed 100 at a time. // You can iterate through each "page" by specifying non-zero value to page parameter. // You can also filter based on BatchShipment status using objectResultsFilter parameter -func (c *Client) RetrieveBatch(objectID string, page uint, objectResultsFilter string) (*models.Batch, error) { +func (c *Client) RetrieveBatch(objectID string, page uint, objectResultsFilter string, shippoSubAccountID string) (*models.Batch, error) { if objectID == "" { return nil, errors.New("Empty object ID") } @@ -30,12 +30,12 @@ func (c *Client) RetrieveBatch(objectID string, page uint, objectResultsFilter s } output := &models.Batch{} - err := c.do(http.MethodGet, url, nil, output) + err := c.do(http.MethodGet, url, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // AddBatchShipmentsToBatch adds batch shipment(s) to an existing Batch. -func (c *Client) AddBatchShipmentsToBatch(objectID string, batchShipments []*models.BatchShipmentInput) (*models.Batch, error) { +func (c *Client) AddBatchShipmentsToBatch(objectID string, batchShipments []*models.BatchShipmentInput, shippoSubAccountID string) (*models.Batch, error) { if objectID == "" { return nil, errors.New("Empty object ID") } @@ -44,12 +44,12 @@ func (c *Client) AddBatchShipmentsToBatch(objectID string, batchShipments []*mod } output := &models.Batch{} - err := c.do(http.MethodPost, "/batches/"+objectID+"/add_shipments", &batchShipments, output) + err := c.do(http.MethodPost, "/batches/"+objectID+"/add_shipments", &batchShipments, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RemoveBatchShipmentsFromBatch removes batch shipment(s) from an existing Batch. -func (c *Client) RemoveBatchShipmentsFromBatch(objectID string, batchShipmentIDs []string) (*models.Batch, error) { +func (c *Client) RemoveBatchShipmentsFromBatch(objectID string, batchShipmentIDs []string, shippoSubAccountID string) (*models.Batch, error) { if objectID == "" { return nil, errors.New("Empty object ID") } @@ -58,7 +58,7 @@ func (c *Client) RemoveBatchShipmentsFromBatch(objectID string, batchShipmentIDs } output := &models.Batch{} - err := c.do(http.MethodPost, "/batches/"+objectID+"/remove_shipments", &batchShipmentIDs, output) + err := c.do(http.MethodPost, "/batches/"+objectID+"/remove_shipments", &batchShipmentIDs, output, c.subAccountHeader(shippoSubAccountID)) return output, err } @@ -66,12 +66,12 @@ func (c *Client) RemoveBatchShipmentsFromBatch(objectID string, batchShipmentIDs // Once you send invoke this function, the batch ObjectStatus will be change to PURCHASING. // When all the shipments are purchased, the ObjectStatus will change to PURCHASED // and you will receive a batch_purchased webhook indicating that the batch has been purchased. -func (c *Client) PurchaseBatch(objectID string) (*models.Batch, error) { +func (c *Client) PurchaseBatch(objectID string, shippoSubAccountID string) (*models.Batch, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Batch{} - err := c.do(http.MethodPost, "/batches/"+objectID+"/purchase", nil, output) + err := c.do(http.MethodPost, "/batches/"+objectID+"/purchase", nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } diff --git a/client/carrier_account.go b/client/carrier_account.go index 3214703..8214b7b 100644 --- a/client/carrier_account.go +++ b/client/carrier_account.go @@ -10,29 +10,29 @@ import ( ) // CreateCarrierAccount creates a new carrier account object. -func (c *Client) CreateCarrierAccount(input *models.CarrierAccountInput) (*models.CarrierAccount, error) { +func (c *Client) CreateCarrierAccount(input *models.CarrierAccountInput, shippoSubAccountID string) (*models.CarrierAccount, error) { if input == nil { return nil, errors.New("nil input") } output := &models.CarrierAccount{} - err := c.do(http.MethodPost, "/carrier_accounts/", input, output) + err := c.do(http.MethodPost, "/carrier_accounts/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveCarrierAccount retrieves an existing carrier account by object id. -func (c *Client) RetrieveCarrierAccount(objectID string) (*models.CarrierAccount, error) { +func (c *Client) RetrieveCarrierAccount(objectID string, shippoSubAccountID string) (*models.CarrierAccount, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.CarrierAccount{} - err := c.do(http.MethodGet, "/carrier_accounts/"+objectID, nil, output) + err := c.do(http.MethodGet, "/carrier_accounts/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllCarrierAccounts lists all carrier accounts. -func (c *Client) ListAllCarrierAccounts() ([]*models.CarrierAccount, error) { +func (c *Client) ListAllCarrierAccounts(shippoSubAccountID string) ([]*models.CarrierAccount, error) { list := []*models.CarrierAccount{} err := c.doList(http.MethodGet, "/carrier_accounts/", nil, func(v json.RawMessage) error { item := &models.CarrierAccount{} @@ -42,13 +42,13 @@ func (c *Client) ListAllCarrierAccounts() ([]*models.CarrierAccount, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } // UpdateCarrierAccount updates an existing carrier account. // AccountID and Carrier cannot be updated because they form the unique identifier together. -func (c *Client) UpdateCarrierAccount(objectID string, input *models.CarrierAccountInput) (*models.CarrierAccount, error) { +func (c *Client) UpdateCarrierAccount(objectID string, input *models.CarrierAccountInput, shippoSubAccountID string) (*models.CarrierAccount, error) { if objectID == "" { return nil, errors.New("Empty object ID") } @@ -57,11 +57,11 @@ func (c *Client) UpdateCarrierAccount(objectID string, input *models.CarrierAcco } output := &models.CarrierAccount{} - err := c.do(http.MethodPut, "/carrier_accounts/"+objectID, input, output) + err := c.do(http.MethodPut, "/carrier_accounts/"+objectID, input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } -func (c *Client) ConnectCarrierAccount(objectID, redirectUrl, state string) (string, error) { +func (c *Client) ConnectCarrierAccount(objectID, redirectUrl, state string, shippoSubAccountID string) (string, error) { if objectID == "" { return "", errors.New("Empty object ID") } @@ -69,7 +69,7 @@ func (c *Client) ConnectCarrierAccount(objectID, redirectUrl, state string) (str url := fmt.Sprintf("/carrier_accounts/%s/signin/initiate?redirect_uri=%s&state=%s&redirect=false", objectID, redirectUrl, state) output := &models.ConnectOauth{} - err := c.do(http.MethodGet, url, nil, output) + err := c.do(http.MethodGet, url, nil, output, c.subAccountHeader(shippoSubAccountID)) if err != nil { return "", err } diff --git a/client/client.go b/client/client.go index 9b7a9d1..d57584f 100644 --- a/client/client.go +++ b/client/client.go @@ -40,10 +40,10 @@ func (c *Client) SetTraceLogger(logger *log.Logger) *log.Logger { return oldLogger } -func (c *Client) do(method, path string, input, output interface{}) error { +func (c *Client) do(method, path string, input, output interface{}, headers map[string]string) error { url := shippoAPIBaseURL + path - req, err := c.createRequest(method, url, input) + req, err := c.createRequest(method, url, input, headers) if err != nil { return fmt.Errorf("Error creating request object: %s", err.Error()) } @@ -58,11 +58,11 @@ func (c *Client) do(method, path string, input, output interface{}) error { return nil } -func (c *Client) doList(method, path string, input interface{}, outputCallback listOutputCallback) error { +func (c *Client) doList(method, path string, input interface{}, outputCallback listOutputCallback, headers map[string]string) error { nextURL := shippoAPIBaseURL + path + "?results=25" for { - req, err := c.createRequest(method, nextURL, input) + req, err := c.createRequest(method, nextURL, input, headers) if err != nil { return fmt.Errorf("Error creating request object: %s", err.Error()) } @@ -91,7 +91,7 @@ func (c *Client) doList(method, path string, input interface{}, outputCallback l return nil } -func (c *Client) createRequest(method, url string, bodyObject interface{}) (req *http.Request, err error) { +func (c *Client) createRequest(method, url string, bodyObject interface{}, headers map[string]string) (req *http.Request, err error) { var reqBodyDebug []byte if c.logger != nil { @@ -104,10 +104,9 @@ func (c *Client) createRequest(method, url string, bodyObject interface{}) (req return } - headers := []string{} for hk, hva := range req.Header { for _, hv := range hva { - headers = append(headers, fmt.Sprintf("%s=%s", hk, hv)) + c.logPrintf("Client.createRequest() Header %s=%s", hk, hv) } } @@ -149,6 +148,13 @@ func (c *Client) createRequest(method, url string, bodyObject interface{}) (req req.Header.Set("Connection", "close") req.Close = true + // add any passed in headers + if headers != nil { + for k, v := range headers { + req.Header.Set(k, v) + } + } + return req, nil } @@ -199,3 +205,11 @@ func (c *Client) logPrintf(format string, args ...interface{}) { c.logger.Printf(format, args...) } } + +func (c *Client) subAccountHeader(id string) map[string]string { + headers := make(map[string]string) + if len(id) > 0 { + headers["SHIPPO-ACCOUNT-ID"] = id + } + return headers +} diff --git a/client/customs.go b/client/customs.go index 31a5b0b..1b3b5f3 100644 --- a/client/customs.go +++ b/client/customs.go @@ -9,29 +9,29 @@ import ( ) // CreateCustomsItem creates a new customs item object. -func (c *Client) CreateCustomsItem(input *models.CustomsItemInput) (*models.CustomsItem, error) { +func (c *Client) CreateCustomsItem(input *models.CustomsItemInput, shippoSubAccountID string) (*models.CustomsItem, error) { if input == nil { return nil, errors.New("nil input") } output := &models.CustomsItem{} - err := c.do(http.MethodPost, "/customs/items/", input, output) + err := c.do(http.MethodPost, "/customs/items/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveCustomsItem retrieves an existing customs item by object id. -func (c *Client) RetrieveCustomsItem(objectID string) (*models.CustomsItem, error) { +func (c *Client) RetrieveCustomsItem(objectID string, shippoSubAccountID string) (*models.CustomsItem, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.CustomsItem{} - err := c.do(http.MethodGet, "/customs/items/"+objectID, nil, output) + err := c.do(http.MethodGet, "/customs/items/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllCustomsItems lists all customs item objects. -func (c *Client) ListAllCustomsItems() ([]*models.CustomsItem, error) { +func (c *Client) ListAllCustomsItems(shippoSubAccountID string) ([]*models.CustomsItem, error) { list := []*models.CustomsItem{} err := c.doList(http.MethodGet, "/customs/items/", nil, func(v json.RawMessage) error { item := &models.CustomsItem{} @@ -41,12 +41,12 @@ func (c *Client) ListAllCustomsItems() ([]*models.CustomsItem, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } // CreateCustomsDeclaration creates a new customs declaration object. -func (c *Client) CreateCustomsDeclaration(input *models.CustomsDeclarationInput) (*models.CustomsDeclaration, error) { +func (c *Client) CreateCustomsDeclaration(input *models.CustomsDeclarationInput, shippoSubAccountID string) (*models.CustomsDeclaration, error) { if input == nil { return nil, errors.New("nil input") } @@ -58,23 +58,23 @@ func (c *Client) CreateCustomsDeclaration(input *models.CustomsDeclarationInput) } output := &models.CustomsDeclaration{} - err := c.do(http.MethodPost, "/customs/declarations/", input, output) + err := c.do(http.MethodPost, "/customs/declarations/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveCustomsDeclaration retrieves an existing customs declaration by object id. -func (c *Client) RetrieveCustomsDeclaration(objectID string) (*models.CustomsDeclaration, error) { +func (c *Client) RetrieveCustomsDeclaration(objectID string, shippoSubAccountID string) (*models.CustomsDeclaration, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.CustomsDeclaration{} - err := c.do(http.MethodGet, "/customs/declarations/"+objectID, nil, output) + err := c.do(http.MethodGet, "/customs/declarations/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllCustomsDeclaration lists all customs declaration objects. -func (c *Client) ListAllCustomsDeclaration() ([]*models.CustomsDeclaration, error) { +func (c *Client) ListAllCustomsDeclaration(shippoSubAccountID string) ([]*models.CustomsDeclaration, error) { list := []*models.CustomsDeclaration{} err := c.doList(http.MethodGet, "/customs/declarations/", nil, func(v json.RawMessage) error { item := &models.CustomsDeclaration{} @@ -84,6 +84,6 @@ func (c *Client) ListAllCustomsDeclaration() ([]*models.CustomsDeclaration, erro list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } diff --git a/client/manifest.go b/client/manifest.go index 7cb1eb4..9176fae 100644 --- a/client/manifest.go +++ b/client/manifest.go @@ -9,29 +9,29 @@ import ( ) // CreateManifest creates a new manifest object. -func (c *Client) CreateManifest(input *models.ManifestInput) (*models.Manifest, error) { +func (c *Client) CreateManifest(input *models.ManifestInput, shippoSubAccountID string) (*models.Manifest, error) { if input == nil { return nil, errors.New("nil input") } output := &models.Manifest{} - err := c.do(http.MethodPost, "/manifests/", input, output) + err := c.do(http.MethodPost, "/manifests/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveManifest retrieves an existing manifest by object id. -func (c *Client) RetrieveManifest(objectID string) (*models.Manifest, error) { +func (c *Client) RetrieveManifest(objectID string, shippoSubAccountID string) (*models.Manifest, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Manifest{} - err := c.do(http.MethodGet, "/manifests/"+objectID, nil, output) + err := c.do(http.MethodGet, "/manifests/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllManifests lists all manifest objects. -func (c *Client) ListAllManifests() ([]*models.Manifest, error) { +func (c *Client) ListAllManifests(shippoSubAccountID string) ([]*models.Manifest, error) { list := []*models.Manifest{} err := c.doList(http.MethodGet, "/manifests/", nil, func(v json.RawMessage) error { item := &models.Manifest{} @@ -41,6 +41,6 @@ func (c *Client) ListAllManifests() ([]*models.Manifest, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } diff --git a/client/parcel.go b/client/parcel.go index 151cf53..8fbffd3 100644 --- a/client/parcel.go +++ b/client/parcel.go @@ -9,29 +9,29 @@ import ( ) // CreateParcel creates a new parcel object. -func (c *Client) CreateParcel(input *models.ParcelInput) (*models.Parcel, error) { +func (c *Client) CreateParcel(input *models.ParcelInput, shippoSubAccountID string) (*models.Parcel, error) { if input == nil { return nil, errors.New("nil input") } output := &models.Parcel{} - err := c.do(http.MethodPost, "/parcels/", input, output) + err := c.do(http.MethodPost, "/parcels/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveParcel retrieves an existing parcel by object id. -func (c *Client) RetrieveParcel(objectID string) (*models.Parcel, error) { +func (c *Client) RetrieveParcel(objectID string, shippoSubAccountID string) (*models.Parcel, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Parcel{} - err := c.do(http.MethodGet, "/parcels/"+objectID, nil, output) + err := c.do(http.MethodGet, "/parcels/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllParcels lists all parcel objects. -func (c *Client) ListAllParcels() ([]*models.Parcel, error) { +func (c *Client) ListAllParcels(shippoSubAccountID string) ([]*models.Parcel, error) { list := []*models.Parcel{} err := c.doList(http.MethodGet, "/parcels/", nil, func(v json.RawMessage) error { item := &models.Parcel{} @@ -41,6 +41,6 @@ func (c *Client) ListAllParcels() ([]*models.Parcel, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } diff --git a/client/rate.go b/client/rate.go index 14e4f25..fd60d1f 100644 --- a/client/rate.go +++ b/client/rate.go @@ -9,7 +9,7 @@ import ( ) // GetShippingRates gets rates for a shipping object. -func (c *Client) GetShippingRates(shipmentObjectID, currencyCode string) ([]*models.Rate, error) { +func (c *Client) GetShippingRates(shipmentObjectID, currencyCode string, shippoSubAccountID string) ([]*models.Rate, error) { if shipmentObjectID == "" { return nil, errors.New("Empty shipment object ID") } @@ -26,17 +26,17 @@ func (c *Client) GetShippingRates(shipmentObjectID, currencyCode string) ([]*mod list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } // RetrieveRate retrieves an existing rate by object id. -func (c *Client) RetrieveRate(objectID string) (*models.Rate, error) { +func (c *Client) RetrieveRate(objectID string, shippoSubAccountID string) (*models.Rate, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Rate{} - err := c.do(http.MethodGet, "/rates/"+objectID, nil, output) + err := c.do(http.MethodGet, "/rates/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } diff --git a/client/refund.go b/client/refund.go index 42338a0..f946fa2 100644 --- a/client/refund.go +++ b/client/refund.go @@ -9,29 +9,29 @@ import ( ) // CreateRefund creates a new refund object. -func (c *Client) CreateRefund(input *models.RefundInput) (*models.Refund, error) { +func (c *Client) CreateRefund(input *models.RefundInput, shippoSubAccountID string) (*models.Refund, error) { if input == nil { return nil, errors.New("nil input") } output := &models.Refund{} - err := c.do(http.MethodPost, "/refunds/", input, output) + err := c.do(http.MethodPost, "/refunds/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveRefund retrieves an existing refund by object id. -func (c *Client) RetrieveRefund(objectID string) (*models.Refund, error) { +func (c *Client) RetrieveRefund(objectID string, shippoSubAccountID string) (*models.Refund, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Refund{} - err := c.do(http.MethodGet, "/refunds/"+objectID, nil, output) + err := c.do(http.MethodGet, "/refunds/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllRefunds list all refund objects. -func (c *Client) ListAllRefunds() ([]*models.Refund, error) { +func (c *Client) ListAllRefunds(shippoSubAccountID string) ([]*models.Refund, error) { list := []*models.Refund{} err := c.doList(http.MethodGet, "/refunds/", nil, func(v json.RawMessage) error { item := &models.Refund{} @@ -41,6 +41,6 @@ func (c *Client) ListAllRefunds() ([]*models.Refund, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } diff --git a/client/shipment.go b/client/shipment.go index ffba38f..ca1baf5 100644 --- a/client/shipment.go +++ b/client/shipment.go @@ -17,7 +17,7 @@ import ( // The Shippo API currently supports Scan-based returns for USPS, Fedex and UPS. // When the ReturnOf flag is set, Shippo API will automatically swap the address_from and address_to fields for label creation. // Please check the return service terms and condition for the carrier you intend to use. -func (c *Client) CreateShipment(input *models.ShipmentInput) (*models.Shipment, error) { +func (c *Client) CreateShipment(input *models.ShipmentInput, shippoSubAccountID string) (*models.Shipment, error) { if input == nil { return nil, errors.New("nil input") } @@ -57,23 +57,23 @@ func (c *Client) CreateShipment(input *models.ShipmentInput) (*models.Shipment, } output := &models.Shipment{} - err := c.do(http.MethodPost, "/shipments/", input, output) + err := c.do(http.MethodPost, "/shipments/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveShipment retrieves an existing shipment by object id. -func (c *Client) RetrieveShipment(objectID string) (*models.Shipment, error) { +func (c *Client) RetrieveShipment(objectID string, shippoSubAccountID string) (*models.Shipment, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Shipment{} - err := c.do(http.MethodGet, "/shipments/"+objectID, nil, output) + err := c.do(http.MethodGet, "/shipments/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllShipments lists all shipment objects. -func (c *Client) ListAllShipments() ([]*models.Shipment, error) { +func (c *Client) ListAllShipments(shippoSubAccountID string) ([]*models.Shipment, error) { list := []*models.Shipment{} err := c.doList(http.MethodGet, "/shipments/", nil, func(v json.RawMessage) error { item := &models.Shipment{} @@ -83,6 +83,6 @@ func (c *Client) ListAllShipments() ([]*models.Shipment, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err } diff --git a/client/tracking_status.go b/client/tracking_status.go index 74f17a9..1aa0ba7 100644 --- a/client/tracking_status.go +++ b/client/tracking_status.go @@ -17,7 +17,7 @@ func (c *Client) GetTrackingUpdate(carrier, trackingNumber string) (*models.Trac } output := &models.TrackingStatus{} - err := c.do(http.MethodGet, "/tracks/"+carrier+"/"+trackingNumber, nil, output) + err := c.do(http.MethodGet, "/tracks/"+carrier+"/"+trackingNumber, nil, output, nil) return output, err } @@ -37,6 +37,6 @@ func (c *Client) RegisterTrackingWebhook(carrier, trackingNumber, metadata strin Carrier: carrier, TrackingNumber: trackingNumber, Metadata: metadata, - }, output) + }, output, nil) return output, err } diff --git a/client/transaction.go b/client/transaction.go index 94f0ed9..5327074 100644 --- a/client/transaction.go +++ b/client/transaction.go @@ -9,29 +9,29 @@ import ( ) // PurchaseShippingLabel creates a new transaction object and purchases the shipping label for the provided rate. -func (c *Client) PurchaseShippingLabel(input *models.TransactionInput) (*models.Transaction, error) { +func (c *Client) PurchaseShippingLabel(input *models.TransactionInput, shippoSubAccountID string) (*models.Transaction, error) { if input == nil { return nil, errors.New("nil input") } output := &models.Transaction{} - err := c.do(http.MethodPost, "/transactions/", input, output) + err := c.do(http.MethodPost, "/transactions/", input, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // RetrieveTransaction retrieves an existing transaction by object id. -func (c *Client) RetrieveTransaction(objectID string) (*models.Transaction, error) { +func (c *Client) RetrieveTransaction(objectID string, shippoSubAccountID string) (*models.Transaction, error) { if objectID == "" { return nil, errors.New("Empty object ID") } output := &models.Transaction{} - err := c.do(http.MethodGet, "/transactions/"+objectID, nil, output) + err := c.do(http.MethodGet, "/transactions/"+objectID, nil, output, c.subAccountHeader(shippoSubAccountID)) return output, err } // ListAllTransactions lists all transaction objects. -func (c *Client) ListAllTransactions() ([]*models.Transaction, error) { +func (c *Client) ListAllTransactions(shippoSubAccountID string) ([]*models.Transaction, error) { list := []*models.Transaction{} err := c.doList(http.MethodGet, "/transactions/", nil, func(v json.RawMessage) error { item := &models.Transaction{} @@ -41,6 +41,6 @@ func (c *Client) ListAllTransactions() ([]*models.Transaction, error) { list = append(list, item) return nil - }) + }, c.subAccountHeader(shippoSubAccountID)) return list, err }