class ActiveMerchant::Billing::BogusGateway

Bogus Gateway

Constants

AMOUNT_ERROR_MESSAGE
AUTHORIZATION
AUTHORIZATION_EMV_DECLINE
AUTHORIZATION_EMV_SUCCESS
CAPTURE_ERROR_MESSAGE
CHECK_ERROR_MESSAGE
FAILURE_MESSAGE
NUMBER_ERROR_MESSAGE
REFUND_ERROR_MESSAGE
SUCCESS_MESSAGE
UNSTORE_ERROR_MESSAGE
VOID_ERROR_MESSAGE

Public Instance Methods

authorize(money, paysource, options = {}) click to toggle source
# 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 = {}) click to toggle source
# 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 = {}) click to toggle source
# 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 = {}) click to toggle source
# 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 = {}) click to toggle source
# 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 = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 93
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 = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 104
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 = {}) click to toggle source
# 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

Private Instance Methods

authorize_emv(money, paysource, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 117
def authorize_emv(money, paysource, options = {})
  money = amount(money)
  case money
  when /00$/
    Response.new(true, SUCCESS_MESSAGE, {:authorized_amount => money}, :test => true, :authorization => AUTHORIZATION, :emv_authorization => AUTHORIZATION_EMV_SUCCESS)
  when /05$/
    Response.new(false, FAILURE_MESSAGE, {:authorized_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error], :emv_authorization => AUTHORIZATION_EMV_DECLINE)
  else
    raise Error, error_message(paysource)
  end
end
authorize_swipe(money, paysource, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 129
def authorize_swipe(money, paysource, options = {})
  money = amount(money)
  case normalize(paysource)
  when /1$/, AUTHORIZATION
    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
error_message(paysource) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 175
def error_message(paysource)
  if paysource.respond_to?(:emv?) && paysource.emv?
    AMOUNT_ERROR_MESSAGE
  elsif paysource.respond_to?(:account_number)
    CHECK_ERROR_MESSAGE
  elsif paysource.respond_to?(:number)
    NUMBER_ERROR_MESSAGE
  end
end
normalize(paysource) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 165
def normalize(paysource)
  if paysource.respond_to?(:account_number) && (paysource.try(:number).blank? || paysource.number.blank?)
    paysource.account_number
  elsif paysource.respond_to?(:number)
    paysource.number
  else
    paysource.to_s
  end
end
purchase_emv(money, paysource, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 141
def purchase_emv(money, paysource, options = {})
  money = amount(money)
  case money
  when /00$/
    Response.new(true, SUCCESS_MESSAGE, {:paid_amount => money}, :test => true, :authorization => AUTHORIZATION, :emv_authorization => AUTHORIZATION_EMV_SUCCESS)
  when /05$/
    Response.new(false, FAILURE_MESSAGE, {:paid_amount => money, :error => FAILURE_MESSAGE }, :test => true, :error_code => STANDARD_ERROR_CODE[:processing_error], :emv_authorization => AUTHORIZATION_EMV_DECLINE)
  else
    raise Error, error_message(paysource)
  end
end
purchase_swipe(money, paysource, options = {}) click to toggle source
# File lib/active_merchant/billing/gateways/bogus.rb, line 153
def purchase_swipe(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