Class: ActiveMerchant::Billing::BogusGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/bogus.rb

Overview

Bogus Gateway

Constant Summary collapse

AUTHORIZATION =
'53433'
SUCCESS_MESSAGE =
"Bogus Gateway: Forced success"
FAILURE_MESSAGE =
"Bogus Gateway: Forced failure"
ERROR_MESSAGE =
"Bogus Gateway: Use CreditCard number 1 for success, 2 for exception and anything else for error"
CREDIT_ERROR_MESSAGE =
"Bogus Gateway: Use trans_id 1 for success, 2 for exception and anything else for error"
UNSTORE_ERROR_MESSAGE =
"Bogus Gateway: Use trans_id 1 for success, 2 for exception and anything else for error"
CAPTURE_ERROR_MESSAGE =
"Bogus Gateway: Use authorization number 1 for exception, 2 for error and anything else for success"
VOID_ERROR_MESSAGE =
"Bogus Gateway: Use authorization number 1 for exception, 2 for error and anything else for success"

Constants inherited from Gateway

Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, #initialize, supports?, #test?

Methods included from Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #ssl_get, #ssl_post

Constructor Details

This class inherits a constructor from ActiveMerchant::Billing::Gateway

Instance Method Details

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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 20

def authorize(money, creditcard, options = {})
  money = amount(money)
  case creditcard.number
  when '1'
    Response.new(true, SUCCESS_MESSAGE, {:authorized_amount => money}, :test => true, :authorization => AUTHORIZATION )
  when '2'
    Response.new(false, FAILURE_MESSAGE, {:authorized_amount => money, :error => FAILURE_MESSAGE }, :test => true)
  else
    raise Error, ERROR_MESSAGE
  end      
end

#capture(money, ident, options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 56

def capture(money, ident, options = {})
  money = amount(money)
  case ident
  when '1'
    raise Error, CAPTURE_ERROR_MESSAGE
  when '2'
    Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
  else
    Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
  end
end

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



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 44

def credit(money, ident, options = {})
  money = amount(money)
  case ident
  when '1'
    raise Error, CREDIT_ERROR_MESSAGE
  when '2'
    Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true)
  else
    Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
  end
end

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



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 32

def purchase(money, creditcard, options = {})
  money = amount(money)
  case creditcard.number
  when '1'
    Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
  when '2'
    Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE },:test => true)
  else
    raise Error, ERROR_MESSAGE
  end
end

#store(creditcard, options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 79

def store(creditcard, options = {})
  case creditcard.number
  when '1'
    Response.new(true, SUCCESS_MESSAGE, {:billingid => '1'}, :test => true, :authorization => AUTHORIZATION )
  when '2'
    Response.new(false, FAILURE_MESSAGE, {:billingid => nil, :error => FAILURE_MESSAGE }, :test => true)
  else
    raise Error, ERROR_MESSAGE
  end              
end

#unstore(identification, options = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 90

def unstore(identification, options = {})
  case identification
  when '1'
    Response.new(true, SUCCESS_MESSAGE, {}, :test => true)
  when '2'
    Response.new(false, FAILURE_MESSAGE, {:error => FAILURE_MESSAGE },:test => true)
  else
    raise Error, UNSTORE_ERROR_MESSAGE
  end
end

#void(ident, options = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 68

def void(ident, options = {})
  case ident
  when '1'
    raise Error, VOID_ERROR_MESSAGE
  when '2'
    Response.new(false, FAILURE_MESSAGE, {:authorization => ident, :error => FAILURE_MESSAGE }, :test => true)
  else
    Response.new(true, SUCCESS_MESSAGE, {:authorization => ident}, :test => true)
  end
end