package bits import ( "context" "encoding/json" "fmt" "net/http" "net/url" "time" "github.com/google/go-querystring/query" "go.fifitido.net/twitch/api/types" ) type GetExtensionTransactionsParams struct { // The ID of the extension whose list of transactions you want to get. ExtensionID string `url:"extension_id"` // A transaction ID used to filter the list of transactions. Specify this parameter for each transaction you want to get. // For example, id=1234&id=5678. You may specify a maximum of 100 IDs. IDs []string `url:"ids,omitempty"` // The maximum number of items to return per page in the response. // The minimum page size is 1 item per page and the maximum is 100 items per page. The default is 20. First *int `url:"first,omitempty"` // The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value. // Read More: https://dev.twitch.tv/docs/api/guide#pagination After *types.Cursor `url:"after,omitempty"` } type GetExtensionTransactionsResponse struct { // The list of transactions. Data []ExtensionTransaction `json:"data"` // Contains the information used to page through the list of results. The object is empty if there are no more pages left to page through. // Read More: https://dev.twitch.tv/docs/api/guide#pagination Pagination types.Pagination `json:"pagination"` } type ExtensionTransaction struct { // An ID that identifies the transaction. ID string `json:"id"` // The UTC date and time (in RFC3339 format) of the transaction. Timestamp time.Time `json:"timestamp"` // The ID of the broadcaster that owns the channel where the transaction occurred. BroadcasterID string `json:"broadcaster_id"` // The broadcaster’s login name. BroadcasterLogin string `json:"broadcaster_login"` // The broadcaster’s display name. BroadcasterName string `json:"broadcaster_name"` // The type of transaction. Possible values are: // // BITS_IN_EXTENSION ProductType string `json:"product_type"` } type ProductData struct { // An ID that identifies the digital product. SKU string `json:"sku"` // Set to twitch.ext. + . Domain string `json:"domain"` // Contains details about the digital product’s cost. Cost ProductDataCost `json:"cost"` // A Boolean value that determines whether the product is in development. Is true if the digital product is in development and cannot be exchanged. InDevelopment bool `json:"in_development"` // The name of the digital product. DisplayName string `json:"display_name"` // This field is always empty since you may purchase only unexpired products. Expiration string `json:"expiration"` // A Boolean value that determines whether the data was broadcast to all instances of the extension. Is true if the data was broadcast to all instances. Broadcast bool `json:"broadcast"` } type ProductDataCost struct { // The amount exchanged for the digital product. Amount int `json:"amount"` // The type of currency exchanged. Possible values are: // // bits Type string `json:"type"` } // Gets an extension’s list of transactions. A transaction records the exchange of a currency (for example, Bits) for a digital product. // // Requires an app access token. func (b *Bits) GetExtensionTransactions(ctx context.Context, params *GetExtensionTransactionsParams) (*GetExtensionTransactionsResponse, error) { v, _ := query.Values(params) endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "extensions/transactions", RawQuery: v.Encode()}) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) if err != nil { return nil, err } res, err := b.client.Do(req) if err != nil { return nil, err } defer res.Body.Close() statusOK := res.StatusCode >= 200 && res.StatusCode < 300 if !statusOK { return nil, fmt.Errorf("failed to get extension transactions (%d)", res.StatusCode) } var data GetExtensionTransactionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err } return &data, nil }