flowcommerce_spree 0.0.17 → 0.0.18

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: 10b41982519fa82948ce03663d36ee56bb19a9efe227a8c723dea3e20614c730
4
- data.tar.gz: a9a4ad3ea162660a65208dfd1b86dbc89ab7d9084b7a641a198be685453e7390
3
+ metadata.gz: a58357f2f4891679ea1b21bf15603d6d61964e1a07d3d4c5259b834207be4605
4
+ data.tar.gz: 16f2b8a0ba784bfeb3685178f0efe12fbd3ddd963d4e7058c84397f7b4d3ac5f
5
5
  SHA512:
6
- metadata.gz: b480ab7c7664a2d5526bfa9250b0a5a7dd296d1ce24d3fe602ca3cd6ddce2f4a987077310843c2d181a7f8fab1cc84134f7259f0b547d2f5e6d12d855c1de342
7
- data.tar.gz: 01ba4ac9afd4e712436112ea49d538068b4d6192ea64f319580a6ee9340d77048a406f500b073118362c29f4c331ed23cb2a10954ad0399dc66da982bd940e9d
6
+ metadata.gz: 4fe235560e3132fcd9ed90d4b3e6577af09817f59a79564ad41b2a60477d08158e7fe52ed67eaea28749af87e59c192a5c98c16f360ea48d810dc97396a4fdde
7
+ data.tar.gz: 0beb3883f44c1b08f520e3a94490b03e960c87fa8be7c41f38399ddbc4ff3db9801e3f47adca93056d6e4e9b2b86c773dfcc670bad6b3954a41279ab6ac472a5
@@ -120,13 +120,33 @@ module FlowcommerceSpree
120
120
  def add_item(line_item)
121
121
  variant = line_item.variant
122
122
  price_root = variant.flow_data&.dig('exp', @experience, 'prices')&.[](0) || {}
123
-
123
+ discount_data = map_discounts(line_item)
124
124
  # create flow order line item
125
- { center: FLOW_CENTER,
126
- number: variant.sku,
127
- quantity: line_item.quantity,
128
- price: { amount: price_root['amount'] || variant.price,
129
- currency: price_root['currency'] || variant.cost_currency } }
125
+ res = { center: FLOW_CENTER,
126
+ number: variant.sku,
127
+ quantity: line_item.quantity,
128
+ price: { amount: price_root['amount'] || variant.price,
129
+ currency: price_root['currency'] || variant.cost_currency },
130
+ discounts: {
131
+ discounts: discount_data
132
+ } }
133
+ res
134
+ end
135
+
136
+ def map_discounts(line_item)
137
+ line_item.adjustments.promotion.eligible.map do |adjustment|
138
+ {
139
+ offer: {
140
+ discriminator: 'discount_offer_fixed',
141
+ money: {
142
+ amount: adjustment.amount.to_f,
143
+ currency: line_item.currency
144
+ }
145
+ },
146
+ target: 'item',
147
+ label: adjustment.label
148
+ }
149
+ end
130
150
  end
131
151
 
132
152
  def write_response_to_order
@@ -63,7 +63,8 @@ module FlowcommerceSpree
63
63
  payment.update_column(:identifier, p['id'])
64
64
  end
65
65
 
66
- return if @order.payments.sum(:amount) < @order.amount || @order.state == 'complete'
66
+ return if @order.completed?
67
+ return if @order.payments.sum(:amount) < @order.flow_io_total_amount || @order.flow_io_balance_amount > 0
67
68
 
68
69
  @order.state = 'confirm'
69
70
  @order.save!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FlowcommerceSpree
4
- VERSION = '0.0.17'
4
+ VERSION = '0.0.18'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowcommerce_spree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurel Branzeanu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-24 00:00:00.000000000 Z
12
+ date: 2021-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_model_serializers
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  - !ruby/object:Gem::Version
286
286
  version: '0'
287
287
  requirements: []
288
- rubygems_version: 3.0.8
288
+ rubygems_version: 3.0.3
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Integration of Spree with Flow API