effective_orders 5.1.2 → 5.1.6
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: '063584ca12ed4cb46363a9c7c99f729889bf536eb0a1afb6021e04f07349532b'
|
4
|
+
data.tar.gz: 313908b8ff6797d96c7139a3598b6790a3fda9fb358e69a240e0ccb5afcd8569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a032b3e32b4387801d3630e58df4ee9b91f890a0d87e42c1c4eacb5cb49875e7494316089c01d9d9bdf8a10e246d09caa8d4d2bb400897221661957fc63034
|
7
|
+
data.tar.gz: 7149e03e2c5f5f830a53f235eafd6c712213d5dd6eb4958554d752e7f8e51d124188cebe432284a8ddde462e2fd5ff7ec21999a00465220fbc9d4cb5f5a84a08
|
@@ -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
|
@@ -225,7 +230,6 @@ module Effective
|
|
225
230
|
retval.size == 1 ? retval.first : retval
|
226
231
|
end
|
227
232
|
|
228
|
-
|
229
233
|
def update_prices!
|
230
234
|
raise('already purchased') if purchased?
|
231
235
|
raise('must be pending or confirmed') unless pending? || confirmed?
|
@@ -346,6 +350,14 @@ module Effective
|
|
346
350
|
order_items.map { |oi| oi.quantity }.sum
|
347
351
|
end
|
348
352
|
|
353
|
+
def send_order_receipt_to_admin?
|
354
|
+
EffectiveOrders.mailer[:send_order_receipt_to_admin] && !free?
|
355
|
+
end
|
356
|
+
|
357
|
+
def send_order_receipt_to_buyer?
|
358
|
+
EffectiveOrders.mailer[:send_order_receipt_to_buyer] && !free?
|
359
|
+
end
|
360
|
+
|
349
361
|
def send_payment_request_to_buyer?
|
350
362
|
EffectiveResources.truthy?(send_payment_request_to_buyer) && !free? && !refund?
|
351
363
|
end
|
@@ -426,11 +438,7 @@ module Effective
|
|
426
438
|
def defer!(provider: 'none', email: true)
|
427
439
|
return false if purchased?
|
428
440
|
|
429
|
-
assign_attributes(
|
430
|
-
state: EffectiveOrders::DEFERRED,
|
431
|
-
payment_provider: provider
|
432
|
-
)
|
433
|
-
|
441
|
+
assign_attributes(state: EffectiveOrders::DEFERRED, payment_provider: provider)
|
434
442
|
save!
|
435
443
|
|
436
444
|
send_payment_request_to_buyer! if email
|
@@ -478,8 +486,8 @@ module Effective
|
|
478
486
|
end
|
479
487
|
|
480
488
|
def send_order_receipts!
|
481
|
-
send_order_receipt_to_admin! if
|
482
|
-
send_order_receipt_to_buyer! if
|
489
|
+
send_order_receipt_to_admin! if send_order_receipt_to_admin?
|
490
|
+
send_order_receipt_to_buyer! if send_order_receipt_to_buyer?
|
483
491
|
send_refund_notification! if refund?
|
484
492
|
end
|
485
493
|
|
@@ -563,6 +571,23 @@ module Effective
|
|
563
571
|
end
|
564
572
|
end
|
565
573
|
|
574
|
+
def assign_user_address
|
575
|
+
return unless user.present?
|
576
|
+
return unless (EffectiveOrders.billing_address || EffectiveOrders.shipping_address)
|
577
|
+
return if EffectiveOrders.billing_address && billing_address.present?
|
578
|
+
return if EffectiveOrders.shipping_address && shipping_address.present?
|
579
|
+
|
580
|
+
if billing_address.blank? && user.respond_to?(:billing_address) && user.billing_address.present?
|
581
|
+
self.billing_address = user.billing_address
|
582
|
+
self.billing_address.full_name ||= user.to_s.presence
|
583
|
+
end
|
584
|
+
|
585
|
+
if shipping_address.blank? && user.respond_to?(:shipping_address) && user.shipping_address.present?
|
586
|
+
self.shipping_address = user.shipping_address
|
587
|
+
self.shipping_address.full_name ||= user.to_s.presence
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
566
591
|
def update_purchasables_purchased_order!
|
567
592
|
order_items.each { |oi| oi.purchasable&.update_column(:purchased_order_id, self.id) }
|
568
593
|
end
|
@@ -24,14 +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
|
-
country = country_code
|
34
|
-
state = state_code
|
30
|
+
country = country_code
|
31
|
+
state = state_code
|
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
|
35
42
|
|
36
43
|
rate = RATES[country]
|
37
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.6
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|