Class: Spree::Gateway::Bogus

Inherits:
Spree::Gateway show all
Defined in:
app/models/spree/gateway/bogus.rb

Direct Known Subclasses

BogusSimple

Constant Summary

TEST_VISA =
['4111111111111111', '4012888888881881', '4222222222222']
TEST_MC =
['5500000000000004', '5555555555554444', '5105105105105100']
TEST_AMEX =
['378282246310005', '371449635398431', '378734493671000', '340000000000009']
TEST_DISC =
['6011000000000004', '6011111111111117', '6011000990139424']
VALID_CCS =
['1', TEST_VISA, TEST_MC, TEST_AMEX, TEST_DISC].flatten

Constants inherited from PaymentMethod

PaymentMethod::DISPLAY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::Gateway

#method_type, #options, #payment_source_class, #provider, #reusable_sources, #reusable_sources_by_order, #supports?

Methods inherited from PaymentMethod

active?, #auto_capture?, available, #display_on, #display_on=, find_with_destroyed, #method_type, #payment_source_class, providers, #reusable_sources, #source_required?, #store_credit?, #supports?

Methods included from Preferences::StaticallyConfigurable

#preference_source=, #preferences, #preferences=

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Attribute Details

#testObject

Returns the value of attribute test



10
11
12
# File 'app/models/spree/gateway/bogus.rb', line 10

def test
  @test
end

Instance Method Details

#actionsObject



71
72
73
# File 'app/models/spree/gateway/bogus.rb', line 71

def actions
  %w(capture void credit)
end

#authorize(_money, credit_card, _options = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'app/models/spree/gateway/bogus.rb', line 24

def authorize(_money, credit_card, _options = {})
  profile_id = credit_card.gateway_customer_profile_id
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
    ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'D' })
  else
    ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { message: 'Bogus Gateway: Forced failure' }, test: true)
  end
end

#cancel(_response_code) ⇒ Object



58
59
60
# File 'app/models/spree/gateway/bogus.rb', line 58

def cancel(_response_code)
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end

#capture(_money, authorization, _gateway_options) ⇒ Object



46
47
48
49
50
51
52
# File 'app/models/spree/gateway/bogus.rb', line 46

def capture(_money, authorization, _gateway_options)
  if authorization == '12345'
    ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true)
  else
    ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', error: 'Bogus Gateway: Forced failure', test: true)
  end
end

#create_profile(payment) ⇒ Object



16
17
18
19
20
21
22
# File 'app/models/spree/gateway/bogus.rb', line 16

def create_profile(payment)
  return if payment.source.has_payment_profile?
  # simulate the storage of credit card profile using remote service
  if success = VALID_CCS.include?(payment.source.number)
    payment.source.update_attributes(gateway_customer_profile_id: generate_profile_id(success))
  end
end

#credit(_money, _credit_card, _response_code, _options = {}) ⇒ Object



42
43
44
# File 'app/models/spree/gateway/bogus.rb', line 42

def credit(_money, _credit_card, _response_code, _options = {})
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/spree/gateway/bogus.rb', line 67

def payment_profiles_supported?
  true
end

#provider_classObject



12
13
14
# File 'app/models/spree/gateway/bogus.rb', line 12

def provider_class
  self.class
end

#purchase(_money, credit_card, _options = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'app/models/spree/gateway/bogus.rb', line 33

def purchase(_money, credit_card, _options = {})
  profile_id = credit_card.gateway_customer_profile_id
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
    ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'M' })
  else
    ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', message: 'Bogus Gateway: Forced failure', test: true)
  end
end

#test?Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'app/models/spree/gateway/bogus.rb', line 62

def test?
  # Test mode is not really relevant with bogus gateway (no such thing as live server)
  true
end

#void(_response_code, _credit_card, _options = {}) ⇒ Object



54
55
56
# File 'app/models/spree/gateway/bogus.rb', line 54

def void(_response_code, _credit_card, _options = {})
  ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end