effective_orders 5.1.4 → 5.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/effective/concerns/purchase.rb +1 -1
- data/app/models/effective/order.rb +56 -14
- data/app/models/effective/tax_rate_calculator.rb +10 -8
- data/app/views/effective/orders/_order_notes.html.haml +2 -2
- data/app/views/effective/orders/mark_as_paid/_form.html.haml +4 -2
- 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: a32c61a739e40a41c7af3d4de0f254f8f1bf0aa673de5c98d82b404f700f1616
|
4
|
+
data.tar.gz: 53f2b2f8e550b45e16fc1b844f6a8ebc30336d3ee10e3ac493a3cd4de07d9b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc2ee60878dc3c1cb2f2f81d86462f5aae9cca2297c1e2859ef90af51ebe9f511d3db580cfd0eddbb5d788f97ff84d2f467e7b65e5dc988d03b060148f3b09a5
|
7
|
+
data.tar.gz: caf788b76fb2affe7ee4d5229d95c9fb62a2da798b1a7a3d981b38f9b8ba8d66f415fdefe8b3560220f3ce8441507a0273897785054e2721dbaa17bead649577
|
@@ -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)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
.card
|
2
2
|
.card-body
|
3
|
-
%h2
|
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
8
|
= f.date_field :purchased_at, required: true
|
@@ -21,4 +23,4 @@
|
|
21
23
|
|
22
24
|
= f.text_area :note_to_buyer, hint: 'This message will be displayed on the receipt.'
|
23
25
|
|
24
|
-
= f.submit order_checkout_label(:mark_as_paid), center: true
|
26
|
+
= f.submit order_checkout_label(order.refund? ? :refund : :mark_as_paid), center: 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.1.
|
4
|
+
version: 5.1.8
|
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
|