Class: SubscriptionProfile
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SubscriptionProfile
- Defined in:
- app/models/subscription_profile.rb
Instance Attribute Summary collapse
-
#credit_card ⇒ Object
validates_presence_of :subscription_id.
-
#request_ip ⇒ Object
validates_presence_of :subscription_id.
Class Method Summary collapse
-
.example_credit_card_params(params = {}) ⇒ Object
————- move this into a test helper…
Instance Method Summary collapse
Instance Attribute Details
#credit_card ⇒ Object
validates_presence_of :subscription_id
5 6 7 |
# File 'app/models/subscription_profile.rb', line 5 def credit_card @credit_card end |
#request_ip ⇒ Object
validates_presence_of :subscription_id
5 6 7 |
# File 'app/models/subscription_profile.rb', line 5 def request_ip @request_ip end |
Class Method Details
.example_credit_card_params(params = {}) ⇒ Object
move this into a test helper…
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/subscription_profile.rb', line 54 def self.example_credit_card_params( params = {}) default = { :first_name => 'First Name', :last_name => 'Last Name', :type => 'visa', :number => '4111111111111111', :month => '10', :year => '2012', :verification_value => '999' }.merge( params ) specific = case SubscriptionConfig.gateway_name when 'authorize_net_cim' { :type => 'visa', :number => '4007000000027', } # 370000000000002 American Express Test Card # 6011000000000012 Discover Test Card # 4007000000027 Visa Test Card # 4012888818888 second Visa Test Card # 3088000000000017 JCB # 38000000000006 Diners Club/ Carte Blanche when 'bogus' { :type => 'bogus', :number => '1', } else {} end default.merge(specific).merge(params) end |
Instance Method Details
#new_credit_card ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'app/models/subscription_profile.rb', line 42 def new_credit_card # populate new card with some saved values ActiveMerchant::Billing::CreditCard.new( :first_name => card_first_name, :last_name => card_last_name, # :address etc too if we have it :type => card_type ) end |
#unstore_card ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/subscription_profile.rb', line 91 def unstore_card return if no_info? || profile_key.nil? transaction do # atomic tx = SubscriptionTransaction.unstore( profile_key ) subscription.transactions.push( tx ) if tx.success? # clear everything in case this is ever called without destroy self.profile_key = nil self.card_first_name = nil self.card_last_name = nil self.card_type = nil self.card_display_number = nil self.card_expires_on = nil self.credit_card = nil # change profile state self.state = 'no_info' # can't call no_info! here, it saves else #errors.add(:credit_card, "failed to #{tx.action} card: #{tx.message}") errors.add_to_base "Failed to #{tx.action} card: #{tx.}" end tx.success end end |