boltgo

package module
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 13 Imported by: 0

README ΒΆ

github.com/speakeasy-sdks/bolt-go

πŸ— Welcome to your new SDK! πŸ—

It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:

SDK Installation

go get github.com/speakeasy-sdks/bolt-go

SDK Example Usage

Example
package main

import (
	"context"
	boltgo "github.com/speakeasy-sdks/bolt-go"
	"github.com/speakeasy-sdks/bolt-go/models/components"
	"log"
)

func main() {
	s := boltgo.New(
		boltgo.WithSecurity(components.Security{
			Oauth: boltgo.String("Bearer <YOUR_ACCESS_TOKEN_HERE>"),
		}),
	)

	var xPublishableKey string = "<value>"

	ctx := context.Background()
	res, err := s.Account.GetDetails(ctx, xPublishableKey)
	if err != nil {
		log.Fatal(err)
	}
	if res.Account != nil {
		// handle response
	}
}

Available Resources and Operations

Account
Payments.Guest
  • Initialize - Initialize a Bolt payment for guest shoppers
  • Update - Update an existing guest payment
  • PerformAction - Perform an irreversible action (e.g. finalize) on a pending guest payment
Payments.LoggedIn
  • Initialize - Initialize a Bolt payment for logged in shoppers
  • Update - Update an existing payment
  • PerformAction - Perform an irreversible action (e.g. finalize) on a pending payment
OAuth
Testing

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.

Error Object Status Code Content Type
sdkerrors.Error 4XX application/json
sdkerrors.SDKError 4xx-5xx /
Example
package main

import (
	"context"
	"errors"
	boltgo "github.com/speakeasy-sdks/bolt-go"
	"github.com/speakeasy-sdks/bolt-go/models/components"
	"github.com/speakeasy-sdks/bolt-go/models/sdkerrors"
	"log"
)

func main() {
	s := boltgo.New(
		boltgo.WithSecurity(components.Security{
			Oauth: boltgo.String("Bearer <YOUR_ACCESS_TOKEN_HERE>"),
		}),
	)

	var xPublishableKey string = "<value>"

	ctx := context.Background()
	res, err := s.Account.GetDetails(ctx, xPublishableKey)
	if err != nil {

		var e *sdkerrors.Error
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.SDKError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}
	}
}

Server Selection

Select Server by Index

You can override the default server globally using the WithServerIndex option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables
0 https://{environment}.bolt.com/v3 environment (default is api-sandbox)
Example
package main

import (
	"context"
	boltgo "github.com/speakeasy-sdks/bolt-go"
	"github.com/speakeasy-sdks/bolt-go/models/components"
	"log"
)

func main() {
	s := boltgo.New(
		boltgo.WithServerIndex(0),
		boltgo.WithSecurity(components.Security{
			Oauth: boltgo.String("Bearer <YOUR_ACCESS_TOKEN_HERE>"),
		}),
	)

	var xPublishableKey string = "<value>"

	ctx := context.Background()
	res, err := s.Account.GetDetails(ctx, xPublishableKey)
	if err != nil {
		log.Fatal(err)
	}
	if res.Account != nil {
		// handle response
	}
}

Variables

Some of the server options above contain variables. If you want to set the values of those variables, the following options are provided for doing so:

  • WithEnvironment boltgo.ServerEnvironment
Override Server URL Per-Client

The default server can also be overridden globally using the WithServerURL option when initializing the SDK client instance. For example:

package main

import (
	"context"
	boltgo "github.com/speakeasy-sdks/bolt-go"
	"github.com/speakeasy-sdks/bolt-go/models/components"
	"log"
)

func main() {
	s := boltgo.New(
		boltgo.WithServerURL("https://{environment}.bolt.com/v3"),
		boltgo.WithSecurity(components.Security{
			Oauth: boltgo.String("Bearer <YOUR_ACCESS_TOKEN_HERE>"),
		}),
	)

	var xPublishableKey string = "<value>"

	ctx := context.Background()
	res, err := s.Account.GetDetails(ctx, xPublishableKey)
	if err != nil {
		log.Fatal(err)
	}
	if res.Account != nil {
		// handle response
	}
}

Custom HTTP Client

The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

The built-in net/http client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.

import (
	"net/http"
	"time"
	"github.com/myorg/your-go-sdk"
)

var (
	httpClient = &http.Client{Timeout: 30 * time.Second}
	sdkClient  = sdk.New(sdk.WithClient(httpClient))
)

This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.

Authentication

Per-Client Security Schemes

This SDK supports the following security schemes globally:

Name Type Scheme
Oauth oauth2 OAuth2 token
APIKey apiKey API key

You can set the security parameters through the WithSecurity option when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:

package main

import (
	"context"
	boltgo "github.com/speakeasy-sdks/bolt-go"
	"github.com/speakeasy-sdks/bolt-go/models/components"
	"log"
)

func main() {
	s := boltgo.New(
		boltgo.WithSecurity(components.Security{
			Oauth: boltgo.String("Bearer <YOUR_ACCESS_TOKEN_HERE>"),
		}),
	)

	var xPublishableKey string = "<value>"

	ctx := context.Background()
	res, err := s.Account.GetDetails(ctx, xPublishableKey)
	if err != nil {
		log.Fatal(err)
	}
	if res.Account != nil {
		// handle response
	}
}

Per-Operation Security Schemes

Some operations in this SDK require the security scheme to be specified at the request level. For example:

package main

import (
	"context"
	boltgo "github.com/speakeasy-sdks/bolt-go"
	"github.com/speakeasy-sdks/bolt-go/models/components"
	"github.com/speakeasy-sdks/bolt-go/models/operations"
	"log"
)

func main() {
	s := boltgo.New()

	var xPublishableKey string = "<value>"

	guestPaymentInitializeRequest := components.GuestPaymentInitializeRequest{
		Profile: components.ProfileCreationData{
			CreateAccount: true,
			FirstName:     "Alice",
			LastName:      "Baker",
			Email:         "alice@example.com",
			Phone:         boltgo.String("+14155550199"),
		},
		Cart: components.Cart{
			OrderReference:   "order_100",
			OrderDescription: boltgo.String("Order #1234567890"),
			DisplayID:        boltgo.String("215614191"),
			Total: components.Amount{
				Currency: components.CurrencyUsd,
				Units:    900,
			},
			Tax: components.Amount{
				Currency: components.CurrencyUsd,
				Units:    900,
			},
		},
		PaymentMethod: components.CreatePaymentMethodInputPaymentMethodCreditCardInput(
			components.PaymentMethodCreditCardInput{
				DotTag: components.DotTagCreditCard,
				BillingAddress: components.CreateAddressReferenceSchemas(
					components.Schemas{
						DotTag: components.SchemasTagID,
						ID:     "D4g3h5tBuVYK9",
					},
				),
				Network:    components.NetworkVisa,
				Bin:        "411111",
				Last4:      "1004",
				Expiration: "2029-03",
				Token:      "a1B2c3D4e5F6G7H8i9J0k1L2m3N4o5P6Q7r8S9t0",
			},
		),
	}

	operationSecurity := operations.GuestPaymentsInitializeSecurity{
		APIKey: "<YOUR_API_KEY_HERE>",
	}

	ctx := context.Background()
	res, err := s.Payments.Guest.Initialize(ctx, operationSecurity, xPublishableKey, guestPaymentInitializeRequest)
	if err != nil {
		log.Fatal(err)
	}
	if res.PaymentResponse != nil {
		// handle response
	}
}

Special Types

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!

SDK Created by Speakeasy

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var ServerList = []string{
	"https://{environment}.bolt.com/v3",
}

ServerList contains the list of servers available to the SDK

Functions ΒΆ

func Bool ΒΆ

func Bool(b bool) *bool

Bool provides a helper function to return a pointer to a bool

func Float32 ΒΆ

func Float32(f float32) *float32

Float32 provides a helper function to return a pointer to a float32

func Float64 ΒΆ

func Float64(f float64) *float64

Float64 provides a helper function to return a pointer to a float64

func Int ΒΆ

func Int(i int) *int

Int provides a helper function to return a pointer to an int

func Int64 ΒΆ

func Int64(i int64) *int64

Int64 provides a helper function to return a pointer to an int64

func String ΒΆ

func String(s string) *string

String provides a helper function to return a pointer to a string

Types ΒΆ

type Account ΒΆ

type Account struct {
	// contains filtered or unexported fields
}

Account endpoints allow you to view and manage shoppers' accounts. For example, you can add or remove addresses and payment information.

func (*Account) DeleteAddress ΒΆ

func (s *Account) DeleteAddress(ctx context.Context, id string, xPublishableKey string) (*operations.AccountAddressDeleteResponse, error)

DeleteAddress - Delete an existing address Delete an existing address. Deleting an address does not invalidate transactions or shipments that are associated with it.

func (*Account) DeletePaymentMethod ΒΆ

func (s *Account) DeletePaymentMethod(ctx context.Context, id string, xPublishableKey string) (*operations.AccountPaymentMethodDeleteResponse, error)

DeletePaymentMethod - Delete an existing payment method Delete an existing payment method. Deleting a payment method does not invalidate transactions or orders that are associated with it.

func (*Account) Detect ΒΆ

func (s *Account) Detect(ctx context.Context, identifier components.Identifier, xPublishableKey string) (*operations.AccountExistsResponse, error)

Detect - Determine the existence of a Bolt account Determine whether or not an identifier is associated with an existing Bolt account.

func (*Account) GetDetails ΒΆ

func (s *Account) GetDetails(ctx context.Context, xPublishableKey string) (*operations.AccountGetResponse, error)

GetDetails - Retrieve account details Retrieve a shopper's account details, such as addresses and payment information

type BoltPublicAPI ΒΆ

type BoltPublicAPI struct {
	// Account endpoints allow you to view and manage shoppers' accounts. For example,
	// you can add or remove addresses and payment information.
	//
	Account  *Account
	Payments *Payments
	// Use this endpoint to retrieve an OAuth token. Use the token to allow your ecommerce server to make calls to the Account
	// endpoint and create a one-click checkout experience for shoppers.
	//
	//
	// https://help.bolt.com/products/accounts/direct-api/oauth-guide/
	OAuth *OAuth
	// Endpoints that allow you to generate and retrieve test data to verify certain
	// flows in non-production environments.
	//
	Testing *Testing
	// contains filtered or unexported fields
}

BoltPublicAPI - Bolt API Reference: A comprehensive Bolt API reference for interacting with Transactions, Orders, Product Catalog, Configuration, Testing, and much more.

func New ΒΆ

func New(opts ...SDKOption) *BoltPublicAPI

New creates a new instance of the SDK with the provided options

type Guest ΒΆ

type Guest struct {
	// contains filtered or unexported fields
}

func (*Guest) Initialize ΒΆ

Initialize a Bolt payment for guest shoppers Initialize a Bolt payment token that will be used to reference this payment to Bolt when it is updated or finalized for guest shoppers.

func (*Guest) PerformAction ΒΆ

func (s *Guest) PerformAction(ctx context.Context, security operations.GuestPaymentsActionSecurity, id string, xPublishableKey string, paymentActionRequest components.PaymentActionRequest) (*operations.GuestPaymentsActionResponse, error)

PerformAction - Perform an irreversible action (e.g. finalize) on a pending guest payment Perform an irreversible action on a pending guest payment, such as finalizing it.

func (*Guest) Update ΒΆ

Update an existing guest payment Update a pending guest payment

type HTTPClient ΒΆ

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient provides an interface for suplying the SDK with a custom HTTP client

type LoggedIn ΒΆ

type LoggedIn struct {
	// contains filtered or unexported fields
}

func (*LoggedIn) Initialize ΒΆ

