effective_orders 2.1.5 → 2.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
  SHA1:
3
- metadata.gz: fc912e7bf2fc4e12905abff50fab57ca0b8479eb
4
- data.tar.gz: 8da57b67b1b09169180d2782e690d0dbdc69389f
3
+ metadata.gz: f067a482a08a63b26a23649c3ff1cbeabdf5a3c9
4
+ data.tar.gz: b1c1adc7ce23f8196a072155261e3a9139761d0f
5
5
  SHA512:
6
- metadata.gz: bbf1ba883263abc262431f857bed188b8f9de0653b93cb337ef0338b0773e537ff2d090a5c36b94d29f340b4e4e179263c2e12caff7dc420feada264256fc905
7
- data.tar.gz: 29744efe4ccfdfe874b5ee905be298950d50dd59c9bdf3070df56751586e8bc9abd621c2a8bf2a2370452d3f7759fe41577e91c313b49accca2af0c3084b4be4
6
+ metadata.gz: 253b5d1cb1877f869558aceaf15be0230f896bddc419821d3bb322a00aff98f576db9103ad8829fe08706a1dca1d2aa03d39398a558b4cad9999a7ec97dce2e7
7
+ data.tar.gz: 2f0d3b522ad5c12632f9d6263459b13a26e2064a1ae838aa9a41dac3fc183a6998207f3937c1dabf6a08c7d47f0010c19cf4b20b828a4fe4a358c6232622efa1
@@ -73,14 +73,10 @@ module Effective
73
73
  @order.attributes = order_params
74
74
  @order.user_id = current_user.id
75
75
 
76
- if EffectiveOrders.require_shipping_address
77
- if @order.shipping_address_same_as_billing? && @order.billing_address.present?
78
- @order.shipping_address = @order.billing_address
79
- end
80
- end
81
-
82
76
  EffectiveOrders.authorized?(self, (@order.persisted? ? :update : :create), @order)
83
77
 
78
+ @order.valid? # This makes sure the correct shipping_address is copied from billing_address if shipping_address_same_as_billing
79
+
84
80
  Effective::Order.transaction do
85
81
  begin
86
82
  if @order.save_billing_address? && @order.user.respond_to?(:billing_address=) && @order.billing_address.present?
@@ -165,16 +165,18 @@ module EffectiveOrdersHelper
165
165
  end
166
166
 
167
167
  def payment_card_label(card)
168
- case card.to_s.downcase[0]
169
- when nil
168
+ card = card.to_s.downcase.gsub(' ', '').strip
169
+
170
+ case card
171
+ when ''
170
172
  'None'
171
- when 'v'
173
+ when 'v', 'visa'
172
174
  'Visa'
173
- when 'm'
175
+ when 'm', 'mc', 'master', 'mastercard'
174
176
  'MasterCard'
175
- when 'a'
177
+ when 'a', 'ax', 'american', 'americanexpress'
176
178
  'American Express'
177
- when 'd'
179
+ when 'd', 'discover'
178
180
  'Discover'
179
181
  else
180
182
  card.to_s
@@ -11,7 +11,7 @@ module Effective
11
11
  :shipping => { singular: true, use_full_name: EffectiveOrders.use_address_full_name }
12
12
  )
13
13
 
14
- attr_accessor :save_billing_address, :save_shipping_address, :shipping_address_same_as_billing # save these addresses to the user if selected
14
+ attr_accessor :save_billing_address, :save_shipping_address # save these addresses to the user if selected
15
15
  attr_accessor :terms_and_conditions # Yes, I agree to the terms and conditions
16
16
 
17
17
  # Settings in the /admin action forms
@@ -126,7 +126,6 @@ module Effective
126
126
  # Set up defaults
127
127
  self.save_billing_address = true
128
128
  self.save_shipping_address = true
129
- self.shipping_address_same_as_billing = true
130
129
 
131
130
  self.user = user || (items.first.user if items.first.kind_of?(Effective::Cart))
132
131
 
@@ -290,10 +289,6 @@ module Effective
290
289
  ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self.send_mark_as_paid_email_to_buyer)
291
290
  end
292
291
 
293
- def shipping_address_same_as_billing?
294
- ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self.shipping_address_same_as_billing)
295
- end
296
-
297
292
  def skip_buyer_validations?
298
293
  ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self.skip_buyer_validations)
299
294
  end
@@ -25,13 +25,9 @@
25
25
  - if EffectiveOrders.require_shipping_address
26
26
  %div{class: "col-sm-#{12 / num_addresses}"}
27
27
  %h3 Shipping Address
28
- - if EffectiveOrders.require_billing_address && EffectiveOrders.require_shipping_address
29
- .shipping_address_fields{style: (f.object.shipping_address_same_as_billing? && (f.object.errors[:shipping_address] || []).blank?) ? 'display: none;' : 'display: block;'}
30
- = effective_address_fields(f, :shipping_address)
31
- - if f.object.user.respond_to?(:shipping_address=)
32
- = f.input :save_shipping_address, as: :boolean, label: 'Save as my default shipping address', required: false
33
-
34
- = f.input :shipping_address_same_as_billing, as: :boolean, label: 'My shipping address is the same as my billing address', required: false
28
+ = effective_address_fields(f, :shipping_address)
29
+ - if f.object.user.respond_to?(:shipping_address=)
30
+ = f.input :save_shipping_address, as: :boolean, label: 'Save as my default shipping address', required: false
35
31
 
36
32
  - if EffectiveOrders.collect_note
37
33
  = render partial: 'effective/orders/order_note_fields', locals: { form: f }
@@ -118,9 +118,9 @@ module EffectiveOrders
118
118
 
119
119
  def self.permitted_params
120
120
  [
121
- :note, :save_billing_address, :save_shipping_address, :shipping_address_same_as_billing, :terms_and_conditions,
122
- billing_address: [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code],
123
- shipping_address: [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code],
121
+ :note, :save_billing_address, :save_shipping_address, :terms_and_conditions,
122
+ billing_address: EffectiveAddresses.permitted_params,
123
+ shipping_address: EffectiveAddresses.permitted_params,
124
124
  user_attributes: (EffectiveOrders.collect_user_fields || []),
125
125
  order_items_attributes: [:stripe_coupon_id, :class, :id]
126
126
  ]
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '2.1.5'.freeze
2
+ VERSION = '2.1.6'.freeze
3
3
  end
@@ -93,7 +93,6 @@ describe Effective::OrdersController, type: :controller do
93
93
  post :create, effective_order: {
94
94
  billing_address: billing_atts, save_billing_address: false,
95
95
  shipping_address: shipping_atts, save_shipping_address: false,
96
- shipping_address_same_as_billing: false,
97
96
  user_attributes: {first_name: 'First', last_name: 'Last', email: 'email@somwhere.com'}
98
97
  }
99
98
 
@@ -108,7 +107,6 @@ describe Effective::OrdersController, type: :controller do
108
107
  post :create, effective_order: {
109
108
  billing_address: billing_atts, save_billing_address: false,
110
109
  shipping_address: shipping_atts, save_shipping_address: false,
111
- shipping_address_same_as_billing: false
112
110
  }
113
111
 
114
112
  (assigns(:order).valid? && assigns(:order).persisted?).should eq true
@@ -123,8 +121,7 @@ describe Effective::OrdersController, type: :controller do
123
121
  it 'assign addresses to the order and the user' do
124
122
  post :create, effective_order: {
125
123
  billing_address: billing_atts, save_billing_address: true,
126
- shipping_address: shipping_atts, save_shipping_address: true,
127
- shipping_address_same_as_billing: false
124
+ shipping_address: shipping_atts, save_shipping_address: true
128
125
  }
129
126
 
130
127
  (assigns(:order).valid? && assigns(:order).persisted?).should eq true
@@ -141,8 +138,7 @@ describe Effective::OrdersController, type: :controller do
141
138
  it 'does not assign the billing_address to user if save_billing_address is false' do
142
139
  post :create, effective_order: {
143
140
  billing_address: billing_atts, save_billing_address: false,
144
- shipping_address: shipping_atts, save_shipping_address: true,
145
- shipping_address_same_as_billing: false
141
+ shipping_address: shipping_atts, save_shipping_address: true
146
142
  }
147
143
 
148
144
  (assigns(:order).valid? && assigns(:order).persisted?).should eq true
@@ -159,8 +155,7 @@ describe Effective::OrdersController, type: :controller do
159
155
  it 'does not assign the shipping_address to user if save_shipping_address is false' do
160
156
  post :create, effective_order: {
161
157
  billing_address: billing_atts, save_billing_address: true,
162
- shipping_address: shipping_atts, save_shipping_address: false,
163
- shipping_address_same_as_billing: false
158
+ shipping_address: shipping_atts, save_shipping_address: false
164
159
  }
165
160
 
166
161
  (assigns(:order).valid? && assigns(:order).persisted?).should eq true
@@ -177,8 +172,7 @@ describe Effective::OrdersController, type: :controller do
177
172
  it 'assign billing address to the order shipping_address when shipping_address_same_as_billing' do
178
173
  post :create, effective_order: {
179
174
  billing_address: billing_atts, save_billing_address: true,
180
- shipping_address: shipping_atts, save_shipping_address: true,
181
- shipping_address_same_as_billing: true
175
+ shipping_address: shipping_atts.merge(shipping_address_same_as_billing: 1), save_shipping_address: true,
182
176
  }
183
177
 
184
178
  (assigns(:order).valid? && assigns(:order).persisted?).should eq true
@@ -194,8 +188,7 @@ describe Effective::OrdersController, type: :controller do
194
188
 
195
189
  it 'assign billing address to the order shipping_address when shipping_address_same_as_billing and no shipping provided' do
196
190
  post :create, effective_order: {
197
- billing_address: billing_atts, save_billing_address: true,
198
- shipping_address_same_as_billing: true
191
+ billing_address: billing_atts, save_billing_address: true, shipping_address: { shipping_address_same_as_billing: 1 }
199
192
  }
200
193
 
