-
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 radar.early_fraud_warning resource
- Loading branch information
Showing
5 changed files
with
150 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
} |
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,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()) | ||
} |
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,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"` | ||
} |
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