goDecide

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2021 License: MIT Imports: 12 Imported by: 0

README

goDecide

Golang SDK for Indicina's Decide API

##How to use GoDecide

###Mono

  1. Create a Mono Statement Object with NewMonoStatement()
  2. Populate the Statement Object with transactions using the MonoStatement.AddTransaction() function
  3. Create a Customer with NewCustomer(). You only need an Id.
  4. Call the PaseMonoStatement Function
  5. Handle the response

If you want to handle the json response from mono directly, use the ParseMonoString() Function.

###Custom Statement

  1. Create a Custom Statement Object with NewCustomStatement()
  2. Populate the Statement Object with transactions using the CustomStatement.AddTransaction() function
  3. Create a Customer with NewCustomer(). You only need an Id.
  4. Call the ParseCustomStatement Function
  5. Handle the response

If you want to handle the json response from mono directly, use the ParseMonoString() Function.

##Example

func monoHandler() httprouter.Handle {
    return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {

	var yahyah []map[string]interface{}

	err := apiHelpers.Unmarshal(r.Body, &yahyah)
	if err != nil {
		apiHelpers.WriteError(w, err, 500, "internal error 1")
		return
	}

	cust := indicina.NewCustomer(
		"id1", "", "", "", "")

	ms := indicina.NewMonoStatement()

	for _, tx := range yahyah {
		ms.AddTransaction(
			int(tx["Amount"].(float64)),
			tx["ID"].(string),
			tx["Date"].(string),
			tx["Narration"].(string),
			tx["Type"].(string),
			tx["Category"].(string),
		)
	}

	ic, err := indicina.Login(
		os.Getenv("INDICINA_CLIENT_ID"),
		os.Getenv("INDICINA_CLIENT_SECRET"),
		os.Getenv("INDICINA_BASE_URL"),
	)
	if err != nil {
		apiHelpers.WriteError(w, err, 500, "internal error 2")
		return
	}

	sum, err := ic.ParseMonoStatement(cust, ms)
	if err != nil {
		apiHelpers.WriteError(w, err, 500, "internal error 3")
		return
	}

	apiHelpers.WriteOKJSONResponse(w, 200, "Mono Summary", sum)
	return

    }
}

Documentation

Index

Constants

