feat: add discount and savings fields to Order struct

Added Discount struct with comprehensive discount information and added discount-related fields (Discounts, SavedAmount, TotalRebateRate) to Order struct to expose discount data from Snipcart API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bastian de Byl
2025-10-03 10:49:36 -04:00
parent a2fdeafc3c
commit 043da741fa

View File

@@ -26,6 +26,29 @@ type Item struct {
Shippable bool `json:"shippable,omitempty"` Shippable bool `json:"shippable,omitempty"`
} }
type Discount struct {
ID string `json:"id"`
DiscountID string `json:"discountId"`
Name string `json:"name"`
Code string `json:"code,omitempty"`
Trigger string `json:"trigger,omitempty"`
Type string `json:"type,omitempty"`
Rate float64 `json:"rate,omitempty"`
Amount float64 `json:"amount,omitempty"`
AmountSaved float64 `json:"amountSaved,omitempty"`
NormalizedRate float64 `json:"normalizedRate,omitempty"`
Combinable bool `json:"combinable"`
HasSavedAmount bool `json:"hasSavedAmount"`
MaxDiscountsPerItem *int `json:"maxDiscountsPerItem,omitempty"`
TotalToReach *float64 `json:"totalToReach,omitempty"`
ProductIds string `json:"productIds,omitempty"`
Categories string `json:"categories,omitempty"`
NumberOfUsages int `json:"numberOfUsages,omitempty"`
AppliesOnAllRecurring bool `json:"appliesOnAllRecurringOrders"`
CreationDate string `json:"creationDate,omitempty"`
ModificationDate string `json:"modificationDate,omitempty"`
}
type OrderTax struct { type OrderTax struct {
Name string `json:"taxName"` Name string `json:"taxName"`
Rate float64 `json:"taxRate"` Rate float64 `json:"taxRate"`
@@ -81,6 +104,9 @@ type Order struct {
ShippingProvider string `json:"shippingProvider,omitempty"` ShippingProvider string `json:"shippingProvider,omitempty"`
ShippingMethod string `json:"shippingMethod,omitempty"` ShippingMethod string `json:"shippingMethod,omitempty"`
ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"` ShippingRateId string `json:"shippingRateUserDefinedId,omitempty"`
Discounts []Discount `json:"discounts,omitempty"`
SavedAmount float64 `json:"savedAmount,omitempty"`
TotalRebateRate float64 `json:"totalRebateRate,omitempty"`
Items []Item `json:"items"` Items []Item `json:"items"`
Taxes []OrderTax `json:"taxes,omitempty"` Taxes []OrderTax `json:"taxes,omitempty"`
Metadata any `json:"metadata"` Metadata any `json:"metadata"`