pay

package
v0.42.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Overview

Package pay handles models related to payments.

Index

Constants

View Source
const (
	MethodKeyAny            cbc.Key = "any" // Use any method available.
	MethodKeyCard           cbc.Key = "card"
	MethodKeyCreditTransfer cbc.Key = "credit-transfer"
	MethodKeyDebitTransfer  cbc.Key = "debit-transfer"
	MethodKeyCash           cbc.Key = "cash"
	MethodKeyCheque         cbc.Key = "cheque"
	MethodKeyCredit         cbc.Key = "credit"
	MethodKeyBankDraft      cbc.Key = "bank-draft"
	MethodKeyDirectDebit    cbc.Key = "direct-debit" // aka. Mandate
	MethodKeyOnline         cbc.Key = "online"       // Website from which payment can be made
)

Standard payment method codes. This is a heavily reduced list of practical codes which can be linked to UNTDID 4461 counterparts. If you require more payment method options, please send your pull requests.

View Source
const (
	// None defined
	TermKeyNA cbc.Key = ""
	// End of Month
	TermKeyEndOfMonth cbc.Key = "end-of-month"
	// Due on a specific date
	TermKeyDueDate cbc.Key = "due-date"
	// Deferred until after the due dates
	TermKeyDeferred cbc.Key = "deferred"
	// Month after the present
	TermKeyProximo cbc.Key = "proximo"
	// on receipt of invoice
	TermKeyInstant cbc.Key = "instant"
	// chosen by buyer
	TermKeyElective cbc.Key = "elective"
	// Seller to advise buyer in separate transaction
	TermKeyPending cbc.Key = "pending"
	// Payment made in advance
	TermKeyAdvance cbc.Key = "advance"
	// Payment on Delivery
	TermKeyDelivery cbc.Key = "delivery"
)

Pre-defined Payment Terms based on UNTDID 4279

Variables

View Source
var MethodKeyDefinitions = []MethodKeyDef{
	{MethodKeyAny, "Any", "Any method available, no preference.", "1"},
	{MethodKeyCard, "Card", "Credit or debit card.", "48"},
	{MethodKeyCreditTransfer, "Credit Transfer", "Sender initiated bank or wire transfer.", "30"},
	{MethodKeyDebitTransfer, "Debit Transfer", "Receiver initiated bank or wire transfer.", "31"},
	{MethodKeyCash, "Cash", "Cash in hand.", "10"},
	{MethodKeyCheque, "Cheque", "Cheque from bank.", ""},
	{MethodKeyCredit, "Credit", "Using credit from previous transactions with the supplier.", ""},
	{MethodKeyBankDraft, "Draft", "Bankers Draft or Bank Cheque.", ""},
	{MethodKeyDirectDebit, "Direct Debit", "Direct debit from the customers bank account.", "49"},
	{MethodKeyOnline, "Online", "Online or web payment.", "68"},
}

MethodKeyDefinitions includes all the payment method keys that are accepted by GOBL.

View Source
var TermKeyDefinitions = []TermKeyDef{
	{TermKeyNA, "NA", "Not yet defined", "16"},
	{TermKeyEndOfMonth, "End of Month", "End of month", "2"},
	{TermKeyDueDate, "Due Date", "Due on a specific date", "3"},
	{TermKeyDeferred, "Deferred", "Deferred until after the due date", "4"},
	{TermKeyProximo, "Proximo", "Month after the present", "9"},
	{TermKeyInstant, "Instant", "On receipt of invoice", "10"},
	{TermKeyElective, "Elective", "Chosen by the buyer", "11"},
	{TermKeyPending, "Pending", "Seller to advise buyer in separate transaction", "13"},
	{TermKeyAdvance, "Advance", "Payment made in advance", "32"},
	{TermKeyDelivery, "Delivery", "Payment on Delivery", "52"},
}

TermKeyDefinitions includes all the currently accepted GOBL Payment Term definitions.

Functions

This section is empty.

Types

type Advance added in v0.2.0

type Advance struct {
	// Unique identifier for this advance.
	UUID *uuid.UUID `json:"uuid,omitempty" jsonschema:"title=UUID"`
	// When the advance was made.
	Date *cal.Date `json:"date,omitempty" jsonschema:"title=Date"`
	// ID or reference for the advance.
	Ref string `json:"ref,omitempty" jsonschema:"title=Reference"`
	// If this "advance" payment has come from a public grant or subsidy, set this to true.
	Grant bool `json:"grant,omitempty" jsonschema:"title=Grant"`
	// Details about the advance.
	Description string `json:"desc" jsonschema:"title=Description"`
	// How much as a percentage of the total with tax was paid
	Percent *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent"`
	// How much was paid.
	Amount num.Amount `json:"amount" jsonschema:"title=Amount"`
	// If different from the parent document's base currency.
	Currency currency.Code `json:"currency,omitempty" jsonschema:"title=Currency"`
}

Advance represents a single payment that has been made already, such as a deposit on an intent to purchase, or as credit from a previous invoice which was later corrected or cancelled.

func (*Advance) CalculateFrom added in v0.30.3

func (a *Advance) CalculateFrom(totalWithTax num.Amount)

CalculateFrom will update the amount using the rate of the provided total, if defined.

func (*Advance) Validate added in v0.2.0

func (a *Advance) Validate() error

Validate checks the advance looks okay

type Card added in v0.2.0

type Card struct {
	// Last 4 digits of the card's Primary Account Number (PAN).
	Last4 string `json:"last4" jsonschema:"title=Last 4"`
	// Name of the person whom the card belongs to.
	Holder string `json:"holder" jsonschema:"title=Holder Name"`
}

Card contains simplified card holder data as a reference for the customer.

type CreditTransfer added in v0.2.0

type CreditTransfer struct {
	// International Bank Account Number
	IBAN string `json:"iban,omitempty" jsonschema:"title=IBAN"`
	// Bank Identifier Code used for international transfers.
	BIC string `json:"bic,omitempty" jsonschema:"title=BIC"`
	// Account number, if IBAN not available.
	Number string `json:"number,omitempty" jsonschema:"title=Number"`
	// Name of the bank.
	Name string `json:"name,omitempty" jsonschema:"title=Name"`
	// Bank office branch address, not normally required.
	Branch *org.Address `json:"branch,omitempty" jsonschema:"title=Branch"`
}

CreditTransfer contains fields that can be used for making payments via a bank transfer or wire.

type DirectDebit added in v0.2.0

type DirectDebit struct {
	// Unique identifier assigned by the payee for referencing the direct debit.
	Ref string `json:"ref,omitempty" jsonschema:"title=Mandate Reference"`
	// Unique banking reference that identifies the payee or seller assigned by the bank.
	Creditor string `json:"creditor,omitempty" jsonschema:"title=Creditor ID"`
	// Account identifier to be debited by the direct debit.
	Account string `json:"account,omitempty" jsonschema:"title=Account"`
}

DirectDebit defines the data that will be used to make the direct debit.

type DueDate added in v0.2.0

type DueDate struct {
	Date     *cal.Date       `json:"date" jsonschema:"title=Date,description=When the payment is due."`
	Notes    string          `json:"notes,omitempty" jsonschema:"title=Notes,description=Other details to take into account for the due date."`
	Amount   num.Amount      `json:"amount" jsonschema:"title=Amount,description=How much needs to be paid by the date."`
	Percent  *num.Percentage `json:"percent,omitempty" jsonschema:"title=Percent,description=Percentage of the total that should be paid by the date."`
	Currency currency.Code   `json:"currency,omitempty" jsonschema:"title=Currency,description=If different from the parent document's base currency."`
}

DueDate contains an amount that should be paid by the given date.

func (*DueDate) Validate added in v0.2.0

func (dd *DueDate) Validate() error

Validate checks the DueDate has the required fields.

type Instructions added in v0.2.0

type Instructions struct {
	// How payment is expected or has been arranged to be collected
	Key cbc.Key `json:"key" jsonschema:"title=Key"`
	// Optional text description of the payment method
	Detail string `json:"detail,omitempty" jsonschema:"title=Detail"`
	// Remittance information, a text value used to link the payment with the invoice.
	Ref string `json:"ref,omitempty" jsonschema:"title=Ref"`
	// Instructions for sending payment via a bank transfer.
	CreditTransfer []*CreditTransfer `json:"credit_transfer,omitempty" jsonschema:"title=Credit Transfer"`
	// Details of the payment that will be made via a credit or debit card.
	Card *Card `json:"card,omitempty" jsonschema:"title=Card"`
	// A group of terms that can be used by the customer or payer to consolidate direct debit payments.
	DirectDebit *DirectDebit `json:"direct_debit,omitempty" jsonschema:"title=Direct Debit"`
	// Array of online payment options
	Online []*Online `json:"online,omitempty" jsonschema:"title=Online"`
	// Any additional instructions that may be required to make the payment.
	Notes string `json:"notes,omitempty" jsonschema:"title=Notes"`
	// Non-structured additional data that may be useful.
	Meta cbc.Meta `json:"meta,omitempty" jsonschema:"title=Meta"`
}

