vatsense 0.1.2 → 0.3.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +57 -0
  4. data/lib/vatsense/client.rb +5 -0
  5. data/lib/vatsense/models/batch.rb +218 -0
  6. data/lib/vatsense/models/batch_delete_response.rb +41 -0
  7. data/lib/vatsense/models/batch_list_response.rb +51 -0
  8. data/lib/vatsense/models/batch_response.rb +23 -0
  9. data/lib/vatsense/models/batch_result.rb +133 -0
  10. data/lib/vatsense/models/batch_results_response.rb +42 -0
  11. data/lib/vatsense/models/create_invoice.rb +9 -1
  12. data/lib/vatsense/models/invoice.rb +11 -3
  13. data/lib/vatsense/models/invoice_create_params.rb +13 -1
  14. data/lib/vatsense/models/rate_list_params.rb +10 -1
  15. data/lib/vatsense/models/usage_retrieve_response.rb +4 -4
  16. data/lib/vatsense/models/validate_check_params.rb +48 -1
  17. data/lib/vatsense/models/validate_check_response.rb +70 -1
  18. data/lib/vatsense/models.rb +4 -0
  19. data/lib/vatsense/resources/batches.rb +249 -0
  20. data/lib/vatsense/resources/invoice.rb +8 -2
  21. data/lib/vatsense/resources/rates.rb +1 -1
  22. data/lib/vatsense/resources/validate.rb +7 -2
  23. data/lib/vatsense/version.rb +1 -1
  24. data/lib/vatsense/webhook.rb +104 -0
  25. data/lib/vatsense.rb +8 -0
  26. data/rbi/vatsense/models/create_invoice.rbi +9 -0
  27. data/rbi/vatsense/models/invoice.rbi +12 -2
  28. data/rbi/vatsense/models/invoice_create_params.rbi +17 -5
  29. data/rbi/vatsense/models/rate_list_params.rbi +13 -0
  30. data/rbi/vatsense/models/usage_retrieve_response.rbi +4 -4
  31. data/rbi/vatsense/models/validate_check_params.rbi +55 -0
  32. data/rbi/vatsense/models/validate_check_response.rbi +140 -0
  33. data/rbi/vatsense/resources/invoice.rbi +4 -0
  34. data/rbi/vatsense/resources/rates.rbi +2 -0
  35. data/rbi/vatsense/resources/validate.rbi +16 -1
  36. data/sig/vatsense/client.rbs +2 -0
  37. data/sig/vatsense/models/batch.rbs +57 -0
  38. data/sig/vatsense/models/batch_delete_response.rbs +17 -0
  39. data/sig/vatsense/models/batch_list_response.rbs +19 -0
  40. data/sig/vatsense/models/batch_response.rbs +10 -0
  41. data/sig/vatsense/models/batch_result.rbs +38 -0
  42. data/sig/vatsense/models/batch_results_response.rbs +17 -0
  43. data/sig/vatsense/models/create_invoice.rbs +6 -1
  44. data/sig/vatsense/models/invoice.rbs +8 -1
  45. data/sig/vatsense/models/invoice_create_params.rbs +13 -3
  46. data/sig/vatsense/models/rate_list_params.rbs +7 -1
  47. data/sig/vatsense/models/validate_check_params.rbs +37 -1
  48. data/sig/vatsense/models/validate_check_response.rbs +63 -0
  49. data/sig/vatsense/resources/batches.rbs +72 -0
  50. data/sig/vatsense/resources/invoice.rbs +2 -0
  51. data/sig/vatsense/resources/rates.rbs +1 -0
  52. data/sig/vatsense/resources/validate.rbs +6 -0
  53. data/sig/vatsense/webhook.rbs +28 -0
  54. metadata +18 -2
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vatsense
4
+ # Checks the `VatSense-Signature` header of webhook events.
5
+ #
6
+ # Every event is a signed JSON `POST` with a header such as
7
+ # `t=1793365200,v1=5257a8...`: `v1` is the hex HMAC-SHA256 of the timestamp, a
8
+ # full stop and the raw request body, keyed with the endpoint's signing secret
9
+ # (`whsec_...`). For 24 hours after a secret is rolled the header carries a
10
+ # second `v1`, so any match is accepted.
11
+ #
12
+ # @example
13
+ # event = Vatsense::Webhook.construct_event(
14
+ # request.raw_post,
15
+ # request.headers[Vatsense::Webhook::SIGNATURE_HEADER],
16
+ # ENV.fetch("VATSENSE_WEBHOOK_SECRET")
17
+ # )
18
+ module Webhook
19
+ # The name of the header that carries the signature.
20
+ SIGNATURE_HEADER = "VatSense-Signature"
21
+
22
+ # Events whose timestamp is more than this many seconds from now are refused.
23
+ DEFAULT_TOLERANCE = 300
24
+
25
+ # The event's signature is missing, malformed, too old or does not match.
26
+ class SignatureError < Vatsense::Errors::Error; end
27
+
28
+ class << self
29
+ # Check an event's signature header against its raw body, exactly as received.
30
+ #
31
+ # @param payload [String] the raw request body
32
+ # @param header [String, nil] the value of the `VatSense-Signature` header
33
+ # @param secret [String] the endpoint's signing secret, starting `whsec_`
34
+ # @param tolerance [Integer, nil] refuse events signed more than this many seconds ago; nil skips the check
35
+ # @param now [Integer, nil] the current Unix time, for tests
36
+ #
37
+ # @raise [Vatsense::Webhook::SignatureError]
38
+ # @return [true]
39
+ def verify_signature(payload, header, secret, tolerance: DEFAULT_TOLERANCE, now: nil)
40
+ raise SignatureError, "The VatSense-Signature header is missing." if header.nil? || header.empty?
41
+ raise SignatureError, "No signing secret was given." if secret.nil? || secret.empty?
42
+
43
+ timestamp = nil
44
+ signatures = []
45
+ header.split(",").each do |part|
46
+ key, value = part.strip.split("=", 2)
47
+ next if value.nil?
48
+
49
+ case key
50
+ in "t"
51
+ raise SignatureError, "The signature header's timestamp is not a number." unless value.match?(/\A\d+\z/)
52
+
53
+ timestamp = Integer(value, 10)
54
+ in "v1"
55
+ signatures << value unless value.empty?
56
+ else
57
+ nil
58
+ end
59
+ end
60
+ raise SignatureError, "The signature header has no timestamp." if timestamp.nil?
61
+ raise SignatureError, "The signature header has no v1 signature." if signatures.empty?
62
+
63
+ current = now || Time.now.to_i
64
+ if !tolerance.nil? && (current - timestamp).abs > tolerance
65
+ raise SignatureError, "The event's timestamp is outside the tolerance."
66
+ end
67
+
68
+ expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{timestamp}.#{payload}")
69
+ return true if signatures.any? { secure_compare(expected, _1) }
70
+
71
+ raise SignatureError, "No signature matches the payload."
72
+ end
73
+
74
+ # Check the signature, then return the event (`id`, `type`, `created`,
75
+ # `livemode`, `data`) as a Hash with symbol keys.
76
+ #
77
+ # @param payload [String]
78
+ # @param header [String, nil]
79
+ # @param secret [String]
80
+ # @param tolerance [Integer, nil]
81
+ # @param now [Integer, nil]
82
+ #
83
+ # @raise [Vatsense::Webhook::SignatureError]
84
+ # @return [Hash{Symbol=>Object}]
85
+ def construct_event(payload, header, secret, tolerance: DEFAULT_TOLERANCE, now: nil)
86
+ verify_signature(payload, header, secret, tolerance: tolerance, now: now)
87
+ event = JSON.parse(payload, symbolize_names: true)
88
+ raise SignatureError, "The payload is not a JSON object." unless event.is_a?(Hash)
89
+
90
+ event
91
+ rescue JSON::ParserError
92
+ raise SignatureError, "The payload is not JSON."
93
+ end
94
+
95
+ private
96
+
97
+ def secure_compare(expected, given)
98
+ return false unless expected.bytesize == given.bytesize
99
+
100
+ OpenSSL.fixed_length_secure_compare(expected, given)
101
+ end
102
+ end
103
+ end
104
+ end
data/lib/vatsense.rb CHANGED
@@ -55,6 +55,12 @@ require_relative "vatsense/client"
55
55
  require_relative "vatsense/models/invoice/invoice_item_input"
