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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78bcd2ec2168ade147fb11d14e8a8f94a30133a0f6fa2df225c3abd0cbb7a7ff
4
- data.tar.gz: fc255f7fc844d6209cd852c84a8f86db9cb97b3ad8d1e80586e5f692ec51a055
3
+ metadata.gz: a58357f2f4891679ea1b21bf15603d6d61964e1a07d3d4c5259b834207be4605
4
+ data.tar.gz: 16f2b8a0ba784bfeb3685178f0efe12fbd3ddd963d4e7058c84397f7b4d3ac5f
5
5
  SHA512:
6
- metadata.gz: 15778423ce300091577ff41aad2c639da5ddb59421db10cf37e7844a9c74997220a0864788675a98d81c330f2fa800fe7ee38bcf703cb813333f2cf99af01687
7
- data.tar.gz: 8b0795bf474136c0c7abd383933b2d809e6e1efc26e00b4c40164f389d707d50c75e7c6f950fc3285d3fc898a7442c2555dfc6d959b067b5a8851c7c9a56fc63
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, _source, options = {})
64
+ def void(authorization_id, options = {})
65
65
  amount = (options[:subtotal] + options[:shipping]) * 0.01
66
- reversal_form = Io::Flow::V0::Models::ReversalForm.new(key: options[:order_id],
67
- authorization_id: authorization_id,
68
- amount: amount,
69
- currency: options[:currency])
70
- FlowcommerceSpree.client.reversals.post(FlowcommerceSpree::ORGANIZATION, reversal_form)
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
- 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.14'
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.14
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-02 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