diff --git a/README.md b/README.md index b37384cd..abbafda7 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,10 @@ The following section explains how to use the advancedbilling library in a new p To use the package in your application, you can install the package from [pkg.go.dev](https://pkg.go.dev/) using the following command: ```bash -$ go get github.com/maxio-com/ab-golang-sdk@v0.2.1 +$ go get github.com/maxio-com/ab-golang-sdk@v0.3.0 ``` -You can also view the package at: https://pkg.go.dev/github.com/maxio-com/ab-golang-sdk@v0.2.1 +You can also view the package at: https://pkg.go.dev/github.com/maxio-com/ab-golang-sdk@v0.3.0 ## Initialize the API Client @@ -102,6 +102,7 @@ This API uses the following authentication schemes. * [API Exports](doc/controllers/api-exports.md) * [Advance Invoice](doc/controllers/advance-invoice.md) * [Billing Portal](doc/controllers/billing-portal.md) +* [Component Price Points](doc/controllers/component-price-points.md) * [Custom Fields](doc/controllers/custom-fields.md) * [Events-Based Billing Segments](doc/controllers/events-based-billing-segments.md) * [Payment Profiles](doc/controllers/payment-profiles.md) diff --git a/client.go b/client.go index 35a945db..69e6852a 100644 --- a/client.go +++ b/client.go @@ -22,6 +22,7 @@ type ClientInterface interface { BillingPortalController() *BillingPortalController CouponsController() *CouponsController ComponentsController() *ComponentsController + ComponentPricePointsController() *ComponentPricePointsController CustomersController() *CustomersController CustomFieldsController() *CustomFieldsController EventsController() *EventsController @@ -61,6 +62,7 @@ type client struct { billingPortalController BillingPortalController couponsController CouponsController componentsController ComponentsController + componentPricePointsController ComponentPricePointsController customersController CustomersController customFieldsController CustomFieldsController eventsController EventsController @@ -96,7 +98,7 @@ func NewClient(configuration Configuration) ClientInterface { configuration: configuration, } - client.userAgent = utilities.UpdateUserAgent("AB SDK Go:0.2.1 on OS {os-info}") + client.userAgent = utilities.UpdateUserAgent("AB SDK Go:0.3.0 on OS {os-info}") client.callBuilderFactory = callBuilderHandler( func(server string) string { if server == "" { @@ -118,6 +120,7 @@ func NewClient(configuration Configuration) ClientInterface { client.billingPortalController = *NewBillingPortalController(*baseController) client.couponsController = *NewCouponsController(*baseController) client.componentsController = *NewComponentsController(*baseController) + client.componentPricePointsController = *NewComponentPricePointsController(*baseController) client.customersController = *NewCustomersController(*baseController) client.customFieldsController = *NewCustomFieldsController(*baseController) client.eventsController = *NewEventsController(*baseController) @@ -182,6 +185,11 @@ func (c *client) ComponentsController() *ComponentsController { return &c.componentsController } +// ComponentPricePointsController returns the componentPricePointsController instance of the client. +func (c *client) ComponentPricePointsController() *ComponentPricePointsController { + return &c.componentPricePointsController +} + // CustomersController returns the customersController instance of the client. func (c *client) CustomersController() *CustomersController { return &c.customersController diff --git a/component_price_points_controller.go b/component_price_points_controller.go new file mode 100644 index 00000000..e2404c3c --- /dev/null +++ b/component_price_points_controller.go @@ -0,0 +1,419 @@ +package advancedbilling + +import ( + "context" + "fmt" + "github.com/apimatic/go-core-runtime/https" + "github.com/apimatic/go-core-runtime/utilities" + "github.com/maxio-com/ab-golang-sdk/errors" + "github.com/maxio-com/ab-golang-sdk/models" +) + +// ComponentPricePointsController represents a controller struct. +type ComponentPricePointsController struct { + baseController +} + +// NewComponentPricePointsController creates a new instance of ComponentPricePointsController. +// It takes a baseController as a parameter and returns a pointer to the ComponentPricePointsController. +func NewComponentPricePointsController(baseController baseController) *ComponentPricePointsController { + componentPricePointsController := ComponentPricePointsController{baseController: baseController} + return &componentPricePointsController +} + +// PromoteComponentPricePointToDefault takes context, componentId, pricePointId as parameters and +// returns an models.ApiResponse with models.ComponentResponse data and +// an error if there was an issue with the request or response. +// Sets a new default price point for the component. This new default will apply to all new subscriptions going forward - existing subscriptions will remain on their current price point. +// See [Price Points Documentation](https://chargify.zendesk.com/hc/en-us/articles/4407755865883#price-points) for more information on price points and moving subscriptions between price points. +// Note: Custom price points are not able to be set as the default for a component. +func (c *ComponentPricePointsController) PromoteComponentPricePointToDefault( + ctx context.Context, + componentId int, + pricePointId int) ( + models.ApiResponse[models.ComponentResponse], + error) { + req := c.prepareRequest( + ctx, + "PUT", + fmt.Sprintf("/components/%v/price_points/%v/default.json", componentId, pricePointId), + ) + req.Authenticate(NewAuth("BasicAuth")) + + var result models.ComponentResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// CreateComponentPricePoint takes context, componentId, body as parameters and +// returns an models.ApiResponse with models.ComponentPricePointResponse data and +// an error if there was an issue with the request or response. +// This endpoint can be used to create a new price point for an existing component. +func (c *ComponentPricePointsController) CreateComponentPricePoint( + ctx context.Context, + componentId int, + body *models.CreateComponentPricePointRequest) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) { + req := c.prepareRequest( + ctx, + "POST", + fmt.Sprintf("/components/%v/price_points.json", componentId), + ) + req.Authenticate(NewAuth("BasicAuth")) + req.Header("Content-Type", "application/json") + if body != nil { + req.Json(body) + } + + var result models.ComponentPricePointResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// ListComponentPricePointsInput represents the input of the ListComponentPricePoints endpoint. +type ListComponentPricePointsInput struct { + // The Chargify id of the component + ComponentId int + // Include an array of currency price data + CurrencyPrices *bool + // Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. + // Use in query `page=1`. + Page *int + // This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. + // Use in query `per_page=200`. + PerPage *int + // Use in query: `filter[type]=catalog,default`. + FilterType []models.PricePointType +} + +// ListComponentPricePoints takes context, componentId, currencyPrices, page, perPage, filterType as parameters and +// returns an models.ApiResponse with models.ComponentPricePointsResponse data and +// an error if there was an issue with the request or response. +// Use this endpoint to read current price points that are associated with a component. +// You may specify the component by using either the numeric id or the `handle:gold` syntax. +// When fetching a component's price points, if you have defined multiple currencies at the site level, you can optionally pass the `?currency_prices=true` query param to include an array of currency price data in the response. +// If the price point is set to `use_site_exchange_rate: true`, it will return pricing based on the current exchange rate. If the flag is set to false, it will return all of the defined prices for each currency. +func (c *ComponentPricePointsController) ListComponentPricePoints( + ctx context.Context, + input ListComponentPricePointsInput) ( + models.ApiResponse[models.ComponentPricePointsResponse], + error) { + req := c.prepareRequest( + ctx, + "GET", + fmt.Sprintf("/components/%v/price_points.json", input.ComponentId), + ) + req.Authenticate(NewAuth("BasicAuth")) + if input.CurrencyPrices != nil { + req.QueryParam("currency_prices", *input.CurrencyPrices) + } + if input.Page != nil { + req.QueryParam("page", *input.Page) + } + if input.PerPage != nil { + req.QueryParam("per_page", *input.PerPage) + } + if input.FilterType != nil { + req.QueryParam("filter[type]", input.FilterType) + } + + var result models.ComponentPricePointsResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentPricePointsResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// BulkCreateComponentPricePoints takes context, componentId, body as parameters and +// returns an models.ApiResponse with models.ComponentPricePointsResponse data and +// an error if there was an issue with the request or response. +// Use this endpoint to create multiple component price points in one request. +func (c *ComponentPricePointsController) BulkCreateComponentPricePoints( + ctx context.Context, + componentId string, + body *models.CreateComponentPricePointsRequest) ( + models.ApiResponse[models.ComponentPricePointsResponse], + error) { + req := c.prepareRequest( + ctx, + "POST", + fmt.Sprintf("/components/%v/price_points/bulk.json", componentId), + ) + req.Authenticate(NewAuth("BasicAuth")) + req.Header("Content-Type", "application/json") + if body != nil { + req.Json(body) + } + + var result models.ComponentPricePointsResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentPricePointsResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// UpdateComponentPricePoint takes context, componentId, pricePointId, body as parameters and +// returns an models.ApiResponse with models.ComponentPricePointResponse data and +// an error if there was an issue with the request or response. +// When updating a price point, it's prices can be updated as well by creating new prices or editing / removing existing ones. +// Passing in a price bracket without an `id` will attempt to create a new price. +// Including an `id` will update the corresponding price, and including the `_destroy` flag set to true along with the `id` will remove that price. +// Note: Custom price points cannot be updated directly. They must be edited through the Subscription. +func (c *ComponentPricePointsController) UpdateComponentPricePoint( + ctx context.Context, + componentId models.UpdateComponentPricePointComponentId, + pricePointId models.UpdateComponentPricePointPricePointId, + body *models.UpdateComponentPricePointRequest) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) { + req := c.prepareRequest( + ctx, + "PUT", + fmt.Sprintf("/components/%v/price_points/%v.json", componentId, pricePointId), + ) + req.Authenticate(NewAuth("BasicAuth")) + req.AppendErrors(map[string]https.ErrorBuilder[error]{ + "422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewErrorArrayMapResponse}, + }) + req.Header("Content-Type", "application/json") + if body != nil { + req.Json(body) + } + + var result models.ComponentPricePointResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// ReadComponentPricePoint takes context, componentId, pricePointId as parameters and +// returns an models.ApiResponse with models.ComponentPricePointResponse data and +// an error if there was an issue with the request or response. +// Use this endpoint to retrieve details for a specific component price point. You can achieve this by using either the component price point ID or handle. +func (c *ComponentPricePointsController) ReadComponentPricePoint( + ctx context.Context, + componentId models.ReadComponentPricePointComponentId, + pricePointId models.ReadComponentPricePointPricePointId) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) { + req := c.prepareRequest( + ctx, + "GET", + fmt.Sprintf("/components/%v/price_points/%v.json", componentId, pricePointId), + ) + req.Authenticate(NewAuth("BasicAuth")) + + var result models.ComponentPricePointResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// ArchiveComponentPricePoint takes context, componentId, pricePointId as parameters and +// returns an models.ApiResponse with models.ComponentPricePointResponse data and +// an error if there was an issue with the request or response. +// A price point can be archived at any time. Subscriptions using a price point that has been archived will continue using it until they're moved to another price point. +func (c *ComponentPricePointsController) ArchiveComponentPricePoint( + ctx context.Context, + componentId models.ArchiveComponentPricePointComponentId, + pricePointId models.ArchiveComponentPricePointPricePointId) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) { + req := c.prepareRequest( + ctx, + "DELETE", + fmt.Sprintf("/components/%v/price_points/%v.json", componentId, pricePointId), + ) + req.Authenticate(NewAuth("BasicAuth")) + req.AppendErrors(map[string]https.ErrorBuilder[error]{ + "422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewErrorListResponse}, + }) + + var result models.ComponentPricePointResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// UnarchiveComponentPricePoint takes context, componentId, pricePointId as parameters and +// returns an models.ApiResponse with models.ComponentPricePointResponse data and +// an error if there was an issue with the request or response. +// Use this endpoint to unarchive a component price point. +func (c *ComponentPricePointsController) UnarchiveComponentPricePoint( + ctx context.Context, + componentId int, + pricePointId int) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) { + req := c.prepareRequest( + ctx, + "PUT", + fmt.Sprintf("/components/%v/price_points/%v/unarchive.json", componentId, pricePointId), + ) + req.Authenticate(NewAuth("BasicAuth")) + + var result models.ComponentPricePointResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// CreateCurrencyPrices takes context, pricePointId, body as parameters and +// returns an models.ApiResponse with models.ComponentCurrencyPricesResponse data and +// an error if there was an issue with the request or response. +// This endpoint allows you to create currency prices for a given currency that has been defined on the site level in your settings. +// When creating currency prices, they need to mirror the structure of your primary pricing. For each price level defined on the component price point, there should be a matching price level created in the given currency. +// Note: Currency Prices are not able to be created for custom price points. +func (c *ComponentPricePointsController) CreateCurrencyPrices( + ctx context.Context, + pricePointId int, + body *models.CreateCurrencyPricesRequest) ( + models.ApiResponse[models.ComponentCurrencyPricesResponse], + error) { + req := c.prepareRequest( + ctx, + "POST", + fmt.Sprintf("/price_points/%v/currency_prices.json", pricePointId), + ) + req.Authenticate(NewAuth("BasicAuth")) + req.AppendErrors(map[string]https.ErrorBuilder[error]{ + "422": {Message: "Unprocessable Entity (WebDAV)", Unmarshaller: errors.NewErrorArrayMapResponse}, + }) + req.Header("Content-Type", "application/json") + if body != nil { + req.Json(body) + } + + var result models.ComponentCurrencyPricesResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentCurrencyPricesResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// UpdateCurrencyPrices takes context, pricePointId, body as parameters and +// returns an models.ApiResponse with models.ComponentCurrencyPricesResponse data and +// an error if there was an issue with the request or response. +// This endpoint allows you to update currency prices for a given currency that has been defined on the site level in your settings. +// Note: Currency Prices are not able to be updated for custom price points. +func (c *ComponentPricePointsController) UpdateCurrencyPrices( + ctx context.Context, + pricePointId int, + body *models.UpdateCurrencyPricesRequest) ( + models.ApiResponse[models.ComponentCurrencyPricesResponse], + error) { + req := c.prepareRequest( + ctx, + "PUT", + fmt.Sprintf("/price_points/%v/currency_prices.json", pricePointId), + ) + req.Authenticate(NewAuth("BasicAuth")) + req.AppendErrors(map[string]https.ErrorBuilder[error]{ + "422": {Message: "Unprocessable Entity (WebDAV)", Unmarshaller: errors.NewErrorArrayMapResponse}, + }) + req.Header("Content-Type", "application/json") + if body != nil { + req.Json(body) + } + + var result models.ComponentCurrencyPricesResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ComponentCurrencyPricesResponse](decoder) + return models.NewApiResponse(result, resp), err +} + +// ListAllComponentPricePointsInput represents the input of the ListAllComponentPricePoints endpoint. +type ListAllComponentPricePointsInput struct { + // Allows including additional data in the response. Use in query: `include=currency_prices`. + Include *models.ListComponentsPricePointsInclude + // Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. + // Use in query `page=1`. + Page *int + // This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. + // Use in query `per_page=200`. + PerPage *int + // Controls the order in which results are returned. + // Use in query `direction=asc`. + Direction *models.SortingDirection + // Filter to use for List PricePoints operations + Filter *models.ListPricePointsFilter +} + +// ListAllComponentPricePoints takes context, include, page, perPage, direction, filter as parameters and +// returns an models.ApiResponse with models.ListComponentsPricePointsResponse data and +// an error if there was an issue with the request or response. +// This method allows to retrieve a list of Components Price Points belonging to a Site. +func (c *ComponentPricePointsController) ListAllComponentPricePoints( + ctx context.Context, + input ListAllComponentPricePointsInput) ( + models.ApiResponse[models.ListComponentsPricePointsResponse], + error) { + req := c.prepareRequest(ctx, "GET", "/components_price_points.json") + req.Authenticate(NewAuth("BasicAuth")) + req.AppendErrors(map[string]https.ErrorBuilder[error]{ + "422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewErrorListResponse}, + }) + if input.Include != nil { + req.QueryParam("include", *input.Include) + } + if input.Page != nil { + req.QueryParam("page", *input.Page) + } + if input.PerPage != nil { + req.QueryParam("per_page", *input.PerPage) + } + if input.Direction != nil { + req.QueryParam("direction", *input.Direction) + } + if input.Filter != nil { + req.QueryParam("filter", *input.Filter) + } + var result models.ListComponentsPricePointsResponse + decoder, resp, err := req.CallAsJson() + if err != nil { + return models.NewApiResponse(result, resp), err + } + + result, err = utilities.DecodeResults[models.ListComponentsPricePointsResponse](decoder) + return models.NewApiResponse(result, resp), err +} diff --git a/components_controller.go b/components_controller.go index 1ec3204f..0be6d033 100644 --- a/components_controller.go +++ b/components_controller.go @@ -180,7 +180,7 @@ func (c *ComponentsController) CreatePrepaidUsageComponent( // an error if there was an issue with the request or response. // This request will create a component definition of kind **event_based_component** under the specified product family. Event-based component can then be added and “allocated” for a subscription. // Event-based components are similar to other component types, in that you define the component parameters (such as name and taxability) and the pricing. A key difference for the event-based component is that it must be attached to a metric. This is because the metric provides the component with the actual quantity used in computing what and how much will be billed each period for each subscription. -// So, instead of reporting usage directly for each component (as you would with metered components), the usage is derived from analysis of your events. +// So, instead of reporting usage directly for each component (as you would with metered components), the usage is derived from analysis of your events. // For more information on components, please see our documentation [here](https://maxio-chargify.zendesk.com/hc/en-us/articles/5405020625677). func (c *ComponentsController) CreateEventBasedComponent( ctx context.Context, @@ -436,35 +436,6 @@ func (c *ComponentsController) UpdateComponent( return models.NewApiResponse(result, resp), err } -// PromoteComponentPricePointToDefault takes context, componentId, pricePointId as parameters and -// returns an models.ApiResponse with models.ComponentResponse data and -// an error if there was an issue with the request or response. -// Sets a new default price point for the component. This new default will apply to all new subscriptions going forward - existing subscriptions will remain on their current price point. -// See [Price Points Documentation](https://chargify.zendesk.com/hc/en-us/articles/4407755865883#price-points) for more information on price points and moving subscriptions between price points. -// Note: Custom price points are not able to be set as the default for a component. -func (c *ComponentsController) PromoteComponentPricePointToDefault( - ctx context.Context, - componentId int, - pricePointId int) ( - models.ApiResponse[models.ComponentResponse], - error) { - req := c.prepareRequest( - ctx, - "PUT", - fmt.Sprintf("/components/%v/price_points/%v/default.json", componentId, pricePointId), - ) - req.Authenticate(NewAuth("BasicAuth")) - - var result models.ComponentResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentResponse](decoder) - return models.NewApiResponse(result, resp), err -} - // ListComponentsForProductFamilyInput represents the input of the ListComponentsForProductFamily endpoint. type ListComponentsForProductFamilyInput struct { // The Chargify id of the product family @@ -543,344 +514,3 @@ func (c *ComponentsController) ListComponentsForProductFamily( result, err = utilities.DecodeResults[[]models.ComponentResponse](decoder) return models.NewApiResponse(result, resp), err } - -// CreateComponentPricePoint takes context, componentId, body as parameters and -// returns an models.ApiResponse with models.ComponentPricePointResponse data and -// an error if there was an issue with the request or response. -// This endpoint can be used to create a new price point for an existing component. -func (c *ComponentsController) CreateComponentPricePoint( - ctx context.Context, - componentId int, - body *models.CreateComponentPricePointRequest) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) { - req := c.prepareRequest( - ctx, - "POST", - fmt.Sprintf("/components/%v/price_points.json", componentId), - ) - req.Authenticate(NewAuth("BasicAuth")) - req.Header("Content-Type", "application/json") - if body != nil { - req.Json(body) - } - - var result models.ComponentPricePointResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// ListComponentPricePointsInput represents the input of the ListComponentPricePoints endpoint. -type ListComponentPricePointsInput struct { - // The Chargify id of the component - ComponentId int - // Include an array of currency price data - CurrencyPrices *bool - // Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. - // Use in query `page=1`. - Page *int - // This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. - // Use in query `per_page=200`. - PerPage *int - // Use in query: `filter[type]=catalog,default`. - FilterType []models.PricePointType -} - -// ListComponentPricePoints takes context, componentId, currencyPrices, page, perPage, filterType as parameters and -// returns an models.ApiResponse with models.ComponentPricePointsResponse data and -// an error if there was an issue with the request or response. -// Use this endpoint to read current price points that are associated with a component. -// You may specify the component by using either the numeric id or the `handle:gold` syntax. -// When fetching a component's price points, if you have defined multiple currencies at the site level, you can optionally pass the `?currency_prices=true` query param to include an array of currency price data in the response. -// If the price point is set to `use_site_exchange_rate: true`, it will return pricing based on the current exchange rate. If the flag is set to false, it will return all of the defined prices for each currency. -func (c *ComponentsController) ListComponentPricePoints( - ctx context.Context, - input ListComponentPricePointsInput) ( - models.ApiResponse[models.ComponentPricePointsResponse], - error) { - req := c.prepareRequest( - ctx, - "GET", - fmt.Sprintf("/components/%v/price_points.json", input.ComponentId), - ) - req.Authenticate(NewAuth("BasicAuth")) - if input.CurrencyPrices != nil { - req.QueryParam("currency_prices", *input.CurrencyPrices) - } - if input.Page != nil { - req.QueryParam("page", *input.Page) - } - if input.PerPage != nil { - req.QueryParam("per_page", *input.PerPage) - } - if input.FilterType != nil { - req.QueryParam("filter[type]", input.FilterType) - } - - var result models.ComponentPricePointsResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentPricePointsResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// BulkCreateComponentPricePoints takes context, componentId, body as parameters and -// returns an models.ApiResponse with models.ComponentPricePointsResponse data and -// an error if there was an issue with the request or response. -// Use this endpoint to create multiple component price points in one request. -func (c *ComponentsController) BulkCreateComponentPricePoints( - ctx context.Context, - componentId string, - body *models.CreateComponentPricePointsRequest) ( - models.ApiResponse[models.ComponentPricePointsResponse], - error) { - req := c.prepareRequest( - ctx, - "POST", - fmt.Sprintf("/components/%v/price_points/bulk.json", componentId), - ) - req.Authenticate(NewAuth("BasicAuth")) - req.Header("Content-Type", "application/json") - if body != nil { - req.Json(body) - } - - var result models.ComponentPricePointsResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentPricePointsResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// UpdateComponentPricePoint takes context, componentId, pricePointId, body as parameters and -// returns an models.ApiResponse with models.ComponentPricePointResponse data and -// an error if there was an issue with the request or response. -// When updating a price point, it's prices can be updated as well by creating new prices or editing / removing existing ones. -// Passing in a price bracket without an `id` will attempt to create a new price. -// Including an `id` will update the corresponding price, and including the `_destroy` flag set to true along with the `id` will remove that price. -// Note: Custom price points cannot be updated directly. They must be edited through the Subscription. -func (c *ComponentsController) UpdateComponentPricePoint( - ctx context.Context, - componentId int, - pricePointId int, - body *models.UpdateComponentPricePointRequest) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) { - req := c.prepareRequest( - ctx, - "PUT", - fmt.Sprintf("/components/%v/price_points/%v.json", componentId, pricePointId), - ) - req.Authenticate(NewAuth("BasicAuth")) - req.AppendErrors(map[string]https.ErrorBuilder[error]{ - "422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewErrorArrayMapResponse}, - }) - req.Header("Content-Type", "application/json") - if body != nil { - req.Json(body) - } - - var result models.ComponentPricePointResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// ArchiveComponentPricePoint takes context, componentId, pricePointId as parameters and -// returns an models.ApiResponse with models.ComponentPricePointResponse data and -// an error if there was an issue with the request or response. -// A price point can be archived at any time. Subscriptions using a price point that has been archived will continue using it until they're moved to another price point. -func (c *ComponentsController) ArchiveComponentPricePoint( - ctx context.Context, - componentId int, - pricePointId int) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) { - req := c.prepareRequest( - ctx, - "DELETE", - fmt.Sprintf("/components/%v/price_points/%v.json", componentId, pricePointId), - ) - req.Authenticate(NewAuth("BasicAuth")) - req.AppendErrors(map[string]https.ErrorBuilder[error]{ - "422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewErrorListResponse}, - }) - - var result models.ComponentPricePointResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// UnarchiveComponentPricePoint takes context, componentId, pricePointId as parameters and -// returns an models.ApiResponse with models.ComponentPricePointResponse data and -// an error if there was an issue with the request or response. -// Use this endpoint to unarchive a component price point. -func (c *ComponentsController) UnarchiveComponentPricePoint( - ctx context.Context, - componentId int, - pricePointId int) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) { - req := c.prepareRequest( - ctx, - "PUT", - fmt.Sprintf("/components/%v/price_points/%v/unarchive.json", componentId, pricePointId), - ) - req.Authenticate(NewAuth("BasicAuth")) - - var result models.ComponentPricePointResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentPricePointResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// CreateCurrencyPrices takes context, pricePointId, body as parameters and -// returns an models.ApiResponse with models.ComponentCurrencyPricesResponse data and -// an error if there was an issue with the request or response. -// This endpoint allows you to create currency prices for a given currency that has been defined on the site level in your settings. -// When creating currency prices, they need to mirror the structure of your primary pricing. For each price level defined on the component price point, there should be a matching price level created in the given currency. -// Note: Currency Prices are not able to be created for custom price points. -func (c *ComponentsController) CreateCurrencyPrices( - ctx context.Context, - pricePointId int, - body *models.CreateCurrencyPricesRequest) ( - models.ApiResponse[models.ComponentCurrencyPricesResponse], - error) { - req := c.prepareRequest( - ctx, - "POST", - fmt.Sprintf("/price_points/%v/currency_prices.json", pricePointId), - ) - req.Authenticate(NewAuth("BasicAuth")) - req.AppendErrors(map[string]https.ErrorBuilder[error]{ - "422": {Message: "Unprocessable Entity (WebDAV)", Unmarshaller: errors.NewErrorArrayMapResponse}, - }) - req.Header("Content-Type", "application/json") - if body != nil { - req.Json(body) - } - - var result models.ComponentCurrencyPricesResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentCurrencyPricesResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// UpdateCurrencyPrices takes context, pricePointId, body as parameters and -// returns an models.ApiResponse with models.ComponentCurrencyPricesResponse data and -// an error if there was an issue with the request or response. -// This endpoint allows you to update currency prices for a given currency that has been defined on the site level in your settings. -// Note: Currency Prices are not able to be updated for custom price points. -func (c *ComponentsController) UpdateCurrencyPrices( - ctx context.Context, - pricePointId int, - body *models.UpdateCurrencyPricesRequest) ( - models.ApiResponse[models.ComponentCurrencyPricesResponse], - error) { - req := c.prepareRequest( - ctx, - "PUT", - fmt.Sprintf("/price_points/%v/currency_prices.json", pricePointId), - ) - req.Authenticate(NewAuth("BasicAuth")) - req.AppendErrors(map[string]https.ErrorBuilder[error]{ - "422": {Message: "Unprocessable Entity (WebDAV)", Unmarshaller: errors.NewErrorArrayMapResponse}, - }) - req.Header("Content-Type", "application/json") - if body != nil { - req.Json(body) - } - - var result models.ComponentCurrencyPricesResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ComponentCurrencyPricesResponse](decoder) - return models.NewApiResponse(result, resp), err -} - -// ListAllComponentPricePointsInput represents the input of the ListAllComponentPricePoints endpoint. -type ListAllComponentPricePointsInput struct { - // Allows including additional data in the response. Use in query: `include=currency_prices`. - Include *models.ListComponentsPricePointsInclude - // Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. - // Use in query `page=1`. - Page *int - // This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. - // Use in query `per_page=200`. - PerPage *int - // Controls the order in which results are returned. - // Use in query `direction=asc`. - Direction *models.SortingDirection - // Filter to use for List PricePoints operations - Filter *models.ListPricePointsFilter -} - -// ListAllComponentPricePoints takes context, include, page, perPage, direction, filter as parameters and -// returns an models.ApiResponse with models.ListComponentsPricePointsResponse data and -// an error if there was an issue with the request or response. -// This method allows to retrieve a list of Components Price Points belonging to a Site. -func (c *ComponentsController) ListAllComponentPricePoints( - ctx context.Context, - input ListAllComponentPricePointsInput) ( - models.ApiResponse[models.ListComponentsPricePointsResponse], - error) { - req := c.prepareRequest(ctx, "GET", "/components_price_points.json") - req.Authenticate(NewAuth("BasicAuth")) - req.AppendErrors(map[string]https.ErrorBuilder[error]{ - "422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewErrorListResponse}, - }) - if input.Include != nil { - req.QueryParam("include", *input.Include) - } - if input.Page != nil { - req.QueryParam("page", *input.Page) - } - if input.PerPage != nil { - req.QueryParam("per_page", *input.PerPage) - } - if input.Direction != nil { - req.QueryParam("direction", *input.Direction) - } - if input.Filter != nil { - req.QueryParam("filter", *input.Filter) - } - var result models.ListComponentsPricePointsResponse - decoder, resp, err := req.CallAsJson() - if err != nil { - return models.NewApiResponse(result, resp), err - } - - result, err = utilities.DecodeResults[models.ListComponentsPricePointsResponse](decoder) - return models.NewApiResponse(result, resp), err -} diff --git a/doc/client.md b/doc/client.md index 8b2bdbe7..5152e299 100644 --- a/doc/client.md +++ b/doc/client.md @@ -47,6 +47,7 @@ The gateway for the SDK. This class acts as a factory for the Controllers and al | billingPortal | Gets BillingPortalController | | coupons | Gets CouponsController | | components | Gets ComponentsController | +| componentPricePoints | Gets ComponentPricePointsController | | customers | Gets CustomersController | | customFields | Gets CustomFieldsController | | events | Gets EventsController | diff --git a/doc/controllers/component-price-points.md b/doc/controllers/component-price-points.md new file mode 100644 index 00000000..66d28c31 --- /dev/null +++ b/doc/controllers/component-price-points.md @@ -0,0 +1,951 @@ +# Component Price Points + +```go +componentPricePointsController := client.ComponentPricePointsController() +``` + +## Class Name + +`ComponentPricePointsController` + +## Methods + +* [Promote Component Price Point to Default](../../doc/controllers/component-price-points.md#promote-component-price-point-to-default) +* [Create Component Price Point](../../doc/controllers/component-price-points.md#create-component-price-point) +* [List Component Price Points](../../doc/controllers/component-price-points.md#list-component-price-points) +* [Bulk Create Component Price Points](../../doc/controllers/component-price-points.md#bulk-create-component-price-points) +* [Update Component Price Point](../../doc/controllers/component-price-points.md#update-component-price-point) +* [Read Component Price Point](../../doc/controllers/component-price-points.md#read-component-price-point) +* [Archive Component Price Point](../../doc/controllers/component-price-points.md#archive-component-price-point) +* [Unarchive Component Price Point](../../doc/controllers/component-price-points.md#unarchive-component-price-point) +* [Create Currency Prices](../../doc/controllers/component-price-points.md#create-currency-prices) +* [Update Currency Prices](../../doc/controllers/component-price-points.md#update-currency-prices) +* [List All Component Price Points](../../doc/controllers/component-price-points.md#list-all-component-price-points) + + +# Promote Component Price Point to Default + +Sets a new default price point for the component. This new default will apply to all new subscriptions going forward - existing subscriptions will remain on their current price point. + +See [Price Points Documentation](https://chargify.zendesk.com/hc/en-us/articles/4407755865883#price-points) for more information on price points and moving subscriptions between price points. + +Note: Custom price points are not able to be set as the default for a component. + +```go +PromoteComponentPricePointToDefault( + ctx context.Context, + componentId int, + pricePointId int) ( + models.ApiResponse[models.ComponentResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | `int` | Template, Required | The Chargify id of the component to which the price point belongs | +| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | + +## Response Type + +[`models.ComponentResponse`](../../doc/models/component-response.md) + +## Example Usage + +```go +ctx := context.Background() + +componentId := 222 + +pricePointId := 10 + +apiResponse, err := componentPricePointsController.PromoteComponentPricePointToDefault(ctx, componentId, pricePointId) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "component": { + "id": 292609, + "name": "Text messages", + "pricing_scheme": "stairstep", + "unit_name": "text message", + "unit_price": null, + "product_family_id": 528484, + "price_per_unit_in_cents": null, + "kind": "metered_component", + "archived": false, + "taxable": false, + "description": null, + "created_at": "2019-08-02T05:54:53-04:00", + "prices": [ + { + "id": 47, + "component_id": 292609, + "starting_quantity": 1, + "ending_quantity": null, + "unit_price": "1.0", + "price_point_id": 173, + "formatted_unit_price": "$1.00" + } + ], + "default_price_point_name": "Original" + } +} +``` + + +# Create Component Price Point + +This endpoint can be used to create a new price point for an existing component. + +```go +CreateComponentPricePoint( + ctx context.Context, + componentId int, + body *models.CreateComponentPricePointRequest) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | `int` | Template, Required | The Chargify id of the component | +| `body` | [`*models.CreateComponentPricePointRequest`](../../doc/models/create-component-price-point-request.md) | Body, Optional | - | + +## Response Type + +[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) + +## Example Usage + +```go +ctx := context.Background() + +componentId := 222 + +body := models.CreateComponentPricePointRequest{ + PricePoint: models.CreateComponentPricePointRequestPricePointContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ + Name: "Wholesale", + Handle: models.ToPointer("wholesale-handle"), + PricingScheme: models.PricingScheme("stairstep"), + Prices: []models.Price{ + models.Price{ + StartingQuantity: models.PriceStartingQuantityContainer.FromString("1"), + EndingQuantity: models.NewOptional(models.ToPointer(models.PriceEndingQuantityContainer.FromString("100"))), + UnitPrice: models.PriceUnitPriceContainer.FromString("5.00"), + }, + models.Price{ + StartingQuantity: models.PriceStartingQuantityContainer.FromString("101"), + UnitPrice: models.PriceUnitPriceContainer.FromString("4.00"), + }, + }, + UseSiteExchangeRate: models.ToPointer(false), + }), +} + +apiResponse, err := componentPricePointsController.CreateComponentPricePoint(ctx, componentId, &body) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + + +# List Component Price Points + +Use this endpoint to read current price points that are associated with a component. + +You may specify the component by using either the numeric id or the `handle:gold` syntax. + +When fetching a component's price points, if you have defined multiple currencies at the site level, you can optionally pass the `?currency_prices=true` query param to include an array of currency price data in the response. + +If the price point is set to `use_site_exchange_rate: true`, it will return pricing based on the current exchange rate. If the flag is set to false, it will return all of the defined prices for each currency. + +```go +ListComponentPricePoints( + ctx context.Context, + input ListComponentPricePointsInput) ( + models.ApiResponse[models.ComponentPricePointsResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | `int` | Template, Required | The Chargify id of the component | +| `currencyPrices` | `*bool` | Query, Optional | Include an array of currency price data | +| `page` | `*int` | Query, Optional | Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
Use in query `page=1`. | +| `perPage` | `*int` | Query, Optional | This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query `per_page=200`. | +| `filterType` | [`[]models.PricePointType`](../../doc/models/price-point-type.md) | Query, Optional | Use in query: `filter[type]=catalog,default`. | + +## Response Type + +[`models.ComponentPricePointsResponse`](../../doc/models/component-price-points-response.md) + +## Example Usage + +```go +ctx := context.Background() + +collectedInput := advancedbilling.ListComponentPricePointsInput{ + ComponentId: 222, + Page: models.ToPointer(2), + PerPage: models.ToPointer(50), +Liquid error: Value cannot be null. (Parameter 'key')} + +apiResponse, err := componentPricePointsController.ListComponentPricePoints(ctx, collectedInput) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "price_points": [ + { + "id": 80, + "default": false, + "name": "Wholesale Two", + "pricing_scheme": "per_unit", + "component_id": 74, + "handle": "wholesale-two", + "archived_at": null, + "created_at": "2017-07-05T13:55:40-04:00", + "updated_at": "2017-07-05T13:55:40-04:00", + "prices": [ + { + "id": 121, + "component_id": 74, + "starting_quantity": 1, + "ending_quantity": null, + "unit_price": "5.0" + } + ] + }, + { + "id": 81, + "default": false, + "name": "MSRP", + "pricing_scheme": "per_unit", + "component_id": 74, + "handle": "msrp", + "archived_at": null, + "created_at": "2017-07-05T13:55:40-04:00", + "updated_at": "2017-07-05T13:55:40-04:00", + "prices": [ + { + "id": 122, + "component_id": 74, + "starting_quantity": 1, + "ending_quantity": null, + "unit_price": "4.0" + } + ] + } + ] +} +``` + + +# Bulk Create Component Price Points + +Use this endpoint to create multiple component price points in one request. + +```go +BulkCreateComponentPricePoints( + ctx context.Context, + componentId string, + body *models.CreateComponentPricePointsRequest) ( + models.ApiResponse[models.ComponentPricePointsResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | `string` | Template, Required | The Chargify id of the component for which you want to fetch price points. | +| `body` | [`*models.CreateComponentPricePointsRequest`](../../doc/models/create-component-price-points-request.md) | Body, Optional | - | + +## Response Type + +[`models.ComponentPricePointsResponse`](../../doc/models/component-price-points-response.md) + +## Example Usage + +```go +ctx := context.Background() + +componentId := "component_id8" + +body := models.CreateComponentPricePointsRequest{ + PricePoints: []models.CreateComponentPricePointsRequestPricePoints{ + models.CreateComponentPricePointsRequestPricePointsContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ + Name: "Wholesale", + Handle: models.ToPointer("wholesale"), + PricingScheme: models.PricingScheme("per_unit"), + Prices: []models.Price{ + models.Price{ + StartingQuantity: models.PriceStartingQuantityContainer.FromNumber(1), + UnitPrice: models.PriceUnitPriceContainer.FromPrecision(float64(5)), + }, + }, + }), + models.CreateComponentPricePointsRequestPricePointsContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ + Name: "MSRP", + Handle: models.ToPointer("msrp"), + PricingScheme: models.PricingScheme("per_unit"), + Prices: []models.Price{ + models.Price{ + StartingQuantity: models.PriceStartingQuantityContainer.FromNumber(1), + UnitPrice: models.PriceUnitPriceContainer.FromPrecision(float64(4)), + }, + }, + }), + models.CreateComponentPricePointsRequestPricePointsContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ + Name: "Special Pricing", + Handle: models.ToPointer("special"), + PricingScheme: models.PricingScheme("per_unit"), + Prices: []models.Price{ + models.Price{ + StartingQuantity: models.PriceStartingQuantityContainer.FromNumber(1), + UnitPrice: models.PriceUnitPriceContainer.FromPrecision(float64(5)), + }, + }, + }), + }, +} + +apiResponse, err := componentPricePointsController.BulkCreateComponentPricePoints(ctx, componentId, &body) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "price_points": [ + { + "id": 80, + "default": false, + "name": "Wholesale Two", + "pricing_scheme": "per_unit", + "component_id": 74, + "handle": "wholesale-two", + "archived_at": null, + "created_at": "2017-07-05T13:55:40-04:00", + "updated_at": "2017-07-05T13:55:40-04:00", + "prices": [ + { + "id": 121, + "component_id": 74, + "starting_quantity": 1, + "ending_quantity": null, + "unit_price": "5.0" + } + ] + }, + { + "id": 81, + "default": false, + "name": "MSRP", + "pricing_scheme": "per_unit", + "component_id": 74, + "handle": "msrp", + "archived_at": null, + "created_at": "2017-07-05T13:55:40-04:00", + "updated_at": "2017-07-05T13:55:40-04:00", + "prices": [ + { + "id": 122, + "component_id": 74, + "starting_quantity": 1, + "ending_quantity": null, + "unit_price": "4.0" + } + ] + } + ] +} +``` + + +# Update Component Price Point + +When updating a price point, it's prices can be updated as well by creating new prices or editing / removing existing ones. + +Passing in a price bracket without an `id` will attempt to create a new price. + +Including an `id` will update the corresponding price, and including the `_destroy` flag set to true along with the `id` will remove that price. + +Note: Custom price points cannot be updated directly. They must be edited through the Subscription. + +```go +UpdateComponentPricePoint( + ctx context.Context, + componentId models.UpdateComponentPricePointComponentId, + pricePointId models.UpdateComponentPricePointPricePointId, + body *models.UpdateComponentPricePointRequest) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | [`models.UpdateComponentPricePointComponentId`](../../doc/models/containers/update-component-price-point-component-id.md) | Template, Required | This is a container for one-of cases. | +| `pricePointId` | [`models.UpdateComponentPricePointPricePointId`](../../doc/models/containers/update-component-price-point-price-point-id.md) | Template, Required | This is a container for one-of cases. | +| `body` | [`*models.UpdateComponentPricePointRequest`](../../doc/models/update-component-price-point-request.md) | Body, Optional | - | + +## Response Type + +[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) + +## Example Usage + +```go +ctx := context.Background() + +componentId := models.UpdateComponentPricePointComponentIdContainer.FromNumber(144) + +pricePointId := models.UpdateComponentPricePointPricePointIdContainer.FromNumber(188) + +body := models.UpdateComponentPricePointRequest{ + PricePoint: models.ToPointer(models.UpdateComponentPricePoint{ + Name: models.ToPointer("Default"), + Prices: []models.UpdatePrice{ + models.UpdatePrice{ + Id: models.ToPointer(1), + EndingQuantity: models.ToPointer(models.UpdatePriceEndingQuantityContainer.FromNumber(100)), + UnitPrice: models.ToPointer(models.UpdatePriceUnitPriceContainer.FromPrecision(float64(5))), + }, + models.UpdatePrice{ + Id: models.ToPointer(2), + Destroy: models.ToPointer(true), + }, + models.UpdatePrice{ + UnitPrice: models.ToPointer(models.UpdatePriceUnitPriceContainer.FromPrecision(float64(4))), + StartingQuantity: models.ToPointer(models.UpdatePriceStartingQuantityContainer.FromNumber(101)), + }, + }, + }), +} + +apiResponse, err := componentPricePointsController.UpdateComponentPricePoint(ctx, componentId, pricePointId, &body) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Errors + +| HTTP Status Code | Error Description | Exception Class | +| --- | --- | --- | +| 422 | Unprocessable Entity (WebDAV) | [`ErrorArrayMapResponseException`](../../doc/models/error-array-map-response-exception.md) | + + +# Read Component Price Point + +Use this endpoint to retrieve details for a specific component price point. You can achieve this by using either the component price point ID or handle. + +```go +ReadComponentPricePoint( + ctx context.Context, + componentId models.ReadComponentPricePointComponentId, + pricePointId models.ReadComponentPricePointPricePointId) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | [`models.ReadComponentPricePointComponentId`](../../doc/models/containers/read-component-price-point-component-id.md) | Template, Required | This is a container for one-of cases. | +| `pricePointId` | [`models.ReadComponentPricePointPricePointId`](../../doc/models/containers/read-component-price-point-price-point-id.md) | Template, Required | This is a container for one-of cases. | + +## Response Type + +[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) + +## Example Usage + +```go +ctx := context.Background() + +componentId := models.ReadComponentPricePointComponentIdContainer.FromNumber(144) + +pricePointId := models.ReadComponentPricePointPricePointIdContainer.FromNumber(188) + +apiResponse, err := componentPricePointsController.ReadComponentPricePoint(ctx, componentId, pricePointId) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + + +# Archive Component Price Point + +A price point can be archived at any time. Subscriptions using a price point that has been archived will continue using it until they're moved to another price point. + +```go +ArchiveComponentPricePoint( + ctx context.Context, + componentId models.ArchiveComponentPricePointComponentId, + pricePointId models.ArchiveComponentPricePointPricePointId) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | [`models.ArchiveComponentPricePointComponentId`](../../doc/models/containers/archive-component-price-point-component-id.md) | Template, Required | This is a container for one-of cases. | +| `pricePointId` | [`models.ArchiveComponentPricePointPricePointId`](../../doc/models/containers/archive-component-price-point-price-point-id.md) | Template, Required | This is a container for one-of cases. | + +## Response Type + +[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) + +## Example Usage + +```go +ctx := context.Background() + +componentId := models.ArchiveComponentPricePointComponentIdContainer.FromNumber(144) + +pricePointId := models.ArchiveComponentPricePointPricePointIdContainer.FromNumber(188) + +apiResponse, err := componentPricePointsController.ArchiveComponentPricePoint(ctx, componentId, pricePointId) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "price_point": { + "id": 79, + "default": false, + "name": "Wholesale", + "pricing_scheme": "stairstep", + "component_id": 74, + "handle": "wholesale-handle", + "archived_at": "2017-07-06T15:04:00-04:00", + "created_at": "2017-07-05T13:44:30-04:00", + "updated_at": "2017-07-05T13:44:30-04:00", + "prices": [ + { + "id": 119, + "component_id": 74, + "starting_quantity": 1, + "ending_quantity": 100, + "unit_price": "5.0" + }, + { + "id": 120, + "component_id": 74, + "starting_quantity": 101, + "ending_quantity": null, + "unit_price": "4.0" + } + ] + } +} +``` + +## Errors + +| HTTP Status Code | Error Description | Exception Class | +| --- | --- | --- | +| 422 | Unprocessable Entity (WebDAV) | [`ErrorListResponseException`](../../doc/models/error-list-response-exception.md) | + + +# Unarchive Component Price Point + +Use this endpoint to unarchive a component price point. + +```go +UnarchiveComponentPricePoint( + ctx context.Context, + componentId int, + pricePointId int) ( + models.ApiResponse[models.ComponentPricePointResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `componentId` | `int` | Template, Required | The Chargify id of the component to which the price point belongs | +| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | + +## Response Type + +[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) + +## Example Usage + +```go +ctx := context.Background() + +componentId := 222 + +pricePointId := 10 + +apiResponse, err := componentPricePointsController.UnarchiveComponentPricePoint(ctx, componentId, pricePointId) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "price_point": { + "id": 79, + "default": false, + "name": "Wholesale", + "pricing_scheme": "stairstep", + "component_id": 74, + "handle": "wholesale-handle", + "archived_at": null, + "created_at": "2017-07-05T13:44:30-04:00", + "updated_at": "2017-07-05T13:44:30-04:00", + "prices": [ + { + "id": 119, + "component_id": 74, + "starting_quantity": 1, + "ending_quantity": 100, + "unit_price": "5.0" + }, + { + "id": 120, + "component_id": 74, + "starting_quantity": 101, + "ending_quantity": null, + "unit_price": "4.0" + } + ] + } +} +``` + + +# Create Currency Prices + +This endpoint allows you to create currency prices for a given currency that has been defined on the site level in your settings. + +When creating currency prices, they need to mirror the structure of your primary pricing. For each price level defined on the component price point, there should be a matching price level created in the given currency. + +Note: Currency Prices are not able to be created for custom price points. + +```go +CreateCurrencyPrices( + ctx context.Context, + pricePointId int, + body *models.CreateCurrencyPricesRequest) ( + models.ApiResponse[models.ComponentCurrencyPricesResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | +| `body` | [`*models.CreateCurrencyPricesRequest`](../../doc/models/create-currency-prices-request.md) | Body, Optional | - | + +## Response Type + +[`models.ComponentCurrencyPricesResponse`](../../doc/models/component-currency-prices-response.md) + +## Example Usage + +```go +ctx := context.Background() + +pricePointId := 10 + +body := models.CreateCurrencyPricesRequest{ + CurrencyPrices: []models.CreateCurrencyPrice{ + models.CreateCurrencyPrice{ + Currency: models.ToPointer("EUR"), + Price: models.ToPointer(float64(50)), + PriceId: models.ToPointer(20), + }, + models.CreateCurrencyPrice{ + Currency: models.ToPointer("EUR"), + Price: models.ToPointer(float64(40)), + PriceId: models.ToPointer(21), + }, + }, +} + +apiResponse, err := componentPricePointsController.CreateCurrencyPrices(ctx, pricePointId, &body) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "currency_prices": [ + { + "id": 100, + "currency": "EUR", + "price": "123", + "formatted_price": "€123,00", + "price_id": 32669, + "price_point_id": 25554 + } + ] +} +``` + +## Errors + +| HTTP Status Code | Error Description | Exception Class | +| --- | --- | --- | +| 422 | Unprocessable Entity (WebDAV) | [`ErrorArrayMapResponseException`](../../doc/models/error-array-map-response-exception.md) | + + +# Update Currency Prices + +This endpoint allows you to update currency prices for a given currency that has been defined on the site level in your settings. + +Note: Currency Prices are not able to be updated for custom price points. + +```go +UpdateCurrencyPrices( + ctx context.Context, + pricePointId int, + body *models.UpdateCurrencyPricesRequest) ( + models.ApiResponse[models.ComponentCurrencyPricesResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | +| `body` | [`*models.UpdateCurrencyPricesRequest`](../../doc/models/update-currency-prices-request.md) | Body, Optional | - | + +## Response Type + +[`models.ComponentCurrencyPricesResponse`](../../doc/models/component-currency-prices-response.md) + +## Example Usage + +```go +ctx := context.Background() + +pricePointId := 10 + +body := models.UpdateCurrencyPricesRequest{ + CurrencyPrices: []models.UpdateCurrencyPrice{ + models.UpdateCurrencyPrice{ + Id: 100, + Price: 51, + }, + models.UpdateCurrencyPrice{ + Id: 101, + Price: 41, + }, + }, +} + +apiResponse, err := componentPricePointsController.UpdateCurrencyPrices(ctx, pricePointId, &body) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "currency_prices": [ + { + "id": 100, + "currency": "EUR", + "price": "123", + "formatted_price": "€123,00", + "price_id": 32669, + "price_point_id": 25554 + } + ] +} +``` + +## Errors + +| HTTP Status Code | Error Description | Exception Class | +| --- | --- | --- | +| 422 | Unprocessable Entity (WebDAV) | [`ErrorArrayMapResponseException`](../../doc/models/error-array-map-response-exception.md) | + + +# List All Component Price Points + +This method allows to retrieve a list of Components Price Points belonging to a Site. + +```go +ListAllComponentPricePoints( + ctx context.Context, + input ListAllComponentPricePointsInput) ( + models.ApiResponse[models.ListComponentsPricePointsResponse], + error) +``` + +## Parameters + +| Parameter | Type | Tags | Description | +| --- | --- | --- | --- | +| `include` | [`*models.ListComponentsPricePointsInclude`](../../doc/models/list-components-price-points-include.md) | Query, Optional | Allows including additional data in the response. Use in query: `include=currency_prices`. | +| `page` | `*int` | Query, Optional | Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
Use in query `page=1`. | +| `perPage` | `*int` | Query, Optional | This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query `per_page=200`. | +| `direction` | [`*models.SortingDirection`](../../doc/models/sorting-direction.md) | Query, Optional | Controls the order in which results are returned.
Use in query `direction=asc`. | +| `filter` | [`*models.ListPricePointsFilter`](../../doc/models/list-price-points-filter.md) | Query, Optional | Filter to use for List PricePoints operations | + +## Response Type + +[`models.ListComponentsPricePointsResponse`](../../doc/models/list-components-price-points-response.md) + +## Example Usage + +```go +ctx := context.Background() + +collectedInput := advancedbilling.ListAllComponentPricePointsInput{ + Include: models.ToPointer(models.ListComponentsPricePointsInclude("currency_prices")), + Page: models.ToPointer(2), + PerPage: models.ToPointer(50), + Filter: models.ToPointer(models.ListPricePointsFilter{ + StartDate: models.ToPointer(parseTime(models.DEFAULT_DATE, "2011-12-17", func(err error) { log.Fatalln(err) })), + EndDate: models.ToPointer(parseTime(models.DEFAULT_DATE, "2011-12-15", func(err error) { log.Fatalln(err) })), + StartDatetime: models.ToPointer(parseTime(time.RFC3339, "12/19/2011 09:15:30", func(err error) { log.Fatalln(err) })), + EndDatetime: models.ToPointer(parseTime(time.RFC3339, "06/07/2019 17:20:06", func(err error) { log.Fatalln(err) })), + Type: []models.PricePointType{ + models.PricePointType("catalog"), + models.PricePointType("default"), + models.PricePointType("custom"), + }, + Ids: []int{ + 1, + 2, + 3, + }, + }), +} + +apiResponse, err := componentPricePointsController.ListAllComponentPricePoints(ctx, collectedInput) +if err != nil { + log.Fatalln(err) +} else { + // Printing the result and response + fmt.Println(apiResponse.Data) + fmt.Println(apiResponse.Response.StatusCode) +} +``` + +## Example Response *(as JSON)* + +```json +{ + "price_points": [ + { + "id": 1, + "name": "Auto-created", + "type": "default", + "pricing_scheme": "per_unit", + "component_id": 2, + "handle": "auto-created", + "archived_at": null, + "created_at": "2021-02-21T11:05:57-05:00", + "updated_at": "2021-02-21T11:05:57-05:00", + "prices": [ + { + "id": 3, + "component_id": 2, + "starting_quantity": 0, + "ending_quantity": null, + "unit_price": "1.0", + "price_point_id": 1, + "formatted_unit_price": "$1.00", + "segment_id": null + } + ], + "tax_included": false + } + ] +} +``` + +## Errors + +| HTTP Status Code | Error Description | Exception Class | +| --- | --- | --- | +| 422 | Unprocessable Entity (WebDAV) | [`ErrorListResponseException`](../../doc/models/error-list-response-exception.md) | + diff --git a/doc/controllers/components.md b/doc/controllers/components.md index 80666425..53484638 100644 --- a/doc/controllers/components.md +++ b/doc/controllers/components.md @@ -21,17 +21,7 @@ componentsController := client.ComponentsController() * [Archive Component](../../doc/controllers/components.md#archive-component) * [List Components](../../doc/controllers/components.md#list-components) * [Update Component](../../doc/controllers/components.md#update-component) -* [Promote Component Price Point to Default](../../doc/controllers/components.md#promote-component-price-point-to-default) * [List Components for Product Family](../../doc/controllers/components.md#list-components-for-product-family) -* [Create Component Price Point](../../doc/controllers/components.md#create-component-price-point) -* [List Component Price Points](../../doc/controllers/components.md#list-component-price-points) -* [Bulk Create Component Price Points](../../doc/controllers/components.md#bulk-create-component-price-points) -* [Update Component Price Point](../../doc/controllers/components.md#update-component-price-point) -* [Archive Component Price Point](../../doc/controllers/components.md#archive-component-price-point) -* [Unarchive Component Price Point](../../doc/controllers/components.md#unarchive-component-price-point) -* [Create Currency Prices](../../doc/controllers/components.md#create-currency-prices) -* [Update Currency Prices](../../doc/controllers/components.md#update-currency-prices) -* [List All Component Price Points](../../doc/controllers/components.md#list-all-component-price-points) # Create Metered Component @@ -1199,87 +1189,6 @@ if err != nil { | 422 | Unprocessable Entity (WebDAV) | [`ErrorListResponseException`](../../doc/models/error-list-response-exception.md) | -# Promote Component Price Point to Default - -Sets a new default price point for the component. This new default will apply to all new subscriptions going forward - existing subscriptions will remain on their current price point. - -See [Price Points Documentation](https://chargify.zendesk.com/hc/en-us/articles/4407755865883#price-points) for more information on price points and moving subscriptions between price points. - -Note: Custom price points are not able to be set as the default for a component. - -```go -PromoteComponentPricePointToDefault( - ctx context.Context, - componentId int, - pricePointId int) ( - models.ApiResponse[models.ComponentResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `componentId` | `int` | Template, Required | The Chargify id of the component to which the price point belongs | -| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | - -## Response Type - -[`models.ComponentResponse`](../../doc/models/component-response.md) - -## Example Usage - -```go -ctx := context.Background() - -componentId := 222 - -pricePointId := 10 - -apiResponse, err := componentsController.PromoteComponentPricePointToDefault(ctx, componentId, pricePointId) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "component": { - "id": 292609, - "name": "Text messages", - "pricing_scheme": "stairstep", - "unit_name": "text message", - "unit_price": null, - "product_family_id": 528484, - "price_per_unit_in_cents": null, - "kind": "metered_component", - "archived": false, - "taxable": false, - "description": null, - "created_at": "2019-08-02T05:54:53-04:00", - "prices": [ - { - "id": 47, - "component_id": 292609, - "starting_quantity": 1, - "ending_quantity": null, - "unit_price": "1.0", - "price_point_id": 173, - "formatted_unit_price": "$1.00" - } - ], - "default_price_point_name": "Original" - } -} -``` - - # List Components for Product Family This request will return a list of components for a particular product family. @@ -1436,805 +1345,3 @@ if err != nil { ] ``` - -# Create Component Price Point - -This endpoint can be used to create a new price point for an existing component. - -```go -CreateComponentPricePoint( - ctx context.Context, - componentId int, - body *models.CreateComponentPricePointRequest) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `componentId` | `int` | Template, Required | The Chargify id of the component | -| `body` | [`*models.CreateComponentPricePointRequest`](../../doc/models/create-component-price-point-request.md) | Body, Optional | - | - -## Response Type - -[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) - -## Example Usage - -```go -ctx := context.Background() - -componentId := 222 - -body := models.CreateComponentPricePointRequest{ - PricePoint: models.CreateComponentPricePointRequestPricePointContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ - Name: "Wholesale", - Handle: models.ToPointer("wholesale-handle"), - PricingScheme: models.PricingScheme("stairstep"), - Prices: []models.Price{ - models.Price{ - StartingQuantity: models.PriceStartingQuantityContainer.FromString("1"), - EndingQuantity: models.NewOptional(models.ToPointer(models.PriceEndingQuantityContainer.FromString("100"))), - UnitPrice: models.PriceUnitPriceContainer.FromString("5.00"), - }, - models.Price{ - StartingQuantity: models.PriceStartingQuantityContainer.FromString("101"), - UnitPrice: models.PriceUnitPriceContainer.FromString("4.00"), - }, - }, - UseSiteExchangeRate: models.ToPointer(false), - }), -} - -apiResponse, err := componentsController.CreateComponentPricePoint(ctx, componentId, &body) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - - -# List Component Price Points - -Use this endpoint to read current price points that are associated with a component. - -You may specify the component by using either the numeric id or the `handle:gold` syntax. - -When fetching a component's price points, if you have defined multiple currencies at the site level, you can optionally pass the `?currency_prices=true` query param to include an array of currency price data in the response. - -If the price point is set to `use_site_exchange_rate: true`, it will return pricing based on the current exchange rate. If the flag is set to false, it will return all of the defined prices for each currency. - -```go -ListComponentPricePoints( - ctx context.Context, - input ListComponentPricePointsInput) ( - models.ApiResponse[models.ComponentPricePointsResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `componentId` | `int` | Template, Required | The Chargify id of the component | -| `currencyPrices` | `*bool` | Query, Optional | Include an array of currency price data | -| `page` | `*int` | Query, Optional | Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
Use in query `page=1`. | -| `perPage` | `*int` | Query, Optional | This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query `per_page=200`. | -| `filterType` | [`[]models.PricePointType`](../../doc/models/price-point-type.md) | Query, Optional | Use in query: `filter[type]=catalog,default`. | - -## Response Type - -[`models.ComponentPricePointsResponse`](../../doc/models/component-price-points-response.md) - -## Example Usage - -```go -ctx := context.Background() - -collectedInput := advancedbilling.ListComponentPricePointsInput{ - ComponentId: 222, - Page: models.ToPointer(2), - PerPage: models.ToPointer(50), -Liquid error: Value cannot be null. (Parameter 'key')} - -apiResponse, err := componentsController.ListComponentPricePoints(ctx, collectedInput) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "price_points": [ - { - "id": 80, - "default": false, - "name": "Wholesale Two", - "pricing_scheme": "per_unit", - "component_id": 74, - "handle": "wholesale-two", - "archived_at": null, - "created_at": "2017-07-05T13:55:40-04:00", - "updated_at": "2017-07-05T13:55:40-04:00", - "prices": [ - { - "id": 121, - "component_id": 74, - "starting_quantity": 1, - "ending_quantity": null, - "unit_price": "5.0" - } - ] - }, - { - "id": 81, - "default": false, - "name": "MSRP", - "pricing_scheme": "per_unit", - "component_id": 74, - "handle": "msrp", - "archived_at": null, - "created_at": "2017-07-05T13:55:40-04:00", - "updated_at": "2017-07-05T13:55:40-04:00", - "prices": [ - { - "id": 122, - "component_id": 74, - "starting_quantity": 1, - "ending_quantity": null, - "unit_price": "4.0" - } - ] - } - ] -} -``` - - -# Bulk Create Component Price Points - -Use this endpoint to create multiple component price points in one request. - -```go -BulkCreateComponentPricePoints( - ctx context.Context, - componentId string, - body *models.CreateComponentPricePointsRequest) ( - models.ApiResponse[models.ComponentPricePointsResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `componentId` | `string` | Template, Required | The Chargify id of the component for which you want to fetch price points. | -| `body` | [`*models.CreateComponentPricePointsRequest`](../../doc/models/create-component-price-points-request.md) | Body, Optional | - | - -## Response Type - -[`models.ComponentPricePointsResponse`](../../doc/models/component-price-points-response.md) - -## Example Usage - -```go -ctx := context.Background() - -componentId := "component_id8" - -body := models.CreateComponentPricePointsRequest{ - PricePoints: []models.CreateComponentPricePointsRequestPricePoints{ - models.CreateComponentPricePointsRequestPricePointsContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ - Name: "Wholesale", - Handle: models.ToPointer("wholesale"), - PricingScheme: models.PricingScheme("per_unit"), - Prices: []models.Price{ - models.Price{ - StartingQuantity: models.PriceStartingQuantityContainer.FromNumber(1), - UnitPrice: models.PriceUnitPriceContainer.FromPrecision(float64(5)), - }, - }, - }), - models.CreateComponentPricePointsRequestPricePointsContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ - Name: "MSRP", - Handle: models.ToPointer("msrp"), - PricingScheme: models.PricingScheme("per_unit"), - Prices: []models.Price{ - models.Price{ - StartingQuantity: models.PriceStartingQuantityContainer.FromNumber(1), - UnitPrice: models.PriceUnitPriceContainer.FromPrecision(float64(4)), - }, - }, - }), - models.CreateComponentPricePointsRequestPricePointsContainer.FromCreateComponentPricePoint(models.CreateComponentPricePoint{ - Name: "Special Pricing", - Handle: models.ToPointer("special"), - PricingScheme: models.PricingScheme("per_unit"), - Prices: []models.Price{ - models.Price{ - StartingQuantity: models.PriceStartingQuantityContainer.FromNumber(1), - UnitPrice: models.PriceUnitPriceContainer.FromPrecision(float64(5)), - }, - }, - }), - }, -} - -apiResponse, err := componentsController.BulkCreateComponentPricePoints(ctx, componentId, &body) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "price_points": [ - { - "id": 80, - "default": false, - "name": "Wholesale Two", - "pricing_scheme": "per_unit", - "component_id": 74, - "handle": "wholesale-two", - "archived_at": null, - "created_at": "2017-07-05T13:55:40-04:00", - "updated_at": "2017-07-05T13:55:40-04:00", - "prices": [ - { - "id": 121, - "component_id": 74, - "starting_quantity": 1, - "ending_quantity": null, - "unit_price": "5.0" - } - ] - }, - { - "id": 81, - "default": false, - "name": "MSRP", - "pricing_scheme": "per_unit", - "component_id": 74, - "handle": "msrp", - "archived_at": null, - "created_at": "2017-07-05T13:55:40-04:00", - "updated_at": "2017-07-05T13:55:40-04:00", - "prices": [ - { - "id": 122, - "component_id": 74, - "starting_quantity": 1, - "ending_quantity": null, - "unit_price": "4.0" - } - ] - } - ] -} -``` - - -# Update Component Price Point - -When updating a price point, it's prices can be updated as well by creating new prices or editing / removing existing ones. - -Passing in a price bracket without an `id` will attempt to create a new price. - -Including an `id` will update the corresponding price, and including the `_destroy` flag set to true along with the `id` will remove that price. - -Note: Custom price points cannot be updated directly. They must be edited through the Subscription. - -```go -UpdateComponentPricePoint( - ctx context.Context, - componentId int, - pricePointId int, - body *models.UpdateComponentPricePointRequest) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `componentId` | `int` | Template, Required | The Chargify id of the component to which the price point belongs | -| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | -| `body` | [`*models.UpdateComponentPricePointRequest`](../../doc/models/update-component-price-point-request.md) | Body, Optional | - | - -## Response Type - -[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) - -## Example Usage - -```go -ctx := context.Background() - -componentId := 222 - -pricePointId := 10 - -body := models.UpdateComponentPricePointRequest{ - PricePoint: models.ToPointer(models.UpdateComponentPricePoint{ - Name: models.ToPointer("Default"), - Prices: []models.UpdatePrice{ - models.UpdatePrice{ - Id: models.ToPointer(1), - EndingQuantity: models.ToPointer(models.UpdatePriceEndingQuantityContainer.FromNumber(100)), - UnitPrice: models.ToPointer(models.UpdatePriceUnitPriceContainer.FromPrecision(float64(5))), - }, - models.UpdatePrice{ - Id: models.ToPointer(2), - Destroy: models.ToPointer(true), - }, - models.UpdatePrice{ - UnitPrice: models.ToPointer(models.UpdatePriceUnitPriceContainer.FromPrecision(float64(4))), - StartingQuantity: models.ToPointer(models.UpdatePriceStartingQuantityContainer.FromNumber(101)), - }, - }, - }), -} - -apiResponse, err := componentsController.UpdateComponentPricePoint(ctx, componentId, pricePointId, &body) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Errors - -| HTTP Status Code | Error Description | Exception Class | -| --- | --- | --- | -| 422 | Unprocessable Entity (WebDAV) | [`ErrorArrayMapResponseException`](../../doc/models/error-array-map-response-exception.md) | - - -# Archive Component Price Point - -A price point can be archived at any time. Subscriptions using a price point that has been archived will continue using it until they're moved to another price point. - -```go -ArchiveComponentPricePoint( - ctx context.Context, - componentId int, - pricePointId int) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `componentId` | `int` | Template, Required | The Chargify id of the component to which the price point belongs | -| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | - -## Response Type - -[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) - -## Example Usage - -```go -ctx := context.Background() - -componentId := 222 - -pricePointId := 10 - -apiResponse, err := componentsController.ArchiveComponentPricePoint(ctx, componentId, pricePointId) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "price_point": { - "id": 79, - "default": false, - "name": "Wholesale", - "pricing_scheme": "stairstep", - "component_id": 74, - "handle": "wholesale-handle", - "archived_at": "2017-07-06T15:04:00-04:00", - "created_at": "2017-07-05T13:44:30-04:00", - "updated_at": "2017-07-05T13:44:30-04:00", - "prices": [ - { - "id": 119, - "component_id": 74, - "starting_quantity": 1, - "ending_quantity": 100, - "unit_price": "5.0" - }, - { - "id": 120, - "component_id": 74, - "starting_quantity": 101, - "ending_quantity": null, - "unit_price": "4.0" - } - ] - } -} -``` - -## Errors - -| HTTP Status Code | Error Description | Exception Class | -| --- | --- | --- | -| 422 | Unprocessable Entity (WebDAV) | [`ErrorListResponseException`](../../doc/models/error-list-response-exception.md) | - - -# Unarchive Component Price Point - -Use this endpoint to unarchive a component price point. - -```go -UnarchiveComponentPricePoint( - ctx context.Context, - componentId int, - pricePointId int) ( - models.ApiResponse[models.ComponentPricePointResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `componentId` | `int` | Template, Required | The Chargify id of the component to which the price point belongs | -| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | - -## Response Type - -[`models.ComponentPricePointResponse`](../../doc/models/component-price-point-response.md) - -## Example Usage - -```go -ctx := context.Background() - -componentId := 222 - -pricePointId := 10 - -apiResponse, err := componentsController.UnarchiveComponentPricePoint(ctx, componentId, pricePointId) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "price_point": { - "id": 79, - "default": false, - "name": "Wholesale", - "pricing_scheme": "stairstep", - "component_id": 74, - "handle": "wholesale-handle", - "archived_at": null, - "created_at": "2017-07-05T13:44:30-04:00", - "updated_at": "2017-07-05T13:44:30-04:00", - "prices": [ - { - "id": 119, - "component_id": 74, - "starting_quantity": 1, - "ending_quantity": 100, - "unit_price": "5.0" - }, - { - "id": 120, - "component_id": 74, - "starting_quantity": 101, - "ending_quantity": null, - "unit_price": "4.0" - } - ] - } -} -``` - - -# Create Currency Prices - -This endpoint allows you to create currency prices for a given currency that has been defined on the site level in your settings. - -When creating currency prices, they need to mirror the structure of your primary pricing. For each price level defined on the component price point, there should be a matching price level created in the given currency. - -Note: Currency Prices are not able to be created for custom price points. - -```go -CreateCurrencyPrices( - ctx context.Context, - pricePointId int, - body *models.CreateCurrencyPricesRequest) ( - models.ApiResponse[models.ComponentCurrencyPricesResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | -| `body` | [`*models.CreateCurrencyPricesRequest`](../../doc/models/create-currency-prices-request.md) | Body, Optional | - | - -## Response Type - -[`models.ComponentCurrencyPricesResponse`](../../doc/models/component-currency-prices-response.md) - -## Example Usage - -```go -ctx := context.Background() - -pricePointId := 10 - -body := models.CreateCurrencyPricesRequest{ - CurrencyPrices: []models.CreateCurrencyPrice{ - models.CreateCurrencyPrice{ - Currency: models.ToPointer("EUR"), - Price: models.ToPointer(float64(50)), - PriceId: models.ToPointer(20), - }, - models.CreateCurrencyPrice{ - Currency: models.ToPointer("EUR"), - Price: models.ToPointer(float64(40)), - PriceId: models.ToPointer(21), - }, - }, -} - -apiResponse, err := componentsController.CreateCurrencyPrices(ctx, pricePointId, &body) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "currency_prices": [ - { - "id": 100, - "currency": "EUR", - "price": "123", - "formatted_price": "€123,00", - "price_id": 32669, - "price_point_id": 25554 - } - ] -} -``` - -## Errors - -| HTTP Status Code | Error Description | Exception Class | -| --- | --- | --- | -| 422 | Unprocessable Entity (WebDAV) | [`ErrorArrayMapResponseException`](../../doc/models/error-array-map-response-exception.md) | - - -# Update Currency Prices - -This endpoint allows you to update currency prices for a given currency that has been defined on the site level in your settings. - -Note: Currency Prices are not able to be updated for custom price points. - -```go -UpdateCurrencyPrices( - ctx context.Context, - pricePointId int, - body *models.UpdateCurrencyPricesRequest) ( - models.ApiResponse[models.ComponentCurrencyPricesResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `pricePointId` | `int` | Template, Required | The Chargify id of the price point | -| `body` | [`*models.UpdateCurrencyPricesRequest`](../../doc/models/update-currency-prices-request.md) | Body, Optional | - | - -## Response Type - -[`models.ComponentCurrencyPricesResponse`](../../doc/models/component-currency-prices-response.md) - -## Example Usage - -```go -ctx := context.Background() - -pricePointId := 10 - -body := models.UpdateCurrencyPricesRequest{ - CurrencyPrices: []models.UpdateCurrencyPrice{ - models.UpdateCurrencyPrice{ - Id: 100, - Price: 51, - }, - models.UpdateCurrencyPrice{ - Id: 101, - Price: 41, - }, - }, -} - -apiResponse, err := componentsController.UpdateCurrencyPrices(ctx, pricePointId, &body) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "currency_prices": [ - { - "id": 100, - "currency": "EUR", - "price": "123", - "formatted_price": "€123,00", - "price_id": 32669, - "price_point_id": 25554 - } - ] -} -``` - -## Errors - -| HTTP Status Code | Error Description | Exception Class | -| --- | --- | --- | -| 422 | Unprocessable Entity (WebDAV) | [`ErrorArrayMapResponseException`](../../doc/models/error-array-map-response-exception.md) | - - -# List All Component Price Points - -This method allows to retrieve a list of Components Price Points belonging to a Site. - -```go -ListAllComponentPricePoints( - ctx context.Context, - input ListAllComponentPricePointsInput) ( - models.ApiResponse[models.ListComponentsPricePointsResponse], - error) -``` - -## Parameters - -| Parameter | Type | Tags | Description | -| --- | --- | --- | --- | -| `include` | [`*models.ListComponentsPricePointsInclude`](../../doc/models/list-components-price-points-include.md) | Query, Optional | Allows including additional data in the response. Use in query: `include=currency_prices`. | -| `page` | `*int` | Query, Optional | Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
Use in query `page=1`. | -| `perPage` | `*int` | Query, Optional | This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query `per_page=200`. | -| `direction` | [`*models.SortingDirection`](../../doc/models/sorting-direction.md) | Query, Optional | Controls the order in which results are returned.
Use in query `direction=asc`. | -| `filter` | [`*models.ListPricePointsFilter`](../../doc/models/list-price-points-filter.md) | Query, Optional | Filter to use for List PricePoints operations | - -## Response Type - -[`models.ListComponentsPricePointsResponse`](../../doc/models/list-components-price-points-response.md) - -## Example Usage - -```go -ctx := context.Background() - -collectedInput := advancedbilling.ListAllComponentPricePointsInput{ - Include: models.ToPointer(models.ListComponentsPricePointsInclude("currency_prices")), - Page: models.ToPointer(2), - PerPage: models.ToPointer(50), - Filter: models.ToPointer(models.ListPricePointsFilter{ - StartDate: models.ToPointer(parseTime(models.DEFAULT_DATE, "2011-12-17", func(err error) { log.Fatalln(err) })), - EndDate: models.ToPointer(parseTime(models.DEFAULT_DATE, "2011-12-15", func(err error) { log.Fatalln(err) })), - StartDatetime: models.ToPointer(parseTime(time.RFC3339, "12/19/2011 09:15:30", func(err error) { log.Fatalln(err) })), - EndDatetime: models.ToPointer(parseTime(time.RFC3339, "06/07/2019 17:20:06", func(err error) { log.Fatalln(err) })), - Type: []models.PricePointType{ - models.PricePointType("catalog"), - models.PricePointType("default"), - models.PricePointType("custom"), - }, - Ids: []int{ - 1, - 2, - 3, - }, - }), -} - -apiResponse, err := componentsController.ListAllComponentPricePoints(ctx, collectedInput) -if err != nil { - log.Fatalln(err) -} else { - // Printing the result and response - fmt.Println(apiResponse.Data) - fmt.Println(apiResponse.Response.StatusCode) -} -``` - -## Example Response *(as JSON)* - -```json -{ - "price_points": [ - { - "id": 1, - "name": "Auto-created", - "type": "default", - "pricing_scheme": "per_unit", - "component_id": 2, - "handle": "auto-created", - "archived_at": null, - "created_at": "2021-02-21T11:05:57-05:00", - "updated_at": "2021-02-21T11:05:57-05:00", - "prices": [ - { - "id": 3, - "component_id": 2, - "starting_quantity": 0, - "ending_quantity": null, - "unit_price": "1.0", - "price_point_id": 1, - "formatted_unit_price": "$1.00", - "segment_id": null - } - ], - "tax_included": false - } - ] -} -``` - -## Errors - -| HTTP Status Code | Error Description | Exception Class | -| --- | --- | --- | -| 422 | Unprocessable Entity (WebDAV) | [`ErrorListResponseException`](../../doc/models/error-list-response-exception.md) | - diff --git a/doc/controllers/product-families.md b/doc/controllers/product-families.md index 00dd7d17..033fd92c 100644 --- a/doc/controllers/product-families.md +++ b/doc/controllers/product-families.md @@ -32,7 +32,7 @@ ListProductsForProductFamily( | Parameter | Type | Tags | Description | | --- | --- | --- | --- | -| `productFamilyId` | `int` | Template, Required | The Chargify id of the product family to which the product belongs | +| `productFamilyId` | `string` | Template, Required | Either the product family's id or its handle prefixed with `handle:` | | `page` | `*int` | Query, Optional | Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
Use in query `page=1`. | | `perPage` | `*int` | Query, Optional | This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
Use in query `per_page=200`. | | `dateField` | [`*models.BasicDateField`](../../doc/models/basic-date-field.md) | Query, Optional | The type of filter you would like to apply to your search.
Use in query: `date_field=created_at`. | @@ -54,7 +54,7 @@ ListProductsForProductFamily( ctx := context.Background() collectedInput := advancedbilling.ListProductsForProductFamilyInput{ - ProductFamilyId: 140, + ProductFamilyId: "product_family_id4", Page: models.ToPointer(2), PerPage: models.ToPointer(50), DateField: models.ToPointer(models.BasicDateField("updated_at")), diff --git a/doc/controllers/product-price-points.md b/doc/controllers/product-price-points.md index 4e855e9c..cc9760f2 100644 --- a/doc/controllers/product-price-points.md +++ b/doc/controllers/product-price-points.md @@ -277,7 +277,7 @@ if err != nil { # Read Product Price Point -Use this endpoint to retrieve details for a specific product price point. +Use this endpoint to retrieve details for a specific product price point. You can achieve this by using either the product price point ID or handle. ```go ReadProductPricePoint( diff --git a/doc/controllers/products.md b/doc/controllers/products.md index 6e018efb..b9e545c2 100644 --- a/doc/controllers/products.md +++ b/doc/controllers/products.md @@ -28,7 +28,7 @@ Use this method to create a product within your Chargify site. ```go CreateProduct( ctx context.Context, - productFamilyId int, + productFamilyId string, body *models.CreateOrUpdateProductRequest) ( models.ApiResponse[models.ProductResponse], error) @@ -38,7 +38,7 @@ CreateProduct( | Parameter | Type | Tags | Description | | --- | --- | --- | --- | -| `productFamilyId` | `int` | Template, Required | The Chargify id of the product family to which the product belongs | +| `productFamilyId` | `string` | Template, Required | Either the product family's id or its handle prefixed with `handle:` | | `body` | [`*models.CreateOrUpdateProductRequest`](../../doc/models/create-or-update-product-request.md) | Body, Optional | - | ## Response Type @@ -50,7 +50,7 @@ CreateProduct( ```go ctx := context.Background() -productFamilyId := 140 +productFamilyId := "product_family_id4" body := models.CreateOrUpdateProductRequest{ Product: models.CreateOrUpdateProduct{ diff --git a/doc/models/containers/archive-component-price-point-component-id.md b/doc/models/containers/archive-component-price-point-component-id.md new file mode 100644 index 00000000..6b097e9e --- /dev/null +++ b/doc/models/containers/archive-component-price-point-component-id.md @@ -0,0 +1,14 @@ + +# Archive Component Price Point Component Id + +## Class Name + +`ArchiveComponentPricePointComponentId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | models.ArchiveComponentPricePointComponentIdContainer.FromNumber(int number) | +| `string` | models.ArchiveComponentPricePointComponentIdContainer.FromString(string mString) | + diff --git a/doc/models/containers/archive-component-price-point-price-point-id.md b/doc/models/containers/archive-component-price-point-price-point-id.md new file mode 100644 index 00000000..a73ba1dd --- /dev/null +++ b/doc/models/containers/archive-component-price-point-price-point-id.md @@ -0,0 +1,14 @@ + +# Archive Component Price Point Price Point Id + +## Class Name + +`ArchiveComponentPricePointPricePointId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | models.ArchiveComponentPricePointPricePointIdContainer.FromNumber(int number) | +| `string` | models.ArchiveComponentPricePointPricePointIdContainer.FromString(string mString) | + diff --git a/doc/models/containers/read-component-price-point-component-id.md b/doc/models/containers/read-component-price-point-component-id.md new file mode 100644 index 00000000..f6942ddb --- /dev/null +++ b/doc/models/containers/read-component-price-point-component-id.md @@ -0,0 +1,14 @@ + +# Read Component Price Point Component Id + +## Class Name + +`ReadComponentPricePointComponentId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | models.ReadComponentPricePointComponentIdContainer.FromNumber(int number) | +| `string` | models.ReadComponentPricePointComponentIdContainer.FromString(string mString) | + diff --git a/doc/models/containers/read-component-price-point-price-point-id.md b/doc/models/containers/read-component-price-point-price-point-id.md new file mode 100644 index 00000000..031ee9f7 --- /dev/null +++ b/doc/models/containers/read-component-price-point-price-point-id.md @@ -0,0 +1,14 @@ + +# Read Component Price Point Price Point Id + +## Class Name + +`ReadComponentPricePointPricePointId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | models.ReadComponentPricePointPricePointIdContainer.FromNumber(int number) | +| `string` | models.ReadComponentPricePointPricePointIdContainer.FromString(string mString) | + diff --git a/doc/models/containers/update-component-price-point-component-id.md b/doc/models/containers/update-component-price-point-component-id.md new file mode 100644 index 00000000..7bb038ef --- /dev/null +++ b/doc/models/containers/update-component-price-point-component-id.md @@ -0,0 +1,14 @@ + +# Update Component Price Point Component Id + +## Class Name + +`UpdateComponentPricePointComponentId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | models.UpdateComponentPricePointComponentIdContainer.FromNumber(int number) | +| `string` | models.UpdateComponentPricePointComponentIdContainer.FromString(string mString) | + diff --git a/doc/models/containers/update-component-price-point-price-point-id.md b/doc/models/containers/update-component-price-point-price-point-id.md new file mode 100644 index 00000000..f87091fd --- /dev/null +++ b/doc/models/containers/update-component-price-point-price-point-id.md @@ -0,0 +1,14 @@ + +# Update Component Price Point Price Point Id + +## Class Name + +`UpdateComponentPricePointPricePointId` + +## Cases + +| Type | Factory Method | +| --- | --- | +| `int` | models.UpdateComponentPricePointPricePointIdContainer.FromNumber(int number) | +| `string` | models.UpdateComponentPricePointPricePointIdContainer.FromString(string mString) | + diff --git a/models/archive_component_price_point_component_id.go b/models/archive_component_price_point_component_id.go new file mode 100644 index 00000000..4ec7b1ea --- /dev/null +++ b/models/archive_component_price_point_component_id.go @@ -0,0 +1,96 @@ +/* +Package advancedbilling + +This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). +*/ +package models + +import ( + "encoding/json" + "errors" + "strings" +) + +// ArchiveComponentPricePointComponentId represents a ArchiveComponentPricePointComponentId struct. +// This is a container for one-of cases. +type ArchiveComponentPricePointComponentId struct { + value any + isNumber bool + isString bool +} + +// String converts the ArchiveComponentPricePointComponentId object to a string representation. +func (a ArchiveComponentPricePointComponentId) String() string { + if bytes, err := json.Marshal(a.value); err == nil { + return strings.Trim(string(bytes), "\"") + } + return "" +} + +// MarshalJSON implements the json.Marshaler interface for ArchiveComponentPricePointComponentId. +// It customizes the JSON marshaling process for ArchiveComponentPricePointComponentId objects. +func (a ArchiveComponentPricePointComponentId) MarshalJSON() ( + []byte, + error) { + if a.value == nil { + return nil, errors.New("No underlying type is set. Please use any of the `models.ArchiveComponentPricePointComponentIdContainer.From*` functions to initialize the ArchiveComponentPricePointComponentId object.") + } + return json.Marshal(a.toMap()) +} + +// toMap converts the ArchiveComponentPricePointComponentId object to a map representation for JSON marshaling. +func (a *ArchiveComponentPricePointComponentId) toMap() any { + switch obj := a.value.(type) { + case *int: + return *obj + case *string: + return *obj + } + return nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface for ArchiveComponentPricePointComponentId. +// It customizes the JSON unmarshaling process for ArchiveComponentPricePointComponentId objects. +func (a *ArchiveComponentPricePointComponentId) UnmarshalJSON(input []byte) error { + result, err := UnmarshallOneOf(input, + NewTypeHolder(new(int), false, &a.isNumber), + NewTypeHolder(new(string), false, &a.isString), + ) + + a.value = result + return err +} + +func (a *ArchiveComponentPricePointComponentId) AsNumber() ( + *int, + bool) { + if !a.isNumber { + return nil, false + } + return a.value.(*int), true +} + +func (a *ArchiveComponentPricePointComponentId) AsString() ( + *string, + bool) { + if !a.isString { + return nil, false + } + return a.value.(*string), true +} + +// internalArchiveComponentPricePointComponentId represents a archiveComponentPricePointComponentId struct. +// This is a container for one-of cases. +type internalArchiveComponentPricePointComponentId struct {} + +var ArchiveComponentPricePointComponentIdContainer internalArchiveComponentPricePointComponentId + +// The internalArchiveComponentPricePointComponentId instance, wrapping the provided int value. +func (a *internalArchiveComponentPricePointComponentId) FromNumber(val int) ArchiveComponentPricePointComponentId { + return ArchiveComponentPricePointComponentId{value: &val} +} + +// The internalArchiveComponentPricePointComponentId instance, wrapping the provided string value. +func (a *internalArchiveComponentPricePointComponentId) FromString(val string) ArchiveComponentPricePointComponentId { + return ArchiveComponentPricePointComponentId{value: &val} +} diff --git a/models/archive_component_price_point_price_point_id.go b/models/archive_component_price_point_price_point_id.go new file mode 100644 index 00000000..48cb281a --- /dev/null +++ b/models/archive_component_price_point_price_point_id.go @@ -0,0 +1,96 @@ +/* +Package advancedbilling + +This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). +*/ +package models + +import ( + "encoding/json" + "errors" + "strings" +) + +// ArchiveComponentPricePointPricePointId represents a ArchiveComponentPricePointPricePointId struct. +// This is a container for one-of cases. +type ArchiveComponentPricePointPricePointId struct { + value any + isNumber bool + isString bool +} + +// String converts the ArchiveComponentPricePointPricePointId object to a string representation. +func (a ArchiveComponentPricePointPricePointId) String() string { + if bytes, err := json.Marshal(a.value); err == nil { + return strings.Trim(string(bytes), "\"") + } + return "" +} + +// MarshalJSON implements the json.Marshaler interface for ArchiveComponentPricePointPricePointId. +// It customizes the JSON marshaling process for ArchiveComponentPricePointPricePointId objects. +func (a ArchiveComponentPricePointPricePointId) MarshalJSON() ( + []byte, + error) { + if a.value == nil { + return nil, errors.New("No underlying type is set. Please use any of the `models.ArchiveComponentPricePointPricePointIdContainer.From*` functions to initialize the ArchiveComponentPricePointPricePointId object.") + } + return json.Marshal(a.toMap()) +} + +// toMap converts the ArchiveComponentPricePointPricePointId object to a map representation for JSON marshaling. +func (a *ArchiveComponentPricePointPricePointId) toMap() any { + switch obj := a.value.(type) { + case *int: + return *obj + case *string: + return *obj + } + return nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface for ArchiveComponentPricePointPricePointId. +// It customizes the JSON unmarshaling process for ArchiveComponentPricePointPricePointId objects. +func (a *ArchiveComponentPricePointPricePointId) UnmarshalJSON(input []byte) error { + result, err := UnmarshallOneOf(input, + NewTypeHolder(new(int), false, &a.isNumber), + NewTypeHolder(new(string), false, &a.isString), + ) + + a.value = result + return err +} + +func (a *ArchiveComponentPricePointPricePointId) AsNumber() ( + *int, + bool) { + if !a.isNumber { + return nil, false + } + return a.value.(*int), true +} + +func (a *ArchiveComponentPricePointPricePointId) AsString() ( + *string, + bool) { + if !a.isString { + return nil, false + } + return a.value.(*string), true +} + +// internalArchiveComponentPricePointPricePointId represents a archiveComponentPricePointPricePointId struct. +// This is a container for one-of cases. +type internalArchiveComponentPricePointPricePointId struct {} + +var ArchiveComponentPricePointPricePointIdContainer internalArchiveComponentPricePointPricePointId + +// The internalArchiveComponentPricePointPricePointId instance, wrapping the provided int value. +func (a *internalArchiveComponentPricePointPricePointId) FromNumber(val int) ArchiveComponentPricePointPricePointId { + return ArchiveComponentPricePointPricePointId{value: &val} +} + +// The internalArchiveComponentPricePointPricePointId instance, wrapping the provided string value. +func (a *internalArchiveComponentPricePointPricePointId) FromString(val string) ArchiveComponentPricePointPricePointId { + return ArchiveComponentPricePointPricePointId{value: &val} +} diff --git a/models/read_component_price_point_component_id.go b/models/read_component_price_point_component_id.go new file mode 100644 index 00000000..961a2828 --- /dev/null +++ b/models/read_component_price_point_component_id.go @@ -0,0 +1,96 @@ +/* +Package advancedbilling + +This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). +*/ +package models + +import ( + "encoding/json" + "errors" + "strings" +) + +// ReadComponentPricePointComponentId represents a ReadComponentPricePointComponentId struct. +// This is a container for one-of cases. +type ReadComponentPricePointComponentId struct { + value any + isNumber bool + isString bool +} + +// String converts the ReadComponentPricePointComponentId object to a string representation. +func (r ReadComponentPricePointComponentId) String() string { + if bytes, err := json.Marshal(r.value); err == nil { + return strings.Trim(string(bytes), "\"") + } + return "" +} + +// MarshalJSON implements the json.Marshaler interface for ReadComponentPricePointComponentId. +// It customizes the JSON marshaling process for ReadComponentPricePointComponentId objects. +func (r ReadComponentPricePointComponentId) MarshalJSON() ( + []byte, + error) { + if r.value == nil { + return nil, errors.New("No underlying type is set. Please use any of the `models.ReadComponentPricePointComponentIdContainer.From*` functions to initialize the ReadComponentPricePointComponentId object.") + } + return json.Marshal(r.toMap()) +} + +// toMap converts the ReadComponentPricePointComponentId object to a map representation for JSON marshaling. +func (r *ReadComponentPricePointComponentId) toMap() any { + switch obj := r.value.(type) { + case *int: + return *obj + case *string: + return *obj + } + return nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface for ReadComponentPricePointComponentId. +// It customizes the JSON unmarshaling process for ReadComponentPricePointComponentId objects. +func (r *ReadComponentPricePointComponentId) UnmarshalJSON(input []byte) error { + result, err := UnmarshallOneOf(input, + NewTypeHolder(new(int), false, &r.isNumber), + NewTypeHolder(new(string), false, &r.isString), + ) + + r.value = result + return err +} + +func (r *ReadComponentPricePointComponentId) AsNumber() ( + *int, + bool) { + if !r.isNumber { + return nil, false + } + return r.value.(*int), true +} + +func (r *ReadComponentPricePointComponentId) AsString() ( + *string, + bool) { + if !r.isString { + return nil, false + } + return r.value.(*string), true +} + +// internalReadComponentPricePointComponentId represents a readComponentPricePointComponentId struct. +// This is a container for one-of cases. +type internalReadComponentPricePointComponentId struct {} + +var ReadComponentPricePointComponentIdContainer internalReadComponentPricePointComponentId + +// The internalReadComponentPricePointComponentId instance, wrapping the provided int value. +func (r *internalReadComponentPricePointComponentId) FromNumber(val int) ReadComponentPricePointComponentId { + return ReadComponentPricePointComponentId{value: &val} +} + +// The internalReadComponentPricePointComponentId instance, wrapping the provided string value. +func (r *internalReadComponentPricePointComponentId) FromString(val string) ReadComponentPricePointComponentId { + return ReadComponentPricePointComponentId{value: &val} +} diff --git a/models/read_component_price_point_price_point_id.go b/models/read_component_price_point_price_point_id.go new file mode 100644 index 00000000..67b3d941 --- /dev/null +++ b/models/read_component_price_point_price_point_id.go @@ -0,0 +1,96 @@ +/* +Package advancedbilling + +This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). +*/ +package models + +import ( + "encoding/json" + "errors" + "strings" +) + +// ReadComponentPricePointPricePointId represents a ReadComponentPricePointPricePointId struct. +// This is a container for one-of cases. +type ReadComponentPricePointPricePointId struct { + value any + isNumber bool + isString bool +} + +// String converts the ReadComponentPricePointPricePointId object to a string representation. +func (r ReadComponentPricePointPricePointId) String() string { + if bytes, err := json.Marshal(r.value); err == nil { + return strings.Trim(string(bytes), "\"") + } + return "" +} + +// MarshalJSON implements the json.Marshaler interface for ReadComponentPricePointPricePointId. +// It customizes the JSON marshaling process for ReadComponentPricePointPricePointId objects. +func (r ReadComponentPricePointPricePointId) MarshalJSON() ( + []byte, + error) { + if r.value == nil { + return nil, errors.New("No underlying type is set. Please use any of the `models.ReadComponentPricePointPricePointIdContainer.From*` functions to initialize the ReadComponentPricePointPricePointId object.") + } + return json.Marshal(r.toMap()) +} + +// toMap converts the ReadComponentPricePointPricePointId object to a map representation for JSON marshaling. +func (r *ReadComponentPricePointPricePointId) toMap() any { + switch obj := r.value.(type) { + case *int: + return *obj + case *string: + return *obj + } + return nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface for ReadComponentPricePointPricePointId. +// It customizes the JSON unmarshaling process for ReadComponentPricePointPricePointId objects. +func (r *ReadComponentPricePointPricePointId) UnmarshalJSON(input []byte) error { + result, err := UnmarshallOneOf(input, + NewTypeHolder(new(int), false, &r.isNumber), + NewTypeHolder(new(string), false, &r.isString), + ) + + r.value = result + return err +} + +func (r *ReadComponentPricePointPricePointId) AsNumber() ( + *int, + bool) { + if !r.isNumber { + return nil, false + } + return r.value.(*int), true +} + +func (r *ReadComponentPricePointPricePointId) AsString() ( + *string, + bool) { + if !r.isString { + return nil, false + } + return r.value.(*string), true +} + +// internalReadComponentPricePointPricePointId represents a readComponentPricePointPricePointId struct. +// This is a container for one-of cases. +type internalReadComponentPricePointPricePointId struct {} + +var ReadComponentPricePointPricePointIdContainer internalReadComponentPricePointPricePointId + +// The internalReadComponentPricePointPricePointId instance, wrapping the provided int value. +func (r *internalReadComponentPricePointPricePointId) FromNumber(val int) ReadComponentPricePointPricePointId { + return ReadComponentPricePointPricePointId{value: &val} +} + +// The internalReadComponentPricePointPricePointId instance, wrapping the provided string value. +func (r *internalReadComponentPricePointPricePointId) FromString(val string) ReadComponentPricePointPricePointId { + return ReadComponentPricePointPricePointId{value: &val} +} diff --git a/models/update_component_price_point_component_id.go b/models/update_component_price_point_component_id.go new file mode 100644 index 00000000..fc5b5155 --- /dev/null +++ b/models/update_component_price_point_component_id.go @@ -0,0 +1,96 @@ +/* +Package advancedbilling + +This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). +*/ +package models + +import ( + "encoding/json" + "errors" + "strings" +) + +// UpdateComponentPricePointComponentId represents a UpdateComponentPricePointComponentId struct. +// This is a container for one-of cases. +type UpdateComponentPricePointComponentId struct { + value any + isNumber bool + isString bool +} + +// String converts the UpdateComponentPricePointComponentId object to a string representation. +func (u UpdateComponentPricePointComponentId) String() string { + if bytes, err := json.Marshal(u.value); err == nil { + return strings.Trim(string(bytes), "\"") + } + return "" +} + +// MarshalJSON implements the json.Marshaler interface for UpdateComponentPricePointComponentId. +// It customizes the JSON marshaling process for UpdateComponentPricePointComponentId objects. +func (u UpdateComponentPricePointComponentId) MarshalJSON() ( + []byte, + error) { + if u.value == nil { + return nil, errors.New("No underlying type is set. Please use any of the `models.UpdateComponentPricePointComponentIdContainer.From*` functions to initialize the UpdateComponentPricePointComponentId object.") + } + return json.Marshal(u.toMap()) +} + +// toMap converts the UpdateComponentPricePointComponentId object to a map representation for JSON marshaling. +func (u *UpdateComponentPricePointComponentId) toMap() any { + switch obj := u.value.(type) { + case *int: + return *obj + case *string: + return *obj + } + return nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface for UpdateComponentPricePointComponentId. +// It customizes the JSON unmarshaling process for UpdateComponentPricePointComponentId objects. +func (u *UpdateComponentPricePointComponentId) UnmarshalJSON(input []byte) error { + result, err := UnmarshallOneOf(input, + NewTypeHolder(new(int), false, &u.isNumber), + NewTypeHolder(new(string), false, &u.isString), + ) + + u.value = result + return err +} + +func (u *UpdateComponentPricePointComponentId) AsNumber() ( + *int, + bool) { + if !u.isNumber { + return nil, false + } + return u.value.(*int), true +} + +func (u *UpdateComponentPricePointComponentId) AsString() ( + *string, + bool) { + if !u.isString { + return nil, false + } + return u.value.(*string), true +} + +// internalUpdateComponentPricePointComponentId represents a updateComponentPricePointComponentId struct. +// This is a container for one-of cases. +type internalUpdateComponentPricePointComponentId struct {} + +var UpdateComponentPricePointComponentIdContainer internalUpdateComponentPricePointComponentId + +// The internalUpdateComponentPricePointComponentId instance, wrapping the provided int value. +func (u *internalUpdateComponentPricePointComponentId) FromNumber(val int) UpdateComponentPricePointComponentId { + return UpdateComponentPricePointComponentId{value: &val} +} + +// The internalUpdateComponentPricePointComponentId instance, wrapping the provided string value. +func (u *internalUpdateComponentPricePointComponentId) FromString(val string) UpdateComponentPricePointComponentId { + return UpdateComponentPricePointComponentId{value: &val} +} diff --git a/models/update_component_price_point_price_point_id.go b/models/update_component_price_point_price_point_id.go new file mode 100644 index 00000000..c2e3c807 --- /dev/null +++ b/models/update_component_price_point_price_point_id.go @@ -0,0 +1,96 @@ +/* +Package advancedbilling + +This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ). +*/ +package models + +import ( + "encoding/json" + "errors" + "strings" +) + +// UpdateComponentPricePointPricePointId represents a UpdateComponentPricePointPricePointId struct. +// This is a container for one-of cases. +type UpdateComponentPricePointPricePointId struct { + value any + isNumber bool + isString bool +} + +// String converts the UpdateComponentPricePointPricePointId object to a string representation. +func (u UpdateComponentPricePointPricePointId) String() string { + if bytes, err := json.Marshal(u.value); err == nil { + return strings.Trim(string(bytes), "\"") + } + return "" +} + +// MarshalJSON implements the json.Marshaler interface for UpdateComponentPricePointPricePointId. +// It customizes the JSON marshaling process for UpdateComponentPricePointPricePointId objects. +func (u UpdateComponentPricePointPricePointId) MarshalJSON() ( + []byte, + error) { + if u.value == nil { + return nil, errors.New("No underlying type is set. Please use any of the `models.UpdateComponentPricePointPricePointIdContainer.From*` functions to initialize the UpdateComponentPricePointPricePointId object.") + } + return json.Marshal(u.toMap()) +} + +// toMap converts the UpdateComponentPricePointPricePointId object to a map representation for JSON marshaling. +func (u *UpdateComponentPricePointPricePointId) toMap() any { + switch obj := u.value.(type) { + case *int: + return *obj + case *string: + return *obj + } + return nil +} + +// UnmarshalJSON implements the json.Unmarshaler interface for UpdateComponentPricePointPricePointId. +// It customizes the JSON unmarshaling process for UpdateComponentPricePointPricePointId objects. +func (u *UpdateComponentPricePointPricePointId) UnmarshalJSON(input []byte) error { + result, err := UnmarshallOneOf(input, + NewTypeHolder(new(int), false, &u.isNumber), + NewTypeHolder(new(string), false, &u.isString), + ) + + u.value = result + return err +} + +func (u *UpdateComponentPricePointPricePointId) AsNumber() ( + *int, + bool) { + if !u.isNumber { + return nil, false + } + return u.value.(*int), true +} + +func (u *UpdateComponentPricePointPricePointId) AsString() ( + *string, + bool) { + if !u.isString { + return nil, false + } + return u.value.(*string), true +} + +// internalUpdateComponentPricePointPricePointId represents a updateComponentPricePointPricePointId struct. +// This is a container for one-of cases. +type internalUpdateComponentPricePointPricePointId struct {} + +var UpdateComponentPricePointPricePointIdContainer internalUpdateComponentPricePointPricePointId + +// The internalUpdateComponentPricePointPricePointId instance, wrapping the provided int value. +func (u *internalUpdateComponentPricePointPricePointId) FromNumber(val int) UpdateComponentPricePointPricePointId { + return UpdateComponentPricePointPricePointId{value: &val} +} + +// The internalUpdateComponentPricePointPricePointId instance, wrapping the provided string value. +func (u *internalUpdateComponentPricePointPricePointId) FromString(val string) UpdateComponentPricePointPricePointId { + return UpdateComponentPricePointPricePointId{value: &val} +} diff --git a/product_families_controller.go b/product_families_controller.go index 9c62aa85..fa46bd31 100644 --- a/product_families_controller.go +++ b/product_families_controller.go @@ -23,8 +23,8 @@ func NewProductFamiliesController(baseController baseController) *ProductFamilie // ListProductsForProductFamilyInput represents the input of the ListProductsForProductFamily endpoint. type ListProductsForProductFamilyInput struct { - // The Chargify id of the product family to which the product belongs - ProductFamilyId int + // Either the product family's id or its handle prefixed with `handle:` + ProductFamilyId string // Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. // Use in query `page=1`. Page *int diff --git a/product_price_points_controller.go b/product_price_points_controller.go index 8321c97d..6e6fcb39 100644 --- a/product_price_points_controller.go +++ b/product_price_points_controller.go @@ -144,7 +144,7 @@ func (p *ProductPricePointsController) UpdateProductPricePoint( // ReadProductPricePoint takes context, productId, pricePointId, currencyPrices as parameters and // returns an models.ApiResponse with models.ProductPricePointResponse data and // an error if there was an issue with the request or response. -// Use this endpoint to retrieve details for a specific product price point. +// Use this endpoint to retrieve details for a specific product price point. You can achieve this by using either the product price point ID or handle. func (p *ProductPricePointsController) ReadProductPricePoint( ctx context.Context, productId models.ReadProductPricePointProductId, diff --git a/products_controller.go b/products_controller.go index 5f598cb7..bd7387f7 100644 --- a/products_controller.go +++ b/products_controller.go @@ -30,7 +30,7 @@ func NewProductsController(baseController baseController) *ProductsController { // + [Changing a Subscription's Product](https://maxio-chargify.zendesk.com/hc/en-us/articles/5404225334669-Product-Changes-Migrations) func (p *ProductsController) CreateProduct( ctx context.Context, - productFamilyId int, + productFamilyId string, body *models.CreateOrUpdateProductRequest) ( models.ApiResponse[models.ProductResponse], error) { diff --git a/test/suite.go b/test/suite.go index e8cbc8c1..95ee8448 100644 --- a/test/suite.go +++ b/test/suite.go @@ -137,7 +137,7 @@ func (s *APISuite) generateProductFamily(ctx context.Context) models.ProductFami } func (s *APISuite) generateProduct(ctx context.Context, productFamilyID int) models.Product { - resp, err := s.client.ProductsController().CreateProduct(ctx, productFamilyID, &models.CreateOrUpdateProductRequest{ + resp, err := s.client.ProductsController().CreateProduct(ctx, fmt.Sprint(productFamilyID), &models.CreateOrUpdateProductRequest{ Product: models.CreateOrUpdateProduct{ Name: s.fkr.RandomStringWithLength(20), PriceInCents: 50,