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"
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"
CHECK_ERROR_MESSAGE =
"Bogus Gateway: Use bank account number ending in 1 for success, 2 for exception and anything else for error"

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, #initialize, non_fractional_currency?, #scrub, #supported_countries, supported_countries, supported_countries=, supports?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Constructor Details

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

Instance Method Details

#authorize(money, paysource, 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, paysource, options = {})
  money = amount(money)
  case normalize(paysource)
  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, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    raise Error, error_message(paysource)
  end
end

#capture(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 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, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
  end
end

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


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

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

  money = amount(money)
  case normalize(paysource)
  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, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    raise Error, error_message(paysource)
  end
end

#purchase(money, paysource, 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, paysource, options = {})
  money = amount(money)
  case normalize(paysource)
  when /1$/, AUTHORIZATION
    Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true, :authorization => AUTHORIZATION)
  when /2$/
    Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    raise Error, error_message(paysource)
  end
end

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


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

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, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true)
  end
end

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


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

def store(paysource, options = {})
  case normalize(paysource)
  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, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    raise Error, error_message(paysource)
  end
end

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


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

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, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    raise Error, UNSTORE_ERROR_MESSAGE
  end
end

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


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

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, :error_code => STANDARD_ERROR_CODE[:processing_error])
  else
    Response.new(true, SUCCESS_MESSAGE, {:authorization => reference}, :test => true)
  end
end