Class: Spree::PaymentMethod::BogusCreditCard

Inherits:
CreditCard show all
Defined in:
app/models/spree/payment_method/bogus_credit_card.rb

Direct Known Subclasses

SimpleBogusCreditCard

Constant Summary collapse

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
AUTHORIZATION_CODE =
'12345'
FAILURE_MESSAGE =
'Bogus Gateway: Forced failure'
SUCCESS_MESSAGE =
'Bogus Gateway: Forced success'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CreditCard

#partial_name, #payment_source_class, #reusable_sources, #reusable_sources_by_order, #supports?

Methods inherited from Spree::PaymentMethod

#auto_capture?, find_sti_class, #gateway, model_name, #options, #partial_name, #payment_source_class, #reusable_sources, #source_required?, #store_credit?, #supports?, #try_void

Methods included from Spree::Preferences::StaticallyConfigurable

#preference_source=, #preferences, #preferences=

Methods inherited from Base

display_includes

Methods included from Core::Permalinks

#generate_permalink, #save_permalink

Instance Attribute Details

#testObject

Returns the value of attribute test.



16
17
18
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 16

def test
  @test
end

Instance Method Details

#actionsObject



82
83
84
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 82

def actions
  %w(capture void credit)
end

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



30
31
32
33
34
35
36
37
38
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 30

def authorize(_money, credit_card, _options = {})
  profile_id = credit_card.gateway_customer_profile_id
  message_detail = " - #{__method__}"
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
    ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'D' })
  else
    ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, { message: FAILURE_MESSAGE + message_detail }, test: true)
  end
end

#capture(_money, authorization, _gateway_options) ⇒ Object



55
56
57
58
59
60
61
62
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 55

def capture(_money, authorization, _gateway_options)
  message_detail = " - #{__method__}"
  if authorization == '12345'
    ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true)
  else
    ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, error: FAILURE_MESSAGE + message_detail, test: true)
  end
end

#create_profile(payment) ⇒ Object



22
23
24
25
26
27
28
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 22

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(gateway_customer_profile_id: generate_profile_id(success))
  end
end

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



50
51
52
53
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 50

def credit(_money, _credit_card, _response_code, _options = {})
  message_detail = " - #{__method__}"
  ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE)
end

#gateway_classObject



18
19
20
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 18

def gateway_class
  self.class
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 78

def payment_profiles_supported?
  true
end

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



40
41
42
43
44
45
46
47
48
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 40

def purchase(_money, credit_card, _options = {})
  profile_id = credit_card.gateway_customer_profile_id
  message_detail = " - #{__method__}"
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
    ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'M' })
  else
    ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, message: FAILURE_MESSAGE + message_detail, test: true)
  end
end

#test?Boolean

Returns:

  • (Boolean)


73
74
75
76
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 73

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



64
65
66
67
68
69
70
71
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 64

def void(_response_code, _credit_card, options = {})
  message_detail = " - #{__method__}"
  if options[:originator].completed?
    ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE)
  else
    ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE + message_detail, {}, test: true, authorization: AUTHORIZATION_CODE)
  end
end