201
194
  (assigns(:order).valid? && assigns(:order).persisted?).should eq true
@@ -211,9 +204,8 @@ describe Effective::OrdersController, type: :controller do
211
204
 
212
205
  it 'assign billing address to the order shipping_address but not the user when shipping_address_same_as_billing provided' do
213
206
  post :create, effective_order: {
214
- billing_address: billing_atts, save_billing_address: false,
215
- save_shipping_address: false,
216
- shipping_address_same_as_billing: true
207
+ billing_address: billing_atts, save_billing_address: false, shipping_address: { shipping_address_same_as_billing: 1 },
208
+ save_shipping_address: false
217
209
  }
218
210
 
219
211
  (assigns(:order).valid? && assigns(:order).persisted?).should eq true
@@ -230,8 +222,7 @@ describe Effective::OrdersController, type: :controller do
230
222
  it 'is invalid when passed an invalid address' do
231
223
  post :create, effective_order: {
232
224
  billing_address: billing_atts, save_billing_address: true,
233
- shipping_address: shipping_atts.tap { |x| x[:address1] = nil }, save_shipping_address: true,
234
- shipping_address_same_as_billing: false
225
+ shipping_address: shipping_atts.tap { |x| x[:address1] = nil }, save_shipping_address: true
235
226
  }
236
227
 
237
228
  (assigns(:order).valid? && assigns(:order).persisted?).should eq false
@@ -277,7 +268,7 @@ describe Effective::OrdersController, type: :controller do
277
268
  end
278
269
 
279
270
  it 'prevents the order from proceeding when missing a required address' do
280
- post :create, effective_order: { billing_address: billing_atts, save_billing_address: true, shipping_address_same_as_billing: false }
271
+ post :create, effective_order: { billing_address: billing_atts, save_billing_address: true }
281
272
 
282
273
  (assigns(:order).valid? && assigns(:order).persisted?).should eq false
283
274
  assigns(:order).errors[:shipping_address].present?.should eq true
@@ -8,3 +8,13 @@
8
8
   (0.1ms) SELECT MAX("orders"."id") FROM "orders"
9
9
   (0.1ms) SELECT MAX("orders"."id") FROM "orders"
10
10
   (0.1ms) SELECT MAX("orders"."id") FROM "orders"
11
+  (0.1ms) SELECT MAX("orders"."id") FROM "orders"
12
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
13
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
14
+  (0.1ms) SELECT MAX("orders"."id") FROM "orders"
15
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
16
+  (0.2ms) SELECT MAX("orders"."id") FROM "orders"
17
+  (0.1ms) SELECT MAX("orders"."id") FROM "orders"
18
+  (0.1ms) SELECT MAX("orders"."id") FROM "orders"
19
+  (0.1ms) SELECT MAX("orders"."id") FROM "orders"
20
+  (0.1ms) SELECT MAX("orders"."id") FROM "orders"
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: 2.1.5
4
+ version: 2.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: 2016-04-12 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 1.5.0
117
+ version: 1.6.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 1.5.0
124
+ version: 1.6.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: stripe-ruby-mock
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -265,7 +265,6 @@ files:
265
265
  - app/assets/javascripts/effective_orders.js
266
266
  - app/assets/javascripts/effective_orders/providers/stripe_charges.js.coffee
267
267
  - app/assets/javascripts/effective_orders/providers/stripe_subscriptions.js.coffee
268
- - app/assets/javascripts/effective_orders/shipping_address_toggle.js.coffee
269
268
  - app/assets/stylesheets/effective_orders.scss
270
269
  - app/assets/stylesheets/effective_orders/_order.scss
271
270
  - app/controllers/admin/customers_controller.rb
@@ -1,30 +0,0 @@
1
- hideShippingAddressFields = (shipping_address) ->
2
- shipping_address.hide().find('input,select').removeAttr('required')
3
-
4
- showShippingAddressFields = (shipping_address) ->
5
- shipping_address.show().find("input:not([name$='[address2]']),select:not([name$='[state_code]'])").prop('required', true)
6
-
7
- initShippingAddressFields = ->
8
- effective_order = $('.effective-order').first()
9
-
10
- if effective_order.length > 0
11
- shipping_address_same_as_billing = effective_order.find('#effective_order_shipping_address_same_as_billing')
12
- shipping_address = effective_order.find('.shipping_address_fields')
13
-
14
- if shipping_address_same_as_billing.length > 0 && shipping_address.length > 0
15
- if shipping_address_same_as_billing.is(':checked')
16
- hideShippingAddressFields(shipping_address)
17
- else
18
- showShippingAddressFields(shipping_address)
19
-
20
- $ -> initShippingAddressFields()
21
- $(document).on 'page:change', -> initShippingAddressFields()
22
-
23
- $(document).on 'change', '#effective_order_shipping_address_same_as_billing', (event) ->
24
- obj = $(event.currentTarget)
25
- shipping_address = obj.closest('form').find('.shipping_address_fields')
26
-
27
- if obj.is(':checked')
28
- hideShippingAddressFields(shipping_address)
29
- else
30
- showShippingAddressFields(shipping_address)