func (s *LoggedIn) Initialize(ctx context.Context, xPublishableKey string, paymentInitializeRequest components.PaymentInitializeRequest) (*operations.PaymentsInitializeResponse, error)

Initialize a Bolt payment for logged in shoppers Initialize a Bolt payment token that will be used to reference this payment to Bolt when it is updated or finalized for logged in shoppers.

func (*LoggedIn) PerformAction ΒΆ

func (s *LoggedIn) PerformAction(ctx context.Context, id string, xPublishableKey string, paymentActionRequest components.PaymentActionRequest) (*operations.PaymentsActionResponse, error)

PerformAction - Perform an irreversible action (e.g. finalize) on a pending payment Perform an irreversible action on a pending payment, such as finalizing it.

func (*LoggedIn) Update ΒΆ

func (s *LoggedIn) Update(ctx context.Context, id string, xPublishableKey string, paymentUpdateRequest components.PaymentUpdateRequest) (*operations.PaymentsUpdateResponse, error)

Update an existing payment Update a pending payment

type OAuth ΒΆ

type OAuth struct {
	// contains filtered or unexported fields
}

OAuth - Use this endpoint to retrieve an OAuth token. Use the token to allow your ecommerce server to make calls to the Account endpoint and create a one-click checkout experience for shoppers.

https://help.bolt.com/products/accounts/direct-api/oauth-guide/

func (*OAuth) GetToken ΒΆ

GetToken - Get OAuth token Retrieve a new or refresh an existing OAuth token.

type Payments ΒΆ

type Payments struct {
	Guest    *Guest
	LoggedIn *LoggedIn
	// contains filtered or unexported fields
}

type SDKOption ΒΆ

type SDKOption func(*BoltPublicAPI)

func WithClient ΒΆ

func WithClient(client HTTPClient) SDKOption

WithClient allows the overriding of the default HTTP client used by the SDK

func WithEnvironment ΒΆ

func WithEnvironment(environment ServerEnvironment) SDKOption

WithEnvironment allows setting the environment variable for url substitution

func WithRetryConfig ΒΆ

func WithRetryConfig(retryConfig utils.RetryConfig) SDKOption

func WithSecurity ΒΆ

func WithSecurity(security components.Security) SDKOption

WithSecurity configures the SDK to use the provided security details

func WithSecuritySource ΒΆ

func WithSecuritySource(security func(context.Context) (components.Security, error)) SDKOption

WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication

func WithServerIndex ΒΆ

func WithServerIndex(serverIndex int) SDKOption

WithServerIndex allows the overriding of the default server by index

func WithServerURL ΒΆ

func WithServerURL(serverURL string) SDKOption

WithServerURL allows the overriding of the default server URL

func WithTemplatedServerURL ΒΆ

func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption

WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters

type ServerEnvironment ΒΆ

type ServerEnvironment string
const (
	ServerEnvironmentAPI        ServerEnvironment = "api"
	ServerEnvironmentAPISandbox ServerEnvironment = "api-sandbox"
)

func (ServerEnvironment) ToPointer ΒΆ

func (e ServerEnvironment) ToPointer() *ServerEnvironment

func (*ServerEnvironment) UnmarshalJSON ΒΆ

func (e *ServerEnvironment) UnmarshalJSON(data []byte) error

type Testing ΒΆ

type Testing struct {
	// contains filtered or unexported fields
}

Testing - Endpoints that allow you to generate and retrieve test data to verify certain flows in non-production environments.

func (*Testing) CreateAccount ΒΆ

func (s *Testing) CreateAccount(ctx context.Context, security operations.TestingAccountCreateSecurity, xPublishableKey string, accountTestCreationData components.AccountTestCreationData) (*operations.TestingAccountCreateResponse, error)

CreateAccount - Create a test account Create a Bolt shopper account for testing purposes.

func (*Testing) GetCreditCard ΒΆ

GetCreditCard - Retrieve a test credit card, including its token Retrieve test credit card information. This includes its token, which is generated against the `4111 1111 1111 1004` test card.

Directories ΒΆ

Path Synopsis
internal
models

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL