payments

package
v0.0.0-...-84d4e1c Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MIT-0 Imports: 9 Imported by: 0

Documentation

Overview

payments contains the http routes that perform CRUD operations on payments

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Links map[string]string

A simple type to add restful links to our responses

type Payment

type Payment struct {
	Id           string            `json:"id"`
	Type         string            `json:"type"`
	Version      int               `json:"version"`
	Organisation string            `json:"organisation_id"`
	Attributes   PaymentAttributes `json:"attributes"`
}

Payment a payment

func NewPaymentFromRepoItem

func NewPaymentFromRepoItem(item *RepoItem) (*Payment, error)

Converts a repo item into a payment

func NewPaymentsFromRepoItems

func NewPaymentsFromRepoItems(items []*RepoItem) ([]*Payment, error)

PaymentsFromRepoItems converts the given slice of repo items to a list of payments

func (*Payment) ToRepoItem

func (p *Payment) ToRepoItem() (*RepoItem, error)

Converts a payment into something that can be saved into the database

func (*Payment) Validate

func (p *Payment) Validate() error

Validate does semantic validation on the payment

type PaymentAttributes

type PaymentAttributes struct {
	Amount string `json:"amount"`
}

Payment attributes captures all detaled information about a payment. Here we are only capturing the Amount, for convenience, and we're leaving out the rest.

func (*PaymentAttributes) Validate

func (pa *PaymentAttributes) Validate() error

Validate does semantic validation on the payment attributes

type PaymentRequest

type PaymentRequest struct {
	Payment *Payment `json:"data"`
}

PaymentRequest represents a http request that contains a payment in its field 'data'

type PaymentResponse

type PaymentResponse struct {
	Data  *Payment `json:"data"`
	Links Links    `json:"links"`
}

PaymentResponse represents a http response that contains a payment in its field 'data' and set of links

type PaymentsResponse

type PaymentsResponse struct {
	Data  []*Payment `json:"data"`
	Links Links      `json:"links"`
}

PaymentsResponse represents a http response that contains a list of payments in its field 'data' and a set of links

type PaymentsService

type PaymentsService struct {
	HttpService
	// contains filtered or unexported fields
}

PaymentsService represents a payments service it defines the routes and the repo to operate with. It inherits fields and functions from util.HttpService

func New

func New(repo Repo, baseUrl string, maxResults int) *PaymentsService

New creates a new PaymentsService with the given repo, base url and maxResults information

func (*PaymentsService) Create

func (s *PaymentsService) Create(w http.ResponseWriter, r *http.Request)

Create a new payment

func (*PaymentsService) Delete

func (s *PaymentsService) Delete(w http.ResponseWriter, r *http.Request)

Delete a payment by id

func (*PaymentsService) Fetch

Fetch a payment by id

func (*PaymentsService) List

List returns a list of payments. We return finite lists of payments so we need to check the from and to query params, and make sure they make sense. If they are not set, we fallback to defaults.

func (*PaymentsService) Routes

func (s *PaymentsService) Routes() *chi.Mux

Routes returns a router with all routes supported by this service

func (*PaymentsService) Update

func (s *PaymentsService) Update(w http.ResponseWriter, r *http.Request)

Update an existing payment

Jump to

Keyboard shortcuts

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