payment

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (

	// ErrValidationServiceTag is returned when ServiceTag is not the correct value
	ErrValidationServiceTag = errors.New("field 'ServiceTag' should be BCD")
	// ErrValidationCharacterSet is returned when CharacterSet is not in the allowed range
	ErrValidationCharacterSet = errors.New("field 'CharacterSet' should be 1..8")
	// ErrValidationVersion is returned when Version is not 1 or 2
	ErrValidationVersion = errors.New("field 'Version' should be 1 or 2")
	// ErrValidationIdentificationCode is returned when IdentificationCode is not the correct value
	ErrValidationIdentificationCode = errors.New("field 'IdentificationCode' should be SCT")
	// ErrValidationBICBeneficiary is returned when BICBeneficiary is not set
	ErrValidationBICBeneficiary = errors.New("field 'BICBeneficiary' is required when version is 1")
	// ErrValidationEuroAmount is returned when EuroAmount is not a valid amount
	ErrValidationEuroAmount = errors.New("field 'EuroAmount' must be 0.01 or more and 999999999.99 or less")
	// ErrValidationPurpose is returned when Purpose is not within bounds
	ErrValidationPurpose = errors.New("field 'Purpose' should not exceed 4 characters")

	// ErrValidationRemittanceRequired is returned when Remittance is empty
	ErrValidationRemittanceRequired = errors.New("field 'Remittance' is required")
	// ErrValidationRemittanceStructuredTooLong is returned when Remittance is not within bounds for structured field
	ErrValidationRemittanceStructuredTooLong = errors.New("structured 'Remittance' should not exceed 35 characters")
	// ErrValidationRemittanceUnstructuredTooLong is returned when Remittance is not within bounds for unstructured field
	ErrValidationRemittanceUnstructuredTooLong = errors.New("unstructured 'Remittance' should not exceed 140 characters")
	// ErrValidationRemittanceUnstructuredCharacters is returned when Remittance contains invalid characters
	ErrValidationRemittanceUnstructuredCharacters = errors.New("unstructured 'Remittance' should only contain alpha-numerics, spaces and/or " + specialChars)

	// ErrValidationNameBeneficiaryRequired is returned when NameBeneficiary is empty
	ErrValidationNameBeneficiaryRequired = errors.New("field 'NameBeneficiary' is required")
	// ErrValidationNameBeneficiaryTooLong is returned when NameBeneficiary is not within bounds
	ErrValidationNameBeneficiaryTooLong = errors.New("field 'NameBeneficiary' should not exceed 70 characers")
	// ErrValidationNameBeneficiaryCharacters is returned when NameBeneficiary contains invalid characters
	ErrValidationNameBeneficiaryCharacters = errors.New("field 'NameBeneficiary' should not only contain alpha-numerics, spaces and/or " + specialChars)
)

Functions

This section is empty.

Types

type Payment

type Payment struct {
	// ServiceTag should always be BCD
	ServiceTag string
	// Version should be v1 or v2
	Version int
	/*
		1: UTF-8 5: ISO 8859-5
		2: ISO 8859-1 6: ISO 8859-7
		3: ISO 8859-2 7: ISO 8859-10
		4: ISO 8859-4 8: ISO 8859-15
	*/
	CharacterSet int
	// IdentificationCode should always be SCT (SEPA Credit Transfer)
	IdentificationCode string
	// AT-23 BIC of the Beneficiary Bank [optional in Version 2]
	// The BIC will continue to be mandatory for SEPA payment transactions involving non-EEA countries.
	BICBeneficiary string
	// AT-21 Name of the Beneficiary
	NameBeneficiary string
	// AT-20 Account number of the Beneficiary
	// Only IBAN is allowed.
	IBANBeneficiary string
	// AT-04 Amount of the Credit Transfer in Euro [optional]
	// Amount must be 0.01 or more and 999999999.99 or less
	EuroAmount float64
	// AT-44 Purpose of the Credit Transfer [optional]
	Purpose string
	// AT-05 Remittance Information (Structured) [optional]
	// Creditor Reference (ISO 11649 RFCreditor Reference may be used
	// *or*
	// AT-05 Remittance Information (Unstructured) [optional]
	Remittance string
	// Beneficiary to originator information [optional]
	B2OInformation string

	// Defines whether the Remittance Information is Structured or Unstructured
	RemittanceIsStructured bool
}

Payment encapsulates all fields needed to generate the QR code

Example
package main

import (
	"fmt"

	"github.com/jovandeginste/payme/payment"
)

const (
	ExampleIBAN       = "FR1420041010050500013M02606"
	ExampleName       = "François D'Alsace S.A."
	ExampleRemittance = "Client:Marie Louise La Lune"
)

func main() {
	p := payment.New()

	p.NameBeneficiary = ExampleName
	p.IBANBeneficiary = ExampleIBAN
	p.EuroAmount = 12.3
	p.Remittance = ExampleRemittance

	o, err := p.ToQRBytes()
	if err != nil {
		panic(err)
	}

	fmt.Println(string(o))
}
Output:

func New

func New() *Payment

New returns a new Payment struct with default values for version 2

func NewStructured

func NewStructured() *Payment

NewStructured returns a default Payment with the Structured flag enabled

func (*Payment) BICBeneficiaryString

func (p *Payment) BICBeneficiaryString() string

BICBeneficiaryString returns the BIC of the beneficiary, depending on the version of the QR code

func (*Payment) CharacterSetString

func (p *Payment) CharacterSetString() string

CharacterSetString returns the character set converted to string

func (*Payment) EuroAmountString

func (p *Payment) EuroAmountString() string

EuroAmountString returns the set amount in financial format (eg. EUR12.34) or an empty string if the amount is 0

func (*Payment) IBAN

func (p *Payment) IBAN() (*iban.IBAN, error)

IBAN returns the parsed IBAN of the beneficiary

func (*Payment) IBANBeneficiaryString

func (p *Payment) IBANBeneficiaryString() string

IBANBeneficiaryString returns the IBAN of the beneficiary in a standardized form

func (*Payment) IsValid

func (p *Payment) IsValid() error

IsValid checks if all fields in the payment are consistent and meet the requirements. It returns the first error it encounters, or nil if all is well.

func (*Payment) PurposeString

func (p *Payment) PurposeString() string

PurposeString returns the parsed purpose

func (*Payment) RemittanceString

func (p *Payment) RemittanceString(structured bool) string

RemittanceString returns the value for the remittance field, independing on being structured

func (*Payment) RemittanceStructured

func (p *Payment) RemittanceStructured() string

RemittanceStructured returns the value for the structured remittance line

func (*Payment) RemittanceText

func (p *Payment) RemittanceText() string

RemittanceText returns the value for the unstructured (freeform) remittance line

func (*Payment) ToQRBytes added in v1.0.2

func (p *Payment) ToQRBytes() ([]byte, error)

ToQRBytes returns an ASCII representation of the QR code You can print this to the console, save to a file, etc.

func (*Payment) ToQRPNG

func (p *Payment) ToQRPNG(qrSize int) ([]byte, error)

ToQRPNG returns an PNG representation of the QR code You should save this to a file, or pass it to an image processing library

func (*Payment) ToString

func (p *Payment) ToString() (string, error)

ToString returns the content of the QR code as string Use this to then generate the QR code in the form you need

func (*Payment) VersionString

func (p *Payment) VersionString() string

VersionString returns the version converted to a 3-digit number with leading zeros

Jump to

Keyboard shortcuts

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