sbanken

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 12 Imported by: 0

README

sbanken-go

tests PkgGoDev Go Report Card

A Go client for the Sbanken API

Exernal information:

Get access to the API

See this page on how to get access to Sbankens API.

Quick example

ctx := context.Background()
cfg := sbanken.Config{
    ClientID:     os.Getenv("CLIENT_ID"),
    ClientSecret: os.Getenv("CLIENT_SECRET"),
}

c, err := sbanken.NewClient(ctx, &cfg, nil)
if err != nil {
    log.Fatal(err)
}


accounts, err := c.ListAccounts(ctx)
if err != nil {
    log.Fatal(err)
}

log.Println(accounts)

Documentation

See pkg.go.dev.

Documentation

Overview

Package sbanken provides an easy way to work with the Sbanken API.

Sbanken API information: https://sbanken.no/bruke/utviklerportalen/ Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html

Index

Constants

View Source
const VERSION = "1.2.0"

Variables

View Source
var (
	// ErrMissingAccountID are returned when accountID is not set.
	ErrMissingAccountID = errors.New("accountID must be set")
	// ErrMissingPaymentID are returned when paymentID is not set.
	ErrMissingPaymentID = errors.New("paymentID must be set")
	// ErrMissingEfakturaID are returned when efakturaID is not set.
	ErrMissingEfakturaID = errors.New("efakturaID must be set")
	// ErrMissingTransferQuery are returned when TransferQuery is not set.
	ErrMissingTransferQuery = errors.New("TransferQuery must be set")
	// ErrMissingEfakturaPayQuery are returned when EfakturaPayQuery is not set.
	ErrMissingEfakturaPayQuery = errors.New("EfakturaPayQuery must be set")
	// ErrMissingPostPayload are returned when PostPayload is not set.
	ErrMissingPostPayload = errors.New("PostPayload must be set")
	// ErrMissingClientID are returned when ClientID is not set.
	ErrMissingClientID = errors.New("ClientID must be set")
	// ErrMissingClientSecret are returned when ClientSecret is not set.
	ErrMissingClientSecret = errors.New("ClientSecret must be set")
	// ErrNotValidOptionStartDate are returned when StartDate is not allowed.
	ErrNotValidOptionStartDate = errors.New("StartDate is not valid option for this method")
	// ErrNotValidOptionEndDate are returned when EndDate is not allowed.
	ErrNotValidOptionEndDate = errors.New("EndDate is not valid option for this method")
	// ErrNotValidOptionStatus are returned when Status is not allowed.
	ErrNotValidOptionStatus = errors.New("Status is not valid option for this method")
)
View Source
var (
	ErrMailboxMessageUnmarshal = errors.New("error unmarshaling json")
)
View Source
var (
	ErrTransactionUnmarshal = errors.New("error unmarshaling json")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID              string  `json:"accountId"`
	Name            string  `json:"name"`
	Type            string  `json:"accountType"`
	Number          string  `json:"accountNumber"`
	OwnerCustomerID string  `json:"ownerCustomerId"`
	Available       float32 `json:"available"`
	Balance         float32 `json:"balance"`
	CreditLimit     float32 `json:"creditLimit"`
}

Account represents an account. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/Accounts

type Address added in v1.1.0

type Address struct {
	AddressLine1 string `json:"addressLine1"`
	AddressLine2 string `json:"addressLine2"`
	AddressLine3 string `json:"addressLine3"`
	AddressLine4 string `json:"addressLine4"`
	Country      string `json:"country"`
	ZipCode      string `json:"zipCode"`
	City         string `json:"city"`
}

Address represents a customer address.

func (Address) String added in v1.2.0

func (a Address) String() string

String returns an address represented as a string.

type Card

