effective_orders 1.6.0 → 1.6.1

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: 9594a00af04e8a3fa775560e34d35e9181e70919
4
- data.tar.gz: 78aca75f4a95e83b1d512c8537346bba1f41a78f
3
+ metadata.gz: f56436464dbe43fb2f2b12173b21c5b6905f8092
4
+ data.tar.gz: fffc2cb0fca162b283bd9c8363ef44ba3d8a85fe
5
5
  SHA512:
6
- metadata.gz: c32c82987c9746f17821c14da0f8d83ede0a180290eb6ad9813f5cda5cc0cbf76ec900e581279e9355247146e1d0aca3f3314658240fe1c371028d21aa8edaf4
7
- data.tar.gz: 5aebd22e4161a00b0db47c7b606055f884e29d4a9f9b1a800fa97aa23b7cfa5c7a789b9e89bf2148ebaf11980144e5be84debc74ab805cb6771f5b3480c1bc8f
6
+ metadata.gz: 1a9dac2ae8b2080f739b5c9a64503ded5bdc2725963c3179347fdd441cd389b2dcc4c28928665b3771225caae59d5d6f411a28db03ee30de354757933d9c2002
7
+ data.tar.gz: 875e6f55e84c991aa291ed034428bbf623c4c07e38c057dba462fff1bb0dcdfbcab5f7cf0c0e664f614ca0500d0dd01f759369eddba866dc36e6e3964eea128e
@@ -28,21 +28,38 @@ if defined?(ActiveAdmin)
28
28
  end
29
29
 
30
30
  index :download_links => false do
31
+ column :purchased_at
32
+
31
33
  column 'Order', :sortable => :id do |order|
32
34
  link_to "##{order.to_param}", effective_orders.order_path(order)
33
35
  end
34
36
 
35
- column 'Buyer', :sortable => :user_id do |order|
37
+ column 'Buyer Email' do |order|
38
+ mail_to order.user.email
39
+ end
40
+
41
+ column 'Buyer Name', :sortable => :user_id do |order|
36
42
  user_path = [EffectiveOrders.active_admin_namespace.presence, 'user_path'].compact.join('_')
37
43
  link_to order.user, (public_send(user_path, order.user) rescue '#')
38
44
  end
39
45
 
40
- column 'Summary' do |order|
41
- order_summary(order)
46
+ column 'Order Items' do |order|
47
+ content_tag(:ul) do
48
+ (order.order_items).map { |oi| content_tag(:li, oi) }.join.html_safe
49
+ end
42
50
  end
43
51
 
44
- column :purchased_at
45
- column :purchase_method
52
+ column 'Total' do |order|
53
+ price_to_currency(order.total)
54
+ end
55
+
56
+ column :payment_method do |order|
57
+ order.payment_method
58
+ end
59
+
60
+ column :payment_card_type do |order|
61
+ order.payment_card_type
62
+ end
46
63
 
47
64
  column do |order|
48
65
  link_to('View Receipt', effective_orders.order_path(order), class: 'member_link view_link') if order.purchased?
@@ -1,6 +1,8 @@
1
1
  .effective-order {
2
- .table {
2
+ table {
3
3
  clear: both;
4
+ width: 600px;
5
+ margin-bottom: 25px;
4
6
 
5
7
  tfoot {
6
8
  > tr:first-child {
@@ -13,12 +15,16 @@
13
15
  padding-right: 65px;
14
16
  }
15
17
 
18
+ td {
19
+ text-align: right;
20
+ }
21
+
16
22
  .actions { border: none; }
17
23
  }
18
-
19
- .price { text-align: right; }
20
24
  }
21
25
 
26
+ .price { text-align: right; }
27
+
22
28
  .effective-stripe-subscription {
23
29
  input {
24
30
  margin-top: 5px;
@@ -34,5 +40,10 @@
34
40
  > * {
35
41
  display: inline-block;
36
42
  }
43
+ }
37
44
 
45
+ @media print {
46
+ .effective-order-purchase-actions { display: none; }
47
+ .print-button { display: none; }
48
+ .resend-receipt-button { display: none; }
38
49
  }
@@ -15,7 +15,7 @@ module EffectiveOrdersHelper
15
15
  title[1..-1].each { |line| output << "<br>#{line}" }
16
16
  end.html_safe
17
17
  end
18
- end.join().html_safe
18
+ end.join.html_safe
19
19
  end
20
20
  end
21
21
 
@@ -107,22 +107,28 @@ module EffectiveOrdersHelper
107
107
  # Used by the _payment_details partial
108
108
  def tableize_hash(hash, options = {class: 'table table-bordered'})
109
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
110
+ content_tag(:table, class: options[:class]) do
111
+ title = options.delete(:title)
112
+
113
+ content = content_tag(:tbody) do
114
+ hash.map do |k, v|
115
+ content_tag(:tr) do
116
+ content_tag((options[:th] ? :th : :td), k) +
117
+ content_tag(:td) do
118
+ if v.kind_of?(Hash)
119
+ tableize_hash(v, options.merge(th: (options.key?(:sub_th) ? options[:sub_th] : options[:th])))
120
+ elsif v.kind_of?(Array)
121
+ '[' + v.join(', ') + ']'
122
+ else
123
+ v
124
+ end
121
125
  end
122
126
  end
123
- end
124
- end.join('').html_safe
125
- end.html_safe
127
+ end.join.html_safe
128
+ end
129
+
130
+ title.blank? ? content : (content_tag(:thead) { content_tag(:tr) { content_tag(:th, title, colspan: 2) } } + content)
131
+ end
126
132
  else
127
133
  hash.to_s.html_safe
128
134
  end
@@ -239,6 +239,8 @@ module Effective
239
239
  end
240
240
 
241
241
  def purchase_method
242
+ return 'None' unless purchased?
243
+
242
244
  if purchased?(:stripe_connect)
243
245
  'Stripe Connect'
244
246
  elsif purchased?(:stripe)
@@ -247,31 +249,47 @@ module Effective
247
249
  'Moneris'
248
250
  elsif purchased?(:paypal)
249
251
  'PayPal'
250
- elsif purchased?
252
+ else
251
253
  'Online'
254
+ end
255
+ end
256
+ alias_method :payment_method, :purchase_method
257
+
258
+ def purchase_card_type
259
+ return 'None' unless purchased?
260
+
261
+ if purchased?(:stripe_connect)
262
+ ((payment[:charge] || payment['charge'])['card']['brand'] rescue 'Unknown')
263
+ elsif purchased?(:stripe)
264
+ ((payment[:charge] || payment['charge'])['card']['brand'] rescue 'Unknown')
265
+ elsif purchased?(:moneris)
266
+ payment[:card] || payment['card'] || 'Unknown'
267
+ elsif purchased?(:paypal)
268
+ payment[:payment_type] || payment['payment_type'] || 'Unknown'
252
269
  else
253
- 'None'
270
+ 'Online'
254
271
  end
255
272
  end
273
+ alias_method :payment_card_type, :purchase_card_type
256
274
 
257
275
  def purchased?(provider = nil)
258
276
  return false if (purchase_state != EffectiveOrders::PURCHASED)
259
- return true if provider == nil
260
-
261
- begin
262
- case provider
263
- when :stripe_connect
264
- payment.keys.first.kind_of?(Numeric) && payment[payment.keys.first].key?('object') && payment[payment.keys.first]['object'] == 'charge'
265
- when :stripe
266
- payment.key?('object') && payment['object'] == 'charge'
267
- when :moneris
268
- payment.key?('response_code') && payment.key?('transactionKey')
269
- when :paypal
270
- else
271
- false
272
- end
273
- rescue => e
274
- false
277
+ return true if provider == nil || payment.kind_of?(Hash) == false
278
+
279
+ case provider.to_sym
280
+ when :stripe_connect
281
+ charge = (payment[:charge] || payment['charge'])
282
+ charge['id'] && charge['customer'] && charge['application_fee'].present?
283
+ when :stripe
284
+ charge = (payment[:charge] || payment['charge'])
285
+ charge['id'] && charge['customer']
286
+ when :moneris
287
+ (payment[:response_code] || payment['response_code']) &&
288
+ (payment[:transactionKey] || payment['transactionKey'])
289
+ when :paypal
290
+ (payment[:payer_email] || payment['payer_email'])
291
+ else
292
+ raise "Unknown provider #{provider} passed to Effective::Order.purchased?"
275
293
  end
276
294
  end
277
295
 
@@ -28,6 +28,10 @@ module Effective
28
28
  scope :sold, -> { joins(:order).where(:orders => {:purchase_state => EffectiveOrders::PURCHASED}) }
29
29
  scope :sold_by, lambda { |user| sold().where(:seller_id => user.try(:id)) }
30
30
 
31
+ def to_s
32
+ (quantity || 0) > 1 ? "#{quantity}x #{title}" : title
33
+ end
34
+
31
35
  def subtotal
32
36
  price * quantity
33
37
  end
@@ -1,40 +1,48 @@
1
1
  - include_download_column = order.purchased? && order.order_items.any? { |order_item| order_item.purchased_download_url.present? rescue false }
2
2
 
3
3
  .effective-order
4
- %table.table{:style => 'width: 600px;margin-bottom:25px;'}
5
-
4
+ %table.table
6
5
  %thead
7
6
  %tr
8
- %th.quantity{:style => 'text-align: left;'} Qty
9
- %th.item{:style => 'text-align: left;'} Item
7
+ %th.quantity Qty
8
+ %th.item= order.order_items.length > 1 ? 'Items' : 'Item'
10
9
  - if include_download_column
11
- %th.download{:style => 'text-align: left;'} Download
12
- %th.price{:style => 'text-align: right;'} Price
10
+ %th.download Download
11
+ %th.price Price
13
12
 
14
13
  %tbody
15
14
  - order.order_items.each do |item|
16
15
  %tr
17
- %td.quantity{:style => 'text-align: left;'}= item.quantity
18
- %td.item{:style => 'text-align: left;'}
16
+ %td.quantity= item.quantity
17
+ %td.item
19
18
  = item.title.html_safe
20
19
  - if order.new_record? && item.purchasable.kind_of?(Effective::Subscription)
21
20
  = render :partial => 'effective/orders/stripe/subscription_fields', :locals => {:form => form, :subscription => item.purchasable }
22
21
 
23
22
  - if include_download_column
24
- %td.download{:style => 'text-align: left;'}
23
+ %td.download
25
24
  - if item.purchased? && (item.purchased_download_url rescue nil).present?
26
25
  = link_to 'download', item.purchased_download_url
27
26
  - else
28
27
  = '-'
29
- %td.price{:style => 'text-align: right;'}= price_to_currency(item.subtotal)
28
+ %td.price= price_to_currency(item.subtotal)
30
29
 
31
30
  %tfoot
32
31
  %tr
33
- %th{:style => 'text-align: right;', :colspan => (include_download_column ? 3 : 2)} Subtotal
34
- %td.price{:style => 'text-align: right;'}= price_to_currency(order.subtotal)
32
+ %th.quantity
33
+ - if include_download_column
34
+ %th.download
35
+ %th.subtotal Subtotal
36
+ %td.price.subtotal-price= price_to_currency(order.subtotal)
35
37
  %tr
36
- %th{:style => 'text-align: right;', :colspan => (include_download_column ? 3 : 2)} Tax
37
- %td.price{:style => 'text-align: right;'}= price_to_currency(order.tax)
38
+ %th.quantity
39
+ - if include_download_column
40
+ %th.download
41
+ %th.tax Tax
42
+ %td.price.tax-price= price_to_currency(order.tax)
38
43
  %tr
39
- %th{:style => 'text-align: right;', :colspan => (include_download_column ? 3 : 2)} Total Due
40
- %td.price{:style => 'text-align: right;'}= price_to_currency(order.total)
44
+ %th.quantity
45
+ - if include_download_column
46
+ %th.download
47
+ %th.total Total Due
48
+ %td.price.total-price= price_to_currency(order.total)
@@ -1,10 +1,3 @@
1
1
  - if order.payment.present?
2
2
  .effective-order-payment-details
3
- %h4 Payment Details
4
-
5
- - if order.purchased?
6
- %p This order was purchased with the following details:
7
- - elsif order.declined?
8
- %p This order was declined with the following details:
9
-
10
- = tableize_hash(order.payment, class: 'table')
3
+ = tableize_hash(order.payment, {class: 'table', title: 'Payment Details'})
@@ -1,14 +1,14 @@
1
1
  .effective-order-shipping
2
- %table.table{:style => 'width: 600px;margin-bottom:25px;'}
2
+ %table.table
3
3
  %thead
4
4
  %tr
5
- %th{:style => 'text-align: left;'}= "#{order.purchased? ? 'Sold to' : 'Bill to'}"
5
+ %th= "#{order.purchased? ? 'Sold to' : 'Bill to'}"
6
6
  - if order.shipping_address.present? && !order.shipping_address.empty?
7
- %th{:style => 'text-align: left;'} Ship to
7
+ %th Ship to
8
8
 
9
9
  %tbody
10
10
  %tr
11
- %td{:style => 'text-align: left;'}
11
+ %td
12
12
  - if order.billing_address.present? && !order.billing_address.empty?
13
13
  = render :partial => 'effective/addresses/address', :locals => {:address => order.billing_address, :email => order.user.email}
14
14
  - else
@@ -18,5 +18,5 @@
18
18
  %br
19
19
 
20
20
  - if order.shipping_address.present? && !order.shipping_address.empty?
21
- %td{:style => 'text-align: left;'}
21
+ %td
22
22
  = render :partial => 'effective/addresses/address', :locals => {:address => order.shipping_address}
@@ -35,7 +35,12 @@ module EffectiveOrders
35
35
  # Set up our Stripe API Key
36
36
  initializer "effective_orders.stripe_api_key", :after => :load_config_initializers do |app|
37
37
  if EffectiveOrders.stripe_enabled
38
- require 'stripe'
38
+ begin
39
+ require 'stripe'
40
+ rescue Exception
41
+ raise "unable to load stripe. Plese add gem 'stripe' to your Gemfile and then 'bundle install'"
42
+ end
43
+
39
44
  ::Stripe.api_key = EffectiveOrders.stripe[:secret_key]
40
45
  end
41
46
  end
@@ -43,7 +48,12 @@ module EffectiveOrders
43
48
  # Use ActiveAdmin (optional)
44
49
  initializer 'effective_orders.active_admin' do
45
50
  if EffectiveOrders.use_active_admin?
46
- require 'activeadmin'
51
+ begin
52
+ require 'activeadmin'
53
+ rescue Exception
54
+ raise "unable to load activeadmin. Plese add gem 'activeadmin' to your Gemfile and then 'bundle install'"
55
+ end
56
+
47
57
  ActiveAdmin.application.load_paths.unshift Dir["#{config.root}/active_admin"]
48
58
 
49
59
  Rails.application.config.to_prepare do
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '1.6.0'.freeze
2
+ VERSION = '1.6.1'.freeze
3
3
  end
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.6.0
4
+ version: 1.6.1
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-11-20 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: devise
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: haml-rails
57
43
  requirement: !ruby/object:Gem::Requirement