op_cart 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/op_cart/orders.js.coffee +29 -7
- data/app/controllers/op_cart/orders_controller.rb +13 -4
- data/app/models/op_cart/order.rb +8 -0
- data/app/views/op_cart/orders/new.html.slim +38 -22
- data/config/locales/op_cart.en.yml +15 -0
- data/db/seeds.rb +11 -0
- data/lib/op_cart/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80553909efd0c95f0fed6955e399223f241b2efe
|
4
|
+
data.tar.gz: 2416d21f1b359f719f0e51e09ac2fb90c191c7e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7883f2f9685b75e35d8c0942cc8079d2d94f50378dd59571f93ae22293db8292310299e9287236ddd82d60d7e9a05aa73270999ba57de69d110c5eaaaa191678
|
7
|
+
data.tar.gz: 67246ac06134e68ac64d8c0ad65981694f1e54ee8863ecb8c926475c9ffcbad0092048d6c244d6b38db031b45a102ac27a362c54a590c8432c0571680800e105
|
@@ -1,27 +1,49 @@
|
|
1
1
|
OpCart =
|
2
|
-
ready: ->
|
2
|
+
ready: ->
|
3
|
+
$number = $ '#order_credit_card_number'
|
4
|
+
$expiry = $ '#order_credit_card_expiry'
|
5
|
+
$cvc = $ '#order_credit_card_cvc'
|
6
|
+
|
7
|
+
$number.payment 'formatCardNumber'
|
8
|
+
$expiry.payment 'formatCardExpiry'
|
9
|
+
$cvc.payment 'formatCardCVC'
|
10
|
+
|
11
|
+
@stripeCreateToken()
|
12
|
+
|
3
13
|
load: -> @ready()
|
4
14
|
|
5
15
|
stripeCreateToken: ->
|
6
|
-
$("#
|
16
|
+
$("#new_order").submit (event) ->
|
7
17
|
$form = $(this)
|
8
|
-
|
9
18
|
$form.find("button").prop "disabled", true
|
10
|
-
|
19
|
+
|
20
|
+
expiration = $("#order_credit_card_expiry").payment "cardExpiryVal"
|
21
|
+
|
22
|
+
Stripe.card.createToken
|
23
|
+
number: $("#order_credit_card_number").val()
|
24
|
+
cvc: $("#order_credit_card_cvc").val()
|
25
|
+
exp_month: expiration.month || 0
|
26
|
+
exp_year: expiration.year || 0
|
27
|
+
, OpCart.stripeResponseHandler
|
11
28
|
|
12
29
|
false # Prevent the form from submitting with the default action
|
13
30
|
|
14
31
|
stripeResponseHandler: (status, response) ->
|
15
|
-
$form = $("#
|
32
|
+
$form = $("#new_order")
|
16
33
|
|
17
34
|
debugger
|
18
|
-
if response.error
|
19
|
-
|
35
|
+
if response.error || !$form.get(0).checkValidity()
|
36
|
+
if response.error
|
37
|
+
errorMessage = response.error.message
|
38
|
+
else
|
39
|
+
errorMessage = 'Email or shipping information missing'
|
40
|
+
$form.find(".payment-errors").text errorMessage
|
20
41
|
$form.find("button").prop "disabled", false
|
21
42
|
else
|
22
43
|
$form.append $("<input type=\"hidden\" name=\"stripeToken\" />").val(response.id)
|
23
44
|
$form.get(0).submit()
|
24
45
|
|
46
|
+
|
25
47
|
$ -> OpCart.ready()
|
26
48
|
$(document).on 'page:load', -> OpCart.load()
|
27
49
|
|
@@ -1,16 +1,25 @@
|
|
1
1
|
module OpCart
|
2
2
|
class OrdersController < ApplicationController
|
3
3
|
def new
|
4
|
-
@
|
4
|
+
@products = [Product.first] # Temp hack to display first product as order
|
5
|
+
@order = Order.new
|
5
6
|
end
|
6
7
|
|
7
8
|
def create
|
8
9
|
product = Product.find params[:product_id]
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
customer = Stripe::Customer.create(
|
12
|
+
card: params[:stripeToken],
|
13
|
+
email: params[:order][:email]
|
14
|
+
)
|
15
|
+
|
16
|
+
# TODO Create Order w/ Line Items
|
17
|
+
# TODO Create shipping address
|
18
|
+
|
19
|
+
Stripe::Charge.create(
|
20
|
+
amount: product.price,
|
12
21
|
currency: "usd",
|
13
|
-
|
22
|
+
customer: customer.id
|
14
23
|
)
|
15
24
|
|
16
25
|
redirect_to new_order_path, notice: 'Thank you for your purchase'
|
data/app/models/op_cart/order.rb
CHANGED
@@ -7,5 +7,13 @@ module OpCart
|
|
7
7
|
{ only_integer: true, greater_than_or_equal_to: 0 } if :tax_amount?
|
8
8
|
validates :status, presence: true
|
9
9
|
validates :user, presence: true
|
10
|
+
|
11
|
+
before_save :charge_customer
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def charge_customer
|
16
|
+
# TODO Create and charge customer
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
@@ -1,29 +1,45 @@
|
|
1
|
+
script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.0.2/jquery.payment.min.js" type="text/javascript"
|
1
2
|
script src="https://js.stripe.com/v2/" type="text/javascript"
|
2
3
|
|
3
4
|
javascript:
|
4
5
|
Stripe.setPublishableKey('#{Rails.configuration.stripe[:publishable_key]}')
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
- if @products.any?
|
8
|
+
-# Hack to display products temporarily
|
9
|
+
.new_order
|
10
|
+
h2 Items in Order
|
11
|
+
ul style="list-style-type: none"
|
12
|
+
- @products.each do |product|
|
13
|
+
li
|
14
|
+
p = product.name
|
15
|
+
p = product.description
|
16
|
+
p = number_to_currency product.price / 100
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
|
18
|
+
= simple_form_for @order do |f|
|
19
|
+
span.payment-errors
|
20
|
+
p
|
21
|
+
h2 Your Information
|
22
|
+
= f.input :email, autofocus: true, input_html: { autocomplete: 'email' }
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
p
|
25
|
+
h2 Shipping Address
|
26
|
+
= f.simple_fields_for :shipping_address do |sa|
|
27
|
+
= sa.input :full_name, input_html: { autocomplete: 'name' }
|
28
|
+
= sa.input :address, input_html: { autocomplete: 'street-address' }
|
29
|
+
= sa.input :zip_code, input_html: { autocomplete: 'postal-code' }
|
30
|
+
= sa.input :city, disabled: true, input_html: { autocomplete: 'city' }
|
31
|
+
= sa.input :state, disabled: true, input_html: { autocomplete: 'state' }
|
32
|
+
|
33
|
+
p
|
34
|
+
h2 Card Details
|
35
|
+
= f.simple_fields_for :credit_card do |c|
|
36
|
+
= c.input :number, input_html: { autocomplete: 'cc-number' }
|
37
|
+
= c.input :expiry, input_html: { autocomplete: 'cc-exp' }
|
38
|
+
= c.input :cvc, input_html: { autocomplete: 'cc-csc' }
|
39
|
+
|
40
|
+
= hidden_field_tag :product_id, @products.first.id
|
41
|
+
|
42
|
+
.form-actions
|
43
|
+
= f.button :button, "Submit Payment"
|
44
|
+
- else
|
45
|
+
p Add an item to your order.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
en:
|
2
|
+
simple_form:
|
3
|
+
placeholders:
|
4
|
+
order:
|
5
|
+
email: "Email"
|
6
|
+
shipping_address:
|
7
|
+
full_name: "Full Name"
|
8
|
+
address: "Street Address"
|
9
|
+
zip_code: "Zip Code"
|
10
|
+
city: "City"
|
11
|
+
state: "State"
|
12
|
+
credit_card:
|
13
|
+
number: "Card Number"
|
14
|
+
expiry: 'MM/YY'
|
15
|
+
cvc: 'CVC'
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
product1_attrs = {
|
2
|
+
name: 'Device 3000',
|
3
|
+
description: 'The original Device 3000',
|
4
|
+
sku: 'A1000',
|
5
|
+
price: 15000,
|
6
|
+
allow_purchases: true,
|
7
|
+
charge_taxes: true,
|
8
|
+
user: User.first,
|
9
|
+
}
|
10
|
+
|
11
|
+
product1 = OpCart::Product.where(sku: product1_attrs[:sku]).first_or_create product1_attrs
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Boehs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Opinionated cart engine for Ruby on Rails
|
70
70
|
email:
|
71
71
|
- ericboehs@gmail.com
|
72
72
|
executables: []
|
@@ -87,10 +87,12 @@ files:
|
|
87
87
|
- app/models/op_cart/product.rb
|
88
88
|
- app/views/op_cart/orders/new.html.slim
|
89
89
|
- config/initializers/stripe.rb
|
90
|
+
- config/locales/op_cart.en.yml
|
90
91
|
- config/routes.rb
|
91
92
|
- db/migrate/20140829191646_create_op_cart_products.rb
|
92
93
|
- db/migrate/20140829200318_create_op_cart_orders.rb
|
93
94
|
- db/migrate/20140829201756_create_op_cart_line_items.rb
|
95
|
+
- db/seeds.rb
|
94
96
|
- lib/op_cart.rb
|
95
97
|
- lib/op_cart/engine.rb
|
96
98
|
- lib/op_cart/version.rb
|