Class: Gateway::Bogus

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

Constant Summary collapse

TEST_VISA =
"4111111111111111"
TEST_MC =
"5500000000000004"
TEST_AMEX =
"340000000000009"
TEST_DISC =
"6011000000000004"
VALID_CCS =
["1", TEST_VISA, TEST_MC, TEST_AMEX, TEST_DISC]

Constants inherited from PaymentMethod

PaymentMethod::DISPLAY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gateway

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

Methods inherited from PaymentMethod

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

Dynamic Method Handling

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

Instance Attribute Details

#testObject

Returns the value of attribute test.



9
10
11
# File 'app/models/gateway/bogus.rb', line 9

def test
  @test
end

Instance Method Details

#authorize(money, creditcard, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'app/models/gateway/bogus.rb', line 25

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-")
    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

#capture(authorization, creditcard, gateway_options) ⇒ Object



47
48
49
50
51
52
53
54
# File 'app/models/gateway/bogus.rb', line 47

def capture(authorization, creditcard, gateway_options)
  if authorization.response_code == "12345"
    ActiveMerchant::Billing::Response.new(true, "Bogus Gateway: Forced success", {}, :test => true, :authorization => '67890')
  else
    ActiveMerchant::Billing::Response.new(false, "Bogus Gateway: Forced failure", :error => 'Bogus Gateway: Forced failure', :test => true)
  end

end

#create_profile(payment) ⇒ Object



19
20
21
22
23
# File 'app/models/gateway/bogus.rb', line 19

def create_profile(payment)
  # simulate the storage of credit card profile using remote service
  success = VALID_CCS.include? payment.source.number
  payment.source.update_attributes(:gateway_customer_profile_id => generate_profile_id(success))
end

#credit(money, creditcard, response_code, options = {}) ⇒ Object



43
44
45
# File 'app/models/gateway/bogus.rb', line 43

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

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/gateway/bogus.rb', line 65

def payment_profiles_supported?
  true
end

#preferencesObject



15
16
17
# File 'app/models/gateway/bogus.rb', line 15

def preferences
  {}
end

#provider_classObject



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

def provider_class
  self.class
end

#purchase(money, creditcard, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'app/models/gateway/bogus.rb', line 34

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-")
    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

#test?Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'app/models/gateway/bogus.rb', line 60

def test?
  # Test mode is not really relevant with bogus gateway (no such thing as live server)
  true
end

#void(response_code, creditcard, options = {}) ⇒ Object



56
57
58
# File 'app/models/gateway/bogus.rb', line 56

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