op_cart 0.0.10 → 0.0.11
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 +4 -4
- data/app/assets/javascripts/op_cart/orders.js.coffee +16 -10
- data/app/controllers/op_cart/orders_controller.rb +23 -5
- data/app/models/op_cart/order.rb +4 -3
- data/app/views/op_cart/orders/new.html.slim +20 -13
- data/app/views/op_cart/orders/show.html.slim +1 -1
- data/config/locales/op_cart.en.yml +1 -1
- data/db/migrate/20140829200318_create_op_cart_orders.rb +0 -1
- data/lib/op_cart/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb4504eab944521ca26e80d782e55b6c943aa7c7
|
4
|
+
data.tar.gz: a6c332fdbd12c6d11d5e94ac470b55f1a8b36c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f24610a0805d6de1a5238e848fc221e843313870c8cbfccaf4240d548cd8e3c0ddd1046823db46f2c1cfab86ffa0b74c3250a6802f32c879ab5e46ed6ec02f
|
7
|
+
data.tar.gz: 5ec244260b96dd7ed28c8dbcb15d1d2bf5bedc520cdf6053c48c96b57fd582c1620b810b723a6aef1bc93f1f2f99d6711bde30caf40a5e4ae0dc7eab4075166d
|
@@ -1,16 +1,13 @@
|
|
1
1
|
@OpCart =
|
2
2
|
ready: ->
|
3
|
-
if $('body').is '.op_cart-orders-new'
|
3
|
+
if $('body').is '.op_cart-orders-new, .op_cart-orders-create'
|
4
|
+
$city = $ '#order_shipping_address_city'
|
5
|
+
$state = $ '#order_shipping_address_state'
|
6
|
+
$zip = $ '#order_shipping_address_zip_code'
|
7
|
+
|
4
8
|
$number = $ '#order_credit_cards_number'
|
5
9
|
$expiry = $ '#order_credit_cards_expiry'
|
6
10
|
$cvc = $ '#order_credit_cards_cvc'
|
7
|
-
$city = $ '#order_shipping_addresses_city'
|
8
|
-
$state = $ '#order_shipping_addresses_state'
|
9
|
-
$zip = $ '#order_shipping_addresses_zip_code'
|
10
|
-
|
11
|
-
$number.payment 'formatCardNumber'
|
12
|
-
$expiry.payment 'formatCardExpiry'
|
13
|
-
$cvc.payment 'formatCardCVC'
|
14
11
|
|
15
12
|
$zip.change ->
|
16
13
|
if $zip.val().length == 5
|
@@ -20,6 +17,12 @@
|
|
20
17
|
$city.prop "disabled", false
|
21
18
|
$state.prop "disabled", false
|
22
19
|
|
20
|
+
if $('#card_details')
|
21
|
+
$number.payment 'formatCardNumber'
|
22
|
+
$expiry.payment 'formatCardExpiry'
|
23
|
+
$cvc.payment 'formatCardCVC'
|
24
|
+
|
25
|
+
@updateDisplayedQuantities()
|
23
26
|
@stripeCreateToken()
|
24
27
|
|
25
28
|
load: ->
|
@@ -50,11 +53,12 @@
|
|
50
53
|
if response.error
|
51
54
|
errorMessage = response.error.message
|
52
55
|
else
|
53
|
-
errorMessage = 'Email or shipping information missing'
|
56
|
+
errorMessage = 'Email or shipping information missing' #TODO: what else is missing?
|
54
57
|
$form.find(".payment-errors").text errorMessage
|
55
58
|
$form.find("button").prop "disabled", false
|
56
59
|
else
|
57
60
|
$('#order_card_token').val response.id
|
61
|
+
$('#order_details').remove()
|
58
62
|
$form.get(0).submit()
|
59
63
|
|
60
64
|
addItemToOrder: (productId, quantity) ->
|
@@ -66,6 +70,9 @@
|
|
66
70
|
@lineItemQuantity productId, 0
|
67
71
|
@updateDisplayedQuantity productId
|
68
72
|
|
73
|
+
updateDisplayedQuantities: ->
|
74
|
+
$('li[data-product-id]').each -> OpCart.updateDisplayedQuantity $(@).data('product-id')
|
75
|
+
|
69
76
|
updateDisplayedQuantity: (productId) ->
|
70
77
|
$quantity = $ "#line_item_product_#{productId} .quantity .value"
|
71
78
|
$quantity.html @lineItemQuantity(productId)
|
@@ -82,4 +89,3 @@
|
|
82
89
|
|
83
90
|
$ -> OpCart.ready()
|
84
91
|
$(document).on 'page:load', OpCart.load
|
85
|
-
|
@@ -9,9 +9,18 @@ module OpCart
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def create
|
12
|
+
@products = Product.all
|
12
13
|
@order = Order.new order_params
|
13
|
-
|
14
|
-
|
14
|
+
if current_user.blank? && user = User.find_by(email: params[:user][:email])
|
15
|
+
if user.valid_password? params[:user][:password]
|
16
|
+
sign_in user
|
17
|
+
else
|
18
|
+
flash[:alert] = 'A user with that email already exists. Please sign in or pick another email.'
|
19
|
+
return render :new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
sign_in create_user unless signed_in?
|
23
|
+
@order.user = current_user
|
15
24
|
add_line_items
|
16
25
|
|
17
26
|
if @order.save
|
@@ -26,6 +35,11 @@ module OpCart
|
|
26
35
|
|
27
36
|
private
|
28
37
|
|
38
|
+
def create_user
|
39
|
+
User.create name: params[:order][:shipping_address][:full_name], email: params[:user][:email],
|
40
|
+
password: params[:user][:password], password_confirmation: params[:user][:password]
|
41
|
+
end
|
42
|
+
|
29
43
|
def set_order
|
30
44
|
# TODO prevent viewing of others' orders
|
31
45
|
# @order = current_user.orders.find params[:id]
|
@@ -33,13 +47,17 @@ module OpCart
|
|
33
47
|
end
|
34
48
|
|
35
49
|
def order_params
|
36
|
-
params.require(:order).permit(:email, :card_token
|
37
|
-
{ shipping_address: [ :full_name, :address, :zip_code, :city, :state ] }
|
50
|
+
params.require(:order).permit(:email, :password, :card_token#,
|
51
|
+
# { shipping_address: [ :full_name, :address, :zip_code, :city, :state ] },
|
38
52
|
)
|
39
53
|
end
|
40
54
|
|
55
|
+
def line_items_params
|
56
|
+
params.require(:line_items).permit :quantities
|
57
|
+
end
|
58
|
+
|
41
59
|
def add_line_items
|
42
|
-
li_quantities_json = JSON.parse
|
60
|
+
li_quantities_json = JSON.parse line_items_params[:quantities]
|
43
61
|
li_quantities_json.each do |product_id, quantity|
|
44
62
|
@order.line_items <<
|
45
63
|
LineItem.new(sellable: Product.find(product_id), quantity: quantity)
|
data/app/models/op_cart/order.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
module OpCart
|
2
2
|
class Order < ActiveRecord::Base
|
3
3
|
has_many :line_items
|
4
|
+
has_one :shipping_address
|
4
5
|
belongs_to :user
|
5
6
|
|
6
7
|
accepts_nested_attributes_for :line_items
|
7
8
|
|
8
|
-
validates :email, presence: true, format: { with: /@/ }
|
9
9
|
validates :total, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
10
10
|
validates :tax_amount, numericality:
|
11
|
-
{ only_integer: true, greater_than_or_equal_to: 0 } if :tax_amount?
|
11
|
+
{ only_integer: true, greater_than_or_equal_to: 0 }, if: :tax_amount?
|
12
12
|
validates :status, presence: true
|
13
13
|
validates :user, presence: true
|
14
14
|
|
15
15
|
before_validation :set_total
|
16
|
+
before_validation -> { self.status = :new }, unless: :status?
|
16
17
|
before_save :charge_customer
|
17
18
|
|
18
19
|
private
|
@@ -24,7 +25,7 @@ module OpCart
|
|
24
25
|
def charge_customer
|
25
26
|
customer = Stripe::Customer.create(
|
26
27
|
card: card_token,
|
27
|
-
email: email
|
28
|
+
email: user.email
|
28
29
|
)
|
29
30
|
|
30
31
|
# TODO Create shipping address
|
@@ -3,13 +3,12 @@
|
|
3
3
|
h2 Purchasble Items
|
4
4
|
ul style="list-style-type: none"
|
5
5
|
- @products.each do |product|
|
6
|
-
li
|
6
|
+
li id="#{dom_id product}" data-product-id=(product.id)
|
7
7
|
p = product.name
|
8
8
|
p = product.description
|
9
9
|
p = number_to_currency product.price / 100
|
10
10
|
p
|
11
|
-
a onclick="OpCart.addItemToOrder(#{product.id}, 1)"
|
12
|
-
| Add to Order
|
11
|
+
a href="#" onclick="OpCart.addItemToOrder(#{product.id}, 1); return false" Add to Order
|
13
12
|
|
14
13
|
h2 Items in Order
|
15
14
|
ul style="list-style-type: none"
|
@@ -21,33 +20,41 @@
|
|
21
20
|
span.name Quantity:
|
22
21
|
span.value 0
|
23
22
|
p
|
24
|
-
a onclick="OpCart.removeItemFromOrder(#{product.id})"
|
25
|
-
| Remove
|
23
|
+
a href="#" onclick="OpCart.removeItemFromOrder(#{product.id}); return false" Remove
|
26
24
|
|
27
25
|
= simple_form_for @order, data: { stripe_key: Rails.configuration.stripe[:publishable_key] } do |f|
|
28
26
|
span.payment-errors
|
29
27
|
p
|
30
28
|
h2 Your Information
|
31
|
-
|
29
|
+
- if current_user.present?
|
30
|
+
strong Email:
|
31
|
+
span = current_user.email
|
32
|
+
- else
|
33
|
+
= simple_fields_for :user do |fu|
|
34
|
+
= fu.input :email, autofocus: true, input_html: { autocomplete: 'email' }
|
35
|
+
= fu.input :password
|
32
36
|
|
33
37
|
p
|
34
38
|
h2 Shipping Address
|
35
|
-
= f.simple_fields_for :
|
39
|
+
= f.simple_fields_for :shipping_address do |sa|
|
36
40
|
= sa.input :full_name, input_html: { autocomplete: 'name' }
|
37
41
|
= sa.input :address, input_html: { autocomplete: 'street-address' }
|
38
42
|
= sa.input :zip_code, input_html: { autocomplete: 'postal-code' }
|
39
43
|
= sa.input :city, disabled: true, input_html: { autocomplete: 'city' }
|
40
44
|
= sa.input :state, disabled: true, input_html: { autocomplete: 'state' }
|
41
45
|
|
42
|
-
p
|
46
|
+
p#card_details
|
43
47
|
h2 Card Details
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
=
|
48
|
+
- if f.object.card_token.present?
|
49
|
+
span Card information already provided.
|
50
|
+
- else
|
51
|
+
= f.simple_fields_for :credit_cards do |c|
|
52
|
+
= c.input :number, input_html: { autocomplete: 'cc-number' }
|
53
|
+
= c.input :expiry, input_html: { autocomplete: 'cc-exp' }
|
54
|
+
= c.input :cvc, input_html: { autocomplete: 'cc-csc' }
|
48
55
|
|
49
56
|
= f.input :card_token, as: :hidden
|
50
|
-
= hidden_field :line_items, :quantities, value:
|
57
|
+
= hidden_field :line_items, :quantities, value: params.fetch(:line_items, {}).fetch(:quantities, {})
|
51
58
|
|
52
59
|
.form-actions
|
53
60
|
= f.button :button, "Submit Payment"
|
data/lib/op_cart/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: op_cart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Boehs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2
|
19
|
+
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.2
|
26
|
+
version: '4.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: slim-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.18'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.18'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pg
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|