56
56
  require_relative "vatsense/models/create_invoice"
57
57
  require_relative "vatsense/models/tax_rate"
58
+ require_relative "vatsense/models/batch"
59
+ require_relative "vatsense/models/batch_delete_response"
60
+ require_relative "vatsense/models/batch_list_response"
61
+ require_relative "vatsense/models/batch_response"
62
+ require_relative "vatsense/models/batch_result"
63
+ require_relative "vatsense/models/batch_results_response"
58
64
  require_relative "vatsense/models/country"
59
65
  require_relative "vatsense/models/country_list_params"
60
66
  require_relative "vatsense/models/country_list_provinces_params"
@@ -103,6 +109,7 @@ require_relative "vatsense/models/validate_check_params"
103
109
  require_relative "vatsense/models/validate_check_response"
104
110
  require_relative "vatsense/models/vat_price"
105
111
  require_relative "vatsense/models"
112
+ require_relative "vatsense/resources/batches"
106
113
  require_relative "vatsense/resources/countries"
107
114
  require_relative "vatsense/resources/currency"
108
115
  require_relative "vatsense/resources/invoice"
@@ -111,3 +118,4 @@ require_relative "vatsense/resources/rates"
111
118
  require_relative "vatsense/resources/sandbox"
112
119
  require_relative "vatsense/resources/usage"
113
120
  require_relative "vatsense/resources/validate"
121
+ require_relative "vatsense/webhook"
@@ -77,6 +77,12 @@ module Vatsense
77
77
  sig { params(notes: String).void }
78
78
  attr_writer :notes
79
79
 
80
+ # For a credit note: the ID of your own sale invoice it credits. Only a `refund`
81
+ # can name one; anything else gets `400` "Invalid Original Invoice ID". The credit
82
+ # note is then headed "Credit note". Used on create only.
83
+ sig { returns(T.nilable(String)) }
84
+ attr_accessor :original_invoice_id
85
+
80
86
  # Pad the auto-generated invoice number with leading zeros to this length.
81
87
  sig { returns(T.nilable(Integer)) }
82
88
  attr_reader :pad_invoice_number
@@ -127,6 +133,7 @@ module Vatsense
127
133
  is_copy: T::Boolean,
128
134
  is_reverse_charge: T::Boolean,
129
135
  notes: String,
136
+ original_invoice_id: T.nilable(String),
130
137
  pad_invoice_number: Integer,
131
138
  serial: String,
132
139
  tax_type: Vatsense::CreateInvoice::TaxType::OrSymbol,
@@ -156,6 +163,7 @@ module Vatsense
156
163
  is_reverse_charge: nil,
157
164
  # Any additional notes for the invoice.
158
165
  notes: nil,
166
+ original_invoice_id: nil,
159
167
  # Pad the auto-generated invoice number with leading zeros to this length.
160
168
  pad_invoice_number: nil,
161
169
  # A serial prepended to the auto-generated invoice number. Each unique serial has
@@ -185,6 +193,7 @@ module Vatsense
185
193
  is_copy: T::Boolean,
186
194
  is_reverse_charge: T::Boolean,
187
195
  notes: String,
196
+ original_invoice_id: T.nilable(String),
188
197
  pad_invoice_number: Integer,
189
198
  serial: String,
190
199
  tax_type: Vatsense::CreateInvoice::TaxType::OrSymbol,
@@ -68,7 +68,7 @@ module Vatsense
68
68
  sig { params(invoice_number: String).void }
69
69
  attr_writer :invoice_number
70
70
 
71
- # Unique URL to view the invoice. Append "/pdf" to download a PDF copy.
71
+ # Unique, unguessable URL to view the invoice. Append "/pdf" for a PDF copy.
72
72
  sig { returns(T.nilable(String)) }
73
73
  attr_reader :invoice_url
74
74
 
@@ -110,6 +110,13 @@ module Vatsense
110
110
  sig { params(object: Vatsense::InvoiceAPI::Object::OrSymbol).void }
111
111
  attr_writer :object
112
112
 
113
+ # On a credit note that names the sale invoice it credits: that invoice's ID.
114
+ sig { returns(T.nilable(String)) }
115
+ attr_reader :original_invoice_id
116
+
117
+ sig { params(original_invoice_id: String).void }
118
+ attr_writer :original_invoice_id
119
+
113
120
  sig { returns(T.nilable(String)) }
114
121
  attr_reader :tax_point
115
122
 
@@ -164,6 +171,7 @@ module Vatsense
164
171
  notes: T.nilable(String),
165
172
  num_items: Integer,
166
173
  object: Vatsense::InvoiceAPI::Object::OrSymbol,
174
+ original_invoice_id: String,
167
175
  tax_point: String,
168
176
  tax_type: Vatsense::InvoiceAPI::TaxType::OrSymbol,
169
177
  totals: Vatsense::InvoiceAPI::Totals::OrHash,
@@ -182,7 +190,7 @@ module Vatsense
182
190
  date: nil,
183
191
  has_vat: nil,
184
192
  invoice_number: nil,
185
- # Unique URL to view the invoice. Append "/pdf" to download a PDF copy.
193
+ # Unique, unguessable URL to view the invoice. Append "/pdf" for a PDF copy.
186
194
  invoice_url: nil,
187
195
  is_copy: nil,
188
196
  is_reverse_charge: nil,
@@ -190,6 +198,7 @@ module Vatsense
190
198
  notes: nil,
191
199
  num_items: nil,
192
200
  object: nil,
201
+ original_invoice_id: nil,
193
202
  tax_point: nil,
194
203
  tax_type: nil,
195
204
  totals: nil,
@@ -218,6 +227,7 @@ module Vatsense
218
227
  notes: T.nilable(String),
219
228
  num_items: Integer,
220
229
  object: Vatsense::InvoiceAPI::Object::TaggedSymbol,
230
+ original_invoice_id: String,
221
231
  tax_point: String,
222
232
  tax_type: Vatsense::InvoiceAPI::TaxType::TaggedSymbol,
223
233
  totals: Vatsense::InvoiceAPI::Totals,
@@ -11,15 +11,27 @@ module Vatsense
11
11
  T.any(Vatsense::InvoiceCreateParams, Vatsense::Internal::AnyHash)
12
12
  end
13
13
 
14
+ # Sent as the `Idempotency-Key` header to retry a create safely.
15
+ sig { returns(T.nilable(String)) }
16
+ attr_reader :idempotency_key
17
+
18
+ sig { params(idempotency_key: String).void }
19
+ attr_writer :idempotency_key
20
+
14
21
  sig do
15
- params(request_options: Vatsense::RequestOptions::OrHash).returns(
16
- T.attached_class
17
- )
22
+ params(
23
+ idempotency_key: String,
24
+ request_options: Vatsense::RequestOptions::OrHash
25
+ ).returns(T.attached_class)
18
26
  end
19
- def self.new(request_options: {})
27
+ def self.new(idempotency_key: nil, request_options: {})
20
28
  end
21
29
 
22
- sig { override.returns({ request_options: Vatsense::RequestOptions }) }
30
+ sig do
31
+ override.returns(
32
+ { idempotency_key: String, request_options: Vatsense::RequestOptions }
33
+ )
34
+ end
23
35
  def to_hash
24
36
  end
25
37
  end
@@ -41,12 +41,23 @@ module Vatsense
41
41
  sig { params(period: Time).void }
42
42
  attr_writer :period
43
43
 
44
+ # Whether to list province and territory rates (rate objects that carry a
45
+ # `province` property) in each country's `other` list. Pass false to leave them
46
+ # out, so only country-wide rates are listed; true, or omitting the parameter,
47
+ # lists them as before. The `standard` rate is always the country-wide one.
48
+ sig { returns(T.nilable(T::Boolean)) }
49
+ attr_reader :provinces
50
+
51
+ sig { params(provinces: T::Boolean).void }
52
+ attr_writer :provinces
53
+
44
54
  sig do
45
55
  params(
46
56
  country_code: String,
47
57
  eu: T::Boolean,
48
58
  ip_address: String,
49
59
  period: Time,
60
+ provinces: T::Boolean,
50
61
  request_options: Vatsense::RequestOptions::OrHash
51
62
  ).returns(T.attached_class)
52
63
  end
@@ -61,6 +72,7 @@ module Vatsense
61
72
  # A historical date to retrieve rates for (format "YYYY-MM-DD HH:MM:SS"). Must be
62
73
  # a past date.
63
74
  period: nil,
75
+ provinces: nil,
64
76
  request_options: {}
65
77
  )
66
78
  end
@@ -72,6 +84,7 @@ module Vatsense
72
84
  eu: T::Boolean,
73
85
  ip_address: String,
74
86
  period: Time,
87
+ provinces: T::Boolean,
75
88
  request_options: Vatsense::RequestOptions
76
89
  }
77
90
  )
@@ -112,14 +112,14 @@ module Vatsense
112
112
  sig { params(remaining: Integer).void }
113
113
  attr_writer :remaining
114
114
 
115
- # Total requests allowed on your plan.
115
+ # Requests available in the current billing period.
116
116
  sig { returns(T.nilable(Integer)) }
117
117
  attr_reader :total
118
118
 
119
119
  sig { params(total: Integer).void }
120
120
  attr_writer :total
121
121
 
122
- # Requests used in the last 30 days.
122
+ # Requests used so far in the current billing period.
123
123
  sig { returns(T.nilable(Integer)) }
124
124
  attr_reader :used
125
125
 
@@ -134,9 +134,9 @@ module Vatsense
134
134
  def self.new(
135
135
  # Requests remaining before the limit is reached.
136
136
  remaining: nil,
137
- # Total requests allowed on your plan.
137
+ # Requests available in the current billing period.
138
138
  total: nil,
139
- # Requests used in the last 30 days.
139
+ # Requests used so far in the current billing period.
140
140
  used: nil
141
141
  )
142
142
  end
@@ -19,6 +19,46 @@ module Vatsense
19
19
  sig { params(eori_number: String).void }
20
20
  attr_writer :eori_number
21
21
 
22
+ # The whole address you hold, as one line, matched against the registered
23
+ # address.
24
+ sig { returns(T.nilable(String)) }
25
+ attr_reader :match_address
26
+
27
+ sig { params(match_address: String).void }
28
+ attr_writer :match_address
29
+
30
+ # The town or city you hold, looked for in the registered address.
31
+ sig { returns(T.nilable(String)) }
32
+ attr_reader :match_city
33
+
34
+ sig { params(match_city: String).void }
35
+ attr_writer :match_city
36
+
37
+ # The company name you hold, matched against the registered name. Legal forms
38
+ # such as Ltd or GmbH, accents, punctuation and word order are ignored. Sending
39
+ # any `match_` parameter adds `match` to the response; matching costs nothing
40
+ # extra.
41
+ sig { returns(T.nilable(String)) }
42
+ attr_reader :match_company_name
43
+
44
+ sig { params(match_company_name: String).void }
45
+ attr_writer :match_company_name
46
+
47
+ # The postcode you hold, looked for in the registered address. Spaces are
48
+ # ignored.
49
+ sig { returns(T.nilable(String)) }
50
+ attr_reader :match_postcode
51
+
52
+ sig { params(match_postcode: String).void }
53
+ attr_writer :match_postcode
54
+
55
+ # The street line you hold, looked for in the registered address.
56
+ sig { returns(T.nilable(String)) }
57
+ attr_reader :match_street
58
+
59
+ sig { params(match_street: String).void }
60
+ attr_writer :match_street
61
+
22
62
  # Your own VAT number. If supplied, the response will include a unique
23
63
  # consultation number issued by the relevant authority (VIES or HMRC). Must
24
64
  # include the leading 2-character country code.
@@ -42,6 +82,11 @@ module Vatsense
42
82
  sig do
43
83
  params(
44
84
  eori_number: String,
85
+ match_address: String,
86
+ match_city: String,
87
+ match_company_name: String,
88
+ match_postcode: String,
89
+ match_street: String,
45
90
  requester_vat_number: String,
46
91
  vat_number: String,
47
92
  request_options: Vatsense::RequestOptions::OrHash
@@ -51,6 +96,11 @@ module Vatsense
51
96
  # The EORI number to validate. Must include the leading 2-character country code
52
97
  # (e.g. "GB123456789123"). UK and EU only.
53
98
  eori_number: nil,
99
+ match_address: nil,
100
+ match_city: nil,
101
+ match_company_name: nil,
102
+ match_postcode: nil,
103
+ match_street: nil,
54
104
  # Your own VAT number. If supplied, the response will include a unique
55
105
  # consultation number issued by the relevant authority (VIES or HMRC). Must
56
106
  # include the leading 2-character country code.
@@ -69,6 +119,11 @@ module Vatsense
69
119
  override.returns(
70
120
  {
71
121
  eori_number: String,
122
+ match_address: String,
123
+ match_city: String,
124
+ match_company_name: String,
125
+ match_postcode: String,
126
+ match_street: String,
72
127
  requester_vat_number: String,
73
128
  vat_number: String,
74
129
  request_options: Vatsense::RequestOptions
@@ -87,6 +87,19 @@ module Vatsense
87
87
  sig { returns(T.nilable(String)) }
88
88
  attr_accessor :consultation_number
89
89
 
90
+ # Only when a `match_` parameter was sent.
91
+ sig do
92
+ returns(T.nilable(Vatsense::Models::ValidateCheckResponse::Data::Match))
93
+ end
94
+ attr_reader :match
95
+
96
+ sig do
97
+ params(
98
+ match: Vatsense::Models::ValidateCheckResponse::Data::Match::OrHash
99
+ ).void
100
+ end
101
+ attr_writer :match
102
+
90
103
  # Whether the VAT/EORI number is valid.
91
104
  sig { returns(T.nilable(T::Boolean)) }
92
105
  attr_reader :valid
@@ -102,6 +115,7 @@ module Vatsense
102
115
  Vatsense::Models::ValidateCheckResponse::Data::Company::EoriValidationCompany::OrHash
103
116
  ),
104
117
  consultation_number: T.nilable(String),
118
+ match: Vatsense::Models::ValidateCheckResponse::Data::Match::OrHash,
105
119
  valid: T::Boolean
106
120
  ).returns(T.attached_class)
107
121
  end
@@ -110,6 +124,8 @@ module Vatsense
110
124
  # Official consultation number (only returned when requester_vat_number is
111
125
  # provided).
112
126
  consultation_number: nil,
127
+ # Only when a `match_` parameter was sent.
128
+ match: nil,
113
129
  # Whether the VAT/EORI number is valid.
114
130
  valid: nil
115
131
  )
@@ -121,6 +137,7 @@ module Vatsense
121
137
  company:
122
138
  Vatsense::Models::ValidateCheckResponse::Data::Company::Variants,
123
139
  consultation_number: T.nilable(String),
140
+ match: Vatsense::Models::ValidateCheckResponse::Data::Match,
124
141
  valid: T::Boolean
125
142
  }
126
143
  )
@@ -128,6 +145,129 @@ module Vatsense
128
145
  def to_hash
129
146
  end
130
147
 
148
+ class Match < Vatsense::Internal::Type::BaseModel
149
+ OrHash =
150
+ T.type_alias do
151
+ T.any(
152
+ Vatsense::Models::ValidateCheckResponse::Data::Match,
153
+ Vatsense::Internal::AnyHash
154
+ )
155
+ end
156
+
157
+ # One entry for each detail sent (company_name, address, street, postcode,
158
+ # city).
159
+ sig do
160
+ returns(
161
+ T.nilable(
162
+ T::Hash[
163
+ Symbol,
164
+ Vatsense::Models::ValidateCheckResponse::Data::Match::Field
165
+ ]
166
+ )
167
+ )
168
+ end
169
+ attr_reader :fields
170
+
171
+ sig do
172
+ params(
173
+ fields:
174
+ T::Hash[
175
+ Symbol,
176
+ Vatsense::Models::ValidateCheckResponse::Data::Match::Field::OrHash
177
+ ]
178
+ ).void
179
+ end
180
+ attr_writer :fields
181
+
182
+ # likely, possible, unlikely or not_applicable.
183
+ sig { returns(T.nilable(String)) }
184
+ attr_reader :result
185
+
186
+ sig { params(result: String).void }
187
+ attr_writer :result
188
+
189
+ # The average of the details sent, with the name counting twice.
190
+ sig { returns(T.nilable(Integer)) }
191
+ attr_accessor :score
192
+
193
+ sig do
194
+ params(
195
+ fields:
196
+ T::Hash[
197
+ Symbol,
198
+ Vatsense::Models::ValidateCheckResponse::Data::Match::Field::OrHash
199
+ ],
200
+ result: String,
201
+ score: T.nilable(Integer)
202
+ ).returns(T.attached_class)
203
+ end
204
+ def self.new(fields: nil, result: nil, score: nil)
205
+ end
206
+
207
+ sig do
208
+ override.returns(
209
+ {
210
+ fields:
211
+ T::Hash[
212
+ Symbol,
213
+ Vatsense::Models::ValidateCheckResponse::Data::Match::Field
214
+ ],
215
+ result: String,
216
+ score: T.nilable(Integer)
217
+ }
218
+ )
219
+ end
220
+ def to_hash
221
+ end
222
+
223
+ class Field < Vatsense::Internal::Type::BaseModel
224
+ OrHash =
225
+ T.type_alias do
226
+ T.any(
227
+ Vatsense::Models::ValidateCheckResponse::Data::Match::Field,
228
+ Vatsense::Internal::AnyHash
229
+ )
230
+ end
231
+
232
+ # match, partial, no_match or not_applicable.
233
+ sig { returns(T.nilable(String)) }
234
+ attr_reader :result
235
+
236
+ sig { params(result: String).void }
237
+ attr_writer :result
238
+
239
+ sig { returns(T.nilable(Integer)) }
240
+ attr_accessor :score
241
+
242
+ # VIES's own answer for that detail on a live EU check; nil when VIES said
243
+ # nothing.
244
+ sig { returns(T.nilable(String)) }
245
+ attr_accessor :vies
246
+
247
+ sig do
248
+ params(
249
+ result: String,
250
+ score: T.nilable(Integer),
251
+ vies: T.nilable(String)
252
+ ).returns(T.attached_class)
253
+ end
254
+ def self.new(result: nil, score: nil, vies: nil)
255
+ end
256
+
257
+ sig do
258
+ override.returns(
259
+ {
260
+ result: String,
261
+ score: T.nilable(Integer),
262
+ vies: T.nilable(String)
263
+ }
264
+ )
265
+ end
266
+ def to_hash
267
+ end
268
+ end
269
+ end
270
+
131
271
  module Company
132
272
  extend Vatsense::Internal::Type::Union
133
273
 
@@ -26,6 +26,8 @@ module Vatsense
26
26
  is_copy: T::Boolean,
27
27
  is_reverse_charge: T::Boolean,
28
28
  notes: String,
29
+ original_invoice_id: T.nilable(String),
30
+ idempotency_key: String,
29
31
  pad_invoice_number: Integer,
30
32
  serial: String,
31
33
  tax_type: Vatsense::CreateInvoice::TaxType::OrSymbol,
@@ -56,6 +58,8 @@ module Vatsense
56
58
  is_reverse_charge: nil,
57
59
  # Any additional notes for the invoice.
58
60
  notes: nil,
61
+ original_invoice_id: nil,
62
+ idempotency_key: nil,
59
63
  # Pad the auto-generated invoice number with leading zeros to this length.
60
64
  pad_invoice_number: nil,
61
65
  # A serial prepended to the auto-generated invoice number. Each unique serial has
@@ -15,6 +15,7 @@ module Vatsense
15
15
  eu: T::Boolean,
16
16
  ip_address: String,
17
17
  period: Time,
18
+ provinces: T::Boolean,
18
19
  request_options: Vatsense::RequestOptions::OrHash
19
20
  ).returns(Vatsense::Models::RateListResponse)
20
21
  end
@@ -29,6 +30,7 @@ module Vatsense
29
30
  # A historical date to retrieve rates for (format "YYYY-MM-DD HH:MM:SS"). Must be
30
31
  # a past date.
31
32
  period: nil,
33
+ provinces: nil,
32
34
  request_options: {}
33
35
  )
34
36
  end
@@ -13,12 +13,22 @@ module Vatsense
13
13
  # **EORI validation** checks against UK and EU records only.
14
14
  #
15
15
  # If the external validation service is temporarily unavailable, the API returns a
16
- # `412` error and the request does not count against your usage quota.
16
+ # `412` error and the request does not count against your usage quota. It also
17
+ # returns the `412`, uncounted, when a check takes longer than 55 seconds for a
18
+ # number checked with VIES or the EU EORI service, or 25 seconds for any other.
19
+ # With a webhook endpoint taking `validation.completed`, a number that got the
20
+ # `412` keeps being checked and the answer is sent by webhook
21
+ # (https://vatsense.com/documentation#webhooks).
17
22
  #
18
23
  # Provide either `vat_number` or `eori_number`, but not both.
19
24
  sig do
20
25
  params(
21
26
  eori_number: String,
27
+ match_address: String,
28
+ match_city: String,
29
+ match_company_name: String,
30
+ match_postcode: String,
31
+ match_street: String,
22
32
  requester_vat_number: String,
23
33
  vat_number: String,
24
34
  request_options: Vatsense::RequestOptions::OrHash
@@ -28,6 +38,11 @@ module Vatsense
28
38
  # The EORI number to validate. Must include the leading 2-character country code
29
39
  # (e.g. "GB123456789123"). UK and EU only.
30
40
  eori_number: nil,
41
+ match_address: nil,
42
+ match_city: nil,
43
+ match_company_name: nil,
44
+ match_postcode: nil,
45
+ match_street: nil,
31
46
  # Your own VAT number. If supplied, the response will include a unique
32
47
  # consultation number issued by the relevant authority (VIES or HMRC). Must
33
48
  # include the leading 2-character country code.
@@ -26,6 +26,8 @@ module Vatsense
26
26
 
27
27
  attr_reader sandbox: Vatsense::Resources::Sandbox
28
28
 
29
+ attr_reader batches: Vatsense::Resources::Batches
30
+
29
31
  private def auth_headers: (
30
32
  security: { basic_auth: bool }
31
33
  ) -> ::Hash[String, String]