View Source
const (
	// v2 Base Url
	V2BaseUrl = "https://api.indicina.co/api/v2/client"

	// statement types
	Mono   = "mono"
	Custom = "custom"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalysisRequest

type AnalysisRequest struct {
	Customer      *Customer      `json:"customer,omitempty"`
	BankStatement *BankStatement `json:"bankStatement,omitempty"`
	Pdf           []byte         `json:"pdf,omitempty"`
	BankCode      string         `json:"bank_code,omitempty"`
	CustomerId    string         `json:"customer_id,omitempty"`
}

type BankStatement

type BankStatement struct {
	Type    string    `json:"type"`
	Content Statement `json:"content"` //Statement Type
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Login

func Login(clientId, clientSecret, baseUrl string) (cl *Client, err error)

Login uses your goDecide ID and Key and returns a client with methods for performing Decide API functions

func (*Client) GetPDFJobStatus

func (cl *Client) GetPDFJobStatus(jobId string) (
	sum *PDFStatementResponse, err error)

func (*Client) ParseCustomStatement

func (cl *Client) ParseCustomStatement(
	customer *Customer, statement *CustomStatement) (
	sum *StatementSummary, err error)

func (*Client) ParseMonoStatement

func (cl *Client) ParseMonoStatement(
	customer *Customer, statement *MonoStatement) (
	sum *StatementSummary, err error)

func (*Client) ParsePDFUpload

func (cl *Client) ParsePDFUpload(file []byte, fileString *string, bankCode, customerId, password string) (
	sum *PDFStatementResponse, err error)

type CustomStatement

type CustomStatement struct {
	Statement []CustomTransaction `json:"statement"`
}

func NewCustomStatement

func NewCustomStatement() *CustomStatement

func (*CustomStatement) AddTransaction

func (ms *CustomStatement) AddTransaction(
	amt, balance int,
	id, date, narr, debitOrCredit string)

func (*CustomStatement) IsStatement

func (ms *CustomStatement) IsStatement() bool

type CustomTransaction

type CustomTransaction struct {
	Id        string `json:"id"`
	Type      string `json:"type"`
	Amount    int    `json:"amount"`
	Narration string `json:"narration"`
	Date      string `json:"date"`
	Balance   int    `json:"balance"`
}

type Customer

type Customer struct {
	Id        string `json:"id"`
	Email     string `json:"email"`
	LastName  string `json:"lastName"`
	FirstName string `json:"firstName"`
	Phone     string `json:"phone"`
}

func NewCustomer

func NewCustomer(id string, email string, lastName string, firstName string, phone string) *Customer

type MonoStatement

type MonoStatement struct {
	Paging struct {
		Total    int    `json:"total"`
		Page     int    `json:"page"`
		Previous string `json:"previous"`
		Next     string `json:"next"`
	} `json:"paging"`
	Data []MonoTransaction `json:"data"`
}

func NewMonoStatement

func NewMonoStatement() *MonoStatement

func (*MonoStatement) AddTransaction

func (ms *MonoStatement) AddTransaction(
	amt int,
	id, date, narr, debitOrCredit,
	category string)

func (*MonoStatement) IsStatement

func (ms *MonoStatement) IsStatement() bool

type MonoTransaction

type MonoTransaction struct {
	Id        string `json:"_id"`
	Amount    int    `json:"amount"`
	Date      string `json:"date"`
	Narration string `json:"narration"`
	Type      string `json:"type"`
	Category  string `json:"category"`
}

type PDFStatementResponse

type PDFStatementResponse struct {
	JobId          string           `json:"jobId"`
	Status         string           `json:"status"`
	DecideResponse StatementSummary `json:"decideResponse""`
}

type Statement

type Statement interface {
	IsStatement() bool
}

type StatementSummary

type StatementSummary struct {
	BehaviouralAnalysis struct {
		AccountSweep                string  `json:"accountSweep"`
		GamblingRate                float64 `json:"gamblingRate"`
		InflowOutflowRate           string  `json:"inflowOutflowRate"`
		LoanAmount                  float64 `json:"loanAmount"`
		LoanInflowRate              float64 `json:"loanInflowRate"`
		LoanRepaymentInflowRate     float64 `json:"loanRepaymentInflowRate"`
		LoanRepayments              float64 `json:"loanRepayments"`
		TopIncomingTransferAccount  string  `json:"topIncomingTransferAccount"`
		TopTransferRecipientAccount string  `json:"topTransferRecipientAccount"`
	} `json:"behaviouralAnalysis"`
	CashFlowAnalysis struct {
		AccountActivity           float64 `json:"accountActivity"`
		AverageBalance            float64 `json:"averageBalance"`
		AverageCredits            float64 `json:"averageCredits"`
		AverageDebits             float64 `json:"averageDebits"`
		ClosingBalance            float64 `json:"closingBalance"`
		FirstDay                  string  `json:"firstDay"`
		LastDay                   string  `json:"lastDay"`
		MonthPeriod               string  `json:"monthPeriod"`
		NetAverageMonthlyEarnings float64 `json:"netAverageMonthlyEarnings"`
		NoOfTransactingMonths     float64 `json:"noOfTransactingMonths"`
		TotalCreditTurnover       float64 `json:"totalCreditTurnover"`
		TotalDebitTurnover        float64 `json:"totalDebitTurnover"`
		YearInStatement           string  `json:"yearInStatement"`
	} `json:"cashFlowAnalysis"`
	IncomeAnalysis struct {
		AverageOtherIncome                  float64     `json:"averageOtherIncome"`
		AverageSalary                       float64     `json:"averageSalary"`
		ConfidenceIntervalonSalaryDetection float64     `json:"confidenceIntervalonSalaryDetection"`
		ExpectedSalaryDay                   interface{} `json:"expectedSalaryDay"`
		LastSalaryDate                      interface{} `json:"lastSalaryDate"`
		MedianIncome                        float64     `json:"medianIncome"`
		NumberOtherIncomePayments           float64     `json:"numberOtherIncomePayments"`
		NumberSalaryPayments                float64     `json:"numberSalaryPayments"`
		SalaryEarner                        string      `json:"salaryEarner"`
		SalaryFrequency                     interface{} `json:"salaryFrequency"`
	} `json:"incomeAnalysis"`
	SpendAnalysis struct {
		Airtime                        float64 `json:"airtime"`
		AtmWithdrawalsSpend            float64 `json:"atmWithdrawalsSpend"`
		AverageRecurringExpense        float64 `json:"averageRecurringExpense"`
		BankCharges                    float64 `json:"bankCharges"`
		Bills                          float64 `json:"bills"`
		CableTv                        float64 `json:"cableTv"`
		ClubsAndBars                   float64 `json:"clubsAndBars"`
		Gambling                       float64 `json:"gambling"`
		HasRecurringExpense            string  `json:"hasRecurringExpense"`
		InternationalTransactionsSpend float64 `json:"internationalTransactionsSpend"`
		PosSpend                       float64 `json:"posSpend"`
		ReligiousGiving                float64 `json:"religiousGiving"`
		SpendOnTransfers               float64 `json:"spendOnTransfers"`
		TotalExpenses                  float64 `json:"totalExpenses"`
		UssdTransactions               float64 `json:"ussdTransactions"`
		UtilitiesAndInternet           float64 `json:"utilitiesAndInternet"`
		WebSpend                       float64 `json:"webSpend"`
	} `json:"spendAnalysis"`
	TransactionPatternAnalysis struct {
		MAWWZeroBalanceInAccount struct {
			Month       string  `json:"month"`
			WeekOfMonth float64 `json:"week_of_month"`
		} `json:"MAWWZeroBalanceInAccount"`
		NODWBalanceLess5000 float64 `json:"NODWBalanceLess5000"`
		HighestMAWOCredit   struct {
			Month       string  `json:"month"`
			WeekOfMonth float64 `json:"week_of_month"`
		} `json:"highestMAWOCredit"`
		HighestMAWODebit struct {
			Month       string  `json:"month"`
			WeekOfMonth float64 `json:"week_of_month"`
		} `json:"highestMAWODebit"`
		LastDateOfCredit                   string        `json:"lastDateOfCredit"`
		LastDateOfDebit                    string        `json:"lastDateOfDebit"`
		MostFrequentBalanceRange           interface{}   `json:"mostFrequentBalanceRange"`
		MostFrequentTransactionRange       interface{}   `json:"mostFrequentTransactionRange"`
		RecurringExpense                   []interface{} `json:"recurringExpense"`
		TransactionsBetween100000And500000 float64       `json:"transactionsBetween100000And500000"`
		TransactionsBetween10000And100000  float64       `json:"transactionsBetween10000And100000"`
		TransactionsGreater500000          float64       `json:"transactionsGreater500000"`
		TransactionsLess10000              float64       `json:"transactionsLess10000"`
	} `json:"transactionPatternAnalysis"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL