slip

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

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 5 Imported by: 0

README

go-slip

Go Package Library for e-Slip generator. MIT license. This package has dependency required WkHTML.

Purpose

This project use to reduce slip paper for any POS or web application and let's customer or user choose to get an e-receipt via scan on-screen QR code or shortlink URL. So customer will redirect to service web and display or download slip file in PNG format for any purpose.

How it's work

Mobile Client or Caller service make a RESTful API call for NewSlip() function and service return a Shorten-URL link for client to use for download or display a file

sequenceDiagram;
  participant Caller
  participant Service
  participant GCS
  Caller->>Service: Create Slip (json)
  Note over Service: Create slip file image
  Service->>GCS: Store image (png)
  GCS->>Service: Success
  Service->>Caller: Slip URL

How to test

  1. Create Google Cloud Storage - new Bucket such as "paybox_slip" as you see in "/slip/repository/gcs_test.go"

  2. Create your Google Cloud - Service Account and place in "$HOME/secret/" and rename as paybox_slip_key.json

  3. then just run...

go test -v ./...

or to test just some package.

go test -v ./repository

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEntity1NotFound = errors.New("domain1: entity1 not found")
)

domain1 errors

Functions

func NewHTTPTransport

func NewHTTPTransport(ep Endpoint) http.Handler

Types

type Body

type Body struct {
	ID          string  `json:"id"`
	Title       string  `json:"title"`
	DocDate     string  `json:"doc_date"`
	DocNumber   string  `json:"doc_number"`
	Ref         string  `json:"ref"`
	Total       float32 `json:"total"`
	ImageURL    string  `json:"image_url"`
	AccessToken string  `json:"access_token"`
	CreateDate  string  `json:"create_date"`
	Lines       []Line  `json:"lines"`
}

type CreateRequest

type CreateRequest struct {
	DocNumber   string `json:"doc_number"`
	RefNumber   string `json:"ref_number"`
	Title       string `json:"title"`
	DocDate     string `json:"doc_date"`
	SlipLines   []Line
	AccessToken string `json:"access_token"`
}

CreateRequest is the request for create endpoint

type CreateResponse

type CreateResponse struct {
	ID  string `json:"id"`
	URL string `json:"url"`
}

CreateResponse is the response for create endpoint

type Database

type Database interface {
	// Registers inserts given Entity1 into storage
	Insert(ctx context.Context, b *Body) (id string, err error)
	// SetField3 sets field3 for Entity1
	FindByID(ctx context.Context, id string) (*Body, error)
}

Database is the slip database interface

type Endpoint

type Endpoint interface {
	Create(context.Context, *CreateRequest) (*CreateResponse, error)
	FindByID(context.Context, *FindByIDRequest) (*FindByIDResponse, error)
}

Endpoint is the slip endpoint

type FindByIDRequest

type FindByIDRequest struct {
	ID string `json:"id"`
}

FindRequest is the request for find endpoint

type FindByIDResponse

type FindByIDResponse struct {
	URL string `json:"id"`
}

FindByIDRespose is the response for find by id endpoint

type Line

type Line struct {
	Seq   int8    `json:"seq"`
	SKU   string  `json:"sku"`
	Name  string  `json:"name"`
	Qty   float32 `json:"qty"`
	Price float32 `json:"price"`
	Note  string  `json:"note"`
}

type Render

type Render interface {
	// HtmlToSlipJPG function create jpeg file image from -> input HTML string
	// -> slip width in pixel
	// -> input file format JPG or PNG
	HtmlToSlipJPG(html string, width int, format string) ([]byte, error)
}

type Service

type Service interface {
	Create(ctx context.Context, b *Body) (id string, url string, err error)
	FindByID(ctx context.Context, id string) (*Body, error)
}

type Storage

type Storage interface {
	StoreFile(ctx context.Context, fileName, objectName string) (url string, err error)
	StoreByte(ctx context.Context, b []byte, objectName string) (url string, err error)
	StoreOriginPNG(ctx context.Context, m image.Image, folderName string) (url string, err error)
	RemoveFile(ctx context.Context, objectName string) error
}

Storage is the slip storage interface for save image file

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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