piggybak 0.4.19 → 0.4.20

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,10 +14,12 @@ Modular / mountable ecommerce gem. Features:
14
14
  Installation
15
15
  ========
16
16
 
17
- * First, add to Gemfile:
17
+ * First, add to Gemfile (from RubyGems, with version specified, or source) with *one* of the following options:
18
18
 
19
- gem "piggybak", :git => "git://github.com/stephskardal/demo.git"
20
-
19
+ gem "piggybak"
20
+ gem "piggybak", '0.4.19'
21
+ gem "piggybak", :git => "git://github.com/stephskardal/piggybak.git"
22
+
21
23
  * Next, run rake task to copy migrations:
22
24
 
23
25
  rake piggybak_engine:install:migrations
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.19
1
+ 0.4.20
@@ -112,14 +112,20 @@ module Piggybak
112
112
  order.recorded_changer = current_user.id
113
113
 
114
114
  if can?(:cancel, order)
115
+ order.adjustments << Piggybak::Adjustment.new(:total => -1*order.total,
116
+ :note => "Cancelled order.",
117
+ :source_id => current_user.id,
118
+ :source_type => "User")
115
119
  order.line_items.each do |line_item|
116
120
  line_item.destroy
117
121
  end
118
- order.payments.each do |payment|
119
- payment.refund
122
+ order.shipments.each do |shipment|
123
+ shipment.destroy
120
124
  end
121
125
  order.update_attribute(:status, "cancelled")
122
-
126
+ order.update_attribute(:total, 0.00)
127
+ order.update_attribute(:total_due, 0.00)
128
+
123
129
  flash[:notice] = "Order #{order.id} cancelled"
124
130
  end
125
131
 
@@ -25,7 +25,7 @@ module Piggybak
25
25
  validates_presence_of :status, :email, :phone, :total, :total_due, :tax_charge, :created_at, :ip_address, :user_agent
26
26
 
27
27
  after_initialize :initialize_nested, :initialize_request
28
- before_validation :set_defaults
28
+ before_validation :set_defaults, :manage_payment_adjustments
29
29
  after_validation :update_totals
30
30
  before_save :process_payments, :update_status, :set_new_record
31
31
  after_save :record_order_note
@@ -56,6 +56,17 @@ module Piggybak
56
56
  end
57
57
  end
58
58
 
59
+ def manage_payment_adjustments
60
+ payments.each do |payment|
61
+ if payment.refund_amt.present?
62
+ self.adjustments << Piggybak::Adjustment.new(:total => -1*payment.refund_amt.to_f,
63
+ :note => "Refund against Payment ##{payment.id} given.",
64
+ :source_id => self.recorded_changer,
65
+ :source_type => "User")
66
+ end
67
+ end
68
+ end
69
+
59
70
  def process_payments
60
71
  has_errors = false
61
72
  self.payments.each do |payment|
@@ -65,8 +76,15 @@ module Piggybak
65
76
  end
66
77
 
67
78
  self.total_due = self.total
79
+
80
+ adjustments.each do |adjustment|
81
+ if !adjustment._destroy
82
+ self.total_due -= adjustment.total
83
+ end
84
+ end
85
+
68
86
  payments_total = payments.inject(0) do |payments_total, payment|
69
- payments_total += payment.total if payment.status == "paid"
87
+ payments_total += payment.total
70
88
  payments_total
71
89
  end
72
90
  self.total_due -= payments_total
@@ -133,26 +151,23 @@ module Piggybak
133
151
  self.total += self.tax_charge
134
152
 
135
153
  shipments.each do |shipment|
136
- if (shipment.new_record? || shipment.status != "shipped") && shipment.shipping_method
154
+ if !shipment._destroy && (shipment.new_record? || shipment.status != "shipped") && shipment.shipping_method
137
155
  calculator = shipment.shipping_method.klass.constantize
138
156
  shipment.total = calculator.rate(shipment.shipping_method, self)
139
- end
140
- if !shipment._destroy
141
157
  self.total += shipment.total
142
158
  end
143
159
  end
144
160
 
161
+ self.total_due = self.total
162
+
145
163
  adjustments.each do |adjustment|
146
164
  if !adjustment._destroy
147
- self.total += adjustment.total
165
+ self.total_due -= adjustment.total
148
166
  end
149
167
  end
150
168
 
