Class: Gateway::AuthorizeNetCim

Inherits:
Gateway show all
Defined in:
app/models/gateway/authorize_net_cim.rb

Constant Summary

Constants inherited from PaymentMethod

PaymentMethod::DISPLAY

Instance Method Summary collapse

Methods inherited from Gateway

current, #method_missing, #method_type, #payment_source_class, #provider

Methods inherited from PaymentMethod

active?, available, current, #destroy, find_with_destroyed, #method_type, #payment_source_class, providers, register

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gateway

Instance Method Details

#authorize(amount, creditcard, gateway_options) ⇒ Object



26
27
28
# File 'app/models/gateway/authorize_net_cim.rb', line 26

def authorize(amount, creditcard, gateway_options)
  create_transaction(amount, creditcard, :auth_only)
end

#capture(authorization, creditcard, gateway_options) ⇒ Object



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

def capture(authorization, creditcard, gateway_options)
  create_transaction((authorization.amount * 100).round, creditcard, :prior_auth_capture, :trans_id => authorization.response_code)
end

#create_profile(payment) ⇒ Object

Create a new CIM customer profile ready to accept a payment



51
52
53
54
55
56
# File 'app/models/gateway/authorize_net_cim.rb', line 51

def create_profile(payment)
  if payment.source.gateway_customer_profile_id.nil?
    profile_hash = create_customer_profile(payment)
    payment.source.update_attributes(:gateway_customer_profile_id => profile_hash[:customer_profile_id], :gateway_payment_profile_id => profile_hash[:customer_payment_profile_id])
  end
end

#create_profile_from_card(card) ⇒ Object

simpler form



59
60
61
62
63
64
# File 'app/models/gateway/authorize_net_cim.rb', line 59

def create_profile_from_card(card)
  if card.gateway_customer_profile_id.nil?
    profile_hash = create_customer_profile(card)
    card.update_attributes(:gateway_customer_profile_id => profile_hash[:customer_profile_id], :gateway_payment_profile_id => profile_hash[:customer_payment_profile_id])
  end
end

#credit(amount, creditcard, response_code, gateway_options) ⇒ Object



38
39
40
# File 'app/models/gateway/authorize_net_cim.rb', line 38

def credit(amount, creditcard, response_code, gateway_options)
  create_transaction(amount, creditcard, :refund, :trans_id => response_code)
end

#optionsObject



15
16
17
18
19
20
21
22
23
24
# File 'app/models/gateway/authorize_net_cim.rb', line 15

def options
  # add :test key in the options hash, as that is what the ActiveMerchant::Billing::AuthorizeNetGateway expects
  if self.prefers? :test_mode
    self.class.default_preferences[:test] = true
  else
    self.class.default_preferences.delete(:test)
  end

  super
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/gateway/authorize_net_cim.rb', line 46

def payment_profiles_supported?
  true
end

#provider_classObject



11
12
13
# File 'app/models/gateway/authorize_net_cim.rb', line 11

def provider_class
  self.class
end

#purchase(amount, creditcard, gateway_options) ⇒ Object



30
31
32
# File 'app/models/gateway/authorize_net_cim.rb', line 30

def purchase(amount, creditcard, gateway_options)
  create_transaction(amount, creditcard, :auth_capture)
end

#void(response_code, creditcard, gateway_options) ⇒ Object



42
43
44
# File 'app/models/gateway/authorize_net_cim.rb', line 42

def void(response_code, creditcard, gateway_options)
  create_transaction(nil, creditcard, :void, :trans_id => response_code)
end