flowcommerce_spree 0.0.13 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4805d4a464c5441b33c467972ef7750f5c350b6748dad10fb5a8d079e0c72b2c
4
- data.tar.gz: dd5a4de7ff06de36712c55b4602d5eb6e490939978ec1bc71a15765393478229
3
+ metadata.gz: 10b41982519fa82948ce03663d36ee56bb19a9efe227a8c723dea3e20614c730
4
+ data.tar.gz: a9a4ad3ea162660a65208dfd1b86dbc89ab7d9084b7a641a198be685453e7390
5
5
  SHA512:
6
- metadata.gz: 465a5624b6a9e4a80732dca72a5d618f1cd14064fb3005212f25f7e9d687c2f2c48ab90992bcae145cb87a8de16bc33c37e5d924c545372fb31f0ff7f90df2d2
7
- data.tar.gz: dcfc5356d0954104ab64c0d4da2282fd21cba1600613c84565734d50ed58bd1c1289bd936e3d8624f2703ed80a3e48c7af4ad20442041fb9dc590c3852839b37
6
+ metadata.gz: b480ab7c7664a2d5526bfa9250b0a5a7dd296d1ce24d3fe602ca3cd6ddce2f4a987077310843c2d181a7f8fab1cc84134f7259f0b547d2f5e6d12d855c1de342
7
+ data.tar.gz: 01ba4ac9afd4e712436112ea49d538068b4d6192ea64f319580a6ee9340d77048a406f500b073118362c29f4c331ed23cb2a10954ad0399dc66da982bd940e9d
@@ -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
@@ -14,7 +16,11 @@ module FlowcommerceSpree
14
16
  flow_updater = FlowcommerceSpree::OrderUpdater.new(order: order)
15
17
  flow_updater.complete_checkout
16
18
 
17
- redirect_to "/thankyou?order=#{params[:order]}&t=#{params[:t]}"
19
+ redirection_path = "/thankyou?order=#{params[:order]}&t=#{params[:t]}"
20
+ locale = order.locale_path
21
+ redirection_path = "/#{locale}#{redirection_path}" if locale
22
+
23
+ redirect_to redirection_path
18
24
  end
19
25
  end
20
26
  end
@@ -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)
@@ -5,7 +5,9 @@
5
5
  module Spree
6
6
  class Gateway
7
7
  class FlowIo < Gateway
8
+ REFUND_VALID_STATES = %w[succeeded pending].freeze
8
9
  REFUND_SUCCESS = 'succeeded'
10
+ REFUND_PENDING = 'pending'
9
11
 
10
12
  def provider_class
11
13
  self.class
@@ -59,13 +61,17 @@ module Spree
59
61
  ActiveMerchant::Billing::Response.new(false, e.to_s, {}, {})
60
62
  end
61
63
 
62
- def void(authorization_id, _source, options = {})
64
+ def void(authorization_id, options = {})
63
65
  amount = (options[:subtotal] + options[:shipping]) * 0.01
64
- reversal_form = Io::Flow::V0::Models::ReversalForm.new(key: options[:order_id],
65
- authorization_id: authorization_id,
66
- amount: amount,
67
- currency: options[:currency])
68
- 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', {}, {})
69
75
  end
70
76
 
71
77
  def create_profile(payment)
@@ -89,19 +95,31 @@ module Spree
89
95
  amount: amount,
90
96
  currency: order.currency)
91
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)
92
103
  response_status = response.status.value
93
- if response_status == REFUND_SUCCESS
104
+ if REFUND_VALID_STATES.include? response_status
94
105
  add_refund_to_order(response, order)
106
+ schedule_status_check(response, order)
95
107
  ActiveMerchant::Billing::Response.new(true,
96
108
  REFUND_SUCCESS,
97
109
  response.to_hash,
98
110
  authorization: response.authorization.id)
99
111
  else
100
- msg = "Partial refund fail. Details: #{response_status}"
101
- ActiveMerchant::Billing::Response.new(false, msg, {}, {})
112
+ ActiveMerchant::Billing::Response.new(false, "Partial refund fail. Details: #{response_status}", {}, {})
102
113
  end
103
114
  end
104
115
 
116
+ def schedule_status_check(response, order)
117
+ return if response.status.value != REFUND_PENDING
118
+
119
+ Rails.logger.warn("[!] #{self.class} for #{order.number} - refund request without succeeded status.")
120
+ FlowcommerceSpree::RefundStatusWorker.perform_async(order.number, response.key)
121
+ end
122
+
105
123
  def add_refund_to_order(response, order)
106
124
  order.flow_data ||= {}
107
125
  order.flow_data['refunds'] ||= []
@@ -54,19 +54,20 @@ module FlowcommerceSpree
54
54
  end
55
55
 
56
56
  def refresh_checkout_token
57
- root_url = Rails.application.routes.url_helpers.root_url
58
57
  order_number = @order.number
58
+ root_url = Rails.application.routes.url_helpers.root_url
59
+ root_url_with_locale = "#{root_url}#{@order.try(:locale_path)}"
59
60
  confirmation_url = "#{root_url}flow/order-completed?order=#{order_number}&t=#{@order.guest_token}"
60
61
  @order.flow_io_attribute_add('flow_return_url', confirmation_url)
61
- @order.flow_io_attribute_add('checkout_continue_shopping_url', root_url)
62
+ @order.flow_io_attribute_add('checkout_continue_shopping_url', root_url_with_locale)
62
63
 
63
64
  FlowcommerceSpree.client.checkout_tokens.post_checkout_and_tokens_by_organization(
64
65
  FlowcommerceSpree::ORGANIZATION, discriminator: 'checkout_token_reference_form',
65
66
  order_number: order_number,
66
67
  session_id: @flow_session_id,
67
- urls: { continue_shopping: root_url,
68
+ urls: { continue_shopping: root_url_with_locale,
68
69
  confirmation: confirmation_url,
69
- invalid_checkout: root_url }
70
+ invalid_checkout: root_url_with_locale }
70
71
  )&.id
71
72
  end
72
73
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FlowcommerceSpree
4
+ class RefundStatusWorker < FlowIoWorker
5
+ sidekiq_options retry: 3, queue: :flow_io
6
+
7
+ def perform(order_number, refund_key)
8
+ response = FlowcommerceSpree.client.refunds.get_by_key(FlowcommerceSpree::ORGANIZATION, refund_key)
9
+ response_status = response.status.value
10
+ return if response_status == 'succeeded'
11
+
12
+ raise "Refund with capture pending for order: #{order_number}, refund status: #{response_status}"
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FlowcommerceSpree
4
- VERSION = '0.0.13'
4
+ VERSION = '0.0.17'
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.13
4
+ version: 0.0.17
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-08-26 00:00:00.000000000 Z
12
+ date: 2021-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: active_model_serializers
@@ -246,6 +246,7 @@ files:
246
246
  - app/views/spree/admin/shared/_order_summary_flow.html.erb
247
247
  - app/workers/flowcommerce_spree/flow_io_worker.rb
248
248
  - app/workers/flowcommerce_spree/import_item_worker.rb
249
+ - app/workers/flowcommerce_spree/refund_status_worker.rb
249
250
  - app/workers/flowcommerce_spree/update_payment_capture_worker.rb
250
251
  - config/rails_best_practices.yml
251
252
  - config/routes.rb