151
- self.total_due = self.total
152
169
  payments.each do |payment|
153
- if payment.status == "paid"
154
- self.total_due -= payment.total
155
- end
170
+ self.total_due -= payment.total
156
171
  end
157
172
  end
158
173
 
@@ -12,9 +12,10 @@ module Piggybak
12
12
 
13
13
  attr_accessor :number
14
14
  attr_accessor :verification_value
15
+ attr_accessor :refund_amt
15
16
 
16
17
  def status_enum
17
- ["paid", "refunded"]
18
+ ["paid"]
18
19
  end
19
20
 
20
21
  def month_enum
@@ -57,29 +58,13 @@ module Piggybak
57
58
  end
58
59
  end
59
60
 
60
- # TODO: Add refund support at some point
61
61
  # Note: It is not added now, because for methods that do not store
62
62
  # user profiles, a credit card number must be passed
63
63
  # If encrypted credit cards are stored on the system,
64
64
  # this can be updated
65
65
  def refund
66
- =begin
67
- # ActiveMerchant::Billing::Base.mode = Piggybak.config.activemerchant_mode
68
-
69
- begin
70
- payment_gateway = self.payment_method.klass.constantize
71
- gateway = payment_gateway::KLASS.new(self.payment_method.key_values)
72
-
73
- b = gateway.refund(self.total*100, self.transaction_id, { :card_number => "4111111111111111" })
74
- rescue Exception => e
75
- return e.inspect
76
- end
77
- =end
78
-
79
- self.update_attribute(:status, "refunded")
80
- self.order.update_attribute(:total_due, self.order.total_due + self.total)
81
-
82
- return "Marked as Refunded"
66
+ # TODO: Create ActiveMerchant refund integration
67
+ return
83
68
  end
84
69
 
85
70
  def admin_label
@@ -8,9 +8,12 @@ Phone: <%= @order.phone %>
8
8
  <% end -%>
9
9
 
10
10
  Subtotal: <%= number_to_currency @order.line_items.inject(0) { |subtotal, li| subtotal + li.total } %>
11
+ Shipping & Handling: <%= number_to_currency @order.shipments.inject(0) { |shipping, shipment| shipping + shipment.total } %>
11
12
  Tax: <%= number_to_currency @order.tax_charge %>
12
- Shipping: <%= number_to_currency @order.shipments.inject(0) { |shipping, shipment| shipping + shipment.total } %>
13
13
  Total: <%= number_to_currency @order.total %>
14
+ Less Payment: <%= number_to_currency(@order.payments.inject(0) { |total, p| total + p.total if p.status == "paid" }) %>
15
+ Adjustments: <%= number_to_currency(@order.adjustments.inject(0) { |total, adj| total + adj.total }) %>
16
+ Balance Due: <%= number_to_currency @order.total_due %>
14
17
 
15
18
  Billing Information
16
19
  <%= raw @order.billing_address.display.gsub("<br />", "\n") %>
@@ -15,19 +15,21 @@ N/A
15
15
  <td>$<%= "%.2f" % form.object.tax_charge %></td>
16
16
  </tr>
17
17
  <tr>
18
- <td>Adjustments</td>
19
- <td>$<%= "%.2f" % form.object.adjustments.inject(0) { |total, adj| total + adj.total } %></td>
18
+ <td>Total</td>
19
+ <td>$<%= "%.2f" % form.object.total %></td>
20
20
  </tr>
21
21
  <tr>
22
- <td>Order Total</td>
23
- <td>$<%= "%.2f" % form.object.total %></td>
22
+ <td>Payments</td>
23
+ <td>$<%= "%.2f" % form.object.payments.inject(0) { |total, payment| total + payment.total } %></td>
24
24
  </tr>
25
- <% if form.object.status != "cancelled" -%>
26
25
  <tr>
27
- <td>Total Due</td>
26
+ <td>Adjustments</td>
27
+ <td>$<%= "%.2f" % form.object.adjustments.inject(0) { |total, adj| total + adj.total } %></td>
28
+ </tr>
29
+ <tr>
30
+ <td>Balance Due</td>
28
31
  <td>$<%= "%.2f" % form.object.total_due %></td>
29
32
  </tr>
30
- <% end -%>
31
33
  <tr>
32
34
  <td>Created at</td>
33
35
  <td><%= form.object.created_at.strftime("%m-%d-%Y") %></td>
