plutus

package module
v0.0.0-...-794a79b Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: MIT Imports: 9 Imported by: 0

README

Plutus

Plutus is a modern tool to manage your payments, charges and invoices of your products. This tool is payment gateway agnostic and works like a new layer on your traditional payment stack.

Important

Currently, plutus only works with Culqi bridge, culqi is a peruvian payment gateway. My focus is implement a Strip bridge and with this continue work on the dashboard client of plutus (see client dir).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AvailableCurrencies = map[string]*Currency{
	PEN.Code: PEN,
	USD.Code: USD,
}

AvailableCurrencies is a map with available currencies

View Source
var ErrInvalidBridge error = errors.New("your bridge are invalid, please choose a valid bridge")
View Source
var ErrNotAvailableBridges error = errors.New("unavailable bridges, please configure one less bridge")
View Source
var PEN = &Currency{
	Name:   "PEN",
	Code:   "PEN",
	Symbol: "s/",
}

PEN represents a Peruvian Currency

View Source
var USD = &Currency{
	Name:   "USD",
	Code:   "USD",
	Symbol: "$",
}

USD represents an American Dollar

Functions

This section is empty.

Types

type BridgeDescription

type BridgeDescription struct {
	Name                 string
	Version              string
	Type                 ProviderType
	CanGenerateCardToken bool
	CanMakeCharge        bool
	CanMakeRefund        bool
}

BridgeDescription is used to describe a bridge, it's a fast overview the capabilities of this bridge

type CardDetails

type CardDetails struct {
	Number     string
	Expiration Date
	CVV        string
	Customer   *Customer
}

CardDetails represents a minimal details to encode your card sensible deatils

func (*CardDetails) Validate

func (card *CardDetails) Validate(mods ...string) bool

type CardToken

type CardToken struct {
	ID        string
	Value     string
	Type      CardTokenType
	Provider  ProviderType
	WithCard  EncodedCardDetails
	CreatedAt time.Time
}

CardToken represents a basic token generated by the charger service

func (*CardToken) FillID

func (token *CardToken) FillID()

FillID fills the id

type CardTokenType

type CardTokenType string

CardTokenType represents a type of token from your charger service

var OneUseToken CardTokenType = "one_use"

OneUseToken is a one use token from your charger

var RecurrentToken CardTokenType = "recurrent"

RecurrentToken is a saved card to recurrent use in your charger service

type ChargeParams

type ChargeParams struct {
	Amount    float64
	Email     string
	Details   string
	Currency  *Currency
	ExtraInfo *Customer
}

ChargeParams represents a minimal params to make a charge with your bridge

type ChargeToken

type ChargeToken struct {
	ID            string
	Value         string
	Message       string
	Provider      ProviderType
	WithCardToken CardToken
	CreatedAt     time.Time
}

ChargeToken is the reponse from your payment bridge

func (*ChargeToken) FillID

func (token *ChargeToken) FillID()

FillID fills the id

type Company

type Company struct {
	Name        string
	OfficialWeb string
	Support     SupportContact
	Custom      map[string]interface{}
}

Company serves to describe your company

type Cost

type Cost struct {
	Amount   float64
	Currency *Currency
}

Cost represents a economic cost

type Currency

type Currency struct {
	Name   string
	Code   string
	Symbol string
}

Currency is struct to describe a currency

type Customer

type Customer struct {
	ID       string
	Person   string
	Name     string
	Email    string
	Phone    string
	Location *Location
}

Customer represents a customer minimal information

func (*Customer) FillID

func (customer *Customer) FillID()

FillID fills the id

func (*Customer) String

func (customer *Customer) String() string

String implement a string representation of a customer

type Date

type Date struct {
	Year  int
	Month int
}

Date is a simple wrap for year and month date

type DeliveryChannel

type DeliveryChannel interface {
	Name() string
	DeliverSale(from *Company, sale *Sale, metadata ...map[string]string) (*SaleRepresentation, error)
}

DeliveryChannel a delivery channel is a way to represent and send a voucher of yourtransaction. examples of delivery channel are: SMTP, SMS, ThermalPrint, etc...

type Discount

type Discount struct {
	Type     DiscountType
	Percent  float64
	Amount   float64
	Currency *Currency
}

Discount is a discount value

type DiscountCode

type DiscountCode struct {
	ID      string `storm:"id"`
	Start   time.Time
	End     time.Time
	MaxUses int
	Uses    []DiscountUseRecord
	Code    string
	Value   *Discount
}

DiscountCode represents a discount promotional code

func (*DiscountCode) FillID

