vat-gst-calculator 0.1.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eadf3b8ac32a3ae3ebb44b73968fb452e84a06bd0aa14cf21ec0ae1a87cb079c
4
- data.tar.gz: ed189868daaff98f1d610917c3be707c1fca1762c0b70ef66ab050f31a27154e
3
+ metadata.gz: cc9dc287543f32912a859dd1fa6c27f95831bd6f9abac619e8b019a0847c8521
4
+ data.tar.gz: 32f9391ac7f64ae551b87b76c1970cb72411cd7825d6289f32f703997a118714
5
5
  SHA512:
6
- metadata.gz: ed1f8a387f82d7c52c3f451e828c51f00a65abd73924d77f4bd3322e744f5bd0abd1368ae90f3571edf705c47f052c82a5d8bd37d3ab292ccc64325afd358a20
7
- data.tar.gz: 8a03f400e292989f10d2c94c2dcf5c85a13f29227710765a0e91be5e6638302841645a02867e48aba023982624023d7b070af8cd5c25a505425c0a04ed67bb0c
6
+ metadata.gz: a38dc3de2e874b4940304784e919160fdb680da92599ea74c082be7fdcefe2116cbef3c181dc826020ecfb9387a61e6bbdd9f33815af55c39ef6f38e8a671f97
7
+ data.tar.gz: f56d180fcaa2f75f65dee845fd9e0ae727375b6d2b31bc438a26039c9e58452a6d3bb87e2d8255bc9a729c3cfa1c87e60f45286669449f6df471a284e671f134
@@ -1,25 +1,32 @@
1
1
  require "easyship/sales_tax/calculator/version"
2
2
  require "easyship/sales_tax/calculator/formula"
3
3
  require "easyship/sales_tax/calculator/fee"
4
-
5
4
  module Easyship
6
5
  module SalesTax
7
6
  module Calculator
8
7
  class Error < StandardError; end
8
+
9
9
  def self.calculate(origin_country_alpha2: nil, destination_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil)
10
10
  return fallback_value if origin_country_alpha2.nil? || origin_country_alpha2.empty? || destination_country_alpha2.nil? || destination_country_alpha2.empty?
11
11
  return fallback_value unless fees.is_a?(Fee)
12
12
 
13
- # TODO(Aloha): support international
14
- return fallback_value if origin_country_alpha2 != destination_country_alpha2
15
- return fallback_value if Formula::DOMESTIC[destination_country_alpha2.to_s].nil? || Formula::DOMESTIC[destination_country_alpha2.to_s].empty?
13
+ if domestic?(origin_country_alpha2, destination_country_alpha2) || within_eu?(origin_country_alpha2, destination_country_alpha2)
14
+ domestic_value(origin_country_alpha2: origin_country_alpha2, origin_state: origin_state, destination_state: destination_state, fees: fees)
15
+ else
16
+ fallback_value
17
+ end
18
+ rescue
19
+ fallback_value
20
+ end
21
+
22
+ def self.domestic_value(origin_country_alpha2: nil, origin_state: nil, destination_state: nil, fees: nil)
23
+ domestic_rates = Formula::DOMESTIC[origin_country_alpha2.to_s]
24
+ return fallback_value if domestic_rates.nil? || domestic_rates.empty?
16
25
 
17
26
  {
18
- sales_tax: tax_calculate(Formula::DOMESTIC[destination_country_alpha2.to_s][:sales_tax], nil, destination_state, fees, false),
19
- provincial_sales_tax: tax_calculate(Formula::DOMESTIC[destination_country_alpha2.to_s][:provincial_sales_taxes], origin_state, destination_state, fees, true)
27
+ sales_tax: tax_calculate(domestic_rates[:sales_tax], nil, destination_state, fees, false),
28
+ provincial_sales_tax: tax_calculate(domestic_rates[:provincial_sales_taxes], origin_state, destination_state, fees, true)
20
29
  }
21
- rescue
22
- fallback_value
23
30
  end
24
31
 
25
32
  def self.fallback_value
@@ -40,9 +47,21 @@ module Easyship
40
47
  end
41
48
 
42
49
  def self.sales_tax_website_name(country_alpha2)
43
- return unless Formula::DOMESTIC[country_alpha2.to_s].present?
50
+ return if Formula::DOMESTIC[country_alpha2.to_s].nil? || Formula::DOMESTIC[country_alpha2.to_s].empty?
44
51
  Formula::DOMESTIC[country_alpha2][:sales_tax_website_name]
45
52
  end
53
+
54
+ def self.in_eu?(country_alpha2)
55
+ %w(NL LU EE LT HU BE PT GB SK HR CZ IT FI PL MT DE SI RO BG AT SE CY DK FR IE ES GR LV).include?(country_alpha2)
56
+ end
57
+
58
+ def self.domestic?(origin_country_alpha2 = nil, destination_country_alpha2 = nil)
59
+ !origin_country_alpha2.nil? && !origin_country_alpha2.empty? && origin_country_alpha2 == destination_country_alpha2
60
+ end
61
+
62
+ def self.within_eu?(origin_country_alpha2 = nil, destination_country_alpha2 = nil)
63
+ in_eu?(origin_country_alpha2) && in_eu?(destination_country_alpha2)
64
+ end
46
65
  end
47
66
  end
48
67
  end
@@ -25,7 +25,7 @@ module Easyship
25
25
  },
26
26
  'GB' => {
27
27
  sales_tax_website_name: 'VAT',
28
- sales_tax: { '_ALL': build_fee_struct(0.2, 0, 0, 0.2) }, # TBC
28
+ sales_tax: { '_ALL': build_fee_struct(0.2, 0, 0.2, 0.2) }, # TBC
29
29
  provincial_sales_taxes: { '_ALL': no_taxes }
30
30
  },
31
31
  'CA' => {
@@ -80,6 +80,116 @@ module Easyship
80
80
  sales_tax_website_name: nil,
81
81
  sales_tax: { '_ALL': no_taxes },
82
82
  provincial_sales_taxes: { '_ALL': no_taxes }
83
+ },
84
+ 'DE' => {
85
+ sales_tax_website_name: 'VAT',
86
+ sales_tax: { '_ALL': build_fee_struct(0.19, 0, 0, 0) },
87
+ provincial_sales_taxes: { '_ALL': no_taxes }
88
+ },
89
+ 'FR' => {
90
+ sales_tax_website_name: 'VAT',
91
+ sales_tax: { '_ALL': build_fee_struct(0.2, 0, 0, 0) },
92
+ provincial_sales_taxes: { '_ALL': no_taxes }
93
+ },
94
+ 'IT' => {
95
+ sales_tax_website_name: 'VAT',
96
+ sales_tax: { '_ALL': build_fee_struct(0.22, 0, 0, 0) },
97
+ provincial_sales_taxes: { '_ALL': no_taxes }
98
+ },
99
+ 'BE' => {
100
+ sales_tax_website_name: 'VAT',
101
+ sales_tax: { '_ALL': build_fee_struct(0.21, 0, 0, 0) },
102
+ provincial_sales_taxes: { '_ALL': no_taxes }
103
+ },
104
+ 'ES' => {
105
+ sales_tax_website_name: 'VAT',
106
+ sales_tax: { '_ALL': build_fee_struct(0.21, 0, 0, 0) },
107
+ provincial_sales_taxes: { '_ALL': no_taxes }
108
+ },
109
+ 'PT' => {
110
+ sales_tax_website_name: 'VAT',
111
+ sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0, 0) },
112
+ provincial_sales_taxes: { '_ALL': no_taxes }
113
+ },
114
+ 'PL' => {
115
+ sales_tax_website_name: 'VAT',
116
+ sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0, 0) },
117
+ provincial_sales_taxes: { '_ALL': no_taxes }
118
+ },
119
+ 'RO' => {
120
+ sales_tax_website_name: 'VAT',
121
+ sales_tax: { '_ALL': build_fee_struct(0.19, 0, 0, 0) },
122
+ provincial_sales_taxes: { '_ALL': no_taxes }
123
+ },
124
+ 'AT' => {
125
+ sales_tax_website_name: 'VAT',
126
+ sales_tax: { '_ALL': build_fee_struct(0.2, 0, 0, 0) },
127
+ provincial_sales_taxes: { '_ALL': no_taxes }
128
+ },
129
+ 'IE' => {
130
+ sales_tax_website_name: 'VAT',
131
+ sales_tax: { '_ALL': build_fee_struct(0.23, 0, 0, 0) },
132
+ provincial_sales_taxes: { '_ALL': no_taxes }
133
+ },
134
+ 'DK' => {
135
+ sales_tax_website_name: 'VAT',
136
+ sales_tax: { '_ALL': build_fee_struct(0.25, 0, 0, 0) },
137
+ provincial_sales_taxes: { '_ALL': no_taxes }
138
+ },
139
+ 'SE' => {
140
+ sales_tax_website_name: 'VAT',
141
+ sales_tax: { '_ALL': build_fee_struct(0.25, 0, 0, 0) },
142
+ provincial_sales_taxes: { '_ALL': no_taxes }
143
+ },
144
+ 'FI' => {
145
+ sales_tax_website_name: 'VAT',
146
+ sales_tax: { '_ALL': build_fee_struct(0.24, 0, 0, 0) },
147
+ provincial_sales_taxes: { '_ALL': no_taxes }
148
+ },
149
+ 'CN' => {
150
+ sales_tax_website_name: 'VAT',
151
+ sales_tax: { '_ALL': build_fee_struct(0.06, 0, 0, 0) },
152
+ provincial_sales_taxes: { '_ALL': no_taxes }
153
+ },
154
+ 'NO' => {
155
+ sales_tax_website_name: 'VAT',
156
+ sales_tax: { '_ALL': build_fee_struct(0.25, 0, 0, 0) },
157
+ provincial_sales_taxes: { '_ALL': no_taxes }
158
+ },
159
+ 'CH' => {
160
+ sales_tax_website_name: 'VAT',
161
+ sales_tax: { '_ALL': build_fee_struct(0.077, 0, 0, 0) },
162
+ provincial_sales_taxes: { '_ALL': no_taxes }
163
+ },
164
+ 'MY' => {
165
+ sales_tax_website_name: 'VAT',
166
+ sales_tax: { '_ALL': build_fee_struct(0.1, 0, 0, 0) },
167
+ provincial_sales_taxes: { '_ALL': no_taxes }
168
+ },
169
+ 'JP' => {
170
+ sales_tax_website_name: 'VAT',
171
+ sales_tax: { '_ALL': build_fee_struct(0.1, 0, 0, 0) },
172
+ provincial_sales_taxes: { '_ALL': no_taxes }
173
+ },
174
+ 'NZ' => {
175
+ sales_tax_website_name: 'VAT',
176
+ sales_tax: { '_ALL': build_fee_struct(0.15, 0, 0, 0) },
177
+ provincial_sales_taxes: { '_ALL': no_taxes }
178
+ },
179
+ 'IN' => {
180
+ sales_tax_website_name: 'VAT',
181
+ sales_tax: { '_ALL': build_fee_struct(0.15, 0, 0, 0) },
182
+ provincial_sales_taxes: { '_ALL': no_taxes }
183
+ },
184
+ 'KR' => {
185
+ sales_tax_website_name: 'VAT',
186
+ sales_tax: { '_ALL': build_fee_struct(0.1, 0, 0, 0) },
187
+ provincial_sales_taxes: { '_ALL': no_taxes }
188
+ },
189
+ 'MX' => {
190
+ sales_tax_website_name: 'VAT',
191
+ sales_tax: { '_ALL': build_fee_struct(0.16, 0, 0, 0) },
192
+ provincial_sales_taxes: { '_ALL': no_taxes }
83
193
  }
