flowcommerce_spree 0.0.20 → 0.0.22

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: c53cdffe59a872bd84ce53aedf0765dff2f282a09114b49da5835ce16b612eb6
4
- data.tar.gz: c4279e859c545ce2b7e212fb388b461956aa53ce26fa85db352395e4d9ade47e
3
+ metadata.gz: ec0a5ef626881b9f75d419d95352d5e624b6bd798da06273d168e7c9b54fe225
4
+ data.tar.gz: 07f6c6f731489691d051fda0c3a8bbc756a378837fda6b82c2adb0e264ab93ad
5
5
  SHA512:
6
- metadata.gz: 29b8e1d3af99d46c5bf9830c790f7a16f8ebd3abe7ab213ff9dcfec690fd629769696bf27edb5eef1475aead7a74e3a1fa8fb658161def03bd77478952692e79
7
- data.tar.gz: 2a68a12590e79515fbe94f5a2a1bafc035eda7059895cbf4c475396b3b9f31400c889356ef540650f4675269c8078227665816c3192cde811d84a3152fc38ad1
6
+ metadata.gz: c2f194a02914aaa4a2e7be9a71b9fa45890eb93622b89e6fd266396daff25f015c1d3c60a051dab87944d85e312a37818e26b167d65693756105ef0743e604b9
7
+ data.tar.gz: 010a52e55f9b722f1fc318e0b76666170739648e7ec104939cd1acd99ee55a9cddba92bea8d056b625cc7a9e2326e4bf93a7a3a45f655f7b8fb3b515910dd7cb
@@ -27,6 +27,8 @@ module Spree
27
27
  response.nil? ? 0 : response['rate']&.to_f
28
28
  end
29
29
 
30
+ def get_order_tax_amount(_taxable); end
31
+
30
32
  private
31
33
 
32
34
  def prev_tax_amount(item)
@@ -36,8 +36,7 @@ module FlowcommerceSpree
36
36
 
37
37
  def store_payment_capture(order, capture)
38
38
  upsert_order_captures(order, capture)
39
- payments = order.flow_io_payments
40
- map_payment_captures_to_spree(order, payments) if payments.present?
39
+ map_payment_captures_to_spree(order)
41
40
  order
42
41
  end
43
42
 
@@ -52,33 +51,31 @@ module FlowcommerceSpree
52
51
  order.update_column(:meta, order.meta.to_json)
53
52
  end
54
53
 
55
- def map_payment_captures_to_spree(order, payments)
54
+ def map_payment_captures_to_spree(order)
55
+ payments = order.flow_io_payments
56
56
  order.flow_data['captures']&.each do |c|
57
- next unless (payment = captured_payment(payments, c, order))
57
+ next unless c['status'] == 'succeeded'
58
+
59
+ payment = map_payment(payments, c, order)
60
+ next unless payment
58
61
 
59
62
  payment.capture_events.create!(amount: c['amount'], meta: { 'flow_data' => { 'id' => c['id'] } })
60
63
  return if payment.completed? || payment.capture_events.sum(:amount) < payment.amount
61
64
 
62
65
  payment.complete
63
66
  end
64
-
65
67
  return if order.completed?
66
68
  return unless order.flow_io_captures_sum >= order.flow_io_total_amount && order.flow_io_balance_amount <= 0
67
69
 
68
70
  FlowcommerceSpree::OrderUpdater.new(order: order).finalize_order
69
71
  end
70
72
 
71
- def captured_payment(flow_order_payments, capture, order)
72
- return unless capture['status'] == 'succeeded'
73
- auth = capture.dig('authorization', 'id')
74
- payment = order.payments.first
73
+ def map_payment(payments, capture, order)
74
+ payments.present? ? captured_payment(payments, capture) : get_payments_from_flow(order, capture)
75
+ end
75
76
 
76
- if flow_order_payments.blank? && payment.response_code.blank?
77
- payment.response_code = capture.dig('authorization', 'key')
78
- payment.identifier = capture.dig('authorization', 'key')
79
- payment.save
80
- return payment
81
- end
77
+ def captured_payment(flow_order_payments, capture)
78
+ auth = capture.dig('authorization', 'id')
82
79
 
83
80
  return unless flow_order_payments&.find { |p| p['reference'] == auth }
84
81
 
@@ -88,6 +85,23 @@ module FlowcommerceSpree
88
85
 
89
86
  payment
90
87
  end
88
+
89
+ def get_payments_from_flow(order, capture)
90
+ flow_io_order ||= FlowcommerceSpree.client.orders
91
+ .get_by_number(FlowcommerceSpree::ORGANIZATION, order.number).to_hash
92
+ return unless flow_io_order[:payments]
93
+
94
+ order.flow_data['order']['payments'] = flow_io_order[:payments]
95
+ attrs_to_update = { meta: order.meta.to_json }
96
+ attrs_to_update.merge!(order.prepare_flow_addresses)
97
+ order.update_columns(attrs_to_update)
98
+ payment = order.payments.first
99
+ payment.response_code = capture.dig('authorization', 'id')
100
+ payment.identifier = capture.dig('authorization', 'id')
101
+ payment.save
102
+
103
+ payment
104
+ end
91
105
  end
92
106
  end
93
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FlowcommerceSpree
4
- VERSION = '0.0.20'
4
+ VERSION = '0.0.22'
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.20
4
+ version: 0.0.22
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: 2022-03-17 00:00:00.000000000 Z
12
+ date: 2022-11-30 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.3.1
288
+ rubygems_version: 3.0.8
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Integration of Spree with Flow API