flowcommerce_spree 0.0.15 → 0.0.19
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/models/spree/calculator/shipping/flow_io.rb +5 -0
- data/app/models/spree/gateway/flow_io.rb +15 -6
- data/app/services/flowcommerce_spree/order_sync.rb +26 -6
- data/app/services/flowcommerce_spree/order_updater.rb +2 -1
- data/lib/flowcommerce_spree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a818d7d94ee9e8fa767079ae2553e7d9c707b488c4c442ce9a57e217dd94a3f
|
4
|
+
data.tar.gz: 72f1daf2d3ccbad727ef67b36757457b35c77dd4de77e841345edc2538e66577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b13a78323e67a21361d34a7779a1699830df83c04dea839b623004c0bdd4792b904e0b06a470bb340c0d46adf9aeed9f9117a17002e3d11ee268c38a029cc57a
|
7
|
+
data.tar.gz: b217a92590b3b515bfb9ae2afc82ec8cb3bef6809f00c3ec20a052c9cfb605e190e442cdd545f2355d8891f3ce37358b3fd7f25758b57d0ac05f8cf96903bd29
|
@@ -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
|
@@ -6,6 +6,7 @@ module Spree
|
|
6
6
|
class FlowIo < ShippingCalculator
|
7
7
|
preference :lower_boundary, :decimal, default: 100
|
8
8
|
preference :charge_default, :decimal, default: 15
|
9
|
+
preference :sample_product_cost, :decimal, default: 9
|
9
10
|
|
10
11
|
def self.description
|
11
12
|
'FlowIO Calculator'
|
@@ -26,6 +27,10 @@ module Spree
|
|
26
27
|
preferred_lower_boundary
|
27
28
|
end
|
28
29
|
|
30
|
+
def default_sample_charge
|
31
|
+
preferred_sample_product_cost
|
32
|
+
end
|
33
|
+
|
29
34
|
private
|
30
35
|
|
31
36
|
def flow_order(package)
|
@@ -61,13 +61,17 @@ module Spree
|
|
61
61
|
ActiveMerchant::Billing::Response.new(false, e.to_s, {}, {})
|
62
62
|
end
|
63
63
|
|
64
|
-
def void(authorization_id,
|
64
|
+
def void(authorization_id, options = {})
|
65
65
|
amount = (options[:subtotal] + options[:shipping]) * 0.01
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
order = Spree::Order.find_by(number: options[:order_id].split('-').first)
|
67
|
+
refund_form = Io::Flow::V0::Models::RefundForm.new(order_number: order.number,
|
68
|
+
amount: amount,
|
69
|
+
currency: options[:currency],
|
70
|
+
authorization_id: authorization_id)
|
71
|
+
response = FlowcommerceSpree.client.refunds.post(FlowcommerceSpree::ORGANIZATION, refund_form)
|
72
|
+
validate_flow_refund_response(response, order)
|
73
|
+
|
74
|
+
ActiveMerchant::Billing::Response.new(true, 'flow-payment-void', {}, {})
|
71
75
|
end
|
72
76
|
|
73
77
|
def create_profile(payment)
|
@@ -91,6 +95,11 @@ module Spree
|
|
91
95
|
amount: amount,
|
92
96
|
currency: order.currency)
|
93
97
|
response = FlowcommerceSpree.client.refunds.post(FlowcommerceSpree::ORGANIZATION, refund_form)
|
98
|
+
result = validate_flow_refund_response(response, order)
|
99
|
+
result
|
100
|
+
end
|
101
|
+
|
102
|
+
def validate_flow_refund_response(response, order)
|
94
103
|
response_status = response.status.value
|
95
104
|
if REFUND_VALID_STATES.include? response_status
|
96
105
|
add_refund_to_order(response, order)
|
@@ -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,8 @@ module FlowcommerceSpree
|
|
63
63
|
payment.update_column(:identifier, p['id'])
|
64
64
|
end
|
65
65
|
|
66
|
-
return if @order.
|
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!
|
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.19
|
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-
|
12
|
+
date: 2021-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_model_serializers
|