diff --git a/README.md b/README.md index 0e4a8b9..146f228 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ This method registers a new **web** payment for the given installation and accou ```go assessment, err := client.RegisterPayment(&incognia.Payment{ - SessionToken: "session-token", + RequestToken: "request-token", AccountID: "account-id", ExternalID: "external-id", PolicyID: "policy-id", @@ -228,11 +228,11 @@ assessment, err := client.RegisterLogin(&incognia.Login{ }) ``` -This method registers a new **web** login for the given account and session-token, returning a `TransactionAssessment`, containing the risk assessment and supporting evidence. +This method registers a new **web** login for the given account and request-token, returning a `TransactionAssessment`, containing the risk assessment and supporting evidence. ```go assessment, err := client.RegisterLogin(&incognia.Login{ - SessionToken: "session-token", + RequestToken: "request-token", AccountID: "account-id", ... }) @@ -284,9 +284,9 @@ assessment, err := client.RegisterPayment(&incognia.Payment{ This method registers a feedback event for the given identifiers (represented in `FeedbackIdentifiers`) related to a signup, login or payment. ```go -occurred_at := time.Parse(time.RFC3339, "2024-07-22T15:20:00Z") +occurredAt, err := time.Parse(time.RFC3339, "2024-07-22T15:20:00Z") feedbackEvent := incognia.AccountTakeover -err := client.RegisterFeedback(feedbackEvent, &occurred_at, &incognia.FeedbackIdentifiers{ +err := client.RegisterFeedback(feedbackEvent, &occurredAt, &incognia.FeedbackIdentifiers{ InstallationID: "some-installation-id", AccountID: "some-account-id", }) diff --git a/incognia.go b/incognia.go index f5dbddd..9430e75 100644 --- a/incognia.go +++ b/incognia.go @@ -20,6 +20,7 @@ var ( ErrMissingSignup = errors.New("missing signup parameters") ErrMissingInstallationID = errors.New("missing installation id") ErrMissingInstallationIDOrSessionToken = errors.New("missing installation id or session token") + ErrMissingIdentifier = errors.New("missing installation id, request token or session token") ErrMissingAccountID = errors.New("missing account id") ErrMissingSignupID = errors.New("missing signup id") ErrMissingTimestamp = errors.New("missing timestamp") @@ -57,6 +58,7 @@ type IncogniaClientConfig struct { type Payment struct { InstallationID *string SessionToken *string + RequestToken string AccountID string ExternalID string PolicyID string @@ -69,6 +71,7 @@ type Payment struct { type Login struct { InstallationID *string SessionToken *string + RequestToken string AccountID string ExternalID string PolicyID string @@ -95,6 +98,8 @@ type Address struct { type Signup struct { InstallationID string + RequestToken string + SessionToken string Address *Address AccountID string PolicyID string @@ -201,12 +206,14 @@ func (c *Client) registerSignup(params *Signup) (ret *SignupAssessment, err erro if params == nil { return nil, ErrMissingSignup } - if params.InstallationID == "" { - return nil, ErrMissingInstallationID + if params.InstallationID == "" && params.RequestToken == "" && params.SessionToken == "" { + return nil, ErrMissingIdentifier } requestBody := postAssessmentRequestBody{ InstallationID: params.InstallationID, + RequestToken: params.RequestToken, + SessionToken: params.SessionToken, AccountID: params.AccountID, PolicyID: params.PolicyID, } @@ -306,8 +313,8 @@ func (c *Client) registerPayment(payment *Payment) (ret *TransactionAssessment, return nil, ErrMissingPayment } - if payment.InstallationID == nil && payment.SessionToken == nil { - return nil, ErrMissingInstallationIDOrSessionToken + if payment.InstallationID == nil && payment.SessionToken == nil && payment.RequestToken == "" { + return nil, ErrMissingIdentifier } if payment.AccountID == "" { @@ -316,6 +323,7 @@ func (c *Client) registerPayment(payment *Payment) (ret *TransactionAssessment, requestBody, err := json.Marshal(postTransactionRequestBody{ InstallationID: payment.InstallationID, + RequestToken: payment.RequestToken, SessionToken: payment.SessionToken, Type: paymentType, AccountID: payment.AccountID, @@ -366,8 +374,8 @@ func (c *Client) registerLogin(login *Login) (*TransactionAssessment, error) { return nil, ErrMissingLogin } - if login.InstallationID == nil && login.SessionToken == nil { - return nil, ErrMissingInstallationIDOrSessionToken + if login.InstallationID == nil && login.SessionToken == nil && login.RequestToken == "" { + return nil, ErrMissingIdentifier } if login.AccountID == "" { @@ -382,6 +390,7 @@ func (c *Client) registerLogin(login *Login) (*TransactionAssessment, error) { ExternalID: login.ExternalID, PaymentMethodIdentifier: login.PaymentMethodIdentifier, SessionToken: login.SessionToken, + RequestToken: login.RequestToken, }) if err != nil { return nil, err diff --git a/incognia_test.go b/incognia_test.go index e913c56..345fffd 100644 --- a/incognia_test.go +++ b/incognia_test.go @@ -24,7 +24,7 @@ var ( now = time.Now() nowMinusSeconds = now.Add(-1 * time.Second) installationId = "installation-id" - sessionToken = "session-token" + requestToken = "request-token" shouldEval bool = true shouldNotEval bool = false emptyQueryString map[string][]string = nil @@ -79,6 +79,7 @@ var ( postSignupRequestBodyWithAllParamsFixture = &postAssessmentRequestBody{ InstallationID: installationId, + RequestToken: requestToken, AddressLine: "address line", StructuredAddress: &StructuredAddress{ Locale: "locale", @@ -218,7 +219,7 @@ var ( }, } postPaymentWebRequestBodyFixture = &postTransactionRequestBody{ - SessionToken: &sessionToken, + RequestToken: requestToken, AccountID: "account-id", ExternalID: "external-id", PolicyID: "policy-id", @@ -314,7 +315,7 @@ var ( }, } paymentWebFixture = &Payment{ - SessionToken: &sessionToken, + RequestToken: requestToken, AccountID: "account-id", ExternalID: "external-id", PolicyID: "policy-id", @@ -410,7 +411,7 @@ var ( ExternalID: "external-id", PolicyID: "policy-id", PaymentMethodIdentifier: "payment-method-identifier", - SessionToken: &sessionToken, + RequestToken: requestToken, } postLoginRequestBodyFixture = &postTransactionRequestBody{ InstallationID: &installationId, @@ -426,7 +427,7 @@ var ( PolicyID: "policy-id", PaymentMethodIdentifier: "payment-method-identifier", Type: loginType, - SessionToken: &sessionToken, + RequestToken: requestToken, } ) @@ -573,6 +574,8 @@ func (suite *IncogniaTestSuite) TestSuccessRegisterSignupWithParams() { response, err := suite.client.RegisterSignupWithParams(&Signup{ InstallationID: postSignupRequestBodyWithAllParamsFixture.InstallationID, + RequestToken: postSignupRequestBodyWithAllParamsFixture.RequestToken, + SessionToken: postSignupRequestBodyWithAllParamsFixture.SessionToken, Address: addressFixture, AccountID: postSignupRequestBodyWithAllParamsFixture.AccountID, PolicyID: postSignupRequestBodyWithAllParamsFixture.PolicyID, @@ -617,7 +620,7 @@ func (suite *IncogniaTestSuite) TestSuccessRegisterSignupAfterTokenExpiration() func (suite *IncogniaTestSuite) TestRegisterSignupEmptyInstallationId() { response, err := suite.client.RegisterSignup("", &Address{}) - suite.EqualError(err, ErrMissingInstallationID.Error()) + suite.EqualError(err, ErrMissingIdentifier.Error()) suite.Nil(response) } @@ -794,7 +797,7 @@ func (suite *IncogniaTestSuite) TestRegisterPaymentNilPayment() { func (suite *IncogniaTestSuite) TestRegisterPaymentEmptyInstallationId() { response, err := suite.client.RegisterPayment(&Payment{AccountID: "some-account-id"}) - suite.EqualError(err, ErrMissingInstallationIDOrSessionToken.Error()) + suite.EqualError(err, ErrMissingIdentifier.Error()) suite.Nil(response) } @@ -903,7 +906,7 @@ func (suite *IncogniaTestSuite) TestRegisterLoginNilLogin() { func (suite *IncogniaTestSuite) TestRegisterLoginNullInstallationIdAndSessionToken() { response, err := suite.client.RegisterLogin(&Login{AccountID: "some-account-id"}) - suite.EqualError(err, ErrMissingInstallationIDOrSessionToken.Error()) + suite.EqualError(err, ErrMissingIdentifier.Error()) suite.Nil(response) } diff --git a/request_types.go b/request_types.go index 16fee52..2f47a2e 100644 --- a/request_types.go +++ b/request_types.go @@ -22,7 +22,9 @@ type StructuredAddress struct { } type postAssessmentRequestBody struct { - InstallationID string `json:"installation_id"` + InstallationID string `json:"installation_id,omitempty"` + RequestToken string `json:"request_token,omitempty"` + SessionToken string `json:"session_token,omitempty"` AddressLine string `json:"address_line,omitempty"` StructuredAddress *StructuredAddress `json:"structured_address,omitempty"` Coordinates *Coordinates `json:"address_coordinates,omitempty"` @@ -136,4 +138,5 @@ type postTransactionRequestBody struct { PaymentValue *PaymentValue `json:"payment_value,omitempty"` PaymentMethods []*PaymentMethod `json:"payment_methods,omitempty"` SessionToken *string `json:"session_token,omitempty"` + RequestToken string `json:"request_token,omitempty"` }