gobl 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ext/hashme.rb +28 -0
- data/lib/gobl/bill/advances.rb +1 -77
- data/lib/gobl/bill/charge.rb +11 -65
- data/lib/gobl/bill/delivery.rb +5 -47
- data/lib/gobl/bill/discount.rb +11 -65
- data/lib/gobl/bill/exchange_rates.rb +1 -77
- data/lib/gobl/bill/invoice.rb +28 -104
- data/lib/gobl/bill/invoice_type.rb +3 -134
- data/lib/gobl/bill/line.rb +13 -65
- data/lib/gobl/bill/line_charge.rb +5 -47
- data/lib/gobl/bill/line_discount.rb +5 -47
- data/lib/gobl/bill/ordering.rb +2 -38
- data/lib/gobl/bill/outlay.rb +11 -59
- data/lib/gobl/bill/payment.rb +5 -47
- data/lib/gobl/bill/preceding.rb +12 -62
- data/lib/gobl/bill/scheme_keys.rb +1 -77
- data/lib/gobl/bill/tax.rb +4 -44
- data/lib/gobl/bill/totals.rb +17 -71
- data/lib/gobl/cal/date.rb +1 -90
- data/lib/gobl/cal/period.rb +5 -41
- data/lib/gobl/currency/code.rb +3 -134
- data/lib/gobl/currency/exchange_rate.rb +5 -41
- data/lib/gobl/document.rb +1 -58
- data/lib/gobl/dsig/digest.rb +5 -41
- data/lib/gobl/dsig/signature.rb +1 -90
- data/lib/gobl/enum.rb +81 -0
- data/lib/gobl/envelope.rb +9 -48
- data/lib/gobl/header.rb +10 -56
- data/lib/gobl/i18n/string.rb +1 -58
- data/lib/gobl/l10n/code.rb +1 -90
- data/lib/gobl/l10n/country_code.rb +3 -134
- data/lib/gobl/map.rb +62 -0
- data/lib/gobl/note/message.rb +5 -44
- data/lib/gobl/num/amount.rb +6 -35
- data/lib/gobl/object.rb +21 -0
- data/lib/gobl/operations.rb +3 -3
- data/lib/gobl/org/address.rb +18 -80
- data/lib/gobl/org/code.rb +1 -90
- data/lib/gobl/org/coordinates.rb +5 -47
- data/lib/gobl/org/email.rb +6 -47
- data/lib/gobl/org/inbox.rb +8 -50
- data/lib/gobl/org/item.rb +13 -65
- data/lib/gobl/org/item_code.rb +4 -41
- data/lib/gobl/org/key.rb +1 -90
- data/lib/gobl/org/meta.rb +1 -58
- data/lib/gobl/org/name.rb +12 -62
- data/lib/gobl/org/note.rb +6 -47
- data/lib/gobl/org/note_key.rb +3 -134
- data/lib/gobl/org/party.rb +14 -71
- data/lib/gobl/org/person.rb +9 -56
- data/lib/gobl/org/registration.rb +9 -59
- data/lib/gobl/org/source_key.rb +3 -134
- data/lib/gobl/org/tax_identity.rb +8 -53
- data/lib/gobl/org/telephone.rb +5 -44
- data/lib/gobl/org/unit.rb +1 -136
- data/lib/gobl/pay/advance.rb +11 -59
- data/lib/gobl/pay/card.rb +5 -41
- data/lib/gobl/pay/credit_transfer.rb +6 -50
- data/lib/gobl/pay/direct_debit.rb +4 -44
- data/lib/gobl/pay/due_date.rb +8 -50
- data/lib/gobl/pay/instructions.rb +11 -62
- data/lib/gobl/pay/method_key.rb +3 -134
- data/lib/gobl/pay/online.rb +4 -41
- data/lib/gobl/pay/term_key.rb +3 -134
- data/lib/gobl/pay/terms.rb +6 -47
- data/lib/gobl/stamp.rb +5 -41
- data/lib/gobl/struct.rb +15 -15
- data/lib/gobl/tax/category.rb +9 -50
- data/lib/gobl/tax/category_total.rb +11 -53
- data/lib/gobl/tax/combo.rb +6 -47
- data/lib/gobl/tax/localities.rb +1 -77
- data/lib/gobl/tax/locality.rb +6 -44
- data/lib/gobl/tax/rate.rb +8 -47
- data/lib/gobl/tax/rate_total.rb +9 -50
- data/lib/gobl/tax/rate_total_surcharge.rb +5 -41
- data/lib/gobl/tax/rate_value.rb +6 -47
- data/lib/gobl/tax/region.rb +12 -56
- data/lib/gobl/tax/scheme.rb +8 -50
- data/lib/gobl/tax/schemes.rb +1 -77
- data/lib/gobl/tax/set.rb +1 -77
- data/lib/gobl/tax/total.rb +4 -41
- data/lib/gobl/uuid/uuid.rb +1 -90
- data/lib/gobl/value.rb +58 -0
- data/lib/gobl/version.rb +1 -1
- data/lib/gobl.rb +3 -1
- data/lib/gobl_extensions/document_helper.rb +3 -3
- data/lib/gobl_extensions/envelope_helper.rb +5 -0
- data/lib/gobl_extensions/i18n/value_keys_helper.rb +3 -3
- data/lib/gobl_extensions/tax/region_helper.rb +3 -9
- metadata +11 -36
- data/home/cavalle/workspace/invopop/gobl.ruby/gobl.gemspec +0 -30
- data/lib/gobl/types.rb +0 -17
data/lib/gobl/org/unit.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Org
|
11
11
|
# Unit describes how the quantity of the product should be interpreted.
|
12
|
-
class Unit < GOBL::
|
12
|
+
class Unit < GOBL::Enum
|
13
13
|
# The Schema ID of the GOBL Unit structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/org/unit'
|
15
15
|
|
@@ -64,141 +64,6 @@ module GOBL
|
|
64
64
|
'sheet' => 'Sheets',
|
65
65
|
'envelope' => 'Envelopes'
|
66
66
|
}.freeze
|
67
|
-
|
68
|
-
attribute :_value, GOBL::Types::String
|
69
|
-
private :_value
|
70
|
-
|
71
|
-
# Creates a new object from a GOBL value
|
72
|
-
#
|
73
|
-
# @param data [String] the GOBL value
|
74
|
-
#
|
75
|
-
# @return [Unit] the object created from the given data
|
76
|
-
def self.from_gobl!(data)
|
77
|
-
new(_value: data)
|
78
|
-
end
|
79
|
-
|
80
|
-
# Returns a GOBL value representing the current object
|
81
|
-
#
|
82
|
-
# @return [String] the GOBL value that represents the current object
|
83
|
-
def to_gobl
|
84
|
-
_value
|
85
|
-
end
|
86
|
-
|
87
|
-
# Returns a {Unit} that corresponds to a given object. The object can be a
|
88
|
-
# `Symbol`, a `String` or anything coercible into one (via `#to_s`).
|
89
|
-
#
|
90
|
-
# @param object [Symbol, String, #to_s] the value of the object.
|
91
|
-
#
|
92
|
-
# @return [Unit] the object corresponding to the given value.
|
93
|
-
#
|
94
|
-
# @example Instantiating from a symbol
|
95
|
-
# unit = GOBL::Org::Unit.new(:g)
|
96
|
-
#
|
97
|
-
# @example Instantiating from a string
|
98
|
-
# unit = GOBL::Org::Unit.new('g')
|
99
|
-
def self.new(object)
|
100
|
-
case object
|
101
|
-
when Hash, self # internal use, not to be used in public calls
|
102
|
-
super
|
103
|
-
when Symbol
|
104
|
-
new find_by_sym(object) || object.to_s
|
105
|
-
else
|
106
|
-
super _value: object.to_s
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# Returns the string representation of the current object
|
111
|
-
#
|
112
|
-
# @return [String] the string representation of the current object
|
113
|
-
def to_s
|
114
|
-
_value.to_s
|
115
|
-
end
|
116
|
-
|
117
|
-
# Returns the symbol representation of the current object
|
118
|
-
#
|
119
|
-
# @return [Symbol] the symbol representation of the current object
|
120
|
-
def to_sym
|
121
|
-
to_s.parameterize.underscore.to_sym
|
122
|
-
end
|
123
|
-
|
124
|
-
# Returns whether the current object is equivalent to a given one. In addition
|
125
|
-
# to {Unit} objects, the current object can be compared to a `Symbol`, a
|
126
|
-
# `String` or anything coercible into one (via `#to_s`)
|
127
|
-
#
|
128
|
-
# @param other [Unit, Symbol, String, #to_s] the other object to compare to
|
129
|
-
#
|
130
|
-
# @return [Boolean] `true` if the objects are equivalent, `false` otherwise
|
131
|
-
#
|
132
|
-
# @example Comparing to another {Unit} object
|
133
|
-
# unit = GOBL::Org::Unit.new('g')
|
134
|
-
# unit == GOBL::Org::Unit.new('g') #=> true
|
135
|
-
# unit == GOBL::Org::Unit.new('kg') #=> false
|
136
|
-
#
|
137
|
-
# @example Comparing to a string
|
138
|
-
# unit = GOBL::Org::Unit.new('g')
|
139
|
-
# unit == 'g' #=> true
|
140
|
-
# unit == 'kg' #=> false
|
141
|
-
#
|
142
|
-
# @example Comparing to a symbol
|
143
|
-
# unit = GOBL::Org::Unit.new('g')
|
144
|
-
# unit == :g #=> true
|
145
|
-
# unit == :kg #=> false
|
146
|
-
def ==(other)
|
147
|
-
case other
|
148
|
-
when self.class
|
149
|
-
super
|
150
|
-
when Symbol
|
151
|
-
to_sym == other
|
152
|
-
else
|
153
|
-
to_s == other.to_s
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
# Returns an array with all the enumerated objects of this type
|
158
|
-
#
|
159
|
-
# @return [Array<Unit>] the array of enumerated objects
|
160
|
-
def self.all
|
161
|
-
ENUM.keys.map { |key| new(key) }
|
162
|
-
end
|
163
|
-
|
164
|
-
# @api private
|
165
|
-
def self.find_by_sym(sym)
|
166
|
-
all.find { |object| object.to_sym == sym }
|
167
|
-
end
|
168
|
-
|
169
|
-
# @api private
|
170
|
-
def self.find_by_inquirer(method_name)
|
171
|
-
method_name =~ /(.+)\?$/ && find_by_sym(Regexp.last_match(1).to_sym)
|
172
|
-
end
|
173
|
-
|
174
|
-
# Returns the description of the current object
|
175
|
-
#
|
176
|
-
# @return [String] the description of the current object
|
177
|
-
def description
|
178
|
-
ENUM.fetch(_value, _value)
|
179
|
-
end
|
180
|
-
|
181
|
-
# @api private
|
182
|
-
def respond_to_missing?(method_name, include_private = false)
|
183
|
-
self.class.find_by_inquirer(method_name) || super
|
184
|
-
end
|
185
|
-
|
186
|
-
# Enables dynamic value inquirers like `Unit#g?` for
|
187
|
-
# each of the declared enum values (see {ENUM}). Each inquirer returns a
|
188
|
-
# `Boolean` denoting whether the value equals the enquired value (`true`) or
|
189
|
-
# not (`false`)
|
190
|
-
#
|
191
|
-
# @example
|
192
|
-
# unit = GOBL::Org::Unit.new('g')
|
193
|
-
# unit.g? # => true
|
194
|
-
# unit.kg? # => false
|
195
|
-
def method_missing(method_name, *args, &block)
|
196
|
-
if value = self.class.find_by_inquirer(method_name)
|
197
|
-
self == value
|
198
|
-
else
|
199
|
-
super
|
200
|
-
end
|
201
|
-
end
|
202
67
|
end
|
203
68
|
end
|
204
69
|
end
|
data/lib/gobl/pay/advance.rb
CHANGED
@@ -9,99 +9,51 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Pay
|
11
11
|
# 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.
|
12
|
-
class Advance < GOBL::
|
12
|
+
class Advance < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Advance structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/pay/advance'
|
15
15
|
|
16
16
|
# @!attribute [r] uuid
|
17
17
|
# Unique identifier for this advance.
|
18
18
|
# @return [GOBL::UUID::UUID]
|
19
|
-
|
19
|
+
property :uuid, GOBL::UUID::UUID
|
20
20
|
|
21
21
|
# @!attribute [r] date
|
22
22
|
# When the advance was made.
|
23
23
|
# @return [GOBL::Cal::Date]
|
24
|
-
|
24
|
+
property :date, GOBL::Cal::Date
|
25
25
|
|
26
26
|
# @!attribute [r] ref
|
27
27
|
# ID or reference for the advance.
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :ref, String
|
30
30
|
|
31
31
|
# @!attribute [r] grant
|
32
32
|
# If this "advance" payment has come from a public grant or subsidy, set this to true.
|
33
33
|
# @return [Boolean]
|
34
|
-
|
34
|
+
property :grant, Boolean
|
35
35
|
|
36
36
|
# @!attribute [r] desc
|
37
37
|
# Details about the advance.
|
38
38
|
# @return [String]
|
39
|
-
|
39
|
+
property :desc, String
|
40
|
+
validates :desc, presence: true
|
40
41
|
|
41
42
|
# @!attribute [r] percent
|
42
43
|
# How much as a percentage of the total with tax was paid
|
43
44
|
# @return [GOBL::Num::Percentage]
|
44
|
-
|
45
|
+
property :percent, GOBL::Num::Percentage
|
45
46
|
|
46
47
|
# @!attribute [r] amount
|
47
48
|
# How much was paid.
|
48
49
|
# @return [GOBL::Num::Amount]
|
49
|
-
|
50
|
+
property :amount, GOBL::Num::Amount
|
51
|
+
validates :amount, presence: true
|
50
52
|
|
51
53
|
# @!attribute [r] currency
|
52
54
|
# If different from the parent document's base currency.
|
53
55
|
# @return [GOBL::Currency::Code]
|
54
|
-
|
55
|
-
|
56
|
-
# Creates a new object from a hash of GOBL data
|
57
|
-
#
|
58
|
-
# @param data [Hash] a hash of GOBL data
|
59
|
-
#
|
60
|
-
# @return [Advance] the object created from the given data
|
61
|
-
def self.from_gobl!(data)
|
62
|
-
data = GOBL::Types::Hash[data]
|
63
|
-
|
64
|
-
new(
|
65
|
-
uuid: data['uuid'] ? GOBL::UUID::UUID.from_gobl!(data['uuid']) : nil,
|
66
|
-
date: data['date'] ? GOBL::Cal::Date.from_gobl!(data['date']) : nil,
|
67
|
-
ref: data['ref'],
|
68
|
-
grant: data['grant'],
|
69
|
-
desc: data['desc'],
|
70
|
-
percent: data['percent'] || nil,
|
71
|
-
amount: data['amount'],
|
72
|
-
currency: data['currency'] ? GOBL::Currency::Code.from_gobl!(data['currency']) : nil
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns a hash of GOBL data representing the current object
|
77
|
-
#
|
78
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
79
|
-
def to_gobl
|
80
|
-
{
|
81
|
-
'uuid' => attributes[:uuid]&.to_gobl,
|
82
|
-
'date' => attributes[:date]&.to_gobl,
|
83
|
-
'ref' => attributes[:ref],
|
84
|
-
'grant' => attributes[:grant],
|
85
|
-
'desc' => attributes[:desc],
|
86
|
-
'percent' => attributes[:percent]&.to_gobl,
|
87
|
-
'amount' => attributes[:amount]&.to_gobl,
|
88
|
-
'currency' => attributes[:currency]&.to_gobl
|
89
|
-
}.compact
|
90
|
-
end
|
91
|
-
|
92
|
-
# @!method self.new(attrs)
|
93
|
-
#
|
94
|
-
# Returns a {Advance} object from a given hash of attributes. Nested
|
95
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
96
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
97
|
-
# parameter.
|
98
|
-
#
|
99
|
-
# The `new` method will only allow to create a new object if all attributes
|
100
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
101
|
-
#
|
102
|
-
# @param attrs [Hash] the hash of attributes
|
103
|
-
#
|
104
|
-
# @return [Advance] the object corresponding to the given input
|
56
|
+
property :currency, GOBL::Currency::Code
|
105
57
|
end
|
106
58
|
end
|
107
59
|
end
|
data/lib/gobl/pay/card.rb
CHANGED
@@ -9,57 +9,21 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Pay
|
11
11
|
# Card contains simplified card holder data as a reference for the customer.
|
12
|
-
class Card < GOBL::
|
12
|
+
class Card < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Card structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/pay/instructions#/$defs/Card'
|
15
15
|
|
16
16
|
# @!attribute [r] last4
|
17
17
|
# Last 4 digits of the card's Primary Account Number (PAN).
|
18
18
|
# @return [String]
|
19
|
-
|
19
|
+
property :last4, String
|
20
|
+
validates :last4, presence: true
|
20
21
|
|
21
22
|
# @!attribute [r] holder
|
22
23
|
# Name of the person whom the card belongs to.
|
23
24
|
# @return [String]
|
24
|
-
|
25
|
-
|
26
|
-
# Creates a new object from a hash of GOBL data
|
27
|
-
#
|
28
|
-
# @param data [Hash] a hash of GOBL data
|
29
|
-
#
|
30
|
-
# @return [Card] the object created from the given data
|
31
|
-
def self.from_gobl!(data)
|
32
|
-
data = GOBL::Types::Hash[data]
|
33
|
-
|
34
|
-
new(
|
35
|
-
last4: data['last4'],
|
36
|
-
holder: data['holder']
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a hash of GOBL data representing the current object
|
41
|
-
#
|
42
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
43
|
-
def to_gobl
|
44
|
-
{
|
45
|
-
'last4' => attributes[:last4],
|
46
|
-
'holder' => attributes[:holder]
|
47
|
-
}.compact
|
48
|
-
end
|
49
|
-
|
50
|
-
# @!method self.new(attrs)
|
51
|
-
#
|
52
|
-
# Returns a {Card} object from a given hash of attributes. Nested
|
53
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
54
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
55
|
-
# parameter.
|
56
|
-
#
|
57
|
-
# The `new` method will only allow to create a new object if all attributes
|
58
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
59
|
-
#
|
60
|
-
# @param attrs [Hash] the hash of attributes
|
61
|
-
#
|
62
|
-
# @return [Card] the object corresponding to the given input
|
25
|
+
property :holder, String
|
26
|
+
validates :holder, presence: true
|
63
27
|
end
|
64
28
|
end
|
65
29
|
end
|
@@ -9,78 +9,34 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Pay
|
11
11
|
# CreditTransfer contains fields that can be used for making payments via a bank transfer or wire.
|
12
|
-
class CreditTransfer < GOBL::
|
12
|
+
class CreditTransfer < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL CreditTransfer structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/pay/instructions#/$defs/CreditTransfer'
|
15
15
|
|
16
16
|
# @!attribute [r] iban
|
17
17
|
# International Bank Account Number
|
18
18
|
# @return [String]
|
19
|
-
|
19
|
+
property :iban, String
|
20
20
|
|
21
21
|
# @!attribute [r] bic
|
22
22
|
# Bank Identifier Code used for international transfers.
|
23
23
|
# @return [String]
|
24
|
-
|
24
|
+
property :bic, String
|
25
25
|
|
26
26
|
# @!attribute [r] number
|
27
27
|
# Account number, if IBAN not available.
|
28
28
|
# @return [String]
|
29
|
-
|
29
|
+
property :number, String
|
30
30
|
|
31
31
|
# @!attribute [r] name
|
32
32
|
# Name of the bank.
|
33
33
|
# @return [String]
|
34
|
-
|
34
|
+
property :name, String
|
35
35
|
|
36
36
|
# @!attribute [r] branch
|
37
37
|
# Bank office branch address, not normally required.
|
38
38
|
# @return [GOBL::Org::Address]
|
39
|
-
|
40
|
-
|
41
|
-
# Creates a new object from a hash of GOBL data
|
42
|
-
#
|
43
|
-
# @param data [Hash] a hash of GOBL data
|
44
|
-
#
|
45
|
-
# @return [CreditTransfer] the object created from the given data
|
46
|
-
def self.from_gobl!(data)
|
47
|
-
data = GOBL::Types::Hash[data]
|
48
|
-
|
49
|
-
new(
|
50
|
-
iban: data['iban'],
|
51
|
-
bic: data['bic'],
|
52
|
-
number: data['number'],
|
53
|
-
name: data['name'],
|
54
|
-
branch: data['branch'] ? GOBL::Org::Address.from_gobl!(data['branch']) : nil
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns a hash of GOBL data representing the current object
|
59
|
-
#
|
60
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
61
|
-
def to_gobl
|
62
|
-
{
|
63
|
-
'iban' => attributes[:iban],
|
64
|
-
'bic' => attributes[:bic],
|
65
|
-
'number' => attributes[:number],
|
66
|
-
'name' => attributes[:name],
|
67
|
-
'branch' => attributes[:branch]&.to_gobl
|
68
|
-
}.compact
|
69
|
-
end
|
70
|
-
|
71
|
-
# @!method self.new(attrs)
|
72
|
-
#
|
73
|
-
# Returns a {CreditTransfer} object from a given hash of attributes. Nested
|
74
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
75
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
76
|
-
# parameter.
|
77
|
-
#
|
78
|
-
# The `new` method will only allow to create a new object if all attributes
|
79
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
80
|
-
#
|
81
|
-
# @param attrs [Hash] the hash of attributes
|
82
|
-
#
|
83
|
-
# @return [CreditTransfer] the object corresponding to the given input
|
39
|
+
property :branch, GOBL::Org::Address
|
84
40
|
end
|
85
41
|
end
|
86
42
|
end
|
@@ -9,64 +9,24 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Pay
|
11
11
|
# DirectDebit defines the data that will be used to make the direct debit.
|
12
|
-
class DirectDebit < GOBL::
|
12
|
+
class DirectDebit < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL DirectDebit structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/pay/instructions#/$defs/DirectDebit'
|
15
15
|
|
16
16
|
# @!attribute [r] ref
|
17
17
|
# Unique identifier assigned by the payee for referencing the direct debit.
|
18
18
|
# @return [String]
|
19
|
-
|
19
|
+
property :ref, String
|
20
20
|
|
21
21
|
# @!attribute [r] creditor
|
22
22
|
# Unique banking reference that identifies the payee or seller assigned by the bank.
|
23
23
|
# @return [String]
|
24
|
-
|
24
|
+
property :creditor, String
|
25
25
|
|
26
26
|
# @!attribute [r] account
|
27
27
|
# Account identifier to be debited by the direct debit.
|
28
28
|
# @return [String]
|
29
|
-
|
30
|
-
|
31
|
-
# Creates a new object from a hash of GOBL data
|
32
|
-
#
|
33
|
-
# @param data [Hash] a hash of GOBL data
|
34
|
-
#
|
35
|
-
# @return [DirectDebit] the object created from the given data
|
36
|
-
def self.from_gobl!(data)
|
37
|
-
data = GOBL::Types::Hash[data]
|
38
|
-
|
39
|
-
new(
|
40
|
-
ref: data['ref'],
|
41
|
-
creditor: data['creditor'],
|
42
|
-
account: data['account']
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Returns a hash of GOBL data representing the current object
|
47
|
-
#
|
48
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
49
|
-
def to_gobl
|
50
|
-
{
|
51
|
-
'ref' => attributes[:ref],
|
52
|
-
'creditor' => attributes[:creditor],
|
53
|
-
'account' => attributes[:account]
|
54
|
-
}.compact
|
55
|
-
end
|
56
|
-
|
57
|
-
# @!method self.new(attrs)
|
58
|
-
#
|
59
|
-
# Returns a {DirectDebit} object from a given hash of attributes. Nested
|
60
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
61
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
62
|
-
# parameter.
|
63
|
-
#
|
64
|
-
# The `new` method will only allow to create a new object if all attributes
|
65
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
66
|
-
#
|
67
|
-
# @param attrs [Hash] the hash of attributes
|
68
|
-
#
|
69
|
-
# @return [DirectDebit] the object corresponding to the given input
|
29
|
+
property :account, String
|
70
30
|
end
|
71
31
|
end
|
72
32
|
end
|
data/lib/gobl/pay/due_date.rb
CHANGED
@@ -9,78 +9,36 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Pay
|
11
11
|
# DueDate contains an amount that should be paid by the given date.
|
12
|
-
class DueDate < GOBL::
|
12
|
+
class DueDate < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL DueDate structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/pay/terms#/$defs/DueDate'
|
15
15
|
|
16
16
|
# @!attribute [r] date
|
17
17
|
# When the payment is due.
|
18
18
|
# @return [GOBL::Cal::Date]
|
19
|
-
|
19
|
+
property :date, GOBL::Cal::Date
|
20
|
+
validates :date, presence: true
|
20
21
|
|
21
22
|
# @!attribute [r] notes
|
22
23
|
# Other details to take into account for the due date.
|
23
24
|
# @return [String]
|
24
|
-
|
25
|
+
property :notes, String
|
25
26
|
|
26
27
|
# @!attribute [r] amount
|
27
28
|
# How much needs to be paid by the date.
|
28
29
|
# @return [GOBL::Num::Amount]
|
29
|
-
|
30
|
+
property :amount, GOBL::Num::Amount
|
31
|
+
validates :amount, presence: true
|
30
32
|
|
31
33
|
# @!attribute [r] percent
|
32
34
|
# Percentage of the total that should be paid by the date.
|
33
35
|
# @return [GOBL::Num::Percentage]
|
34
|
-
|
36
|
+
property :percent, GOBL::Num::Percentage
|
35
37
|
|
36
38
|
# @!attribute [r] currency
|
37
39
|
# If different from the parent document's base currency.
|
38
40
|
# @return [GOBL::Currency::Code]
|
39
|
-
|
40
|
-
|
41
|
-
# Creates a new object from a hash of GOBL data
|
42
|
-
#
|
43
|
-
# @param data [Hash] a hash of GOBL data
|
44
|
-
#
|
45
|
-
# @return [DueDate] the object created from the given data
|
46
|
-
def self.from_gobl!(data)
|
47
|
-
data = GOBL::Types::Hash[data]
|
48
|
-
|
49
|
-
new(
|
50
|
-
date: GOBL::Cal::Date.from_gobl!(data['date']),
|
51
|
-
notes: data['notes'],
|
52
|
-
amount: data['amount'],
|
53
|
-
percent: data['percent'] || nil,
|
54
|
-
currency: data['currency'] ? GOBL::Currency::Code.from_gobl!(data['currency']) : nil
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Returns a hash of GOBL data representing the current object
|
59
|
-
#
|
60
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
61
|
-
def to_gobl
|
62
|
-
{
|
63
|
-
'date' => attributes[:date]&.to_gobl,
|
64
|
-
'notes' => attributes[:notes],
|
65
|
-
'amount' => attributes[:amount]&.to_gobl,
|
66
|
-
'percent' => attributes[:percent]&.to_gobl,
|
67
|
-
'currency' => attributes[:currency]&.to_gobl
|
68
|
-
}.compact
|
69
|
-
end
|
70
|
-
|
71
|
-
# @!method self.new(attrs)
|
72
|
-
#
|
73
|
-
# Returns a {DueDate} object from a given hash of attributes. Nested
|
74
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
75
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
76
|
-
# parameter.
|
77
|
-
#
|
78
|
-
# The `new` method will only allow to create a new object if all attributes
|
79
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
80
|
-
#
|
81
|
-
# @param attrs [Hash] the hash of attributes
|
82
|
-
#
|
83
|
-
# @return [DueDate] the object corresponding to the given input
|
41
|
+
property :currency, GOBL::Currency::Code
|
84
42
|
end
|
85
43
|
end
|
86
44
|
end
|
@@ -9,106 +9,55 @@
|
|
9
9
|
module GOBL
|
10
10
|
module Pay
|
11
11
|
# Instructions holds a set of instructions that determine how the payment has or should be made.
|
12
|
-
class Instructions < GOBL::
|
12
|
+
class Instructions < GOBL::Object
|
13
13
|
# The Schema ID of the GOBL Instructions structure
|
14
14
|
SCHEMA_ID = 'https://gobl.org/draft-0/pay/instructions'
|
15
15
|
|
16
16
|
# @!attribute [r] key
|
17
17
|
# How payment is expected or has been arranged to be collected
|
18
18
|
# @return [MethodKey]
|
19
|
-
|
19
|
+
property :key, MethodKey
|
20
|
+
validates :key, presence: true
|
20
21
|
|
21
22
|
# @!attribute [r] detail
|
22
23
|
# Optional text description of the payment method
|
23
24
|
# @return [String]
|
24
|
-
|
25
|
+
property :detail, String
|
25
26
|
|
26
27
|
# @!attribute [r] ref
|
27
28
|
# Remittance information, a text value used to link the payment with the invoice.
|
28
29
|
# @return [String]
|
29
|
-
|
30
|
+
property :ref, String
|
30
31
|
|
31
32
|
# @!attribute [r] credit_transfer
|
32
33
|
# Instructions for sending payment via a bank transfer.
|
33
34
|
# @return [Array<CreditTransfer>]
|
34
|
-
|
35
|
+
property :credit_transfer, [CreditTransfer]
|
35
36
|
|
36
37
|
# @!attribute [r] card
|
37
38
|
# Details of the payment that will be made via a credit or debit card.
|
38
39
|
# @return [Card]
|
39
|
-
|
40
|
+
property :card, Card
|
40
41
|
|
41
42
|
# @!attribute [r] direct_debit
|
42
43
|
# A group of terms that can be used by the customer or payer to consolidate direct debit payments.
|
43
44
|
# @return [DirectDebit]
|
44
|
-
|
45
|
+
property :direct_debit, DirectDebit
|
45
46
|
|
46
47
|
# @!attribute [r] online
|
47
48
|
# Array of online payment options
|
48
49
|
# @return [Array<Online>]
|
49
|
-
|
50
|
+
property :online, [Online]
|
50
51
|
|
51
52
|
# @!attribute [r] notes
|
52
53
|
# Any additional instructions that may be required to make the payment.
|
53
54
|
# @return [String]
|
54
|
-
|
55
|
+
property :notes, String
|
55
56
|
|
56
57
|
# @!attribute [r] meta
|
57
58
|
# Non-structured additional data that may be useful.
|
58
59
|
# @return [GOBL::Org::Meta]
|
59
|
-
|
60
|
-
|
61
|
-
# Creates a new object from a hash of GOBL data
|
62
|
-
#
|
63
|
-
# @param data [Hash] a hash of GOBL data
|
64
|
-
#
|
65
|
-
# @return [Instructions] the object created from the given data
|
66
|
-
def self.from_gobl!(data)
|
67
|
-
data = GOBL::Types::Hash[data]
|
68
|
-
|
69
|
-
new(
|
70
|
-
key: MethodKey.from_gobl!(data['key']),
|
71
|
-
detail: data['detail'],
|
72
|
-
ref: data['ref'],
|
73
|
-
credit_transfer: data['credit_transfer']&.map { |item| CreditTransfer.from_gobl!(item) },
|
74
|
-
card: data['card'] ? Card.from_gobl!(data['card']) : nil,
|
75
|
-
direct_debit: data['direct_debit'] ? DirectDebit.from_gobl!(data['direct_debit']) : nil,
|
76
|
-
online: data['online']&.map { |item| Online.from_gobl!(item) },
|
77
|
-
notes: data['notes'],
|
78
|
-
meta: data['meta'] ? GOBL::Org::Meta.from_gobl!(data['meta']) : nil
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
# Returns a hash of GOBL data representing the current object
|
83
|
-
#
|
84
|
-
# @return [Hash] the array of GOBL data that represents the current object
|
85
|
-
def to_gobl
|
86
|
-
{
|
87
|
-
'key' => attributes[:key]&.to_gobl,
|
88
|
-
'detail' => attributes[:detail],
|
89
|
-
'ref' => attributes[:ref],
|
90
|
-
'credit_transfer' => attributes[:credit_transfer]&.map { |item| item&.to_gobl },
|
91
|
-
'card' => attributes[:card]&.to_gobl,
|
92
|
-
'direct_debit' => attributes[:direct_debit]&.to_gobl,
|
93
|
-
'online' => attributes[:online]&.map { |item| item&.to_gobl },
|
94
|
-
'notes' => attributes[:notes],
|
95
|
-
'meta' => attributes[:meta]&.to_gobl
|
96
|
-
}.compact
|
97
|
-
end
|
98
|
-
|
99
|
-
# @!method self.new(attrs)
|
100
|
-
#
|
101
|
-
# Returns a {Instructions} object from a given hash of attributes. Nested
|
102
|
-
# attributes are supported: the constructor will instantiate the proper GOBL
|
103
|
-
# objects when nested hashes or arrays are given as part of the `attrs`
|
104
|
-
# parameter.
|
105
|
-
#
|
106
|
-
# The `new` method will only allow to create a new object if all attributes
|
107
|
-
# marked as mandatory and not calculated in the JSON schema are provided.
|
108
|
-
#
|
109
|
-
# @param attrs [Hash] the hash of attributes
|
110
|
-
#
|
111
|
-
# @return [Instructions] the object corresponding to the given input
|
60
|
+
property :meta, GOBL::Org::Meta
|
112
61
|
end
|
113
62
|
end
|
114
63
|
end
|