workarea-klarna 1.0.0.beta1 → 1.0.0.beta2

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: a35826c1d47f935b8d5ebbb1a6f2fc3337be504e7120edf742c647e8d7eb6c7f
4
- data.tar.gz: a2648778ca85ad42996fa7f9bf5c730826358b7786b98895d34c0b526b3a5e04
3
+ metadata.gz: 6841a7473e3e7298fc8a4cc26544a61f93b4631b8bcc62e5631d94e7757b7751
4
+ data.tar.gz: 87bc257f83535b11edca9b84d92e6f224c19faafd5545fa365670db9a2e3ff9f
5
5
  SHA512:
6
- metadata.gz: 9272c87153840555efbd07912dd17afa1128997f36b7e7d4525db7e754e95df80195a6673eac3af03469fa5ee55c0eb2263cbb75ced854bc28e50a600b8d7aa2
7
- data.tar.gz: 21b70955ce13278c77615cddfdb6e93ad0e1c5d8eed7d857585c8395e6a29ca52ff6b720af761f5efb09ec0f07cc25070956d94bef38b735e60240a42ea9c949
6
+ metadata.gz: 99c77dc7ab625edf169e108dca137f69c4c2d7d8eaab730ea4b8831bc33bcc9ec5930b0c37f478dc38076363ee6cb3bb2b86dfdfa192c9d1e563f58f94f02ad1
7
+ data.tar.gz: fb073131ab19afd532b9a661d86ae2b5005cffde5eb64d0b8322ed464b03e110be500bd3b829ddd7f5cc7012a13db3e19d6dd97788344e60361b44dc3211c1a7
@@ -1,3 +1,18 @@
1
+ Workarea Klarna 1.0.0.beta2 (2020-09-22)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * bump version
5
+
6
+
7
+ Matt Duffy
8
+
9
+ * Include tax in totals for non-NA continents
10
+
11
+
12
+ Matt Duffy
13
+
14
+
15
+
1
16
  Workarea Klarna 1.0.0.beta1 (2020-07-28)
2
17
  --------------------------------------------------------------------------------
3
18
 
@@ -89,15 +89,24 @@ module Workarea
89
89
  def format_item(item)
90
90
  view_model = Storefront::OrderItemViewModel.new(item)
91
91
  breadcrumbs = Navigation::Breadcrumbs.from_global_id(item.via) if item.via.present?
92
+
92
93
  tax_amount, tax_rate = item_tax_data(item)
94
+ unit_price = item.current_unit_price.cents
95
+ total_amount = item.total_price.cents
96
+
97
+ if include_tax_in_totals?
98
+ tax_amount_per_item = tax_amount / item.quantity
99
+ unit_price += tax_amount_per_item
100
+ total_amount += tax_amount
101
+ end
93
102
 
94
103
  {
95
104
  name: view_model.product_name,
96
105
  type: item.shipping? ? 'physical' : 'digital',
97
106
  reference: item.sku,
98
107
  quantity: item.quantity,
99
- unit_price: item.current_unit_price.cents,
100
- total_amount: item.total_price.cents,
108
+ unit_price: unit_price,
109
+ total_amount: total_amount,
101
110
  total_tax_amount: tax_amount,
102
111
  tax_rate: tax_rate,
103
112
  product_url: Workarea::Storefront::Engine.routes.url_helpers.product_url(
@@ -132,6 +141,9 @@ module Workarea
132
141
  .sum(&:amount)
133
142
  .cents
134
143
 
144
+ tax_rate = ((shipping_tax * 1.0 / shipping_total).round(2) * 10000).to_i
145
+ shipping_total += shipping_tax if include_tax_in_totals?
146
+
135
147
  {
136
148
  name: 'Shipping',
137
149
  type: 'shipping_fee',
@@ -139,7 +151,7 @@ module Workarea
139
151
  unit_price: shipping_total,
140
152
  total_amount: shipping_total,
141
153
  total_tax_amount: shipping_tax,
142
- tax_rate: ((shipping_tax * 1.0 / shipping_total).round(2) * 10000).to_i
154
+ tax_rate: tax_rate
143
155
  }
144
156
  end
145
157
 
@@ -225,7 +237,11 @@ module Workarea
225
237
  end
226
238
 
227
239
  def include_tax_line?
228
- payment.address.country.alpha2 == 'US'
240
+ payment.address.country.continent == 'North America'
241
+ end
242
+
243
+ def include_tax_in_totals?
244
+ !include_tax_line?
229
245
  end
230
246
 
231
247
  def remove_inline_tax(hash)
@@ -1,5 +1,5 @@
1
1
  module Workarea
2
2
  module Klarna
3
- VERSION = "1.0.0.beta1".freeze
3
+ VERSION = "1.0.0.beta2".freeze
4
4
  end
5
5
  end
@@ -90,8 +90,8 @@ module Workarea
90
90
  assert_equal('physical', line[:type])
91
91
  assert_equal('SKU', line[:reference])
92
92
  assert_equal(2, line[:quantity])
93
- assert_equal(500, line[:unit_price])
94
- assert_equal(1000, line[:total_amount])
93
+ assert_equal(540, line[:unit_price])
94
+ assert_equal(1081, line[:total_amount])
95
95
  assert_equal(81, line[:total_tax_amount])
96
96
  assert_equal(800, line[:tax_rate])
97
97
  assert_includes(line[:product_url], '/products/integration-product')
@@ -101,8 +101,8 @@ module Workarea
101
101
  assert_equal('Shipping', line[:name])
102
102
  assert_equal('shipping_fee', line[:type])
103
103
  assert_equal(1, line[:quantity])
104
- assert_equal(700, line[:unit_price])
105
- assert_equal(700, line[:total_amount])
104
+ assert_equal(763, line[:unit_price])
105
+ assert_equal(763, line[:total_amount])
106
106
  assert_equal(63, line[:total_tax_amount])
107
107
  assert_equal(900, line[:tax_rate])
108
108
 
@@ -4,7 +4,27 @@ module Workarea
4
4
  module Klarna
5
5
  class Gateway
6
6
  class RequestTest < TestCase
7
- setup :configure_klarna_data, :payment
7
+ setup :clear_env, :configure_klarna_data, :payment
8
+ teardown :reset_env
9
+
10
+ def clear_env
11
+ @env_na_username = ENV['WORKAREA_KLARNA_NA_USERNAME']
12
+ @env_na_password = ENV['WORKAREA_KLARNA_NA_PASSWORD']
13
+ @env_eur_username = ENV['WORKAREA_KLARNA_EUR_USERNAME']
14
+ @env_eur_password = ENV['WORKAREA_KLARNA_EUR_PASSWORD']
15
+
16
+ ENV.delete('WORKAREA_KLARNA_NA_USERNAME')
17
+ ENV.delete('WORKAREA_KLARNA_NA_PASSWORD')
18
+ ENV.delete('WORKAREA_KLARNA_EUR_USERNAME')
19
+ ENV.delete('WORKAREA_KLARNA_EUR_PASSWORD')
20
+ end
21
+
22
+ def reset_env
23
+ ENV['WORKAREA_KLARNA_NA_USERNAME'] = @env_na_username
24
+ ENV['WORKAREA_KLARNA_NA_PASSWORD'] = @env_na_password
25
+ ENV['WORKAREA_KLARNA_EUR_USERNAME'] = @env_eur_username
26
+ ENV['WORKAREA_KLARNA_EUR_PASSWORD'] = @env_eur_password
27
+ end
8
28
 
9
29
  def order
10
30
  @order ||= create_order
@@ -43,11 +63,8 @@ module Workarea
43
63
  payment.set_address(supported_eur_address)
44
64
  assert_equal(Workarea.config.klarna_eur_username, request.username)
45
65
 
46
- @env_eur_user = ENV['WORKAREA_KLARNA_EUR_USERNAME']
47
66
  ENV['WORKAREA_KLARNA_EUR_USERNAME'] = 'env_eur_user'
48
67
  assert_equal('env_eur_user', request.username)
49
- ensure
50
- ENV['WORKAREA_KLARNA_EUR_USERNAME'] = @env_eur_user
51
68
  end
52
69
 
53
70
  def test_password
@@ -62,11 +79,8 @@ module Workarea
62
79
  payment.set_address(supported_eur_address)
63
80
  assert_equal(Workarea.config.klarna_eur_password, request.password)
64
81
 
65
- @env_eur_pass = ENV['WORKAREA_KLARNA_EUR_PASSWORD']
66
82
  ENV['WORKAREA_KLARNA_EUR_PASSWORD'] = 'env_eur_user'
67
83
  assert_equal('env_eur_user', request.password)
68
- ensure
69
- ENV['WORKAREA_KLARNA_EUR_PASSWORD'] = @env_eur_pass
70
84
  end
71
85
 
72
86
  def test_continent_key
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-klarna
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workarea