Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.49.0"
".": "1.50.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 118
configured_endpoints: 126
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-a5a28a58483355d3cc3da7ac5c452d548ee17183324318198052968121ca7dba.yml
openapi_spec_hash: a317931a99e6d4a122919135a0363e40
config_hash: 05c94c0e6dbeab2c9b554c2e0d6371a0
config_hash: bcf82bddb691f6be773ac6cae8c03b9a
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.50.0 (2026-01-08)

Full Changelog: [v1.49.0...v1.50.0](https://github.com/orbcorp/orb-go/compare/v1.49.0...v1.50.0)

### Features

* **api:** manual updates ([619d599](https://github.com/orbcorp/orb-go/commit/619d5991d058fbad50a8db80355a0015965d25ce))

## 1.49.0 (2026-01-06)

Full Changelog: [v1.48.0...v1.49.0](https://github.com/orbcorp/orb-go/compare/v1.48.0...v1.49.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Or to pin the version:
<!-- x-release-please-start-version -->

```sh
go get -u 'github.com/orbcorp/orb-go@v1.49.0'
go get -u 'github.com/orbcorp/orb-go@v1.50.0'
```

<!-- x-release-please-end -->
Expand Down
30 changes: 30 additions & 0 deletions api.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Client struct {

Webhooks *WebhookService
SubscriptionChanges *SubscriptionChangeService
CreditBlocks *CreditBlockService
}

// DefaultClientOptions read from the environment (ORB_API_KEY, ORB_WEBHOOK_SECRET,
Expand Down Expand Up @@ -79,6 +80,7 @@ func NewClient(opts ...option.RequestOption) (r *Client) {
r.Alerts = NewAlertService(opts...)
r.DimensionalPriceGroups = NewDimensionalPriceGroupService(opts...)
r.SubscriptionChanges = NewSubscriptionChangeService(opts...)
r.CreditBlocks = NewCreditBlockService(opts...)

return
}
Expand Down
188 changes: 188 additions & 0 deletions creditblock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package orb

import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"time"

"github.com/orbcorp/orb-go/internal/apijson"
"github.com/orbcorp/orb-go/internal/requestconfig"
"github.com/orbcorp/orb-go/option"
)

// CreditBlockService contains methods and other services that help with
// interacting with the orb API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewCreditBlockService] method instead.
type CreditBlockService struct {
Options []option.RequestOption
}

// NewCreditBlockService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewCreditBlockService(opts ...option.RequestOption) (r *CreditBlockService) {
r = &CreditBlockService{}
r.Options = opts
return
}

// This endpoint returns a credit block identified by its block_id.
func (r *CreditBlockService) Get(ctx context.Context, blockID string, opts ...option.RequestOption) (res *CreditBlockGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if blockID == "" {
err = errors.New("missing required block_id parameter")
return
}
path := fmt.Sprintf("credit_blocks/%s", blockID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}

// This endpoint deletes a credit block by its ID.
//
// When a credit block is deleted:
//
// - The block is removed from the customer's credit ledger.
// - Any usage of the credit block is reversed, and the ledger is replayed as if
// the block never existed.
// - If invoices were generated from the purchase of the credit block, they will be
// deleted if in draft status, voided if issued, or a credit note will be issued
// if the invoice is paid.
//
// <Note>
// Issued invoices that had credits applied from this block will not be regenerated, but the ledger will
// reflect the state as if credits from the deleted block were never applied.
// </Note>
func (r *CreditBlockService) Delete(ctx context.Context, blockID string, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
if blockID == "" {
err = errors.New("missing required block_id parameter")
return
}
path := fmt.Sprintf("credit_blocks/%s", blockID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return
}

// The Credit Block resource models prepaid credits within Orb.
type CreditBlockGetResponse struct {
ID string `json:"id,required"`
Balance float64 `json:"balance,required"`
EffectiveDate time.Time `json:"effective_date,required,nullable" format:"date-time"`
ExpiryDate time.Time `json:"expiry_date,required,nullable" format:"date-time"`
Filters []CreditBlockGetResponseFilter `json:"filters,required"`
MaximumInitialBalance float64 `json:"maximum_initial_balance,required,nullable"`
PerUnitCostBasis string `json:"per_unit_cost_basis,required,nullable"`
Status CreditBlockGetResponseStatus `json:"status,required"`
JSON creditBlockGetResponseJSON `json:"-"`
}

// creditBlockGetResponseJSON contains the JSON metadata for the struct
// [CreditBlockGetResponse]
type creditBlockGetResponseJSON struct {
ID apijson.Field
Balance apijson.Field
EffectiveDate apijson.Field
ExpiryDate apijson.Field
Filters apijson.Field
MaximumInitialBalance apijson.Field
PerUnitCostBasis apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *CreditBlockGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r creditBlockGetResponseJSON) RawJSON() string {
return r.raw
}

type CreditBlockGetResponseFilter struct {
// The property of the price to filter on.
Field CreditBlockGetResponseFiltersField `json:"field,required"`
// Should prices that match the filter be included or excluded.
Operator CreditBlockGetResponseFiltersOperator `json:"operator,required"`
// The IDs or values that match this filter.
Values []string `json:"values,required"`
JSON creditBlockGetResponseFilterJSON `json:"-"`
}

// creditBlockGetResponseFilterJSON contains the JSON metadata for the struct
// [CreditBlockGetResponseFilter]
type creditBlockGetResponseFilterJSON struct {
Field apijson.Field
Operator apijson.Field
Values apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *CreditBlockGetResponseFilter) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r creditBlockGetResponseFilterJSON) RawJSON() string {
return r.raw
}

// The property of the price to filter on.
type CreditBlockGetResponseFiltersField string

const (
CreditBlockGetResponseFiltersFieldPriceID CreditBlockGetResponseFiltersField = "price_id"
CreditBlockGetResponseFiltersFieldItemID CreditBlockGetResponseFiltersField = "item_id"
CreditBlockGetResponseFiltersFieldPriceType CreditBlockGetResponseFiltersField = "price_type"
CreditBlockGetResponseFiltersFieldCurrency CreditBlockGetResponseFiltersField = "currency"
CreditBlockGetResponseFiltersFieldPricingUnitID CreditBlockGetResponseFiltersField = "pricing_unit_id"
)

func (r CreditBlockGetResponseFiltersField) IsKnown() bool {
switch r {
case CreditBlockGetResponseFiltersFieldPriceID, CreditBlockGetResponseFiltersFieldItemID, CreditBlockGetResponseFiltersFieldPriceType, CreditBlockGetResponseFiltersFieldCurrency, CreditBlockGetResponseFiltersFieldPricingUnitID:
return true
}
return false
}

// Should prices that match the filter be included or excluded.
type CreditBlockGetResponseFiltersOperator string

const (
CreditBlockGetResponseFiltersOperatorIncludes CreditBlockGetResponseFiltersOperator = "includes"
CreditBlockGetResponseFiltersOperatorExcludes CreditBlockGetResponseFiltersOperator = "excludes"
)

func (r CreditBlockGetResponseFiltersOperator) IsKnown() bool {
switch r {
case CreditBlockGetResponseFiltersOperatorIncludes, CreditBlockGetResponseFiltersOperatorExcludes:
return true
}
return false
}

type CreditBlockGetResponseStatus string

const (
CreditBlockGetResponseStatusActive CreditBlockGetResponseStatus = "active"
CreditBlockGetResponseStatusPendingPayment CreditBlockGetResponseStatus = "pending_payment"
)

func (r CreditBlockGetResponseStatus) IsKnown() bool {
switch r {
case CreditBlockGetResponseStatusActive, CreditBlockGetResponseStatusPendingPayment:
return true
}
return false
}
58 changes: 58 additions & 0 deletions creditblock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package orb_test

import (
"context"
"errors"
"os"
"testing"

"github.com/orbcorp/orb-go"
"github.com/orbcorp/orb-go/internal/testutil"
"github.com/orbcorp/orb-go/option"
)

func TestCreditBlockGet(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := orb.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.CreditBlocks.Get(context.TODO(), "block_id")
if err != nil {
var apierr *orb.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

func TestCreditBlockDelete(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := orb.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
err := client.CreditBlocks.Delete(context.TODO(), "block_id")
if err != nil {
var apierr *orb.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package internal

const PackageVersion = "1.49.0" // x-release-please-version
const PackageVersion = "1.50.0" // x-release-please-version
Loading