payment

package module
v0.0.0-...-8ae4905 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

README

Payment

Build Status Coverage Status Go Report Card

A microservices-demo service that provides payment services. This build is built, tested and released by travis.

Bugs, Feature Requests and Contributing

We'd love to see community contributions. We like to keep it simple and use Github issues to track bugs and feature requests and pull requests to manage contributions.

API Spec

Checkout the API Spec here

Build

Dependencies
cd $GOPATH/src/github.com/microservices-demo/payment/
go get -u github.com/FiloSottile/gvt
gvt restore
Using native Go tools

In order to build the project locally you need to make sure that the repository directory is located in the correct $GOPATH directory: $GOPATH/src/github.com/microservices-demo/payment/. Once that is in place you can build by running:

cd $GOPATH/src/github.com/microservices-demo/payment/paymentsvc/
go build -o payment

The result is a binary named payment, in the current directory.

Using Docker Compose

docker-compose build

Test

COMMIT=test make test

Run

Using Go native

If you followed to Go build instructions, you should have a "payment" binary in $GOPATH/src/github.com/microservices-demo/payment/cmd/paymentsvc/. To run it use:

./payment
ts=2016-12-14T11:48:58Z caller=main.go:29 transport=HTTP port=8080
Using Docker Compose

If you used Docker Compose to build the payment project, the result should be a Docker image called weaveworksdemos/payment. To run it use:

docker-compose up

You can now access the service via http://localhost:8082

Check

You can check the health of the service by doing a GET request to the health endpoint:

curl http://localhost:8082/health
{"health":[{"service":"payment","status":"OK","time":"2016-12-14 12:22:04.716316395 +0000 UTC"}]}

Use

You can authorise a payment by POSTing to the paymentAuth endpoint:

curl -H "Content-Type: application/json" -X POST -d'{"Amount":40}'  http://localhost:8082/paymentAuth
{"authorised":true}

Push

GROUP=weaveworksdemos COMMIT=test ./scripts/push.sh

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidJson = errors.New("Invalid json")
View Source
var ErrInvalidPaymentAmount = errors.New("Invalid payment amount")
View Source
var (
	HTTPLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "http_request_duration_seconds",
		Help:    "Time (in seconds) spent serving HTTP requests.",
		Buckets: prometheus.DefBuckets,
	}, []string{"method", "path", "status_code", "isWS"})
)

Functions

func MakeAuthoriseEndpoint

func MakeAuthoriseEndpoint(s Service) endpoint.Endpoint

MakeListEndpoint returns an endpoint via the given service.

func MakeHTTPHandler

func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer stdopentracing.Tracer) *mux.Router

MakeHTTPHandler mounts the endpoints into a REST-y HTTP handler.

func MakeHealthEndpoint

func MakeHealthEndpoint(s Service) endpoint.Endpoint

MakeHealthEndpoint returns current health of the given service.

func WireUp

func WireUp(ctx context.Context, declineAmount float32, tracer stdopentracing.Tracer, serviceName string) (http.Handler, log.Logger)

Types

type Authorisation

type Authorisation struct {
	Authorised bool   `json:"authorised"`
	Message    string `json:"message"`
}

type AuthoriseRequest

type AuthoriseRequest struct {
	Amount float32 `json:"amount"`
}

AuthoriseRequest represents a request for payment authorisation. The Amount is the total amount of the transaction

type AuthoriseResponse

type AuthoriseResponse struct {
	Authorisation Authorisation
	Err           error
}

AuthoriseResponse returns a response of type Authorisation and an error, Err.

type Endpoints

type Endpoints struct {
	AuthoriseEndpoint endpoint.Endpoint
	HealthEndpoint    endpoint.Endpoint
}

Endpoints collects the endpoints that comprise the Service.

func MakeEndpoints

func MakeEndpoints(s Service, tracer stdopentracing.Tracer) Endpoints

MakeEndpoints returns an Endpoints structure, where each endpoint is backed by the given service.

type Health

type Health struct {
	Service string `json:"service"`
	Status  string `json:"status"`
	Time    string `json:"time"`
}

type Middleware

type Middleware func(Service) Service

Middleware decorates a service.

func LoggingMiddleware

func LoggingMiddleware(logger log.Logger) Middleware

LoggingMiddleware logs method calls, parameters, results, and elapsed time.

type Service

type Service interface {
	Authorise(total float32) (Authorisation, error) // GET /paymentAuth
	Health() []Health                               // GET /health
}

func NewAuthorisationService

func NewAuthorisationService(declineOverAmount float32) Service

NewFixedService returns a simple implementation of the Service interface, fixed over a predefined set of socks and tags. In a real service you'd probably construct this with a database handle to your socks DB, etc.

type UnmarshalKeyError

type UnmarshalKeyError struct {
	Key  string
	JSON string
}

func (*UnmarshalKeyError) Error

func (e *UnmarshalKeyError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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