Skip to content

Commit

Permalink
Pull credit cards from our system rather than stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbyron committed Oct 19, 2012
1 parent 29175b2 commit 4faf0cb
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 16 deletions.
4 changes: 0 additions & 4 deletions app/assets/javascripts/pr.payment_processor.coffee
Expand Up @@ -13,10 +13,6 @@ class PR.PaymentProcessor
$.facebox { div: '#update-credit-card' }, 'update-credit-card'
e.preventDefault()

$(document).on 'click', 'a.current-cc', (e) ->
$.facebox { ajax: $(this).attr('href') }, 'current-credit-card'
e.preventDefault()

formSubmit: (event) =>
event.preventDefault();

Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/partials/_settings.sass
Expand Up @@ -55,6 +55,8 @@ form.edit_user
display: none
a.current-cc
margin-left: 10px
#current-credit-card
margin-left: 1em

#facebox
.update-credit-card, .current-credit-card
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/users_controller.rb
Expand Up @@ -19,6 +19,7 @@ def notifications; end
def billing
@subscriptions = SubscriptionDecorator.decorate(
@user.subscriptions.order("start_date"))
@credit_card = current_user.credit_card
end

def update_credit_card
Expand All @@ -29,13 +30,6 @@ def update_credit_card
redirect_to billing_settings_path
end

def current_credit_card
payment_gateway = current_user.payment_gateway
@card = payment_gateway.current_credit_card

render :layout => false
end

def update
params[:current_page] ||= :edit

Expand Down
7 changes: 7 additions & 0 deletions app/models/credit_card.rb
@@ -0,0 +1,7 @@
class CreditCard < ActiveRecord::Base
belongs_to :user

def description
"XXXX-XXXX-XXXX-#{last_four} #{expiration_month}/#{expiration_year}"
end
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Expand Up @@ -7,6 +7,8 @@ class User < ActiveRecord::Base
has_many :subscriptions
has_many :payment_logs

has_one :credit_card

validates_uniqueness_of :contact_email, :on => :update
validates :status, :inclusion => {
:in => STATUSES, :message => "%{value} is not a valid status" }
Expand Down
5 changes: 2 additions & 3 deletions app/views/users/billing.html.haml
Expand Up @@ -27,9 +27,8 @@
- if @user.payment_provider == "stripe"
%p
= link_to "Update your credit card", '#', :class => "btn update-cc"
= link_to "Show which card we are currently billing",
current_credit_card_path,
:class => "current-cc", :rel => "facebox"
- if @credit_card
%span#current-credit-card Current Card: #{@credit_card.description}

#update-credit-card
%h1 Update your credit card
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20121019183135_create_credit_cards.rb
@@ -0,0 +1,15 @@
class CreateCreditCards < ActiveRecord::Migration
def up
create_table :credit_cards do |t|
t.belongs_to :user
t.string :last_four
t.integer :expiration_month
t.integer :expiration_year
t.timestamps
end
end

def down
drop_table :credit_cards
end
end
12 changes: 10 additions & 2 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20121011002134) do
ActiveRecord::Schema.define(:version => 20121019183135) do

create_table "announcements", :force => true do |t|
t.text "title"
Expand Down Expand Up @@ -80,6 +80,15 @@
t.datetime "updated_at"
end

create_table "credit_cards", :force => true do |t|
t.integer "user_id"
t.string "last_four"
t.integer "expiration_month"
t.integer "expiration_year"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "delayed_jobs", :force => true do |t|
t.integer "priority", :default => 0
t.integer "attempts", :default => 0
Expand Down Expand Up @@ -150,7 +159,6 @@
t.string "contact_email"
t.string "access_token"
t.boolean "notify_updates", :default => true, :null => false
t.text "mailchimp_web_id"
t.text "payment_provider"
t.text "payment_provider_id"
end
Expand Down

0 comments on commit 4faf0cb

Please sign in to comment.