solidus-returnly 0.2.1 → 0.3.0
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 +4 -4
- data/LICENSE +18 -23
- data/README.md +2 -8
- data/Rakefile +1 -1
- data/app/controllers/spree/api/returnly/refunds_controller.rb +0 -2
- data/app/controllers/spree/api/returnly/version_controller.rb +8 -7
- data/lib/generators/solidus_returnly/install/install_generator.rb +0 -11
- data/lib/solidus-returnly.rb +1 -1
- data/lib/solidus/returnly/calculator.rb +47 -33
- data/lib/solidus/returnly/engine.rb +1 -2
- data/lib/solidus/returnly/refunds.rb +20 -24
- data/lib/solidus/returnly/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0f4def9162a15735d56d0e508c00f16b208d490
|
4
|
+
data.tar.gz: 4a4871b9e78dbbabaf7749a4e3367011567c46d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c8a78e67e2dbcd2ec8c42f451f0105c81f2b83d71b2b44935f995722c81dfc450a7876d9aaac786f23b9fabdd26c38525c98341adde5c3b8c6c250d54505d46
|
7
|
+
data.tar.gz: 31e5fcbcb4fa977710be28e31dea281c1554248390a142f8b52e0a47354d8fb117b2eb7dcd43c183d8fb4b111caef1c2f75c837f57d10f4ff1b9118234ff29ab
|
data/LICENSE
CHANGED
@@ -1,26 +1,21 @@
|
|
1
|
-
|
2
|
-
All rights reserved.
|
1
|
+
The MIT License
|
3
2
|
|
4
|
-
|
5
|
-
are permitted provided that the following conditions are met:
|
3
|
+
Copyright (c) 2017 Returnly Technologies, Inc.
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
endorse or promote products derived from this software without specific
|
14
|
-
prior written permission.
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -3,19 +3,13 @@ Solidus Returnly
|
|
3
3
|
|
4
4
|
This gem adds the required APIs to allow returnly obtain an estimate, process a return and apply a reimbursement
|
5
5
|
|
6
|
-
|
7
|
-
KNOW ISSUES
|
8
|
-
-----------
|
9
|
-
* Currently the restock feature only supports the order shipping warehouse
|
10
|
-
* The API user should have the right to create an order there is no an special permission yet for this api
|
11
|
-
|
12
6
|
Installation
|
13
7
|
------------
|
14
8
|
|
15
9
|
Add solidus_returnly to your Gemfile:
|
16
10
|
|
17
11
|
```ruby
|
18
|
-
gem '
|
12
|
+
gem 'solidus-returnly'
|
19
13
|
```
|
20
14
|
|
21
15
|
Bundle your dependencies and run the installation generator:
|
@@ -155,4 +149,4 @@ Response:
|
|
155
149
|
```
|
156
150
|
|
157
151
|
|
158
|
-
Copyright (c) 2017 Returnly Technologies, Inc
|
152
|
+
Copyright (c) 2017 Returnly Technologies, Inc
|
data/Rakefile
CHANGED
@@ -2,7 +2,6 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module Returnly
|
4
4
|
class RefundsController < ApiController
|
5
|
-
|
6
5
|
def estimate
|
7
6
|
authorize! :create, Order
|
8
7
|
render json: Solidus::Returnly::Calculator.process(order, line_items_params)
|
@@ -39,4 +38,3 @@ module Spree
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
42
|
-
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Returnly
|
4
|
+
class VersionController < ApiController
|
5
|
+
def index
|
6
|
+
render json: {
|
7
|
+
extension_version: Solidus::Returnly::VERSION,
|
8
|
+
platform_version: Spree.solidus_version
|
9
|
+
}
|
10
|
+
end
|
9
11
|
end
|
10
|
-
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -4,26 +4,15 @@ module SolidusReturnly
|
|
4
4
|
class_option :auto_run_migrations, type: :boolean, default: false
|
5
5
|
|
6
6
|
def add_javascripts
|
7
|
-
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_returnly\n"
|
8
|
-
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_returnly\n"
|
9
7
|
end
|
10
8
|
|
11
9
|
def add_stylesheets
|
12
|
-
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_returnly\n", before: /\*\//, verbose: true
|
13
|
-
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_returnly\n", before: /\*\//, verbose: true
|
14
10
|
end
|
15
11
|
|
16
12
|
def add_migrations
|
17
|
-
run 'bundle exec rake railties:install:migrations FROM=solidus_returnly'
|
18
13
|
end
|
19
14
|
|
20
15
|
def run_migrations
|
21
|
-
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
22
|
-
if run_migrations
|
23
|
-
run 'bundle exec rake db:migrate'
|
24
|
-
else
|
25
|
-
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
26
|
-
end
|
27
16
|
end
|
28
17
|
end
|
29
18
|
end
|
data/lib/solidus-returnly.rb
CHANGED
@@ -13,16 +13,18 @@ module Solidus
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def calculated_estimate
|
16
|
-
total =
|
16
|
+
total = 0.0
|
17
|
+
sub_total = 0.0
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
line_items_return_items.values.flatten.each do |return_item|
|
20
|
+
total += return_item.total
|
21
|
+
sub_total += return_item.pre_tax_amount
|
20
22
|
end
|
21
23
|
|
22
24
|
{
|
23
25
|
total_amount: total,
|
24
|
-
subtotal_amount:
|
25
|
-
tax_amount:
|
26
|
+
subtotal_amount: sub_total,
|
27
|
+
tax_amount: total - sub_total,
|
26
28
|
discount_amount: order.promo_total,
|
27
29
|
shipping_amount: order.shipment_total,
|
28
30
|
line_items: present_line_items
|
@@ -30,44 +32,58 @@ module Solidus
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def present_line_items
|
33
|
-
line_items_return_items.map do |
|
34
|
-
line_item = line_item
|
35
|
+
line_items_return_items.values.map do |return_items|
|
36
|
+
line_item = return_items.first.inventory_unit.line_item
|
37
|
+
|
38
|
+
total_amount = 0.0
|
39
|
+
sub_total = 0.0
|
40
|
+
|
41
|
+
return_items.each do |return_item|
|
42
|
+
total_amount += return_item.total
|
43
|
+
sub_total += return_item.pre_tax_amount
|
44
|
+
end
|
35
45
|
|
36
46
|
{
|
37
47
|
order_line_item_id: line_item.id,
|
38
|
-
quantity:
|
39
|
-
total_amount:
|
40
|
-
tax_amount:
|
41
|
-
discount_amount: line_item.adjustment_total,
|
48
|
+
quantity: return_items.size,
|
49
|
+
total_amount: total_amount,
|
50
|
+
tax_amount: total_amount - sub_total
|
42
51
|
}
|
43
52
|
end
|
44
53
|
end
|
45
54
|
|
55
|
+
def set_tax(return_item)
|
56
|
+
percent_of_tax = (return_item.amount <= 0) ? 0 : return_item.amount /
|
57
|
+
Spree::ReturnItem.refund_amount_calculator.new.compute(return_item)
|
46
58
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
59
|
+
additional_tax_total = percent_of_tax * return_item.inventory_unit.additional_tax_total
|
60
|
+
included_tax_total = percent_of_tax * return_item.inventory_unit.included_tax_total
|
61
|
+
|
62
|
+
return_item.additional_tax_total = additional_tax_total
|
63
|
+
return_item.included_tax_total = included_tax_total
|
52
64
|
|
65
|
+
return_item
|
66
|
+
end
|
53
67
|
|
54
68
|
def line_items_return_items
|
55
69
|
found_return_items = {}
|
56
70
|
|
57
|
-
|
71
|
+
line_items.each do |line_item|
|
58
72
|
quantity = line_item[:quantity].to_i
|
59
73
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
74
|
+
next unless quantity > 0
|
75
|
+
available_inventory_units = line_item_inventory_unit(line_item).slice(0, quantity)
|
76
|
+
|
77
|
+
available_inventory_units.each do |inventory_unit|
|
78
|
+
found_return_items[line_item[:order_line_item_id]] ||= []
|
79
|
+
|
80
|
+
return_item = Spree::ReturnItem.new({ amount: inventory_unit.line_item.price,
|
81
|
+
acceptance_status: 'accepted',
|
82
|
+
inventory_unit_id: inventory_unit.id,
|
83
|
+
reception_status_event: 'receive'
|
84
|
+
})
|
85
|
+
|
86
|
+
found_return_items[line_item[:order_line_item_id]] << set_tax(return_item)
|
71
87
|
end
|
72
88
|
end
|
73
89
|
|
@@ -75,11 +91,11 @@ module Solidus
|
|
75
91
|
end
|
76
92
|
|
77
93
|
def line_item_inventory_unit(line_item)
|
78
|
-
returnable_inventory_units.select {|iu| iu.line_item_id == line_item[:order_line_item_id].to_i}
|
94
|
+
returnable_inventory_units.select { |iu| iu.line_item_id == line_item[:order_line_item_id].to_i }
|
79
95
|
end
|
80
96
|
|
81
97
|
def line_item(id)
|
82
|
-
returnable_line_items.
|
98
|
+
returnable_line_items.find { |i| i.id == id.to_i }
|
83
99
|
end
|
84
100
|
|
85
101
|
def returnable_inventory_units
|
@@ -93,10 +109,8 @@ module Solidus
|
|
93
109
|
end
|
94
110
|
|
95
111
|
def requested_line_items
|
96
|
-
line_items.map {|item| item[:order_line_item_id]}
|
112
|
+
line_items.map { |item| item[:order_line_item_id] }
|
97
113
|
end
|
98
114
|
end
|
99
115
|
end
|
100
116
|
end
|
101
|
-
|
102
|
-
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Solidus
|
2
2
|
module Returnly
|
3
3
|
class Refunds
|
4
|
-
attr_accessor :calculator, :order, :line_items, :restock, :transactions
|
4
|
+
attr_accessor :calculator, :order, :line_items, :restock, :transactions, :customer_return
|
5
5
|
|
6
6
|
def initialize(order:, line_items:, restock: true, transactions:)
|
7
7
|
self.order = order
|
@@ -9,25 +9,19 @@ module Solidus
|
|
9
9
|
self.calculator = Calculator.new order, line_items
|
10
10
|
self.restock = restock
|
11
11
|
self.transactions = transactions
|
12
|
-
|
13
|
-
|
14
|
-
def restock_return(customer_return)
|
15
|
-
customer_return.return_items.each do |item|
|
16
|
-
customer_return.stock_location.restock(item.inventory_unit.variant, 1, customer_return)
|
17
|
-
end
|
12
|
+
self.customer_return = Spree::CustomerReturn.new customer_return_params
|
18
13
|
end
|
19
14
|
|
20
15
|
def proceed!
|
21
|
-
customer_return = Spree::CustomerReturn.new customer_return_params
|
22
16
|
customer_return.return_items = calculator.line_items_return_items.values.flatten
|
23
17
|
|
24
18
|
customer_return.return_items.each do |return_item|
|
25
|
-
return_item.amount = refund_amount_per_item
|
26
|
-
return_item.resellable =
|
19
|
+
return_item.amount = refund_amount_per_item - Money.from_amount(return_item.total - return_item.pre_tax_amount)
|
20
|
+
return_item.resellable = restock
|
27
21
|
end
|
28
22
|
|
29
23
|
if customer_return.save!
|
30
|
-
|
24
|
+
perform_reimbursement
|
31
25
|
processed_customer_return(customer_return, reimbursement)
|
32
26
|
end
|
33
27
|
end
|
@@ -37,32 +31,35 @@ module Solidus
|
|
37
31
|
refund_id: customer_return.number,
|
38
32
|
created_at: customer_return.created_at,
|
39
33
|
updated_at: customer_return.updated_at,
|
40
|
-
line_items: customer_return.return_items.map {|
|
34
|
+
line_items: customer_return.return_items.group_by{ |ri| ri.inventory_unit.line_item.id }.map {|_, return_items|
|
41
35
|
{
|
42
|
-
refund_line_item_id:
|
43
|
-
order_line_item_id:
|
44
|
-
|
36
|
+
refund_line_item_id: return_items.first.id,
|
37
|
+
order_line_item_id: return_items.first.inventory_unit.line_item.id,
|
38
|
+
refunded_amount_per_item: return_items.first.amount.to_f,
|
39
|
+
total_refunded_per_line_item: return_items.sum(&:amount).to_f,
|
40
|
+
quantity: return_items.size
|
45
41
|
}
|
46
42
|
},
|
47
43
|
transactions: [
|
48
44
|
id: reimbursement.id,
|
49
45
|
amount: reimbursement.total
|
50
46
|
],
|
51
|
-
|
52
|
-
restock: true
|
47
|
+
restock: restock
|
53
48
|
}
|
54
49
|
end
|
55
50
|
|
56
|
-
def perform_reimbursement
|
57
|
-
reimbursement = Spree::Reimbursement.build_from_customer_return(customer_return)
|
51
|
+
def perform_reimbursement
|
58
52
|
reimbursement.save!
|
59
53
|
reimbursement.perform!
|
60
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
def reimbursement
|
57
|
+
@_reimbursement ||= Spree::Reimbursement.build_from_customer_return(customer_return)
|
61
58
|
end
|
62
59
|
|
63
60
|
def customer_return_params
|
64
61
|
{
|
65
|
-
stock_location_id: stock_location_id
|
62
|
+
stock_location_id: stock_location_id
|
66
63
|
}
|
67
64
|
end
|
68
65
|
|
@@ -71,7 +68,7 @@ module Solidus
|
|
71
68
|
end
|
72
69
|
|
73
70
|
def refund_available_amount
|
74
|
-
@available_amount ||=
|
71
|
+
@available_amount ||= transactions.sum { |t| Money.from_amount(t[:amount].to_f) }
|
75
72
|
end
|
76
73
|
|
77
74
|
def refund_amount_per_item
|
@@ -79,5 +76,4 @@ module Solidus
|
|
79
76
|
end
|
80
77
|
end
|
81
78
|
end
|
82
|
-
|
83
|
-
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus-returnly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Returnly Technologies, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus
|
@@ -234,6 +234,20 @@ dependencies:
|
|
234
234
|
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: byebug
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
237
251
|
description: Solidus API extensions for returnly
|
238
252
|
email: support@returnly.com
|
239
253
|
executables: []
|