flowcommerce_spree 0.0.17 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/spree/core/controller_helpers/flow_io_order_helper_decorator.rb +2 -2
- data/app/services/flowcommerce_spree/order_sync.rb +26 -6
- data/app/services/flowcommerce_spree/order_updater.rb +10 -1
- data/app/services/flowcommerce_spree/webhooks/capture_upserted_v2.rb +11 -3
- data/lib/flowcommerce_spree/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c53cdffe59a872bd84ce53aedf0765dff2f282a09114b49da5835ce16b612eb6
|
4
|
+
data.tar.gz: c4279e859c545ce2b7e212fb388b461956aa53ce26fa85db352395e4d9ade47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29b8e1d3af99d46c5bf9830c790f7a16f8ebd3abe7ab213ff9dcfec690fd629769696bf27edb5eef1475aead7a74e3a1fa8fb658161def03bd77478952692e79
|
7
|
+
data.tar.gz: 2a68a12590e79515fbe94f5a2a1bafc035eda7059895cbf4c475396b3b9f31400c889356ef540650f4675269c8078227665816c3192cde811d84a3152fc38ad1
|
@@ -26,8 +26,8 @@ module Spree
|
|
26
26
|
|
27
27
|
attrs_to_update = {}
|
28
28
|
|
29
|
-
# Update last_ip_address only
|
30
|
-
attrs_to_update = { last_ip_address: ip_address } if @
|
29
|
+
# Update last_ip_address only when last_ip_address is different.
|
30
|
+
attrs_to_update = { last_ip_address: ip_address } if @current_order.last_ip_address != ip_address
|
31
31
|
|
32
32
|
# :meta is a jsonb column costly to update every time, especially with all the flow.io data, that's why
|
33
33
|
# here it is updated only if no zone_id there was inside :meta
|
@@ -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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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,16 @@ module FlowcommerceSpree
|
|
63
63
|
payment.update_column(:identifier, p['id'])
|
64
64
|
end
|
65
65
|
|
66
|
-
|
66
|
+
if @order.payments.blank?
|
67
|
+
payment_method = Spree::PaymentMethod.find_by type: 'Spree::Gateway::FlowIo'
|
68
|
+
placeholder_payment = Spree::Payment.new(amount: @order.flow_io_total_amount, order: @order,
|
69
|
+
source: nil, payment_method_id: payment_method.id, state: 'pending')
|
70
|
+
@order.payments << placeholder_payment
|
71
|
+
@order.save
|
72
|
+
end
|
73
|
+
|
74
|
+
return if @order.completed?
|
75
|
+
return if @order.payments.sum(:amount) < @order.flow_io_total_amount
|
67
76
|
|
68
77
|
@order.state = 'confirm'
|
69
78
|
@order.save!
|
@@ -54,7 +54,7 @@ module FlowcommerceSpree
|
|
54
54
|
|
55
55
|
def map_payment_captures_to_spree(order, payments)
|
56
56
|
order.flow_data['captures']&.each do |c|
|
57
|
-
next unless (payment = captured_payment(payments, c))
|
57
|
+
next unless (payment = captured_payment(payments, c, order))
|
58
58
|
|
59
59
|
payment.capture_events.create!(amount: c['amount'], meta: { 'flow_data' => { 'id' => c['id'] } })
|
60
60
|
return if payment.completed? || payment.capture_events.sum(:amount) < payment.amount
|
@@ -68,10 +68,18 @@ module FlowcommerceSpree
|
|
68
68
|
FlowcommerceSpree::OrderUpdater.new(order: order).finalize_order
|
69
69
|
end
|
70
70
|
|
71
|
-
def captured_payment(flow_order_payments, capture)
|
71
|
+
def captured_payment(flow_order_payments, capture, order)
|
72
72
|
return unless capture['status'] == 'succeeded'
|
73
|
-
|
74
73
|
auth = capture.dig('authorization', 'id')
|
74
|
+
payment = order.payments.first
|
75
|
+
|
76
|
+
if flow_order_payments.blank? && payment.response_code.blank?
|
77
|
+
payment.response_code = capture.dig('authorization', 'key')
|
78
|
+
payment.identifier = capture.dig('authorization', 'key')
|
79
|
+
payment.save
|
80
|
+
return payment
|
81
|
+
end
|
82
|
+
|
75
83
|
return unless flow_order_payments&.find { |p| p['reference'] == auth }
|
76
84
|
|
77
85
|
return unless (payment = Spree::Payment.find_by(response_code: auth))
|
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.
|
4
|
+
version: 0.0.20
|
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:
|
12
|
+
date: 2022-03-17 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.
|
288
|
+
rubygems_version: 3.0.3.1
|
289
289
|
signing_key:
|
290
290
|
specification_version: 4
|
291
291
|
summary: Integration of Spree with Flow API
|