Instructions determine how the payment has or should be made. A single "key" exists in which the preferred payment method should be provided, all other details serve as a reference.

func (Instructions) JSONSchemaExtend added in v0.38.0

func (Instructions) JSONSchemaExtend(schema *jsonschema.Schema)

JSONSchemaExtend adds the method key definitions to the schema.

func (*Instructions) UNTDID4461 added in v0.28.0

func (i *Instructions) UNTDID4461() cbc.Code

UNTDID4461 provides the standard UNTDID 4461 code for the instruction's key.

func (*Instructions) Validate added in v0.28.0

func (i *Instructions) Validate() error

Validate ensures the fields provided in the instructions are valid.

type MethodKeyDef added in v0.29.0

type MethodKeyDef struct {
	// Key being described
	Key cbc.Key `json:"key" jsonschema:"title=Key"`
	// Human value of the key
	Title string `json:"title" jsonschema:"title=Title"`
	// Details about the meaning of the key
	Description string `json:"description" jsonschema:"title=Description"`
	// UNTDID 4461 Equivalent Code
	UNTDID4461 cbc.Code `json:"untdid4461" jsonschema:"title=UNTDID 4461 Code"`
}

MethodKeyDef is used to define each of the Method Keys that can be accepted by GOBL.

type Online added in v0.2.0

type Online struct {
	// Descriptive name given to the online provider.
	Name string `json:"name,omitempty" jsonschema:"title=Name"`
	// Full URL to be used for payment.
	Address string `json:"addr" jsonschema:"title=Address"`
}

Online provides the details required to make a payment online using a website

func (*Online) Validate added in v0.2.0

func (u *Online) Validate() error

Validate ensures the Online method details look correct.

type TermKeyDef added in v0.29.0

type TermKeyDef struct {
	// The key being defined
	Key cbc.Key `json:"key" jsonschema:"title=Key"`
	// Human readable title for the key
	Title string `json:"title" jsonschema:"title=Title"`
	// Human text for the key
	Description string `json:"description" jsonschema:"title=Description"`
	// The equivalent UNTDID 4279 Code
	UNTDID4279 cbc.Code `json:"untdid4279" jsonschema:"title=UNTDID 4279 Code"`
}

TermKeyDef holds a definition of a single payment term key

type Terms

type Terms struct {
	// Type of terms to be applied.
	Key cbc.Key `json:"key" jsonschema:"title=Key"`
	// Text detail of the chosen payment terms.
	Detail string `json:"detail,omitempty" jsonschema:"title=Detail"`
	// Set of dates for agreed payments.
	DueDates []*DueDate `json:"due_dates,omitempty" jsonschema:"title=Due Dates"`
	// Description of the conditions for payment.
	Notes string `json:"notes,omitempty" jsonschema:"title=Notes"`
}

Terms defines when we expect the customer to pay, or have paid, for the contents of the document.

func (*Terms) CalculateDues added in v0.2.0

func (t *Terms) CalculateDues(sum num.Amount)

CalculateDues goes through each DueDate. If it has a percentage value set, it'll be used to calculate the amount.

func (Terms) JSONSchemaExtend added in v0.38.0

func (Terms) JSONSchemaExtend(schema *jsonschema.Schema)

JSONSchemaExtend adds the payment terms key list to the schema.

func (*Terms) UNTDID4279 added in v0.28.0

func (t *Terms) UNTDID4279() cbc.Code

UNTDID4279 returns the UNTDID 4270 code associated with the terms key.

func (*Terms) Validate added in v0.2.0

func (t *Terms) Validate() error

Validate ensures that the terms contain everything required.

Jump to

Keyboard shortcuts

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