effective_orders 5.2.9 → 5.2.13

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: bc66dfb86e929b29d30edefe87326d4caeae9250f1db593e4c1955eb6fd39c32
4
- data.tar.gz: 95239c7500bce2fd5d6a48cc9e1c1fe6667ea0af12f3e028820ffa3c52c0843e
3
+ metadata.gz: 3ee6f41ea9ce0cfac7925305431dbbe362e436288d427744245fc6dbc915c554
4
+ data.tar.gz: 35cbbbe657adcb8c2d7c823600f9b8c01f9e7a8de4a54a2eec4279413db035e7
5
5
  SHA512:
6
- metadata.gz: a00bb7a4142c5b326412a69d1cfa1c112825933efdd565eecfc422fdb55fc54f06b56e8cde8335705b701dc43403ba4086ababa4c5c6cbeb609cc30eb1e0599e
7
- data.tar.gz: 2ce6a0d26f8e9a0c3be3b5540ff25e68eb65408c126d38e9d35c89bb79109499e9b125e5ca5e9842b537a1eab4e13c16becc6b71cbfa75fb2b8a233a8e7b0c3e
6
+ metadata.gz: bf9913f68f1018d10eaf8a3602c410bf0d6e5a733e211bbc0e9b16066458c7bf305e522350ec02083a1cead2dcc228846b894f14c699fcaa0af5d8f62077946d
7
+ data.tar.gz: 5e1b5b09d51db9180f14ef8665e1dae2b34ad7f20d8f9031d96a8f1c75405ddcb6e9a2bd12f3a735fd894e55c53c7ef0698ddf375ddadf6c8edd061493bb0826
@@ -1,4 +1,5 @@
1
1
  module EffectiveMonerisCheckoutHelper
2
+ SCRUB = /[^\w\d#,\s]/
2
3
 
3
4
  def moneris_checkout_preload_request(order)
4
5
  # Make the Preload Request
@@ -19,8 +20,8 @@ module EffectiveMonerisCheckoutHelper
19
20
  language: 'en',
20
21
 
21
22
  contact_details: {
22
- first_name: order.billing_first_name,
23
- last_name: order.billing_last_name,
23
+ first_name: moneris_checkout_scrub(order.billing_first_name),
24
+ last_name: moneris_checkout_scrub(order.billing_last_name),
24
25
  email: order.email,
25
26
  }
26
27
  }
@@ -28,9 +29,9 @@ module EffectiveMonerisCheckoutHelper
28
29
  if (address = order.billing_address).present?
