caboose-cms 0.7.32 → 0.7.33

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
  SHA1:
3
- metadata.gz: cf73a0624a9f94e70152332af86b9243830223b4
4
- data.tar.gz: 7e0652094da351a6fac5869d5640519a6cd75227
3
+ metadata.gz: eee3bd393d5eb753c883fd555d241aa3d790640a
4
+ data.tar.gz: f6fa71d9f3932d75862609bbc75d0b1cc171db97
5
5
  SHA512:
6
- metadata.gz: 74fdea743f279164ccb14b373dbe6037e12e48a9fbc784df3329395ac65905dbfd40817477d47a1399028d735f6b0c87e4e1f450478effcfba6905236eacd6f3
7
- data.tar.gz: 704317bed6f156998edc1eef3c94c2e900ae4ec1b8bcbac30c0ab5434233e050e883c3834e0d5e0e5dc66beab023b6a2965aa85008b62107c6e6f5b55cb8eec0
6
+ metadata.gz: f57e8f2ec6374e8f43bf3a235415544844fbd250f92c576b629ab802ec740f785314dd7cb36ef843e21a4abfb459983c56c44fea0abcadce65a99ddfdda45e20
7
+ data.tar.gz: 7ee62db868c39619c6ab397fb733ee4a09962ebdc7c44005683b6fb1eecfbe6abe7a87e4441ed8d7bba116a2ae0455d3d52b6ab5a701077b9802ff06c75d703d
@@ -135,6 +135,85 @@ module Caboose
135
135
  #
136
136
  # ap response
137
137
  #end
138
+
139
+ def self.sync_order_transactions(site_id, d1, d2)
140
+
141
+ site = Site.find(site_id)
142
+ sc = site.store_config
143
+
144
+ # Get all the batches in the date period
145
+ rt = AuthorizeNet::Reporting::Transaction.new(sc.pp_username, sc.pp_password)
146
+ resp = rt.get_settled_batch_list(d1, d2, true)
147
+ return false if !resp.success?
148
+ batch_ids = []
149
+ batches = resp.batch_list
150
+ batch_ids = batches.collect{ |batch| batch.id }
151
+
152
+ orders = {}
153
+
154
+ # Settled transactions
155
+ batch_ids.each do |batch_id|
156
+ rt = AuthorizeNet::Reporting::Transaction.new(sc.pp_username, sc.pp_password)
157
+ resp = rt.get_transaction_list(batch_id)
158
+ next if !resp.success?
159
+
160
+ transactions = resp.transactions
161
+ transactions.each do |t|
162
+ order_id = t.order.invoice_num
163
+ orders[order_id] = [] if orders[order_id].nil?
164
+ orders[order_id] << t
165
+ end
166
+ end
167
+
168
+ # Unsettled transactions
169
+ rt = AuthorizeNet::Reporting::Transaction.new(sc.pp_username, sc.pp_password)
170
+ resp = rt.get_unsettled_transaction_list
171
+ if resp.success?
172
+ transactions = resp.transactions
173
+ transactions.each do |t|
174
+ order_id = t.order.invoice_num
175
+ orders[order_id] = [] if orders[order_id].nil?
176
+ orders[order_id] << t
177
+ end
178
+ end
179
+
180
+ # Verify all the transactions exist locally
181
+ orders.each do |order_id, transactions|
182
+ transactions.each do |t|
183
+ self.verify_order_transaction_exists(t)
184
+ end
185
+ end
186
+
187
+ # Update the financial_status and status of all affected orders
188
+ orders.each do |order_id, transactions|
189
+ order = Order.where(:id => order_id).first
190
+ next if order.nil?
191
+ order.determine_statuses
192
+ end
193
+ end
138
194
 
195
+ def self.verify_order_transaction_exists(t)
196
+
197
+ order_id = t.order.invoice_num
198
+ ttype = OrderTransaction.type_from_authnet_status(t.status)
199
+
200
+ ot = OrderTransaction.where(:order_id => order_id, :transaction_id => t.id, :transaction_type => ttype).first
201
+ if ot
202
+ puts "Found order transaction for #{t.id}."
203
+ return
204
+ end
205
+
206
+ puts "Creating order transaction for #{t.id}..."
207
+ ot = OrderTransaction.create(
208
+ :order_id => order_id,
209
+ :transaction_id => t.id,
210
+ :transaction_type => ttype,
211
+ :amount => t.settle_amount,
212
+ :date_processed => t.submitted_at,
213
+ :success => !(t.status == 'declined')
214
+ )
215
+ end
216
+
217
+
139
218
  end
140
219
  end
@@ -85,7 +85,8 @@ class Caboose::Block < ActiveRecord::Base
85
85
  if b.block_type.field_type == 'file'
86
86
  return b.media.file if b.media
87
87
  return b.file
88
- end
88
+ end
89
+ return "" if b.value.nil? || b.value.strip.length == 0
89
90
  view = options && options[:view] ? options[:view] : ActionView::Base.new(ActionController::Base.view_paths)
90
91
  return view.render(:inline => b.value, :locals => options)
91
92
  end
@@ -422,6 +422,33 @@ module Caboose
422
422
  OrdersMailer.configure_for_site(self.site_id).customer_payment_authorization(self).deliver
423
423
  end
424
424
 
425
+ def determine_statuses
426
+
427
+ auth = false
428
+ capture = false
429
+ void = false
430
+ refund = false
431
+
432
+ self.order_transactions.each do |ot|
433
+ auth = true if ot.transaction_type == OrderTransaction::TYPE_AUTHORIZE && ot.success == true
434
+ capture = true if ot.transaction_type == OrderTransaction::TYPE_CAPTURE && ot.success == true
435
+ void = true if ot.transaction_type == OrderTransaction::TYPE_VOID && ot.success == true
436
+ refund = true if ot.transaction_type == OrderTransaction::TYPE_REFUND && ot.success == true
437
+ end
438
+
439
+ if refund then self.financial_status = Order::FINANCIAL_STATUS_REFUNDED
440
+ elsif void then self.financial_status = Order::FINANCIAL_STATUS_VOIDED
441
+ elsif capture then self.financial_status = Order::FINANCIAL_STATUS_CAPTURED
442
+ elsif auth then self.financial_status = Order::FINANCIAL_STATUS_AUTHORIZED
443
+ else self.financial_status = Order::FINANCIAL_STATUS_PENDING
444
+ end
445
+
446
+ self.status = Order::STATUS_PENDING if self.status == Order::STATUS_CART && (refund || void || capture || auth)
447
+
448
+ self.save
449
+
450
+ end
451
+
425
452
  end
426
453
  end
427
454
 
@@ -25,6 +25,16 @@ module Caboose
25
25
  self.amount = 0.00 if self.amount.nil?
26
26
  end
27
27
 
28
+ def self.type_from_authnet_status(status)
29
+ case status
30
+ when 'settledSuccessfully' then OrderTransaction::TYPE_CAPTURE
31
+ when 'voided' then OrderTransaction::TYPE_VOID
32
+ when 'declined' then OrderTransaction::TYPE_AUTHORIZE
33
+ when 'authorizedPendingCapture' then OrderTransaction::TYPE_AUTHORIZE
34
+ when 'refundSettledSuccessfully' then OrderTransaction::TYPE_REFUND
35
+ end
36
+ end
37
+
28
38
  end
29
39
  end
30
40
 
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.7.32'
2
+ VERSION = '0.7.33'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.32
4
+ version: 0.7.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-15 00:00:00.000000000 Z
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg