effective_orders 5.1.3 → 5.1.7
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642b6831172be548e28cec2adf8c2f13f75ec9ef9af0e1cb15ee48cb763e3edc
|
4
|
+
data.tar.gz: ce4111bbaf7d8fb7a50e16c7ff8a0a43ae412586d2c7063a9c6e910d1337fbc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7e2f6adabe417e43819f95c46e12dcc2c36680c82bedc870041a7665a700428428888927eb35b1dca18ab89d3d695b03183edc3cb35be3e1406f3befa0eee80
|
7
|
+
data.tar.gz: 5650b3ed6960e16d3c630be6697ab9fe69084122a543f2cbbfec875a6defa3fefeb0bb19655affcaadbb4b15e074d5191579aead15107a91f447b401ae31f2aa
|
@@ -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 &&
|
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,6 +69,7 @@ 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
75
|
self.state = EffectiveOrders::CONFIRMED if pending?
|
@@ -156,30 +157,34 @@ module Effective
|
|
156
157
|
def initialize(atts = nil, &block)
|
157
158
|
super(state: EffectiveOrders::PENDING) # Initialize with state: PENDING
|
158
159
|
|
159
|
-
return unless atts.present?
|
160
|
+
return self unless atts.present?
|
160
161
|
|
161
162
|
if atts.kind_of?(Hash)
|
162
|
-
items = Array(atts
|
163
|
+
items = Array(atts[:item]) + Array(atts[:items])
|
163
164
|
|
164
|
-
self.user = atts
|
165
|
+
self.user = atts[:user] || (items.first.user if items.first.respond_to?(:user))
|
165
166
|
|
166
|
-
if (address = atts
|
167
|
+
if (address = atts[:billing_address]).present?
|
167
168
|
self.billing_address = address
|
168
169
|
self.billing_address.full_name ||= user.to_s.presence
|
169
170
|
end
|
170
171
|
|
171
|
-
if (address = atts
|
172
|
+
if (address = atts[:shipping_address]).present?
|
172
173
|
self.shipping_address = address
|
173
174
|
self.shipping_address.full_name ||= user.to_s.presence
|
174
175
|
end
|
175
176
|
|
176
|
-
atts.
|
177
|
+
atts.except(:item, :items, :user, :billing_address, :shipping_address).each do |key, value|
|
178
|
+
self.send("#{key}=", value)
|
179
|
+
end
|
177
180
|
|
178
181
|
add(items) if items.present?
|
179
182
|
else # Attributes are not a Hash
|
180
183
|
self.user = atts.user if atts.respond_to?(:user)
|
181
184
|
add(atts)
|
182
185
|
end
|
186
|
+
|
187
|
+
self
|
183
188
|
end
|
184
189
|
|
185
190
|
# Items can be an Effective::Cart, an Effective::order, a single acts_as_purchasable, or multiple acts_as_purchasables
|
@@ -198,9 +203,21 @@ module Effective
|
|
198
203
|
# Duplicate an existing order
|
199
204
|
self.note_to_buyer ||= item.note_to_buyer
|
200
205
|
self.note_internal ||= item.note_internal
|
206
|
+
self.cc ||= item.cc
|
201
207
|
|
202
208
|
item.order_items.select { |oi| oi.purchasable.kind_of?(Effective::Product) }.map do |oi|
|
203
|
-
|
209
|
+
purchasable = oi.purchasable
|
210
|
+
|
211
|
+
product = Effective::Product.new(name: purchasable.purchasable_name, price: purchasable.price, tax_exempt: purchasable.tax_exempt)
|
212
|
+
|
213
|
+
# Copy over any extended attributes that may have been created
|
214
|
+
atts = purchasable.dup.attributes.except('name', 'price', 'tax_exempt', 'purchased_order_id').compact
|
215
|
+
|
216
|
+
atts.each do |k, v|
|
217
|
+
next unless product.respond_to?("#{k}=") && product.respond_to?(k)
|
218
|
+
product.send("#{k}=", v) if product.send(k).blank?
|
219
|
+
end
|
220
|
+
|
204
221
|
Effective::CartItem.new(quantity: oi.quantity, purchasable: product)
|
205
222
|
end
|
206
223
|
else
|
@@ -278,6 +295,10 @@ module Effective
|
|
278
295
|
[card, '-', last4].compact.join(' ')
|
279
296
|
end
|
280
297
|
|
298
|
+
def duplicate
|
299
|
+
Effective::Order.new(self)
|
300
|
+
end
|
301
|
+
|
281
302
|
# For moneris and moneris_checkout. Just a unique value.
|
282
303
|
def transaction_id
|
283
304
|
[to_param, billing_name.to_s.parameterize.presence, Time.zone.now.to_i].compact.join('-')
|
@@ -345,6 +366,14 @@ module Effective
|
|
345
366
|
order_items.map { |oi| oi.quantity }.sum
|
346
367
|
end
|
347
368
|
|
369
|
+
def send_order_receipt_to_admin?
|
370
|
+
EffectiveOrders.mailer[:send_order_receipt_to_admin] && !free?
|
371
|
+
end
|
372
|
+
|
373
|
+
def send_order_receipt_to_buyer?
|
374
|
+
EffectiveOrders.mailer[:send_order_receipt_to_buyer] && !free?
|
375
|
+
end
|
376
|
+
|
348
377
|
def send_payment_request_to_buyer?
|
349
378
|
EffectiveResources.truthy?(send_payment_request_to_buyer) && !free? && !refund?
|
350
379
|
end
|
@@ -425,11 +454,7 @@ module Effective
|
|
425
454
|
def defer!(provider: 'none', email: true)
|
426
455
|
return false if purchased?
|
427
456
|
|
428
|
-
assign_attributes(
|
429
|
-
state: EffectiveOrders::DEFERRED,
|
430
|
-
payment_provider: provider
|
431
|
-
)
|
432
|
-
|
457
|
+
assign_attributes(state: EffectiveOrders::DEFERRED, payment_provider: provider)
|
433
458
|
save!
|
434
459
|
|
435
460
|
send_payment_request_to_buyer! if email
|
@@ -477,8 +502,8 @@ module Effective
|
|
477
502
|
end
|
478
503
|
|
479
504
|
def send_order_receipts!
|
480
|
-
send_order_receipt_to_admin! if
|
481
|
-
send_order_receipt_to_buyer! if
|
505
|
+
send_order_receipt_to_admin! if send_order_receipt_to_admin?
|
506
|
+
send_order_receipt_to_buyer! if send_order_receipt_to_buyer?
|
482
507
|
send_refund_notification! if refund?
|
483
508
|
end
|
484
509
|
|
@@ -562,6 +587,23 @@ module Effective
|
|
562
587
|
end
|
563
588
|
end
|
564
589
|
|
590
|
+
def assign_user_address
|
591
|
+
return unless user.present?
|
592
|
+
return unless (EffectiveOrders.billing_address || EffectiveOrders.shipping_address)
|
593
|
+
return if EffectiveOrders.billing_address && billing_address.present?
|
594
|
+
return if EffectiveOrders.shipping_address && shipping_address.present?
|
595
|
+
|
596
|
+
if billing_address.blank? && user.respond_to?(:billing_address) && user.billing_address.present?
|
597
|
+
self.billing_address = user.billing_address
|
598
|
+
self.billing_address.full_name ||= user.to_s.presence
|
599
|
+
end
|
600
|
+
|
601
|
+
if shipping_address.blank? && user.respond_to?(:shipping_address) && user.shipping_address.present?
|
602
|
+
self.shipping_address = user.shipping_address
|
603
|
+
self.shipping_address.full_name ||= user.to_s.presence
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
565
607
|
def update_purchasables_purchased_order!
|
566
608
|
order_items.each { |oi| oi.purchasable&.update_column(:purchased_order_id, self.id) }
|
567
609
|
end
|
@@ -24,19 +24,21 @@ module Effective
|
|
24
24
|
@order = order
|
25
25
|
@country_code = country_code
|
26
26
|
@state_code = state_code
|
27
|
-
|
28
|
-
raise 'expected an order, or a country and state code' unless (order || country_code)
|
29
|
-
raise 'expected an order OR a country and state code. Not both.' if (order && country_code)
|
30
27
|
end
|
31
28
|
|
32
29
|
def tax_rate
|
33
30
|
country = country_code
|
34
|
-
country ||= order.billing_address.country_code if order.billing_address.present?
|
35
|
-
country ||= order.user.billing_address.country_code if order.user.respond_to?(:billing_address) && order.user.billing_address.present?
|
36
|
-
|
37
31
|
state = state_code
|
38
|
-
|
39
|
-
|
32
|
+
|
33
|
+
if order.present? && order.billing_address.present?
|
34
|
+
country ||= order.billing_address.country_code
|
35
|
+
state ||= order.billing_address.state_code
|
36
|
+
end
|
37
|
+
|
38
|
+
if order.present? && order.user.respond_to?(:billing_address) && order.user.billing_address.present?
|
39
|
+
country ||= order.user.billing_address.country_code
|
40
|
+
state ||= order.user.billing_address.state_code
|
41
|
+
end
|
40
42
|
|
41
43
|
rate = RATES[country]
|
42
44
|
return rate if rate.kind_of?(Numeric)
|
data/lib/effective_orders.rb
CHANGED
@@ -107,7 +107,7 @@ module EffectiveOrders
|
|
107
107
|
|
108
108
|
# The Effective::Order.payment_provider value must be in this collection
|
109
109
|
def self.payment_providers
|
110
|
-
[
|
110
|
+
@payment_providers ||= [
|
111
111
|
('cheque' if cheque?),
|
112
112
|
('credit card' if mark_as_paid?),
|
113
113
|
('free' if free?),
|
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.
|
4
|
+
version: 5.1.7
|
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-
|
11
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|