Skip to content

Commit

Permalink
Add address to credit card info.
Browse files Browse the repository at this point in the history
  • Loading branch information
scrozier committed Feb 3, 2012
1 parent 84b1fda commit 07ea2fc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 13 deletions.
17 changes: 17 additions & 0 deletions app/controllers/tickets_controller.rb
Expand Up @@ -64,6 +64,12 @@ def reserve
return
end

unless address_ok
flash.now[:error] = 'Please enter your complete billing address.'
render :action => :show
return
end

end

if (@in_memory_of.present? && @in_memory_by.blank?) ||
Expand Down Expand Up @@ -161,6 +167,10 @@ def fill_credit_card_info_from_params
@donation.credit_card_verification = params[:credit_card_verification]
@donation.credit_card_first_name = params[:credit_card_first_name]
@donation.credit_card_last_name = params[:credit_card_last_name]
@donation.credit_card_address = params[:credit_card_address]
@donation.credit_card_city = params[:credit_card_city]
@donation.credit_card_state = params[:credit_card_state]
@donation.credit_card_zip = params[:credit_card_zip]
end

def extract_donation_amount(standard_amount, amount)
Expand All @@ -169,4 +179,11 @@ def extract_donation_amount(standard_amount, amount)
return standard_amount.to_i
end

def address_ok
params[:credit_card_address] &&
params[:credit_card_city] &&
params[:credit_card_state] &&
params[:credit_card_zip]
end

end
26 changes: 22 additions & 4 deletions app/models/donation.rb
Expand Up @@ -14,7 +14,11 @@ class Donation < ActiveRecord::Base
:credit_card_expiration_year,
:credit_card_verification,
:credit_card_first_name,
:credit_card_last_name
:credit_card_last_name,
:credit_card_address,
:credit_card_city,
:credit_card_state,
:credit_card_zip

if Rails.env.production?
ActiveMerchant::Billing::Base.mode = :production
Expand All @@ -34,11 +38,25 @@ def card_valid?
:first_name => @credit_card_first_name,
:last_name => @credit_card_last_name,
:verification_value => @credit_card_verification,
:type => @credit_card_type
:type => @credit_card_type,
)
@credit_card.valid?
end


def name_and_address
{
:email => patron.email,
:billing_address => {
:name => "#{@credit_card_first_name} #{@credit_card_last_name}",
:address1 => @credit_card_address,
:city => @credit_card_city,
:state => @credit_card_state,
:country => "US",
:zip => @credit_card_zip
}
}
end

# Returns a 2-element array:
# [successful?, transaction ID (string) or error message if payment unsuccessful]
def process_payment
Expand All @@ -55,7 +73,7 @@ def process_payment
description += "/Tickets, #{reservation.concert.name}"
end

response = gateway.purchase((amount * 100).to_i, @credit_card, :description => description)
response = gateway.purchase((amount * 100).to_i, @credit_card, name_and_address.merge({:description => description}))
return [true, response.authorization] if response.success?
return [false, response.message]

Expand Down
7 changes: 7 additions & 0 deletions app/views/tickets/donation_confirm.html.haml
Expand Up @@ -22,6 +22,9 @@
%tr
%td Name on card
%td= "#{@donation.credit_card_first_name} #{@donation.credit_card_last_name}"
%tr
%td Billing address
%td= raw "#{@donation.credit_card_address}<br />#{@donation.credit_card_city} #{@donation.credit_card_state} #{@donation.credit_card_zip}"
%tr
%td Amount
%td= dollar_amount(@donation.amount)
Expand All @@ -36,6 +39,10 @@
= hidden_field_tag :credit_card_verification, @donation.credit_card_verification
= hidden_field_tag :credit_card_first_name, @donation.credit_card_first_name
= hidden_field_tag :credit_card_last_name, @donation.credit_card_last_name
= hidden_field_tag :credit_card_address, @donation.credit_card_address
= hidden_field_tag :credit_card_city, @donation.credit_card_city
= hidden_field_tag :credit_card_state, @donation.credit_card_state
= hidden_field_tag :credit_card_zip, @donation.credit_card_zip
= hidden_field_tag :amount, @donation.amount
.actions
= submit_tag 'Process donation', :class => 'btn primary'
Expand Down
29 changes: 20 additions & 9 deletions app/views/tickets/show.html.haml
Expand Up @@ -67,6 +67,13 @@
.input
= text_field_tag :credit_card_first_name, @donation.credit_card_first_name, :class => "span3"
= text_field_tag :credit_card_last_name, @donation.credit_card_last_name, :class => "span3"
= app_text_field_tag :credit_card_address, @credit_card_address
= label_tag :credit_card_first_name, 'Credit card billing address (city, state, zip)'
.input
= text_field_tag :credit_card_city, @credit_card_city, :class => "span3"
= text_field_tag :credit_card_state, @credit_card_state, :class => "span1"
= text_field_tag :credit_card_zip, @credit_card_zip, :class => "span2"

.clearfix
= label_tag :standard_amount, 'Amount'
.input
Expand Down Expand Up @@ -108,17 +115,21 @@
= select_tag :credit_card_expiration_month, options_for_card_expiration_month(@donation.credit_card_expiration_month), :class => 'span3'
= select_tag :credit_card_expiration_year, options_for_card_expiration_year(@donation.credit_card_expiration_year), :class => 'span2'
= app_text_field_tag :credit_card_verification, 'Card verification value (CVV)', 1, @donation.credit_card_verification
= label_tag :credit_card_first_name, 'Name on card (first, last)'
.input
= text_field_tag :credit_card_first_name, @donation.credit_card_first_name, :class => "span3"
= text_field_tag :credit_card_last_name, @donation.credit_card_last_name, :class => "span3"
.clearfix
= label_tag :credit_card_first_name, 'Name on card (first, last)'
.input
= text_field_tag :credit_card_first_name, @donation.credit_card_first_name, :class => "span3"
= text_field_tag :credit_card_last_name, @donation.credit_card_last_name, :class => "span3"
= app_text_field_tag :credit_card_address, 'Credit card billing address (required)', 5, @donation.credit_card_address
.clearfix
= label_tag :credit_card_city, '(city, state, zip)'
.input
= text_field_tag :credit_card_city, @donation.credit_card_city, :class => "span3"
= text_field_tag :credit_card_state, @donation.credit_card_state, :class => "span1"
= text_field_tag :credit_card_zip, @donation.credit_card_zip, :class => "span2"
.clearfix
= app_text_field_tag :amount, nil, 2, @donation.amount






.actions
= submit_tag 'Request tickets', :class => 'btn primary'

Expand Down

0 comments on commit 07ea2fc

Please sign in to comment.