Skip to content

Commit

Permalink
Merge pull request #173 from recurly/v3-v2021-02-25-1667937927
Browse files Browse the repository at this point in the history
Generated Latest Changes for v2021-02-25 (External Subscriptions feature)
  • Loading branch information
Patrick-Duvall authored Nov 9, 2022
2 parents 90e07f4 + 5809be3 commit a8881d9
Show file tree
Hide file tree
Showing 11 changed files with 1,115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions add_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type AddOn struct {
// Type of usage, returns usage type if `add_on_type` is `usage`.
UsageType string `json:"usage_type,omitempty"`

// The type of calculation to be employed for an add-on. Cumulative billing will sum all usage records created in the current billing cycle. Last-in-period billing will apply only the most recent usage record in the billing period. If no value is specified, cumulative billing will be used.
UsageCalculationType string `json:"usage_calculation_type,omitempty"`

// The percentage taken of the monetary amount of usage tracked. This can be up to 4 decimal places. A value between 0.0 and 100.0.
UsagePercentage float64 `json:"usage_percentage,omitempty"`

Expand Down
3 changes: 3 additions & 0 deletions add_on_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type AddOnCreate struct {
// overview of how to configure usage add-ons.
UsageType *string `json:"usage_type,omitempty"`

// The type of calculation to be employed for an add-on. Cumulative billing will sum all usage records created in the current billing cycle. Last-in-period billing will apply only the most recent usage record in the billing period. If no value is specified, cumulative billing will be used.
UsageCalculationType *string `json:"usage_calculation_type,omitempty"`

// The percentage taken of the monetary amount of usage tracked. This can be up to 4 decimal places. A value between 0.0 and 100.0. Required if `add_on_type` is usage, `tier_type` is `flat` and `usage_type` is percentage. Must be omitted otherwise.
UsagePercentage *float64 `json:"usage_percentage,omitempty"`

Expand Down
3 changes: 3 additions & 0 deletions add_on_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type AddOnUpdate struct {
// The percentage taken of the monetary amount of usage tracked. This can be up to 4 decimal places. A value between 0.0 and 100.0. Required if `add_on_type` is usage, `tier_type` is `flat` and `usage_type` is percentage. Must be omitted otherwise.
UsagePercentage *float64 `json:"usage_percentage,omitempty"`

// The type of calculation to be employed for an add-on. Cumulative billing will sum all usage records created in the current billing cycle. Last-in-period billing will apply only the most recent usage record in the billing period. If no value is specified, cumulative billing will be used.
UsageCalculationType *string `json:"usage_calculation_type,omitempty"`

// System-generated unique identifier for a measured unit to be associated with the add-on. Either `measured_unit_id` or `measured_unit_name` are required when `add_on_type` is `usage`. If `measured_unit_id` and `measured_unit_name` are both present, `measured_unit_id` will be used.
MeasuredUnitId *string `json:"measured_unit_id,omitempty"`

Expand Down
169 changes: 169 additions & 0 deletions client_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ type ClientInterface interface {
RemoveMeasuredUnit(measuredUnitId string, opts ...Option) (*MeasuredUnit, error)
RemoveMeasuredUnitWithContext(ctx context.Context, measuredUnitId string, opts ...Option) (*MeasuredUnit, error)

ListExternalProducts(params *ListExternalProductsParams, opts ...Option) (ExternalProductLister, error)

GetExternalProduct(externalProductId string, opts ...Option) (*ExternalProduct, error)
GetExternalProductWithContext(ctx context.Context, externalProductId string, opts ...Option) (*ExternalProduct, error)

ListExternalSubscriptions(params *ListExternalSubscriptionsParams, opts ...Option) (ExternalSubscriptionLister, error)

GetExternalSubscription(externalSubscriptionId string, opts ...Option) (*ExternalSubscription, error)
GetExternalSubscriptionWithContext(ctx context.Context, externalSubscriptionId string, opts ...Option) (*ExternalSubscription, error)

ListInvoices(params *ListInvoicesParams, opts ...Option) (InvoiceLister, error)

GetInvoice(invoiceId string, opts ...Option) (*Invoice, error)
Expand Down Expand Up @@ -395,6 +405,8 @@ type ClientInterface interface {
GetInvoiceTemplateWithContext(ctx context.Context, invoiceTemplateId string, opts ...Option) (*InvoiceTemplate, error)

ListEntitlements(accountId string, params *ListEntitlementsParams, opts ...Option) (EntitlementsLister, error)

ListAccountExternalSubscriptions(accountId string, params *ListAccountExternalSubscriptionsParams, opts ...Option) (ExternalSubscriptionLister, error)
}

type ListSitesParams struct {
Expand Down Expand Up @@ -3361,6 +3373,130 @@ func (c *Client) removeMeasuredUnit(ctx context.Context, measuredUnitId string,
return result, err
}

type ListExternalProductsParams struct {

// Sort - Sort field. You *really* only want to sort by `updated_at` in ascending
// order. In descending order updated records will move behind the cursor and could
// prevent some records from being returned.
Sort *string
}

func (list *ListExternalProductsParams) URLParams() []KeyValue {
var options []KeyValue

if list.Sort != nil {
options = append(options, KeyValue{Key: "sort", Value: *list.Sort})
}

return options
}

// ListExternalProducts List a site's external products
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/list_external_products
//
// Returns: A list of the the external_products on a site.
func (c *Client) ListExternalProducts(params *ListExternalProductsParams, opts ...Option) (ExternalProductLister, error) {
path, err := c.InterpolatePath("/external_products")
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
path = BuildURL(path, params)
return NewExternalProductList(c, path, requestOptions), nil
}

// GetExternalProduct wraps GetExternalProductWithContext using the background context
func (c *Client) GetExternalProduct(externalProductId string, opts ...Option) (*ExternalProduct, error) {
ctx := context.Background()
return c.getExternalProduct(ctx, externalProductId, opts...)
}

// GetExternalProductWithContext Fetch an external product
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/get_external_product
//
// Returns: Settings for an external product.
func (c *Client) GetExternalProductWithContext(ctx context.Context, externalProductId string, opts ...Option) (*ExternalProduct, error) {
return c.getExternalProduct(ctx, externalProductId, opts...)
}

func (c *Client) getExternalProduct(ctx context.Context, externalProductId string, opts ...Option) (*ExternalProduct, error) {
path, err := c.InterpolatePath("/external_products/{external_product_id}", externalProductId)
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
result := &ExternalProduct{}
err = c.Call(ctx, http.MethodGet, path, nil, nil, requestOptions, result)
if err != nil {
return nil, err
}
return result, err
}

type ListExternalSubscriptionsParams struct {

// Sort - Sort field. You *really* only want to sort by `updated_at` in ascending
// order. In descending order updated records will move behind the cursor and could
// prevent some records from being returned.
Sort *string
}

func (list *ListExternalSubscriptionsParams) URLParams() []KeyValue {
var options []KeyValue

if list.Sort != nil {
options = append(options, KeyValue{Key: "sort", Value: *list.Sort})
}

return options
}

// ListExternalSubscriptions List a site's external subscriptions
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/list_external_subscriptions
//
// Returns: A list of the the external_subscriptions on a site.
func (c *Client) ListExternalSubscriptions(params *ListExternalSubscriptionsParams, opts ...Option) (ExternalSubscriptionLister, error) {
path, err := c.InterpolatePath("/external_subscriptions")
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
path = BuildURL(path, params)
return NewExternalSubscriptionList(c, path, requestOptions), nil
}

// GetExternalSubscription wraps GetExternalSubscriptionWithContext using the background context
func (c *Client) GetExternalSubscription(externalSubscriptionId string, opts ...Option) (*ExternalSubscription, error) {
ctx := context.Background()
return c.getExternalSubscription(ctx, externalSubscriptionId, opts...)
}

// GetExternalSubscriptionWithContext Fetch an external subscription
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/get_external_subscription
//
// Returns: Settings for an external subscription.
func (c *Client) GetExternalSubscriptionWithContext(ctx context.Context, externalSubscriptionId string, opts ...Option) (*ExternalSubscription, error) {
return c.getExternalSubscription(ctx, externalSubscriptionId, opts...)
}

func (c *Client) getExternalSubscription(ctx context.Context, externalSubscriptionId string, opts ...Option) (*ExternalSubscription, error) {
path, err := c.InterpolatePath("/external_subscriptions/{external_subscription_id}", externalSubscriptionId)
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
result := &ExternalSubscription{}
err = c.Call(ctx, http.MethodGet, path, nil, nil, requestOptions, result)
if err != nil {
return nil, err
}
return result, err
}

type ListInvoicesParams struct {

// Ids - Filter results by their IDs. Up to 200 IDs can be passed at once using
Expand Down Expand Up @@ -6292,3 +6428,36 @@ func (c *Client) ListEntitlements(accountId string, params *ListEntitlementsPara
path = BuildURL(path, params)
return NewEntitlementsList(c, path, requestOptions), nil
}

type ListAccountExternalSubscriptionsParams struct {

// Sort - Sort field. You *really* only want to sort by `updated_at` in ascending
// order. In descending order updated records will move behind the cursor and could
// prevent some records from being returned.
Sort *string
}

func (list *ListAccountExternalSubscriptionsParams) URLParams() []KeyValue {
var options []KeyValue

if list.Sort != nil {
options = append(options, KeyValue{Key: "sort", Value: *list.Sort})
}

return options
}

// ListAccountExternalSubscriptions List an account's external subscriptions
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/list_account_external_subscriptions
//
// Returns: A list of the the external_subscriptions on an account.
func (c *Client) ListAccountExternalSubscriptions(accountId string, params *ListAccountExternalSubscriptionsParams, opts ...Option) (ExternalSubscriptionLister, error) {
path, err := c.InterpolatePath("/accounts/{account_id}/external_subscriptions", accountId)
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
path = BuildURL(path, params)
return NewExternalSubscriptionList(c, path, requestOptions), nil
}
138 changes: 138 additions & 0 deletions external_product.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// This file is automatically created by Recurly's OpenAPI generation process
// and thus any edits you make by hand will be lost. If you wish to make a
// change to this file, please create a Github issue explaining the changes you
// need and we will usher them to the appropriate places.
package recurly

import (
"context"
"net/http"
"time"
)

type ExternalProduct struct {
recurlyResponse *ResponseMetadata

// System-generated unique identifier for an external product ID, e.g. `e28zov4fw0v2`.
Id string `json:"id,omitempty"`

// Object type
Object string `json:"object,omitempty"`

// Name to identify the external product in Recurly.
Name string `json:"name,omitempty"`

// Just the important parts.
Plan PlanMini `json:"plan,omitempty"`

// When the external product was created in Recurly.
CreatedAt time.Time `json:"created_at,omitempty"`

// When the external product was updated in Recurly.
UpdatedAt time.Time `json:"updated_at,omitempty"`

// List of external product references of the external product.
ExternalProductReferences []ExternalProductReferenceMini `json:"external_product_references,omitempty"`
}

// GetResponse returns the ResponseMetadata that generated this resource
func (resource *ExternalProduct) GetResponse() *ResponseMetadata {
return resource.recurlyResponse
}

// setResponse sets the ResponseMetadata that generated this resource
func (resource *ExternalProduct) setResponse(res *ResponseMetadata) {
resource.recurlyResponse = res
}

// internal struct for deserializing accounts
type externalProductList struct {
ListMetadata
Data []ExternalProduct `json:"data"`
recurlyResponse *ResponseMetadata
}

// GetResponse returns the ResponseMetadata that generated this resource
func (resource *externalProductList) GetResponse() *ResponseMetadata {
return resource.recurlyResponse
}

// setResponse sets the ResponseMetadata that generated this resource
func (resource *externalProductList) setResponse(res *ResponseMetadata) {
resource.recurlyResponse = res
}

// ExternalProductList allows you to paginate ExternalProduct objects
type ExternalProductList struct {
client HTTPCaller
requestOptions *RequestOptions
nextPagePath string
hasMore bool
data []ExternalProduct
}

func NewExternalProductList(client HTTPCaller, nextPagePath string, requestOptions *RequestOptions) *ExternalProductList {
return &ExternalProductList{
client: client,
requestOptions: requestOptions,
nextPagePath: nextPagePath,
hasMore: true,
}
}

type ExternalProductLister interface {
Fetch() error
FetchWithContext(ctx context.Context) error
Count() (*int64, error)
CountWithContext(ctx context.Context) (*int64, error)
Data() []ExternalProduct
HasMore() bool
Next() string
}

func (list *ExternalProductList) HasMore() bool {
return list.hasMore
}

func (list *ExternalProductList) Next() string {
return list.nextPagePath
}

func (list *ExternalProductList) Data() []ExternalProduct {
return list.data
}

// Fetch fetches the next page of data into the `Data` property
func (list *ExternalProductList) FetchWithContext(ctx context.Context) error {
resources := &externalProductList{}
err := list.client.Call(ctx, http.MethodGet, list.nextPagePath, nil, nil, list.requestOptions, resources)
if err != nil {
return err
}
// copy over properties from the response
list.nextPagePath = resources.Next
list.hasMore = resources.HasMore
list.data = resources.Data
return nil
}

// Fetch fetches the next page of data into the `Data` property
func (list *ExternalProductList) Fetch() error {
return list.FetchWithContext(context.Background())
}

// Count returns the count of items on the server that match this pager
func (list *ExternalProductList) CountWithContext(ctx context.Context) (*int64, error) {
resources := &externalProductList{}
err := list.client.Call(ctx, http.MethodHead, list.nextPagePath, nil, nil, list.requestOptions, resources)
if err != nil {
return nil, err
}
resp := resources.GetResponse()
return resp.TotalRecords, nil
}

// Count returns the count of items on the server that match this pager
func (list *ExternalProductList) Count() (*int64, error) {
return list.CountWithContext(context.Background())
}
Loading

0 comments on commit a8881d9

Please sign in to comment.