Skip to content

Commit

Permalink
Feat: Add custom properties support to login and payment APIs (#62)
Browse files Browse the repository at this point in the history
* feat: Add custom properties support to login and payment APIs

* Add README example for login

* Make custom properties map clearer on readme

* Add generic test for custom properties
  • Loading branch information
brunoekferrari authored Jan 13, 2025
1 parent 928b724 commit e20e806
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 53 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ assessment, err := client.RegisterPayment(&incognia.Payment{
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
CustomProperties: myCustomPropertiesMap
Addresses: []*incognia.TransactionAddress{
{
Type: incognia.Billing,
Expand Down Expand Up @@ -216,6 +217,7 @@ assessment, err := client.RegisterLogin(&incognia.Login{
ExternalID: "external-id",
PolicyID: "policy-id",
PaymentMethodIdentifier: "payment-method-identifier",
CustomProperties: myCustomPropertiesMap,
})
```

Expand Down
44 changes: 24 additions & 20 deletions incognia.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ type IncogniaClientConfig struct {
}

type Payment struct {
InstallationID *string
SessionToken *string
RequestToken string
AccountID string
ExternalID string
PolicyID string
Addresses []*TransactionAddress
Value *PaymentValue
Methods []*PaymentMethod
Eval *bool
InstallationID *string
SessionToken *string
RequestToken string
AccountID string
ExternalID string
PolicyID string
Addresses []*TransactionAddress
Value *PaymentValue
Methods []*PaymentMethod
Eval *bool
CustomProperties map[string]interface{}
}

type Login struct {
Expand All @@ -66,6 +67,7 @@ type Login struct {
PolicyID string
PaymentMethodIdentifier string
Eval *bool
CustomProperties map[string]interface{}
}

type FeedbackIdentifiers struct {
Expand Down Expand Up @@ -282,16 +284,17 @@ 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,
PolicyID: payment.PolicyID,
ExternalID: payment.ExternalID,
Addresses: payment.Addresses,
PaymentValue: payment.Value,
PaymentMethods: payment.Methods,
InstallationID: payment.InstallationID,
RequestToken: payment.RequestToken,
SessionToken: payment.SessionToken,
Type: paymentType,
AccountID: payment.AccountID,
PolicyID: payment.PolicyID,
ExternalID: payment.ExternalID,
Addresses: payment.Addresses,
PaymentValue: payment.Value,
PaymentMethods: payment.Methods,
CustomProperties: payment.CustomProperties,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -351,6 +354,7 @@ func (c *Client) registerLogin(login *Login) (*TransactionAssessment, error) {
PaymentMethodIdentifier: login.PaymentMethodIdentifier,
SessionToken: login.SessionToken,
RequestToken: login.RequestToken,
CustomProperties: login.CustomProperties,
})
if err != nil {
return nil, err
Expand Down
35 changes: 22 additions & 13 deletions incognia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ const (
)

var (
now = time.Now()
nowMinusSeconds = now.Add(-1 * time.Second)
installationId = "installation-id"
requestToken = "request-token"
now = time.Now()
nowMinusSeconds = now.Add(-1 * time.Second)
installationId = "installation-id"
requestToken = "request-token"
customProperty = map[string]interface{}{
"custom_1": "custom_value_1",
"custom_2": "custom_value_2",
}
shouldEval bool = true
shouldNotEval bool = false
emptyQueryString map[string][]string = nil
Expand Down Expand Up @@ -174,11 +178,12 @@ var (
},
}
postPaymentRequestBodyFixture = &postTransactionRequestBody{
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Type: paymentType,
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
Type: paymentType,
CustomProperties: customProperty,
Addresses: []*TransactionAddress{
{
Type: Billing,
Expand Down Expand Up @@ -271,10 +276,11 @@ var (
Type: paymentType,
}
paymentFixture = &Payment{
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
InstallationID: &installationId,
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
CustomProperties: customProperty,
Addresses: []*TransactionAddress{
{
Type: Billing,
Expand Down Expand Up @@ -390,6 +396,7 @@ var (
AccountID: "account-id",
ExternalID: "external-id",
PolicyID: "policy-id",
CustomProperties: customProperty,
PaymentMethodIdentifier: "payment-method-identifier",
}
loginFixtureWithShouldEval = &Login{
Expand All @@ -399,6 +406,7 @@ var (
PolicyID: "policy-id",
PaymentMethodIdentifier: "payment-method-identifier",
Eval: &shouldEval,
CustomProperties: customProperty,
}
loginFixtureWithShouldNotEval = &Login{
InstallationID: &installationId,
Expand All @@ -421,6 +429,7 @@ var (
PolicyID: "policy-id",
PaymentMethodIdentifier: "payment-method-identifier",
Type: loginType,
CustomProperties: customProperty,
}
postLoginWebRequestBodyFixture = &postTransactionRequestBody{
AccountID: "account-id",
Expand Down
42 changes: 22 additions & 20 deletions request_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ type StructuredAddress struct {
}

type postAssessmentRequestBody struct {
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"`
AccountID string `json:"account_id,omitempty"`
PolicyID string `json:"policy_id,omitempty"`
ExternalID string `json:"external_id,omitempty"`
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"`
AccountID string `json:"account_id,omitempty"`
PolicyID string `json:"policy_id,omitempty"`
ExternalID string `json:"external_id,omitempty"`
CustomProperties map[string]interface{} `json:"custom_properties,omitempty"`
}

type FeedbackType string
Expand Down Expand Up @@ -133,15 +134,16 @@ type PaymentMethod struct {
}

type postTransactionRequestBody struct {
ExternalID string `json:"external_id,omitempty"`
PolicyID string `json:"policy_id,omitempty"`
InstallationID *string `json:"installation_id,omitempty"`
PaymentMethodIdentifier string `json:"payment_method_identifier,omitempty"`
Type transactionType `json:"type"`
AccountID string `json:"account_id"`
Addresses []*TransactionAddress `json:"addresses,omitempty"`
PaymentValue *PaymentValue `json:"payment_value,omitempty"`
PaymentMethods []*PaymentMethod `json:"payment_methods,omitempty"`
SessionToken *string `json:"session_token,omitempty"`
RequestToken string `json:"request_token,omitempty"`
ExternalID string `json:"external_id,omitempty"`
PolicyID string `json:"policy_id,omitempty"`
InstallationID *string `json:"installation_id,omitempty"`
PaymentMethodIdentifier string `json:"payment_method_identifier,omitempty"`
Type transactionType `json:"type"`
AccountID string `json:"account_id"`
Addresses []*TransactionAddress `json:"addresses,omitempty"`
PaymentValue *PaymentValue `json:"payment_value,omitempty"`
PaymentMethods []*PaymentMethod `json:"payment_methods,omitempty"`
SessionToken *string `json:"session_token,omitempty"`
RequestToken string `json:"request_token,omitempty"`
CustomProperties map[string]interface{} `json:"custom_properties,omitempty"`
}

0 comments on commit e20e806

Please sign in to comment.