Skip to content

Commit

Permalink
feat: update client to confirm to gocardless api changes (#13)
Browse files Browse the repository at this point in the history
* feat: add refresh token method to the client

* feat: updates

* feat: update nordigen references to gocardless

* update nordigen references to gocardless
  • Loading branch information
cksidharthan authored Sep 22, 2024
1 parent 7086880 commit 30dd5cb
Show file tree
Hide file tree
Showing 32 changed files with 531 additions and 402 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jobs:
runs-on: ubuntu-latest
env:
GOPRIVATE: "github.com/cksidharthan/*"
NORDIGEN_SECRET_ID: ${{ secrets.NORDIGEN_SECRET_ID }}
NORDIGEN_SECRET_KEY: ${{ secrets.NORDIGEN_SECRET_KEY }}
NORDIGEN_TEST_ACCOUNT_ID: ${{ secrets.NORDIGEN_TEST_ACCOUNT_ID }}
GOCARDLESS_SECRET_ID: ${{ secrets.GOCARDLESS_SECRET_ID }}
GOCARDLESS_SECRET_KEY: ${{ secrets.GOCARDLESS_SECRET_KEY }}
GOCARDLESS_TEST_ACCOUNT_ID: ${{ secrets.GOCARDLESS_TEST_ACCOUNT_ID }}
steps:
# Checkout
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.4
v0.0.5
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# go-nordigen
Go Library for [Nordigen Openbanking API v2](https://nordigen.com/en/account_information_documenation/api-documention/overview/)
# go-gocardless
Go Library for [GoCardless Bank Account Data API](https://developer.gocardless.com/bank-account-data/overview)

## Requirements
- Go 1.16+
- Nordigen API Secret ID & Key
- Gocardless API Secret ID & Key
- Taskfile (optional)

## Usage
Expand All @@ -16,12 +16,12 @@ Usage examples can be found in the respective package's `*_test.go` files.
- Institutions
- Requisitions

Please refer to [Nordigen API Documentation](https://nordigen.com/en/docs/account-information/integration/parameters-and-responses/) for more information on the endpoints.
Please refer to [GoCardless Bank Account Data API](https://developer.gocardless.com/bank-account-data/overview) 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/cksidharthan/go-nordigen/issues) page.
Please report any issues or bugs to the [Issues](https://github.com/cksidharthan/go-gocardless/issues) page.

![pkg-coverage-img](./assets/cover-treemap.svg?raw=true "Unit Test Coverage Image")
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ tasks:
- task deps
- task fmt
- task lint
- task test
- task test
46 changes: 22 additions & 24 deletions accounts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package nordigen

import "time"
package gocardless

type Account struct {
ID string `json:"id"`
Expand All @@ -13,12 +11,12 @@ type Account struct {
}

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"`
BalanceAmount Amount `json:"balanceAmount"`
BalanceType string `json:"balanceType"`
ReferenceDate string `json:"referenceDate"`
CreditLimitIncluded bool `json:"creditLimitIncluded"`
LastChangeDateTime TimeWithTimeZoneInfo `json:"lastChangeDateTime"`
LastCommittedTransaction string `json:"lastCommittedTransaction"`
}

type Amount struct {
Expand Down Expand Up @@ -61,21 +59,21 @@ type TransactionParams struct {
}

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"`
TransactionID string `json:"transactionId"`
BookingDate string `json:"bookingDate"`
ValueDate string `json:"valueDate"`
BookingDateTime TimeWithTimeZoneInfo `json:"bookingDateTime"`
ValueDateTime TimeWithTimeZoneInfo `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"`
Expand Down
38 changes: 29 additions & 9 deletions accounts_endpoints.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package nordigen
package gocardless

import (
"context"
"fmt"
"net/url"
"time"
)

// GetAccount retrieves an account by ID
func (c Client) GetAccount(ctx context.Context, token string, accountID string) (*Account, error) {
func (c Client) GetAccount(ctx context.Context, accountID string) (*Account, error) {
var account Account
endpointURL := AccountsPath + accountID
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &account)
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &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) {
func (c Client) GetAccountBalances(ctx context.Context, accountID string) (*Balances, error) {
var balances Balances
endpointURL := AccountsPath + accountID + "/balances"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &balances)
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &balances)
if err != nil {
return nil, err
}
Expand All @@ -28,10 +31,10 @@ func (c Client) GetAccountBalances(ctx context.Context, token string, accountID
}

// GetAccountDetails retrieves details for an account by ID
func (c Client) GetAccountDetails(ctx context.Context, token string, accountID string) (*Details, error) {
func (c Client) GetAccountDetails(ctx context.Context, accountID string) (*Details, error) {
var details Details
endpointURL := AccountsPath + accountID + "/details"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &details)
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &details)
if err != nil {
return nil, err
}
Expand All @@ -40,10 +43,27 @@ func (c Client) GetAccountDetails(ctx context.Context, token string, accountID s
}

// GetAccountTransactions retrieves transactions for an account by ID
func (c Client) GetAccountTransactions(ctx context.Context, token string, accountID string) (*Transactions, error) {
// dateFrom and dateTo are optional parameters.
func (c Client) GetAccountTransactions(ctx context.Context, accountID string, dateFrom, dateTo *time.Time) (*Transactions, error) {
var transactions Transactions
endpointURL := AccountsPath + accountID + "/transactions"
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &transactions)

// Build query parameters
u, err := url.Parse(endpointURL)
if err != nil {
return nil, fmt.Errorf("failed to parse URL: %w", err)
}

q := u.Query()
if dateFrom != nil {
q.Set("date_from", dateFrom.Format(time.RFC3339))
}
if dateTo != nil {
q.Set("date_to", dateTo.Format(time.RFC3339))
}
u.RawQuery = q.Encode()

err = c.HTTP.Get(ctx, u.String(), RequestHeadersWithAuth(c.Token.Access), &transactions)
if err != nil {
return nil, err
}
Expand Down
76 changes: 28 additions & 48 deletions accounts_endpoints_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nordigen_test
package gocardless_test

import (
"context"
Expand All @@ -14,31 +14,25 @@ func TestClient_GetAccount(t *testing.T) {
t.Run("get an account by ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
client, err := getTestClient(t)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
assert.NoError(t, err)
assert.NotNil(t, token)

testAccountID := os.Getenv("NORDIGEN_TEST_ACCOUNT_ID")
testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID")

account, err := client.GetAccount(context.Background(), token.Access, testAccountID)
account, err := client.GetAccount(context.Background(), testAccountID)
assert.NoError(t, err)
assert.NotNil(t, account)
})

t.Run("get an account by invalid ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
client, err := getTestClient(t)
assert.NoError(t, err)
assert.NotNil(t, token)
assert.NotNil(t, client)

account, err := client.GetAccount(context.Background(), token.Access, "invalid")
account, err := client.GetAccount(context.Background(), "invalid")
assert.Error(t, err)
assert.Nil(t, account)
})
Expand All @@ -50,31 +44,25 @@ func TestClient_GetAccountBalances(t *testing.T) {
t.Run("get balances for an account by ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
client, err := getTestClient(t)
assert.NoError(t, err)
assert.NotNil(t, token)
assert.NotNil(t, client)

testAccountID := os.Getenv("NORDIGEN_TEST_ACCOUNT_ID")
testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID")

balances, err := client.GetAccountBalances(context.Background(), token.Access, testAccountID)
balances, err := client.GetAccountBalances(context.Background(), testAccountID)
assert.NoError(t, err)
assert.NotNil(t, balances)
})

t.Run("get balances for an account by invalid ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
client, err := getTestClient(t)
assert.NoError(t, err)
assert.NotNil(t, token)
assert.NotNil(t, client)

balances, err := client.GetAccountBalances(context.Background(), token.Access, "invalid")
balances, err := client.GetAccountBalances(context.Background(), "invalid")
assert.Error(t, err)
assert.Nil(t, balances)
})
Expand All @@ -86,31 +74,29 @@ func TestClient_GetAccountDetails(t *testing.T) {
t.Run("get details for an account by ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
client, err := getTestClient(t)
assert.NoError(t, err)
assert.NotNil(t, token)
assert.NotNil(t, client)

testAccountID := os.Getenv("NORDIGEN_TEST_ACCOUNT_ID")
testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID")

details, err := client.GetAccountDetails(context.Background(), token.Access, testAccountID)
details, err := client.GetAccountDetails(context.Background(), testAccountID)
assert.NoError(t, err)
assert.NotNil(t, details)
})

t.Run("get details for an account by invalid ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
client, err := getTestClient(t)
assert.NoError(t, err)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
assert.NoError(t, err)
assert.NotNil(t, token)

details, err := client.GetAccountDetails(context.Background(), token.Access, "invalid")
details, err := client.GetAccountDetails(context.Background(), "invalid")
assert.Error(t, err)
assert.Nil(t, details)
})
Expand All @@ -122,31 +108,25 @@ func TestClient_GetAccountTransactions(t *testing.T) {
t.Run("get transactions for an account by ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
client, err := getTestClient(t)
assert.NoError(t, err)
assert.NotNil(t, token)
assert.NotNil(t, client)

testAccountID := os.Getenv("NORDIGEN_TEST_ACCOUNT_ID")
testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID")

transactions, err := client.GetAccountTransactions(context.Background(), token.Access, testAccountID)
transactions, err := client.GetAccountTransactions(context.Background(), testAccountID, nil, nil)
assert.NoError(t, err)
assert.NotNil(t, transactions)
})

t.Run("get transactions for an account by invalid ID", func(t *testing.T) {
t.Parallel()

client := getTestClient(t)
assert.NotNil(t, client)

token, err := client.NewToken(context.Background())
client, err := getTestClient(t)
assert.NoError(t, err)
assert.NotNil(t, token)
assert.NotNil(t, client)

transactions, err := client.GetAccountTransactions(context.Background(), token.Access, "invalid")
transactions, err := client.GetAccountTransactions(context.Background(), "invalid", nil, nil)
assert.Error(t, err)
assert.Nil(t, transactions)
})
Expand Down
18 changes: 8 additions & 10 deletions agreements.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package nordigen

import "time"
package gocardless

type AgreementRequestBody struct {
InstitutionID string `json:"institution_id"`
Expand All @@ -10,13 +8,13 @@ type AgreementRequestBody struct {
}

type Agreement struct {
ID string `json:"id"`
Created time.Time `json:"created"`
InstitutionID string `json:"institution_id"`
MaxHistoricalDays int `json:"max_historical_days"`
AccessValidForDays int `json:"access_valid_for_days"`
AccessScope []string `json:"access_scope"`
Accepted time.Time `json:"accepted"`
ID string `json:"id"`
Created *TimeWithTimeZoneInfoZ `json:"created"`
InstitutionID string `json:"institution_id"`
MaxHistoricalDays int `json:"max_historical_days"`
AccessValidForDays int `json:"access_valid_for_days"`
AccessScope []string `json:"access_scope"`
Accepted *TimeWithTimeZoneInfoZ `json:"accepted"`
}

type ListAgreementsParams struct {
Expand Down
Loading

0 comments on commit 30dd5cb

Please sign in to comment.