diff --git a/README.md b/README.md index e559656..20abfd9 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,9 @@ func main() { Currency: CurrencyJPY, Amount: 350, Items: []Item{ - {Name: "レブロン 18 LOW", Amount: 250, Currency: CurrencyJPY, Quantity: 1}, + {Name: "レブロン 18 LOW", Amount: 1000, Currency: CurrencyJPY, Quantity: Ptr(1)}, + {Name: "discount", Amount: 100, Currency: CurrencyJPY, Kind: Ptr(LineItemKindDiscount)}, + {Name: "tax", Amount: 250, Currency: CurrencyJPY, Kind: Ptr(LineItemKindTax)}, }, ShippingInfo: ShippingInfo{ Address: Address{Country: AddressCountryJP, PostalCode: "123", Locality: "locality", Line1: "line1"}, diff --git a/const.go b/const.go index 6313ca2..23cd3f6 100644 --- a/const.go +++ b/const.go @@ -158,3 +158,10 @@ const ( ExpandNo Expand = "no" ) + +// Defines values for LineItemKind +const ( + LineItemKindProduct LineItemKind = "product" + LineItemKindDiscount LineItemKind = "discount" + LineItemKindTax LineItemKind = "tax" +) diff --git a/tests/integration/order_test.go b/tests/integration/order_test.go index 38d02f5..e6dcba9 100644 --- a/tests/integration/order_test.go +++ b/tests/integration/order_test.go @@ -80,6 +80,19 @@ func (suite *IntegrationTestSuite) TestRetrieveAnOrderExpanded() { order, _ := ConvertToStruct[OrderExpanded](result.JSON200) suite.NotNil(order.Id) + + suite.Run("TestRetrieveAnOrderExpandedSupportsNewLineItem", func() { + for _, item := range *order.LineItems { + if *item.Kind == LineItemKindTax { + suite.EqualValues(int(*item.Amount), 250) + suite.EqualValues(*item.Currency, CurrencyJPY) + } + if *item.Kind == LineItemKindDiscount { + suite.EqualValues(int(*item.Amount), 100) + suite.EqualValues(*item.Currency, CurrencyJPY) + } + } + }) } func (suite *IntegrationTestSuite) TestCancelAnOrder() { diff --git a/tests/integration/suite_test.go b/tests/integration/suite_test.go index 540ea77..3245809 100644 --- a/tests/integration/suite_test.go +++ b/tests/integration/suite_test.go @@ -29,9 +29,11 @@ func TestCheckOutTestSuite(t *testing.T) { func NewCheckoutPayload() *CreateACheckoutSessionJSONRequestBody { checkoutPayload := CreateACheckoutSessionJSONRequestBody{ Currency: CurrencyJPY, - Amount: 350, + Amount: 1250, Items: []Item{ - {Name: "レブロン 18 LOW", Amount: 250, Currency: CurrencyJPY, Quantity: 1}, + {Name: "レブロン 18 LOW", Amount: 1000, Currency: CurrencyJPY, Quantity: Ptr(1)}, + {Name: "discount", Amount: 100, Currency: CurrencyJPY, Kind: Ptr(LineItemKindDiscount)}, + {Name: "tax", Amount: 250, Currency: CurrencyJPY, Kind: Ptr(LineItemKindTax)}, }, ShippingInfo: ShippingInfo{ Address: Address{Country: AddressCountryJP, PostalCode: "123", Locality: "locality", Line1: "line1"}, diff --git a/types.go b/types.go index b5a6009..6114f1c 100644 --- a/types.go +++ b/types.go @@ -266,11 +266,17 @@ type EventSubscription string // A URL for an image for this product, meant to be displayed to the customer. type ImageUrl string +// LineItem Kind +type LineItemKind string + // Item type Item struct { // The unit amount of this line item. Amount float32 `json:"amount"` + // The kind of this line item. Can be either of product, tax and discount. If non given it will be treated as a product + Kind *LineItemKind `json:"kind,omitempty"` + // The brand of the Product. Brand *string `json:"brand,omitempty"` @@ -306,7 +312,7 @@ type Item struct { ProductMetadata *Metadata `json:"productMetadata,omitempty"` // The quantity of products. Needs to be positive or zero. - Quantity int `json:"quantity"` + Quantity *int `json:"quantity,omitempty"` // A - ideally unique - string to reference the Product in your system (e.g. a product ID, etc.). Reference *string `json:"reference,omitempty"` @@ -321,6 +327,15 @@ type LineItemExpanded struct { CreatedAt *CreatedAt `json:"createdAt,omitempty"` Description *string `json:"description,omitempty"` + // The kind of this line item. Can be either of product, tax and discount. If non given it will be treated as a product + Kind *LineItemKind `json:"kind,omitempty"` + + // The unit amount of this line item. + Amount *float32 `json:"amount,omitempty"` + + // Three-letter ISO currency code, in uppercase. Must be a supported currency. + Currency *Currency `json:"currency,omitempty"` + // The unique identifier for the Line Item object. Id *LineItemId `json:"id,omitempty"`