vat-gst-calculator 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eadf3b8ac32a3ae3ebb44b73968fb452e84a06bd0aa14cf21ec0ae1a87cb079c
4
- data.tar.gz: ed189868daaff98f1d610917c3be707c1fca1762c0b70ef66ab050f31a27154e
3
+ metadata.gz: ef8d215f45467ecd5763e3b9fe214096f83e4f7d84ffa7009224bf3c77a85c39
4
+ data.tar.gz: 63a30ff1ee4e9fddf812684191f57c6315fe7bb2441bb7c8081fbf053720e9b1
5
5
  SHA512:
6
- metadata.gz: ed1f8a387f82d7c52c3f451e828c51f00a65abd73924d77f4bd3322e744f5bd0abd1368ae90f3571edf705c47f052c82a5d8bd37d3ab292ccc64325afd358a20
7
- data.tar.gz: 8a03f400e292989f10d2c94c2dcf5c85a13f29227710765a0e91be5e6638302841645a02867e48aba023982624023d7b070af8cd5c25a505425c0a04ed67bb0c
6
+ metadata.gz: 72020eb1ffe54a6851bbb2d385088925b936a68fc39e04bb5bec87227a2672a03e0a87b072c3cc7a01fea2b5e755d6a133efecbe47dc2be36b4fad7aaf9a42de
7
+ data.tar.gz: 2588c15b22de2b5d594b187236f2119e6c68cb13d2d0f6f47c8c70c656a01ea49f5e7716837c67ff0598470c316e52c85395dfb127f8358b3740c10c0538d45c
@@ -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
@@ -1,7 +1,7 @@
1
1
  module Easyship
2
2
  module SalesTax
3
3
  module Calculator
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aloha Chen
8
+ - Paul LD
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2019-07-18 00:00:00.000000000 Z
12
+ date: 2019-11-05 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: []