checkout

package
v0.0.0-...-df769fd Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionRequiredError

type ActionRequiredError struct {
	Action *PaymentAction
	Result *FinalizeResult
}

ActionRequiredError reports a guarded stop when payment needs redirect/3DS.

func (*ActionRequiredError) Error

func (e *ActionRequiredError) Error() string

type CheckoutIssue

type CheckoutIssue struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

CheckoutIssue is a normalized validation or business issue returned by checkout.

type CheckoutPreview

type CheckoutPreview struct {
	Provider        string             `json:"provider"`
	UserID          string             `json:"user_id"`
	CartID          string             `json:"cart_id,omitempty"`
	ItemCount       int                `json:"item_count"`
	Total           *Money             `json:"total,omitempty"`
	Reservation     *ReservationWindow `json:"reservation,omitempty"`
	Payment         *PaymentSelection  `json:"payment,omitempty"`
	ReadyToFinalize bool               `json:"ready_to_finalize"`
	Issues          []CheckoutIssue    `json:"issues,omitempty"`
	Raw             map[string]any     `json:"raw,omitempty"`
}

CheckoutPreview is the normalized Frisco express-checkout cart snapshot.

type Client

type Client interface {
	Preview(s *session.Session, opts PreviewOptions) (*CheckoutPreview, error)
	Finalize(s *session.Session, opts FinalizeOptions) (*FinalizeResult, error)
}

Client is the provider-aware checkout interface shared by Frisco and Delio.

func NewClient

func NewClient(provider string) Client

NewClient returns a provider-aware checkout client.

Unknown or empty providers fall back to the existing Frisco implementation so the returned client is always usable; provider validation still happens in the concrete client methods.

func NewClientForSession

func NewClientForSession(s *session.Session, fallbackProvider string) Client

NewClientForSession selects a checkout client from the session when possible.

type DelioClient

type DelioClient struct{}

DelioClient implements the Delio checkout core using internal/delio helpers.

func NewDelioClient

func NewDelioClient() *DelioClient

NewDelioClient returns a checkout client backed by internal/delio helpers.

func (*DelioClient) Finalize

func (c *DelioClient) Finalize(s *session.Session, opts FinalizeOptions) (*FinalizeResult, error)

Finalize safely attempts the Delio payment step and only reports placed when the provider response clearly proves the order was placed.

func (*DelioClient) Preview

Preview fetches and normalizes the current Delio checkout state.

type FinalizeGuard

type FinalizeGuard struct {
	ExpectedCartID    string   `json:"expected_cart_id,omitempty"`
	ExpectedItemCount *int     `json:"expected_item_count,omitempty"`
	ExpectedTotal     *float64 `json:"expected_total,omitempty"`
}

FinalizeGuard allows callers to verify the preview state before placing an order.

type FinalizeOptions

type FinalizeOptions struct {
	Provider            string         `json:"provider,omitempty"`
	UserID              string         `json:"user_id,omitempty"`
	Guard               *FinalizeGuard `json:"guard,omitempty"`
	AllowActionRequired bool           `json:"allow_action_required,omitempty"`
}

FinalizeOptions controls Frisco order finalization.

type FinalizeResult

type FinalizeResult struct {
	Provider    string           `json:"provider"`
	UserID      string           `json:"user_id"`
	Status      FinalizeStatus   `json:"status"`
	OrderID     string           `json:"order_id,omitempty"`
	Preview     *CheckoutPreview `json:"preview,omitempty"`
	Action      *PaymentAction   `json:"action,omitempty"`
	Readback    *OrderReadback   `json:"readback,omitempty"`
	APIResponse map[string]any   `json:"api_response,omitempty"`
}

FinalizeResult captures the POST /order response plus optional readback.

type FinalizeStatus

type FinalizeStatus string

FinalizeStatus is the normalized high-level outcome of a finalize attempt.

const (
	FinalizeStatusPlaced         FinalizeStatus = "placed"
	FinalizeStatusRequiresAction FinalizeStatus = "requires_action"
	FinalizeStatusPending        FinalizeStatus = "pending"
	FinalizeStatusUnknown        FinalizeStatus = "unknown"
)

type FriscoClient

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

FriscoClient implements the Frisco-only express-checkout core flow.

func NewFriscoClient

func NewFriscoClient() *FriscoClient

NewFriscoClient returns a checkout client backed by internal/httpclient.

func NewFriscoClientForTests

func NewFriscoClientForTests(httpClient *http.Client) *FriscoClient

NewFriscoClientForTests allows tests to inject a custom HTTP client.

func (*FriscoClient) Finalize

func (c *FriscoClient) Finalize(s *session.Session, opts FinalizeOptions) (*FinalizeResult, error)

Finalize places the Frisco express-checkout order, reads the order back when possible, and blocks redirect/3DS flows behind a structured ActionRequiredError by default.

func (*FriscoClient) Preview

Preview fetches and normalizes Frisco express-checkout cart data.

type GuardMismatchError

type GuardMismatchError struct {
	Field string
	Want  string
	Got   string
}

GuardMismatchError reports that finalize guards did not match the fresh preview.

func (*GuardMismatchError) Error

func (e *GuardMismatchError) Error() string

type MalformedResponseError

type MalformedResponseError struct {
	Operation string
	Message   string
}

MalformedResponseError reports that the provider returned an unexpected shape.

func (*MalformedResponseError) Error

func (e *MalformedResponseError) Error() string

type Money

type Money struct {
	Amount   float64 `json:"amount"`
	Currency string  `json:"currency,omitempty"`
}

Money captures a typed monetary amount extracted from checkout payloads.

type OrderReadback

type OrderReadback struct {
	OrderID  string           `json:"order_id,omitempty"`
	Order    map[string]any   `json:"order,omitempty"`
	Payments []map[string]any `json:"payments,omitempty"`
}

OrderReadback contains post-finalize GET responses when an order ID is known.

type PaymentAction

type PaymentAction struct {
	Kind    PaymentActionKind `json:"kind"`
	URL     string            `json:"url,omitempty"`
	Method  string            `json:"method,omitempty"`
	Message string            `json:"message,omitempty"`
	Payload map[string]any    `json:"payload,omitempty"`
}

PaymentAction captures required post-finalize interaction such as redirect/3DS.

func (*PaymentAction) IsRedirect

func (a *PaymentAction) IsRedirect() bool

IsRedirect reports whether the action URL is an absolute web URL.

type PaymentActionKind

type PaymentActionKind string

PaymentActionKind describes what kind of user/browser step is still required.

const (
	PaymentActionKindRedirect PaymentActionKind = "redirect"
	PaymentActionKind3DS      PaymentActionKind = "3ds"
)

type PaymentSelection

type PaymentSelection struct {
	Method  string `json:"method,omitempty"`
	Channel string `json:"channel,omitempty"`
	Status  string `json:"status,omitempty"`
}

PaymentSelection describes the currently selected payment option in checkout.

type PreviewOptions

type PreviewOptions struct {
	Provider string `json:"provider,omitempty"`
	UserID   string `json:"user_id,omitempty"`
}

PreviewOptions controls checkout preview fetching.

type ReservationWindow

type ReservationWindow struct {
	StartsAt       string `json:"starts_at,omitempty"`
	EndsAt         string `json:"ends_at,omitempty"`
	DeliveryMethod string `json:"delivery_method,omitempty"`
	Warehouse      string `json:"warehouse,omitempty"`
}

ReservationWindow summarizes the reserved delivery window used for checkout.

type UnsupportedProviderError

type UnsupportedProviderError struct {
	Provider  string
	Supported []string
}

UnsupportedProviderError reports that the selected provider is not supported by the requested checkout flow.

func (*UnsupportedProviderError) Error

func (e *UnsupportedProviderError) Error() string

Jump to

Keyboard shortcuts

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