type Card struct {
	ID            string `json:"cardId"`
	Number        string `json:"cardNumber"`
	ExpiryDate    string `json:"expiryDate"`
	Status        string `json:"status"`
	Type          string `json:"cardType"`
	ProductCode   string `json:"productCode"`
	AccountNumber string `json:"accountNumber"`
	AccountOwner  string `json:"accountOwner"`
	CustomerID    string `json:"customerId"`
	VersionNumber int    `json:"cardVersionNumber"`
}

Card represents a card. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/Cards/Cards_List

type CardDetails

type CardDetails struct {
	CardNumber                  string  `json:"cardNumber"`
	MerchantCategoryCode        string  `json:"merchantCategoryCode"`
	MerchantCategoryDescription string  `json:"merchantCategoryDescription"`
	MerchantCity                string  `json:"merchantCity"`
	MerchantName                string  `json:"merchantName"`
	OriginalCurrencyCode        string  `json:"originalCurrencyCode"`
	PurchaseDate                string  `json:"purchaseDate"`
	TransactionID               string  `json:"transactionId"`
	CurrencyAmount              float32 `json:"currencyAmount"`
	CurrencyRate                float32 `json:"currencyRate"`
}

CardDetails contains card details about the card used.

type Client

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

Client represents an Sbanken client.

func NewClient

func NewClient(ctx context.Context, cfg *Config, httpClient *http.Client) (*Client, error)

NewClient returns a new Sbanken client. If httpClient is nil, http.DefaultClient will be used.

func (*Client) DeleteArchiveMessage added in v1.3.0

func (c *Client) DeleteArchiveMessage(ctx context.Context, id int) error

func (*Client) DeleteInboxMessage added in v1.3.0

func (c *Client) DeleteInboxMessage(ctx context.Context, id int) error

func (*Client) GetArchiveMessageCount added in v1.3.0

func (c *Client) GetArchiveMessageCount(ctx context.Context, q *MailboxCountQuery) (int, error)

func (*Client) GetCustomer added in v1.1.0

func (c *Client) GetCustomer(ctx context.Context) (Customer, error)

GetCustomer lists customer information.

func (*Client) GetInboxMessageCount added in v1.3.0

func (c *Client) GetInboxMessageCount(ctx context.Context, q *MailboxCountQuery) (int, error)

func (*Client) ListAccounts

func (c *Client) ListAccounts(ctx context.Context) ([]Account, error)

ListAccounts lists the accounts.

func (*Client) ListArchiveMessages added in v1.3.0

func (c *Client) ListArchiveMessages(ctx context.Context, q *MailboxListQuery) ([]MailboxMessage, error)

func (*Client) ListArchivedTransactions added in v1.2.0

func (c *Client) ListArchivedTransactions(ctx context.Context, accountID string, q *TransactionListQuery) ([]Transaction, error)

ListArchivedTransactions returns archived transactions.

func (*Client) ListCards

func (c *Client) ListCards(ctx context.Context) ([]Card, error)

ListCards lists the cards.

func (*Client) ListEfakturas

func (c *Client) ListEfakturas(ctx context.Context, q *EfakturaListQuery) ([]Efaktura, error)

ListEfakturas lists efakturas.

func (*Client) ListInboxMessages added in v1.3.0

func (c *Client) ListInboxMessages(ctx context.Context, q *MailboxListQuery) ([]MailboxMessage, error)

func (*Client) ListNewEfakturas

func (c *Client) ListNewEfakturas(ctx context.Context, q *EfakturaListQuery) ([]Efaktura, error)

ListNewEfakturas lists efakturas that have not yet been processed by the customer.

func (*Client) ListPayments

func (c *Client) ListPayments(ctx context.Context, accountID string, q *PaymentListQuery) ([]Payment, error)

ListPayments list the payments. The accountID are required.

func (*Client) ListStandingOrders

func (c *Client) ListStandingOrders(ctx context.Context, accountID string) ([]StandingOrder, error)

ListStandingOrders lists the standing orders for repeated transfers and payments. The accoundID are required.

