-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the
LineItem
resource and APIs
- Loading branch information
1 parent
a130c55
commit 66da794
Showing
6 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package stripe | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// LineItemTax represent the details of one tax rate applied to a line item. | ||
type LineItemTax struct { | ||
Amount int64 `json:"amount"` | ||
TaxRate *TaxRate `json:"tax_rate"` | ||
} | ||
|
||
// LineItem is the resource representing a line item. | ||
type LineItem struct { | ||
APIResource | ||
AmountSubtotal int64 `json:"amount_subtotal"` | ||
AmountTotal int64 `json:"amount_total"` | ||
Currency Currency `json:"currency"` | ||
Description string `json:"description"` | ||
ID string `json:"id"` | ||
Object string `json:"object"` | ||
Price *Price `json:"price"` | ||
Quantity int64 `json:"quantity"` | ||
Taxes []*LineItemTax `json:"taxes"` | ||
} | ||
|
||
// LineItemList is a list of prices as returned from a list endpoint. | ||
type LineItemList struct { | ||
APIResource | ||
ListMeta | ||
Data []*LineItem `json:"data"` | ||
} | ||
|
||
// UnmarshalJSON handles deserialization of a LineItem. | ||
// This custom unmarshaling is needed because the resulting | ||
// property may be an id or the full struct if it was expanded. | ||
func (s *LineItem) UnmarshalJSON(data []byte) error { | ||
if id, ok := ParseID(data); ok { | ||
s.ID = id | ||
return nil | ||
} | ||
|
||
type price LineItem | ||
var v price | ||
if err := json.Unmarshal(data, &v); err != nil { | ||
return err | ||
} | ||
|
||
*s = LineItem(v) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Package lineitem provides the tools needs to interact with the LineItem resource. | ||
package lineitem | ||
|
||
import ( | ||
stripe "github.com/stripe/stripe-go/v71" | ||
) | ||
|
||
// LineItemIter is an iterator for line items across various resources. | ||
type LineItemIter struct { | ||
*stripe.Iter | ||
} | ||
|
||
// LineItem returns the line item which the iterator is currently pointing to. | ||
func (i *LineItemIter) LineItem() *stripe.LineItem { | ||
return i.Current().(*stripe.LineItem) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters