diff --git a/catalog.go b/catalog.go index 96e18db..6505909 100644 --- a/catalog.go +++ b/catalog.go @@ -180,8 +180,7 @@ type SearchCatalogObjectsRequest struct { // ITEM_OPTION_VAL, ITEM_VARIATION, or MODIFIER), you must explicitly include all the types of interest // in this field. ObjectTypes []CatalogObjectType `json:"object_types,omitempty" url:"-"` - // If `true`, deleted objects will be included in the results. Deleted objects will have their - // `is_deleted` field set to `true`. + // If `true`, deleted objects will be included in the results. Defaults to `false`. Deleted objects will have their `is_deleted` field set to `true`. If `include_deleted_objects` is `true`, then the `include_category_path_to_root` request parameter must be `false`. Both properties cannot be `true` at the same time. IncludeDeletedObjects *bool `json:"include_deleted_objects,omitempty" url:"-"` // If `true`, the response will include additional objects that are related to the // requested objects. Related objects are objects that are referenced by object ID by the objects @@ -208,10 +207,7 @@ type SearchCatalogObjectsRequest struct { // the implementation may return more or fewer results. If the supplied limit is negative, zero, or // is higher than the maximum limit of 1,000, it will be ignored. Limit *int `json:"limit,omitempty" url:"-"` - // Specifies whether or not to include the `path_to_root` list for each returned category instance. The `path_to_root` list consists - // of `CategoryPathToRootNode` objects and specifies the path that starts with the immediate parent category of the returned category - // and ends with its root category. If the returned category is a top-level category, the `path_to_root` list is empty and is not returned - // in the response payload. + // Specifies whether or not to include the `path_to_root` list for each returned category instance. The `path_to_root` list consists of `CategoryPathToRootNode` objects and specifies the path that starts with the immediate parent category of the returned category and ends with its root category. If the returned category is a top-level category, the `path_to_root` list is empty and is not returned in the response payload. If `include_category_path_to_root` is `true`, then the `include_deleted_objects` request parameter must be `false`. Both properties cannot be `true` at the same time. IncludeCategoryPathToRoot *bool `json:"include_category_path_to_root,omitempty" url:"-"` } diff --git a/client/client.go b/client/client.go index 9a7073f..ebcdc16 100644 --- a/client/client.go +++ b/client/client.go @@ -65,7 +65,6 @@ type Client struct { GiftCards *giftcardsclient.Client Inventory *inventory.Client Invoices *invoices.Client - Labor *laborclient.Client Locations *locationsclient.Client Loyalty *loyaltyclient.Client Merchants *merchantsclient.Client @@ -82,6 +81,7 @@ type Client struct { Terminal *terminalclient.Client Vendors *vendors.Client CashDrawers *cashdrawersclient.Client + Labor *laborclient.Client Webhooks *webhooksclient.Client } @@ -118,7 +118,6 @@ func NewClient(opts ...option.RequestOption) *Client { GiftCards: giftcardsclient.NewClient(opts...), Inventory: inventory.NewClient(opts...), Invoices: invoices.NewClient(opts...), - Labor: laborclient.NewClient(opts...), Locations: locationsclient.NewClient(opts...), Loyalty: loyaltyclient.NewClient(opts...), Merchants: merchantsclient.NewClient(opts...), @@ -135,6 +134,7 @@ func NewClient(opts ...option.RequestOption) *Client { Terminal: terminalclient.NewClient(opts...), Vendors: vendors.NewClient(opts...), CashDrawers: cashdrawersclient.NewClient(opts...), + Labor: laborclient.NewClient(opts...), Webhooks: webhooksclient.NewClient(opts...), } } diff --git a/core/request_option.go b/core/request_option.go index 69ccc70..30c5572 100644 --- a/core/request_option.go +++ b/core/request_option.go @@ -52,7 +52,7 @@ func (r *RequestOptions) ToHeader() http.Header { if r.Token != "" { header.Set("Authorization", "Bearer "+r.Token) } - version := fmt.Sprintf("%v", "2024-11-20") + version := fmt.Sprintf("%v", "2025-01-23") if envValue := os.Getenv("VERSION"); envValue != "" { version = envValue } @@ -64,8 +64,8 @@ func (r *RequestOptions) cloneHeader() http.Header { headers := r.HTTPHeader.Clone() headers.Set("X-Fern-Language", "Go") headers.Set("X-Fern-SDK-Name", "github.com/square/square-go-sdk") - headers.Set("X-Fern-SDK-Version", "v1.0.1") - headers.Set("User-Agent", "github.com/square/square-go-sdk/1.0.1") + headers.Set("X-Fern-SDK-Version", "v1.1.0") + headers.Set("User-Agent", "github.com/square/square-go-sdk/1.1.0") return headers } diff --git a/customers.go b/customers.go index 7594dd6..4ea4aef 100644 --- a/customers.go +++ b/customers.go @@ -8,16 +8,6 @@ import ( internal "github.com/square/square-go-sdk/internal" ) -type BulkCreateCustomersRequest struct { - // A map of 1 to 100 individual create requests, represented by `idempotency key: { customer data }` - // key-value pairs. - // - // Each key is an [idempotency key](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency) - // that uniquely identifies the create request. Each value contains the customer data used to create the - // customer profile. - Customers map[string]*BulkCreateCustomerData `json:"customers,omitempty" url:"-"` -} - type BulkDeleteCustomersRequest struct { // The IDs of the [customer profiles](entity:Customer) to delete. CustomerIDs []string `json:"customer_ids,omitempty" url:"-"` @@ -40,6 +30,16 @@ type BulkUpdateCustomersRequest struct { Customers map[string]*BulkUpdateCustomerData `json:"customers,omitempty" url:"-"` } +type BulkCreateCustomersRequest struct { + // A map of 1 to 100 individual create requests, represented by `idempotency key: { customer data }` + // key-value pairs. + // + // Each key is an [idempotency key](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency) + // that uniquely identifies the create request. Each value contains the customer data used to create the + // customer profile. + Customers map[string]*BulkCreateCustomerData `json:"customers,omitempty" url:"-"` +} + type CreateCustomerRequest struct { // The idempotency key for the request. For more information, see // [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency). @@ -788,12 +788,6 @@ type Customer struct { CreatedAt *string `json:"created_at,omitempty" url:"created_at,omitempty"` // The timestamp when the customer profile was last updated, in RFC 3339 format. UpdatedAt *string `json:"updated_at,omitempty" url:"updated_at,omitempty"` - // Payment details of the credit, debit, and gift cards stored on file for the customer profile. - // - // DEPRECATED at version 2021-06-16 and will be RETIRED at version 2024-12-18. Replaced by calling [ListCards](api-endpoint:Cards-ListCards) (for credit and debit cards on file) - // or [ListGiftCards](api-endpoint:GiftCards-ListGiftCards) (for gift cards on file) and including the `customer_id` query parameter. - // For more information, see [Migration notes](https://developer.squareup.com/docs/customers-api/what-it-does#migrate-customer-cards). - Cards []*Card `json:"cards,omitempty" url:"cards,omitempty"` // The given name (that is, the first name) associated with the customer profile. GivenName *string `json:"given_name,omitempty" url:"given_name,omitempty"` // The family name (that is, the last name) associated with the customer profile. @@ -825,7 +819,7 @@ type Customer struct { GroupIDs []string `json:"group_ids,omitempty" url:"group_ids,omitempty"` // The IDs of [customer segments](entity:CustomerSegment) the customer belongs to. SegmentIDs []string `json:"segment_ids,omitempty" url:"segment_ids,omitempty"` - // The Square-assigned version number of the customer profile. The version number is incremented each time an update is committed to the customer profile, except for changes to customer segment membership and cards on file. + // The Square-assigned version number of the customer profile. The version number is incremented each time an update is committed to the customer profile, except for changes to customer segment membership. Version *int64 `json:"version,omitempty" url:"version,omitempty"` // The tax ID associated with the customer profile. This field is present only for customers of sellers in EU countries or the United Kingdom. // For more information, see [Customer tax IDs](https://developer.squareup.com/docs/customers-api/what-it-does#customer-tax-ids). @@ -856,13 +850,6 @@ func (c *Customer) GetUpdatedAt() *string { return c.UpdatedAt } -func (c *Customer) GetCards() []*Card { - if c == nil { - return nil - } - return c.Cards -} - func (c *Customer) GetGivenName() *string { if c == nil { return nil diff --git a/customers/client/client.go b/customers/client/client.go index 4c3d800..3321dd8 100644 --- a/customers/client/client.go +++ b/customers/client/client.go @@ -175,7 +175,7 @@ func (c *Client) Create( // - `company_name` // - `email_address` // - `phone_number` -func (c *Client) BulkCreateCustomers( +func (c *Client) BatchCreate( ctx context.Context, request *squaregosdk.BulkCreateCustomersRequest, opts ...option.RequestOption, @@ -298,8 +298,6 @@ func (c *Client) BulkRetrieveCustomers( // Updates multiple customer profiles. // // This endpoint takes a map of individual update requests and returns a map of responses. -// -// You cannot use this endpoint to change cards on file. To make changes, use the [Cards API](api:Cards) or [Gift Cards API](api:GiftCards). func (c *Client) BulkUpdateCustomers( ctx context.Context, request *squaregosdk.BulkUpdateCustomersRequest, @@ -429,8 +427,6 @@ func (c *Client) Get( // To add or update a field, specify the new value. To remove a field, specify `null`. // // To update a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile. -// -// You cannot use this endpoint to change cards on file. To make changes, use the [Cards API](api:Cards) or [Gift Cards API](api:GiftCards). func (c *Client) Update( ctx context.Context, request *squaregosdk.UpdateCustomerRequest, @@ -472,7 +468,7 @@ func (c *Client) Update( return response, nil } -// Deletes a customer profile from a business. This operation also unlinks any associated cards on file. +// Deletes a customer profile from a business. // // To delete a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile. func (c *Client) Delete( diff --git a/invoices/client.go b/invoices/client.go index 100644a..48586f7 100644 --- a/invoices/client.go +++ b/invoices/client.go @@ -482,7 +482,7 @@ func (c *Client) Cancel( // // In addition to the required `ORDERS_WRITE` and `INVOICES_WRITE` permissions, `CUSTOMERS_READ` // and `PAYMENTS_WRITE` are required when publishing invoices configured for card-on-file payments. -func (c *Client) Publisb( +func (c *Client) Publish( ctx context.Context, request *squaregosdk.PublishInvoiceRequest, opts ...option.RequestOption, diff --git a/labor.go b/labor.go deleted file mode 100644 index 1bbed36..0000000 --- a/labor.go +++ /dev/null @@ -1,155 +0,0 @@ -// This file was auto-generated by Fern from our API Definition. - -package square - -import ( - json "encoding/json" - fmt "fmt" - internal "github.com/square/square-go-sdk/internal" -) - -type CreateBreakTypeRequest struct { - // A unique string value to ensure the idempotency of the operation. - IdempotencyKey *string `json:"idempotency_key,omitempty" url:"-"` - // The `BreakType` to be created. - BreakType *BreakType `json:"break_type,omitempty" url:"-"` -} - -type LaborListRequest struct { - // Filter the returned `BreakType` results to only those that are associated with the - // specified location. - LocationID *string `json:"-" url:"location_id,omitempty"` - // The maximum number of `BreakType` results to return per page. The number can range between 1 - // and 200. The default is 200. - Limit *int `json:"-" url:"limit,omitempty"` - // A pointer to the next page of `BreakType` results to fetch. - Cursor *string `json:"-" url:"cursor,omitempty"` -} - -// The response to the request to create a `BreakType`. The response contains -// the created `BreakType` object and might contain a set of `Error` objects if -// the request resulted in errors. -type CreateBreakTypeResponse struct { - // The `BreakType` that was created by the request. - BreakType *BreakType `json:"break_type,omitempty" url:"break_type,omitempty"` - // Any errors that occurred during the request. - Errors []*Error `json:"errors,omitempty" url:"errors,omitempty"` - - extraProperties map[string]interface{} - rawJSON json.RawMessage -} - -func (c *CreateBreakTypeResponse) GetBreakType() *BreakType { - if c == nil { - return nil - } - return c.BreakType -} - -func (c *CreateBreakTypeResponse) GetErrors() []*Error { - if c == nil { - return nil - } - return c.Errors -} - -func (c *CreateBreakTypeResponse) GetExtraProperties() map[string]interface{} { - return c.extraProperties -} - -func (c *CreateBreakTypeResponse) UnmarshalJSON(data []byte) error { - type unmarshaler CreateBreakTypeResponse - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *c = CreateBreakTypeResponse(value) - extraProperties, err := internal.ExtractExtraProperties(data, *c) - if err != nil { - return err - } - c.extraProperties = extraProperties - c.rawJSON = json.RawMessage(data) - return nil -} - -func (c *CreateBreakTypeResponse) String() string { - if len(c.rawJSON) > 0 { - if value, err := internal.StringifyJSON(c.rawJSON); err == nil { - return value - } - } - if value, err := internal.StringifyJSON(c); err == nil { - return value - } - return fmt.Sprintf("%#v", c) -} - -// The response to a request for a set of `BreakType` objects. The response contains -// the requested `BreakType` objects and might contain a set of `Error` objects if -// the request resulted in errors. -type ListBreakTypesResponse struct { - // A page of `BreakType` results. - BreakTypes []*BreakType `json:"break_types,omitempty" url:"break_types,omitempty"` - // The value supplied in the subsequent request to fetch the next page - // of `BreakType` results. - Cursor *string `json:"cursor,omitempty" url:"cursor,omitempty"` - // Any errors that occurred during the request. - Errors []*Error `json:"errors,omitempty" url:"errors,omitempty"` - - extraProperties map[string]interface{} - rawJSON json.RawMessage -} - -func (l *ListBreakTypesResponse) GetBreakTypes() []*BreakType { - if l == nil { - return nil - } - return l.BreakTypes -} - -func (l *ListBreakTypesResponse) GetCursor() *string { - if l == nil { - return nil - } - return l.Cursor -} - -func (l *ListBreakTypesResponse) GetErrors() []*Error { - if l == nil { - return nil - } - return l.Errors -} - -func (l *ListBreakTypesResponse) GetExtraProperties() map[string]interface{} { - return l.extraProperties -} - -func (l *ListBreakTypesResponse) UnmarshalJSON(data []byte) error { - type unmarshaler ListBreakTypesResponse - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *l = ListBreakTypesResponse(value) - extraProperties, err := internal.ExtractExtraProperties(data, *l) - if err != nil { - return err - } - l.extraProperties = extraProperties - l.rawJSON = json.RawMessage(data) - return nil -} - -func (l *ListBreakTypesResponse) String() string { - if len(l.rawJSON) > 0 { - if value, err := internal.StringifyJSON(l.rawJSON); err == nil { - return value - } - } - if value, err := internal.StringifyJSON(l); err == nil { - return value - } - return fmt.Sprintf("%#v", l) -} diff --git a/labor/break_types.go b/labor/break_types.go index d2cdcc7..a2fd27e 100644 --- a/labor/break_types.go +++ b/labor/break_types.go @@ -6,6 +6,13 @@ import ( squaregosdk "github.com/square/square-go-sdk" ) +type CreateBreakTypeRequest struct { + // A unique string value to ensure the idempotency of the operation. + IdempotencyKey *string `json:"idempotency_key,omitempty" url:"-"` + // The `BreakType` to be created. + BreakType *squaregosdk.BreakType `json:"break_type,omitempty" url:"-"` +} + type BreakTypesDeleteRequest struct { // The UUID for the `BreakType` being deleted. ID string `json:"-" url:"-"` @@ -16,6 +23,17 @@ type BreakTypesGetRequest struct { ID string `json:"-" url:"-"` } +type BreakTypesListRequest struct { + // Filter the returned `BreakType` results to only those that are associated with the + // specified location. + LocationID *string `json:"-" url:"location_id,omitempty"` + // The maximum number of `BreakType` results to return per page. The number can range between 1 + // and 200. The default is 200. + Limit *int `json:"-" url:"limit,omitempty"` + // A pointer to the next page of `BreakType` results to fetch. + Cursor *string `json:"-" url:"cursor,omitempty"` +} + type UpdateBreakTypeRequest struct { // The UUID for the `BreakType` being updated. ID string `json:"-" url:"-"` diff --git a/labor/breaktypes/client.go b/labor/breaktypes/client.go index 4cd46dd..841d601 100644 --- a/labor/breaktypes/client.go +++ b/labor/breaktypes/client.go @@ -4,6 +4,7 @@ package breaktypes import ( context "context" + fmt "fmt" squaregosdk "github.com/square/square-go-sdk" core "github.com/square/square-go-sdk/core" internal "github.com/square/square-go-sdk/internal" @@ -39,6 +40,115 @@ func NewClient(opts ...option.RequestOption) *Client { } } +// Returns a paginated list of `BreakType` instances for a business. +func (c *Client) List( + ctx context.Context, + request *labor.BreakTypesListRequest, + opts ...option.RequestOption, +) (*core.Page[*squaregosdk.BreakType], error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := baseURL + "/v2/labor/break-types" + queryParams, err := internal.QueryValues(request) + if err != nil { + return nil, err + } + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + + prepareCall := func(pageRequest *internal.PageRequest[*string]) *internal.CallParams { + if pageRequest.Cursor != nil { + queryParams.Set("cursor", fmt.Sprintf("%v", *pageRequest.Cursor)) + } + nextURL := endpointURL + if len(queryParams) > 0 { + nextURL += "?" + queryParams.Encode() + } + return &internal.CallParams{ + URL: nextURL, + Method: http.MethodGet, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: pageRequest.Response, + } + } + readPageResponse := func(response *squaregosdk.ListBreakTypesResponse) *internal.PageResponse[*string, *squaregosdk.BreakType] { + next := response.Cursor + results := response.BreakTypes + return &internal.PageResponse[*string, *squaregosdk.BreakType]{ + Next: next, + Results: results, + } + } + pager := internal.NewCursorPager( + c.caller, + prepareCall, + readPageResponse, + ) + return pager.GetPage(ctx, request.Cursor) +} + +// Creates a new `BreakType`. +// +// A `BreakType` is a template for creating `Break` objects. +// You must provide the following values in your request to this +// endpoint: +// +// - `location_id` +// - `break_name` +// - `expected_duration` +// - `is_paid` +// +// You can only have three `BreakType` instances per location. If you attempt to add a fourth +// `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of 3 breaks per location." +// is returned. +func (c *Client) Create( + ctx context.Context, + request *labor.CreateBreakTypeRequest, + opts ...option.RequestOption, +) (*squaregosdk.CreateBreakTypeResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := baseURL + "/v2/labor/break-types" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + + var response *squaregosdk.CreateBreakTypeResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + }, + ); err != nil { + return nil, err + } + return response, nil +} + // Returns a single `BreakType` specified by `id`. func (c *Client) Get( ctx context.Context, diff --git a/labor/client/client.go b/labor/client/client.go index 25226e8..38ba3e5 100644 --- a/labor/client/client.go +++ b/labor/client/client.go @@ -3,9 +3,6 @@ package client import ( - context "context" - fmt "fmt" - squaregosdk "github.com/square/square-go-sdk" core "github.com/square/square-go-sdk/core" internal "github.com/square/square-go-sdk/internal" breaktypes "github.com/square/square-go-sdk/labor/breaktypes" @@ -54,112 +51,3 @@ func NewClient(opts ...option.RequestOption) *Client { WorkweekConfigs: workweekconfigs.NewClient(opts...), } } - -// Returns a paginated list of `BreakType` instances for a business. -func (c *Client) List( - ctx context.Context, - request *squaregosdk.LaborListRequest, - opts ...option.RequestOption, -) (*core.Page[*squaregosdk.BreakType], error) { - options := core.NewRequestOptions(opts...) - baseURL := internal.ResolveBaseURL( - options.BaseURL, - c.baseURL, - "https://connect.squareup.com", - ) - endpointURL := baseURL + "/v2/labor/break-types" - queryParams, err := internal.QueryValues(request) - if err != nil { - return nil, err - } - headers := internal.MergeHeaders( - c.header.Clone(), - options.ToHeader(), - ) - - prepareCall := func(pageRequest *internal.PageRequest[*string]) *internal.CallParams { - if pageRequest.Cursor != nil { - queryParams.Set("cursor", fmt.Sprintf("%v", *pageRequest.Cursor)) - } - nextURL := endpointURL - if len(queryParams) > 0 { - nextURL += "?" + queryParams.Encode() - } - return &internal.CallParams{ - URL: nextURL, - Method: http.MethodGet, - Headers: headers, - MaxAttempts: options.MaxAttempts, - BodyProperties: options.BodyProperties, - QueryParameters: options.QueryParameters, - Client: options.HTTPClient, - Response: pageRequest.Response, - } - } - readPageResponse := func(response *squaregosdk.ListBreakTypesResponse) *internal.PageResponse[*string, *squaregosdk.BreakType] { - next := response.Cursor - results := response.BreakTypes - return &internal.PageResponse[*string, *squaregosdk.BreakType]{ - Next: next, - Results: results, - } - } - pager := internal.NewCursorPager( - c.caller, - prepareCall, - readPageResponse, - ) - return pager.GetPage(ctx, request.Cursor) -} - -// Creates a new `BreakType`. -// -// A `BreakType` is a template for creating `Break` objects. -// You must provide the following values in your request to this -// endpoint: -// -// - `location_id` -// - `break_name` -// - `expected_duration` -// - `is_paid` -// -// You can only have three `BreakType` instances per location. If you attempt to add a fourth -// `BreakType` for a location, an `INVALID_REQUEST_ERROR` "Exceeded limit of 3 breaks per location." -// is returned. -func (c *Client) Create( - ctx context.Context, - request *squaregosdk.CreateBreakTypeRequest, - opts ...option.RequestOption, -) (*squaregosdk.CreateBreakTypeResponse, error) { - options := core.NewRequestOptions(opts...) - baseURL := internal.ResolveBaseURL( - options.BaseURL, - c.baseURL, - "https://connect.squareup.com", - ) - endpointURL := baseURL + "/v2/labor/break-types" - headers := internal.MergeHeaders( - c.header.Clone(), - options.ToHeader(), - ) - headers.Set("Content-Type", "application/json") - - var response *squaregosdk.CreateBreakTypeResponse - if err := c.caller.Call( - ctx, - &internal.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - Headers: headers, - MaxAttempts: options.MaxAttempts, - BodyProperties: options.BodyProperties, - QueryParameters: options.QueryParameters, - Client: options.HTTPClient, - Request: request, - Response: &response, - }, - ); err != nil { - return nil, err - } - return response, nil -} diff --git a/locations/custom_attribute_definitions.go b/locations/custom_attribute_definitions.go index 76c689c..a94a4a3 100644 --- a/locations/custom_attribute_definitions.go +++ b/locations/custom_attribute_definitions.go @@ -18,6 +18,11 @@ type CreateLocationCustomAttributeDefinitionRequest struct { IdempotencyKey *string `json:"idempotency_key,omitempty" url:"-"` } +type CustomAttributeDefinitionsDeleteRequest struct { + // The key of the custom attribute definition to delete. + Key string `json:"-" url:"-"` +} + type CustomAttributeDefinitionsGetRequest struct { // The key of the custom attribute definition to retrieve. If the requesting application // is not the definition owner, you must use the qualified key. @@ -41,3 +46,26 @@ type CustomAttributeDefinitionsListRequest struct { // For more information, see [Pagination](https://developer.squareup.com/docs/build-basics/common-api-patterns/pagination). Cursor *string `json:"-" url:"cursor,omitempty"` } + +type UpdateLocationCustomAttributeDefinitionRequest struct { + // The key of the custom attribute definition to update. + Key string `json:"-" url:"-"` + // The custom attribute definition that contains the fields to update. This endpoint + // supports sparse updates, so only new or changed fields need to be included in the request. + // Only the following fields can be updated: + // - `name` + // - `description` + // - `visibility` + // - `schema` for a `Selection` data type. Only changes to the named options or the maximum number of allowed + // selections are supported. + // + // For more information, see + // [Update a location custom attribute definition](https://developer.squareup.com/docs/location-custom-attributes-api/custom-attribute-definitions#update-custom-attribute-definition). + // To enable [optimistic concurrency](https://developer.squareup.com/docs/build-basics/common-api-patterns/optimistic-concurrency) + // control, specify the current version of the custom attribute definition. + // If this is not important for your application, `version` can be set to -1. + CustomAttributeDefinition *squaregosdk.CustomAttributeDefinition `json:"custom_attribute_definition,omitempty" url:"-"` + // A unique identifier for this request, used to ensure idempotency. For more information, + // see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency). + IdempotencyKey *string `json:"idempotency_key,omitempty" url:"-"` +} diff --git a/locations/custom_attributes.go b/locations/custom_attributes.go index 9898ae0..97a550a 100644 --- a/locations/custom_attributes.go +++ b/locations/custom_attributes.go @@ -65,29 +65,6 @@ type CustomAttributesListRequest struct { WithDefinitions *bool `json:"-" url:"with_definitions,omitempty"` } -type UpdateLocationCustomAttributeDefinitionRequest struct { - // The key of the custom attribute definition to update. - Key string `json:"-" url:"-"` - // The custom attribute definition that contains the fields to update. This endpoint - // supports sparse updates, so only new or changed fields need to be included in the request. - // Only the following fields can be updated: - // - `name` - // - `description` - // - `visibility` - // - `schema` for a `Selection` data type. Only changes to the named options or the maximum number of allowed - // selections are supported. - // - // For more information, see - // [Update a location custom attribute definition](https://developer.squareup.com/docs/location-custom-attributes-api/custom-attribute-definitions#update-custom-attribute-definition). - // To enable [optimistic concurrency](https://developer.squareup.com/docs/build-basics/common-api-patterns/optimistic-concurrency) - // control, specify the current version of the custom attribute definition. - // If this is not important for your application, `version` can be set to -1. - CustomAttributeDefinition *squaregosdk.CustomAttributeDefinition `json:"custom_attribute_definition,omitempty" url:"-"` - // A unique identifier for this request, used to ensure idempotency. For more information, - // see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency). - IdempotencyKey *string `json:"idempotency_key,omitempty" url:"-"` -} - type UpsertLocationCustomAttributeRequest struct { // The ID of the target [location](entity:Location). LocationID string `json:"-" url:"-"` diff --git a/locations/customattributedefinitions/client.go b/locations/customattributedefinitions/client.go index 63b09ba..c0e2f7e 100644 --- a/locations/customattributedefinitions/client.go +++ b/locations/customattributedefinitions/client.go @@ -193,3 +193,91 @@ func (c *Client) Get( } return response, nil } + +// Updates a location-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account. +// Use this endpoint to update the following fields: `name`, `description`, `visibility`, or the +// `schema` for a `Selection` data type. +// Only the definition owner can update a custom attribute definition. +func (c *Client) Update( + ctx context.Context, + request *locations.UpdateLocationCustomAttributeDefinitionRequest, + opts ...option.RequestOption, +) (*squaregosdk.UpdateLocationCustomAttributeDefinitionResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := internal.EncodeURL( + baseURL+"/v2/locations/custom-attribute-definitions/%v", + request.Key, + ) + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + + var response *squaregosdk.UpdateLocationCustomAttributeDefinitionResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPut, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + }, + ); err != nil { + return nil, err + } + return response, nil +} + +// Deletes a location-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account. +// Deleting a custom attribute definition also deletes the corresponding custom attribute from +// all locations. +// Only the definition owner can delete a custom attribute definition. +func (c *Client) Delete( + ctx context.Context, + request *locations.CustomAttributeDefinitionsDeleteRequest, + opts ...option.RequestOption, +) (*squaregosdk.DeleteLocationCustomAttributeDefinitionResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := internal.EncodeURL( + baseURL+"/v2/locations/custom-attribute-definitions/%v", + request.Key, + ) + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + + var response *squaregosdk.DeleteLocationCustomAttributeDefinitionResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodDelete, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + }, + ); err != nil { + return nil, err + } + return response, nil +} diff --git a/locations/customattributes/client.go b/locations/customattributes/client.go index b464e17..ed23917 100644 --- a/locations/customattributes/client.go +++ b/locations/customattributes/client.go @@ -40,94 +40,6 @@ func NewClient(opts ...option.RequestOption) *Client { } } -// Updates a location-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account. -// Use this endpoint to update the following fields: `name`, `description`, `visibility`, or the -// `schema` for a `Selection` data type. -// Only the definition owner can update a custom attribute definition. -func (c *Client) Update( - ctx context.Context, - request *locations.UpdateLocationCustomAttributeDefinitionRequest, - opts ...option.RequestOption, -) (*squaregosdk.UpdateLocationCustomAttributeDefinitionResponse, error) { - options := core.NewRequestOptions(opts...) - baseURL := internal.ResolveBaseURL( - options.BaseURL, - c.baseURL, - "https://connect.squareup.com", - ) - endpointURL := internal.EncodeURL( - baseURL+"/v2/locations/custom-attribute-definitions/%v", - request.Key, - ) - headers := internal.MergeHeaders( - c.header.Clone(), - options.ToHeader(), - ) - headers.Set("Content-Type", "application/json") - - var response *squaregosdk.UpdateLocationCustomAttributeDefinitionResponse - if err := c.caller.Call( - ctx, - &internal.CallParams{ - URL: endpointURL, - Method: http.MethodPut, - Headers: headers, - MaxAttempts: options.MaxAttempts, - BodyProperties: options.BodyProperties, - QueryParameters: options.QueryParameters, - Client: options.HTTPClient, - Request: request, - Response: &response, - }, - ); err != nil { - return nil, err - } - return response, nil -} - -// Deletes a [custom attribute](entity:CustomAttribute) associated with a location. -// To delete a custom attribute owned by another application, the `visibility` setting must be -// `VISIBILITY_READ_WRITE_VALUES`. -func (c *Client) Delete( - ctx context.Context, - request *locations.CustomAttributesDeleteRequest, - opts ...option.RequestOption, -) (*squaregosdk.DeleteLocationCustomAttributeResponse, error) { - options := core.NewRequestOptions(opts...) - baseURL := internal.ResolveBaseURL( - options.BaseURL, - c.baseURL, - "https://connect.squareup.com", - ) - endpointURL := internal.EncodeURL( - baseURL+"/v2/locations/%v/custom-attributes/%v", - request.LocationID, - request.Key, - ) - headers := internal.MergeHeaders( - c.header.Clone(), - options.ToHeader(), - ) - - var response *squaregosdk.DeleteLocationCustomAttributeResponse - if err := c.caller.Call( - ctx, - &internal.CallParams{ - URL: endpointURL, - Method: http.MethodDelete, - Headers: headers, - MaxAttempts: options.MaxAttempts, - BodyProperties: options.BodyProperties, - QueryParameters: options.QueryParameters, - Client: options.HTTPClient, - Response: &response, - }, - ); err != nil { - return nil, err - } - return response, nil -} - // Deletes [custom attributes](entity:CustomAttribute) for locations as a bulk operation. // To delete a custom attribute owned by another application, the `visibility` setting must be // `VISIBILITY_READ_WRITE_VALUES`. @@ -381,3 +293,46 @@ func (c *Client) Upsert( } return response, nil } + +// Deletes a [custom attribute](entity:CustomAttribute) associated with a location. +// To delete a custom attribute owned by another application, the `visibility` setting must be +// `VISIBILITY_READ_WRITE_VALUES`. +func (c *Client) Delete( + ctx context.Context, + request *locations.CustomAttributesDeleteRequest, + opts ...option.RequestOption, +) (*squaregosdk.DeleteLocationCustomAttributeResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := internal.EncodeURL( + baseURL+"/v2/locations/%v/custom-attributes/%v", + request.LocationID, + request.Key, + ) + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + + var response *squaregosdk.DeleteLocationCustomAttributeResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodDelete, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + }, + ); err != nil { + return nil, err + } + return response, nil +} diff --git a/merchants/client/client.go b/merchants/client/client.go index ad8abfe..cfc8c83 100644 --- a/merchants/client/client.go +++ b/merchants/client/client.go @@ -20,8 +20,8 @@ type Client struct { caller *internal.Caller header http.Header - CustomAttributes *customattributes.Client CustomAttributeDefinitions *customattributedefinitions.Client + CustomAttributes *customattributes.Client } func NewClient(opts ...option.RequestOption) *Client { @@ -41,8 +41,8 @@ func NewClient(opts ...option.RequestOption) *Client { }, ), header: options.ToHeader(), - CustomAttributes: customattributes.NewClient(opts...), CustomAttributeDefinitions: customattributedefinitions.NewClient(opts...), + CustomAttributes: customattributes.NewClient(opts...), } } diff --git a/merchants/custom_attribute_definitions.go b/merchants/custom_attribute_definitions.go index 81adc9b..de0d7c2 100644 --- a/merchants/custom_attribute_definitions.go +++ b/merchants/custom_attribute_definitions.go @@ -6,6 +6,18 @@ import ( squaregosdk "github.com/square/square-go-sdk" ) +type CreateMerchantCustomAttributeDefinitionRequest struct { + // The custom attribute definition to create. Note the following: + // - With the exception of the `Selection` data type, the `schema` is specified as a simple URL to the JSON schema + // definition hosted on the Square CDN. For more information, including supported values and constraints, see + // [Supported data types](https://developer.squareup.com/docs/devtools/customattributes/overview#supported-data-types). + // - `name` is required unless `visibility` is set to `VISIBILITY_HIDDEN`. + CustomAttributeDefinition *squaregosdk.CustomAttributeDefinition `json:"custom_attribute_definition,omitempty" url:"-"` + // A unique identifier for this request, used to ensure idempotency. For more information, + // see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency). + IdempotencyKey *string `json:"idempotency_key,omitempty" url:"-"` +} + type CustomAttributeDefinitionsDeleteRequest struct { // The key of the custom attribute definition to delete. Key string `json:"-" url:"-"` @@ -22,6 +34,19 @@ type CustomAttributeDefinitionsGetRequest struct { Version *int `json:"-" url:"version,omitempty"` } +type CustomAttributeDefinitionsListRequest struct { + // Filters the `CustomAttributeDefinition` results by their `visibility` values. + VisibilityFilter *squaregosdk.VisibilityFilter `json:"-" url:"visibility_filter,omitempty"` + // The maximum number of results to return in a single paged response. This limit is advisory. + // The response might contain more or fewer results. The minimum value is 1 and the maximum value is 100. + // The default value is 20. For more information, see [Pagination](https://developer.squareup.com/docs/build-basics/common-api-patterns/pagination). + Limit *int `json:"-" url:"limit,omitempty"` + // The cursor returned in the paged response from the previous call to this endpoint. + // Provide this cursor to retrieve the next page of results for your original request. + // For more information, see [Pagination](https://developer.squareup.com/docs/build-basics/common-api-patterns/pagination). + Cursor *string `json:"-" url:"cursor,omitempty"` +} + type UpdateMerchantCustomAttributeDefinitionRequest struct { // The key of the custom attribute definition to update. Key string `json:"-" url:"-"` diff --git a/merchants/custom_attributes.go b/merchants/custom_attributes.go index 2b90569..708b2d6 100644 --- a/merchants/custom_attributes.go +++ b/merchants/custom_attributes.go @@ -19,18 +19,6 @@ type BulkUpsertMerchantCustomAttributesRequest struct { Values map[string]*squaregosdk.BulkUpsertMerchantCustomAttributesRequestMerchantCustomAttributeUpsertRequest `json:"values,omitempty" url:"-"` } -type CreateMerchantCustomAttributeDefinitionRequest struct { - // The custom attribute definition to create. Note the following: - // - With the exception of the `Selection` data type, the `schema` is specified as a simple URL to the JSON schema - // definition hosted on the Square CDN. For more information, including supported values and constraints, see - // [Supported data types](https://developer.squareup.com/docs/devtools/customattributes/overview#supported-data-types). - // - `name` is required unless `visibility` is set to `VISIBILITY_HIDDEN`. - CustomAttributeDefinition *squaregosdk.CustomAttributeDefinition `json:"custom_attribute_definition,omitempty" url:"-"` - // A unique identifier for this request, used to ensure idempotency. For more information, - // see [Idempotency](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency). - IdempotencyKey *string `json:"idempotency_key,omitempty" url:"-"` -} - type CustomAttributesDeleteRequest struct { // The ID of the target [merchant](entity:Merchant). MerchantID string `json:"-" url:"-"` diff --git a/merchants/customattributedefinitions/client.go b/merchants/customattributedefinitions/client.go index 13d4dff..7e06403 100644 --- a/merchants/customattributedefinitions/client.go +++ b/merchants/customattributedefinitions/client.go @@ -4,6 +4,7 @@ package customattributedefinitions import ( context "context" + fmt "fmt" squaregosdk "github.com/square/square-go-sdk" core "github.com/square/square-go-sdk/core" internal "github.com/square/square-go-sdk/internal" @@ -39,6 +40,111 @@ func NewClient(opts ...option.RequestOption) *Client { } } +// Lists the merchant-related [custom attribute definitions](entity:CustomAttributeDefinition) that belong to a Square seller account. +// When all response pages are retrieved, the results include all custom attribute definitions +// that are visible to the requesting application, including those that are created by other +// applications and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`. +func (c *Client) List( + ctx context.Context, + request *merchants.CustomAttributeDefinitionsListRequest, + opts ...option.RequestOption, +) (*core.Page[*squaregosdk.CustomAttributeDefinition], error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := baseURL + "/v2/merchants/custom-attribute-definitions" + queryParams, err := internal.QueryValues(request) + if err != nil { + return nil, err + } + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + + prepareCall := func(pageRequest *internal.PageRequest[*string]) *internal.CallParams { + if pageRequest.Cursor != nil { + queryParams.Set("cursor", fmt.Sprintf("%v", *pageRequest.Cursor)) + } + nextURL := endpointURL + if len(queryParams) > 0 { + nextURL += "?" + queryParams.Encode() + } + return &internal.CallParams{ + URL: nextURL, + Method: http.MethodGet, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: pageRequest.Response, + } + } + readPageResponse := func(response *squaregosdk.ListMerchantCustomAttributeDefinitionsResponse) *internal.PageResponse[*string, *squaregosdk.CustomAttributeDefinition] { + next := response.Cursor + results := response.CustomAttributeDefinitions + return &internal.PageResponse[*string, *squaregosdk.CustomAttributeDefinition]{ + Next: next, + Results: results, + } + } + pager := internal.NewCursorPager( + c.caller, + prepareCall, + readPageResponse, + ) + return pager.GetPage(ctx, request.Cursor) +} + +// Creates a merchant-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account. +// Use this endpoint to define a custom attribute that can be associated with a merchant connecting to your application. +// A custom attribute definition specifies the `key`, `visibility`, `schema`, and other properties +// for a custom attribute. After the definition is created, you can call +// [UpsertMerchantCustomAttribute](api-endpoint:MerchantCustomAttributes-UpsertMerchantCustomAttribute) or +// [BulkUpsertMerchantCustomAttributes](api-endpoint:MerchantCustomAttributes-BulkUpsertMerchantCustomAttributes) +// to set the custom attribute for a merchant. +func (c *Client) Create( + ctx context.Context, + request *merchants.CreateMerchantCustomAttributeDefinitionRequest, + opts ...option.RequestOption, +) (*squaregosdk.CreateMerchantCustomAttributeDefinitionResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := baseURL + "/v2/merchants/custom-attribute-definitions" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + + var response *squaregosdk.CreateMerchantCustomAttributeDefinitionResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + }, + ); err != nil { + return nil, err + } + return response, nil +} + // Retrieves a merchant-related [custom attribute definition](entity:CustomAttributeDefinition) from a Square seller account. // To retrieve a custom attribute definition created by another application, the `visibility` // setting must be `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`. diff --git a/merchants/customattributes/client.go b/merchants/customattributes/client.go index acfb395..8b652dd 100644 --- a/merchants/customattributes/client.go +++ b/merchants/customattributes/client.go @@ -40,116 +40,6 @@ func NewClient(opts ...option.RequestOption) *Client { } } -// Lists the [custom attributes](entity:CustomAttribute) associated with a merchant. -// You can use the `with_definitions` query parameter to also retrieve custom attribute definitions -// in the same call. -// When all response pages are retrieved, the results include all custom attributes that are -// visible to the requesting application, including those that are owned by other applications -// and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`. -func (c *Client) List( - ctx context.Context, - request *merchants.CustomAttributesListRequest, - opts ...option.RequestOption, -) (*core.Page[*squaregosdk.CustomAttribute], error) { - options := core.NewRequestOptions(opts...) - baseURL := internal.ResolveBaseURL( - options.BaseURL, - c.baseURL, - "https://connect.squareup.com", - ) - endpointURL := internal.EncodeURL( - baseURL+"/v2/merchants/%v/custom-attributes", - request.MerchantID, - ) - queryParams, err := internal.QueryValues(request) - if err != nil { - return nil, err - } - headers := internal.MergeHeaders( - c.header.Clone(), - options.ToHeader(), - ) - - prepareCall := func(pageRequest *internal.PageRequest[*string]) *internal.CallParams { - if pageRequest.Cursor != nil { - queryParams.Set("cursor", fmt.Sprintf("%v", *pageRequest.Cursor)) - } - nextURL := endpointURL - if len(queryParams) > 0 { - nextURL += "?" + queryParams.Encode() - } - return &internal.CallParams{ - URL: nextURL, - Method: http.MethodGet, - Headers: headers, - MaxAttempts: options.MaxAttempts, - BodyProperties: options.BodyProperties, - QueryParameters: options.QueryParameters, - Client: options.HTTPClient, - Response: pageRequest.Response, - } - } - readPageResponse := func(response *squaregosdk.ListMerchantCustomAttributesResponse) *internal.PageResponse[*string, *squaregosdk.CustomAttribute] { - next := response.Cursor - results := response.CustomAttributes - return &internal.PageResponse[*string, *squaregosdk.CustomAttribute]{ - Next: next, - Results: results, - } - } - pager := internal.NewCursorPager( - c.caller, - prepareCall, - readPageResponse, - ) - return pager.GetPage(ctx, request.Cursor) -} - -// Creates a merchant-related [custom attribute definition](entity:CustomAttributeDefinition) for a Square seller account. -// Use this endpoint to define a custom attribute that can be associated with a merchant connecting to your application. -// A custom attribute definition specifies the `key`, `visibility`, `schema`, and other properties -// for a custom attribute. After the definition is created, you can call -// [UpsertMerchantCustomAttribute](api-endpoint:MerchantCustomAttributes-UpsertMerchantCustomAttribute) or -// [BulkUpsertMerchantCustomAttributes](api-endpoint:MerchantCustomAttributes-BulkUpsertMerchantCustomAttributes) -// to set the custom attribute for a merchant. -func (c *Client) Create( - ctx context.Context, - request *merchants.CreateMerchantCustomAttributeDefinitionRequest, - opts ...option.RequestOption, -) (*squaregosdk.CreateMerchantCustomAttributeDefinitionResponse, error) { - options := core.NewRequestOptions(opts...) - baseURL := internal.ResolveBaseURL( - options.BaseURL, - c.baseURL, - "https://connect.squareup.com", - ) - endpointURL := baseURL + "/v2/merchants/custom-attribute-definitions" - headers := internal.MergeHeaders( - c.header.Clone(), - options.ToHeader(), - ) - headers.Set("Content-Type", "application/json") - - var response *squaregosdk.CreateMerchantCustomAttributeDefinitionResponse - if err := c.caller.Call( - ctx, - &internal.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - Headers: headers, - MaxAttempts: options.MaxAttempts, - BodyProperties: options.BodyProperties, - QueryParameters: options.QueryParameters, - Client: options.HTTPClient, - Request: request, - Response: &response, - }, - ); err != nil { - return nil, err - } - return response, nil -} - // Deletes [custom attributes](entity:CustomAttribute) for a merchant as a bulk operation. // To delete a custom attribute owned by another application, the `visibility` setting must be // `VISIBILITY_READ_WRITE_VALUES`. @@ -239,6 +129,71 @@ func (c *Client) BatchUpsert( return response, nil } +// Lists the [custom attributes](entity:CustomAttribute) associated with a merchant. +// You can use the `with_definitions` query parameter to also retrieve custom attribute definitions +// in the same call. +// When all response pages are retrieved, the results include all custom attributes that are +// visible to the requesting application, including those that are owned by other applications +// and set to `VISIBILITY_READ_ONLY` or `VISIBILITY_READ_WRITE_VALUES`. +func (c *Client) List( + ctx context.Context, + request *merchants.CustomAttributesListRequest, + opts ...option.RequestOption, +) (*core.Page[*squaregosdk.CustomAttribute], error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := internal.EncodeURL( + baseURL+"/v2/merchants/%v/custom-attributes", + request.MerchantID, + ) + queryParams, err := internal.QueryValues(request) + if err != nil { + return nil, err + } + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + + prepareCall := func(pageRequest *internal.PageRequest[*string]) *internal.CallParams { + if pageRequest.Cursor != nil { + queryParams.Set("cursor", fmt.Sprintf("%v", *pageRequest.Cursor)) + } + nextURL := endpointURL + if len(queryParams) > 0 { + nextURL += "?" + queryParams.Encode() + } + return &internal.CallParams{ + URL: nextURL, + Method: http.MethodGet, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: pageRequest.Response, + } + } + readPageResponse := func(response *squaregosdk.ListMerchantCustomAttributesResponse) *internal.PageResponse[*string, *squaregosdk.CustomAttribute] { + next := response.Cursor + results := response.CustomAttributes + return &internal.PageResponse[*string, *squaregosdk.CustomAttribute]{ + Next: next, + Results: results, + } + } + pager := internal.NewCursorPager( + c.caller, + prepareCall, + readPageResponse, + ) + return pager.GetPage(ctx, request.Cursor) +} + // Retrieves a [custom attribute](entity:CustomAttribute) associated with a merchant. // You can use the `with_definition` query parameter to also retrieve the custom attribute definition // in the same call. diff --git a/payments.go b/payments.go index 34696c0..9e3722e 100644 --- a/payments.go +++ b/payments.go @@ -13,6 +13,11 @@ type PaymentsCancelRequest struct { PaymentID string `json:"-" url:"-"` } +type CancelPaymentByIdempotencyKeyRequest struct { + // The `idempotency_key` identifying the payment to be canceled. + IdempotencyKey string `json:"idempotency_key" url:"-"` +} + type CompletePaymentRequest struct { // The unique ID identifying the payment to be completed. PaymentID string `json:"-" url:"-"` @@ -649,6 +654,56 @@ func (b *BuyNowPayLaterDetails) String() string { return fmt.Sprintf("%#v", b) } +// Defines the response returned by +// [CancelPaymentByIdempotencyKey](api-endpoint:Payments-CancelPaymentByIdempotencyKey). +// On success, `errors` is empty. +type CancelPaymentByIdempotencyKeyResponse struct { + // Any errors that occurred during the request. + Errors []*Error `json:"errors,omitempty" url:"errors,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CancelPaymentByIdempotencyKeyResponse) GetErrors() []*Error { + if c == nil { + return nil + } + return c.Errors +} + +func (c *CancelPaymentByIdempotencyKeyResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *CancelPaymentByIdempotencyKeyResponse) UnmarshalJSON(data []byte) error { + type unmarshaler CancelPaymentByIdempotencyKeyResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CancelPaymentByIdempotencyKeyResponse(value) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *CancelPaymentByIdempotencyKeyResponse) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + // Defines the response returned by [CancelPayment](api-endpoint:Payments-CancelPayment). type CancelPaymentResponse struct { // Information about errors encountered during the request. diff --git a/payments/client.go b/payments/client.go index d91c099..458f0eb 100644 --- a/payments/client.go +++ b/payments/client.go @@ -147,29 +147,36 @@ func (c *Client) Create( return response, nil } -// Cancels (voids) a payment. You can use this endpoint to cancel a payment with -// the APPROVED `status`. -func (c *Client) Cancel( +// Cancels (voids) a payment identified by the idempotency key that is specified in the +// request. +// +// Use this method when the status of a `CreatePayment` request is unknown (for example, after you send a +// `CreatePayment` request, a network error occurs and you do not get a response). In this case, you can +// direct Square to cancel the payment using this endpoint. In the request, you provide the same +// idempotency key that you provided in your `CreatePayment` request that you want to cancel. After +// canceling the payment, you can submit your `CreatePayment` request again. +// +// Note that if no payment with the specified idempotency key is found, no action is taken and the endpoint +// returns successfully. +func (c *Client) CancelByIdempotencyKey( ctx context.Context, - request *squaregosdk.PaymentsCancelRequest, + request *squaregosdk.CancelPaymentByIdempotencyKeyRequest, opts ...option.RequestOption, -) (*squaregosdk.CancelPaymentResponse, error) { +) (*squaregosdk.CancelPaymentByIdempotencyKeyResponse, error) { options := core.NewRequestOptions(opts...) baseURL := internal.ResolveBaseURL( options.BaseURL, c.baseURL, "https://connect.squareup.com", ) - endpointURL := internal.EncodeURL( - baseURL+"/v2/payments/%v/cancel", - request.PaymentID, - ) + endpointURL := baseURL + "/v2/payments/cancel" headers := internal.MergeHeaders( c.header.Clone(), options.ToHeader(), ) + headers.Set("Content-Type", "application/json") - var response *squaregosdk.CancelPaymentResponse + var response *squaregosdk.CancelPaymentByIdempotencyKeyResponse if err := c.caller.Call( ctx, &internal.CallParams{ @@ -180,6 +187,7 @@ func (c *Client) Cancel( BodyProperties: options.BodyProperties, QueryParameters: options.QueryParameters, Client: options.HTTPClient, + Request: request, Response: &response, }, ); err != nil { @@ -271,6 +279,47 @@ func (c *Client) Update( return response, nil } +// Cancels (voids) a payment. You can use this endpoint to cancel a payment with +// the APPROVED `status`. +func (c *Client) Cancel( + ctx context.Context, + request *squaregosdk.PaymentsCancelRequest, + opts ...option.RequestOption, +) (*squaregosdk.CancelPaymentResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.squareup.com", + ) + endpointURL := internal.EncodeURL( + baseURL+"/v2/payments/%v/cancel", + request.PaymentID, + ) + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + + var response *squaregosdk.CancelPaymentResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + }, + ); err != nil { + return nil, err + } + return response, nil +} + // Completes (captures) a payment. // By default, payments are set to complete immediately after they are created. // diff --git a/types.go b/types.go index 7bcd960..9a4bc39 100644 --- a/types.go +++ b/types.go @@ -2443,56 +2443,6 @@ func (c *CancelLoyaltyPromotionResponse) String() string { return fmt.Sprintf("%#v", c) } -// Defines the response returned by -// [CancelPaymentByIdempotencyKey](api-endpoint:Payments-CancelPaymentByIdempotencyKey). -// On success, `errors` is empty. -type CancelPaymentByIdempotencyKeyResponse struct { - // Any errors that occurred during the request. - Errors []*Error `json:"errors,omitempty" url:"errors,omitempty"` - - extraProperties map[string]interface{} - rawJSON json.RawMessage -} - -func (c *CancelPaymentByIdempotencyKeyResponse) GetErrors() []*Error { - if c == nil { - return nil - } - return c.Errors -} - -func (c *CancelPaymentByIdempotencyKeyResponse) GetExtraProperties() map[string]interface{} { - return c.extraProperties -} - -func (c *CancelPaymentByIdempotencyKeyResponse) UnmarshalJSON(data []byte) error { - type unmarshaler CancelPaymentByIdempotencyKeyResponse - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *c = CancelPaymentByIdempotencyKeyResponse(value) - extraProperties, err := internal.ExtractExtraProperties(data, *c) - if err != nil { - return err - } - c.extraProperties = extraProperties - c.rawJSON = json.RawMessage(data) - return nil -} - -func (c *CancelPaymentByIdempotencyKeyResponse) String() string { - if len(c.rawJSON) > 0 { - if value, err := internal.StringifyJSON(c.rawJSON); err == nil { - return value - } - } - if value, err := internal.StringifyJSON(c); err == nil { - return value - } - return fmt.Sprintf("%#v", c) -} - type CancelTerminalActionResponse struct { // Information on errors encountered during the request. Errors []*Error `json:"errors,omitempty" url:"errors,omitempty"` @@ -4868,12 +4818,6 @@ type CatalogItem struct { LabelColor *string `json:"label_color,omitempty" url:"label_color,omitempty"` // Indicates whether the item is taxable (`true`) or non-taxable (`false`). Default is `true`. IsTaxable *bool `json:"is_taxable,omitempty" url:"is_taxable,omitempty"` - // If `true`, the item can be added to shipping orders from the merchant's online store. - AvailableOnline *bool `json:"available_online,omitempty" url:"available_online,omitempty"` - // If `true`, the item can be added to pickup orders from the merchant's online store. - AvailableForPickup *bool `json:"available_for_pickup,omitempty" url:"available_for_pickup,omitempty"` - // If `true`, the item can be added to electronically fulfilled orders from the merchant's online store. - AvailableElectronically *bool `json:"available_electronically,omitempty" url:"available_electronically,omitempty"` // The ID of the item's category, if any. Deprecated since 2023-12-13. Use `CatalogItem.categories`, instead. CategoryID *string `json:"category_id,omitempty" url:"category_id,omitempty"` // A set of IDs indicating the taxes enabled for @@ -4946,6 +4890,7 @@ type CatalogItem struct { // A server-generated plaintext version of the `description_html` field, without formatting tags. DescriptionPlaintext *string `json:"description_plaintext,omitempty" url:"description_plaintext,omitempty"` // A list of IDs representing channels, such as a Square Online site, where the item can be made visible or available. + // This field is read only and cannot be edited. Channels []string `json:"channels,omitempty" url:"channels,omitempty"` // Indicates whether this item is archived (`true`) or not (`false`). IsArchived *bool `json:"is_archived,omitempty" url:"is_archived,omitempty"` @@ -4995,27 +4940,6 @@ func (c *CatalogItem) GetIsTaxable() *bool { return c.IsTaxable } -func (c *CatalogItem) GetAvailableOnline() *bool { - if c == nil { - return nil - } - return c.AvailableOnline -} - -func (c *CatalogItem) GetAvailableForPickup() *bool { - if c == nil { - return nil - } - return c.AvailableForPickup -} - -func (c *CatalogItem) GetAvailableElectronically() *bool { - if c == nil { - return nil - } - return c.AvailableElectronically -} - func (c *CatalogItem) GetCategoryID() *string { if c == nil { return nil @@ -14066,6 +13990,65 @@ func (c *CreateBookingCustomAttributeDefinitionResponse) String() string { return fmt.Sprintf("%#v", c) } +// The response to the request to create a `BreakType`. The response contains +// the created `BreakType` object and might contain a set of `Error` objects if +// the request resulted in errors. +type CreateBreakTypeResponse struct { + // The `BreakType` that was created by the request. + BreakType *BreakType `json:"break_type,omitempty" url:"break_type,omitempty"` + // Any errors that occurred during the request. + Errors []*Error `json:"errors,omitempty" url:"errors,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CreateBreakTypeResponse) GetBreakType() *BreakType { + if c == nil { + return nil + } + return c.BreakType +} + +func (c *CreateBreakTypeResponse) GetErrors() []*Error { + if c == nil { + return nil + } + return c.Errors +} + +func (c *CreateBreakTypeResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *CreateBreakTypeResponse) UnmarshalJSON(data []byte) error { + type unmarshaler CreateBreakTypeResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CreateBreakTypeResponse(value) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *CreateBreakTypeResponse) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + type CreateCatalogImageRequest struct { // A unique string that identifies this CreateCatalogImage request. // Keys can be any valid string but must be unique for every CreateCatalogImage request. @@ -23389,6 +23372,75 @@ func (l *ListBookingCustomAttributesResponse) String() string { return fmt.Sprintf("%#v", l) } +// The response to a request for a set of `BreakType` objects. The response contains +// the requested `BreakType` objects and might contain a set of `Error` objects if +// the request resulted in errors. +type ListBreakTypesResponse struct { + // A page of `BreakType` results. + BreakTypes []*BreakType `json:"break_types,omitempty" url:"break_types,omitempty"` + // The value supplied in the subsequent request to fetch the next page + // of `BreakType` results. + Cursor *string `json:"cursor,omitempty" url:"cursor,omitempty"` + // Any errors that occurred during the request. + Errors []*Error `json:"errors,omitempty" url:"errors,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (l *ListBreakTypesResponse) GetBreakTypes() []*BreakType { + if l == nil { + return nil + } + return l.BreakTypes +} + +func (l *ListBreakTypesResponse) GetCursor() *string { + if l == nil { + return nil + } + return l.Cursor +} + +func (l *ListBreakTypesResponse) GetErrors() []*Error { + if l == nil { + return nil + } + return l.Errors +} + +func (l *ListBreakTypesResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties +} + +func (l *ListBreakTypesResponse) UnmarshalJSON(data []byte) error { + type unmarshaler ListBreakTypesResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *l = ListBreakTypesResponse(value) + extraProperties, err := internal.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l.rawJSON = json.RawMessage(data) + return nil +} + +func (l *ListBreakTypesResponse) String() string { + if len(l.rawJSON) > 0 { + if value, err := internal.StringifyJSON(l.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(l); err == nil { + return value + } + return fmt.Sprintf("%#v", l) +} + type ListCashDrawerShiftEventsResponse struct { // Opaque cursor for fetching the next page. Cursor is not present in // the last page of results. @@ -32240,19 +32292,21 @@ func (p *PaymentLinkRelatedResources) String() string { type PaymentOptions struct { // Indicates whether the `Payment` objects created from this `TerminalCheckout` are automatically // `COMPLETED` or left in an `APPROVED` state for later modification. + // + // Default: true Autocomplete *bool `json:"autocomplete,omitempty" url:"autocomplete,omitempty"` - // The duration of time after the payment's creation when Square automatically cancels the - // payment. This automatic cancellation applies only to payments that do not reach a terminal state - // (COMPLETED or CANCELED) before the `delay_duration` time period. + // The duration of time after the payment's creation when Square automatically resolves the + // payment. This automatic resolution applies only to payments that do not reach a terminal state + // (`COMPLETED` or `CANCELED`) before the `delay_duration` time period. // // This parameter should be specified as a time duration, in RFC 3339 format, with a minimum value - // of 1 minute. + // of 1 minute and a maximum value of 36 hours. This feature is only supported for card payments, + // and all payments will be considered card-present. + // + // This parameter can only be set for a delayed capture payment (`autocomplete=false`). For more + // information, see [Delayed Capture](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/delayed-capture#time-threshold). // - // Note: This feature is only supported for card payments. This parameter can only be set for a delayed - // capture payment (`autocomplete=false`). - // Default: - // - Card-present payments: "PT36H" (36 hours) from the creation time. - // - Card-not-present payments: "P7D" (7 days) from the creation time. + // Default: "PT36H" (36 hours) from the creation time DelayDuration *string `json:"delay_duration,omitempty" url:"delay_duration,omitempty"` // If set to `true` and charging a Square Gift Card, a payment might be returned with // `amount_money` equal to less than what was requested. For example, a request for $20 when charging @@ -32260,18 +32314,21 @@ type PaymentOptions struct { // to prompt the buyer for an additional payment to cover the remainder or cancel the Gift Card // payment. // - // This field cannot be `true` when `autocomplete = true`. - // This field cannot be `true` when an `order_id` isn't specified. + // This parameter can only be set for a delayed capture payment (`autocomplete=false`). // - // For more information, see - // [Take Partial Payments](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/partial-payments-with-gift-cards). + // For more information, see [Take Partial Payments](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/partial-payments-with-gift-cards). // // Default: false AcceptPartialAuthorization *bool `json:"accept_partial_authorization,omitempty" url:"accept_partial_authorization,omitempty"` - // The action to be applied to the payment when the delay_duration has elapsed. + // The action to be applied to the `Payment` when the delay_duration has elapsed. // The action must be CANCEL or COMPLETE. // - // This parameter can only be set for a delayed capture payment (when `autocomplete` is `false`). + // The action cannot be set to COMPLETE if an `order_id` is present on the TerminalCheckout. + // + // This parameter can only be set for a delayed capture payment (`autocomplete=false`). For more + // information, see [Delayed Capture](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/delayed-capture#time-threshold). + // + // Default: CANCEL // See [DelayAction](#type-delayaction) for possible values DelayAction *PaymentOptionsDelayAction `json:"delay_action,omitempty" url:"delay_action,omitempty"`