Skip to content

Commit

Permalink
Move UsageRecord to pointers for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Jun 6, 2018
1 parent f875db9 commit 0af1351
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
9 changes: 4 additions & 5 deletions usage_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ type UsageRecord struct {
// and date, and fills it with a quantity.
type UsageRecordParams struct {
Params `form:"*"`
Action string `form:"action"`
Quantity uint64 `form:"quantity"`
QuantityZero bool `form:"quantity,zero"`
SubscriptionItem string `form:"-"` // passed in the URL
Timestamp uint64 `form:"timestamp"`
Action *string `form:"action"`
Quantity *uint64 `form:"quantity"`
SubscriptionItem *string `form:"-"` // passed in the URL
Timestamp *uint64 `form:"timestamp"`
}
8 changes: 4 additions & 4 deletions usage_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ func TestUsageRecordParams_AppendTo(t *testing.T) {
params *UsageRecordParams
want interface{}
}{
{"action", &UsageRecordParams{Action: "increment"}, "increment"},
{"quantity", &UsageRecordParams{Quantity: 2000}, strconv.FormatUint(2000, 10)},
{"quantity", &UsageRecordParams{QuantityZero: true}, strconv.FormatUint(0, 10)},
{"timestamp", &UsageRecordParams{Timestamp: 123123123}, strconv.FormatUint(123123123, 10)},
{"action", &UsageRecordParams{Action: String("increment")}, "increment"},
{"quantity", &UsageRecordParams{Quantity: UInt64(2000)}, strconv.FormatUint(2000, 10)},
{"quantity", &UsageRecordParams{Quantity: UInt64(0)}, strconv.FormatUint(0, 10)},
{"timestamp", &UsageRecordParams{Timestamp: UInt64(123123123)}, strconv.FormatUint(123123123, 10)},
}
for _, tc := range testCases {
t.Run(tc.field, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion usagerecord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c Client) New(params *stripe.UsageRecordParams) (*stripe.UsageRecord, erro
body := &form.Values{}
form.AppendTo(body, params)

url := fmt.Sprintf("/subscription_items/%s/usage_records", url.QueryEscape(params.SubscriptionItem))
url := fmt.Sprintf("/subscription_items/%s/usage_records", url.QueryEscape(stripe.StringValue(params.SubscriptionItem)))
record := &stripe.UsageRecord{}
err := c.B.Call("POST", url, c.Key, body, &params.Params, record)

Expand Down
8 changes: 4 additions & 4 deletions usagerecord/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
func TestUsageRecordNew(t *testing.T) {
now := uint64(time.Now().Unix())
usageRecord, err := New(&stripe.UsageRecordParams{
Quantity: 123,
Timestamp: now,
Action: stripe.UsageRecordParamsActionIncrement,
SubscriptionItem: "si_123",
Quantity: stripe.UInt64(123),
Timestamp: stripe.UInt64(now),
Action: stripe.String(stripe.UsageRecordParamsActionIncrement),
SubscriptionItem: stripe.String("si_123"),
})
assert.Nil(t, err)
assert.NotNil(t, usageRecord)
Expand Down

0 comments on commit 0af1351

Please sign in to comment.