effective_orders 5.1.5 → 5.1.9

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: 70fd6793f180e1b0106c700cef6aacc0363cf7b2e3c76389e53db1301e6bac4e
4
- data.tar.gz: 9fca2375abb56fd3052d2c098324f0dd6eb3d675772700f8ee792a12e54b39a6
3
+ metadata.gz: aebed7dcf8c4b8c6e754b4425d407020ab7e3078baa82e0e5ddb10d748041d74
4
+ data.tar.gz: a834e0574e803ad7af2e568395814a3fc7e2b129953dcc37e52bea17bae1a963
5
5
  SHA512:
6
- metadata.gz: 5c33291651b6c2e6789040feca6573827a2f61f64b1b6553692ebfc4b45382949f0814b5257bfa7fc3d65d461b8a36bf01051565acf06474638a9f9771268d4b
7
- data.tar.gz: 51155ef9663bc5912b70c7c9be2232a55aa4d7565eeaf19eca83eea7f216b1d809d998259f347a2fc643755215792c323e3b7e8eb4ffd6c5b2f733899f407604
6
+ metadata.gz: b4162e7ec6328b52f4dc36b3a79199966980948cc8dbb9612a460105e4f9682c70586424be157baf897b07f501bff158499e80f3c77ea7f229b3351fa9bc9d61
7
+ data.tar.gz: 27eff0b3035f2dbaf1e426aa7337a933b8f90ef44e88da04eac4fab0ba77f3d7d8ea3695b6bd3cf6e7d42f933f5186868076e45fb25c66717b1d8e423401883d
@@ -11,7 +11,7 @@ module Effective
11
11
  Effective::Cart.where(user: @order.user).destroy_all
12
12
 
13
13
  if flash[:success].blank?
14
- if email && EffectiveOrders.mailer[:send_order_receipt_to_buyer]
14
+ if email && @order.send_order_receipt_to_buyer?
15
15
  flash[:success] = "Payment successful! A receipt has been sent to #{@order.emails_send_to}"
16
16
  else
17
17
  flash[:success] = "Payment successful! An email receipt has not been sent."
@@ -69,9 +69,10 @@ module Effective
69
69
  before_validation { assign_billing_name }
70
70
  before_validation { assign_email }
71
71
  before_validation { assign_last_address }
72
+ before_validation { assign_user_address }
72
73
 
73
74
  before_validation(if: -> { confirmed_checkout }) do
74
- self.state = EffectiveOrders::CONFIRMED if pending?
75
+ assign_attributes(state: EffectiveOrders::CONFIRMED) if pending?
75
76
  end
76
77
 
77
78
  before_save(if: -> { state_was == EffectiveOrders::PURCHASED }) do
@@ -142,6 +143,7 @@ module Effective
142
143
  scope :confirmed, -> { where(state: EffectiveOrders::CONFIRMED) }
143
144
  scope :deferred, -> { where(state: EffectiveOrders::DEFERRED) }
144
145
  scope :declined, -> { where(state: EffectiveOrders::DECLINED) }
146
+ scope :abandoned, -> { where(state: EffectiveOrders::ABANDONED) }
145
147
  scope :refunds, -> { purchased.where('total < ?', 0) }
146
148
 
147
149
  # Effective::Order.new()
@@ -156,30 +158,34 @@ module Effective
156
158
  def initialize(atts = nil, &block)
157
159
  super(state: EffectiveOrders::PENDING) # Initialize with state: PENDING
158
160
 
159
- return unless atts.present?
161
+ return self unless atts.present?
160
162
 
161
163
  if atts.kind_of?(Hash)
162
- items = Array(atts.delete(:item)) + Array(atts.delete(:items))
164
+ items = Array(atts[:item]) + Array(atts[:items])
163
165
 
164
- self.user = atts.delete(:user) || (items.first.user if items.first.respond_to?(:user))
166
+ self.user = atts[:user] || (items.first.user if items.first.respond_to?(:user))
165
167
 
166
- if (address = atts.delete(:billing_address)).present?
168
+ if (address = atts[:billing_address]).present?
167
169
  self.billing_address = address
168
170
  self.billing_address.full_name ||= user.to_s.presence
169
171
  end
170
172
 
171
- if (address = atts.delete(:shipping_address)).present?
173
+ if (address = atts[:shipping_address]).present?
172
174
  self.shipping_address = address
173
175
  self.shipping_address.full_name ||= user.to_s.presence
174
176
  end
175
177
 
176
- atts.each { |key, value| self.send("#{key}=", value) }
178
+ atts.except(:item, :items, :user, :billing_address, :shipping_address).each do |key, value|
179
+ self.send("#{key}=", value)
180
+ end
177
181
 
178
182
  add(items) if items.present?
179
183
  else # Attributes are not a Hash
180
184
  self.user = atts.user if atts.respond_to?(:user)
181
185
  add(atts)
182
186
  end
187
+
188
+ self
183
189
  end
184
190
 
185
191
  # Items can be an Effective::Cart, an Effective::order, a single acts_as_purchasable, or multiple acts_as_purchasables
@@ -198,9 +204,21 @@ module Effective
198
204
  # Duplicate an existing order
199
205
  self.note_to_buyer ||= item.note_to_buyer
200
206
  self.note_internal ||= item.note_internal
207
+ self.cc ||= item.cc
201
208
 
202
209
  item.order_items.select { |oi| oi.purchasable.kind_of?(Effective::Product) }.map do |oi|
203
- product = Effective::Product.new(name: oi.purchasable.purchasable_name, price: oi.purchasable.price, tax_exempt: oi.purchasable.tax_exempt)
210
+ purchasable = oi.purchasable
211
+
212
+ product = Effective::Product.new(name: purchasable.purchasable_name, price: purchasable.price, tax_exempt: purchasable.tax_exempt)
213
+
214
+ # Copy over any extended attributes that may have been created
215
+ atts = purchasable.dup.attributes.except('name', 'price', 'tax_exempt', 'purchased_order_id').compact
216
+
217
+ atts.each do |k, v|
218
+ next unless product.respond_to?("#{k}=") && product.respond_to?(k)
219
+ product.send("#{k}=", v) if product.send(k).blank?
220
+ end
221
+
204
222
  Effective::CartItem.new(quantity: oi.quantity, purchasable: product)
205
223
  end
206
224
  else
@@ -278,6 +296,10 @@ module Effective
278
296
  [card, '-', last4].compact.join(' ')
279
297
  end
280
298
 
299
+ def duplicate
300
+ Effective::Order.new(self)
301
+ end
302
+
281
303
  # For moneris and moneris_checkout. Just a unique value.
282
304
  def transaction_id
283
305
  [to_param, billing_name.to_s.parameterize.presence, Time.zone.now.to_i].compact.join('-')
@@ -313,6 +335,10 @@ module Effective
313
335
  state == EffectiveOrders::DECLINED
314
336
  end
315
337
 
338
+ def abandoned?
339
+ state == EffectiveOrders::ABANDONED
340
+ end
341
+
316
342
  def purchasables
317
343
  order_items.map { |order_item| order_item.purchasable }
318
344
  end
@@ -345,6 +371,14 @@ module Effective
345
371
  order_items.map { |oi| oi.quantity }.sum
346
372
  end
347
373
 
374
+ def send_order_receipt_to_admin?
375
+ EffectiveOrders.mailer[:send_order_receipt_to_admin] && !free?
376
+ end
377
+
378
+ def send_order_receipt_to_buyer?
379
+ EffectiveOrders.mailer[:send_order_receipt_to_buyer] && !free?
380
+ end
381
+
348
382
  def send_payment_request_to_buyer?
349
383
  EffectiveResources.truthy?(send_payment_request_to_buyer) && !free? && !refund?
350
384
  end
@@ -425,11 +459,7 @@ module Effective
425
459
  def defer!(provider: 'none', email: true)
426
460
  return false if purchased?
427
461
 
428
- assign_attributes(
429
- state: EffectiveOrders::DEFERRED,
430
- payment_provider: provider
431
- )
432
-
462
+ assign_attributes(state: EffectiveOrders::DEFERRED, payment_provider: provider)
433
463
  save!
434
464
 
435
465
  send_payment_request_to_buyer! if email
@@ -477,8 +507,8 @@ module Effective
477
507
  end
478
508
 
