diff --git a/.travis.yml b/.travis.yml index 33f9cb5d21..9a3f183893 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ cache: env: global: # If changing this number, please also change it in `testing/testing.go`. - - STRIPE_MOCK_VERSION=0.56.0 + - STRIPE_MOCK_VERSION=0.57.0 go: - "1.9.x" diff --git a/radar/earlyfraudwarning/client.go b/radar/earlyfraudwarning/client.go new file mode 100644 index 0000000000..564208641a --- /dev/null +++ b/radar/earlyfraudwarning/client.go @@ -0,0 +1,65 @@ +// Package earlyfraudwarning provides API functions related to early fraud +// warnings. +// +// For more details, see: https://stripe.com/docs/api/early_fraud_warnings?lang=go +package earlyfraudwarning + +import ( + "net/http" + + stripe "github.com/stripe/stripe-go" + "github.com/stripe/stripe-go/form" +) + +// Client is used to interact with the /radar/early_fraud_warnings API. +type Client struct { + B stripe.Backend + Key string +} + +// Get returns the details of an early fraud warning. +func Get(id string, params *stripe.RadarEarlyFraudWarningParams) (*stripe.RadarEarlyFraudWarning, error) { + return getC().Get(id, params) +} + +// Get returns the details of an early fraud warning. +func (c Client) Get(id string, params *stripe.RadarEarlyFraudWarningParams) (*stripe.RadarEarlyFraudWarning, error) { + path := stripe.FormatURLPath("/v1/issuer_fraud_records/%s", id) + ifr := &stripe.RadarEarlyFraudWarning{} + err := c.B.Call(http.MethodGet, path, c.Key, params, ifr) + return ifr, err +} + +// List returns a list of early fraud warnings. +func List(params *stripe.RadarEarlyFraudWarningListParams) *Iter { + return getC().List(params) +} + +// List returns a list of early fraud warnings. +func (c Client) List(listParams *stripe.RadarEarlyFraudWarningListParams) *Iter { + return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) { + list := &stripe.RadarEarlyFraudWarningList{} + err := c.B.CallRaw(http.MethodGet, "/v1/issuer_fraud_records", c.Key, b, p, list) + + ret := make([]interface{}, len(list.Values)) + for i, v := range list.Values { + ret[i] = v + } + + return ret, list.ListMeta, err + })} +} + +// Iter is an iterator for early fraud warnings. +type Iter struct { + *stripe.Iter +} + +// RadarEarlyFraudWarning returns the early fraud warning which the iterator is currently pointing to. +func (i *Iter) RadarEarlyFraudWarning() *stripe.RadarEarlyFraudWarning { + return i.Current().(*stripe.RadarEarlyFraudWarning) +} + +func getC() Client { + return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} +} diff --git a/radar/earlyfraudwarning/client_test.go b/radar/earlyfraudwarning/client_test.go new file mode 100644 index 0000000000..3f4ae08b6d --- /dev/null +++ b/radar/earlyfraudwarning/client_test.go @@ -0,0 +1,35 @@ +package earlyfraudwarning + +import ( + "testing" + + assert "github.com/stretchr/testify/require" + stripe "github.com/stripe/stripe-go" + _ "github.com/stripe/stripe-go/testing" +) + +func TestRadarEarlyFraudWarningGet(t *testing.T) { + ifr, err := Get("ifr_123", nil) + assert.Nil(t, err) + assert.NotNil(t, ifr) +} + +func TestRadarEarlyFraudWarningList(t *testing.T) { + i := List(&stripe.RadarEarlyFraudWarningListParams{}) + + // Verify that we can get at least one issuer fraud record + assert.True(t, i.Next()) + assert.Nil(t, i.Err()) + assert.NotNil(t, i.RadarEarlyFraudWarning()) +} + +func TestRadarEarlyFraudWarningListByChargeID(t *testing.T) { + i := List(&stripe.RadarEarlyFraudWarningListParams{ + Charge: stripe.String("ch_123"), + }) + + // Verify that we can get at least one issuer fraud record + assert.True(t, i.Next()) + assert.Nil(t, i.Err()) + assert.NotNil(t, i.RadarEarlyFraudWarning()) +} diff --git a/radar_earlyfraudwarning.go b/radar_earlyfraudwarning.go new file mode 100644 index 0000000000..f2350d9e17 --- /dev/null +++ b/radar_earlyfraudwarning.go @@ -0,0 +1,48 @@ +package stripe + +// RadarEarlyFraudWarningFraudType are strings that map to the type of fraud labelled by the issuer. +type RadarEarlyFraudWarningFraudType string + +// List of values that RadarEarlyFraudWarningFraudType can take. +const ( + RadarEarlyFraudWarningFraudTypeCardNeverReceived RadarEarlyFraudWarningFraudType = "card_never_received" + RadarEarlyFraudWarningFraudTypeFraudulentCardApplication RadarEarlyFraudWarningFraudType = "fraudulent_card_application" + RadarEarlyFraudWarningFraudTypeMadeWithCounterfeitCard RadarEarlyFraudWarningFraudType = "made_with_counterfeit_card" + RadarEarlyFraudWarningFraudTypeMadeWithLostCard RadarEarlyFraudWarningFraudType = "made_with_lost_card" + RadarEarlyFraudWarningFraudTypeMadeWithStolenCard RadarEarlyFraudWarningFraudType = "made_with_stolen_card" + RadarEarlyFraudWarningFraudTypeMisc RadarEarlyFraudWarningFraudType = "misc" + RadarEarlyFraudWarningFraudTypeUnauthorizedUseOfCard RadarEarlyFraudWarningFraudType = "unauthorized_use_of_card" +) + +// RadarEarlyFraudWarningParams is the set of parameters that can be used when +// retrieving early fraud warnings. For more details see +// https://stripe.com/docs/api/early_fraud_warnings/retrieve. +type RadarEarlyFraudWarningParams struct { + Params `form:"*"` +} + +// RadarEarlyFraudWarningListParams is the set of parameters that can be used when +// listing early fraud warnings. For more details see +// https://stripe.com/docs/api/early_fraud_warnings/list. +type RadarEarlyFraudWarningListParams struct { + ListParams `form:"*"` + Charge *string `form:"charge"` +} + +// RadarEarlyFraudWarningList is a list of early fraud warnings as retrieved from a +// list endpoint. +type RadarEarlyFraudWarningList struct { + ListMeta + Values []*RadarEarlyFraudWarning `json:"data"` +} + +// RadarEarlyFraudWarning is the resource representing an early fraud warning. For +// more details see https://stripe.com/docs/api/early_fraud_warnings/object. +type RadarEarlyFraudWarning struct { + Actionable bool `json:"actionable"` + Charge *Charge `json:"charge"` + Created int64 `json:"created"` + FraudType RadarEarlyFraudWarningFraudType `json:"fraud_type"` + ID string `json:"id"` + Livemode bool `json:"livemode"` +} diff --git a/testing/testing.go b/testing/testing.go index b9ab2cfc03..39059712a4 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -25,7 +25,7 @@ const ( // added in a more recent version of stripe-mock, we can show people a // better error message instead of the test suite crashing with a bunch of // confusing 404 errors or the like. - MockMinimumVersion = "0.56.0" + MockMinimumVersion = "0.57.0" // TestMerchantID is a token that can be used to represent a merchant ID in // simple tests.