effective_orders 5.2.8 → 5.2.12

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: 7850176b4c32949c586aa453834799cb0063919a1eb7437e5111f2a280e19fc0
4
- data.tar.gz: e5753a21c4ba634a779bce34c0dafae0d94492db53f51bbb89720f860ea17985
3
+ metadata.gz: e6fc5fddf4893dd467c30bd2ae4f505b1c4f4f191e819601364bc230d8530627
4
+ data.tar.gz: 6a157d58abcf4836b1324b17dbee3fcb502e23e2924d59daa1ef8a957cb91fbb
5
5
  SHA512:
6
- metadata.gz: 6251dfd17f63fce47aa1484d26bfb68afaa24f080819f8f8a00ffc21e280e36396c0d25ee6d0fc400af01120539d39f71aaef91bdb8770d9f28a87dd5198b4d6
7
- data.tar.gz: 65a6ad794d855f8057f5e14051ec1d0b7099e21e54b864238f61b5a020f17f0f1a93042a30c74dcd0b5b581385ac1e466eb075344054958506a9ee2ad7e7605a
6
+ metadata.gz: 9c98604d9238a92c62d41422b31f63001144fa47eaa5dbcf7359cf98ec849e8846d07db9be11e498df0024b66212bb674afcc646ab9f7bf4922c8b446a947ba5
7
+ data.tar.gz: 537d27c651f334bb17a189d4f3085eca6f0b33e9aaa742ea9ae270f5f3f6d00746d56007a10a5abbe2941ecbd083ae42a052bfbeecc627f0a79e31076b2dcb7c
@@ -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?
@@ -318,9 +343,9 @@ module Effective
318
343
  Effective::Order.new(self)
319
344
  end
320
345
 
321
- # For moneris and moneris_checkout. Just a unique value.
346
+ # For moneris and moneris_checkout. Just a unique value. Must be 50 characters or fewer or will raise moneris error.
322
347
  def transaction_id
323
- [to_param, billing_name.to_s.parameterize.presence, Time.zone.now.to_i, rand(10000)].compact.join('-')
348
+ [to_param, billing_name.to_s.parameterize.first(20).presence, Time.zone.now.to_i, rand(1000..9999)].compact.join('-')
324
349
  end
325
350
 
326
351
  def billing_first_name
@@ -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?
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.2.8'.freeze
2
+ VERSION = '5.2.12'.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.8
4
+ version: 5.2.12
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-21 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails