Documentation ¶
Index ¶
- Variables
- type Payment
- func (p *Payment) BICBeneficiaryString() string
- func (p *Payment) CharacterSetString() string
- func (p *Payment) EuroAmountString() string
- func (p *Payment) IBAN() (*iban.IBAN, error)
- func (p *Payment) IBANBeneficiaryString() string
- func (p *Payment) IsValid() error
- func (p *Payment) PurposeString() string
- func (p *Payment) RemittanceString(structured bool) string
- func (p *Payment) RemittanceStructured() string
- func (p *Payment) RemittanceText() string
- func (p *Payment) ToQRBytes() ([]byte, error)
- func (p *Payment) ToQRPNG(qrSize int) ([]byte, error)
- func (p *Payment) ToString() (string, error)
- func (p *Payment) VersionString() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 NewStructured ¶
func NewStructured() *Payment
NewStructured returns a default Payment with the Structured flag enabled
func (*Payment) BICBeneficiaryString ¶
BICBeneficiaryString returns the BIC of the beneficiary, depending on the version of the QR code
func (*Payment) CharacterSetString ¶
CharacterSetString returns the character set converted to string
func (*Payment) EuroAmountString ¶
EuroAmountString returns the set amount in financial format (eg. EUR12.34) or an empty string if the amount is 0
func (*Payment) IBANBeneficiaryString ¶
IBANBeneficiaryString returns the IBAN of the beneficiary in a standardized form
func (*Payment) IsValid ¶
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 ¶
PurposeString returns the parsed purpose
func (*Payment) RemittanceString ¶
RemittanceString returns the value for the remittance field, independing on being structured
func (*Payment) RemittanceStructured ¶
RemittanceStructured returns the value for the structured remittance line
func (*Payment) RemittanceText ¶
RemittanceText returns the value for the unstructured (freeform) remittance line
func (*Payment) ToQRBytes ¶ added in v1.0.2
ToQRBytes returns an ASCII representation of the QR code You can print this to the console, save to a file, etc.
func (*Payment) ToQRPNG ¶
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 ¶
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 ¶
VersionString returns the version converted to a 3-digit number with leading zeros