trebbianno-ruby-api 0.0.4 → 0.0.5
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 +4 -4
- data/lib/trebbianno/order.rb +22 -4
- data/lib/trebbianno/version.rb +1 -1
- data/spec/fixtures/test_build_order_request.xml +2 -2
- data/spec/lib/order_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b904a315b8d56e9ad2da99a1d9f168d2ef81eb42
|
4
|
+
data.tar.gz: 03a0dc92627b0d216368ef528a4feb18c03a49fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c10427b70d37b3440ff8d05190cda60fe5be4d72cb6f6aee09d5124dbe819a32f844f7c9a8183f2bee1a447f4cff2004195f1f7dc6e7064a2d4718c9a0789ab3
|
7
|
+
data.tar.gz: 4d5d04b9c2cb85e9e8771afe7ae5dbd35edfacc68cdf670264d20231a837e53eda52abc17d84923e92b25cd52adcf157349ddfb85b92f63f206f87cf48056158
|
data/lib/trebbianno/order.rb
CHANGED
@@ -7,7 +7,7 @@ module Trebbianno
|
|
7
7
|
construct_xml "orders" do |xml|
|
8
8
|
|
9
9
|
xml.order do
|
10
|
-
|
10
|
+
|
11
11
|
build_user xml
|
12
12
|
|
13
13
|
address = order[:shipping_address]
|
@@ -49,13 +49,31 @@ module Trebbianno
|
|
49
49
|
xml.ordernumber order[:number]
|
50
50
|
xml.sku line_item[:sku]
|
51
51
|
xml.qty line_item[:quantity]
|
52
|
-
xml.unitprice line_item
|
52
|
+
xml.unitprice unit_price(line_item, order)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
58
|
-
|
57
|
+
def unit_price(line_item, order)
|
58
|
+
adjusted_price(line_item, order).round(2)
|
59
|
+
end
|
60
|
+
|
61
|
+
def adjusted_price(line_item, order)
|
62
|
+
line_item[:price] - line_item_discount(line_item[:price], order)
|
63
|
+
end
|
64
|
+
|
65
|
+
def line_item_discount(item_price, order)
|
66
|
+
(item_price * discount_percent(order)).round(2)
|
67
|
+
end
|
68
|
+
|
69
|
+
def discount_percent(order)
|
70
|
+
order[:item_discount].to_f / line_item_count(order)
|
71
|
+
end
|
72
|
+
|
73
|
+
def line_item_count(order)
|
74
|
+
order[:line_items].inject(0) do |sum, hash|
|
75
|
+
sum + hash[:price]
|
76
|
+
end
|
59
77
|
end
|
60
78
|
|
61
79
|
end
|
data/lib/trebbianno/version.rb
CHANGED
@@ -21,13 +21,13 @@
|
|
21
21
|
<ordernumber>R123123123</ordernumber>
|
22
22
|
<sku>123332211</sku>
|
23
23
|
<qty>1</qty>
|
24
|
-
<unitprice>
|
24
|
+
<unitprice>86.67</unitprice>
|
25
25
|
</orderline>
|
26
26
|
<orderline>
|
27
27
|
<ordernumber>R123123123</ordernumber>
|
28
28
|
<sku>123332212</sku>
|
29
29
|
<qty>1</qty>
|
30
|
-
<unitprice>
|
30
|
+
<unitprice>173.33</unitprice>
|
31
31
|
</orderline>
|
32
32
|
</order>
|
33
33
|
</orders>
|
data/spec/lib/order_spec.rb
CHANGED
@@ -39,10 +39,10 @@ describe Trebbianno::Order do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
describe 'private#line_item_discount' do
|
42
|
-
let(:discount) {[
|
42
|
+
let(:discount) {[13.33, 26.67]}
|
43
43
|
it 'should calculate discount price for line item' do
|
44
44
|
order_hash[:line_items].each_with_index do |item, index|
|
45
|
-
discount_amount = order_client.send(:line_item_discount, order_hash)
|
45
|
+
discount_amount = order_client.send(:line_item_discount, item[:price], order_hash)
|
46
46
|
expect(discount_amount).to eq discount[index]
|
47
47
|
end
|
48
48
|
end
|