qiwi

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2017 License: MIT Imports: 12 Imported by: 2

README

Qiwi GoDoc

An golang qiwi.com api client

Qiwi.com - CIS and Russian Payment system and this package relevant for Russian-speaking users. All the following documentation will be in Russian.

Чтобы получить токен доступа, перейдите по ссылке

Установка

go get -u github.com/zhuharev/qiwi

Использование

token = "YOUR_TOKEN"
qw := qiwi.New(token)

// get last 10 payments
resp, err := qw.History.Payments(10)
if err != nil {
  // handle error
}
log.Printf("%v", resp)

Documentation

Index

Constants

View Source
const (
	// BaseURL represent base url
	BaseURL = "https://edge.qiwi.com"
	// OpenBaseURL open base url
	OpenBaseURL = "https://qiwi.com"
	// VersionAPI current qiwi.com api version
	VersionAPI = "v1"

	// CurrencyRUB rub id
	CurrencyRUB = "643"
)
View Source
const (
	// EndpointProfile endpoint
	EndpointProfile = "person-profile/v1/profile/current"
	// EndpointIdent identification endpoint
	EndpointIdent = "identification/v1/persons/%s/identification" // %s - wallet
	// EndpointPaymentsHistory get history
	EndpointPaymentsHistory = "payment-history/v1/persons/%s/payments" // %s - wallet
	// EndpointStat get stat of payments
	EndpointStat = "payment-history/v1/persons/%s/payments/total" // %s - wallet
	// EndpointTxnInfo get info anout single txn
	EndpointTxnInfo = "payment-history/v1/transactions/%s" // %s - txn_id
	// EndpointBalance get wallet balance
	EndpointBalance = "funding-sources/v1/accounts/current"
	// EndpointCardsDetect detect code of PS
	EndpointCardsDetect = "card/detect.action"
	// EndpointCardsPayment send money from wallet
	EndpointCardsPayment = "sinap/api/v2/terms/%d/payments"
	// EndpointComission a provider comission
	EndpointComission = "sinap/providers/%d/form"
	// EndpointSpecialComission comission for specific amount
	EndpointSpecialComission = "sinap/providers/%d/onlineCommission"
)

Variables

View Source
var (
	// ErrSyntaxError error with bad request
	ErrSyntaxError = fmt.Errorf("Ошибка синтаксиса запроса (неправильный формат данных)")
	// ErrTokenInvalid error
	ErrTokenInvalid = fmt.Errorf("Неверный токен или истек срок действия токена")
	// ErrNotFound error
	ErrNotFound = fmt.Errorf("Не найден кошелёк, транзакция или отсутствуют платежи с указанными признаками")
	// ErrRateLimitReached error
	ErrRateLimitReached = fmt.Errorf("Слишком много запросов, сервис временно недоступен")
)
View Source
var (
	// OpenMethods not require Bearer token
	OpenMethods = map[string]bool{
		EndpointCardsDetect: true,
	}
)

Functions

func Debug

func Debug(c *Client)

Debug enable debug

func Wallet

func Wallet(wallet string) func(c *Client)

Wallet set wallet to client example: qw := qiwi.New(token, qiwi.Wallet("70000000000"))

Types

type Balance

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

Balance for payment-history endpoints

func NewBalance

func NewBalance(c *Client) *Balance

NewBalance returns new Balance obj

func (*Balance) Current

func (b *Balance) Current() (hr BalanceResponse, err error)

Current call api and get current user balance

type BalanceResponse

type BalanceResponse struct {
	Accounts []struct {
		Alias   string `json:"alias"`
		FsAlias string `json:"fsAlias"`
		Title   string `json:"title"`
		Type    struct {
			ID    string `json:"id"`
			Title string `json:"title"`
		} `json:"type"`
		HasBalance bool `json:"hasBalance"`
		Balance    struct {
			Amount   float64 `json:"amount"`
			Currency int     `json:"currency"`
		} `json:"balance"`
		Currency int `json:"currency"`
	} `json:"accounts"`
}

BalanceResponse response of balance request

type Cards

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

Cards for payment-history endpoints

func NewCards

func NewCards(c *Client) *Cards

NewCards returns new Cards obj

func (*Cards) Detect

func (c *Cards) Detect(cardNumber string) (id int, err error)

Detect detect card PS

func (*Cards) Payment

func (c *Cards) Payment(psID int, amount float64, cardNumber string, comments ...string) (res PaymentResponse, err error)

Payment make mayment

type CardsDetectResponse

type CardsDetectResponse struct {
	Code struct {
		Value json.Number `json:"value"`
		Name  string      `json:"_name"`
	} `json:"code"`
	Message json.Number `json:"message"`
}

CardsDetectResponse api response

type Client

type Client struct {
	Payments *Payments
	Profile  *Profile
	Balance  *Balance
	Cards    *Cards
	// contains filtered or unexported fields
}

Client main struct

func New

func New(token string, opts ...Opt) *Client

New returns client

func (*Client) SetWallet

func (c *Client) SetWallet(wallet string)

SetWallet set wallet for client

type ComissionResponse added in v0.0.2

type ComissionResponse struct {
	Content struct {
		Terms struct {
			Commission struct {
				Ranges []struct {
					Bound float64 `json:"bound"`
					Fixed float64 `json:"fixed"`
					Rate  float64 `json:"rate"`
					Min   float64 `json:"min"`
					Max   float64 `json:"max"`
				} `json:"ranges"`
			} `json:"commission"`
		} `json:"terms"`
	} `json:"content"`
}

ComissionResponse json unserialazer

type Opt

type Opt func(c *Client)

Opt returns func for changing client used for New

type PaymentRequest

type PaymentRequest struct {
	ID  string `json:"id"`
	Sum struct {
		Amount   float64 `json:"amount"`
		Currency string  `json:"currency"`
	} `json:"sum"`
	PaymentMethod struct {
		Type      string `json:"type"`
		AccountID string `json:"accountId"`
	} `json:"paymentMethod"`
	Fields struct {
		Account string `json:"account"`
	} `json:"fields"`
	// Qiwi to qiwi related field
	Comment string `json:"comment,omitempty"`
}

PaymentRequest request of payment

type PaymentResponse

type PaymentResponse struct {
	ID     string `json:"id"`
	Terms  string `json:"terms"`
	Fields struct {
		Account string `json:"account"`
	} `json:"fields"`
	Sum struct {
		Amount   float64 `json:"amount"`
		Currency string  `json:"currency"`
	} `json:"sum"`
	Source      string `json:"source"`
	Transaction struct {
		ID    string `json:"id"`
		State struct {
			Code string `json:"code"`
		} `json:"state"`
	} `json:"transaction"`
	// Qiwi to qiwi related field
	Comment string `json:"comment,omitempty"`
}

PaymentResponse foemat of payment response

type Payments added in v0.0.2

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

Payments for payment-history endpoints

func NewPayments added in v0.0.2

func NewPayments(c *Client) *Payments

NewPayments returns new Payments obj

func (*Payments) Comission added in v0.0.2

func (p *Payments) Comission(providerID int) (res ComissionResponse, err error)

Comission get provider comission

func (*Payments) History added in v0.0.2

func (p *Payments) History(rows uint, params ...url.Values) (pr PaymentsResponse, err error)

History call api and get payments history

func (*Payments) SpecialComission added in v0.0.2

func (p *Payments) SpecialComission(providerID int, to string, amount float64) (res SpecialComissionResponse, err error)

SpecialComission get provider comission

func (*Payments) Stat added in v0.0.2

func (p *Payments) Stat(startDate, endDate time.Time, params ...url.Values) (res StatResponse, err error)

Stat get sum of incoming and outgoing payments

type PaymentsResponse

type PaymentsResponse struct {
	Data        []Txn       `json:"data"`
	NextTxnID   interface{} `json:"nextTxnId"`
	NextTxnDate interface{} `json:"nextTxnDate"`
}

PaymentsResponse api response format

type Profile

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

Profile for profile endpoints

func NewProfile

func NewProfile(c *Client) *Profile

NewProfile returns new Profile obj

func (*Profile) Current

func (h *Profile) Current() (pr ProfileResponse, err error)

Current call api and get current user profile

type ProfileResponse

type ProfileResponse struct {
	AuthInfo struct {
		BoundEmail    string    `json:"boundEmail"`
		IP            string    `json:"ip"`
		LastLoginDate time.Time `json:"lastLoginDate"`
		MobilePinInfo struct {
			LastMobilePinChange time.Time `json:"lastMobilePinChange"`
			MobilePinUsed       bool      `json:"mobilePinUsed"`
			NextMobilePinChange time.Time `json:"nextMobilePinChange"`
		} `json:"mobilePinInfo"`
		PassInfo struct {
			LastPassChange time.Time `json:"lastPassChange"`
			NextPassChange time.Time `json:"nextPassChange"`
			PasswordUsed   bool      `json:"passwordUsed"`
		} `json:"passInfo"`
		PersonID int64 `json:"personId"`
		PinInfo  struct {
			PinUsed bool `json:"pinUsed"`
		} `json:"pinInfo"`
		RegistrationDate time.Time `json:"registrationDate"`
	} `json:"authInfo"`
	ContractInfo struct {
		Blocked            bool          `json:"blocked"`
		ContractID         int64         `json:"contractId"`
		CreationDate       time.Time     `json:"creationDate"`
		Features           []interface{} `json:"features"`
		IdentificationInfo []struct {
			BankAlias           string `json:"bankAlias"`
			IdentificationLevel string `json:"identificationLevel"`
		} `json:"identificationInfo"`
	} `json:"contractInfo"`
	UserInfo struct {
		DefaultPayCurrency int         `json:"defaultPayCurrency"`
		DefaultPaySource   int         `json:"defaultPaySource"`
		Email              interface{} `json:"email"`
		FirstTxnID         int64       `json:"firstTxnId"`
		Language           string      `json:"language"`
		Operator           string      `json:"operator"`
		PhoneHash          string      `json:"phoneHash"`
		PromoEnabled       interface{} `json:"promoEnabled"`
	} `json:"userInfo"`
}

ProfileResponse reponse

type SpecialComissionRequest added in v0.0.2

type SpecialComissionRequest struct {
	Account       string `json:"account"`
	PaymentMethod struct {
		Type      string `json:"type"`
		AccountID string `json:"accountId"`
	} `json:"paymentMethod"`
	PurchaseTotals struct {
		Total struct {
			Amount   float64 `json:"amount"`
			Currency string  `json:"currency"`
		} `json:"total"`
	} `json:"purchaseTotals"`
}

SpecialComissionRequest json serializer

type SpecialComissionResponse added in v0.0.2

type SpecialComissionResponse struct {
	ProviderID  int `json:"providerId"`
	WithdrawSum struct {
		Amount   float64 `json:"amount"`
		Currency string  `json:"currency"`
	} `json:"withdrawSum"`
	EnrollmentSum struct {
		Amount   float64 `json:"amount"`
		Currency string  `json:"currency"`
	} `json:"enrollmentSum"`
	QwCommission struct {
		Amount   float64 `json:"amount"`
		Currency string  `json:"currency"`
	} `json:"qwCommission"`
	FundingSourceCommission struct {
		Amount   float64 `json:"amount"`
		Currency string  `json:"currency"`
	} `json:"fundingSourceCommission"`
	WithdrawToEnrollmentRate float64 `json:"withdrawToEnrollmentRate"`
}

SpecialComissionResponse json unserialazer

type StatResponse

type StatResponse struct {
	IncomingTotal []struct {
		Amount   float64 `json:"amount"`
		Currency int     `json:"currency"`
	} `json:"incomingTotal"`
	OutgoingTotal []struct {
		Amount   float64 `json:"amount"`
		Currency int     `json:"currency"`
	} `json:"outgoingTotal"`
}

StatResponse response of stat endpoind

type Txn

type Txn struct {
	TxnID      int64     `json:"txnId"`
	PersonID   int64     `json:"personId"`
	Date       time.Time `json:"date"`
	ErrorCode  int       `json:"errorCode"`
	Error      string    `json:"error"`
	Status     string    `json:"status"`
	Type       string    `json:"type"`
	StatusText string    `json:"statusText"`
	TrmTxnID   string    `json:"trmTxnId"`
	Account    string    `json:"account"`
	Sum        struct {
		Amount   float64 `json:"amount"`
		Currency int     `json:"currency"`
	} `json:"sum"`
	Commission struct {
		Amount   float64 `json:"amount"`
		Currency int     `json:"currency"`
	} `json:"commission"`
	Total struct {
		Amount   float64 `json:"amount"`
		Currency int     `json:"currency"`
	} `json:"total"`
	Provider struct {
		ID          int           `json:"id"`
		ShortName   string        `json:"shortName"`
		LongName    string        `json:"longName"`
		LogoURL     string        `json:"logoUrl"`
		Description string        `json:"description"`
		Keys        string        `json:"keys"`
		SiteURL     string        `json:"siteUrl"`
		Extras      []interface{} `json:"extras"`
	} `json:"provider"`
	Source                 interface{}   `json:"source"`
	Comment                string        `json:"comment"`
	CurrencyRate           int           `json:"currencyRate"`
	Extras                 []interface{} `json:"extras"`
	ChequeReady            bool          `json:"chequeReady"`
	BankDocumentAvailable  bool          `json:"bankDocumentAvailable"`
	BankDocumentReady      bool          `json:"bankDocumentReady"`
	RepeatPaymentEnabled   bool          `json:"repeatPaymentEnabled"`
	FavoritePaymentEnabled bool          `json:"favoritePaymentEnabled"`
	RegularPaymentEnabled  bool          `json:"regularPaymentEnabled"`
}

Txn represent qiwi transaction

Jump to

Keyboard shortcuts

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