Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove invalid feedback types and add missing ones #58

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,6 @@ assessment, err := client.RegisterSignupWithParams(&incognia.Signup{
})
```

### Getting a Signup

This method allows you to query the latest assessment for a given signup event, returning a `SignupAssessment`, containing the risk assessment and supporting evidence:

```go
signupID := "c9ac2803-c868-4b7a-8323-8a6b96298ebe"
assessment, err := client.GetSignupAssessment(signupID)
```

### Registering Payment

This method registers a new payment for the given installation and account, returning a `TransactionAssessment`, containing the risk assessment and supporting evidence.
Expand Down
33 changes: 0 additions & 33 deletions incognia.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ var (
ErrMissingInstallationIDOrSessionToken = errors.New("missing installation id or session token")
ErrMissingAccountID = errors.New("missing account id")
ErrMissingSignupID = errors.New("missing signup id")
ErrMissingTimestamp = errors.New("missing timestamp")
ErrInvalidFeedbackType = errors.New("invalid feedback type")
ErrMissingClientIDOrClientSecret = errors.New("client id and client secret are required")
ErrConfigIsNil = errors.New("incognia client config is required")
)
Expand Down Expand Up @@ -141,37 +139,6 @@ func New(config *IncogniaClientConfig) (*Client, error) {
return &Client{clientID: config.ClientID, clientSecret: config.ClientSecret, tokenProvider: tokenProvider, netClient: netClient, endpoints: &endpoints}, nil
}

func (c *Client) GetSignupAssessment(signupID string) (ret *SignupAssessment, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
ret = nil
}
}()

return c.getSignupAssessment(signupID)
}

func (c *Client) getSignupAssessment(signupID string) (ret *SignupAssessment, err error) {
if signupID == "" {
return nil, ErrMissingSignupID
}

req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", c.endpoints.Signups, signupID), nil)
if err != nil {
return nil, err
}

var signupAssessment SignupAssessment

err = c.doRequest(req, &signupAssessment)
if err != nil {
return nil, err
}

return &signupAssessment, nil
}

func (c *Client) RegisterSignup(installationID string, address *Address) (ret *SignupAssessment, err error) {
defer func() {
if r := recover(); r != nil {
Expand Down
97 changes: 2 additions & 95 deletions incognia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,7 @@ func (suite *IncogniaTestSuite) TestManualRefreshTokenProviderErrorTokenNotFound
tokenProvider := NewManualRefreshTokenProvider(NewTokenClient(&TokenClientConfig{ClientID: clientID, ClientSecret: clientSecret}))
client, _ := New(&IncogniaClientConfig{ClientID: clientID, ClientSecret: clientSecret, TokenProvider: tokenProvider})

_, err := client.GetSignupAssessment("any-signup-id")
suite.EqualError(err, ErrTokenNotFound.Error())

_, err = client.RegisterLogin(loginFixture)
_, err := client.RegisterLogin(loginFixture)
suite.EqualError(err, ErrTokenNotFound.Error())

_, err = client.RegisterPayment(paymentFixture)
Expand All @@ -490,16 +487,10 @@ func (suite *IncogniaTestSuite) TestManualRefreshTokenProviderSuccess() {
tokenProvider.Refresh()

suite.client = client
signupID := "signup-id"

signupServer := suite.mockGetSignupsEndpoint(token, signupID, signupAssessmentFixture)
defer signupServer.Close()
_, err := client.GetSignupAssessment(signupID)
suite.NoError(err)

loginServer := suite.mockPostTransactionsEndpoint(token, postLoginRequestBodyFixture, transactionAssessmentFixture, emptyQueryString)
defer loginServer.Close()
_, err = client.RegisterLogin(loginFixture)
_, err := client.RegisterLogin(loginFixture)
suite.NoError(err)

paymentServer := suite.mockPostTransactionsEndpoint(token, postPaymentRequestBodyFixture, transactionAssessmentFixture, emptyQueryString)
Expand All @@ -513,60 +504,6 @@ func (suite *IncogniaTestSuite) TestManualRefreshTokenProviderSuccess() {
suite.NoError(err)
}

func (suite *IncogniaTestSuite) TestSuccessGetSignupAssessment() {
signupID := "signup-id"
signupServer := suite.mockGetSignupsEndpoint(token, signupID, signupAssessmentFixture)
defer signupServer.Close()

response, err := suite.client.GetSignupAssessment(signupID)
suite.NoError(err)
suite.Equal(signupAssessmentFixture, response)
}

func (suite *IncogniaTestSuite) TestSuccessGetSignupAssessmentAfterTokenExpiration() {
signupID := "signup-id"
signupServer := suite.mockGetSignupsEndpoint(token, signupID, signupAssessmentFixture)
defer signupServer.Close()

response, err := suite.client.GetSignupAssessment(signupID)
suite.NoError(err)
suite.Equal(signupAssessmentFixture, response)

token, _ := suite.client.tokenProvider.GetToken()
token.(*accessToken).ExpiresIn = 0

response, err = suite.client.GetSignupAssessment(signupID)
suite.NoError(err)
suite.Equal(signupAssessmentFixture, response)
}
func (suite *IncogniaTestSuite) TestGetSignupAssessmentEmptySignupId() {
response, err := suite.client.GetSignupAssessment("")
suite.EqualError(err, ErrMissingSignupID.Error())
suite.Nil(response)
}

func (suite *IncogniaTestSuite) TestForbiddenGetSignupAssessment() {
signupID := "signup-id"
signupServer := suite.mockGetSignupsEndpoint("some-other-token", signupID, signupAssessmentFixture)
defer signupServer.Close()

response, err := suite.client.GetSignupAssessment(signupID)
suite.Nil(response)
suite.EqualError(err, "403 Forbidden")
}

func (suite *IncogniaTestSuite) TestGetSignupAssessmentErrors() {
errors := []int{http.StatusBadRequest, http.StatusInternalServerError}
for _, status := range errors {
statusServer := mockStatusServer(status)
suite.client.endpoints.Signups = statusServer.URL

response, err := suite.client.GetSignupAssessment("any-signup-id")
suite.Nil(response)
suite.Contains(err.Error(), strconv.Itoa(status))
}
}

func (suite *IncogniaTestSuite) TestSuccessRegisterSignupWithParams() {
signupServer := suite.mockPostSignupsEndpoint(token, postSignupRequestBodyWithAllParamsFixture, signupAssessmentFixture)
defer signupServer.Close()
Expand Down Expand Up @@ -966,8 +903,6 @@ func (suite *IncogniaTestSuite) TestPanic() {
suite.Equal(err.Error(), panicString)
_, err = suite.client.RegisterSignup("some-installationId", addressFixture)
suite.Equal(err.Error(), panicString)
_, err = suite.client.GetSignupAssessment("some-signup-id")
suite.Equal(err.Error(), panicString)
_, err = suite.client.RegisterPayment(paymentFixture)
suite.Equal(err.Error(), panicString)
}
Expand Down Expand Up @@ -1083,34 +1018,6 @@ func (suite *IncogniaTestSuite) mockPostSignupsEndpoint(expectedToken string, ex
return signupsServer
}

func (suite *IncogniaTestSuite) mockGetSignupsEndpoint(expectedToken, expectedSignupID string, expectedResponse *SignupAssessment) *httptest.Server {
getSignupsServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "application/json")

if !isRequestAuthorized(r, expectedToken) {
w.WriteHeader(http.StatusForbidden)
return
}

defer r.Body.Close()

splitUrl := strings.Split(r.URL.RequestURI(), "/")
requestSignupID := splitUrl[len(splitUrl)-1]

if requestSignupID == expectedSignupID {
res, _ := json.Marshal(expectedResponse)
w.Write(res)
return
}

w.WriteHeader(http.StatusNotFound)
}))

suite.client.endpoints.Signups = getSignupsServer.URL

return getSignupsServer
}

func isRequestAuthorized(request *http.Request, expectedToken string) bool {
tokenType, token := readAuthorizationHeader(request)

Expand Down
48 changes: 26 additions & 22 deletions request_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,32 @@ type postAssessmentRequestBody struct {
type FeedbackType string

const (
PaymentAccepted FeedbackType = "payment_accepted"
PaymentDeclined FeedbackType = "payment_declined"
PaymentDeclinedByRiskAnalysis FeedbackType = "payment_declined_by_risk_analysis"
PaymentDeclinedByAcquirer FeedbackType = "payment_declined_by_acquirer"
PaymentDeclinedByBusiness FeedbackType = "payment_declined_by_business"
PaymentDeclinedByManualReview FeedbackType = "payment_declined_by_manual_review"
PaymentAcceptedByThirdParty FeedbackType = "payment_accepted_by_third_party"
LoginAccepted FeedbackType = "login_accepted"
LoginDeclined FeedbackType = "login_declined"
SignupAccepted FeedbackType = "signup_accepted"
SignupDeclined FeedbackType = "signup_declined"
ChallengePassed FeedbackType = "challenge_passed"
ChallengeFailed FeedbackType = "challenge_failed"
PasswordChangedSuccessfully FeedbackType = "password_changed_successfully"
PasswordChangeFailed FeedbackType = "password_change_failed"
Verified FeedbackType = "verified"
NotVerified FeedbackType = "not_verified"
Chargeback FeedbackType = "chargeback"
PromotionAbuse FeedbackType = "promotion_abuse"
AccountTakeover FeedbackType = "account_takeover"
MposFraud FeedbackType = "mpos_fraud"
ChargebackNotification FeedbackType = "chargeback_notification"
AccountAllowed FeedbackType = "account_allowed"
DeviceAllowed FeedbackType = "device_allowed"
Verified FeedbackType = "verified"
Reset FeedbackType = "reset"
AccountTakeover FeedbackType = "account_takeover"
IdentityFraud FeedbackType = "identity_fraud"
Chargeback FeedbackType = "chargeback"
ChargebackNotification FeedbackType = "chargeback_notification"
PromotionAbuse FeedbackType = "promotion_abuse"
LoginAccepted FeedbackType = "login_accepted"
LoginAcceptedByDeviceVerification FeedbackType = "login_accepted_by_device_verification"
LoginAcceptedByFacialBiometrics FeedbackType = "login_accepted_by_facial_biometrics"
LoginAcceptedByManualReview FeedbackType = "login_accepted_by_manual_review"
LoginDeclined FeedbackType = "login_declined"
LoginDeclinedByFacialBiometrics FeedbackType = "login_declined_by_facial_biometrics"
LoginDeclinedByManualReview FeedbackType = "login_declined_by_manual_review"
PaymentAccepted FeedbackType = "payment_accepted"
PaymentAcceptedByControlGroup FeedbackType = "payment_accepted_by_control_group"
PaymentAcceptedByThirdParty FeedbackType = "payment_accepted_by_third_party"
PaymentDeclined FeedbackType = "payment_declined"
PaymentDeclinedByAcquirer FeedbackType = "payment_declined_by_acquirer"
PaymentDeclinedByBusiness FeedbackType = "payment_declined_by_business"
PaymentDeclinedByManualReview FeedbackType = "payment_declined_by_manual_review"
PaymentDeclinedByRiskAnalysis FeedbackType = "payment_declined_by_risk_analysis"
SignupAccepted FeedbackType = "signup_accepted"
SignupDeclined FeedbackType = "signup_declined"
)

type postFeedbackRequestBody struct {
Expand Down
Loading