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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34511876560d7a99a31838f447cbfadc4a30c70c
4
- data.tar.gz: a5d30c4367be050345e227f33790c39a82b04729
3
+ metadata.gz: b0cabc11a1540a88ee03c9f24f9cb94c92caa2fa
4
+ data.tar.gz: fc21c6a4e480ed8f26ecdd573bc52bfd0158e50f
5
5
  SHA512:
6
- metadata.gz: 9509286115a6fdcb802c962b777aab0d4a6d8950c34620b11b48b7c0ec138e2e87892ffdddb07efb89de171c2a07565e7d1ac40c3b2bcdc456bfaa86c7ccbd42
7
- data.tar.gz: 2dfca854a6115611fdfceb10629780a1128adc2f3a022cb4f49e44c96715f2f1bf171cfcc83ba1770d84f1c85f39d20b10e84691fee1a4a4e37033614a569fa2
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
- tableize_hash(v, options.merge(th: (options.key?(:sub_th) ? options[:sub_th] : options[:th])))
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.card = token # This sets the default_card to the new card
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 && stripe_customer.default_card.present?
46
- card = stripe_customer.cards.retrieve(stripe_customer.default_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
- if Rails.env.production?
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
- if Rails.env.production?
331
- (OrdersMailer.order_receipt_to_seller(self, seller, order_items).deliver rescue false)
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.order_receipt_to_seller(self, seller, order_items).deliver
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
- %p= mail_to EffectiveOrders.mailer[:admin_email] || 'info@acmeindustries.com'
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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '1.6.4'.freeze
2
+ VERSION = '1.6.5'.freeze
3
3
  end
@@ -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"=>"#{::Stripe::Coupon.create().id}", 'id' => "#{subscription.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 }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Effective::WebhooksController do
3
+ describe Effective::WebhooksController, type: :controller do
4
4
  routes { EffectiveOrders::Engine.routes }
5
5
 
6
6
  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'
@@ -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 = ::Stripe::Coupon.create()
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 = ::Stripe::Coupon.create(:percent_off => 25)
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 = ::Stripe::Coupon.create(:percent_off => nil, :amount_off => 100)
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
@@ -6,6 +6,7 @@ require 'rspec/rails'
6
6
  require 'rspec/autorun'
7
7
  require 'factory_girl_rails'
8
8
  require 'stripe_mock'
9
+ require 'pry'
9
10
 
10
11
  # Requires supporting ruby files with custom matchers and macros, etc,
11
12
  # in spec/support/ and its subdirectories.
@@ -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 = Stripe::Coupon.create()
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect