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 +4 -4
- data/app/helpers/effective_moneris_checkout_helper.rb +13 -7
- data/app/models/effective/order.rb +43 -10
- data/lib/effective_orders/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ee6f41ea9ce0cfac7925305431dbbe362e436288d427744245fc6dbc915c554
|
4
|
+
data.tar.gz: 35cbbbe657adcb8c2d7c823600f9b8c01f9e7a8de4a54a2eec4279413db035e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
386
|
+
present_order_items.map { |order_item| order_item.purchasable }
|
362
387
|
end
|
363
388
|
|
364
389
|
def subtotal
|
365
|
-
self[:subtotal] ||
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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()
|
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
|
-
|
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
|
-
|
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
|
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.
|
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:
|
11
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|