Skip to content

Commit

Permalink
feature: add premium endpoint implementations (#8)
Browse files Browse the repository at this point in the history
* feature: update balance and transaction structs

* code refactor

* Update pull_request_template.md

* refactor code

* feat: add premium account transactions endpoint

* Update README.md

* format and lint issues fix

* Update Taskfile.yml
  • Loading branch information
cksidharthan authored May 7, 2023
1 parent 92033a8 commit c81b58f
Show file tree
Hide file tree
Showing 51 changed files with 1,294 additions and 1,456 deletions.
3 changes: 0 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ A brief summary of the changes made in the PR
### Check list

- [ ] `task pr-check` command executed successfully after the changes
- [ ] Tested helm deploy is working fine in local machine with the changes
- [ ] Tested docker compose is working fine in local machine with the changes
- [ ] Required changes are made in `Taskfile.yml` (if required)
- [ ] Optimal test coverage is added ( > 70%)
- [ ] Check if the Traces are present in Jaeger
- [ ] Ran manual e2e testing (if required)
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ Usage examples can be found in the respective package's `*_test.go` files.

Please refer to [Nordigen API Documentation](https://nordigen.com/en/docs/account-information/integration/parameters-and-responses/) for more information on the endpoints.

# Pending Endpoints
- Payments - Since this needs some access to the API which is paid, I will not be implementing this since I can't test. If you would like to contribute, please feel free to open a PR.

# Issues
Please report any issues or bugs to the [Issues](https://github.com/weportfolio/go-nordigen/issues) page.

![pkg-coverage-img](./assets/cover-treemap.svg?raw=true "Unit Test Coverage Image")
24 changes: 22 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
version: 3

env:
TAG_NAME:
sh: |
# check if the current branch is main
if [ "$(git rev-parse --abbrev-ref HEAD)" = "main" ]; then
# if the current branch is main, then use the version as is
cat .version
else
# if the current branch is not main, then append the branch hash to the version
cat .version | git rev-parse --short HEAD
fi
tasks:
dev-setup:
desc: "Setup development environment"
Expand Down Expand Up @@ -42,5 +54,13 @@ tasks:
tag:
desc: "Tagging the release"
cmds:
- git tag -a $(cat .version) -m "Release v$(cat .version)"
- git push origin $(cat .version)
- git tag -a {{.TAG_NAME}} -m "Release {{.TAG_NAME}}"
- git push origin {{.TAG_NAME}}

pr-check:
desc: "PR Check"
cmds:
- task deps
- task fmt
- task lint
- task test
104 changes: 104 additions & 0 deletions accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package nordigen

import "time"

type Account struct {
ID string `json:"id"`
Created string `json:"created"`
LastAccessed string `json:"last_accessed"`
IBAN string `json:"iban"`
InstitutionID string `json:"institution_id"`
Status string `json:"status"`
OwnerName string `json:"owner_name"`
}

type Balance struct {
BalanceAmount Amount `json:"balanceAmount"`
BalanceType string `json:"balanceType"`
ReferenceDate string `json:"referenceDate"`
CreditLimitIncluded bool `json:"creditLimitIncluded"`
LastChangeDateTime time.Time `json:"lastChangeDateTime"`
LastCommittedTransaction string `json:"lastCommittedTransaction"`
}

type Amount struct {
Amount string `json:"amount"`
Currency string `json:"currency"`
}

type Balances struct {
Balances []Balance `json:"balances"`
}

// AccountDetails is a struct that contains the details of an account
// Some fields might be empty, depending on the account type
type AccountDetails struct {
BBAN string `json:"bban"`
BIC string `json:"bic"`
Details string `json:"details"`
DisplayName string `json:"displayName"`
LinkedAccounts string `json:"linkedAccounts"`
MisISDN string `json:"misIsdn"`
OwnerAddressUnstructured string `json:"ownerAddressUnstructured"`
Status string `json:"status"`
Usage string `json:"usage"`
ResourceID string `json:"resourceId"`
IBAN string `json:"iban"`
Currency string `json:"currency"`
OwnerName string `json:"ownerName"`
Name string `json:"name"`
Product string `json:"product"`
CashAccountType string `json:"cashAccountType"`
}

type Details struct {
Account AccountDetails `json:"account"`
}

type TransactionParams struct {
DateFrom string `url:"date_from,omitempty" json:"date_from,omitempty"`
DateTo string `url:"date_to,omitempty" json:"date_to,omitempty"`
}

type Transaction struct {
TransactionID string `json:"transactionId"`
BookingDate string `json:"bookingDate"`
ValueDate string `json:"valueDate"`
BookingDateTime time.Time `json:"bookingDateTime"`
ValueDateTime time.Time `json:"valueDateTime"`
TransactionAmount Amount `json:"transactionAmount"`
CreditorName string `json:"creditorName"`
CreditorAccount Account `json:"creditorAccount"`
DebtorName string `json:"debtorName"`
DebtorAccount Account `json:"debtorAccount"`
BankTransactionCode string `json:"bankTransactionCode"`
RemittanceInformationUnstructured string `json:"remittanceInformationUnstructured"`
RemittanceInformationUnstructuredArray []string `json:"remittanceInformationUnstructuredArray"`
ProprietaryBankTransactionCode string `json:"proprietaryBankTransactionCode"`
InternalTransactionID string `json:"internalTransactionId"`

AdditionalInformation string `json:"additionalInformation"`
AdditionalInformationStructured string `json:"additionalInformationStructured"`
BalanceAfterTransaction Balance `json:"balanceAfterTransaction"`
CheckID string `json:"checkId"`
CreditorID string `json:"creditorId"`
// CurrencyExchange []string `json:"currencyExchange"`
DebtorAgent string `json:"debtorAgent"`
EndToEndID string `json:"endToEndId"`
EntryReference string `json:"entryReference"`
MandateID string `json:"mandateId"`
MerchantCategoryCode string `json:"merchantCategoryCode"`
RemittanceInformationStructured string `json:"remittanceInformationStructured"`
RemittanceInformationStructuredArray []string `json:"remittanceInformationStructuredArray"`
UltimateCollector string `json:"ultimateCreditor"`
UltimateDebtor string `json:"ultimateDebtor"`
}

type Transactions struct {
Transactions TransactionList `json:"transactions"`
}

type TransactionList struct {
Booked []Transaction `json:"booked"`
Pending []Transaction `json:"pending"`
}
52 changes: 52 additions & 0 deletions accounts_endpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package nordigen

import (
"context"
)

// GetAccount retrieves an account by ID
func (c Client) GetAccount(ctx context.Context, token string, accountID string) (*Account, error) {
var account Account
endpointURL := AccountsPath + accountID
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &account)
if err != nil {
return nil, err
}
return &account, nil
}

// GetAccountBalances retrieves balances for an account by ID
func (c Client) GetAccountBalances(ctx context.Context, token string, accountID string) (*Balances, error) {
var balances Balances
endpointURL := AccountsPath + accountID + "/balances"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &balances)
if err != nil {
return nil, err
}

return &balances, nil
}

// GetAccountDetails retrieves details for an account by ID
func (c Client) GetAccountDetails(ctx context.Context, token string, accountID string) (*Details, error) {
var details Details
endpointURL := AccountsPath + accountID + "/details"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &details)
if err != nil {
return nil, err
}

return &details, nil
}

// GetAccountTransactions retrieves transactions for an account by ID
func (c Client) GetAccountTransactions(ctx context.Context, token string, accountID string) (*Transactions, error) {
var transactions Transactions
endpointURL := AccountsPath + accountID + "/transactions"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &transactions)
if err != nil {
return nil, err
}

return &transactions, nil
}
Loading

0 comments on commit c81b58f

Please sign in to comment.