petra

package module
v0.0.0-...-9250373 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 11 Imported by: 0

README

petra-go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Message        string        `json:"message,omitempty"`
	HTTPStatusCode int           `json:"code,omitempty"`
	Details        ErrorResponse `json:"details,omitempty"`
	URL            *url.URL      `json:"url,omitempty"`
	Header         http.Header   `json:"header,omitempty"`
}

func (*APIError) Error

func (aerr *APIError) Error() string

APIError supports the error interface

type Client

type Client struct {

	// Services supported by the Petra API.
	// Miscellaneous actions are directly implemented on the Client object
	Customer       *CustomerService
	Transaction    *TransactionService
	Page           *PageService
	Invoice        *InvoiceService
	LoggingEnabled bool
	Log            Logger
	// contains filtered or unexported fields
}

Client manages communication with the Petra API

func NewClient

func NewClient(key string, httpClient *http.Client) *Client

NewClient creates a new Petra API client with the given API key and HTTP client, allowing overriding of the HTTP client to use. This is useful if you're running in a Google AppEngine environment where the http.DefaultClient is not available.

func (*Client) Call

func (c *Client) Call(method, path string, body, v interface{}) error

Call actually does the HTTP request to Petra API

type CreateTransactionRequest

type CreateTransactionRequest struct {
	Amount float32 `json:"amount,omitempty"`
	Email  string  `json:"email,omitempty"`
	Type   string  `json:"type,omitempty"`
}

type Customer

type Customer struct {
	ID           int      `json:"id,omitempty"`
	CreatedAt    string   `json:"createdAt,omitempty"`
	UpdatedAt    string   `json:"updatedAt,omitempty"`
	Domain       string   `json:"domain,omitempty"`
	Integration  int      `json:"integration,omitempty"`
	FirstName    string   `json:"first_name,omitempty"`
	LastName     string   `json:"last_name,omitempty"`
	Email        string   `json:"email,omitempty"`
	Phone        string   `json:"phone,omitempty"`
	Metadata     Metadata `json:"metadata,omitempty"`
	CustomerCode string   `json:"customer_code,omitempty"`
}

type CustomerList

type CustomerList struct {
	Meta   ListMeta
	Values []Customer `json:"data"`
}

type CustomerService

type CustomerService service

func (*CustomerService) Create

func (s *CustomerService) Create(customer *Customer) (*Customer, error)

func (*CustomerService) Get

func (s *CustomerService) Get(customerCode string) (*Customer, error)

func (*CustomerService) List

func (s *CustomerService) List() (*CustomerList, error)

func (*CustomerService) ListN

func (s *CustomerService) ListN(count, offset int) (*CustomerList, error)

func (*CustomerService) Update

func (s *CustomerService) Update(customer *Customer) (*Customer, error)

type ErrorResponse

type ErrorResponse struct {
	Status  bool                   `json:"status,omitempty"`
	Message string                 `json:"message,omitempty"`
	Errors  map[string]interface{} `json:"errors,omitempty"`
}

ErrorResponse represents an error response from the Petra API server

type Invoice

type Invoice struct {
	ID          int    `json:"id:,omitempty"`
	CreatedAt   string `json:"createdAt,omitempty"`
	UpdatedAt   string `json:"updatedAt,omitempty"`
	Domain      string `json:"domain,omitempty"`
	Integration int    `json:"integration,omitempty"`
	Email       string `json:"email,omitempty"`
}

type InvoiceList

type InvoiceList struct {
	Meta   ListMeta
	Values []Invoice `json:"data"`
}

type InvoiceService

type InvoiceService service

func (*InvoiceService) Create

func (s *InvoiceService) Create(invoice *Invoice) (*Invoice, error)

func (*InvoiceService) Get

func (s *InvoiceService) Get(id string) (*Invoice, error)

func (*InvoiceService) List

func (s *InvoiceService) List() (*InvoiceList, error)

func (*InvoiceService) ListN

func (s *InvoiceService) ListN(count, offset int) (*InvoiceList, error)

func (*InvoiceService) Update

func (s *InvoiceService) Update(customer *Invoice) (*Invoice, error)

type ListMeta

type ListMeta struct {
	Total     int `json:"total"`
	Skipped   int `json:"skipped"`
	PerPage   int `json:"perPage"`
	Page      int `json:"page"`
	PageCount int `json:"pageCount"`
}

ListMeta is pagination metadata for paginated responses from the Petra API

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger interface for custom loggers

type Metadata

type Metadata map[string]interface{}

Metadata is an key-value pairs added to Petra API requests

type Page

type Page struct {
	ID           int                 `json:"id,omitempty"`
	CreatedAt    string              `json:"createdAt,omitempty"`
	UpdatedAt    string              `json:"updatedAt,omitempty"`
	Domain       string              `json:"domain,omitempty"`
	Integration  int                 `json:"integration,omitempty"`
	Name         string              `json:"name,omitempty"`
	Slug         string              `json:"slug,omitempty"`
	Description  string              `json:"description,omitempty"`
	Amount       float32             `json:"amount,omitempty"`
	Currency     string              `json:"currency,omitempty"`
	Active       bool                `json:"active,omitempty"`
	RedirectURL  string              `json:"redirect_url,omitempty"`
	CustomFields []map[string]string `json:"custom_fields,omitempty"`
}

type PageList

type PageList struct {
	Meta   ListMeta
	Values []Page `json:"data,omitempty"`
}

PageList is a list object for pages.

type PageService

type PageService service

func (*PageService) Create

func (s *PageService) Create(page *Page) (*Page, error)

func (*PageService) Get

func (s *PageService) Get(id int) (*Page, error)

func (*PageService) List

func (s *PageService) List() (*PageList, error)

func (*PageService) ListN

func (s *PageService) ListN(count, offset int) (*PageList, error)

func (*PageService) Update

func (s *PageService) Update(page *Page) (*Page, error)

type RequestValues

type RequestValues url.Values

RequestValues aliased to url.Values as a workaround

func (RequestValues) MarshalJSON

func (v RequestValues) MarshalJSON() ([]byte, error)

MarshalJSON to handle custom JSON decoding for RequestValues

type Response

type Response map[string]interface{}

Response represents arbitrary response data

type Transaction

type Transaction struct {
	ID              int                    `json:"id,omitempty"`
	CreatedAt       string                 `json:"createdAt,omitempty"`
	Domain          string                 `json:"domain,omitempty"`
	Metadata        string                 `json:"metadata,omitempty"` //TODO: why is transaction metadata a string?
	Status          string                 `json:"status,omitempty"`
	Reference       string                 `json:"reference,omitempty"`
	Amount          float32                `json:"amount,omitempty"`
	Message         string                 `json:"message,omitempty"`
	GatewayResponse string                 `json:"gateway_response,omitempty"`
	PaidAt          string                 `json:"piad_at,omitempty"`
	Channel         string                 `json:"channel,omitempty"`
	Currency        string                 `json:"currency,omitempty"`
	IPAddress       string                 `json:"ip_address,omitempty"`
	Log             map[string]interface{} `json:"log,omitempty"` // TODO: same as timeline?
	Fees            int                    `json:"int,omitempty"`
	FeesSplit       string                 `json:"fees_split,omitempty"` // TODO: confirm data type
	Customer        Customer               `json:"customer,omitempty"`
}

type TransactionList

type TransactionList struct {
	Meta   ListMeta
	Values []Transaction `json:"data"`
}

type TransactionService

type TransactionService service

func (*TransactionService) Get

func (s *TransactionService) Get(id int) (*Transaction, error)

func (*TransactionService) Initialize

func (*TransactionService) List

func (*TransactionService) ListN

func (s *TransactionService) ListN(count, offset int) (*TransactionList, error)

func (*TransactionService) Verify

func (s *TransactionService) Verify(reference string) (*Transaction, error)

Jump to

Keyboard shortcuts

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