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 ending in 1 for success, 2 for exception and anything else for error"
CREDIT_ERROR_MESSAGE =
"Bogus Gateway: Use CreditCard number ending in 1 for success, 2 for exception and anything else for error"
UNSTORE_ERROR_MESSAGE =
"Bogus Gateway: Use trans_id ending in 1 for success, 2 for exception and anything else for error"
CAPTURE_ERROR_MESSAGE =
"Bogus Gateway: Use authorization number ending in 1 for exception, 2 for error and anything else for success"
VOID_ERROR_MESSAGE =
"Bogus Gateway: Use authorization number ending in 1 for exception, 2 for error and anything else for success"
REFUND_ERROR_MESSAGE =
"Bogus Gateway: Use trans_id number ending in 1 for exception, 2 for error and anything else for success"

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, 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 CreditCardFormatting

#format

Constructor Details

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

Instance Method Details

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



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

def authorize(money, credit_card_or_reference, options = {})
  money = amount(money)
  case normalize(credit_card_or_reference)
  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, reference, options = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 86

def capture(money, reference, options = {})
  money = amount(money)
  case reference
  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, credit_card_or_reference, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 57

def credit(money, credit_card_or_reference, options = {})
  if credit_card_or_reference.is_a?(String)
    deprecated CREDIT_DEPRECATION_MESSAGE
    return refund(money, credit_card_or_reference, options)
  end

  money = amount(money)
  case normalize(credit_card_or_reference)
  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, CREDIT_ERROR_MESSAGE
  end
end

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



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

def purchase(money, credit_card_or_reference, options = {})
  money = amount(money)
  case normalize(credit_card_or_reference)
  when /1$/, AUTHORIZATION
    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

#recurring(money, credit_card_or_reference, options = {}) ⇒ Object



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

def recurring(money, credit_card_or_reference, options = {})
  money = amount(money)
  case normalize(credit_card_or_reference)
  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

#refund(money, reference, options = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 74

def refund(money, reference, options = {})
  money = amount(money)
  case reference
  when /1$/
    raise Error, REFUND_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

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



109
110
111
112
113
114
115
116
117
118
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 109

def store(credit_card_or_reference, options = {})
  case normalize(credit_card_or_reference)
  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(reference, options = {}) ⇒ Object



120
121
122
123
124
125
126
127
128
129
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 120

def unstore(reference, options = {})
  case reference
  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(reference, options = {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 98

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