@@ -39,7 +41,9 @@ N/A
39
41
  <ul>
40
42
  <li><%= link_to "Send or Resend Email Confirmation", piggybak.email_order_url(form.object.id) %></li>
41
43
  <li><%= link_to "View as Text", piggybak.download_order_url(form.object.id) %></li>
44
+ <% if form.object.total_due == 0.00 -%>
42
45
  <li><%= link_to "Cancel Order", piggybak.cancel_order_url(form.object.id) %> (This does not mark the payment gateway payments. This marks payments tied to ths order in this database as refunded, and marks the order as cancelled.)</li>
46
+ <% end -%>
43
47
  </ul>
44
48
  </td>
45
49
  </tr>
@@ -123,14 +123,10 @@ module Piggybak
123
123
  field :email
124
124
  field :phone
125
125
  field :ip_address do
126
- read_only do
127
- !bindings[:object].new_record?
128
- end
126
+ read_only true
129
127
  end
130
128
  field :user_agent do
131
- read_only do
132
- !bindings[:object].new_record?
133
- end
129
+ read_only true
134
130
  end
135
131
  field :billing_address do
136
132
  help "Required"
@@ -258,7 +254,7 @@ module Piggybak
258
254
  end
259
255
  end
260
256
  field :total do
261
- help "A negative value will add credit to an order. A positive value will add charges to the order."
257
+ help "A negative value represents credit. A positive value represents charge."
262
258
  read_only do
263
259
  !bindings[:object].new_record?
264
260
  end
@@ -328,12 +324,11 @@ module Piggybak
328
324
  end
329
325
  help "This will automatically be calculated at the time of processing."
330
326
  end
331
- field :actions do
327
+ field :refund_amt do
332
328
  visible do
333
329
  !bindings[:object].new_record?
334
330
  end
335
- partial "payment_refund"
336
- help "This does not mark the payment gateway payment as refunded. This only marks this local payment as refunded."
331
+ help "This does not interact with the payment gateway."
337
332
  end
338
333
  end
339
334
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "piggybak"
8
- s.version = "0.4.19"
8
+ s.version = "0.4.20"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steph Skardal", "Brian Buchalter"]
12
- s.date = "2012-07-21"
12
+ s.date = "2012-07-23"
13
13
  s.description = "Mountable ecommerce"
14
14
  s.email = "steph@endpoint.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piggybak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.19
4
+ version: 0.4.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-21 00:00:00.000000000 Z
13
+ date: 2012-07-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: countries
17
- requirement: &13456480 !ruby/object:Gem::Requirement
17
+ requirement: &16897980 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *13456480
25
+ version_requirements: *16897980
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
- requirement: &13469800 !ruby/object:Gem::Requirement
28
+ requirement: &16908660 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *13469800
36
+ version_requirements: *16908660
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: jeweler
39
- requirement: &13468720 !ruby/object:Gem::Requirement
39
+ requirement: &16904040 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.6.4
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *13468720
47
+ version_requirements: *16904040
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &13468100 !ruby/object:Gem::Requirement
50
+ requirement: &16911640 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *13468100
58
+ version_requirements: *16911640
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rspec-rails
61
- requirement: &13467260 !ruby/object:Gem::Requirement
61
+ requirement: &16924000 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 2.7.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *13467260
69
+ version_requirements: *16924000
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: factory_girl
72
- requirement: &13466500 !ruby/object:Gem::Requirement
72
+ requirement: &16934680 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *13466500
80
+ version_requirements: *16934680
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: diff-lcs
83
- requirement: &13480520 !ruby/object:Gem::Requirement
83
+ requirement: &16933400 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *13480520
91
+ version_requirements: *16933400
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: shoulda
94
- requirement: &13474840 !ruby/object:Gem::Requirement
94
+ requirement: &16931440 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *13474840
102
+ version_requirements: *16931440
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: simplecov
105
- requirement: &13488120 !ruby/object:Gem::Requirement
105
+ requirement: &16930900 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *13488120
113
+ version_requirements: *16930900
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: tzinfo
116
- requirement: &13485880 !ruby/object:Gem::Requirement
116
+ requirement: &16930280 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *13485880
124
+ version_requirements: *16930280
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: devise
127
- requirement: &13496320 !ruby/object:Gem::Requirement
127
+ requirement: &16927880 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *13496320
135
+ version_requirements: *16927880
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: rails_admin
138
- requirement: &13491320 !ruby/object:Gem::Requirement
138
+ requirement: &16943060 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: '0'
144
144
  type: :runtime