479
509
  def send_order_receipts!
480
- send_order_receipt_to_admin! if EffectiveOrders.mailer[:send_order_receipt_to_admin]
481
- send_order_receipt_to_buyer! if EffectiveOrders.mailer[:send_order_receipt_to_buyer]
510
+ send_order_receipt_to_admin! if send_order_receipt_to_admin?
511
+ send_order_receipt_to_buyer! if send_order_receipt_to_buyer?
482
512
  send_refund_notification! if refund?
483
513
  end
484
514
 
@@ -562,6 +592,23 @@ module Effective
562
592
  end
563
593
  end
564
594
 
595
+ def assign_user_address
596
+ return unless user.present?
597
+ return unless (EffectiveOrders.billing_address || EffectiveOrders.shipping_address)
598
+ return if EffectiveOrders.billing_address && billing_address.present?
599
+ return if EffectiveOrders.shipping_address && shipping_address.present?
600
+
601
+ if billing_address.blank? && user.respond_to?(:billing_address) && user.billing_address.present?
602
+ self.billing_address = user.billing_address
603
+ self.billing_address.full_name ||= user.to_s.presence
604
+ end
605
+
606
+ if shipping_address.blank? && user.respond_to?(:shipping_address) && user.shipping_address.present?
607
+ self.shipping_address = user.shipping_address
608
+ self.shipping_address.full_name ||= user.to_s.presence
609
+ end
610
+ end
611
+
565
612
  def update_purchasables_purchased_order!
566
613
  order_items.each { |oi| oi.purchasable&.update_column(:purchased_order_id, self.id) }
567
614
  end
@@ -11,7 +11,7 @@
11
11
  %tbody
12
12
  %tr
13
13
  - if order.note.present?
14
- %td= order.note
14
+ %td= simple_format(order.note)
15
15
 
16
16
  - if order.note_to_buyer.present?
17
- %td= order.note_to_buyer
17
+ %td= simple_format(order.note_to_buyer)
@@ -1,9 +1,14 @@
1
1
  .card
2
2
  .card-body
3
- %h2 Admin: Mark as Paid
3
+ %h2
4
+ Admin:
5
+ = order.refund? ? 'Complete Refund' : 'Mark as Paid'
4
6
 
5
7
  = effective_form_with(model: order, url: effective_orders.mark_as_paid_order_path(order), method: :post) do |f|
6
- = f.date_field :purchased_at, required: true
8
+ - if order.refund?
9
+ = f.hidden_field :purchased_at, value: Time.zone.now
10
+ - else
11
+ = f.date_field :purchased_at, required: true
7
12
 
8
13
  = f.select :payment_provider, EffectiveOrders.payment_providers, required: true
9
14
 
@@ -21,4 +26,4 @@
21
26
 
22
27
  = f.text_area :note_to_buyer, hint: 'This message will be displayed on the receipt.'
23
28
 
24
- = f.submit order_checkout_label(:mark_as_paid), center: true
29
+ = f.submit 'Admin: ' + order_checkout_label(order.refund? ? :refund : :mark_as_paid)
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.1.5'.freeze
2
+ VERSION = '5.1.9'.freeze
3
3
  end
@@ -10,7 +10,16 @@ module EffectiveOrders
10
10
  DEFERRED = 'deferred' # Deferred providers. Cheque or Phone was selected.
11
11
  PURCHASED = 'purchased' # Purchased by provider
12
12
  DECLINED = 'declined' # Declined by provider
13
- STATES = { PENDING => PENDING, CONFIRMED => CONFIRMED, DEFERRED => DEFERRED, PURCHASED => PURCHASED, DECLINED => DECLINED }
13
+ ABANDONED = 'abandoned' # Not set by this gem. Can be set outside it.
14
+
15
+ STATES = {
16
+ PENDING => PENDING,
17
+ CONFIRMED => CONFIRMED,
18
+ DEFERRED => DEFERRED,
19
+ PURCHASED => PURCHASED,
20
+ DECLINED => DECLINED,
21
+ ABANDONED => ABANDONED
22
+ }
14
23
 
15
24
  # Subscription statuses (as per stripe)
16
25
  ACTIVE = 'active'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.5
4
+ version: 5.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-31 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails