effective_orders 1.4.2 → 1.4.3

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/effective_orders/stripe_charges.js.coffee +11 -3
  3. data/app/assets/javascripts/effective_orders/stripe_subscriptions.js.coffee +2 -2
  4. data/app/controllers/effective/orders_controller.rb +13 -9
  5. data/app/controllers/effective/providers/moneris.rb +5 -0
  6. data/app/controllers/effective/providers/paypal.rb +3 -1
  7. data/app/helpers/effective_orders_helper.rb +24 -0
  8. data/app/models/concerns/acts_as_purchasable.rb +1 -1
  9. data/app/models/effective/order.rb +5 -3
  10. data/app/views/admin/orders/show.html.haml +0 -9
  11. data/app/views/effective/orders/_checkout_step_2.html.haml +9 -7
  12. data/app/views/effective/orders/_my_purchases.html.haml +3 -1
  13. data/app/views/effective/orders/_order.html.haml +6 -3
  14. data/app/views/effective/orders/_order_actions.html.haml +4 -0
  15. data/app/views/effective/orders/_order_payment_details.html.haml +3 -7
  16. data/app/views/effective/orders/declined.html.haml +2 -7
  17. data/app/views/effective/orders/moneris/_form.html.haml +1 -1
  18. data/app/views/effective/orders/my_purchases.html.haml +0 -3
  19. data/app/views/effective/orders/my_sales.html.haml +0 -3
  20. data/app/views/effective/orders/paypal/_form.html.haml +1 -1
  21. data/app/views/effective/orders/pretend/_form.html.haml +1 -1
  22. data/app/views/effective/orders/purchased.html.haml +0 -5
  23. data/app/views/effective/orders/show.html.haml +1 -12
  24. data/app/views/effective/orders/stripe/_form.html.haml +1 -2
  25. data/app/views/effective/orders_mailer/order_receipt_to_admin.html.haml +1 -1
  26. data/app/views/effective/orders_mailer/order_receipt_to_buyer.html.haml +1 -1
  27. data/lib/effective_orders.rb +1 -0
  28. data/lib/effective_orders/version.rb +1 -1
  29. data/lib/generators/templates/effective_orders.rb +4 -0
  30. data/spec/controllers/moneris_orders_controller_spec.rb +0 -112
  31. data/spec/dummy/log/test.log +8 -0
  32. data/spec/models/order_spec.rb +8 -5
  33. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f869116475dda7d252b6202a1384be1bb181f7bf
4
- data.tar.gz: d0288050d30d8915e2a3b255c5405e8ef9ed8567
3
+ metadata.gz: f9fa7393376be54a691baf0c759f4facf0ad65f8
4
+ data.tar.gz: 23ecc5ef071404acf15b5825f4d0d52c11d40e98
5
5
  SHA512:
6
- metadata.gz: 81e62b3d4520668550b0d993c4c14f0c0c26d80bd6f8be7c26537e4555af3376d3e1a061948cf1132045a684fd0a81f2cf2a0ca4b935a170176b5a8485cf684c
7
- data.tar.gz: b35df012dc37eb2b2391c661947d6238b5333839c7d777ca2cdff0573b0c476b5c248043be21503deb3460d1150259ed7a5db6222fb4aae5d27de5410de3fbf0
6
+ metadata.gz: 08e2d17111c520e4f222eebce38f9c24d7954da10270c8017531d83f21c756f1189b4f963ace2f61d93894105e203a79401483a93bea32e787742cf03986e142
7
+ data.tar.gz: 81aed4009f266646b8e60824c431f1beff5ada601550d83e66af90998c878434ab1a5d8a878c93192bda8f59574e5013c14efd6f030ba374bf984a90d4df2669
@@ -3,11 +3,16 @@ stripeCheckoutHandler = (key, form) ->
3
3
  key: key
4
4
  token: (token, args) ->
5
5
  if token.error
6
- form.find("input[type='submit']").prop('disabled', false)
6
+ form.find("input[type='submit']").removeProp('disabled')
7
+ $('input[data-disable-with]').each -> try $.rails.enableFormElement($(this))
8
+
7
9
  alert("An error ocurred when contacting Stripe. Your card has not been charged. Please refresh the page and try again. #{token.error.message}")
8
10
  else
9
- form.find("input[type='submit']").prop('disabled', true)
10
11
  form.find('input#effective_stripe_charge_token').val('' + token['id'])
12
+
13
+ form.find("input[type='submit']").prop('disabled', true)
14
+ $('input[data-disable-with]').each -> try $.rails.disableFormElement($(this))
15
+
11
16
  form.submit()
12
17
 
13
18
  $(document).on 'click', "#effective-orders-new-charge-form form input[type='submit']", (event) ->
@@ -17,10 +22,13 @@ $(document).on 'click', "#effective-orders-new-charge-form form input[type='subm
17
22
  form = obj.find('form').first()
18
23
 
19
24
  form.find("input[type='submit']").prop('disabled', true)
25
+ $('input[data-disable-with]').each -> try $.rails.disableFormElement($(this))
20
26
 
21
27
  stripeCheckoutHandler(obj.data('stripe-publishable-key'), form).open
22
28
  name: obj.data('site-title')
23
29
  email: obj.data('user-email')
24
30
  description: obj.data('description')
25
31
  amount: obj.data('amount')
26
- closed: -> form.find("input[type='submit']").prop('disabled', false)
32
+ closed: ->
33
+ form.find("input[type='submit']").removeProp('disabled')
34
+ $('input[data-disable-with]').each -> try $.rails.enableFormElement($(this))
@@ -3,7 +3,7 @@ stripeCheckoutHandler = (key, form) ->
3
3
  key: key
4
4
  token: (token, args) ->
5
5
  if token.error
6
- form.find("input[type='submit']").prop('disabled', false)
6
+ form.find("input[type='submit']").removeProp('disabled')
7
7
  alert("An error ocurred when contacting Stripe. Your card has not been charged. Please refresh the page and try again. #{token.error.message}")
8
8
  else
9
9
  form.find("input[type='submit']").prop('disabled', true)
@@ -25,4 +25,4 @@ $(document).on 'click', "#effective-orders-new-subscription-form form input[type
25
25
  email: obj.data('user-email')
26
26
  description: plan.text()
27
27
  panelLabel: 'Start Subscription'
28
- closed: -> form.find("input[type='submit']").prop('disabled', false)
28
+ closed: -> form.find("input[type='submit']").removeProp('disabled')
@@ -38,7 +38,7 @@ module Effective
38
38
 
39
39
  if EffectiveOrders.require_shipping_address
40
40
  if @order.shipping_address_same_as_billing? && @order.billing_address.present?
41
- @order.shipping_address ||= @order.billing_address
41
+ @order.shipping_address = @order.billing_address
42
42
  end
43
43
  end
44
44
 
@@ -91,15 +91,13 @@ module Effective
91
91
  # Purchases is an Order History page. List of purchased orders
92
92
  def my_purchases
93
93
  @orders = Order.purchased_by(current_user)
94
-
95
- EffectiveOrders.authorized?(self, :index, Effective::Order)
94
+ EffectiveOrders.authorized?(self, :index, Effective::Order.new(user: current_user))
96
95
  end
97
96
 
98
97
  # Sales is a list of what products beign sold by me have been purchased
99
98
  def my_sales
100
99
  @order_items = OrderItem.sold_by(current_user)
101
-
102
- EffectiveOrders.authorized?(self, :index, Effective::Order)
100
+ EffectiveOrders.authorized?(self, :index, Effective::Order.new(user: current_user))
103
101
  end
104
102
 
105
103
  # Thank you for Purchasing this Order. This is where a successfully purchased order ends up
@@ -128,11 +126,17 @@ module Effective
128
126
  end
129
127
 
130
128
  def pretend_purchase
131
- if (Rails.env.development? || Rails.env.test?) || EffectiveOrders.allow_pretend_purchase_in_production
132
- @order = Order.find(params[:id])
133
- EffectiveOrders.authorized?(self, :update, @order)
129
+ @order = Order.find(params[:id])
130
+ EffectiveOrders.authorized?(self, :update, @order)
131
+
132
+ if (Rails.env.production? == false && EffectiveOrders.allow_pretend_purchase_in_development)
134
133
  order_purchased('for pretend', params[:purchased_redirect_url], params[:declined_redirect_url])
135
134
  end
135
+
136
+ if (Rails.env.production? == true && EffectiveOrders.allow_pretend_purchase_in_production)
137
+ order_purchased('for pretend', params[:purchased_redirect_url], params[:declined_redirect_url])
138
+ end
139
+
136
140
  end
137
141
 
138
142
  protected
@@ -181,7 +185,7 @@ module Effective
181
185
  when 'my_purchases' ; 'Order History'
182
186
  when 'my_sales' ; 'Sales History'
183
187
  when 'purchased' ; 'Thank You'
184
- when 'declined' ; 'Unable to process payment'
188
+ when 'declined' ; 'Payment Declined'
185
189
  when 'show' ; 'Order Receipt'
186
190
  else 'Checkout'
187
191
  end
@@ -16,6 +16,11 @@ module Effective
16
16
  purchased_redirect_url = params.delete(:rvar_purchased_redirect_url)
17
17
  declined_redirect_url = params.delete(:rvar_declined_redirect_url)
18
18
 
19
+ if @order.purchased? # Fallback to a success condition of the Order is already purchased
20
+ order_purchased(params, purchased_redirect_url)
21
+ return
22
+ end
23
+
19
24
  if params[:result].to_s == '1' && params[:transactionKey].present?
20
25
  verify_params = parse_moneris_response(send_moneris_verify_request(params[:transactionKey])) || {}
21
26
 
@@ -13,7 +13,9 @@ module Effective
13
13
  EffectiveOrders.authorized?(self, :update, @order)
14
14
 
15
15
  if @order.present?
16
- if params[:payment_status] == 'Completed' && params[:custom] == EffectiveOrders.paypal[:secret]
16
+ if @order.purchased?
17
+ order_purchased(params)
18
+ elsif (params[:payment_status] == 'Completed' && params[:custom] == EffectiveOrders.paypal[:secret])
17
19
  order_purchased(params)
18
20
  else
19
21
  order_declined(params)
@@ -104,4 +104,28 @@ module EffectiveOrdersHelper
104
104
  alias_method :render_purchases, :render_order_history
105
105
  alias_method :render_my_purchases, :render_order_history
106
106
 
107
+ # Used by the _payment_details partial
108
+ def tableize_hash(hash, options = {class: 'table table-bordered'})
109
+ if hash.present? && hash.kind_of?(Hash)
110
+ content_tag(:table, options[:class]) do
111
+ hash.map do |k, v|
112
+ content_tag(:tr) do
113
+ content_tag((options[:th] ? :th : :td), k) +
114
+ content_tag(:td) do
115
+ if v.kind_of?(Hash)
116
+ tableize_hash(v, options.merge({:class => 'table table-bordered', :th => (options.key?(:sub_th) ? options[:sub_th] : options[:th])}))
117
+ elsif v.kind_of?(Array)
118
+ '[' + v.join(', ') + ']'
119
+ else
120
+ v
121
+ end
122
+ end
123
+ end
124
+ end.join('').html_safe
125
+ end.html_safe
126
+ else
127
+ hash.to_s.html_safe
128
+ end
129
+ end
130
+
107
131
  end
@@ -66,7 +66,7 @@ module ActsAsPurchasable
66
66
  end
67
67
 
68
68
  def title
69
- self[:title] || 'ActsAsPurchasable'
69
+ self[:title] || to_s
70
70
  end
71
71
 
72
72
  def tax_exempt
@@ -56,8 +56,8 @@ module Effective
56
56
  self.save_shipping_address = true
57
57
  self.shipping_address_same_as_billing = true
58
58
 
59
+ self.user = (items.delete(:user) if items.kind_of?(Hash)) || user
59
60
  add_to_order(items) if items.present?
60
- self.user = user if user.present?
61
61
  end
62
62
 
63
63
  def add(item, quantity = 1)
@@ -94,6 +94,8 @@ module Effective
94
94
  alias_method :add_to_order, :add
95
95
 
96
96
  def user=(user)
97
+ return if user.nil?
98
+
97
99
  super
98
100
 
99
101
  # Copy user addresses into this order if they are present
@@ -195,7 +197,7 @@ module Effective
195
197
  def purchase!(payment_details = nil, opts = {})
196
198
  opts = {validate: true, email: true}.merge(opts)
197
199
 
198
- return true if purchased?
200
+ return false if purchased?
199
201
  raise EffectiveOrders::AlreadyDeclinedException.new('order already declined') if (declined? && opts[:validate])
200
202
 
201
203
  success = false
@@ -222,7 +224,7 @@ module Effective
222
224
  end
223
225
 
224
226
  def decline!(payment_details = nil)
225
- return true if declined?
227
+ return false if declined?
226
228
 
227
229
  raise EffectiveOrders::AlreadyPurchasedException.new('order already purchased') if purchased?
228
230
 
@@ -1,11 +1,2 @@
1
1
  = render :partial => 'effective/orders/order', :locals => {:order => @order}
2
- %hr
3
2
  = render :partial => 'effective/orders/order_payment_details', :locals => {:order => @order}
4
-
5
- %hr
6
- = link_to 'Back', :back, :class => 'btn btn-primary'
7
- - if @order.purchased?
8
- = '-'
9
- = link_to 'Resend Receipt', effective_orders.resend_buyer_receipt_path(@order), 'data-confirm' => 'This action will email the buyer a copy of the original email receipt. Send receipt now?', :class => 'btn btn-default'
10
-
11
-
@@ -1,19 +1,21 @@
1
1
  = render order
2
2
 
3
3
  .effective-order.effective-order-purchase-actions
4
- - if EffectiveOrders.allow_pretend_purchase_in_production
5
- = render :partial => '/effective/orders/pretend/form', locals: {label: 'Purchase Order', order: order, purchased_redirect_url: purchased_redirect_url, declined_redirect_url: declined_redirect_url}
6
- %p= EffectiveOrders.allow_pretend_purchase_in_production_message
7
- - elsif (Rails.env.development? || Rails.env.test?)
4
+ - if (Rails.env.production? == false && EffectiveOrders.allow_pretend_purchase_in_development)
8
5
  = render :partial => '/effective/orders/pretend/form', locals: {label: 'Purchase Order (development only)', order: order, purchased_redirect_url: purchased_redirect_url, declined_redirect_url: declined_redirect_url}
9
6
 
7
+ - if (Rails.env.production? == true && EffectiveOrders.allow_pretend_purchase_in_production)
8
+ = render :partial => '/effective/orders/pretend/form', locals: {label: 'Purchase Order', order: order, purchased_redirect_url: purchased_redirect_url, declined_redirect_url: declined_redirect_url}
9
+
10
10
  - if EffectiveOrders.moneris_enabled
11
- = render :partial => '/effective/orders/moneris/form', :locals => {:order => order, :purchased_redirect_url => purchased_redirect_url, :declined_redirect_url => declined_redirect_url}
11
+ = render :partial => '/effective/orders/moneris/form', locals: {order: order, purchased_redirect_url: purchased_redirect_url, declined_redirect_url: declined_redirect_url}
12
12
 
13
13
  - if EffectiveOrders.paypal_enabled
14
- = render :partial => '/effective/orders/paypal/form', :locals => {:order => order}
14
+ = render :partial => '/effective/orders/paypal/form', locals: {order: order}
15
15
 
16
16
  - if EffectiveOrders.stripe_enabled
17
- = render :partial => '/effective/orders/stripe/form', :locals => {:order => order}
17
+ = render :partial => '/effective/orders/stripe/form', locals: {order: order}
18
18
 
19
+ - if (Rails.env.production? == true && EffectiveOrders.allow_pretend_purchase_in_production)
20
+ %p= EffectiveOrders.allow_pretend_purchase_in_production_message
19
21
 
@@ -4,12 +4,14 @@
4
4
  %th Order
5
5
  %th Date of Purchase
6
6
  %th Description
7
+ %th
7
8
  %tbody
8
9
  - orders.each do |order|
9
10
  %tr
10
- %td= link_to "##{order.to_param}", order_path.gsub(':id', order.to_param)
11
+ %td= order.to_param
11
12
  %td= order.purchased_at.strftime("%Y-%m-%d %H:%M")
12
13
  %td= order_summary(order)
14
+ %td= link_to 'View', order_path.gsub(':id', order.to_param)
13
15
 
14
16
  - unless orders.present?
15
17
  %p You have no purchased orders
@@ -1,4 +1,7 @@
1
1
  .effective-order
2
- = render :partial => 'effective/orders/order_header', :locals => {:order => order}
3
- = render :partial => 'effective/orders/order_shipping', :locals => {:order => order}
4
- = render :partial => 'effective/orders/order_items', :locals => {:order => order}
2
+ - unless defined?(no_order_actions)
3
+ = render partial: 'effective/orders/order_actions', locals: {order: order}
4
+
5
+ = render partial: 'effective/orders/order_header', locals: {order: order}
6
+ = render partial: 'effective/orders/order_shipping', locals: {order: order}
7
+ = render partial: 'effective/orders/order_items', locals: {order: order}
@@ -0,0 +1,4 @@
1
+ - if order.purchased?
2
+ %p.pull-right
3
+ = link_to 'Print', '#', :class => 'btn btn-default print-button', 'data-role' => 'print-button', :onClick => "window.print(); false;"
4
+ = link_to 'Resend Receipt', effective_orders.resend_buyer_receipt_path(order), :data => {'confirm' => 'This action will email you a copy of the original email receipt. Send receipt now?', 'disable_with' => 'Resending...'}, :class => 'btn btn-default'
@@ -6,11 +6,7 @@
6
6
  - elsif order.declined?
7
7
  %p This order was declined with the following details:
8
8
 
9
- %table.table
10
- %tbody
11
- - order.payment.each do |k, v|
12
- %tr
13
- %td= k
14
- %td= v
9
+ = tableize_hash(order.payment)
10
+
15
11
  - else
16
- %p None
12
+ %p No payment details present
@@ -1,10 +1,5 @@
1
- %h2 Unable to Purchase
2
- %p There was an error purchasing an order.
1
+ %h2 Payment Declined
3
2
 
4
- = render @order
3
+ %p Your #{link_to_current_cart(label: 'Shopping Cart')} items have been saved. Please try again.
5
4
 
6
- %p Your cart has been restored.
7
5
 
8
- %hr
9
- = link_to 'Home', root_url, :class => 'btn btn-primary'
10
- = link_to_current_cart :class => 'btn btn-default'
@@ -34,4 +34,4 @@
34
34
  = hidden_field_tag(:bill_postal_code, address.postal_code)
35
35
  = hidden_field_tag(:bill_country, address.country)
36
36
 
37
- = submit_tag 'Checkout with Moneris', :class => 'btn btn-primary', :data => {'disable_with' => 'Proceeding to Moneris...' }
37
+ = submit_tag 'Pay with Moneris', :class => 'btn btn-primary', :data => {'disable_with' => 'Continuing...' }
@@ -1,6 +1,3 @@
1
1
  %h2 Order History
2
2
 
3
3
  = render_order_history(@orders)
4
-
5
- %hr
6
- = link_to 'Home', root_url, :class => 'btn btn-primary'
@@ -23,6 +23,3 @@
23
23
 
24
24
  - unless @order_items.present?
25
25
  %p You have no sales
26
-
27
- %hr
28
- = link_to 'Home', root_url, :class => 'btn btn-primary'
@@ -2,4 +2,4 @@
2
2
  = hidden_field_tag :cmd, '_s-xclick'
3
3
  = hidden_field_tag :encrypted, paypal_encrypted_payload(order)
4
4
 
5
- = submit_tag 'Checkout with PayPal', :class => 'btn btn-primary', :data => {'disable_with' => 'Proceeding to PayPal...' }
5
+ = submit_tag 'Pay with PayPal', :class => 'btn btn-primary', :data => {'disable_with' => 'Continuing...' }
@@ -1,2 +1,2 @@
1
1
  = form_tag(effective_orders.pretend_purchase_path(order, :purchased_redirect_url => purchased_redirect_url, :declined_redirect_url => declined_redirect_url), method: :post) do
2
- = submit_tag label, :class => 'btn btn-primary', :data => {'disable_with' => 'Purchasing...' }
2
+ = submit_tag label, :class => 'btn btn-primary', :data => {'disable_with' => 'Continuing...' }
@@ -2,9 +2,4 @@
2
2
 
3
3
  %p You have successfully purchased the following:
4
4
 
5
- %a.btn.btn-default.pull-right{'data-role' => 'print-button', :class => 'print-button', :onClick => "window.print(); false;"} Print
6
-
7
5
  = render @order
8
-
9
- %hr
10
- = link_to 'Home', root_url, :class => 'btn btn-primary'
@@ -1,16 +1,5 @@
1
- - if @order.purchased?
2
- %h2 Receipt
3
- - else
4
- %h2 Order
5
- %hr
6
-
7
- %p.pull-right
8
- %a.btn.btn-default{'data-role' => 'print-button', :class => 'print-button', :onClick => "window.print(); false;"} Print
9
- - if @order.purchased?
10
- = link_to 'Resend Receipt', effective_orders.resend_buyer_receipt_path(@order), :data => {'confirm' => 'This action will email you a copy of the original email receipt. Send receipt now?', 'disable_with' => 'Resending...'}, :class => 'btn btn-default'
1
+ %h2= (@order.purchased? ? 'Receipt' : 'Order')
11
2
 
12
3
  = render @order
13
4
 
14
- = link_to 'Back', :back, :class => 'btn btn-primary'
15
-
16
5
 
@@ -4,5 +4,4 @@
4
4
  = simple_form_for(@stripe_charge || Effective::StripeCharge.new(order), (EffectiveOrders.simple_form_options || {}).merge(:url => effective_orders.stripe_charges_path)) do |f|
5
5
  = f.input :effective_order_id, :as => :hidden
6
6
  = f.input :token, :as => :hidden
7
- = f.submit 'Continue to Payment', :class => 'btn btn-primary'
8
-
7
+ = f.submit 'Pay with Stripe', :class => 'stripe-button', :data => {'disable_with' => 'Continuing...' }
@@ -5,4 +5,4 @@
5
5
  %body
6
6
  %p An order has been successfully purchased:
7
7
 
8
- = render @order
8
+ = render(@order, no_order_actions: true)
@@ -5,4 +5,4 @@
5
5
  %body
6
6
  %p Your order has been successfully purchased:
7
7
 
8
- = render @order
8
+ = render(@order, no_order_actions: true)
@@ -28,6 +28,7 @@ module EffectiveOrders
28
28
  mattr_accessor :obfuscate_order_ids
29
29
  mattr_accessor :silence_deprecation_warnings
30
30
 
31
+ mattr_accessor :allow_pretend_purchase_in_development
31
32
  mattr_accessor :allow_pretend_purchase_in_production
32
33
  mattr_accessor :allow_pretend_purchase_in_production_message
33
34
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '1.4.2'.freeze
2
+ VERSION = '1.4.3'.freeze
3
3
  end
@@ -74,6 +74,10 @@ EffectiveOrders.setup do |config|
74
74
  # and just display the 'Thank You' after checkout is clicked
75
75
  config.allow_free_orders = true
76
76
 
77
+ # Display a 'Purchase order' button on the Checkout screen allowing the user
78
+ # to purchase an Order without going through the payment processor
79
+ config.allow_pretend_purchase_in_development = true
80
+
77
81
  # Allow Pretend Purchase in Production
78
82
  # WARNING: Setting this option to true will allow users to purchase! an Order without entering a credit card
79
83
  # WARNING: When true, users can purchase! anything without paying money
@@ -131,115 +131,3 @@ describe Effective::OrdersController do
131
131
 
132
132
  end
133
133
  end
134
-
135
-
136
- # describe '#stripe_charge' do
137
- # before do
138
- # sign_in order.user
139
- # end
140
-
141
- # describe 'invalid parameters' do
142
- # it 'raises RecordNotFound when passed an unknown order id' do
143
- # expect {
144
- # post :stripe_charge, stripe_charge_params.tap { |x| x[:effective_stripe_charge]['effective_order_id'] = 999 }
145
- # }.to raise_error(ActiveRecord::RecordNotFound)
146
- # end
147
-
148
- # it 'renders the :create action on validation failure' do
149
- # subject.should_not_receive(:process_stripe_charge)
150
-
151
- # post :stripe_charge, stripe_charge_params.tap { |x| x[:effective_stripe_charge]['token'] = nil }
152
-
153
- # flash[:danger].downcase.include?('token').should eq true
154
- # assigns(:stripe_charge).errors[:token].present?.should eq true
155
-
156
- # assigns(:order).purchased?.should eq false
157
- # response.should render_template(:checkout)
158
- # end
159
- # end
160
-
161
- # describe 'valid parameters' do
162
- # it 'redirects to order_purchase_path on success' do
163
- # post :stripe_charge, stripe_charge_params
164
- # assigns(:order).purchased?.should eq true
165
- # response.should redirect_to "/orders/#{assigns(:order).to_param}/purchased"
166
- # end
167
-
168
- # it 'assigns the @stripe_charge, @order and @buyer properly' do
169
- # post :stripe_charge, stripe_charge_params
170
-
171
- # assigns(:stripe_charge).valid?.should eq true
172
- # assigns(:stripe_charge).order.should eq order
173
- # assigns(:order).should eq order
174
- # assigns(:buyer).should eq buyer
175
- # end
176
-
177
- # it 'calls process_stripe_charge when the stripe_charge form object is valid' do
178
- # subject.should_receive(:process_stripe_charge)
179
- # post :stripe_charge, stripe_charge_params
180
- # end
181
-
182
- # it 'assigns the buyer a new card based on the passed token' do
183
- # Effective::Customer.any_instance.should_receive(:update_card!).with(token)
184
- # post :stripe_charge, stripe_charge_params
185
- # end
186
-
187
- # it 'stores the Stripe::Charge info in the order.payment' do
188
- # post :stripe_charge, stripe_charge_params
189
- # assigns(:order).payment[:charge]['object'].should eq 'charge'
190
- # assigns(:order).payment[:charge]['amount'].should eq (order.total*100).to_i
191
- # assigns(:order).payment[:charge]['customer'].should eq buyer.stripe_customer_id
192
- # end
193
- # end
194
-
195
- # describe 'stripe charge errors' do
196
- # it 'rollsback the entire transaction when Stripe::Charge fails' do
197
- # StripeMock.prepare_card_error(:card_declined)
198
-
199
- # post :stripe_charge, stripe_charge_params
200
-
201
- # assigns(:order).purchased?.should eq false
202
- # assigns(:stripe_charge).errors[:base].first.downcase.include?('unable to process order with stripe').should eq true
203
- # assigns(:stripe_charge).errors[:base].first.downcase.include?('the card was declined').should eq true
204
- # response.should render_template(:checkout)
205
- # end
206
- # end
207
- # end
208
-
209
- # describe '#stripe_charge with a subscription' do
210
- # let(:order) { FactoryGirl.create(:order_with_subscription) }
211
- # let(:buyer) { Effective::Customer.for_user(order.user) }
212
- # let(:subscription) { order.order_items[1].purchasable }
213
- # let(:token) { 'tok_123456789' }
214
- # let(:stripe_charge_params) do
215
- # {:effective_stripe_charge => {'effective_order_id' => order.to_param, 'token' => token}}
216
- # end
217
-
218
- # before do
219
- # sign_in order.user
220
- # end
221
-
222
- # it 'redirects to order_purchase_path on success' do
223
- # post :stripe_charge, stripe_charge_params
224
- # assigns(:order).purchased?.should eq true
225
- # response.should redirect_to "/orders/#{assigns(:order).to_param}/purchased"
226
- # end
227
-
228
- # it 'makes a Stripe::Charge for only the non-Subscription OrderItems' do
229
- # post :stripe_charge, stripe_charge_params
230
- # assigns(:order).payment[:charge]['object'].should eq 'charge'
231
- # assigns(:order).payment[:charge]['amount'].should eq (order.order_items.first.total * 100).to_i
232
- # end
233
-
234
- # it 'makes a Stripe::Subscription for the Subscriptions' do
235
- # post :stripe_charge, stripe_charge_params
236
-
237
- # assigns(:order).payment[:subscriptions]["#{subscription.stripe_plan_id}"]['object'].should eq 'subscription'
238
- # assigns(:order).payment[:subscriptions]["#{subscription.stripe_plan_id}"]['plan'].should eq subscription.stripe_plan_id
239
- # subscription.reload.stripe_subscription_id.present?.should eq true
240
- # subscription.reload.stripe_coupon_id.present?.should eq true
241
-
242
- # Effective::Subscription.find(subscription.id).purchased?.should eq true
243
- # end
244
- # end
245
- #end
@@ -174,3 +174,11 @@
174
174
   (0.2ms) SELECT MAX("orders"."id") FROM "orders"
175
175
   (0.3ms) SELECT MAX("orders"."id") FROM "orders"
176
176
   (0.3ms) SELECT MAX("orders"."id") FROM "orders"
177
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
178
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
179
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
180
+  (0.1ms) SELECT MAX("orders"."id") FROM "orders"
181
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
182
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
183
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
184
+  (0.3ms) SELECT MAX("orders"."id") FROM "orders"
@@ -164,10 +164,9 @@ describe Effective::Order do
164
164
  order.purchase!('by a test')
165
165
  end
166
166
 
167
- it 'throws an error when purchased twice' do
167
+ it 'returns true when purchased twice' do
168
168
  order.purchase!('first time')
169
-
170
- expect { order.purchase!('second time') }.to raise_error(EffectiveOrders::AlreadyPurchasedException)
169
+ order.purchase!('second time').should eq false
171
170
  end
172
171
 
173
172
  it 'sends emails to the admin, buyer and seller' do
@@ -245,10 +244,14 @@ describe Effective::Order do
245
244
  order.decline!('by a test')
246
245
  end
247
246
 
248
- it 'throws an error when declined twice' do
247
+ it 'returns false when declined twice' do
249
248
  order.decline!('first time')
249
+ order.decline!('second time').should eq false
250
+ end
250
251
 
251
- expect { order.decline!('second time') }.to raise_error(EffectiveOrders::AlreadyDeclinedException)
252
+ it 'returns false when declined twice' do
253
+ order.decline!('first time')
254
+ order.decline!('second time').should eq false
252
255
  end
253
256
 
254
257
  it 'is included with the declined scope' do
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: 1.4.2
4
+ version: 1.4.3
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: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -368,6 +368,7 @@ files:
368
368
  - app/views/effective/orders/_checkout_step_2.html.haml
369
369
  - app/views/effective/orders/_my_purchases.html.haml
370
370
  - app/views/effective/orders/_order.html.haml
371
+ - app/views/effective/orders/_order_actions.html.haml
371
372
  - app/views/effective/orders/_order_header.html.haml
372
373
  - app/views/effective/orders/_order_items.html.haml
373
374
  - app/views/effective/orders/_order_payment_details.html.haml