84
194
  }.freeze
85
195
  end
@@ -1,7 +1,7 @@
1
1
  module Easyship
2
2
  module SalesTax
3
3
  module Calculator
4
- VERSION = "0.1.0"
4
+ VERSION = "0.4.2"
5
5
  end
6
6
  end
7
7
  end
@@ -6,8 +6,8 @@ require "easyship/sales_tax/calculator/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "vat-gst-calculator"
8
8
  spec.version = Easyship::SalesTax::Calculator::VERSION
9
- spec.authors = ["Aloha Chen"]
10
- spec.email = ["y.alohac@gmail.com"]
9
+ spec.authors = ["Aloha Chen", "Paul LD"]
10
+ spec.email = ["y.alohac@gmail.com", "paul.lugagnedelpon@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Calculate Sales Tax}
13
13
  spec.description = %q{Calculating VAT/GST/PST based on shipping rate, insurance fee, pickup_fee...etc}
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vat-gst-calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aloha Chen
8
- autorequire:
8
+ - Paul LD
9
+ autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2019-07-18 00:00:00.000000000 Z
12
+ date: 2020-12-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -69,6 +70,7 @@ dependencies:
69
70
  description: Calculating VAT/GST/PST based on shipping rate, insurance fee, pickup_fee...etc
70
71
  email:
71
72
  - y.alohac@gmail.com
73
+ - paul.lugagnedelpon@gmail.com
72
74
  executables: []
73
75
  extensions: []
74
76
  extra_rdoc_files: []
@@ -90,7 +92,7 @@ homepage: https://github.com/easyship/vat-gst-calculator
90
92
  licenses:
91
93
  - MIT
92
94
  metadata: {}
93
- post_install_message:
95
+ post_install_message:
94
96
  rdoc_options: []
95
97
  require_paths:
96
98
  - lib
@@ -105,8 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
107
  - !ruby/object:Gem::Version
106
108
  version: '0'
107
109
  requirements: []
108
- rubygems_version: 3.0.4
109
- signing_key:
110
+ rubygems_version: 3.0.9
111
+ signing_key:
110
112
  specification_version: 4
111
113
  summary: Calculate Sales Tax
112
114
  test_files: []