Documentation ¶
Index ¶
- Constants
- func CheckCardNumber(card string) error
- func NewKievLocation() *time.Location
- type Amount
- type BalanceOpts
- type Card
- type CardBalance
- type Client
- type ClientOpts
- type CommonOpts
- type DoFunc
- type Doer
- type Error
- type Funds
- type LogFunc
- type Logger
- type Merchant
- type MerchantSign
- type Request
- type RequestData
- type Response
- type ResponseData
- type Statement
- type Statements
- type StatementsOpts
Constants ¶
const ( // DecimalPrecision of Amount DecimalPrecision int64 = 100 )
Variables ¶
This section is empty.
Functions ¶
func CheckCardNumber ¶
CheckCardNumber returns an error if card number is not valid
func NewKievLocation ¶
NewKievLocation returns time.Location of Europe/Kiev time zone
Types ¶
type Amount ¶
type Amount int64
Amount represents p24 amount. It is float value with accurate to two decimal places for example 123.45, -12, 12.02, 33.20 . All number after two decimal places will be skipped during parsing. "123.6789" parsed to 123.67
func (Amount) Float64 ¶
Float64 returns float64 representation of a. It returns 0 if a > math.MaxFloat64
func (Amount) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for a
func (*Amount) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for a. All number after two decimal places will be skipped during parsing. "123.6789" parsed to 123.67
type BalanceOpts ¶
type BalanceOpts struct { CardNumber string Country string CommonOpts }
BalanceOpts is sets of options required for performs p24 card balance request
type Card ¶
type Card struct { Account string `xml:"account"` Number string `xml:"card_number"` AccName string `xml:"acc_name"` AccType string `xml:"acc_type"` Currency string `xml:"currency"` Type string `xml:"card_type"` MainCard string `xml:"main_card_number"` Status string `xml:"card_stat"` Src string `xml:"src"` }
Card represents state of a p24 merchant card
type CardBalance ¶
type CardBalance struct { Date time.Time `xml:"-"` Dyn string `xml:"bal_dyn"` Card Card `xml:"card"` Available Amount `xml:"av_balance"` Balance Amount `xml:"balance"` FinLimit Amount `xml:"fin_limit"` TradeLimit Amount `xml:"trade_limit"` }
CardBalance is struct for mapping p24 card balance response. Represents balance of a p24 merchant card
func (CardBalance) MarshalXML ¶
func (cb CardBalance) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML implements xml.Marshaler interface for cb
func (*CardBalance) UnmarshalXML ¶
func (cb *CardBalance) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML implements xml.Unmarshaler interface for cb
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client performs p24 api calls with given Doer, Merchant, Logger. Implements p24 information API client. see: https://api.privatbank.ua/#p24/main
func NewClient ¶
func NewClient(opts ClientOpts) *Client
NewClient returns Client instance with given opts
func (*Client) DoContext ¶
func (c *Client) DoContext(ctx context.Context, url, method string, req Request, resp *Response) error
DoContext performs a p24 http api call with given url, method, request and unmarshal response body to resp if no errors occurred nolint:gocyclo // Is a complexity function
func (*Client) GetCardBalance ¶
func (c *Client) GetCardBalance(ctx context.Context, opts BalanceOpts) (CardBalance, error)
GetCardBalance returns CardBalance for given opts. Performs p24 card balance api call. see: https://api.privatbank.ua/#p24/balance
func (*Client) GetStatements ¶
func (c *Client) GetStatements(ctx context.Context, opts StatementsOpts) (Statements, error)
GetStatements returns Statements for given opts. Performs p24 orders api call. see: https://api.privatbank.ua/#p24/orders
type ClientOpts ¶
ClientOpts is a full set of all parameters to initialize Client
type CommonOpts ¶
CommonOpts store common request options used across all p24 requests
func DefaultCommonOpts ¶
func DefaultCommonOpts() CommonOpts
DefaultCommonOpts returns default CommonOpts
type Funds ¶
Funds represents p24 funds with special currency code and amount value. Funds string representation is "<amount> <currency>", <currency> can be empty string for example "23.12 UAH", "-12 USD", "0.0 "
func (Funds) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for funds
func (*Funds) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for funds
type LogFunc ¶
type LogFunc func(format string, args ...interface{})
LogFunc type is an adapter to allow the use of ordinary functions as Logger
type Logger ¶
type Logger interface {
Logf(format string, args ...interface{})
}
Logger defines minimal logger interface
type Merchant ¶
Merchant store p24 merchant id and password see: https://api.privatbank.ua/#p24/registration
func (Merchant) Sign ¶
func (m Merchant) Sign(data []byte) MerchantSign
Sign returns MerchantSign of provided data
func (Merchant) VerifySign ¶
func (m Merchant) VerifySign(data []byte, dataSign MerchantSign) error
VerifySign returns an error if dataSign not from merchant.Sign(data)
type MerchantSign ¶
MerchantSign store p24 merchant id and signature. It required for all p24 responses/requests
type Request ¶
type Request struct { XMLName xml.Name `xml:"request"` Version string `xml:"version,attr"` MerchantSign MerchantSign `xml:"merchant"` Data RequestData `xml:"data"` }
Request is struct for mapping p24 api request
func NewRequest ¶
func NewRequest(m Merchant, reqData RequestData) Request
NewRequest returns Request with MerchantSign of reqData
type RequestData ¶
type RequestData struct { XMLName xml.Name `xml:"data"` Payment struct { ID string `xml:"id,attr"` Prop []struct { Name string `xml:"name,attr"` Value string `xml:"value,attr"` } `xml:"prop"` } `xml:"payment"` CommonOpts }
RequestData is struct for mapping p24 request data
type Response ¶
type Response struct { Data ResponseData `xml:"data"` XMLName xml.Name `xml:"response"` MerchantSign MerchantSign `xml:"merchant"` Version string `xml:"version,attr"` }
Response is struct for mapping p24 api response
type ResponseData ¶
type ResponseData struct { Info interface{} `xml:"info"` XMLName xml.Name `xml:"data"` Oper string `xml:"oper"` }
ResponseData is struct for mapping p24 response data
func (*ResponseData) UnmarshalXML ¶
func (rd *ResponseData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML implement xml.Unmarshaler interface with decoding to 'Info interface{}' field. Info must be not zero value. nolint:gocyclo // UnmarshalXML is a complexity operation
type Statement ¶
type Statement struct { Card string `xml:"card,attr"` Appcode string `xml:"appcode,attr"` Date time.Time `xml:"-"` Terminal string `xml:"terminal,attr"` Description string `xml:"description,attr"` Amount Funds `xml:"amount,attr"` CardAmount Funds `xml:"cardamount,attr"` Rest Funds `xml:"rest,attr"` }
Statement represents a Statement of a p24 merchant
func (Statement) MarshalXML ¶
MarshalXML implements xml.Marshaler interface for s
func (*Statement) UnmarshalXML ¶
UnmarshalXML implements xml.Unmarshaler interface for s
type Statements ¶
type Statements struct { Status string `xml:"status,attr"` Statements []Statement `xml:"statement"` Credit Amount `xml:"credit,attr"` Debet Amount `xml:"debet,attr"` }
Statements struct for mapping p24 get statements response. Represents statements list of a p24 merchant
type StatementsOpts ¶
StatementsOpts is sets of options required for performs p24 statements request
func (StatementsOpts) Validate ¶
func (r StatementsOpts) Validate() error
Validate r for current date range and card number. P24 statements api provide date range with max 90 days