flowcommerce_spree 0.0.14 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/flowcommerce_spree/orders_controller.rb +2 -0
- 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 +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a58357f2f4891679ea1b21bf15603d6d61964e1a07d3d4c5259b834207be4605
|
4
|
+
data.tar.gz: 16f2b8a0ba784bfeb3685178f0efe12fbd3ddd963d4e7058c84397f7b4d3ac5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fe235560e3132fcd9ed90d4b3e6577af09817f59a79564ad41b2a60477d08158e7fe52ed67eaea28749af87e59c192a5c98c16f360ea48d810dc97396a4fdde
|
7
|
+
data.tar.gz: 0beb3883f44c1b08f520e3a94490b03e960c87fa8be7c41f38399ddbc4ff3db9801e3f47adca93056d6e4e9b2b86c773dfcc670bad6b3954a41279ab6ac472a5
|
@@ -5,6 +5,8 @@ module FlowcommerceSpree
|
|
5
5
|
wrap_parameters false
|
6
6
|
|
7
7
|
skip_before_action :setup_tracking, only: :order_completed
|
8
|
+
skip_before_action :prepare_order
|
9
|
+
skip_before_action :before_render
|
8
10
|
|
9
11
|
# proxy enpoint between flow and thankyou page.
|
10
12
|
# /flow/order_completed endpoint
|
@@ -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.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-
|
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.
|
288
|
+
rubygems_version: 3.0.3
|
289
289
|
signing_key:
|
290
290
|
specification_version: 4
|
291
291
|
summary: Integration of Spree with Flow API
|