func (d *DiscountCode) FillID()

FillID fills the id

type DiscountType

type DiscountType string

DiscountType is a type of discount, actually plutus support static or percentual types

var PercentDiscount DiscountType = "percent"

PercentDiscount is a static discount (e.g. 20%)

var StaticDiscount DiscountType = "static"

StaticDiscount is a static discount (e.g. 100PEN)

type DiscountUseRecord

type DiscountUseRecord struct {
	At time.Time
	By *Customer
}

DiscountUseRecord is a record of discount code use

type EncodedCardDetails

type EncodedCardDetails struct {
	Number         string
	ExpirationYear int
	Customer       *Customer
}

EncodedCardDetails represents a encoded card details (hidden complete number and expiration year too)

type FlowType

type FlowType string

FlowType is how the flow of resources (money in this case) is propagated

var Charge FlowType = "charge"

Charge represents a money flow from your customer to you

type ID

type ID string

ID represents an id managed and generated by plutus

type Location

type Location struct {
	Address     string
	City        string
	State       string
	CountryCode string
	ZIP         string
}

Location is a set of fields to localize to customer

type NewDiscountCode

type NewDiscountCode struct {
	Code    string
	Start   *time.Time
	End     time.Time
	MaxUses int
	Value   Discount
}

NewDiscountCode is a wrapper to create a new discount code

type PaymentBridge

type PaymentBridge interface {
	Description() *BridgeDescription
	NewToken(details CardDetails, kind CardTokenType) (*CardToken, error)
	MakeCharge(source CardToken, params ChargeParams) (*ChargeToken, error)
	MakeRefund(source ChargeToken, params RefundParams) (*RefundToken, error)
}

PaymentBridge is an abstraction layer for your charger ends

type Product

type Product struct {
	Name    string
	Details string
	Cost    Cost
}

Product is a product description

type ProductList

type ProductList map[Quantity]*Product

ProductList is a quantized list of products

type ProviderType

type ProviderType int
const CULQI ProviderType = 0
const DUMMY ProviderType = 4
const PAYPAL ProviderType = 1
const STRIPE ProviderType = 3
const VISANET ProviderType = 2

type Quantity

type Quantity int

Quantity is an int representing a quantity

type RefundParams

type RefundParams struct {
	Amount   float64
	Reason   string
	Currency *Currency
}

RefundParams represents a minimal params to make a refund with your bridge

type RefundToken

type RefundToken struct {
	ID        string `storm:"id"`
	Value     string `storm:"unique"`
	CreatedAt time.Time
}

RefundToken is the reponse from your payment bridge

func (*RefundToken) FillID

func (refund *RefundToken) FillID()

FillID fills the id

type Repository

type Repository interface {
	SaveCustomer(c context.Context, customer *Customer) (*Customer, error)
	GetCustomer(c context.Context, ID string) (*Customer, error)
	UpdateCustomer(c context.Context, ID string, updatePayload Customer) (*Customer, error)
	RemoveCustomer(c context.Context, ID string) (*Customer, error)

	SaveCardToken(c context.Context, cardToken *CardToken) (*CardToken, error)
	GetCardToken(c context.Context, ID string) (*CardToken, error)
	UpdateCardToken(c context.Context, ID string, updatePayload CardToken) (*CardToken, error)
	RemoveCardToken(c context.Context, ID string) (*CardToken, error)

	SaveChargeToken(c context.Context, chargeToken *ChargeToken) (*ChargeToken, error)
	GetChargeToken(c context.Context, ID string) (*ChargeToken, error)
	UpdateChargeToken(c context.Context, ID string, updatePayload ChargeToken) (*ChargeToken, error)
	RemoveChargeToken(c context.Context, ID string) (*ChargeToken, error)

	SaveSale(c context.Context, sale *Sale) (*Sale, error)
	GetSale(c context.Context, ID string) (*Sale, error)
	UpdateSale(c context.Context, ID string, updatePayload Sale) (*Sale, error)
	RemoveSale(c context.Context, ID string) (*Sale, error)
}

Repository represents a bag where you can to put your basic objects

type Sale

type Sale struct {
	ID            string `storm:"id"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
	State         SaleState
	Customer      *Customer
	Products      []Product
	DiscountCodes []DiscountCode
	CardToken     *CardToken
	Charge        *ChargeToken
	CurrencyToPay *Currency
}

Sale is a bidirectional transaction

func (*Sale) FillID

func (sale *Sale) FillID()

FillID fills the id

type SaleRepresentation

type SaleRepresentation struct {
	Data        []byte
	Name        string
	ContentType string
}

SaleRepresentation is a representation of one sale

type SaleState

type SaleState string

SaleState represents the state of any sale

var Done SaleState = "done"

Done is a done sale

var Draft SaleState = "draft"

Draft is the earliest state of sale

var Null SaleState = "null"

Null is a null sale, only for debug porpuses

var PaidOut SaleState = "pay_out"

PaidOut is a charged sale

var Signed SaleState = "signed"

Signed is a signed and final modeling sale

type SalesEngine

type SalesEngine struct {
	Company          *Company
	Bridges          []PaymentBridge
	Repository       Repository
	DeliveryChannels []DeliveryChannel
}

SalesEngine is the core engine of plutus

func (*SalesEngine) ChargeSale

func (*SalesEngine) ChargeSaleAuto

func (*SalesEngine) ChargeSaleWithNativeToken

func (e *SalesEngine) ChargeSaleWithNativeToken(c context.Context, req *proto.ChargeWithNativeToken) (*proto.ChargeToken, error)

func (*SalesEngine) CreateDiscountCode

func (e *SalesEngine) CreateDiscountCode(c context.Context, req *proto.DiscountCodeRequest) (*proto.DiscountCode, error)

func (*SalesEngine) DeleteCardToken

func (e *SalesEngine) DeleteCardToken(c context.Context, req *proto.CardTokenByID) (*proto.CardToken, error)

func (*SalesEngine) DeleteDiscountCode

func (e *SalesEngine) DeleteDiscountCode(c context.Context, req *proto.DiscountCodeID) (*proto.DiscountCodes, error)

func (*SalesEngine) DeliverSale

func (*SalesEngine) DoneSale

func (e *SalesEngine) DoneSale(c context.Context, req *proto.SaleIDRequest) (*proto.Sale, error)

func (*SalesEngine) GetActiveDiscountCodes

func (e *SalesEngine) GetActiveDiscountCodes(c context.Context, req *proto.ActiveDiscountsRequest) (*proto.DiscountCodes, error)

func (*SalesEngine) GetCardTokenOfCustomerByID

func (e *SalesEngine) GetCardTokenOfCustomerByID(c context.Context, req *proto.CardTokenByID) (*proto.CardToken, error)

func (*SalesEngine) GetDiscountCode

func (e *SalesEngine) GetDiscountCode(c context.Context, req *proto.DiscountCodeID) (*proto.DiscountCode, error)

func (*SalesEngine) GetSale

func (e *SalesEngine) GetSale(c context.Context, req *proto.SaleIDRequest) (*proto.Sale, error)

func (*SalesEngine) GetSales

func (*SalesEngine) NewCardToken

func (*SalesEngine) NewCardTokenAuto

func (e *SalesEngine) NewCardTokenAuto(c context.Context, req *proto.NewCardTokenAutoRequest) (*proto.CardToken, error)

func (*SalesEngine) NewCardTokenFromNative

func (e *SalesEngine) NewCardTokenFromNative(c context.Context, req *proto.NewCardTokenNativeRequest) (*proto.CardToken, error)

func (*SalesEngine) NewFastSale

func (e *SalesEngine) NewFastSale(c context.Context, req *proto.FastSale) (*proto.Sale, error)

func (*SalesEngine) NewSale

func (e *SalesEngine) NewSale(c context.Context, req *proto.NewSaleRequest) (*proto.Sale, error)

func (*SalesEngine) UpdateSale

func (e *SalesEngine) UpdateSale(c context.Context, req *proto.SaleUpdateRequest) (*proto.Sale, error)

func (*SalesEngine) ValidateDiscountCode

func (e *SalesEngine) ValidateDiscountCode(c context.Context, req *proto.DiscountCodeValue) (*proto.DiscountCodeExist, error)

type SupportContact

type SupportContact struct {
	Email string
	Phone string
}

SupportContact wraps the support contact of your company

type Transaction

type Transaction struct {
	ID        string
	Type      FlowType
	State     TransactionState
	Snapshots []*TransactionSnapshot
	Give      ProductList
	Expected  ProductList
}

Transaction represents a transaction of money

type TransactionSnapshot

type TransactionSnapshot struct {
	At       time.Time
	Snapshot Transaction
}

TransactionSnapshot is a snapshot of one time transaction

type TransactionState

type TransactionState string

TransactionState is the state of a transaction

var Created TransactionState = "created"

Created is when the transaction eas early created

Directories

Path Synopsis
bridges
delivery
examples
repository

Jump to

Keyboard shortcuts

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