29
30
  params.merge!(
30
31
  billing_details: {
31
- address_1: address.address1,
32
- address_2: address.address2,
33
- city: address.city,
32
+ address_1: moneris_checkout_scrub(address.address1),
33
+ address_2: moneris_checkout_scrub(address.address2),
34
+ city: moneris_checkout_scrub(address.city),
34
35
  province: address.state_code,
35
36
  country: address.country_code,
36
37
  postal_code: address.postal_code
@@ -41,8 +42,8 @@ module EffectiveMonerisCheckoutHelper
41
42
  if (address = order.shipping_address).present?
42
43
  params.merge!(
43
44
  shipping_details: {
44
- address_1: address.address1,
45
- address_2: address.address2,
45
+ address_1: moneris_checkout_scrub(address.address1),
46
+ address_2: moneris_checkout_scrub(address.address2),
46
47
  city: address.city,
47
48
  province: address.state_code,
48
49
  country: address.country_code,
@@ -62,4 +63,9 @@ module EffectiveMonerisCheckoutHelper
62
63
  }
63
64
  end
64
65
 
66
+ def moneris_checkout_scrub(value)
67
+ return value unless value.kind_of?(String)
68
+ value.gsub(SCRUB, '')
69
+ end
70
+
65
71
  end
@@ -190,6 +190,31 @@ module Effective
190
190
  self
191
191
  end
192
192
 
193
+ def remove(*items)
194
+ raise 'unable to alter a purchased order' if purchased?
195
+ raise 'unable to alter a declined order' if declined?
196
+
197
+ removed = items.map do |item|
198
+ order_item = if item.kind_of?(Effective::OrderItem)
199
+ order_items.find { |oi| oi == item }
200
+ else
201
+ order_items.find { |oi| oi.purchasable == item }
202
+ end
203
+
204
+ raise("Unable to find order item for #{item}") if order_item.blank?
205
+ order_item
206
+ end
207
+
208
+ removed.each { |order_item| order_item.mark_for_destruction }
209
+
210
+ # Make sure to reset stored aggregates
211
+ self.total = nil
212
+ self.subtotal = nil
213
+ self.tax = nil
214
+
215
+ removed.length == 1 ? removed.first : removed
216
+ end
217
+
193
218
  # Items can be an Effective::Cart, an Effective::order, a single acts_as_purchasable, or multiple acts_as_purchasables
194
219
  # add(Product.first) => returns an Effective::OrderItem
195
220
  # add(Product.first, current_cart) => returns an array of Effective::OrderItems
@@ -249,7 +274,7 @@ module Effective
249
274
  raise('already purchased') if purchased?
250
275
  raise('must be pending or confirmed') unless pending? || confirmed?
251
276
 
252
- order_items.each do |item|
277
+ present_order_items.each do |item|
253
278
  purchasable = item.purchasable
254
279
 
255
280
  if purchasable.blank? || purchasable.marked_for_destruction?
@@ -358,11 +383,11 @@ module Effective
358
383
  end
359
384
 
360
385
  def purchasables
361
- order_items.map { |order_item| order_item.purchasable }
386
+ present_order_items.map { |order_item| order_item.purchasable }
362
387
  end
363
388
 
364
389
  def subtotal
365
- self[:subtotal] || order_items.map { |oi| oi.subtotal }.sum
390
+ self[:subtotal] || present_order_items.map { |oi| oi.subtotal }.sum
366
391
  end
367
392
 
368
393
  def tax_rate
@@ -386,7 +411,7 @@ module Effective
386
411
  end
387
412
 
388
413
  def num_items
389
- order_items.map { |oi| oi.quantity }.sum
414
+ present_order_items.map { |oi| oi.quantity }.sum
390
415
  end
391
416
 
392
417
  def send_order_receipt_to_admin?
@@ -459,7 +484,7 @@ module Effective
459
484
  self.payment = payment_to_h(payment) if self.payment.blank?
460
485
 
461
486
  begin
462
- EffectiveResources.transaction do
487
+ Effective::Order.transaction do
463
488
  run_purchasable_callbacks(:before_purchase)
464
489
 
465
490
  save!
@@ -468,7 +493,7 @@ module Effective
468
493
  run_purchasable_callbacks(:after_purchase)
469
494
  end
470
495
  rescue => e
471
- EffectiveResources.transaction do
496
+ Effective::Order.transaction do
472
497
  save!(validate: false)
473
498
  update_purchasables_purchased_order!
474
499
  end
@@ -508,7 +533,7 @@ module Effective
508
533
  skip_buyer_validations: true
509
534
  )
510
535
 
511
- EffectiveResources.transaction do
536
+ Effective::Order.transaction do
512
537
  begin
513
538
  run_purchasable_callbacks(:before_decline)
514
539
  save!(validate: validate)
@@ -586,7 +611,7 @@ module Effective
586
611
 
587
612
  def assign_order_totals
588
613
  self.subtotal = present_order_items.map { |oi| oi.subtotal }.sum
589
- self.tax_rate = get_tax_rate() unless (tax_rate || 0) > 0
614
+ self.tax_rate = get_tax_rate()
590
615
  self.tax = get_tax()
591
616
  self.total = subtotal + (tax || 0)
592
617
  end
@@ -640,11 +665,19 @@ module Effective
640
665
 
641
666
  def run_purchasable_callbacks(name)
642
667
  order_items.select { |item| item.purchasable.respond_to?(name) }.each do |item|
643
- EffectiveResources.transaction(item) { item.purchasable.public_send(name, self, item) }
668
+ if item.class.respond_to?(:transaction)
669
+ item.class.transaction { item.purchasable.public_send(name, self, item) }
670
+ else
671
+ item.purchasable.public_send(name, self, item)
672
+ end
644
673
  end
645
674
 
646
675
  if parent.respond_to?(name)
647
- EffectiveResources.transaction(parent) { parent.public_send(name, self) }
676
+ if parent.class.respond_to?(:transaction)
677
+ parent.class.transaction { parent.public_send(name, self) }
678
+ else
679
+ parent.public_send(name, self)
680
+ end
648
681
  end
649
682
 
650
683
  true
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.2.9'.freeze
2
+ VERSION = '5.2.13'.freeze
3
3
  end
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.2.9
4
+ version: 5.2.13
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-12-22 00:00:00.000000000 Z
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails