discount

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package discount provides models generated from the stable ACP discount extension schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocation

type Allocation struct {
	// Amount allocated to this target in minor (cents) currency units.
	Amount int `json:"amount" yaml:"amount" mapstructure:"amount"`

	// JSONPath to the allocation target (e.g., '$.line_items[0]',
	// '$.totals.shipping').
	Path string `json:"path" yaml:"path" mapstructure:"path"`
}

Breakdown of how a discount amount was allocated to a specific target.

func (*Allocation) UnmarshalJSON

func (j *Allocation) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type AppliedDiscount

type AppliedDiscount struct {
	// Breakdown of where this discount was allocated. Sum of allocation amounts
	// equals total amount.
	Allocations []Allocation `json:"allocations,omitempty,omitzero" yaml:"allocations,omitempty" mapstructure:"allocations,omitempty"`

	// Total discount amount in minor (cents) currency units.
	Amount int `json:"amount" yaml:"amount" mapstructure:"amount"`

	// True if applied automatically by merchant rules (no code required).
	Automatic bool `json:"automatic,omitempty,omitzero" yaml:"automatic,omitempty" mapstructure:"automatic,omitempty"`

	// The discount code entered by the user. Omitted for automatic discounts.
	Code *string `json:"code,omitempty,omitzero" yaml:"code,omitempty" mapstructure:"code,omitempty"`

	// Details about the underlying coupon/promotion.
	Coupon Coupon `json:"coupon" yaml:"coupon" mapstructure:"coupon"`

	// RFC 3339 timestamp when the discount expires.
	End *time.Time `json:"end,omitempty,omitzero" yaml:"end,omitempty" mapstructure:"end,omitempty"`

	// Unique identifier for this applied discount instance.
	Id string `json:"id" yaml:"id" mapstructure:"id"`

	// Allocation method. 'each' = applied independently per item (allocations
	// typically included). 'across' = applied to order total (allocations typically
	// omitted).
	Method *AppliedDiscountMethod `json:"method,omitempty,omitzero" yaml:"method,omitempty" mapstructure:"method,omitempty"`

	// Stacking order for discount calculation. Lower numbers applied first (1 =
	// first).
	Priority *int `json:"priority,omitempty,omitzero" yaml:"priority,omitempty" mapstructure:"priority,omitempty"`

	// RFC 3339 timestamp when the discount became active.
	Start *time.Time `json:"start,omitempty,omitzero" yaml:"start,omitempty" mapstructure:"start,omitempty"`
}

A discount that was successfully applied to the checkout session.

func (*AppliedDiscount) UnmarshalJSON

func (j *AppliedDiscount) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type AppliedDiscountMethod

type AppliedDiscountMethod string
const AppliedDiscountMethodAcross AppliedDiscountMethod = "across"
const AppliedDiscountMethodEach AppliedDiscountMethod = "each"

func (*AppliedDiscountMethod) UnmarshalJSON

func (j *AppliedDiscountMethod) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type CheckoutCreateRequestWithDiscount

type CheckoutCreateRequestWithDiscount interface{}

Checkout session create request extended with discount codes.

type CheckoutUpdateRequestWithDiscount

type CheckoutUpdateRequestWithDiscount interface{}

Checkout session update request extended with discount codes.

type CheckoutWithDiscount

type CheckoutWithDiscount interface{}

Checkout session extended with discount capability.

type Coupon

type Coupon struct {
	// Fixed discount amount in minor currency units. Mutually exclusive with
	// percent_off.
	AmountOff *int `json:"amount_off,omitempty,omitzero" yaml:"amount_off,omitempty" mapstructure:"amount_off,omitempty"`

	// ISO 4217 currency code for amount_off. Required if amount_off is set.
	Currency *string `json:"currency,omitempty,omitzero" yaml:"currency,omitempty" mapstructure:"currency,omitempty"`

	// How long the discount applies. 'once' = single use, 'repeating' = multiple
	// billing periods, 'forever' = indefinitely.
	Duration *CouponDuration `json:"duration,omitempty,omitzero" yaml:"duration,omitempty" mapstructure:"duration,omitempty"`

	// Number of months the coupon applies if duration is 'repeating'.
	DurationInMonths *int `json:"duration_in_months,omitempty,omitzero" yaml:"duration_in_months,omitempty" mapstructure:"duration_in_months,omitempty"`

	// Unique identifier for the coupon.
	Id string `json:"id" yaml:"id" mapstructure:"id"`

	// Maximum number of times this coupon can be redeemed across all customers.
	MaxRedemptions *int `json:"max_redemptions,omitempty,omitzero" yaml:"max_redemptions,omitempty" mapstructure:"max_redemptions,omitempty"`

	// Arbitrary key-value metadata attached to the coupon.
	Metadata CouponMetadata `json:"metadata,omitempty,omitzero" yaml:"metadata,omitempty" mapstructure:"metadata,omitempty"`

	// Human-readable coupon name (e.g., 'Summer Sale 20% Off').
	Name string `json:"name" yaml:"name" mapstructure:"name"`

	// Percentage discount (0-100). Mutually exclusive with amount_off.
	PercentOff *float64 `json:"percent_off,omitempty,omitzero" yaml:"percent_off,omitempty" mapstructure:"percent_off,omitempty"`

	// Number of times this coupon has been redeemed.
	TimesRedeemed *int `json:"times_redeemed,omitempty,omitzero" yaml:"times_redeemed,omitempty" mapstructure:"times_redeemed,omitempty"`
}

Coupon details describing the discount terms.

func (*Coupon) UnmarshalJSON

func (j *Coupon) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type CouponDuration

type CouponDuration string
const CouponDurationForever CouponDuration = "forever"
const CouponDurationOnce CouponDuration = "once"
const CouponDurationRepeating CouponDuration = "repeating"

func (*CouponDuration) UnmarshalJSON

func (j *CouponDuration) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type CouponMetadata

type CouponMetadata map[string]string

Arbitrary key-value metadata attached to the coupon.

type DiscountErrorCodes

type DiscountErrorCodes string
const DiscountErrorCodesDiscountCodeAlreadyApplied DiscountErrorCodes = "discount_code_already_applied"
const DiscountErrorCodesDiscountCodeCombinationDisallowed DiscountErrorCodes = "discount_code_combination_disallowed"
const DiscountErrorCodesDiscountCodeExpired DiscountErrorCodes = "discount_code_expired"
const DiscountErrorCodesDiscountCodeInvalid DiscountErrorCodes = "discount_code_invalid"
const DiscountErrorCodesDiscountCodeMinimumNotMet DiscountErrorCodes = "discount_code_minimum_not_met"
const DiscountErrorCodesDiscountCodeUsageLimitReached DiscountErrorCodes = "discount_code_usage_limit_reached"
const DiscountErrorCodesDiscountCodeUserIneligible DiscountErrorCodes = "discount_code_user_ineligible"
const DiscountErrorCodesDiscountCodeUserNotLoggedIn DiscountErrorCodes = "discount_code_user_not_logged_in"

func (*DiscountErrorCodes) UnmarshalJSON

func (j *DiscountErrorCodes) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type DiscountsRequest

type DiscountsRequest struct {
	// Discount codes to apply. Case-insensitive. Replaces previously submitted codes.
	// Send empty array to clear.
	Codes []string `json:"codes,omitempty,omitzero" yaml:"codes,omitempty" mapstructure:"codes,omitempty"`
}

Discount codes input for checkout create/update requests.

type DiscountsResponse

type DiscountsResponse struct {
	// Discounts successfully applied (code-based and automatic).
	Applied []AppliedDiscount `json:"applied,omitempty,omitzero" yaml:"applied,omitempty" mapstructure:"applied,omitempty"`

	// Echo of submitted discount codes.
	Codes []string `json:"codes,omitempty,omitzero" yaml:"codes,omitempty" mapstructure:"codes,omitempty"`

	// Discount codes that could not be applied, with reasons.
	Rejected []RejectedDiscount `json:"rejected,omitempty,omitzero" yaml:"rejected,omitempty" mapstructure:"rejected,omitempty"`
}

Discount codes input, applied discounts, and rejected codes in checkout responses.

type RejectedDiscount

type RejectedDiscount struct {
	// The discount code that was rejected.
	Code string `json:"code" yaml:"code" mapstructure:"code"`

	// Human-readable explanation of why the code was rejected.
	Message *string `json:"message,omitempty,omitzero" yaml:"message,omitempty" mapstructure:"message,omitempty"`

	// Error code indicating why the discount was rejected.
	Reason DiscountErrorCodes `json:"reason" yaml:"reason" mapstructure:"reason"`
}

A discount code that could not be applied, with the reason.

func (*RejectedDiscount) UnmarshalJSON

func (j *RejectedDiscount) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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