Skip to content

Commit

Permalink
Merge pull request #4 from smartpay-co/hsatac/sc-7511/go-sdk-supports…
Browse files Browse the repository at this point in the history
…-new-line-item-kinds

feat: support new line item kinds
  • Loading branch information
hSATAC authored Sep 22, 2022
2 parents f3408ef + 3493509 commit e344f4a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
7 changes: 7 additions & 0 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,10 @@ const (

ExpandNo Expand = "no"
)

// Defines values for LineItemKind
const (
LineItemKindProduct LineItemKind = "product"
LineItemKindDiscount LineItemKind = "discount"
LineItemKindTax LineItemKind = "tax"
)
13 changes: 13 additions & 0 deletions tests/integration/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
17 changes: 16 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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"`
Expand All @@ -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"`

Expand Down

0 comments on commit e344f4a

Please sign in to comment.