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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ed3330958e03459888c682dd28c10106da11922d09009f661d3e8d1a29d32a4
4
- data.tar.gz: ae942f91846355379eac2fb8a54b8ca6156c749b20732137250c35e3a2cc605f
3
+ metadata.gz: 3a818d7d94ee9e8fa767079ae2553e7d9c707b488c4c442ce9a57e217dd94a3f
4
+ data.tar.gz: 72f1daf2d3ccbad727ef67b36757457b35c77dd4de77e841345edc2538e66577
5
5
  SHA512:
6
- metadata.gz: cc69d6f4e090cf11bdd80f95f7534451ae060b862f896ac0fbeff276f51b98a672cb7132245408fe97393c8cc118cba8917ee570f530d20534d0a375697e423e
7
- data.tar.gz: 73b06be7f5ef0d6db3532e992f7f3daba0eb71e9a65e3d72b25ba5a4044630213781979cc74e768689f1f729180f46064e41d581ff4ab50f3957100319ed6e32
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 for a new request_id
30
- attrs_to_update = { last_ip_address: ip_address } if @request_id != request_id
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, _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.15'
4
+ VERSION = '0.0.19'
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.15
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-09-03 00:00:00.000000000 Z
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