Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ ALTER TABLE platform
DROP COLUMN IF EXISTS api_key,
DROP COLUMN IF EXISTS authentication,
ADD COLUMN activated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- for activating prod users
ADD COLUMN name TEXT NOT NULL,
ADD COLUMN name TEXT NOT NULL DEFAULT '',
ADD COLUMN description TEXT DEFAULT '',
ADD COLUMN domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API)
ADD COLUMN ip_addresses TEXT[] DEFAULT NULL; -- define which API ips can make calls (API-to-API)
ADD COLUMN domains TEXT[] DEFAULT '{}'::TEXT[], -- define which domains can make calls to API (web-to-API)
ADD COLUMN ip_addresses TEXT[] DEFAULT '{}'::TEXT[]; -- define which API ips can make calls (API-to-API)

-------------------------------------------------------------------------
-- TRANSACTION -------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CREATE TABLE apikey (
deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL,
type TEXT NOT NULL, -- [public,private] for now all public?
data TEXT NOT NULL, -- the key itself
description TEXT DEFAULT NULL,
description TEXT DEFAULT '',
created_by UUID REFERENCES platform_member (id),
platform_id UUID REFERENCES platform (id)
);
Expand Down
54 changes: 26 additions & 28 deletions pkg/service/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,29 @@ func (t transaction) safetyCheck(p transactionProcessingData) (transactionProces
}

// Validate Transaction through Real Time Rules engine
err = t.unit21Evaluate(p.transactionModel.ID)
// RTR is not released for Unit21 Production (slated for Late February 2023)
evaluation, err := t.unit21Evaluate(p.transactionModel.ID)
if err != nil {
// If Unit21 Evaluate fails, just log, but otherwise continue with the transaction
log.Printf("Error evaluating transaction in Unit21: %s", common.StringError(err))
return p, nil // NOTE: intentionally returning nil here in order to continue the transaction
}

if !evaluation {
err = t.updateTransactionStatus("Failed", p.transactionModel.ID)
if err != nil {
return p, common.StringError(err)
}

err = t.unit21CreateTransaction(p.transactionModel.ID)
if err != nil {
return p, common.StringError(err)
}

return p, common.StringError(errors.New("risk: Transaction Failed Unit21 Real Time Rules Evaluation"))
}

err = t.updateTransactionStatus("Unit21 Authorized", p.transactionModel.ID)
if err != nil {
return p, common.StringError(err)
}
Expand Down Expand Up @@ -807,12 +829,12 @@ func (t transaction) unit21CreateTransaction(transactionId string) (err error) {
return nil
}

func (t transaction) unit21Evaluate(transactionId string) (err error) {
func (t transaction) unit21Evaluate(transactionId string) (evaluation bool, err error) {
//Check transaction in Unit21
txModel, err := t.repos.Transaction.GetById(transactionId)
if err != nil {
log.Printf("Error getting tx model in Unit21 in Tx Evaluate: %s", common.StringError(err))
return common.StringError(err)
return evaluation, common.StringError(err)
}

u21Repo := unit21.TransactionRepo{
Expand All @@ -822,31 +844,7 @@ func (t transaction) unit21Evaluate(transactionId string) (err error) {
}

u21Tx := unit21.NewTransaction(u21Repo)
evaluation, err := u21Tx.Evaluate(txModel)
if err != nil {
log.Printf("Error evaluating transaction in Unit21: %s", common.StringError(err))
return common.StringError(err)
}

if !evaluation {
err = t.updateTransactionStatus("Failed", transactionId)
if err != nil {
return common.StringError(err)
}

err = t.unit21CreateTransaction(transactionId)
if err != nil {
return common.StringError(err)
}

return common.StringError(errors.New("risk: Transaction Failed Unit21 Real Time Rules Evaluation"))
}
err = t.updateTransactionStatus("Unit21 Authorized", transactionId)
if err != nil {
return common.StringError(err)
}

return nil
return u21Tx.Evaluate(txModel)
}

func (t transaction) updateTransactionStatus(status string, transactionId string) (err error) {
Expand Down