func (*Client) ListTransactions

func (c *Client) ListTransactions(ctx context.Context, accountID string, q *TransactionListQuery) ([]Transaction, error)

ListTransactions returns the latest transactions of the given account.

func (*Client) MoveArchiveMessage added in v1.3.0

func (c *Client) MoveArchiveMessage(ctx context.Context, id int) error

func (*Client) MoveInboxMessage added in v1.3.0

func (c *Client) MoveInboxMessage(ctx context.Context, id int) error

func (*Client) PayEfaktura

func (c *Client) PayEfaktura(ctx context.Context, q *EfakturaPayQuery) error

PayEfaktura pays an efaktura. The EfakturaPayQuery are required.

func (*Client) ReadAccount

func (c *Client) ReadAccount(ctx context.Context, accountID string) (Account, error)

ReadAccount reads an account. The accountID are required.

func (*Client) ReadArchiveAttachment added in v1.3.0

func (c *Client) ReadArchiveAttachment(ctx context.Context, messageID int, attachmentID int) (MailboxAttachment, error)

func (*Client) ReadArchiveMessage added in v1.3.0

func (c *Client) ReadArchiveMessage(ctx context.Context, id int) (MailboxMessage, error)

func (*Client) ReadEfaktura

func (c *Client) ReadEfaktura(ctx context.Context, efakturaID string) (Efaktura, error)

ReadEfaktura reads an efaktura. The efakturaID are required.

func (*Client) ReadInboxAttachment added in v1.3.0

func (c *Client) ReadInboxAttachment(ctx context.Context, messageID int, attachmentID int) (MailboxAttachment, error)

func (*Client) ReadInboxMessage added in v1.3.0

func (c *Client) ReadInboxMessage(ctx context.Context, id int) (MailboxMessage, error)

func (*Client) ReadPayment

func (c *Client) ReadPayment(ctx context.Context, accountID string, paymentID string) (Payment, error)

ReadPayment reads a payment. The accountID and paymentID are required.

func (*Client) Transfer

func (c *Client) Transfer(ctx context.Context, q *TransferQuery) error

Transfer executes a transfer between two accounts. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/Transfers

func (*Client) UpdateArchiveMessageReadStatus added in v1.3.0

func (c *Client) UpdateArchiveMessageReadStatus(ctx context.Context, id int, read bool) error

func (*Client) UpdateInboxMessageReadStatus added in v1.3.0

func (c *Client) UpdateInboxMessageReadStatus(ctx context.Context, id int, read bool) error

type Config

type Config struct {
	// ClientID is required.
	ClientID string
	// ClientSecret is required.
	ClientSecret string
	// CustomerID is deprecated.
	CustomerID string
	// UserAgent is for optionally setting a custom user agent.
	UserAgent string
	// contains filtered or unexported fields
}

Config represents Sbanken client config.

type Customer added in v1.1.0

type Customer struct {
	CustomerID    string        `json:"customerID"`
	FirstName     string        `json:"firstName"`
	LastName      string        `json:"lastName"`
	EmailAddress  string        `json:"emailAddress"`
	DateOfBirth   string        `json:"dateOfBirth"`
	PostalAddress Address       `json:"postalAddress"`
	StreetAddress Address       `json:"streetAddress"`
	PhoneNumbers  []PhoneNumber `json:"phoneNumbers"`
}

Customer represents a customer. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/Customers

type Efaktura

type Efaktura struct {
	ID                  string  `json:"eFakturaId"`
	IssuerID            string  `json:"issuerId"`
	Reference           string  `json:"eFakturaReference"`
	DocumentType        string  `json:"documentType"`
	Status              string  `json:"status"`
	KID                 string  `json:"kid"`
	OriginalDueDate     string  `json:"originalDueDate"`
	UpdatedDueDate      string  `json:"updatedDueDate"`
	NotificationDate    string  `json:"notificationDate"`
	IssuerName          string  `json:"issuerName"`
	CreditAccountNumber string  `json:"creditAccountNumber"`
	OriginalAmount      float32 `json:"originalAmount"`
	UpdatedAmount       float32 `json:"updatedAmount"`
	MinimumAmount       float32 `json:"minimumAmount"`
}

Efaktura represents an efaktura. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/Efaktura

type EfakturaListQuery

type EfakturaListQuery struct {
	StartDate time.Time
	EndDate   time.Time
	Status    string
	Index     string
	Length    string
}

EfakturaListQuery represents query parameters for querying efakturas.

func (*EfakturaListQuery) QueryString

func (q *EfakturaListQuery) QueryString(u string) (string, error)

QueryString translates the query into a query string.

type EfakturaPayQuery

type EfakturaPayQuery struct {
	ID                   string `json:"eFakturaId"`
	AccountID            string `json:"accountId"`
	PayOnlyMinimumAmount bool   `json:"PayOnlyMinimumAmount"`
}

EfakturaPayQuery represents a payment query.

type Error

type Error struct {
	ErrorString string
	Type        string
	Message     string
	Code        int
	StatusCode  int
}

Error represents a standard error.

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of the error.

type MailboxAttachment added in v1.3.0

type MailboxAttachment struct {
	ID         int    `json:"attachmentID"`
	Name       string `json:"name"`
	Attachment string `json:"attachment"`
}

type MailboxCountQuery added in v1.3.0

type MailboxCountQuery struct {
	StartDate time.Time
	EndDate   time.Time
	Status    string
}

func (*MailboxCountQuery) QueryString added in v1.3.0

func (q *MailboxCountQuery) QueryString(u string) (string, error)

type MailboxListQuery added in v1.3.0

type MailboxListQuery struct {
	StartDate time.Time
	EndDate   time.Time
	Status    string
	Index     string
	Length    string
}

MailboxQuery represents query parameteres for querying the mailbox.

func (*MailboxListQuery) QueryString added in v1.3.0

func (q *MailboxListQuery) QueryString(u string) (string, error)

type MailboxMessage added in v1.3.0

type MailboxMessage struct {
	Subject      string `json:"subject"`
	Category     string `json:"category"`
	Source       string `json:"source"`
	Status       string `json:"status"`
	LinkName     string `json:"linkName"`
	LinkURL      string `json:"linkUrl"`
	ReceivedDate string `json:"receivedDate"`
	ID           int    `json:"id"`
	Flag         int    `json:"flag"`
	AttachmentID int    `json:"attachmentId"`
}

MailboxMessage represents a mailbox message. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html?urls.primaryName=API%20Beta%20V2#/Mailbox

func (*MailboxMessage) UnmarshalJSON added in v1.3.0

func (m *MailboxMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON is implemented due to a bug in sbankens API. Category and Status should contain strings, but contain ints. The custom unmarshaler supports both string and ints for these fields.

type Payment

type Payment struct {
	AllowedNewStatusTypes  []string `json:"allowedNewStatusTypes"`
	ID                     string   `json:"paymentId"`
	RecipientAccountNumber string   `json:"recipientAccountNumber"`
	DueDate                string   `json:"dueDate"`
	KID                    string   `json:"kid"`
	Text                   string   `json:"text"`
	Status                 string   `json:"status"`
	StatusDetails          string   `json:"statusDetails"`
	ProductType            string   `json:"productType"`
	PaymentType            string   `json:"paymentType"`
	BeneficiaryName        string   `json:"beneficiaryName"`
	Amount                 float32  `json:"amount"`
	PaymentNumber          int      `json:"paymentNumber"`
	IsActive               bool     `json:"isActive"`
}

Payment represents a payment. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/Payments

type PaymentListQuery

type PaymentListQuery struct {
	Index  string
	Length string
}

PaymentListQuery represents query parameters for querying payments.

func (*PaymentListQuery) QueryString

func (q *PaymentListQuery) QueryString(u string) (string, error)

QueryString translates the query into a query string.

type PhoneNumber added in v1.1.0

type PhoneNumber struct {
	CountryCode string `json:"countryCode"`
	Number      string `json:"number"`
}

PhoneNumber represents a customer phone number.

type StandingOrder

type StandingOrder struct {
	FreeTerms              []string `json:"freeTerms"`
	BeneficiaryName        string   `json:"beneficiaryName"`
	CID                    string   `json:"cId"`
	CreditAccountNumber    string   `json:"creditAccountNumber"`
	DebitAccountNumber     string   `json:"debitAccountNumber"`
	Frequency              string   `json:"frequency"`
	LastPaymentDate        string   `json:"lastPaymentDate"`
	NextDueDate            string   `json:"nextDueDate"`
	StandingOrderEndDate   string   `json:"standingOrderEndDate"`
	StandingOrderStartDate string   `json:"standingOrderStartDate"`
	StandingOrderType      string   `json:"standingOrderType"`
	Amount                 float32  `json:"amount"`
	StandingOrderID        int      `json:"standingOrderId"`
}

StandingOrder represents a standing order (repeated transfers and payments). Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/StandingOrders

type Transaction

type Transaction struct {
	CardDetails                 CardDetails        `json:"cardDetails"`
	TransactionDetails          TransactionDetails `json:"transactionDetails"`
	AccountingDate              string             `json:"accountingDate"`
	InterestDate                string             `json:"interestDate"`
	OtherAccountNumber          string             `json:"otherAccountNumber"`
	Text                        string             `json:"text"`
	TransactionType             string             `json:"transactionType"`
	TransactionTypeText         string             `json:"transactionTypeText"`
	ReservationType             string             `json:"reservationType"`
	TransactionID               string             `json:"transactionId"`
	Source                      string             `json:"source"`
	Amount                      float32            `json:"amount"`
	TransactionTypeCode         int                `json:"transactionTypeCode"`
	IsReservation               bool               `json:"isReservation"`
	CardDetailsSpecified        bool               `json:"cardDetailsSpecified"`
	OtherAccountNumberSpecified bool               `json:"otherAccountNumberSpecified"`
	TransactionDetailSpecified  bool               `json:"transactionDetailSpecified"`
}

Transaction represents a transaction. Sbanken API documentation: https://publicapi.sbanken.no/openapi/apibeta/index.html#/Transactions

func (*Transaction) UnmarshalJSON added in v1.3.0

func (t *Transaction) UnmarshalJSON(data []byte) error

UnmarshalJSON is implemented due to a bug in sbankens API. The Source field should contain a string, but contain an int. The custom unmarshaler supports both string and ints for this fields.

type TransactionDetails

type TransactionDetails struct {
	ID                     string `json:"transactionId"`
	FormattedAccountNumber string `json:"formattedAccountNumber"`
	CID                    string `json:"cid"`
	AmountDescription      string `json:"amountDescription"`
	ReceiverName           string `json:"receiverName"`
	PayerName              string `json:"payerName"`
	RegistrationDate       string `json:"registrationDate"`
	NumericReference       int    `json:"numericReference"`
}

TransactionDetails contains transaction details.

type TransactionListQuery

type TransactionListQuery struct {
	StartDate time.Time
	EndDate   time.Time
	Index     string
	Length    string
}

TransactionListQuery represents query parameters for querying transactions.

func (*TransactionListQuery) QueryString

func (q *TransactionListQuery) QueryString(u string) (string, error)

QueryString translates the query into a query string.

type TransferQuery

type TransferQuery struct {
	FromAccountID string  `json:"fromAccountId"`
	ToAccountID   string  `json:"toAccountId"`
	Message       string  `json:"message"`
	Amount        float32 `json:"amount"`
}

TransferQuery represents the query for transferring between accounts.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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