flowcommerce_spree 0.0.13 → 0.0.14

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: 78bcd2ec2168ade147fb11d14e8a8f94a30133a0f6fa2df225c3abd0cbb7a7ff
4
+ data.tar.gz: fc255f7fc844d6209cd852c84a8f86db9cb97b3ad8d1e80586e5f692ec51a055
5
5
  SHA512:
6
- metadata.gz: 465a5624b6a9e4a80732dca72a5d618f1cd14064fb3005212f25f7e9d687c2f2c48ab90992bcae145cb87a8de16bc33c37e5d924c545372fb31f0ff7f90df2d2
7
- data.tar.gz: dcfc5356d0954104ab64c0d4da2282fd21cba1600613c84565734d50ed58bd1c1289bd936e3d8624f2703ed80a3e48c7af4ad20442041fb9dc590c3852839b37
6
+ metadata.gz: 15778423ce300091577ff41aad2c639da5ddb59421db10cf37e7844a9c74997220a0864788675a98d81c330f2fa800fe7ee38bcf703cb813333f2cf99af01687
7
+ data.tar.gz: 8b0795bf474136c0c7abd383933b2d809e6e1efc26e00b4c40164f389d707d50c75e7c6f950fc3285d3fc898a7442c2555dfc6d959b067b5a8851c7c9a56fc63
@@ -14,7 +14,11 @@ module FlowcommerceSpree
14
14
  flow_updater = FlowcommerceSpree::OrderUpdater.new(order: order)
15
15
  flow_updater.complete_checkout
16
16
 
17
- redirect_to "/thankyou?order=#{params[:order]}&t=#{params[:t]}"
17
+ redirection_path = "/thankyou?order=#{params[:order]}&t=#{params[:t]}"
18
+ locale = order.locale_path
19
+ redirection_path = "/#{locale}#{redirection_path}" if locale
20
+
21
+ redirect_to redirection_path
18
22
  end
19
23
  end
20
24
  end
@@ -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 == REFUND_SUCCESS
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
- msg = "Partial refund fail. Details: #{response_status}"
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', 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.14'
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.14
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-02 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