From 0af135172c95f32ff72c53dd752ceb426e181eb6 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Sat, 14 Apr 2018 14:45:57 -0400 Subject: [PATCH] Move UsageRecord to pointers for parameters --- usage_record.go | 9 ++++----- usage_record_test.go | 8 ++++---- usagerecord/client.go | 2 +- usagerecord/client_test.go | 8 ++++---- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/usage_record.go b/usage_record.go index d093dab302..daca6153b2 100644 --- a/usage_record.go +++ b/usage_record.go @@ -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"` } diff --git a/usage_record_test.go b/usage_record_test.go index 8608568fc3..6e42f6d207 100644 --- a/usage_record_test.go +++ b/usage_record_test.go @@ -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) { diff --git a/usagerecord/client.go b/usagerecord/client.go index ee4b82593c..592c3e8a07 100644 --- a/usagerecord/client.go +++ b/usagerecord/client.go @@ -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, ¶ms.Params, record) diff --git a/usagerecord/client_test.go b/usagerecord/client_test.go index 64391b2fe3..62d04d1470 100644 --- a/usagerecord/client_test.go +++ b/usagerecord/client_test.go @@ -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)