Class: PaymentProfile

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
PaymentProfileCim
Defined in:
app/models/payment_profile.rb

Overview

NOTE Payment profile methods have been created however these methods have not been tested in any fashion

These method are here to give you a heads start.  Once CIM is created these methods will be ready for use.

> Please refer to the following web page about seting up CIM. This code has not been fully tested but

should serve you very well.

cookingandcoding.com/2010/01/14/using-activemerchant-with-authorize-net-and-authorize-cim/

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from PaymentProfileCim

#create, #destroy, #update

Instance Attribute Details

- (Object) credit_card

Returns the value of attribute credit_card



34
35
36
# File 'app/models/payment_profile.rb', line 34

def credit_card
  @credit_card
end

- (Object) request_ip

Returns the value of attribute request_ip



34
35
36
# File 'app/models/payment_profile.rb', line 34

def request_ip
  @request_ip
end

Instance Method Details

- (CreditCard) credit_card_info=(card_or_params)

method used by forms to credit a temp credit card


behave like it's

has_one :credit_card
accepts_nested_attributes_for :credit_card_info

Parameters:

  • (none)

Returns:

  • (CreditCard)


86
87
88
89
90
91
92
93
94
# File 'app/models/payment_profile.rb', line 86

def credit_card_info=( card_or_params )
  self.credit_card = case card_or_params
    when ActiveMerchant::Billing::CreditCard, nil
      card_or_params
    else
      ActiveMerchant::Billing::CreditCard.new(card_or_params)
    end
  set_minimal_cc_data(self.credit_card)
end

- (Object) inactivate!



53
54
55
56
# File 'app/models/payment_profile.rb', line 53

def inactivate!
  self.active = false
  self.save!
end

- (Object) name

attr_accessible # none



49
50
51
# File 'app/models/payment_profile.rb', line 49

def name
  [cc_type, last_digits].join(' - ')
end

- (CreditCard) new_credit_card

credit card object with known values

Parameters:

  • (none)

Returns:

  • (CreditCard)


100
101
102
103
104
105
106
107
108
# File 'app/models/payment_profile.rb', line 100

def new_credit_card
  # populate new card with some saved values
  ActiveMerchant::Billing::CreditCard.new(
    :first_name  => user.first_name,
    :last_name   => user.last_name,
    # :address etc too if we have it
    :brand        => cc_type
  )
end

- (Object) save_default_profile(cc_user)

Use this method to create a PaymentProfile

> This method will create a new PaymentProfile and if the PaymentProfile is a default PaymentProfile it

> will make all other PaymentProfiles that belong to the user non-default

@ return [Boolean] true or nil

Parameters:

  • user (User)

    associated to the payment profile

  • hash (Hash)

    of attributes for the new address



65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/payment_profile.rb', line 65

def save_default_profile(cc_user)
  PaymentProfile.transaction do
    if self.default == true
      PaymentProfile.update_all( { :default  => false},
                          { :payment_profiles => {
                                :user_id => cc_user.id,
                                          } }) if cc_user
    end
    self.user = cc_user
    self.save
  end
end