flowcommerce_spree 0.0.11 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/current_zone_loader_decorator.rb +10 -6
- data/app/controllers/flowcommerce_spree/orders_controller.rb +7 -1
- data/app/controllers/users/sessions_controller_decorator.rb +3 -1
- data/app/models/spree/gateway/flow_io.rb +12 -3
- data/app/services/flowcommerce_spree/order_sync.rb +5 -4
- data/app/workers/flowcommerce_spree/refund_status_worker.rb +15 -0
- data/lib/flowcommerce_spree/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ed3330958e03459888c682dd28c10106da11922d09009f661d3e8d1a29d32a4
|
4
|
+
data.tar.gz: ae942f91846355379eac2fb8a54b8ca6156c749b20732137250c35e3a2cc605f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc69d6f4e090cf11bdd80f95f7534451ae060b862f896ac0fbeff276f51b98a672cb7132245408fe97393c8cc118cba8917ee570f530d20534d0a375697e423e
|
7
|
+
data.tar.gz: 73b06be7f5ef0d6db3532e992f7f3daba0eb71e9a65e3d72b25ba5a4044630213781979cc74e768689f1f729180f46064e41d581ff4ab50f3957100319ed6e32
|
@@ -6,14 +6,18 @@ CurrentZoneLoader.module_eval do
|
|
6
6
|
def current_zone
|
7
7
|
return @current_zone if defined?(@current_zone)
|
8
8
|
|
9
|
-
@current_zone = if (session_region_name = session['region']&.[](
|
9
|
+
@current_zone = if (session_region_name = session['region']&.[](:name))
|
10
10
|
Spree::Zones::Product.find_by(name: session_region_name, status: 'active')
|
11
11
|
end
|
12
12
|
|
13
|
-
@current_zone ||=
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
@current_zone ||= fetch_current_zone
|
14
|
+
@current_zone
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_current_zone
|
18
|
+
if request_iso_code.present?
|
19
|
+
@current_zone = flow_zone || Spree::Country.find_by(iso: request_iso_code)&.product_zones&.active&.first
|
20
|
+
end
|
17
21
|
|
18
22
|
@current_zone ||= Spree::Zones::Product.find_by(name: 'International') ||
|
19
23
|
Spree::Zones::Product.new(name: 'International', taxon_ids: [], currencies: %w[USD CAD])
|
@@ -21,8 +25,8 @@ CurrentZoneLoader.module_eval do
|
|
21
25
|
current_zone_name = @current_zone.name
|
22
26
|
session['region'] = { name: current_zone_name, available_currencies: @current_zone.available_currencies,
|
23
27
|
request_iso_code: request_iso_code }
|
24
|
-
|
25
28
|
Rails.logger.debug("Using product zone: #{current_zone_name}")
|
29
|
+
|
26
30
|
@current_zone
|
27
31
|
end
|
28
32
|
|
@@ -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
|
-
|
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
|
@@ -11,7 +11,9 @@ module Users
|
|
11
11
|
FlowcommerceSpree::OrderSync.new(order: current_order, flow_session_id: flow_session_id).synchronize!
|
12
12
|
return render json: { error: :checkout_token_missing }, status: 422 if checkout_token.blank?
|
13
13
|
|
14
|
-
|
14
|
+
checkout_url = ENV['FLOW_CHECKOUT_URL'] || 'https://checkout.flow.io'
|
15
|
+
|
16
|
+
render json: { checkout_url: "#{checkout_url}/tokens/#{checkout_token}" }, status: 200
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
@@ -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
|
@@ -90,18 +92,25 @@ module Spree
|
|
90
92
|
currency: order.currency)
|
91
93
|
response = FlowcommerceSpree.client.refunds.post(FlowcommerceSpree::ORGANIZATION, refund_form)
|
92
94
|
response_status = response.status.value
|
93
|
-
if response_status
|
95
|
+
if REFUND_VALID_STATES.include? response_status
|
94
96
|
add_refund_to_order(response, order)
|
97
|
+
schedule_status_check(response, order)
|
95
98
|
ActiveMerchant::Billing::Response.new(true,
|
96
99
|
REFUND_SUCCESS,
|
97
100
|
response.to_hash,
|
98
101
|
authorization: response.authorization.id)
|
99
102
|
else
|
100
|
-
|
101
|
-
ActiveMerchant::Billing::Response.new(false, msg, {}, {})
|
103
|
+
ActiveMerchant::Billing::Response.new(false, "Partial refund fail. Details: #{response_status}", {}, {})
|
102
104
|
end
|
103
105
|
end
|
104
106
|
|
107
|
+
def schedule_status_check(response, order)
|
108
|
+
return if response.status.value != REFUND_PENDING
|
109
|
+
|
110
|
+
Rails.logger.warn("[!] #{self.class} for #{order.number} - refund request without succeeded status.")
|
111
|
+
FlowcommerceSpree::RefundStatusWorker.perform_async(order.number, response.key)
|
112
|
+
end
|
113
|
+
|
105
114
|
def add_refund_to_order(response, order)
|
106
115
|
order.flow_data ||= {}
|
107
116
|
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',
|
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:
|
68
|
+
urls: { continue_shopping: root_url_with_locale,
|
68
69
|
confirmation: confirmation_url,
|
69
|
-
invalid_checkout:
|
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
|
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.15
|
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-09-03 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
|