boltgo

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-3.0, MIT Imports: 13 Imported by: 0

README

github.com/BoltApp/bolt-go

SDK Installation

go get github.com/BoltApp/bolt-go

SDK Example Usage

Example
package main

import (
	"context"
	boltgo "github.com/BoltApp/bolt-go"
	"github.com/BoltApp/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
Orders
  • OrdersCreate - Create an order that was placed outside the Bolt ecosystem.
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.AccountGetResponseBody 4XX application/json
sdkerrors.SDKError 4xx-5xx /
Example
package main

import (
	"context"
	"errors"
	boltgo "github.com/BoltApp/bolt-go"
	"github.com/BoltApp/bolt-go/models/components"
	"github.com/BoltApp/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.AccountGetResponseBody
		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/BoltApp/bolt-go"
	"github.com/BoltApp/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/BoltApp/bolt-go"
	"github.com/BoltApp/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/BoltApp/bolt-go"
	"github.com/BoltApp/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/BoltApp/bolt-go"
	"github.com/BoltApp/bolt-go/models/components"
	"github.com/BoltApp/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.CreatePaymentMethodInputPaymentMethodPaypal(
			components.PaymentMethodPaypal{
				DotTag:     components.PaymentMethodPaypalTagPaypal,
				SuccessURL: "https://www.example.com/paypal-callback/success",
				CancelURL:  "https://www.example.com/paypal-callback/cancel",
			},
		),
	}

	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!

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) AddAddress

func (s *Account) AddAddress(ctx context.Context, xPublishableKey string, addressListing components.AddressListingInput) (*operations.AccountAddressCreateResponse, error)

AddAddress - Add an address Add an address to the shopper's account

func (*Account) AddPaymentMethod

func (s *Account) AddPaymentMethod(ctx context.Context, xPublishableKey string, paymentMethod components.PaymentMethodInput) (*operations.AccountAddPaymentMethodResponse, error)

AddPaymentMethod - Add a payment method to a shopper's Bolt account Wallet. Add a payment method to a shopper's Bolt account Wallet. For security purposes, this request must come from your backend because authentication requires the use of your private key.<br /> **Note**: Before using this API, the credit card details must be tokenized using Bolt's JavaScript library function, which is documented in [Install the Bolt Tokenizer](https://help.bolt.com/developers/references/bolt-tokenizer).

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

func (*Account) UpdateAddress

func (s *Account) UpdateAddress(ctx context.Context, id string, xPublishableKey string, addressListing components.AddressListingInput) (*operations.AccountAddressEditResponse, error)

UpdateAddress - Edit an existing address Edit an existing address on the shopper's account. This does not edit addresses that are already associated with other resources, such as transactions or shipments.

type BoltTypescriptSDK

type BoltTypescriptSDK 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
	// Use the Orders API to create and manage orders, including orders that have been placed outside the Bolt ecosystem.
	//
	Orders *Orders
	// 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
}

BoltTypescriptSDK - 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) *BoltTypescriptSDK

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 Orders

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

Orders - Use the Orders API to create and manage orders, including orders that have been placed outside the Bolt ecosystem.

func (*Orders) OrdersCreate

func (s *Orders) OrdersCreate(ctx context.Context, security operations.OrdersCreateSecurity, xPublishableKey string, order components.Order) (*operations.OrdersCreateResponse, error)

OrdersCreate - Create an order that was placed outside the Bolt ecosystem. Create an order that was placed outside the Bolt ecosystem.

type Payments

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

type SDKOption

type SDKOption func(*BoltTypescriptSDK)

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 can be used to process payments.

func (*Testing) TestingAccountPhoneGet added in v0.4.2

func (s *Testing) TestingAccountPhoneGet(ctx context.Context, security operations.TestingAccountPhoneGetSecurity, xPublishableKey string) (*operations.TestingAccountPhoneGetResponse, error)

TestingAccountPhoneGet - Get a random phone number Get a random, fictitious phone number that is not assigned to any existing account.

Directories

Path Synopsis
internal
models

Jump to

Keyboard shortcuts

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