qvapay

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 16 Imported by: 0

README

qvapay-go

A simple non-official paymentClient for qvapay service with go, for our comunity

Setup

You can install this package by using the go get tool and installing:

go get github.com/kenriortega/qvapay-go

Sign up on QvaPay

Create your account to process payments through QvaPay at qvapay.com/register.

Using the paymentClient

First create your QvaPay paymentClient using your app credentials.

paymentClient := qvapaygo.NewClient(
    os.Getenv("APP_ID"), // app_id
    os.Getenv("SECRET_ID"), // secret_id
    qvapaygo.BaseURL, // constants url base https://qvapay.com/api
    false, // skip verificationSSL
    nil, // custom http.PaymentAppClient
    nil, // debug io.Writter (os.Stdout)
)

Get your app info
...
info, err := paymentClient.GetInfo(context.Background())
if err != nil {
    log.Fatalf(err.Error())
}
fmt.Println(info)

Get your account balance
...
balance, err := paymentClient.GetBalance(context.Background())
if err != nil {
    log.Fatalf(err.Error())
}
fmt.Println(balance)

Create an invoice
...
invoice, err := paymentClient.CreateInvoice(
    context.Background(),
    25.60,
    "Enanitos verdes",
    "BRID56568989",
)
if err != nil {
    log.Fatalf(err.Error())
}
fmt.Println(invoice)
Get transaction
...
inputId := "6507ee0d-db6c-4aa9-b59a-75dc7f6eab52"
tx, err := paymentClient.GetTransaction(context.Background(), inputId)
if err != nil {
    log.Fatalf(err.Error())
}
fmt.Println(tx)
Get transactions
...
txs, err := paymentClient.GetTransactions(context.Background())
if err != nil {
    log.Fatalf(err.Error())
}
fmt.Println(txs)

You can also read the QvaPay API documentation: qvapay.com/docs. ​

Documentation

Overview

Package qvapay is the no-official qvapay apps SDK for Go.
Use it to interact with the Qvapay API.

Examples can be found at
https://github.com/kenriortega/qvapay-go/tree/main/examples
If you find an issue with the SDK, please report through
https://github.com/kenriortega/qvapay-go/issues/new

https://documenter.getpostman.com/view/8765260/TzzHnDGw#55629b48-821c-49cf-af14-ce76cfe0d65f

Index

Constants

View Source
const (
	ApiVersion = "v1"
	BaseURL    = "https://qvapay.com/api"
)
View Source
const (
	RouteInfo    = "info"
	RouteInvoice = "create_invoice"
	RouteTxs     = "transactions"
	RouteTx      = "transaction"
	RouteBalance = "balance"
)

Variables

This section is empty.

Functions

func DrainBody added in v0.2.0

func DrainBody(respBody io.ReadCloser)

func HandleAPIErrorResponse added in v0.3.0

func HandleAPIErrorResponse(response string) error

func ParseUrlQueryParams added in v0.3.0

func ParseUrlQueryParams(query QueryParams, requestUrl *url.URL)

ParseUrlQueryParams ...

Types

type APIError added in v0.3.0

type APIError struct {
	ErrorMessage interface{} `json:"error"`
}

APIError is used to describe errors from the API. See https://docs.blockfrost.io/#section/Errors

func (*APIError) Error added in v0.3.0

func (e *APIError) Error() string

type APIQueryParams

type APIQueryParams struct {
	Page int
}

type App

type App struct {
	UserID   int    `json:"user_id,omitempty"`
	Name     string `json:"name,omitempty"`
	URL      string `json:"url,omitempty"`
	Desc     string `json:"desc,omitempty"`
	Callback string `json:"callback,omitempty"`
	Uuid     string `json:"uuid,omitempty"`
	Active   int    `json:"active,omitempty"`
	Enabled  int    `json:"enabled,omitempty"`
}

App object

type AppInfoResponse

type AppInfoResponse struct {
	UserID   int    `json:"user_id,omitempty"`
	Name     string `json:"name,omitempty"`
	URL      string `json:"url,omitempty"`
	Desc     string `json:"desc,omitempty"`
	Callback string `json:"callback,omitempty"`
	Uuid     string `json:"uuid,omitempty"`
	Active   int    `json:"active,omitempty"`
	Enabled  int    `json:"enabled,omitempty"`
	Secret   string `json:"secret,omitempty"`
}

AppInfoResponse it`s an object that show general datail about your app

func (*AppInfoResponse) ToJSON added in v0.2.0

func (ai *AppInfoResponse) ToJSON() string

ToJSON ...

type IQvaPay added in v0.3.0

type IQvaPay interface {
	// GetInfo returns the corresponding object info on fetch call, or an error.
	GetInfo(ctx context.Context) (*AppInfoResponse, error)
	// CreateInvoice ...
	CreateInvoice(
		ctx context.Context,
		amount float64,
		description string,
		remoteID string,
	) (*InvoiceResponse, error)
	// GetTransactions ...
	GetTransactions(ctx context.Context, query APIQueryParams) (*TransactionsResponse, error)
	// GetTransaction ...
	GetTransaction(ctx context.Context, id string) (*TransactionReponse, error)
	// GetBalance ...
	GetBalance(ctx context.Context) (float64, error)

	// Offers ...
	Offers(ctx context.Context, query QueryParams) (map[string]any, error)
}

func QvaPayFactory added in v0.3.0

func QvaPayFactory(apiType string, opts Options) (IQvaPay, error)

QvaPayFactory it`s a constructor factory method

type InvoiceResponse

type InvoiceResponse struct {
	AppID           string `json:"app_id,omitempty"`
	Amount          string `json:"amount,omitempty"`
	Desciption      string `json:"desciption,omitempty"`
	RemoteID        string `json:"remote_id,omitempty"`
	Signed          string `json:"signed,omitempty"`
	TransactionUUID string `json:"transation_uuid,omitempty"` // report typo miss c (transaction_uuid)
	URL             string `json:"url,omitempty"`
	SignedUrl       string `json:"signedUrl,omitempty"`
}

InvoiceResponse object

func (*InvoiceResponse) ToJSON added in v0.2.0

func (i *InvoiceResponse) ToJSON() string

type Options added in v0.3.0

type Options struct {
	//  API's base url
	BaseURL string
	//optional, defaults to http.DefaultClient
	HttpClient *http.Client
	//optional for debuging
	Debug io.Writer
	// App endpoints
	AppID      string
	SecretID   string
	SkipVerify bool
}

type Owner

type Owner struct {
	ID       string `json:"uuid,omitempty"`
	Username string `json:"username,omitempty"`
	Name     string `json:"name,omitempty"`
	Lastname string `json:"lastname,omitempty"`
}

Owner object

type PaymentAppClient added in v0.3.0

type PaymentAppClient interface {
	IQvaPay
}

PaymentAppClient is an interface that implements https://qvapay.com/api

func NewPaymentAppClient added in v0.3.0

func NewPaymentAppClient(
	opts Options,
) PaymentAppClient

type QueryParams added in v0.3.0

type QueryParams struct {
	Page int
}

QueryParams ...

type QvaClient added in v0.3.0

type QvaClient interface {
	IQvaPay
}

QvaClient is an interface that implements some method for Qvapay

func NewQvaPay added in v0.3.0

func NewQvaPay(
	opts Options,
) QvaClient

NewQvaPay constructor

type TransPortAuthBasic added in v0.3.0

type TransPortAuthBasic struct {
	Transport http.RoundTripper
	Token     string
}

func (TransPortAuthBasic) RoundTrip added in v0.3.0

func (t TransPortAuthBasic) RoundTrip(r *http.Request) (*http.Response, error)

type Transaction

type Transaction struct {
	ID           string `json:"uuid,omitempty"`
	UserID       int    `json:"user_id,omitempty"`
	AppID        int    `json:"app_id,omitempty"`
	Amount       string `json:"amount,omitempty"`
	Description  string `json:"description,omitempty"`
	RemoteID     string `json:"remote_id,omitempty"`
	Status       string `json:"status,omitempty"`
	PaidByUserID int    `json:"paid_by_user_id,omitempty"`
	Signed       int    `json:"signed,omitempty"`
	CreatedAt    string `json:"created_at,omitempty"`
	UpdatedAt    string `json:"updated_at,omitempty"`
}

Transaction object

type TransactionPaidBy

type TransactionPaidBy struct {
	Name string `json:"name,omitempty"`
}

TransactionPaidBy object

type TransactionReponse

type TransactionReponse struct {
	ID                string `json:"uuid,omitempty"`
	UserID            int    `json:"user_id,omitempty"`
	AppID             int    `json:"app_id,omitempty"`
	Amount            string `json:"amount,omitempty"`
	Description       string `json:"description,omitempty"`
	RemoteID          string `json:"remote_id,omitempty"`
	Status            string `json:"status,omitempty"`
	PaidByUserID      int    `json:"paid_by_user_id,omitempty"`
	Signed            int    `json:"signed,omitempty"`
	CreatedAt         string `json:"created_at,omitempty"`
	UpdatedAt         string `json:"updated_at,omitempty"`
	TransactionPaidBy `json:"paid_by,omitempty"`
	App               `json:"app,omitempty"`
	Owner             `json:"owner,omitempty"`
}

TransactionReponse object

func (*TransactionReponse) ToJSON added in v0.2.0

func (tx *TransactionReponse) ToJSON() string

type TransactionsResponse

type TransactionsResponse struct {
	CurrentPage  int           `json:"current_page,omitempty"`
	Data         []Transaction `json:"data,omitempty"`
	FristPageURL string        `json:"frist_page_url,omitempty"`
	From         int           `json:"from,omitempty"`
	LastPage     int           `json:"last_page,omitempty"`
	LastPageURL  string        `json:"last_page_url,omitempty"`
	NextPageURL  string        `json:"next_page_url,omitempty"`
	Path         string        `json:"path,omitempty"`
	PerPage      int           `json:"per_page,omitempty"`
	PrevPageURL  string        `json:"prev_page_url,omitempty"`
	To           int           `json:"to,omitempty"`
	Total        int           `json:"total,omitempty"`
}

TransactionsResponse reposnses

func (*TransactionsResponse) ToJSON added in v0.2.0

func (txs *TransactionsResponse) ToJSON() string

Directories

Path Synopsis
examples
p2p
txs

Jump to

Keyboard shortcuts

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