Class: Spree::PaymentMethod::BogusCreditCard
- Inherits:
-
CreditCard
show all
- Defined in:
- app/models/spree/payment_method/bogus_credit_card.rb
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
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#actions ⇒ Object
-
#authorize(_money, credit_card, _options = {}) ⇒ Object
-
#capture(_money, authorization, _gateway_options) ⇒ Object
-
#create_profile(payment) ⇒ Object
-
#credit(_money, _credit_card, _response_code, _options = {}) ⇒ Object
-
#gateway_class ⇒ Object
-
#payment_profiles_supported? ⇒ Boolean
-
#purchase(_money, credit_card, _options = {}) ⇒ Object
-
#test? ⇒ Boolean
-
#try_void(_payment) ⇒ Object
-
#void(_response_code, _credit_card, _options = {}) ⇒ Object
Methods inherited from CreditCard
#partial_name, #payment_source_class, #reusable_sources, #reusable_sources_by_order, #supports?
active?, #auto_capture?, available, const_missing, #deprecated_method_type_override, #display_on, #display_on=, find_with_destroyed, #gateway, #method_type, model_name, #options, #partial_name, #payment_source_class, providers, #reusable_sources, #source_required?, #store_credit?, #supports?
#preference_source=, #preferences, #preferences=
#paranoia_delete, #paranoia_destroy
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
#admin_form_preference_names, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Attribute Details
#test ⇒ Object
Returns the value of attribute test.
12
13
14
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 12
def test
@test
end
|
Instance Method Details
#actions ⇒ Object
74
75
76
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 74
def actions
%w(capture void credit)
end
|
#authorize(_money, credit_card, _options = {}) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 26
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
|
#capture(_money, authorization, _gateway_options) ⇒ Object
48
49
50
51
52
53
54
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 48
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
18
19
20
21
22
23
24
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 18
def create_profile(payment)
return if payment.source.has_payment_profile?
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
44
45
46
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 44
def credit(_money, _credit_card, _response_code, _options = {})
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end
|
#gateway_class ⇒ Object
14
15
16
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 14
def gateway_class
self.class
end
|
#payment_profiles_supported? ⇒ Boolean
70
71
72
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 70
def payment_profiles_supported?
true
end
|
#purchase(_money, credit_card, _options = {}) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 35
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
65
66
67
68
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 65
def test?
true
end
|
#try_void(_payment) ⇒ Object
61
62
63
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 61
def try_void(_payment)
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end
|
#void(_response_code, _credit_card, _options = {}) ⇒ Object
56
57
58
|
# File 'app/models/spree/payment_method/bogus_credit_card.rb', line 56
def void(_response_code, _credit_card, _options = {})
ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
end
|