Skip to content

Commit

Permalink
Merge pull request #197 from recurly/v3-v2021-02-25-5146870733
Browse files Browse the repository at this point in the history
Generated Latest Changes for v2021-02-25 (Multiple Business Entities)
  • Loading branch information
csampson authored Jun 1, 2023
2 parents 72fb9a3 + b446e54 commit 19b4fae
Show file tree
Hide file tree
Showing 9 changed files with 508 additions and 0 deletions.
3 changes: 3 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type Account struct {
// The email address used for communicating with this customer. The customer will also use this email address to log into your hosted account management pages. This value does not need to be unique.
Email string `json:"email,omitempty"`

// Unique ID to identify the business entity assigned to the account. Available when the `Multiple Business Entities` feature is enabled.
OverrideBusinessEntityId string `json:"override_business_entity_id,omitempty"`

// Used to determine the language and locale of emails sent on behalf of the merchant to the customer.
PreferredLocale string `json:"preferred_locale,omitempty"`

Expand Down
3 changes: 3 additions & 0 deletions account_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type AccountCreate struct {
// The tax exemption certificate number for the account. If the merchant has an integration for the Vertex tax provider, this optional value will be sent in any tax calculation requests for the account.
ExemptionCertificate *string `json:"exemption_certificate,omitempty"`

// Unique ID to identify the business entity assigned to the account. Available when the `Multiple Business Entities` feature is enabled.
OverrideBusinessEntityId *string `json:"override_business_entity_id,omitempty"`

// The account code of the parent account to be associated with this account. Passing an empty value removes any existing parent association from this account. If both `parent_account_code` and `parent_account_id` are passed, the non-blank value in `parent_account_id` will be used. Only one level of parent child relationship is allowed. You cannot assign a parent account that itself has a parent account.
ParentAccountCode *string `json:"parent_account_code,omitempty"`

Expand Down
3 changes: 3 additions & 0 deletions account_purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type AccountPurchase struct {
// The tax exemption certificate number for the account. If the merchant has an integration for the Vertex tax provider, this optional value will be sent in any tax calculation requests for the account.
ExemptionCertificate *string `json:"exemption_certificate,omitempty"`

// Unique ID to identify the business entity assigned to the account. Available when the `Multiple Business Entities` feature is enabled.
OverrideBusinessEntityId *string `json:"override_business_entity_id,omitempty"`

// The account code of the parent account to be associated with this account. Passing an empty value removes any existing parent association from this account. If both `parent_account_code` and `parent_account_id` are passed, the non-blank value in `parent_account_id` will be used. Only one level of parent child relationship is allowed. You cannot assign a parent account that itself has a parent account.
ParentAccountCode *string `json:"parent_account_code,omitempty"`

Expand Down
3 changes: 3 additions & 0 deletions account_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type AccountUpdate struct {
// The tax exemption certificate number for the account. If the merchant has an integration for the Vertex tax provider, this optional value will be sent in any tax calculation requests for the account.
ExemptionCertificate *string `json:"exemption_certificate,omitempty"`

// Unique ID to identify the business entity assigned to the account. Available when the `Multiple Business Entities` feature is enabled.
OverrideBusinessEntityId *string `json:"override_business_entity_id,omitempty"`

// The account code of the parent account to be associated with this account. Passing an empty value removes any existing parent association from this account. If both `parent_account_code` and `parent_account_id` are passed, the non-blank value in `parent_account_id` will be used. Only one level of parent child relationship is allowed. You cannot assign a parent account that itself has a parent account.
ParentAccountCode *string `json:"parent_account_code,omitempty"`

Expand Down
150 changes: 150 additions & 0 deletions business_entity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// 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 BusinessEntity struct {
recurlyResponse *ResponseMetadata

// Business entity ID
Id string `json:"id,omitempty"`

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

// The entity code of the business entity.
Code string `json:"code,omitempty"`

// This name describes your business entity and will appear on the invoice.
Name string `json:"name,omitempty"`

// Address information for the business entity that will appear on the invoice.
InvoiceDisplayAddress Address `json:"invoice_display_address,omitempty"`

// Address information for the business entity that will be used for calculating taxes.
TaxAddress Address `json:"tax_address,omitempty"`

// VAT number for the customer used on the invoice.
DefaultVatNumber string `json:"default_vat_number,omitempty"`

// Registration number for the customer used on the invoice.
DefaultRegistrationNumber string `json:"default_registration_number,omitempty"`

// List of countries for which the business entity will be used.
SubscriberLocationCountries []string `json:"subscriber_location_countries,omitempty"`

// Created at
CreatedAt time.Time `json:"created_at,omitempty"`

// Last updated at
UpdatedAt time.Time `json:"updated_at,omitempty"`
}

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

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

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

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

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

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

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

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

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

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

func (list *BusinessEntityList) Data() []BusinessEntity {
return list.data
}

// Fetch fetches the next page of data into the `Data` property
func (list *BusinessEntityList) FetchWithContext(ctx context.Context) error {
resources := &businessEntityList{}
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 *BusinessEntityList) Fetch() error {
return list.FetchWithContext(context.Background())
}

// Count returns the count of items on the server that match this pager
func (list *BusinessEntityList) CountWithContext(ctx context.Context) (*int64, error) {
resources := &businessEntityList{}
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 *BusinessEntityList) Count() (*int64, error) {
return list.CountWithContext(context.Background())
}
139 changes: 139 additions & 0 deletions client_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ type ClientInterface interface {

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

GetBusinessEntity(businessEntityId string, opts ...Option) (*BusinessEntity, error)
GetBusinessEntityWithContext(ctx context.Context, businessEntityId string, opts ...Option) (*BusinessEntity, error)

ListBusinessEntities(opts ...Option) (BusinessEntityLister, error)

ListGiftCards(opts ...Option) (GiftCardLister, error)

CreateGiftCard(body *GiftCardCreate, opts ...Option) (*GiftCard, error)
Expand All @@ -467,6 +472,8 @@ type ClientInterface interface {

RedeemGiftCard(redemptionCode string, body *GiftCardRedeem, opts ...Option) (*GiftCard, error)
RedeemGiftCardWithContext(ctx context.Context, redemptionCode string, body *GiftCardRedeem, opts ...Option) (*GiftCard, error)

ListBusinessEntityInvoices(businessEntityId string, params *ListBusinessEntityInvoicesParams, opts ...Option) (InvoiceLister, error)
}

type ListSitesParams struct {
Expand Down Expand Up @@ -7058,6 +7065,49 @@ func (c *Client) ListAccountExternalSubscriptions(accountId string, params *List
return NewExternalSubscriptionList(c, path, requestOptions), nil
}

// GetBusinessEntity wraps GetBusinessEntityWithContext using the background context
func (c *Client) GetBusinessEntity(businessEntityId string, opts ...Option) (*BusinessEntity, error) {
ctx := context.Background()
return c.getBusinessEntity(ctx, businessEntityId, opts...)
}

// GetBusinessEntityWithContext Fetch a business entity
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/get_business_entity
//
// Returns: Business entity details
func (c *Client) GetBusinessEntityWithContext(ctx context.Context, businessEntityId string, opts ...Option) (*BusinessEntity, error) {
return c.getBusinessEntity(ctx, businessEntityId, opts...)
}

func (c *Client) getBusinessEntity(ctx context.Context, businessEntityId string, opts ...Option) (*BusinessEntity, error) {
path, err := c.InterpolatePath("/business_entities/{business_entity_id}", businessEntityId)
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
result := &BusinessEntity{}
err = c.Call(ctx, http.MethodGet, path, nil, nil, requestOptions, result)
if err != nil {
return nil, err
}
return result, err
}

// ListBusinessEntities List business entities
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/list_business_entities
//
// Returns: List of all business entities on your site.
func (c *Client) ListBusinessEntities(opts ...Option) (BusinessEntityLister, error) {
path, err := c.InterpolatePath("/business_entities")
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
return NewBusinessEntityList(c, path, requestOptions), nil
}

// ListGiftCards List gift cards
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/list_gift_cards
Expand Down Expand Up @@ -7187,3 +7237,92 @@ func (c *Client) redeemGiftCard(ctx context.Context, redemptionCode string, body
}
return result, err
}

type ListBusinessEntityInvoicesParams struct {

// Ids - Filter results by their IDs. Up to 200 IDs can be passed at once using
// commas as separators, e.g. `ids=h1at4d57xlmy,gyqgg0d3v9n1,jrsm5b4yefg6`.
// **Important notes:**
// * The `ids` parameter cannot be used with any other ordering or filtering
// parameters (`limit`, `order`, `sort`, `begin_time`, `end_time`, etc)
// * Invalid or unknown IDs will be ignored, so you should check that the
// results correspond to your request.
// * Records are returned in an arbitrary order. Since results are all
// returned at once you can sort the records yourself.
Ids []string

// Limit - Limit number of records 1-200.
Limit *int

// Order - Sort order.
Order *string

// 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

// BeginTime - Inclusively filter by begin_time when `sort=created_at` or `sort=updated_at`.
// **Note:** this value is an ISO8601 timestamp. A partial timestamp that does not include a time zone will default to UTC.
BeginTime *time.Time

// EndTime - Inclusively filter by end_time when `sort=created_at` or `sort=updated_at`.
// **Note:** this value is an ISO8601 timestamp. A partial timestamp that does not include a time zone will default to UTC.
EndTime *time.Time

// Type - Filter by type when:
// - `type=charge`, only charge invoices will be returned.
// - `type=credit`, only credit invoices will be returned.
// - `type=non-legacy`, only charge and credit invoices will be returned.
// - `type=legacy`, only legacy invoices will be returned.
Type *string
}

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

if list.Ids != nil {
options = append(options, KeyValue{Key: "ids", Value: strings.Join(list.Ids, ",")})
}

if list.Limit != nil {
options = append(options, KeyValue{Key: "limit", Value: strconv.Itoa(*list.Limit)})
}

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

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

if list.BeginTime != nil {
options = append(options, KeyValue{Key: "begin_time", Value: formatTime(*list.BeginTime)})
}

if list.EndTime != nil {
options = append(options, KeyValue{Key: "end_time", Value: formatTime(*list.EndTime)})
}

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

return options
}

// ListBusinessEntityInvoices List a business entity's invoices
//
// API Documentation: https://developers.recurly.com/api/v2021-02-25#operation/list_business_entity_invoices
//
// Returns: A list of the business entity's invoices.
func (c *Client) ListBusinessEntityInvoices(businessEntityId string, params *ListBusinessEntityInvoicesParams, opts ...Option) (InvoiceLister, error) {
path, err := c.InterpolatePath("/business_entities/{business_entity_id}/invoices", businessEntityId)
if err != nil {
return nil, err
}
requestOptions := NewRequestOptions(opts...)
path = BuildURL(path, params)
return NewInvoiceList(c, path, requestOptions), nil
}
3 changes: 3 additions & 0 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ type Invoice struct {

// Last communication attempt.
FinalDunningEvent bool `json:"final_dunning_event,omitempty"`

// Unique ID to identify the business entity assigned to the invoice. Available when the `Multiple Business Entities` feature is enabled.
BusinessEntityId string `json:"business_entity_id,omitempty"`
}

// GetResponse returns the ResponseMetadata that generated this resource
Expand Down
Loading

0 comments on commit 19b4fae

Please sign in to comment.