Class: Gateway::AuthorizeNetCim

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

Instance Method Summary collapse

Instance Method Details

#authorize(amount, creditcard, gateway_options) ⇒ Object



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

def authorize(amount, creditcard, gateway_options)
  t_options = { :order => {:invoice_number => gateway_options[:order_id] } }
   create_transaction( amount, creditcard, :auth_only, t_options )
end

#capture(authorization, creditcard, gateway_options) ⇒ Object



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

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



55
56
57
58
59
60
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 55

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



63
64
65
66
67
68
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 63

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



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

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

#optionsObject



18
19
20
21
22
23
24
25
26
27
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 18

def options
  # add :test key in the options hash, as that is what the ActiveMerchant::Billing::AuthorizeNetGateway expects
  if self.preferred_test_mode
    self.class.preference :test, :boolean, :default => true
  else
    self.class.remove_preference :test
  end

  super
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 50

def payment_profiles_supported?
  true
end

#provider_classObject



14
15
16
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 14

def provider_class
  self.class
end

#purchase(amount, creditcard, gateway_options) ⇒ Object



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

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

#void(response_code, creditcard, gateway_options) ⇒ Object



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

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