diff --git a/CHANGELOG.md b/CHANGELOG.md index 2503d4a..92d378a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## Next Release + +- New `CreateUpsCarrierAccount` and `UpdateUpsCarrierAccount` methods and associated parameter structs, required to use for UPS accounts due to new `/ups_oauth_registrations` endpoint. + - Starting `2024-08-05`, UPS accounts will require a new payload to register or update. See [UPS OAuth 2.0 Update](https://support.easypost.com/hc/en-us/articles/26635027512717-UPS-OAuth-2-0-Update) for more details. + - Attempting to use the generic `CreateCarrierAccount` and `UpdateCarrierAccount` methods with UPS accounts will throw an `InvalidFunctionError`. + ## v4.3.1 (2024-07-01) - Adds missing `Readable` and `Logo` fields to `CarrierType` struct diff --git a/Makefile b/Makefile index 0f9e26a..0f3b728 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,13 @@ clean: coverage: go clean -testcache && go test ./tests -v -coverprofile=covprofile -coverpkg=./... && go tool cover -html=covprofile +## init-examples-submodule - Initialize the examples submodule +init-examples-submodule: + git submodule init + git submodule update + ## install - Install and vendor dependencies -install: | update-examples-submodule +install: | init-examples-submodule brew install golangci-lint || exit 0 go mod vendor go build -o $(PROJECT_PATH) diff --git a/carrier.go b/carrier.go index eca2062..6726b3f 100644 --- a/carrier.go +++ b/carrier.go @@ -11,8 +11,7 @@ type CarrierField struct { Value string `json:"value,omitempty"` } -// CarrierFields contains the data for carrier account fields for production -// and/or test credentials. +// CarrierFields contains the data for carrier account fields for production and/or test credentials. type CarrierFields struct { Credentials map[string]*CarrierField `json:"credentials,omitempty"` TestCredentials map[string]*CarrierField `json:"test_credentials,omitempty"` @@ -20,8 +19,8 @@ type CarrierFields struct { CustomWorkflow bool `json:"custom_workflow,omitempty"` } -// CarrierAccount encapsulates credentials and other information related to a -// carrier account. +// CarrierAccount encapsulates credentials and other information related to a carrier account. +// This struct is also used as a parameter set for creating and updating non-UPS carrier accounts. type CarrierAccount struct { ID string `json:"id,omitempty"` Object string `json:"object,omitempty"` @@ -39,8 +38,7 @@ type CarrierAccount struct { BillingType string `json:"billing_type,omitempty"` } -// CarrierType contains information on a supported carrier. It can be used to -// determine the valid fields for a carrier account. +// CarrierType contains information on a supported carrier. It can be used to determine the valid fields for a carrier account. type CarrierType struct { Object string `json:"object,omitempty"` Type string `json:"type,omitempty"` @@ -50,34 +48,58 @@ type CarrierType struct { } type carrierAccountRequest struct { - CarrierAccount *CarrierAccount `json:"carrier_account,omitempty"` + Data *CarrierAccount `json:"carrier_account,omitempty"` } -func (c *Client) selectCarrierAccountCreationEndpoint(account CarrierAccount) string { +// UpsCarrierAccountCreationParameters contains the parameters needed to create a new UPS carrier account. +type UpsCarrierAccountCreationParameters struct { + Type string `json:"type,omitempty"` + Description string `json:"description,omitempty"` + Reference string `json:"reference,omitempty"` + AccountNumber string `json:"account_number,omitempty"` +} + +type upsCarrierAccountCreationRequest struct { + Data *UpsCarrierAccountCreationParameters `json:"ups_oauth_registrations,omitempty"` +} + +// UpsCarrierAccountUpdateParameters contains the parameters needed to update a UPS carrier account. +type UpsCarrierAccountUpdateParameters struct { + AccountNumber string `json:"account_number,omitempty"` +} + +type upsCarrierAccountUpdateRequest struct { + Data *UpsCarrierAccountUpdateParameters `json:"ups_oauth_registrations,omitempty"` +} + +func (c *Client) selectCarrierAccountCreationEndpoint(typ string) string { for _, carrier := range getCarrierAccountTypesWithCustomWorkflows() { - if account.Type == carrier { + if typ == carrier { return "carrier_accounts/register" } } + for _, carrier := range getUpsCarrierAccountTypes() { + if typ == carrier { + return "ups_oauth_registrations" + } + } + return "carrier_accounts" } -// GetCarrierTypes returns a list of supported carrier types for the current -// user. +// GetCarrierTypes returns a list of supported carrier types for the current user. func (c *Client) GetCarrierTypes() (out []*CarrierType, err error) { return c.GetCarrierTypesWithContext(context.Background()) } -// GetCarrierTypesWithContext performs the same operation as GetCarrierTypes, -// but allows specifying a context that can interrupt the request. +// GetCarrierTypesWithContext performs the same operation as GetCarrierTypes, but allows specifying a context that can interrupt the request. func (c *Client) GetCarrierTypesWithContext(ctx context.Context) (out []*CarrierType, err error) { err = c.get(ctx, "carrier_types", &out) return } -// CreateCarrierAccount creates a new carrier account. It can only be used with -// a production API key. +// CreateCarrierAccount creates a new carrier account. It can only be used with a production API key. // // c := easypost.New(MyEasyPostAPIKey) // out, err := c.CreateCarrierAccount( @@ -92,29 +114,60 @@ func (c *Client) GetCarrierTypesWithContext(ctx context.Context) (out []*Carrier // }, // }, // ) +// +// Users cannot create UPS accounts with this function, must use CreateUpsCarrierAccount. An error will be returned if the user tries to create a UPS account with this function. func (c *Client) CreateCarrierAccount(in *CarrierAccount) (out *CarrierAccount, err error) { return c.CreateCarrierAccountWithContext(context.Background(), in) } -// CreateCarrierAccountWithContext performs the same operation as -// CreateCarrierAccount, but allows specifying a context that can interrupt the -// request. +// CreateCarrierAccountWithContext performs the same operation as CreateCarrierAccount, but allows specifying a context that can interrupt the request. +// Users cannot create UPS accounts with this function, must use CreateUpsCarrierAccount. An error will be returned if the user tries to create a UPS account with this function. func (c *Client) CreateCarrierAccountWithContext(ctx context.Context, in *CarrierAccount) (out *CarrierAccount, err error) { - req := &carrierAccountRequest{CarrierAccount: in} - endpoint := c.selectCarrierAccountCreationEndpoint(*in) + // Users cannot create UPS accounts with this function, must use CreateUpsCarrierAccount + for _, carrier := range getUpsCarrierAccountTypes() { + if in.Type == carrier { + return nil, newInvalidFunctionError("users must use CreateUpsCarrierAccount to create UPS accounts") + } + } + + req := &carrierAccountRequest{Data: in} + endpoint := c.selectCarrierAccountCreationEndpoint(in.Type) err = c.post(ctx, endpoint, req, &out) return } -// ListCarrierAccounts returns a list of all carrier accounts available to the -// authenticated account. +// CreateUpsCarrierAccount creates a new UPS carrier account. It can only be used with a production API key. +// Users cannot create non-UPS accounts with this function, must use CreateCarrierAccount. An error will be returned if the user tries to create a non-UPS account with this function. +func (c *Client) CreateUpsCarrierAccount(in *UpsCarrierAccountCreationParameters) (out *CarrierAccount, err error) { + return c.CreateUpsCarrierAccountWithContext(context.Background(), in) +} + +// CreateUpsCarrierAccountWithContext performs the same operation as CreateUpsCarrierAccount, but allows specifying a context that can interrupt the request. +// Users cannot create non-UPS accounts with this function, must use CreateCarrierAccount. An error will be returned if the user tries to create a non-UPS account with this function. +func (c *Client) CreateUpsCarrierAccountWithContext(ctx context.Context, in *UpsCarrierAccountCreationParameters) (out *CarrierAccount, err error) { + // Users cannot create non-UPS accounts with this function, must use CreateCarrierAccount + isUpsAccount := false + for _, carrier := range getUpsCarrierAccountTypes() { + if in.Type == carrier { + isUpsAccount = true + break + } + } + if !isUpsAccount { + return nil, newInvalidFunctionError("users must use CreateCarrierAccount to create non-UPS accounts") + } + + req := &upsCarrierAccountCreationRequest{Data: in} + err = c.post(ctx, "ups_oauth_registrations", req, &out) + return +} + +// ListCarrierAccounts returns a list of all carrier accounts available to the authenticated account. func (c *Client) ListCarrierAccounts() (out []*CarrierAccount, err error) { return c.ListCarrierAccountsWithContext(context.Background()) } -// ListCarrierAccountsWithContext performs the same operation as -// ListCarrierAccounts, but allows specifying a context that can interrupt the -// request. +// ListCarrierAccountsWithContext performs the same operation as ListCarrierAccounts, but allows specifying a context that can interrupt the request. func (c *Client) ListCarrierAccountsWithContext(ctx context.Context) (out []*CarrierAccount, err error) { err = c.get(ctx, "carrier_accounts", &out) return @@ -125,16 +178,13 @@ func (c *Client) GetCarrierAccount(carrierAccountID string) (out *CarrierAccount return c.GetCarrierAccountWithContext(context.Background(), carrierAccountID) } -// GetCarrierAccountWithContext performs the same operation as -// GetCarrierAccount, but allows specifying a context that can interrupt the -// request. +// GetCarrierAccountWithContext performs the same operation as GetCarrierAccount, but allows specifying a context that can interrupt the request. func (c *Client) GetCarrierAccountWithContext(ctx context.Context, carrierAccountID string) (out *CarrierAccount, err error) { err = c.get(ctx, "carrier_accounts/"+carrierAccountID, &out) return } -// UpdateCarrierAccount updates the carrier account. Only the Description, -// Reference, Credentials and TestCredentials attributes can be updated. +// UpdateCarrierAccount updates the carrier account. Only the Description, Reference, Credentials and TestCredentials attributes can be updated. // // c := easypost.New(MyEasyPostAPIKey) // out, err := c.UpdateCarrierAccount( @@ -146,27 +196,70 @@ func (c *Client) GetCarrierAccountWithContext(ctx context.Context, carrierAccoun // }, // }, // ) +// +// Users cannot update UPS accounts with this function, must use UpdateUpsCarrierAccount. An error will be returned if the user tries to update a UPS account with this function. func (c *Client) UpdateCarrierAccount(in *CarrierAccount) (out *CarrierAccount, err error) { return c.UpdateCarrierAccountWithContext(context.Background(), in) } -// UpdateCarrierAccountWithContext performs the same operation as -// UpdateCarrierAccount, but allows specifying a context that can interrupt the -// request. +// UpdateCarrierAccountWithContext performs the same operation as UpdateCarrierAccount, but allows specifying a context that can interrupt the request. +// Users cannot update UPS accounts with this function, must use UpdateUpsCarrierAccount. An error will be returned if the user tries to update a UPS account with this function. func (c *Client) UpdateCarrierAccountWithContext(ctx context.Context, in *CarrierAccount) (out *CarrierAccount, err error) { - req := &carrierAccountRequest{CarrierAccount: in} + account, err := c.GetCarrierAccount(in.ID) + if err != nil { + return nil, err + } + + // Users cannot update UPS accounts with this function, must use UpdateUpsCarrierAccount + for _, carrier := range getUpsCarrierAccountTypes() { + if account.Type == carrier { + return nil, newInvalidFunctionError("users must use UpdateUpsCarrierAccount to update UPS accounts") + } + } + + req := &carrierAccountRequest{Data: in} err = c.patch(ctx, "carrier_accounts/"+in.ID, req, &out) return } +// UpdateUpsCarrierAccount updates a UPS carrier account. +// Users cannot update non-UPS accounts with this function, must use UpdateCarrierAccount. An error will be returned if the user tries to update a non-UPS account with this function. +func (c *Client) UpdateUpsCarrierAccount(id string, in *UpsCarrierAccountUpdateParameters) (out *CarrierAccount, err error) { + return c.UpdateUpsCarrierAccountWithContext(context.Background(), id, in) +} + +// UpdateUpsCarrierAccountWithContext performs the same operation as UpdateUpsCarrierAccount, but allows specifying a context that can interrupt the request. +// Users cannot update non-UPS accounts with this function, must use UpdateCarrierAccount. An error will be returned if the user tries to update a non-UPS account with this function. +func (c *Client) UpdateUpsCarrierAccountWithContext(ctx context.Context, id string, in *UpsCarrierAccountUpdateParameters) (out *CarrierAccount, err error) { + account, err := c.GetCarrierAccount(id) + if err != nil { + return nil, err + } + + // Users cannot update non-UPS accounts with this function, must use UpdateCarrierAccount + isUpsAccount := false + for _, carrier := range getUpsCarrierAccountTypes() { + if account.Type == carrier { + isUpsAccount = true + break + } + } + if !isUpsAccount { + return nil, newInvalidFunctionError("users must use UpdateCarrierAccount to update non-UPS accounts") + } + + req := &upsCarrierAccountUpdateRequest{Data: in} + err = c.patch(ctx, "ups_oauth_registrations/"+id, req, &out) + return + +} + // DeleteCarrierAccount removes the carrier account with the given ID. func (c *Client) DeleteCarrierAccount(carrierAccountID string) error { return c.DeleteCarrierAccountWithContext(context.Background(), carrierAccountID) } -// DeleteCarrierAccountWithContext performs the same operation as -// DeleteCarrierAccount, but allows specifying a context that can interrupt the -// request. +// DeleteCarrierAccountWithContext performs the same operation as DeleteCarrierAccount, but allows specifying a context that can interrupt the request. func (c *Client) DeleteCarrierAccountWithContext(ctx context.Context, carrierAccountID string) error { return c.del(ctx, "carrier_accounts/"+carrierAccountID) } diff --git a/constants.go b/constants.go index a2ce18c..91f089c 100644 --- a/constants.go +++ b/constants.go @@ -1,7 +1,11 @@ package easypost func getCarrierAccountTypesWithCustomWorkflows() []string { - return []string{"FedexAccount", "UpsAccount", "FedexSmartpostAccount"} + return []string{"FedexAccount", "FedexSmartpostAccount"} +} + +func getUpsCarrierAccountTypes() []string { + return []string{"UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount"} } var ApiDidNotReturnErrorDetails = "API did not return error details" diff --git a/error.go b/error.go index af1672d..aee40a0 100644 --- a/error.go +++ b/error.go @@ -144,6 +144,16 @@ func newExternalApiError(message string) *ExternalApiError { return &ExternalApiError{LibraryError{Message: message}} } +// InvalidFunctionError is raised when a function call is invalid or not allowed. +type InvalidFunctionError struct { + LocalError +} + +// newInvalidFunctionError returns a new InvalidFunctionError object with the given message. +func newInvalidFunctionError(message string) *InvalidFunctionError { + return &InvalidFunctionError{LocalError{LibraryError{Message: message}}} +} + // API/HTTP error types // APIError represents an error that occurred while communicating with the EasyPost API. diff --git a/tests/carrier_account_test.go b/tests/carrier_account_test.go index ea51fd1..3889794 100644 --- a/tests/carrier_account_test.go +++ b/tests/carrier_account_test.go @@ -30,19 +30,18 @@ func (c *ClientTests) TestCarrierAccountCreate() { require.NoError(err) } -func (c *ClientTests) TestCarrierAccountCreateWithCustomWorkflow() { - assert, require := c.Assert(), c.Require() - +func (c *ClientTests) TestCarrierAccountCreateWithCustomWorkflow() { // FedExAccount client := c.ProdClient() + assert, require := c.Assert(), c.Require() - carrierAccount := c.fixture.BasicCarrierAccount() - carrierAccount.Type = "FedexAccount" + createParameters := c.fixture.BasicCarrierAccount() + createParameters.Type = "FedexAccount" // we need to include data in this interface, otherwise it will be omitted during the API call - carrierAccount.RegistrationData = map[string]interface{}{ + createParameters.RegistrationData = map[string]interface{}{ "some": "data", } - _, err := client.CreateCarrierAccount(carrierAccount) + _, err := client.CreateCarrierAccount(createParameters) // We're sending bad data to the API, so we expect an error require.Error(err) @@ -61,6 +60,54 @@ func (c *ClientTests) TestCarrierAccountCreateWithCustomWorkflow() { assert.True(errorFound) } +func (c *ClientTests) TestCarrierAccountPreventUsersUsingUpsAccountForGenericCreation() { + client := c.ProdClient() + assert, require := c.Assert(), c.Require() + + createParameters := c.fixture.BasicCarrierAccount() + createParameters.Type = "UpsAccount" + + _, err := client.CreateCarrierAccount(createParameters) + require.Error(err) + + assert.Equal(reflect.TypeOf(&easypost.InvalidFunctionError{}), reflect.TypeOf(err)) +} + +func (c *ClientTests) TestCarrierAccountCreateUps() { + client := c.ProdClient() + assert, require := c.Assert(), c.Require() + + createParameters := &easypost.UpsCarrierAccountCreationParameters{ + AccountNumber: "123456789", + Type: "UpsAccount", + } + + carrierAccount, err := client.CreateUpsCarrierAccount(createParameters) + require.NoError(err) + + assert.Equal(reflect.TypeOf(&easypost.CarrierAccount{}), reflect.TypeOf(carrierAccount)) + assert.True(strings.HasPrefix(carrierAccount.ID, "ca_")) + assert.Equal("UpsAccount", carrierAccount.Type) + + err = client.DeleteCarrierAccount(carrierAccount.ID) + require.NoError(err) +} + +func (c *ClientTests) TestCarrierAccountPreventUsersUsingNotUpsAccountForUpsCreation() { + client := c.ProdClient() + assert, require := c.Assert(), c.Require() + + createParameters := &easypost.UpsCarrierAccountCreationParameters{ + AccountNumber: "123456789", + Type: "NotUpsAccount", + } + + _, err := client.CreateUpsCarrierAccount(createParameters) + require.Error(err) + + assert.Equal(reflect.TypeOf(&easypost.InvalidFunctionError{}), reflect.TypeOf(err)) +} + func (c *ClientTests) TestCarrierAccountRetrieve() { client := c.ProdClient() assert, require := c.Assert(), c.Require() @@ -99,14 +146,12 @@ func (c *ClientTests) TestCarrierAccountUpdate() { carrierAccount, err := c.GenerateCarrierAccount() require.NoError(err) - carrierAccount.Description = testDescription + updateParameters := &easypost.CarrierAccount{ + ID: carrierAccount.ID, + Description: testDescription, + } - updatedCarrierAccount, err := client.UpdateCarrierAccount( - &easypost.CarrierAccount{ - ID: carrierAccount.ID, - Description: testDescription, - }, - ) + updatedCarrierAccount, err := client.UpdateCarrierAccount(updateParameters) require.NoError(err) assert.Equal(reflect.TypeOf(&easypost.CarrierAccount{}), reflect.TypeOf(updatedCarrierAccount)) @@ -117,6 +162,91 @@ func (c *ClientTests) TestCarrierAccountUpdate() { require.NoError(err) } +func (c *ClientTests) TestCarrierAccountPreventUsersUsingUpsAccountForGenericUpdate() { + id := "ca_123" + + mockRequests := []easypost.MockRequest{ + { + MatchRule: easypost.MockRequestMatchRule{ + Method: "GET", + UrlRegexPattern: "v2\\/carrier_accounts/" + id + "$", + }, + ResponseInfo: easypost.MockRequestResponseInfo{ + StatusCode: 200, + Body: `{"id": "` + id + `", "type": "UpsAccount"}`, + }, + }, + } + + client := c.MockClient(mockRequests) + assert, require := c.Assert(), c.Require() + + updateParameters := &easypost.CarrierAccount{ + ID: id, + Description: "My custom description", + } + + _, err := client.UpdateCarrierAccount(updateParameters) + require.Error(err) + + assert.Equal(reflect.TypeOf(&easypost.InvalidFunctionError{}), reflect.TypeOf(err)) +} + +func (c *ClientTests) TestCarrierAccountUpdateUps() { + client := c.ProdClient() + assert, require := c.Assert(), c.Require() + + createParameters := &easypost.UpsCarrierAccountCreationParameters{ + AccountNumber: "123456789", + Type: "UpsAccount", + } + + carrierAccount, err := client.CreateUpsCarrierAccount(createParameters) + require.NoError(err) + + updateParameters := &easypost.UpsCarrierAccountUpdateParameters{ + AccountNumber: "987654321", + } + + updatedCarrierAccount, err := client.UpdateUpsCarrierAccount(carrierAccount.ID, updateParameters) + require.NoError(err) + + assert.Equal(reflect.TypeOf(&easypost.CarrierAccount{}), reflect.TypeOf(updatedCarrierAccount)) + assert.True(strings.HasPrefix(updatedCarrierAccount.ID, "ca_")) + + err = client.DeleteCarrierAccount(carrierAccount.ID) + require.NoError(err) +} + +func (c *ClientTests) TestCarrierAccountPreventUsersUsingNotUpsAccountForUpsUpdate() { + id := "ca_123" + + mockRequests := []easypost.MockRequest{ + { + MatchRule: easypost.MockRequestMatchRule{ + Method: "GET", + UrlRegexPattern: "v2\\/carrier_accounts/" + id + "$", + }, + ResponseInfo: easypost.MockRequestResponseInfo{ + StatusCode: 200, + Body: `{"id": "` + id + `", "type": "NotUpsAccount"}`, + }, + }, + } + + client := c.MockClient(mockRequests) + assert, require := c.Assert(), c.Require() + + updateParameters := &easypost.UpsCarrierAccountUpdateParameters{ + AccountNumber: "987654321", + } + + _, err := client.UpdateUpsCarrierAccount(id, updateParameters) + require.Error(err) + + assert.Equal(reflect.TypeOf(&easypost.InvalidFunctionError{}), reflect.TypeOf(err)) +} + func (c *ClientTests) TestCarrierAccountDelete() { client := c.ProdClient() require := c.Require() diff --git a/tests/cassettes/TestCarrierAccountCreate.yaml b/tests/cassettes/TestCarrierAccountCreate.yaml index b75b5a7..fd0c560 100644 --- a/tests/cassettes/TestCarrierAccountCreate.yaml +++ b/tests/cassettes/TestCarrierAccountCreate.yaml @@ -14,9 +14,9 @@ interactions: url: https://api.easypost.com/v2/carrier_accounts method: POST response: - body: '{"billing_type":"carrier","clone":false,"created_at":"2023-11-30T20:10:40Z","credentials":{},"description":"DHL - eCommerce Solutions Account","fields":{},"id":"ca_f822821a937244a6b455357dfb5cced5","logo":null,"object":"CarrierAccount","readable":"DHL - eCommerce Solutions","reference":null,"test_credentials":{},"type":"DhlEcsAccount","updated_at":"2023-11-30T20:10:40Z"}' + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:08Z","credentials":{},"description":"DHL + eCommerce Solutions Account","fields":{},"id":"ca_94291c154236418183431f8e0a6396f1","logo":null,"object":"CarrierAccount","readable":"DHL + eCommerce Solutions","reference":null,"test_credentials":{},"type":"DhlEcsAccount","updated_at":"2024-07-10T23:00:08Z"}' headers: Cache-Control: - private, no-cache, no-store @@ -37,20 +37,20 @@ interactions: X-Download-Options: - noopen X-Ep-Request-Uuid: - - 32e015fa6568ec40e7896122001b4a40 + - 35d2ed5f668f1278f41b62e9003cbc05 X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb33nuq + - bigweb36nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb1nuq b3de2c47ef - - extlb1nuq 003ad9bca0 + - intlb4nuq fa152d4755 + - extlb2nuq fa152d4755 X-Runtime: - - "0.111035" + - "0.070008" X-Version-Label: - - easypost-202311301748-2efb918c5f-master + - easypost-202407102141-c1077ec6f9-master X-Xss-Protection: - 1; mode=block status: 201 Created @@ -64,7 +64,7 @@ interactions: - REDACTED User-Agent: - REDACTED - url: https://api.easypost.com/v2/carrier_accounts/ca_f822821a937244a6b455357dfb5cced5 + url: https://api.easypost.com/v2/carrier_accounts/ca_94291c154236418183431f8e0a6396f1 method: DELETE response: body: '{}' @@ -83,25 +83,27 @@ interactions: - max-age=31536000; includeSubDomains; preload X-Backend: - easypost + X-Canary: + - direct X-Content-Type-Options: - nosniff X-Download-Options: - noopen X-Ep-Request-Uuid: - - 32e015fa6568ec40e7896122001b4a7b + - 35d2ed5f668f1278f41b62e9003cbc29 X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb40nuq + - bigweb32nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb2nuq b3de2c47ef - - extlb1nuq 003ad9bca0 + - intlb4nuq fa152d4755 + - extlb2nuq fa152d4755 X-Runtime: - - "0.119608" + - "0.064514" X-Version-Label: - - easypost-202311301748-2efb918c5f-master + - easypost-202407102141-c1077ec6f9-master X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/tests/cassettes/TestCarrierAccountCreateUps.yaml b/tests/cassettes/TestCarrierAccountCreateUps.yaml new file mode 100644 index 0000000..5f651fa --- /dev/null +++ b/tests/cassettes/TestCarrierAccountCreateUps.yaml @@ -0,0 +1,107 @@ +--- +version: 1 +interactions: +- request: + body: '{"ups_oauth_registrations":{"account_number":"123456789","type":"UpsAccount"}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/ups_oauth_registrations + method: POST + response: + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:08Z","credentials":{},"description":null,"fields":{},"id":"ca_5462da65bdb34ab4ac7c607703c9ecf4","logo":null,"object":"CarrierAccount","readable":"UPS","reference":null,"test_credentials":null,"type":"UpsAccount","updated_at":"2024-07-10T23:00:08Z"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 35d2ed5f668f1278f41b62e9003cbc51 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb42nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq fa152d4755 + - extlb2nuq fa152d4755 + X-Runtime: + - "0.220166" + X-Version-Label: + - easypost-202407102141-c1077ec6f9-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" +- request: + body: "" + form: {} + headers: + Authorization: + - REDACTED + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/carrier_accounts/ca_5462da65bdb34ab4ac7c607703c9ecf4 + method: DELETE + response: + body: '{}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 35d2ed5f668f1278f41b62e9003cbcb8 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb39nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb3nuq fa152d4755 + - extlb2nuq fa152d4755 + X-Runtime: + - "0.060721" + X-Version-Label: + - easypost-202407102141-c1077ec6f9-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/tests/cassettes/TestCarrierAccountCreateWithCustomWorkflow.yaml b/tests/cassettes/TestCarrierAccountCreateWithCustomWorkflow.yaml index d77300b..8178805 100644 --- a/tests/cassettes/TestCarrierAccountCreateWithCustomWorkflow.yaml +++ b/tests/cassettes/TestCarrierAccountCreateWithCustomWorkflow.yaml @@ -49,20 +49,20 @@ interactions: X-Download-Options: - noopen X-Ep-Request-Uuid: - - 32e015fa6568ec41e7896122001b4abb + - 35d2ed5f668f1278f41b62e9003cbcd8 X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb42nuq + - bigweb39nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb2nuq b3de2c47ef - - extlb1nuq 003ad9bca0 + - intlb3nuq fa152d4755 + - extlb2nuq fa152d4755 X-Runtime: - - "0.149074" + - "0.044392" X-Version-Label: - - easypost-202311301748-2efb918c5f-master + - easypost-202407102141-c1077ec6f9-master X-Xss-Protection: - 1; mode=block status: 422 Unprocessable Entity diff --git a/tests/cassettes/TestCarrierAccountUpdate.yaml b/tests/cassettes/TestCarrierAccountUpdate.yaml index cc2e24a..3e2db38 100644 --- a/tests/cassettes/TestCarrierAccountUpdate.yaml +++ b/tests/cassettes/TestCarrierAccountUpdate.yaml @@ -14,9 +14,9 @@ interactions: url: https://api.easypost.com/v2/carrier_accounts method: POST response: - body: '{"billing_type":"carrier","clone":false,"created_at":"2023-11-30T20:10:43Z","credentials":{},"description":"DHL - eCommerce Solutions Account","fields":{},"id":"ca_b7c16c4c3e93437dbb18a6c3c41e2c80","logo":null,"object":"CarrierAccount","readable":"DHL - eCommerce Solutions","reference":null,"test_credentials":{},"type":"DhlEcsAccount","updated_at":"2023-11-30T20:10:43Z"}' + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:09Z","credentials":{},"description":"DHL + eCommerce Solutions Account","fields":{},"id":"ca_1e440e0201754527b0c19d3ccbbb5c1e","logo":null,"object":"CarrierAccount","readable":"DHL + eCommerce Solutions","reference":null,"test_credentials":{},"type":"DhlEcsAccount","updated_at":"2024-07-10T23:00:09Z"}' headers: Cache-Control: - private, no-cache, no-store @@ -37,27 +37,80 @@ interactions: X-Download-Options: - noopen X-Ep-Request-Uuid: - - 32e015fa6568ec43e7896122001b4ca8 + - 35d2ed5f668f1278f41b62e9003cbcef X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb40nuq + - bigweb33nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb1nuq b3de2c47ef - - extlb1nuq 003ad9bca0 + - intlb4nuq fa152d4755 + - extlb2nuq fa152d4755 X-Runtime: - - "0.121038" + - "0.079382" X-Version-Label: - - easypost-202311301748-2efb918c5f-master + - easypost-202407102141-c1077ec6f9-master X-Xss-Protection: - 1; mode=block status: 201 Created code: 201 duration: "" - request: - body: '{"carrier_account":{"description":"My custom description","id":"ca_b7c16c4c3e93437dbb18a6c3c41e2c80"}}' + body: "" + form: {} + headers: + Authorization: + - REDACTED + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/carrier_accounts/ca_1e440e0201754527b0c19d3ccbbb5c1e + method: GET + response: + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:09Z","credentials":{},"description":"DHL + eCommerce Solutions Account","fields":{},"id":"ca_1e440e0201754527b0c19d3ccbbb5c1e","logo":null,"object":"CarrierAccount","readable":"DHL + eCommerce Solutions","reference":null,"test_credentials":{},"type":"DhlEcsAccount","updated_at":"2024-07-10T23:00:09Z"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 35d2ed5f668f1279f41b62e9003cbd0e + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb34nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb3nuq fa152d4755 + - extlb2nuq fa152d4755 + X-Runtime: + - "0.042087" + X-Version-Label: + - easypost-202407102141-c1077ec6f9-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"carrier_account":{"description":"My custom description","id":"ca_1e440e0201754527b0c19d3ccbbb5c1e"}}' form: {} headers: Authorization: @@ -66,12 +119,12 @@ interactions: - application/json User-Agent: - REDACTED - url: https://api.easypost.com/v2/carrier_accounts/ca_b7c16c4c3e93437dbb18a6c3c41e2c80 + url: https://api.easypost.com/v2/carrier_accounts/ca_1e440e0201754527b0c19d3ccbbb5c1e method: PATCH response: - body: '{"billing_type":"carrier","clone":false,"created_at":"2023-11-30T20:10:43Z","credentials":{},"description":"My - custom description","fields":{},"id":"ca_b7c16c4c3e93437dbb18a6c3c41e2c80","logo":null,"object":"CarrierAccount","readable":"DHL - eCommerce Solutions","reference":null,"test_credentials":{},"type":"DhlEcsAccount","updated_at":"2023-11-30T20:10:43Z"}' + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:09Z","credentials":{},"description":"My + custom description","fields":{},"id":"ca_1e440e0201754527b0c19d3ccbbb5c1e","logo":null,"object":"CarrierAccount","readable":"DHL + eCommerce Solutions","reference":null,"test_credentials":{},"type":"DhlEcsAccount","updated_at":"2024-07-10T23:00:09Z"}' headers: Cache-Control: - private, no-cache, no-store @@ -92,20 +145,20 @@ interactions: X-Download-Options: - noopen X-Ep-Request-Uuid: - - 32e015fa6568ec43e7896122001b4cdb + - 35d2ed5f668f1279f41b62e9003cbd2a X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb36nuq + - bigweb35nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb1nuq b3de2c47ef - - extlb1nuq 003ad9bca0 + - intlb3nuq fa152d4755 + - extlb2nuq fa152d4755 X-Runtime: - - "0.307089" + - "0.094039" X-Version-Label: - - easypost-202311301748-2efb918c5f-master + - easypost-202407102141-c1077ec6f9-master X-Xss-Protection: - 1; mode=block status: 200 OK @@ -119,7 +172,7 @@ interactions: - REDACTED User-Agent: - REDACTED - url: https://api.easypost.com/v2/carrier_accounts/ca_b7c16c4c3e93437dbb18a6c3c41e2c80 + url: https://api.easypost.com/v2/carrier_accounts/ca_1e440e0201754527b0c19d3ccbbb5c1e method: DELETE response: body: '{}' @@ -143,20 +196,20 @@ interactions: X-Download-Options: - noopen X-Ep-Request-Uuid: - - 32e015fa6568ec43e7896122001b4d3d + - 35d2ed5f668f1279f41b62e9003cbd56 X-Frame-Options: - SAMEORIGIN X-Node: - - bigweb38nuq + - bigweb39nuq X-Permitted-Cross-Domain-Policies: - none X-Proxied: - - intlb2nuq b3de2c47ef - - extlb1nuq 003ad9bca0 + - intlb3nuq fa152d4755 + - extlb2nuq fa152d4755 X-Runtime: - - "0.120274" + - "0.062216" X-Version-Label: - - easypost-202311301748-2efb918c5f-master + - easypost-202407102141-c1077ec6f9-master X-Xss-Protection: - 1; mode=block status: 200 OK diff --git a/tests/cassettes/TestCarrierAccountUpdateUps.yaml b/tests/cassettes/TestCarrierAccountUpdateUps.yaml new file mode 100644 index 0000000..05c2e06 --- /dev/null +++ b/tests/cassettes/TestCarrierAccountUpdateUps.yaml @@ -0,0 +1,215 @@ +--- +version: 1 +interactions: +- request: + body: '{"ups_oauth_registrations":{"account_number":"123456789","type":"UpsAccount"}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/ups_oauth_registrations + method: POST + response: + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:09Z","credentials":{},"description":null,"fields":{},"id":"ca_3f3a30eaca1a49fa9360967184448e00","logo":null,"object":"CarrierAccount","readable":"UPS","reference":null,"test_credentials":null,"type":"UpsAccount","updated_at":"2024-07-10T23:00:09Z"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 35d2ed5f668f1279f41b62e9003cbd75 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb39nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq fa152d4755 + - extlb2nuq fa152d4755 + X-Runtime: + - "0.093533" + X-Version-Label: + - easypost-202407102141-c1077ec6f9-master + X-Xss-Protection: + - 1; mode=block + status: 201 Created + code: 201 + duration: "" +- request: + body: "" + form: {} + headers: + Authorization: + - REDACTED + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/carrier_accounts/ca_3f3a30eaca1a49fa9360967184448e00 + method: GET + response: + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:09Z","credentials":{},"description":null,"fields":{},"id":"ca_3f3a30eaca1a49fa9360967184448e00","logo":null,"object":"CarrierAccount","readable":"UPS","reference":null,"test_credentials":null,"type":"UpsAccount","updated_at":"2024-07-10T23:00:09Z"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 35d2ed5f668f1279f41b62e9003cbda0 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb39nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb3nuq fa152d4755 + - extlb2nuq fa152d4755 + X-Runtime: + - "0.043407" + X-Version-Label: + - easypost-202407102141-c1077ec6f9-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"ups_oauth_registrations":{"account_number":"987654321"}}' + form: {} + headers: + Authorization: + - REDACTED + Content-Type: + - application/json + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/ups_oauth_registrations/ca_3f3a30eaca1a49fa9360967184448e00 + method: PATCH + response: + body: '{"billing_type":"carrier","clone":false,"created_at":"2024-07-10T23:00:09Z","credentials":{},"description":null,"fields":{},"id":"ca_3f3a30eaca1a49fa9360967184448e00","logo":null,"object":"CarrierAccount","readable":"UPS","reference":null,"test_credentials":null,"type":"UpsAccount","updated_at":"2024-07-10T23:00:09Z"}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Canary: + - direct + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 35d2ed5f668f1279f41b62e9003cbdc1 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb32nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq fa152d4755 + - extlb2nuq fa152d4755 + X-Runtime: + - "0.074505" + X-Version-Label: + - easypost-202407102141-c1077ec6f9-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Authorization: + - REDACTED + User-Agent: + - REDACTED + url: https://api.easypost.com/v2/carrier_accounts/ca_3f3a30eaca1a49fa9360967184448e00 + method: DELETE + response: + body: '{}' + headers: + Cache-Control: + - private, no-cache, no-store + Content-Type: + - application/json; charset=utf-8 + Expires: + - "0" + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + X-Backend: + - easypost + X-Canary: + - direct + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Ep-Request-Uuid: + - 35d2ed5f668f1279f41b62e9003cbde7 + X-Frame-Options: + - SAMEORIGIN + X-Node: + - bigweb43nuq + X-Permitted-Cross-Domain-Policies: + - none + X-Proxied: + - intlb4nuq fa152d4755 + - extlb2nuq fa152d4755 + X-Runtime: + - "0.062747" + X-Version-Label: + - easypost-202407102141-c1077ec6f9-master + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: ""