145
145
  prerelease: false
146
- version_requirements: *13491320
146
+ version_requirements: *16943060
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: devise
149
- requirement: &13503000 !ruby/object:Gem::Requirement
149
+ requirement: &16942480 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: '0'
155
155
  type: :runtime
156
156
  prerelease: false
157
- version_requirements: *13503000
157
+ version_requirements: *16942480
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: activemerchant
160
- requirement: &13502040 !ruby/object:Gem::Requirement
160
+ requirement: &16941740 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
@@ -165,10 +165,10 @@ dependencies:
165
165
  version: '0'
166
166
  type: :runtime
167
167
  prerelease: false
168
- version_requirements: *13502040
168
+ version_requirements: *16941740
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: countries
171
- requirement: &13500940 !ruby/object:Gem::Requirement
171
+ requirement: &16940960 !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
174
174
  - - ! '>='
@@ -176,10 +176,10 @@ dependencies:
176
176
  version: '0'
177
177
  type: :runtime
178
178
  prerelease: false
179
- version_requirements: *13500940
179
+ version_requirements: *16940960
180
180
  - !ruby/object:Gem::Dependency
181
181
  name: rspec
182
- requirement: &13499920 !ruby/object:Gem::Requirement
182
+ requirement: &16940020 !ruby/object:Gem::Requirement
183
183
  none: false
184
184
  requirements:
185
185
  - - ! '>='
@@ -187,10 +187,10 @@ dependencies:
187
187
  version: '0'
188
188
  type: :development
189
189
  prerelease: false
190
- version_requirements: *13499920
190
+ version_requirements: *16940020
191
191
  - !ruby/object:Gem::Dependency
192
192
  name: rspec-rails
193
- requirement: &13498860 !ruby/object:Gem::Requirement
193
+ requirement: &16938740 !ruby/object:Gem::Requirement
194
194
  none: false
195
195
  requirements:
196
196
  - - ! '>='
@@ -198,10 +198,10 @@ dependencies:
198
198
  version: '0'
199
199
  type: :development
200
200
  prerelease: false
201
- version_requirements: *13498860
201
+ version_requirements: *16938740
202
202
  - !ruby/object:Gem::Dependency
203
203
  name: diff-lcs
204
- requirement: &13497320 !ruby/object:Gem::Requirement
204
+ requirement: &16937620 !ruby/object:Gem::Requirement
205
205
  none: false
206
206
  requirements:
207
207
  - - ! '>='
@@ -209,10 +209,10 @@ dependencies:
209
209
  version: '0'
210
210
  type: :development
211
211
  prerelease: false
212
- version_requirements: *13497320
212
+ version_requirements: *16937620
213
213
  - !ruby/object:Gem::Dependency
214
214
  name: factory_girl
215
- requirement: &13512640 !ruby/object:Gem::Requirement
215
+ requirement: &16936040 !ruby/object:Gem::Requirement
216
216
  none: false
217
217
  requirements:
218
218
  - - ! '>='
@@ -220,10 +220,10 @@ dependencies:
220
220
  version: '0'
221
221
  type: :development
222
222
  prerelease: false
223
- version_requirements: *13512640
223
+ version_requirements: *16936040
224
224
  - !ruby/object:Gem::Dependency
225
225
  name: shoulda
226
- requirement: &13510300 !ruby/object:Gem::Requirement
226
+ requirement: &16950660 !ruby/object:Gem::Requirement
227
227
  none: false
228
228
  requirements:
229
229
  - - ! '>='
@@ -231,7 +231,7 @@ dependencies:
231
231
  version: '0'
232
232
  type: :development
233
233
  prerelease: false
234
- version_requirements: *13510300
234
+ version_requirements: *16950660
235
235
  description: Mountable ecommerce
236
236
  email: steph@endpoint.com
237
237
  executables: []
@@ -399,7 +399,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
399
399
  version: '0'
400
400
  segments:
401
401
  - 0
402
- hash: -3204187034108170490
402
+ hash: -1592593640259621563
403
403
  required_rubygems_version: !ruby/object:Gem::Requirement
404
404
  none: false
405
405
  requirements: