moss_generator 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +23 -5
- data/lib/moss_generator/stripe.rb +6 -5
- data/lib/moss_generator/stripe_charge_row.rb +42 -11
- data/lib/moss_generator/version.rb +1 -1
- data/moss_generator.gemspec +3 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b18873ce424594b2a4cafe9dd26d23f6688352561e59820aa7f8229911cc4857
|
4
|
+
data.tar.gz: cc35447764a10b96f53035af22e5429809ad7ea10dc7adcb835089e0e69b5024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ff56e1b296d590a99db183d73cd1b4ebb80efbfaaccceb4df5862bc7a01da9d06f50340fe5a941a3c463a556af1293b5dbc6a500938b6bb52b264c54d53af04
|
7
|
+
data.tar.gz: 6ec37d480db38da5abc948afd423928741e25b0c4273dbb02c8e373fe74ca697d04f86cc2e8c424061ae536c4697b6790a1910fff46ffef7fd33841380b68234
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
moss_generator (0.
|
4
|
+
moss_generator (0.4.0)
|
5
|
+
countries (~> 3.1)
|
5
6
|
money (~> 6.14)
|
6
7
|
valvat (~> 1.1)
|
7
8
|
|
@@ -15,23 +16,37 @@ GEM
|
|
15
16
|
nokogiri
|
16
17
|
ast (2.4.1)
|
17
18
|
builder (3.2.4)
|
18
|
-
|
19
|
+
byebug (11.1.3)
|
20
|
+
coderay (1.1.3)
|
21
|
+
concurrent-ruby (1.1.8)
|
22
|
+
countries (3.1.0)
|
23
|
+
i18n_data (~> 0.11.0)
|
24
|
+
sixarm_ruby_unaccent (~> 1.1)
|
25
|
+
unicode_utils (~> 1.4)
|
19
26
|
diff-lcs (1.4.4)
|
20
27
|
gyoku (1.3.1)
|
21
28
|
builder (>= 2.1.2)
|
22
29
|
httpi (2.4.5)
|
23
30
|
rack
|
24
31
|
socksify
|
25
|
-
i18n (1.8.
|
32
|
+
i18n (1.8.10)
|
26
33
|
concurrent-ruby (~> 1.0)
|
27
|
-
|
34
|
+
i18n_data (0.11.0)
|
35
|
+
method_source (1.0.0)
|
36
|
+
money (6.14.1)
|
28
37
|
i18n (>= 0.6.4, <= 2)
|
29
|
-
nokogiri (1.11.
|
38
|
+
nokogiri (1.11.3-x86_64-darwin)
|
30
39
|
racc (~> 1.4)
|
31
40
|
nori (2.6.0)
|
32
41
|
parallel (1.20.1)
|
33
42
|
parser (3.0.0.0)
|
34
43
|
ast (~> 2.4.1)
|
44
|
+
pry (0.13.1)
|
45
|
+
coderay (~> 1.1)
|
46
|
+
method_source (~> 1.0)
|
47
|
+
pry-byebug (3.9.0)
|
48
|
+
byebug (~> 11.0)
|
49
|
+
pry (~> 0.13.0)
|
35
50
|
public_suffix (4.0.6)
|
36
51
|
racc (1.5.2)
|
37
52
|
rack (2.2.3)
|
@@ -80,8 +95,10 @@ GEM
|
|
80
95
|
nokogiri (>= 1.8.1)
|
81
96
|
nori (~> 2.4)
|
82
97
|
wasabi (~> 3.4)
|
98
|
+
sixarm_ruby_unaccent (1.2.0)
|
83
99
|
socksify (1.7.1)
|
84
100
|
unicode-display_width (1.7.0)
|
101
|
+
unicode_utils (1.4.0)
|
85
102
|
valvat (1.1.0)
|
86
103
|
savon (>= 2.3.0)
|
87
104
|
wasabi (3.6.1)
|
@@ -94,6 +111,7 @@ PLATFORMS
|
|
94
111
|
|
95
112
|
DEPENDENCIES
|
96
113
|
moss_generator!
|
114
|
+
pry-byebug
|
97
115
|
rake (~> 13.0)
|
98
116
|
rspec (~> 3.0)
|
99
117
|
rubocop (~> 1.7)
|
@@ -8,17 +8,18 @@ module MossGenerator
|
|
8
8
|
class Stripe
|
9
9
|
class NoTurnoverCountryError < StandardError; end
|
10
10
|
|
11
|
-
attr_reader :charges, :vat_number, :period, :year
|
11
|
+
attr_reader :charges, :vat_number, :period, :year, :rates
|
12
12
|
|
13
|
-
def initialize(charges, vat_number, period, year)
|
13
|
+
def initialize(charges, vat_number, period, year, rates)
|
14
14
|
@charges = charges
|
15
15
|
@vat_number = vat_number
|
16
16
|
@period = period
|
17
17
|
@year = year
|
18
|
+
@rates = rates
|
18
19
|
end
|
19
20
|
|
20
|
-
def self.call(charges, vat_number, period, year)
|
21
|
-
new(charges, vat_number, period, year).call
|
21
|
+
def self.call(charges, vat_number, period, year, rates)
|
22
|
+
new(charges, vat_number, period, year, rates).call
|
22
23
|
end
|
23
24
|
|
24
25
|
def call
|
@@ -45,7 +46,7 @@ module MossGenerator
|
|
45
46
|
|
46
47
|
def group_charges_rows
|
47
48
|
charges_rows = charges.map do |charge|
|
48
|
-
charge_row = MossGenerator::StripeChargeRow.new(charge)
|
49
|
+
charge_row = MossGenerator::StripeChargeRow.new(charge, rates)
|
49
50
|
next if charge_row.skippable?
|
50
51
|
|
51
52
|
charge_row
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'moss_generator/vat_rate'
|
4
4
|
require 'money'
|
5
5
|
require 'valvat/local'
|
6
|
+
require 'countries'
|
6
7
|
|
7
8
|
module MossGenerator
|
8
9
|
# Parse charge data from single Stripe charge
|
@@ -11,12 +12,13 @@ module MossGenerator
|
|
11
12
|
|
12
13
|
class NoVatRateForCountryError < StandardError; end
|
13
14
|
|
14
|
-
class
|
15
|
+
class NoExchangeRateForCurrencyOrDateError < StandardError; end
|
15
16
|
|
16
|
-
attr_reader :charge
|
17
|
+
attr_reader :charge, :rates
|
17
18
|
|
18
|
-
def initialize(charge)
|
19
|
+
def initialize(charge, rates)
|
19
20
|
@charge = charge
|
21
|
+
@rates = rates
|
20
22
|
end
|
21
23
|
|
22
24
|
def country_code
|
@@ -44,7 +46,12 @@ module MossGenerator
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def skippable?
|
47
|
-
|
49
|
+
not_completed? ||
|
50
|
+
company? ||
|
51
|
+
fetch_country_code.nil? ||
|
52
|
+
sold_outside_of_eu? ||
|
53
|
+
swedish_charge? ||
|
54
|
+
refunded?
|
48
55
|
end
|
49
56
|
|
50
57
|
private
|
@@ -55,6 +62,14 @@ module MossGenerator
|
|
55
62
|
Valvat::Syntax.validate(charge.dig('metadata', 'vat_number'))
|
56
63
|
end
|
57
64
|
|
65
|
+
def sold_outside_of_eu?
|
66
|
+
ISO3166::Country.new(fetch_country_code).in_eu? ? false : true
|
67
|
+
end
|
68
|
+
|
69
|
+
def swedish_charge?
|
70
|
+
fetch_country_code.casecmp?('SE')
|
71
|
+
end
|
72
|
+
|
58
73
|
def not_completed?
|
59
74
|
charge['status'] != 'succeeded'
|
60
75
|
end
|
@@ -63,13 +78,6 @@ module MossGenerator
|
|
63
78
|
charge['refunded']
|
64
79
|
end
|
65
80
|
|
66
|
-
def amount_with_vat
|
67
|
-
return charge['amount'] if charge['currency'].casecmp?('eur')
|
68
|
-
return if skippable?
|
69
|
-
|
70
|
-
raise NotInEuroError, "charge: #{charge}"
|
71
|
-
end
|
72
|
-
|
73
81
|
def percent_without_vat
|
74
82
|
1 / (vat_rate_calculatable_percent + 1)
|
75
83
|
end
|
@@ -81,5 +89,28 @@ module MossGenerator
|
|
81
89
|
def fetch_country_code
|
82
90
|
charge.dig('payment_method_details', 'card', 'country')
|
83
91
|
end
|
92
|
+
|
93
|
+
def amount_with_vat
|
94
|
+
return if skippable?
|
95
|
+
return charge['amount'] if charge['currency'].casecmp?('eur')
|
96
|
+
|
97
|
+
exchanged_amount = calculate_amount_from_rate
|
98
|
+
return exchanged_amount unless exchanged_amount.nil?
|
99
|
+
|
100
|
+
raise NoExchangeRateForCurrencyOrDateError, "charge: #{charge}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def calculate_amount_from_rate
|
104
|
+
# Have to reverse the rate. The base rate is in EUR, so if we have a rate
|
105
|
+
# to SEK, the rate will represent the rate from EUR to SEK, but we need
|
106
|
+
# the other way around.
|
107
|
+
date = Time.at(charge['created']).to_date.to_s
|
108
|
+
currency = charge['currency'].upcase
|
109
|
+
rate = rates.dig(date, currency)
|
110
|
+
return if rate.nil?
|
111
|
+
|
112
|
+
reversed_rate = 1 / rate
|
113
|
+
charge['amount'] * reversed_rate
|
114
|
+
end
|
84
115
|
end
|
85
116
|
end
|
data/moss_generator.gemspec
CHANGED
@@ -31,9 +31,12 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
33
|
# spec.add_dependency to register a new dependency of your gem
|
34
|
+
spec.add_dependency 'countries', '~> 3.1'
|
34
35
|
spec.add_dependency 'money', '~> 6.14'
|
35
36
|
spec.add_dependency 'valvat', '~> 1.1'
|
36
37
|
|
38
|
+
spec.add_development_dependency 'pry-byebug'
|
39
|
+
|
37
40
|
# For more information and examples about making a new gem, checkout our
|
38
41
|
# guide at: https://bundler.io/guides/creating_gem.html
|
39
42
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moss_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- frdrkolsson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: countries
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: money
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
description: Skatteverket Mini One Stop Shop (MOSS) generator.
|
42
70
|
email:
|
43
71
|
- fredrik.olsson@standout.se
|