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'
AUTHORIZATION_EMV_SUCCESS =
'8A023030'
AUTHORIZATION_EMV_DECLINE =
'8A023035'
SUCCESS_MESSAGE =
'Bogus Gateway: Forced success'
FAILURE_MESSAGE =
'Bogus Gateway: Forced failure'
NUMBER_ERROR_MESSAGE =
'Bogus Gateway: Use CreditCard number ending in 1 for success, 2 for exception and anything else for error'
AMOUNT_ERROR_MESSAGE =
'Bogus Gateway: Use amount ending in 00 for success, 05 for failure and anything else for exception'
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::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #initialize, #scrub, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

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

Instance Method Details

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



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

def authorize(money, paysource, options = {})
  if paysource.respond_to?(:emv?) && paysource.emv?
    authorize_emv(money, paysource, options)
  else
    authorize_swipe(money, paysource, options)
  end
end

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



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

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



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

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
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 33

def purchase(money, paysource, options = {})
  if paysource.respond_to?(:emv?) && paysource.emv?
    purchase_emv(money, paysource, options)
  else
    purchase_swipe(money, paysource, options)
  end
end

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



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

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

#verify(credit_card, options = {}) ⇒ Object



93
94
95
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 93

def verify(credit_card, options = {})
  authorize(0, credit_card, options)
end

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



82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/bogus.rb', line 82

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