-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
739 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.order-details{ | ||
width: 100%; | ||
|
||
th{ | ||
text-align: left; | ||
} | ||
|
||
th, td{ | ||
padding: 7px; | ||
border-bottom: 1px solid black; | ||
} | ||
} | ||
|
||
.order-button{ | ||
text-align: center; | ||
margin-top: 15px; | ||
} | ||
|
||
.address{ | ||
input{ | ||
width: 100%; | ||
margin-bottom: 5px; | ||
padding: 5px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* SECTIONS */ | ||
.section { | ||
clear: both; | ||
padding: 0px; | ||
margin: 0px; | ||
} | ||
|
||
/* COLUMN SETUP */ | ||
.col { | ||
display: block; | ||
float:left; | ||
margin: 1% 0 1% 1.6%; | ||
} | ||
.col:first-child { margin-left: 0; } | ||
|
||
/* GROUPING */ | ||
.group:before, | ||
.group:after { content:""; display:table; } | ||
.group:after { clear:both;} | ||
.group { zoom:1; /* For IE 6/7 */ } | ||
|
||
/* GRID OF THREE */ | ||
.span_3_of_3 { width: 100%; } | ||
.span_2_of_3 { width: 66.13%; } | ||
.span_1_of_3 { width: 32.26%; } | ||
|
||
/* GO FULL WIDTH BELOW 480 PIXELS */ | ||
@media only screen and (max-width: 480px) { | ||
.col { margin: 1% 0 1% 0%; } | ||
.span_3_of_3, .span_2_of_3, .span_1_of_3 { width: 100%; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
class DeckOrdersController < ApplicationController | ||
before_filter :validate_logged_in | ||
skip_before_action :verify_authenticity_token | ||
|
||
def show | ||
@order = DeckOrder.find(params[:id]) | ||
unless @order.user == current_user then redirect_to root_path end | ||
@title = "Order \##{@order.id}" | ||
end | ||
|
||
def new | ||
@deck = Deck.find(params[:deck]) | ||
@title = "Order Deck" | ||
|
||
if current_user.stripe_customer_id | ||
@customer = current_user.stripe_customer | ||
end | ||
end | ||
|
||
def quote | ||
@deck = Deck.find(params[:address][:deck_id]) | ||
unless @deck.user == current_user then redirect_to root_path end | ||
@title = "Order Deck" | ||
|
||
shipping = DeckOrder.calculate_shipping({ | ||
:country => params[:address][:country], | ||
:state => params[:address][:state], | ||
:city => params[:address][:city], | ||
:zip => params[:address][:zip] | ||
}) | ||
|
||
@quote = { | ||
:deck_price => '%.2f' % @deck.price, | ||
:shipping_price => '%.2f' % shipping[1], | ||
:shipping_service => shipping[0], | ||
:total_price => '%.2f' % (@deck.price + shipping[1]), | ||
:total_price_cents => ((@deck.price + shipping[1]) * 100).to_i, | ||
:city => "#{params[:address][:city]}, #{params[:address][:state]}, #{params[:address][:country]}", | ||
:shipping_name => params[:address][:name], | ||
:shipping_zip => params[:address][:zip], | ||
:shipping_line1 => params[:address][:line1], | ||
:shipping_line2 => params[:address][:line2], | ||
:address => params[:address] | ||
} | ||
|
||
render "new" | ||
end | ||
|
||
def order | ||
deck = Deck.find(params[:order][:deck_id]) | ||
unless deck.user == current_user then redirect_to root_path end | ||
|
||
# re-calculate everything to make sure the client isn't lying to us | ||
shipping = DeckOrder.calculate_shipping({ | ||
:country => params[:order][:address_country], | ||
:state => params[:order][:address_state], | ||
:city => params[:order][:address_city], | ||
:zip => params[:order][:address_zip] | ||
}) | ||
|
||
total_price = ((shipping[1] + deck.price) * 100).to_i | ||
|
||
token = params[:stripeToken] | ||
|
||
unless current_user.stripe_customer | ||
customer = Stripe::Customer.create( | ||
:description => current_user.name, | ||
:email => current_user.email, | ||
:metadata => { | ||
:user_id => current_user.id | ||
}, | ||
:source => token, | ||
:shipping => { | ||
:name => params[:order][:address_name], | ||
:address => { | ||
:line1 => params[:order][:address_line1], | ||
:line2 => params[:order][:address_line2], | ||
:country => params[:order][:address_country], | ||
:state => params[:order][:address_state], | ||
:city => params[:order][:address_city], | ||
:postal_code => params[:order][:address_zip] | ||
} | ||
} | ||
) | ||
|
||
current_user.update(:stripe_customer_id => customer["id"]) | ||
else | ||
customer = current_user.stripe_customer | ||
end | ||
|
||
begin | ||
charge = Stripe::Charge.create( | ||
:amount => total_price, | ||
:currency => "usd", | ||
:customer => customer["id"], | ||
:receipt_email => current_user.email, | ||
:description => "Custom Deck Print for #{current_user.email}", | ||
:metadata => { | ||
:user_id => current_user.id | ||
} | ||
) | ||
|
||
order = DeckOrder.create({ | ||
:deck => deck, | ||
:user => current_user, | ||
:shipping_name => params[:order][:address_name], | ||
:shipping_line_1 => params[:order][:address_line1], | ||
:shipping_line_2 => params[:order][:address_line2], | ||
:shipping_country => params[:order][:address_country], | ||
:shipping_city => params[:order][:address_city], | ||
:shipping_state => params[:order][:address_state], | ||
:shipping_zip => params[:order][:address_zip], | ||
:base_price => deck.price, | ||
:shipping_price => shipping[1], | ||
:stripe_charge_id => charge["id"] | ||
}) | ||
|
||
charge = Stripe::Charge.retrieve(charge["id"]) | ||
charge.metadata = { | ||
:user_id => current_user.id, | ||
:order_id => order.id | ||
} | ||
charge.save | ||
|
||
redirect_to order | ||
rescue Stripe::CardError => e | ||
render plain: "There was an error processing your card. Please go back and try again." | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module DeckOrdersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class DeckOrder < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :deck | ||
after_initialize :default_values | ||
|
||
def default_values | ||
self.shipped ||= false | ||
end | ||
|
||
def tracking_url | ||
"https://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=#{self.tracking_number}&loc=en_us" | ||
end | ||
|
||
def self.calculate_shipping(address) | ||
package = ActiveShipping::Package.new(16, [5, 5, 5], units: :imperial) | ||
|
||
origin = ActiveShipping::Location.new({ | ||
country: $ship_from_country, | ||
state: $ship_from_state, | ||
city: $ship_from_city, | ||
zip: $ship_from_zip | ||
}) | ||
|
||
dest = ActiveShipping::Location.new({ | ||
country: address[:country], | ||
state: address[:state], | ||
city: address[:city], | ||
zip: address[:zip] | ||
}) | ||
|
||
# format it properly :) | ||
rate = $ups.find_rates(origin, dest, package).rates.sort_by(&:price)[0] | ||
[rate.service_name, rate.price / 100.00] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h1>Order a Deck</h1> | ||
|
||
<p> | ||
You can have your deck printed in the same size as CAH cards and shipped to | ||
your doorstep! To start, click the deck you would like to purchase: | ||
</p> | ||
|
||
<div class="decks"> | ||
<% current_user.decks.order("id DESC").each do |deck| %> | ||
<%= render partial: "decks/module_order", locals: { deck: deck } %> | ||
<% end %> | ||
</div> |
Oops, something went wrong.