Skip to content

Commit

Permalink
Rename Creditcard to Credit Card
Browse files Browse the repository at this point in the history
[Fixes #1605]
  • Loading branch information
Trung Lê authored and radar committed Jun 6, 2012
1 parent 4b499b8 commit cfad733
Show file tree
Hide file tree
Showing 48 changed files with 114 additions and 109 deletions.
4 changes: 2 additions & 2 deletions core/app/controllers/spree/admin/payments_controller.rb
Expand Up @@ -21,7 +21,7 @@ def new
def create
@payment = @order.payments.build(object_params)
if @payment.payment_method.is_a?(Spree::Gateway) && @payment.payment_method.payment_profiles_supported? && params[:card].present? and params[:card] != 'new'
@payment.source = Creditcard.find_by_id(params[:card])
@payment.source = CreditCard.find_by_id(params[:card])
end

begin
Expand Down Expand Up @@ -83,7 +83,7 @@ def load_data
else
@payment_method = @payment_methods.first
end
@previous_cards = @order.creditcards.with_payment_profile
@previous_cards = @order.credit_cards.with_payment_profile
end

def load_order
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/app_configuration.rb
Expand Up @@ -35,7 +35,7 @@ class AppConfiguration < Preferences::Configuration
preference :alternative_billing_phone, :boolean, :default => false # Request extra phone for bill addr
preference :alternative_shipping_phone, :boolean, :default => false # Request extra phone for ship addr
preference :always_put_site_name_in_title, :boolean, :default => true
preference :auto_capture, :boolean, :default => false # automatically capture the creditcard (as opposed to just authorize and capture later)
preference :auto_capture, :boolean, :default => false # automatically capture the credit card (as opposed to just authorize and capture later)
preference :cache_static_content, :boolean, :default => true
preference :check_for_spree_alerts, :boolean, :default => true
preference :checkout_zone, :string, :default => nil # replace with the name of a zone if you would like to limit the countries
Expand Down
@@ -1,5 +1,5 @@
module Spree
class Creditcard < ActiveRecord::Base
class CreditCard < ActiveRecord::Base
has_many :payments, :as => :source, :class_name => "Spree::Payment"

before_save :set_last_digits
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/gateway.rb
Expand Up @@ -10,7 +10,7 @@ class Gateway < PaymentMethod
attr_accessible :preferred_server, :preferred_test_mode

def payment_source_class
Creditcard
CreditCard
end

# instantiates the selected gateway and configures with the options stored in the database
Expand Down
20 changes: 10 additions & 10 deletions core/app/models/spree/gateway/bogus.rb
Expand Up @@ -23,29 +23,29 @@ def create_profile(payment)
payment.source.update_attributes(:gateway_customer_profile_id => generate_profile_id(success))
end

def authorize(money, creditcard, options = {})
profile_id = creditcard.gateway_customer_profile_id
if VALID_CCS.include? creditcard.number or (profile_id and profile_id.starts_with? 'BGS-')
def authorize(money, credit_card, options = {})
profile_id = credit_card.gateway_customer_profile_id
if VALID_CCS.include? credit_card.number or (profile_id and profile_id.starts_with? 'BGS-')
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
else
ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { :message => 'Bogus Gateway: Forced failure' }, :test => true)
end
end

def purchase(money, creditcard, options = {})
profile_id = creditcard.gateway_customer_profile_id
if VALID_CCS.include? creditcard.number or (profile_id and profile_id.starts_with? 'BGS-')
def purchase(money, credit_card, options = {})
profile_id = credit_card.gateway_customer_profile_id
if VALID_CCS.include? credit_card.number or (profile_id and profile_id.starts_with? 'BGS-')
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
else
ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', :message => 'Bogus Gateway: Forced failure', :test => true)
end
end

def credit(money, creditcard, response_code, options = {})
def credit(money, credit_card, response_code, options = {})
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345')
end

def capture(authorization, creditcard, gateway_options)
def capture(authorization, credit_card, gateway_options)
if authorization.response_code == '12345'
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '67890')
else
Expand All @@ -54,7 +54,7 @@ def capture(authorization, creditcard, gateway_options)

end

def void(response_code, creditcard, options = {})
def void(response_code, credit_card, options = {})
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345')
end

Expand All @@ -77,7 +77,7 @@ def generate_profile_id(success)
prefix = success ? 'BGS' : 'FAIL'
while record
random = "#{prefix}-#{Array.new(6){rand(6)}.join}"
record = Creditcard.where(:gateway_customer_profile_id => random).first
record = CreditCard.where(:gateway_customer_profile_id => random).first
end
random
end
Expand Down
8 changes: 4 additions & 4 deletions core/app/models/spree/gateway/bogus_simple.rb
Expand Up @@ -6,16 +6,16 @@ def payment_profiles_supported?
false
end

def authorize(money, creditcard, options = {})
if VALID_CCS.include? creditcard.number
def authorize(money, credit_card, options = {})
if VALID_CCS.include? credit_card.number
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
else
ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { :message => 'Bogus Gateway: Forced failure' }, :test => true)
end
end

def purchase(money, creditcard, options = {})
if VALID_CCS.include? creditcard.number
def purchase(money, credit_card, options = {})
if VALID_CCS.include? credit_card.number
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
else
ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', :message => 'Bogus Gateway: Forced failure', :test => true)
Expand Down
6 changes: 3 additions & 3 deletions core/app/models/spree/order.rb
Expand Up @@ -380,9 +380,9 @@ def name
end
end

def creditcards
creditcard_ids = payments.from_creditcard.map(&:source_id).uniq
Creditcard.scoped(:conditions => { :id => creditcard_ids })
def credit_cards
credit_card_ids = payments.from_credit_card.map(&:source_id).uniq
CreditCard.scoped(:conditions => { :id => credit_card_ids })
end

def process_payments!
Expand Down
4 changes: 2 additions & 2 deletions core/app/models/spree/payment.rb
Expand Up @@ -18,7 +18,7 @@ class Payment < ActiveRecord::Base

attr_accessible :amount, :payment_method_id, :source_attributes

scope :from_creditcard, where(:source_type => 'Spree::Creditcard')
scope :from_credit_card, where(:source_type => 'Spree::CreditCard')
scope :with_state, lambda { |s| where(:state => s) }
scope :completed, with_state('completed')
scope :pending, with_state('pending')
Expand Down Expand Up @@ -90,7 +90,7 @@ def profiles_supported?
end

def create_payment_profile
return unless source.is_a?(Creditcard) && source.number && !source.has_payment_profile?
return unless source.is_a?(CreditCard) && source.number && !source.has_payment_profile?
payment_method.create_profile(self)
rescue ActiveMerchant::ConnectionError => e
gateway_error e
Expand Down
8 changes: 4 additions & 4 deletions core/app/models/spree/payment/processing.rb
Expand Up @@ -32,8 +32,8 @@ def capture!
check_environment

if payment_method.payment_profiles_supported?
# Gateways supporting payment profiles will need access to creditcard object because this stores the payment profile information
# so supply the authorization itself as well as the creditcard, rather than just the authorization code
# Gateways supporting payment profiles will need access to credit card object because this stores the payment profile information
# so supply the authorization itself as well as the credit card, rather than just the authorization code
response = payment_method.capture(self, source, gateway_options)
else
# Standard ActiveMerchant capture usage
Expand All @@ -51,8 +51,8 @@ def void_transaction!
check_environment

if payment_method.payment_profiles_supported?
# Gateways supporting payment profiles will need access to creditcard object because this stores the payment profile information
# so supply the authorization itself as well as the creditcard, rather than just the authorization code
# Gateways supporting payment profiles will need access to credit card object because this stores the payment profile information
# so supply the authorization itself as well as the credit card, rather than just the authorization code
response = payment_method.void(self.response_code, source, gateway_options)
else
# Standard ActiveMerchant void usage
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/payment_method.rb
Expand Up @@ -16,7 +16,7 @@ def provider_class
end

# The class that will process payments for this payment type, used for @payment.source
# e.g. Creditcard in the case of a the Gateway payment type
# e.g. CreditCard in the case of a the Gateway payment type
# nil means the payment method doesn't require a source e.g. check
def payment_source_class
raise 'You must implement payment_source_class method for this gateway.'
Expand Down
Expand Up @@ -6,7 +6,7 @@
<label><%= radio_button_tag :card, 'new', @previous_cards.none? %> <%= t(:use_new_cc) %></label>
</p>
<div id="card_form" data-hook>
<%= image_tag 'creditcards/creditcard.gif', :id => 'creditcard-image' %>
<%= image_tag 'credit_cards/credit_card.gif', :id => 'credit-card-image' %>
<% param_prefix = "payment_source[#{payment_method.id}]" %>

<div data-hook="card_number">
Expand Down
@@ -1,5 +1,5 @@
<fieldset data-hook="creditcard">
<legend><%= t(:creditcard) %></legend>
<fieldset data-hook="credit_card">
<legend><%= t(:credit_card) %></legend>

<table class="index">
<tr>
Expand Down
2 changes: 1 addition & 1 deletion core/app/views/spree/admin/shared/_tabs.html.erb
@@ -1,5 +1,5 @@
<%= tab :overview, :route => :admin %>
<%= tab :orders, :payments, :creditcard_payments, :shipments, :creditcards, :return_authorizations %>
<%= tab :orders, :payments, :creditcard_payments, :shipments, :credit_cards, :return_authorizations %>
<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons %>
<%= tab :reports %>
<%= tab :configurations, :general_settings, :mail_methods, :tax_categories, :zones, :states, :payment_methods, :inventory_settings, :taxonomies, :shipping_methods, :trackers, :label => 'configuration' %>
2 changes: 1 addition & 1 deletion core/app/views/spree/checkout/payment/_gateway.html.erb
@@ -1,4 +1,4 @@
<%= image_tag 'creditcards/creditcard.gif', :id => 'creditcard-image' %>
<%= image_tag 'credit_cards/credit_card.gif', :id => 'credit-card-image' %>
<% param_prefix = "payment_source[#{payment_method.id}]" %>

<p class="field" data-hook="card_number">
Expand Down
8 changes: 4 additions & 4 deletions core/app/views/spree/content/cvv.html.erb
Expand Up @@ -3,11 +3,11 @@
<p>For Visa, MasterCard, and Discover cards, the card code is the last 3 digit number located on the back of your card on or above your signature line. For an American Express card, it is the 4 digits on the FRONT above the end of your card number.</p>
<p>To help reduce fraud in the card-not-present environment, credit card companies have introduced a card code program. Visa calls this code Card Verification Value (CVV); MasterCard calls it Card Validation Code (CVC); Discover calls it Card ID (CID). The card code is a three- or four- digit security code that is printed on the back of cards. The number typically appears at the end of the signature panel.</p>
<div class="cid-caption">Visa</div>
<%= image_tag 'creditcards/visa_cid.gif' %>
<%= image_tag 'credit_cards/visa_cid.gif' %>
<div class="cid-caption">Master Card</div>
<%= image_tag 'creditcards/master_cid.jpg' %>
<%= image_tag 'credit_cards/master_cid.jpg' %>
<div class="cid-caption">American Express</div>
<%= image_tag 'creditcards/amex_cid.gif' %>
<%= image_tag 'credit_cards/amex_cid.gif' %>
<div class="cid-caption">Discover</div>
<%= image_tag 'creditcards/discover_cid.gif' %>
<%= image_tag 'credit_cards/discover_cid.gif' %>
</div>
10 changes: 5 additions & 5 deletions core/app/views/spree/shared/_order_details.html.erb
Expand Up @@ -24,15 +24,15 @@
<div class="columns omega four">
<h6><%= t(:payment_information) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:payment) unless @order.completed? %></h6>
<div class="payment-info">
<% unless order.creditcards.empty? %>
<% unless order.credit_cards.empty? %>
<span class="cc-type">
<%= image_tag "creditcards/icons/#{order.creditcards.first.cc_type}.png" %>
<%= t(:ending_in)%> <%= order.creditcards.first.last_digits %>
<%= image_tag "credit_cards/icons/#{order.credit_cards.first.cc_type}.png" %>
<%= t(:ending_in)%> <%= order.credit_cards.first.last_digits %>
</span>
<br />
<span class="full-name">
<%= order.creditcards.first.first_name %>
<%= order.creditcards.first.last_name %>
<%= order.credit_cards.first.first_name %>
<%= order.credit_cards.first.last_name %>
</span>
<% end %>
</div>
Expand Down
10 changes: 5 additions & 5 deletions core/config/locales/en.yml
Expand Up @@ -37,7 +37,7 @@ en:
iso_name: "ISO Name"
name: Name
numcode: "ISO Code"
spree/creditcard:
spree/credit_card:
cc_type: Type
month: Month
number: Number
Expand Down Expand Up @@ -140,7 +140,7 @@ en:
spree/country:
one: Country
other: Countries
spree/creditcard:
spree/credit_card:
one: "Credit Card"
other: "Credit Cards"
spree/creditcard_payment:
Expand Down Expand Up @@ -330,8 +330,8 @@ en:
credit_card_payment: "Credit Card Payment"
credit_owed: "Credit Owed"
credit_total: Credit Total
creditcard: Creditcard
creditcards: Creditcards
credit_card: Credit Card
credit_cards: Credit Cards
credits: Credits
current: Current
customer: Customer
Expand Down Expand Up @@ -871,7 +871,7 @@ en:
search_results: "Search results for '%{keywords}'"
searching: Searching
secure_connection_type: Secure Connection Type
secure_creditcard: Secure Creditcard
secure_credit_card: Secure Credit Card
select: Select
select_from_prototype: "Select From Prototype"
select_preferred_shipping_option: "Select preferred shipping option"
Expand Down
2 changes: 1 addition & 1 deletion core/config/routes.rb
Expand Up @@ -19,7 +19,7 @@
post :populate, :on => :collection

resources :line_items
resources :creditcards
resources :credit_cards
resources :creditcard_payments

resources :shipments do
Expand Down
10 changes: 5 additions & 5 deletions core/db/migrate/20100209144531_polymorphic_payments.rb
Expand Up @@ -12,17 +12,17 @@ def up
end
execute "UPDATE payments SET payable_type = 'Order'"

Spree::Creditcard.table_name = 'creditcards'
Spree::CreditCard.table_name = 'creditcards'

Spree::Creditcard.all.each do |creditcard|
if checkout = Checkout.find_by_id(creditcard.checkout_id) and checkout.order
Spree::CreditCard.all.each do |credit_card|
if checkout = Checkout.find_by_id(credit_card.checkout_id) && checkout.order
if payment = checkout.order.payments.first
execute "UPDATE payments SET source_type = 'Creditcard', source_id = #{creditcard.id} WHERE id = #{payment.id}"
execute "UPDATE payments SET source_type = 'Creditcard', source_id = #{credit_card.id} WHERE id = #{payment.id}"
end
end
end

Spree::Creditcard.table_name = 'spree_creditcards'
Spree::CreditCard.table_name = 'spree_creditcards'

remove_column :creditcards, :checkout_id
end
Expand Down
Expand Up @@ -3,15 +3,15 @@ def up
add_column :creditcard_txns, :payment_id, :integer

# Temporarily set back to creditcards
Spree::Creditcard.table_name = 'creditcards'
Spree::CreditCard.table_name = 'creditcards'

ActiveRecord::Base.connection.select_all('SELECT * FROM creditcard_txns').each do |txn_attrs|
if creditcard = Spree::Creditcard.find_by_id(txn_attrs['creditcard_id']) and creditcard.payments.first
execute "UPDATE creditcard_txns SET payment_id = #{creditcard.payments.first.id} WHERE id = #{txn_attrs['id']}"
if credit_card = Spree::CreditCard.find_by_id(txn_attrs['creditcard_id']) && credit_card.payments.first
execute "UPDATE creditcard_txns SET payment_id = #{credit_card.payments.first.id} WHERE id = #{txn_attrs['id']}"
end
end

Spree::Creditcard.table_name = 'spree_creditcards'
Spree::CreditCard.table_name = 'spree_creditcards'

remove_column :creditcard_txns, :creditcard_payment_id
end
Expand Down
@@ -0,0 +1,5 @@
class RenameCreditcardsToCreditCards < ActiveRecord::Migration
def change
rename_table :spree_creditcards, :spree_credit_cards
end
end
@@ -1,10 +1,10 @@
# allows creditcard info to be saved to the datbase which is needed for factories to work properly
class TestCard < Spree::Creditcard
# allows credit card info to be saved to the database which is needed for factories to work properly
class TestCard < Spree::CreditCard
def remove_readonly_attributes(attributes) attributes; end
end

FactoryGirl.define do
factory :creditcard, :class => TestCard do
factory :credit_card, :class => TestCard do
verification_value 123
month 12
year 2013
Expand Down
Expand Up @@ -2,7 +2,7 @@
factory :payment, :class => Spree::Payment do
amount 45.75
payment_method { FactoryGirl.create(:bogus_payment_method) }
source { FactoryGirl.build(:creditcard) }
source { FactoryGirl.build(:credit_card) }
order { FactoryGirl.create(:order) }
state 'pending'
response_code '12345'
Expand Down

0 comments on commit cfad733

Please sign in to comment.