bodega 0.4.4 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem 'activerecord', '>= 3.2.11'
4
+ gem 'addressabler'
4
5
  gem 'configurator2', '>= 0.1.3'
5
6
  gem 'i18n'
6
7
  gem 'maintain'
@@ -31,6 +31,10 @@ GEM
31
31
  activesupport (3.2.11)
32
32
  i18n (~> 0.6)
33
33
  multi_json (~> 1.0)
34
+ addressable (2.3.3)
35
+ addressabler (0.0.5)
36
+ addressable
37
+ addressable (>= 2.2.2)
34
38
  arel (3.0.2)
35
39
  builder (3.0.4)
36
40
  coderay (1.0.8)
@@ -111,6 +115,7 @@ PLATFORMS
111
115
  DEPENDENCIES
112
116
  active_shipping
113
117
  activerecord (>= 3.2.11)
118
+ addressabler
114
119
  configurator2 (>= 0.1.3)
115
120
  database_cleaner
116
121
  i18n
data/Rakefile CHANGED
@@ -4,13 +4,13 @@
4
4
  require 'rubygems'
5
5
  require 'bundler'
6
6
 
7
- begin
8
- Bundler.setup(:default, :development)
9
- rescue Bundler::BundlerError => e
10
- $stderr.puts e.message
11
- $stderr.puts "Run `bundle install` to install missing gems"
12
- exit e.status_code
13
- end
7
+ #begin
8
+ #Bundler.setup(:default, :development)
9
+ #rescue Bundler::BundlerError => e
10
+ #$stderr.puts e.message
11
+ #$stderr.puts "Run `bundle install` to install missing gems"
12
+ #exit e.status_code
13
+ #end
14
14
  require 'rake'
15
15
 
16
16
  require 'jeweler'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.9
@@ -22,7 +22,7 @@ class Bodega::OrdersController < ApplicationController
22
22
  def create
23
23
  if current_order.update_attributes(params[:order])
24
24
  if !current_order.new_shipping_rates? && params[:checkout]
25
- redirect_to current_order.payment_method.checkout_url(complete_order_url, new_order_url)
25
+ redirect_to current_order.payment_method.checkout_url(complete_order_url, new_order_url, params)
26
26
  else
27
27
  redirect_to new_order_path
28
28
  end
@@ -16,7 +16,7 @@ module Bodega
16
16
  has_many :order_products, class_name: 'Bodega::OrderProduct', dependent: :destroy
17
17
  accepts_nested_attributes_for :order_products
18
18
 
19
- delegate :empty?, to: :order_products
19
+ delegate :count, :empty?, :size, to: :order_products
20
20
 
21
21
  maintain :status do
22
22
  state :new, 1, default: true
@@ -89,6 +89,10 @@ module Bodega
89
89
  order_products.inject(Money.new(0)) {|sum, order_product| sum += order_product.subtotal }
90
90
  end
91
91
 
92
+ def summary
93
+ order_products.map(&:quantity_and_name).to_sentence
94
+ end
95
+
92
96
  def to_param
93
97
  identifier
94
98
  end
@@ -9,6 +9,8 @@ module Bodega
9
9
  belongs_to :order, class_name: 'Bodega::Order'
10
10
  belongs_to :product, polymorphic: true
11
11
 
12
+ default_scope order(:created_at)
13
+
12
14
  delegate :keep_stock?, :price, to: :product
13
15
 
14
16
  monetize :total_cents
@@ -1,4 +1,4 @@
1
- <%= form_for(current_order, method: :post, url: new_order_path) do |form| %>
1
+ <%= form_for(current_order, method: :post, url: new_order_path, id: 'bodega-checkout') do |form| %>
2
2
  <table id="bodega-cart">
3
3
  <thead>
4
4
  <tr><th class="product-name" colspan="2"><%= t 'bodega.product' %></th><th class="product-price"><%= t 'bodega.price' %></th><th class="product-total" colspan="2"><%= t 'bodega.total' %></th></tr>
@@ -13,7 +13,7 @@
13
13
  <% if current_order.ready? -%>
14
14
  <tr>
15
15
  <td class="product-total-label" colspan="3"><%= t 'bodega.total' %></td>
16
- <td class="product-total"><%= humanized_money_with_symbol current_order.total %></td>
16
+ <td class="product-total" nowrap="nowrap"><%= humanized_money_with_symbol current_order.total %></td>
17
17
  <td></td>
18
18
  </tr>
19
19
  <% end -%>
@@ -26,3 +26,4 @@
26
26
  <%= button_tag t('bodega.calculate_shipping'), id: 'bodega-update', name: :update, value: 1 %>
27
27
  <% end -%>
28
28
  <% end =%>
29
+ <%= render Bodega.config.payment_method.to_s %>
@@ -1,8 +1,6 @@
1
1
  <tr>
2
- <td class="shipping-postal-code">
2
+ <td class="shipping-postal-code" colspan="3">
3
3
  <%= form.text_field :postal_code, placeholder: t('bodega.postal_code') %>
4
- </td>
5
- <td class="shipping-rates" colspan="2">
6
4
  <% if current_order.postal_code.present? -%>
7
5
  <%= form.select :shipping_rate_code, current_order.shipping_rate_options %>
8
6
  <% end -%>
@@ -0,0 +1,24 @@
1
+ <%= javascript_include_tag 'https://checkout.stripe.com/v2/checkout.js' %>
2
+ <script type="text/javascript">
3
+ $('#bodega-checkout').click(function(event) {
4
+ event.preventDefault();
5
+ var button = $(this);
6
+ var form = button.parents('form');
7
+
8
+ var token = function(response) {
9
+ button.attr('name', '');
10
+ input = $('<input type="hidden" name="stripe" />').val(response.id);
11
+ form.append('<input type="hidden" name="checkout" value="1" />');
12
+ form.append(input).submit();
13
+ };
14
+
15
+ StripeCheckout.open({
16
+ key: <%= Bodega.config.stripe.publishable_key.inspect.html_safe %>,
17
+ amount: <%= current_order.total_cents %>,
18
+ name: <%= Bodega.config.store_name.inspect.html_safe %>,
19
+ description: <%= current_order.summary.inspect.html_safe %>,
20
+ panelLabel: 'Confirm:',
21
+ token: token
22
+ });
23
+ });
24
+ </script>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "bodega"
8
- s.version = "0.4.4"
8
+ s.version = "0.4.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Flip Sasser"]
12
- s.date = "2013-02-05"
12
+ s.date = "2013-03-31"
13
13
  s.description = "Bodega adds checkout logic to any model in your app!"
14
14
  s.email = "flip@x451.com"
15
15
  s.extra_rdoc_files = [
@@ -65,7 +65,7 @@ Gem::Specification.new do |s|
65
65
  s.homepage = "http://github.com/flipsasser/bodega"
66
66
  s.licenses = ["MIT"]
67
67
  s.require_paths = ["lib"]
68
- s.rubygems_version = "1.8.24"
68
+ s.rubygems_version = "1.8.25"
69
69
  s.summary = "Bodega adds checkout logic to any model in your app!"
70
70
 
71
71
  if s.respond_to? :specification_version then
@@ -73,12 +73,14 @@ Gem::Specification.new do |s|
73
73
 
74
74
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
75
75
  s.add_runtime_dependency(%q<activerecord>, [">= 3.2.11"])
76
+ s.add_runtime_dependency(%q<addressabler>, [">= 0"])
76
77
  s.add_runtime_dependency(%q<configurator2>, [">= 0.1.3"])
77
78
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
78
79
  s.add_runtime_dependency(%q<maintain>, [">= 0"])
79
80
  s.add_runtime_dependency(%q<money-rails>, [">= 0"])
80
81
  else
81
82
  s.add_dependency(%q<activerecord>, [">= 3.2.11"])
83
+ s.add_dependency(%q<addressabler>, [">= 0"])
82
84
  s.add_dependency(%q<configurator2>, [">= 0.1.3"])
83
85
  s.add_dependency(%q<i18n>, [">= 0"])
84
86
  s.add_dependency(%q<maintain>, [">= 0"])
@@ -86,6 +88,7 @@ Gem::Specification.new do |s|
86
88
  end
87
89
  else
88
90
  s.add_dependency(%q<activerecord>, [">= 3.2.11"])
91
+ s.add_dependency(%q<addressabler>, [">= 0"])
89
92
  s.add_dependency(%q<configurator2>, [">= 0.1.3"])
90
93
  s.add_dependency(%q<i18n>, [">= 0"])
91
94
  s.add_dependency(%q<maintain>, [">= 0"])
@@ -11,12 +11,14 @@ module Bodega
11
11
  option :customer_method, :current_user
12
12
  option :max_quantity, 1000
13
13
 
14
+ option :store_name, "Store name (override in Bodega.config.store_name)"
15
+
14
16
  # Auto-detect payment method. If a user has the Paypal gem installed,
15
17
  # it'll use that. If a user has the Plinq gem installed, it'll use that.
16
18
  # Otherwise, it'll be all, "HEY I NEED A PAYMENT METHOD" when checkout
17
19
  # starts.
18
20
  option :payment_method, lambda {
19
- defined?(::Plinq) ? :plinq : defined?(::Paypal) ? :paypal : raise("No payment method detected. Please set one using `Bodega.config.payment_method=`")
21
+ defined?(::Plinq) ? :plinq : defined?(::Paypal) ? :paypal : defined?(::Stripe) ? :stripe : raise("No payment method detected. Please set one using `Bodega.config.payment_method=`")
20
22
  }
21
23
 
22
24
  # Defaults to no shipping. Change to :fedex, :ups, or :usps and add
@@ -2,5 +2,6 @@ module Bodega
2
2
  module PaymentMethod
3
3
  autoload :Paypal, 'bodega/payment_method/paypal'
4
4
  autoload :Plinq, 'bodega/payment_method/plinq'
5
+ autoload :Stripe, 'bodega/payment_method/stripe'
5
6
  end
6
7
  end
@@ -7,7 +7,7 @@ module Bodega
7
7
 
8
8
  attr_accessor :options, :order
9
9
 
10
- def checkout_url(success_url, cancel_url)
10
+ def checkout_url(success_url, cancel_url, params = {})
11
11
  raise "Implement #{self.class.name}#checkout_url"
12
12
  end
13
13
 
@@ -5,7 +5,7 @@ module Bodega
5
5
  class Paypal < Base
6
6
  options :username, :password, :signature
7
7
 
8
- def checkout_url(success_url, cancel_url)
8
+ def checkout_url(success_url, cancel_url, params = {})
9
9
  response = client.setup(request, success_url, cancel_url)
10
10
  response.redirect_uri
11
11
  end
@@ -32,7 +32,7 @@ module Bodega
32
32
  def request
33
33
  @request ||= ::Paypal::Payment::Request.new(
34
34
  amount: order.total.to_f,
35
- description: order.order_products.map(&:quantity_and_name).to_sentence,
35
+ description: order.summary,
36
36
  items: order.order_products.map {|order_product|
37
37
  {
38
38
  name: order_product.name,
@@ -0,0 +1,53 @@
1
+ require 'bodega/payment_method/base'
2
+ require 'addressabler'
3
+
4
+ module Bodega
5
+ module PaymentMethod
6
+ class Stripe < Base
7
+ options :secret_key, :publishable_key
8
+
9
+ # Redirect to /cart/complete?stripe=tokenToVerifyPayment
10
+ def checkout_url(success_url, cancel_url, params = {})
11
+ uri = Addressable::URI.heuristic_parse(success_url)
12
+ uri.query_hash[:stripe] = params[:stripe]
13
+ uri.to_s
14
+ end
15
+
16
+ def complete!(options = {})
17
+ ::Stripe.api_key = Bodega.config.stripe.secret_key
18
+ ::Stripe::Charge.create(
19
+ amount: order.total_cents,
20
+ currency: 'usd',
21
+ card: options[:stripe],
22
+ description: order.summary
23
+ ).id
24
+ end
25
+
26
+ protected
27
+ def client
28
+ ::Paypal.sandbox! if Bodega.config.test_mode
29
+ @client ||= ::Paypal::Express::Request.new(
30
+ username: Bodega.config.paypal.username,
31
+ password: Bodega.config.paypal.password,
32
+ signature: Bodega.config.paypal.signature
33
+ )
34
+ end
35
+
36
+ def request
37
+ @request ||= ::Paypal::Payment::Request.new(
38
+ amount: order.total.to_f,
39
+ description: order.order_products.map(&:quantity_and_name).to_sentence,
40
+ items: order.order_products.map {|order_product|
41
+ {
42
+ name: order_product.name,
43
+ amount: order_product.price.to_f,
44
+ quantity: order_product.quantity
45
+ }
46
+ },
47
+ shipping_amount: order.shipping.to_f,
48
+ tax_amount: order.tax.to_f
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
@@ -45,19 +45,18 @@ module Bodega
45
45
  def packages
46
46
  @packages ||= [].tap do |packages|
47
47
  order.order_products.each do |order_product|
48
- packages.push(package_for(order_product)) if shippable?(order_product.product)
48
+ packages.push(*packages_for(order_product)) if shippable?(order_product.product)
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
- def package_for(order_product)
53
+ def packages_for(order_product)
54
54
  product = order_product.product
55
- weight = product.weight * order_product.quantity
56
-
57
- dimensions = product.dimensions
58
- dimensions[2] = dimensions[2] * order_product.quantity
59
-
60
- Package.new(weight, dimensions, units: Bodega.config.shipping.units)
55
+ packages = []
56
+ order_product.quantity.times do
57
+ packages.push(Package.new(product.weight, product.dimensions, units: Bodega.config.shipping.units))
58
+ end
59
+ packages
61
60
  end
62
61
 
63
62
  def shippable?(product)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bodega
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-05 00:00:00.000000000 Z
12
+ date: 2013-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.2.11
30
+ - !ruby/object:Gem::Dependency
31
+ name: addressabler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: configurator2
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +131,9 @@ files:
115
131
  - app/models/bodega/product.rb
116
132
  - app/views/bodega/orders/_cart.html.erb
117
133
  - app/views/bodega/orders/_cart_row.html.erb
134
+ - app/views/bodega/orders/_paypal.html.erb
118
135
  - app/views/bodega/orders/_shipping_row.html.erb
136
+ - app/views/bodega/orders/_stripe.html.erb
119
137
  - app/views/bodega/orders/edit.html.erb
120
138
  - app/views/bodega/orders/new.html.erb
121
139
  - app/views/bodega/orders/show.html.erb
@@ -130,6 +148,7 @@ files:
130
148
  - lib/bodega/payment_method.rb
131
149
  - lib/bodega/payment_method/base.rb
132
150
  - lib/bodega/payment_method/paypal.rb
151
+ - lib/bodega/payment_method/stripe.rb
133
152
  - lib/bodega/shipping_method.rb
134
153
  - lib/bodega/shipping_method/base.rb
135
154
  - lib/bodega/shipping_method/ups.rb
@@ -156,9 +175,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
175
  - - ! '>='
157
176
  - !ruby/object:Gem::Version
158
177
  version: '0'
159
- segments:
160
- - 0
161
- hash: 272964422154723195
162
178
  required_rubygems_version: !ruby/object:Gem::Requirement
163
179
  none: false
164
180
  requirements:
@@ -167,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
183
  version: '0'
168
184
  requirements: []
169
185
  rubyforge_project:
170
- rubygems_version: 1.8.24
186
+ rubygems_version: 1.8.25
171
187
  signing_key:
172
188
  specification_version: 3
173
189
  summary: Bodega adds checkout logic to any model in your app!