effective_orders 1.6.4 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/app/helpers/effective_orders_helper.rb +1 -1
- data/app/models/effective/customer.rb +26 -3
- data/app/models/effective/order.rb +16 -15
- data/app/views/effective/orders/_order_header.html.haml +2 -1
- data/lib/effective_orders.rb +11 -0
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/templates/effective_orders.rb +3 -1
- data/spec/controllers/carts_controller_spec.rb +3 -3
- data/spec/controllers/moneris_orders_controller_spec.rb +1 -1
- data/spec/controllers/orders_controller_spec.rb +2 -2
- data/spec/controllers/stripe_orders_controller_spec.rb +1 -1
- data/spec/controllers/webhooks_controller_spec.rb +1 -1
- data/spec/dummy/config/initializers/effective_orders.rb +2 -1
- data/spec/helpers/effective_orders_helper_spec.rb +1 -1
- data/spec/models/order_spec.rb +2 -2
- data/spec/models/subscription_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/support/factories.rb +6 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0cabc11a1540a88ee03c9f24f9cb94c92caa2fa
|
4
|
+
data.tar.gz: fc21c6a4e480ed8f26ecdd573bc52bfd0158e50f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13f4e0de53ff90ae3e16d4ec953bcd0906273aeee46f801fcc95c76ce619aeea414e52c6bd91a6ea158284dcb5bb4f7afdb1d7e49a7cde79ff13567f82072c76
|
7
|
+
data.tar.gz: 34783651f411c842092b59469e8001258762e350de2f9c51ecd24a0a9535ab14b7663a52dd177f2c49968c00e1b9dbf7ddc6025b8399ad9e1626f5e49f5482bf
|
data/README.md
CHANGED
@@ -487,6 +487,12 @@ If you are using effective_orders to roll your own custom payment workflow, you
|
|
487
487
|
- `order_summary(order)` to display some quick details of an Order and its OrderItems.
|
488
488
|
- `order_payment_to_html(order)` to display the payment processor details for an order's payment transaction.
|
489
489
|
|
490
|
+
#### Send Order Receipts in the Background
|
491
|
+
|
492
|
+
Emails will be sent immediately unless `config.mailer[:deliver_method] == :deliver_later`.
|
493
|
+
|
494
|
+
If you are using [Delayed::Job](https://github.com/collectiveidea/delayed_job) to send emails in a background process then you should set the `delayed_job_deliver` option so that `config.mailer[:delayed_job_deliver] == true`.
|
495
|
+
|
490
496
|
|
491
497
|
### Effective::Order Model
|
492
498
|
|
@@ -116,7 +116,7 @@ module EffectiveOrdersHelper
|
|
116
116
|
content_tag((options[:th] ? :th : :td), k) +
|
117
117
|
content_tag(:td) do
|
118
118
|
if v.kind_of?(Hash)
|
119
|
-
|
119
|
+
tableize_order_payment(v, options.merge(th: (options.key?(:sub_th) ? options[:sub_th] : options[:th])))
|
120
120
|
elsif v.kind_of?(Array)
|
121
121
|
'[' + v.join(', ') + ']'
|
122
122
|
else
|
@@ -40,10 +40,14 @@ module Effective
|
|
40
40
|
|
41
41
|
def update_card!(token)
|
42
42
|
if token.present? # Oh, so they want to use a new credit card...
|
43
|
-
stripe_customer.
|
43
|
+
if stripe_customer.respond_to?(:cards)
|
44
|
+
stripe_customer.card = token # This sets the default_card to the new card
|
45
|
+
elsif stripe_customer.respond_to?(:sources)
|
46
|
+
stripe_customer.source = token
|
47
|
+
end
|
44
48
|
|
45
|
-
if stripe_customer.save &&
|
46
|
-
card =
|
49
|
+
if stripe_customer.save && default_card.present?
|
50
|
+
card = cards.retrieve(default_card)
|
47
51
|
|
48
52
|
self.stripe_active_card = "**** **** **** #{card.last4} #{card.brand} #{card.exp_month}/#{card.exp_year}"
|
49
53
|
self.save!
|
@@ -57,5 +61,24 @@ module Effective
|
|
57
61
|
stripe_connect_access_token.present?
|
58
62
|
end
|
59
63
|
|
64
|
+
private
|
65
|
+
|
66
|
+
def default_card
|
67
|
+
case
|
68
|
+
when stripe_customer.respond_to?(:default_card)
|
69
|
+
stripe_customer.default_card
|
70
|
+
when stripe_customer.respond_to?(:default_source)
|
71
|
+
stripe_customer.default_source
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def cards
|
76
|
+
case
|
77
|
+
when stripe_customer.respond_to?(:cards)
|
78
|
+
stripe_customer.cards
|
79
|
+
when stripe_customer.respond_to?(:sources)
|
80
|
+
stripe_customer.sources
|
81
|
+
end
|
82
|
+
end
|
60
83
|
end
|
61
84
|
end
|
@@ -305,35 +305,36 @@ module Effective
|
|
305
305
|
|
306
306
|
def send_order_receipt_to_admin!
|
307
307
|
return false unless purchased? && EffectiveOrders.mailer[:send_order_receipt_to_admin]
|
308
|
-
|
309
|
-
if Rails.env.production?
|
310
|
-
(OrdersMailer.order_receipt_to_admin(self).deliver rescue false)
|
311
|
-
else
|
312
|
-
OrdersMailer.order_receipt_to_admin(self).deliver
|
313
|
-
end
|
308
|
+
send_email(:order_receipt_to_admin, self)
|
314
309
|
end
|
315
310
|
|
316
311
|
def send_order_receipt_to_buyer!
|
317
312
|
return false unless purchased? && EffectiveOrders.mailer[:send_order_receipt_to_buyer]
|
318
313
|
|
319
|
-
|
320
|
-
(OrdersMailer.order_receipt_to_buyer(self).deliver rescue false)
|
321
|
-
else
|
322
|
-
OrdersMailer.order_receipt_to_buyer(self).deliver
|
323
|
-
end
|
314
|
+
send_email(:order_receipt_to_buyer, self)
|
324
315
|
end
|
325
316
|
|
326
317
|
def send_order_receipt_to_seller!
|
327
318
|
return false unless purchased?(:stripe_connect) && EffectiveOrders.mailer[:send_order_receipt_to_seller]
|
328
319
|
|
329
320
|
order_items.group_by(&:seller).each do |seller, order_items|
|
330
|
-
|
331
|
-
|
321
|
+
send_email(:order_receipt_to_seller, self, seller, order_items)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
private
|
326
|
+
|
327
|
+
def send_email(email, *mailer_args)
|
328
|
+
begin
|
329
|
+
if EffectiveOrders.mailer[:delayed_job_deliver] && EffectiveOrders.mailer[:deliver_method] == :deliver_later
|
330
|
+
(OrdersMailer.delay.public_send(email, *mailer_args) rescue false)
|
332
331
|
else
|
333
|
-
OrdersMailer.
|
332
|
+
(OrdersMailer.public_send(email, *mailer_args).public_send(EffectiveOrders.mailer[:deliver_method]) rescue false)
|
334
333
|
end
|
334
|
+
rescue => e
|
335
|
+
raise e unless Rails.env.production?
|
336
|
+
return false
|
335
337
|
end
|
336
338
|
end
|
337
|
-
|
338
339
|
end
|
339
340
|
end
|
@@ -2,7 +2,8 @@
|
|
2
2
|
%h3 Acme Industries Inc.
|
3
3
|
.row
|
4
4
|
.col-sm-6
|
5
|
-
|
5
|
+
- email_address = EffectiveOrders.mailer[:admin_email] || 'info@acmeindustries.com'
|
6
|
+
%p= mail_to u(email_address), email_address
|
6
7
|
%p
|
7
8
|
1234 Fake Street
|
8
9
|
%br
|
data/lib/effective_orders.rb
CHANGED
@@ -61,8 +61,19 @@ module EffectiveOrders
|
|
61
61
|
mattr_accessor :moneris
|
62
62
|
mattr_accessor :stripe
|
63
63
|
|
64
|
+
mattr_accessor :deliver_method
|
65
|
+
|
64
66
|
def self.setup
|
65
67
|
yield self
|
68
|
+
|
69
|
+
unless mailer[:deliver_method].present?
|
70
|
+
self.mailer[:deliver_method] = case
|
71
|
+
when Rails.gem_version >= Gem::Version.new('4.2')
|
72
|
+
:deliver_now
|
73
|
+
else
|
74
|
+
:deliver
|
75
|
+
end
|
76
|
+
end
|
66
77
|
end
|
67
78
|
|
68
79
|
def self.authorized?(controller, action, resource)
|
@@ -144,7 +144,9 @@ EffectiveOrders.setup do |config|
|
|
144
144
|
:subject_prefix => '[example]',
|
145
145
|
:subject_for_admin_receipt => '',
|
146
146
|
:subject_for_buyer_receipt => '',
|
147
|
-
:subject_for_seller_receipt => ''
|
147
|
+
:subject_for_seller_receipt => '',
|
148
|
+
:deliver_method => nil,
|
149
|
+
:delayed_job_deliver => false
|
148
150
|
}
|
149
151
|
|
150
152
|
# Moneris configuration
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Effective::CartsController do
|
3
|
+
describe Effective::CartsController, type: :controller do
|
4
4
|
routes { EffectiveOrders::Engine.routes }
|
5
5
|
|
6
6
|
let(:user) { FactoryGirl.create(:user) }
|
@@ -77,7 +77,7 @@ describe Effective::CartsController do
|
|
77
77
|
assigns(:cart).size.should eq 1
|
78
78
|
assigns(:cart).find(product).present?.should eq true
|
79
79
|
|
80
|
-
sign_in user
|
80
|
+
sign_in user
|
81
81
|
controller.instance_variable_set(:@cart, nil) # This is what happens in a real RailsController. zzz.
|
82
82
|
|
83
83
|
get :show
|
@@ -100,7 +100,7 @@ describe Effective::CartsController do
|
|
100
100
|
assigns(:cart).size.should eq 1
|
101
101
|
assigns(:cart).find(product).present?.should eq true
|
102
102
|
|
103
|
-
sign_in cart.user
|
103
|
+
sign_in cart.user
|
104
104
|
controller.instance_variable_set(:@cart, nil) # This is what happens in a real RailsController. zzz.
|
105
105
|
|
106
106
|
get :show
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
# We're testing the effective/providers/moneris.rb file, which is included into the OrdersController at runtime
|
4
4
|
|
5
|
-
describe Effective::OrdersController do
|
5
|
+
describe Effective::OrdersController, type: :controller do
|
6
6
|
routes { EffectiveOrders::Engine.routes }
|
7
7
|
|
8
8
|
let(:order) { FactoryGirl.create(:order) }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Effective::OrdersController do
|
3
|
+
describe Effective::OrdersController, type: :controller do
|
4
4
|
routes { EffectiveOrders::Engine.routes }
|
5
5
|
|
6
6
|
let(:purchased_order) { FactoryGirl.create(:purchased_order) }
|
@@ -288,7 +288,7 @@ describe Effective::OrdersController do
|
|
288
288
|
let(:subscription) { cart_with_subscription.cart_items.find { |obj| obj.purchasable.kind_of?(Effective::Subscription)}.purchasable }
|
289
289
|
|
290
290
|
let(:valid_order_with_new_subscription_coupon_attributes) do
|
291
|
-
valid_order_attributes.tap { |x| x[:effective_order]['order_items_attributes'] = {'0' => {"class"=>"Effective::Subscription", "stripe_coupon_id"=>"#{
|
291
|
+
valid_order_attributes.tap { |x| x[:effective_order]['order_items_attributes'] = {'0' => {"class"=>"Effective::Subscription", "stripe_coupon_id"=>"#{FactoryGirl.create(:stripe_coupon).id}", 'id' => "#{subscription.id}"}} }
|
292
292
|
end
|
293
293
|
|
294
294
|
before do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
# We're testing the effective/providers/stripe.rb file, which is included into the OrdersController at runtime
|
4
4
|
|
5
|
-
describe Effective::OrdersController do
|
5
|
+
describe Effective::OrdersController, type: :controller do
|
6
6
|
routes { EffectiveOrders::Engine.routes }
|
7
7
|
|
8
8
|
before { StripeMock.start }
|
@@ -137,7 +137,8 @@ EffectiveOrders.setup do |config|
|
|
137
137
|
:subject_prefix => '[example]',
|
138
138
|
:subject_for_admin_receipt => '',
|
139
139
|
:subject_for_buyer_receipt => '',
|
140
|
-
:subject_for_seller_receipt => ''
|
140
|
+
:subject_for_seller_receipt => '',
|
141
|
+
:delayed_job_deliver => false
|
141
142
|
}
|
142
143
|
|
143
144
|
# Moneris configuration
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe EffectiveOrdersHelper do
|
3
|
+
describe EffectiveOrdersHelper, :type => :helper do
|
4
4
|
describe '#price_to_currency' do
|
5
5
|
it 'converts an integer number of cents to a currency formatted string' do
|
6
6
|
price_to_currency(1050).should eq '$10.50'
|
data/spec/models/order_spec.rb
CHANGED
@@ -165,8 +165,8 @@ describe Effective::Order do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'returns true when purchased twice' do
|
168
|
-
order.purchase!('first time')
|
169
|
-
order.purchase!('second time').should eq false
|
168
|
+
order.purchase!('first time by a test')
|
169
|
+
order.purchase!('second time by a test').should eq false
|
170
170
|
end
|
171
171
|
|
172
172
|
it 'sends emails to the admin, buyer and seller' do
|
@@ -53,7 +53,7 @@ describe Effective::Subscription do
|
|
53
53
|
it 'sets the stripe coupon' do
|
54
54
|
subscription = Effective::Subscription.new()
|
55
55
|
|
56
|
-
coupon =
|
56
|
+
coupon = FactoryGirl.create(:stripe_coupon)
|
57
57
|
subscription.stripe_coupon_id = coupon.id
|
58
58
|
subscription.stripe_coupon.id.should eq coupon.id
|
59
59
|
end
|
@@ -76,7 +76,7 @@ describe Effective::Subscription do
|
|
76
76
|
subscription = Effective::Subscription.new()
|
77
77
|
|
78
78
|
plan = ::Stripe::Plan.create(:id => 'stripe_plan', :name => 'Stripe Plan', :amount => 1000, :currency => 'USD', :interval => 'month')
|
79
|
-
coupon =
|
79
|
+
coupon = FactoryGirl.create(:stripe_coupon, :percent_off => 25)
|
80
80
|
|
81
81
|
subscription.stripe_plan_id = plan.id
|
82
82
|
subscription.stripe_coupon_id = coupon.id
|
@@ -89,7 +89,7 @@ describe Effective::Subscription do
|
|
89
89
|
subscription = Effective::Subscription.new()
|
90
90
|
|
91
91
|
plan = ::Stripe::Plan.create(:id => 'stripe_plan', :name => 'Stripe Plan', :amount => 1000, :currency => 'USD', :interval => 'month')
|
92
|
-
coupon =
|
92
|
+
coupon = FactoryGirl.create(:stripe_coupon, :percent_off => nil, :amount_off => 100)
|
93
93
|
|
94
94
|
subscription.stripe_plan_id = plan.id
|
95
95
|
subscription.stripe_coupon_id = coupon.id
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/factories.rb
CHANGED
@@ -42,7 +42,7 @@ FactoryGirl.define do
|
|
42
42
|
|
43
43
|
before(:create) do |subscription|
|
44
44
|
stripe_plan = Stripe::Plan.create(:id => "stripe_plan_#{subscription.object_id}", :name => 'Stripe Plan', :amount => 1000, :currency => 'USD', :interval => 'month')
|
45
|
-
stripe_coupon =
|
45
|
+
stripe_coupon = FactoryGirl.create(:stripe_coupon)
|
46
46
|
|
47
47
|
subscription.stripe_plan_id = stripe_plan.id
|
48
48
|
subscription.stripe_coupon_id = stripe_coupon.id
|
@@ -108,11 +108,15 @@ FactoryGirl.define do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
factory :purchased_order, :parent => :order do
|
111
|
-
after(:create) { |order| order.purchase! }
|
111
|
+
after(:create) { |order| order.purchase!('by a test') }
|
112
112
|
end
|
113
113
|
|
114
114
|
factory :declined_order, :parent => :order do
|
115
115
|
after(:create) { |order| order.decline! }
|
116
116
|
end
|
117
117
|
|
118
|
+
factory :stripe_coupon, :class => Stripe::Coupon do
|
119
|
+
to_create {|c| c.save}
|
120
|
+
duration 'once'
|
121
|
+
end
|
118
122
|
end
|